mxsfb_out.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 2016 Marek Vasut <marex@denx.de>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/of_graph.h>
  14. #include <drm/drm_atomic.h>
  15. #include <drm/drm_atomic_helper.h>
  16. #include <drm/drm_crtc.h>
  17. #include <drm/drm_crtc_helper.h>
  18. #include <drm/drm_fb_cma_helper.h>
  19. #include <drm/drm_gem_cma_helper.h>
  20. #include <drm/drm_panel.h>
  21. #include <drm/drm_plane_helper.h>
  22. #include <drm/drm_simple_kms_helper.h>
  23. #include <drm/drmP.h>
  24. #include "mxsfb_drv.h"
  25. static struct mxsfb_drm_private *
  26. drm_connector_to_mxsfb_drm_private(struct drm_connector *connector)
  27. {
  28. return container_of(connector, struct mxsfb_drm_private, connector);
  29. }
  30. static int mxsfb_panel_get_modes(struct drm_connector *connector)
  31. {
  32. struct mxsfb_drm_private *mxsfb =
  33. drm_connector_to_mxsfb_drm_private(connector);
  34. if (mxsfb->panel)
  35. return mxsfb->panel->funcs->get_modes(mxsfb->panel);
  36. return 0;
  37. }
  38. static const struct
  39. drm_connector_helper_funcs mxsfb_panel_connector_helper_funcs = {
  40. .get_modes = mxsfb_panel_get_modes,
  41. };
  42. static enum drm_connector_status
  43. mxsfb_panel_connector_detect(struct drm_connector *connector, bool force)
  44. {
  45. struct mxsfb_drm_private *mxsfb =
  46. drm_connector_to_mxsfb_drm_private(connector);
  47. if (mxsfb->panel)
  48. return connector_status_connected;
  49. return connector_status_disconnected;
  50. }
  51. static void mxsfb_panel_connector_destroy(struct drm_connector *connector)
  52. {
  53. struct mxsfb_drm_private *mxsfb =
  54. drm_connector_to_mxsfb_drm_private(connector);
  55. if (mxsfb->panel)
  56. drm_panel_detach(mxsfb->panel);
  57. drm_connector_unregister(connector);
  58. drm_connector_cleanup(connector);
  59. }
  60. static const struct drm_connector_funcs mxsfb_panel_connector_funcs = {
  61. .dpms = drm_atomic_helper_connector_dpms,
  62. .detect = mxsfb_panel_connector_detect,
  63. .fill_modes = drm_helper_probe_single_connector_modes,
  64. .destroy = mxsfb_panel_connector_destroy,
  65. .reset = drm_atomic_helper_connector_reset,
  66. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  67. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  68. };
  69. static int mxsfb_attach_endpoint(struct drm_device *drm,
  70. const struct of_endpoint *ep)
  71. {
  72. struct mxsfb_drm_private *mxsfb = drm->dev_private;
  73. struct device_node *np;
  74. struct drm_panel *panel;
  75. int ret = -EPROBE_DEFER;
  76. np = of_graph_get_remote_port_parent(ep->local_node);
  77. panel = of_drm_find_panel(np);
  78. of_node_put(np);
  79. if (!panel)
  80. return -EPROBE_DEFER;
  81. mxsfb->connector.dpms = DRM_MODE_DPMS_OFF;
  82. mxsfb->connector.polled = 0;
  83. drm_connector_helper_add(&mxsfb->connector,
  84. &mxsfb_panel_connector_helper_funcs);
  85. ret = drm_connector_init(drm, &mxsfb->connector,
  86. &mxsfb_panel_connector_funcs,
  87. DRM_MODE_CONNECTOR_Unknown);
  88. if (!ret)
  89. mxsfb->panel = panel;
  90. return ret;
  91. }
  92. int mxsfb_create_output(struct drm_device *drm)
  93. {
  94. struct device_node *ep_np = NULL;
  95. struct of_endpoint ep;
  96. int ret;
  97. for_each_endpoint_of_node(drm->dev->of_node, ep_np) {
  98. ret = of_graph_parse_endpoint(ep_np, &ep);
  99. if (!ret)
  100. ret = mxsfb_attach_endpoint(drm, &ep);
  101. if (ret) {
  102. of_node_put(ep_np);
  103. return ret;
  104. }
  105. }
  106. return 0;
  107. }