mdp4_lvds_connector.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) 2014 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. * Author: Vinay Simha <vinaysimha@inforcecomputing.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/gpio.h>
  19. #include "mdp4_kms.h"
  20. struct mdp4_lvds_connector {
  21. struct drm_connector base;
  22. struct drm_encoder *encoder;
  23. struct drm_panel *panel;
  24. };
  25. #define to_mdp4_lvds_connector(x) container_of(x, struct mdp4_lvds_connector, base)
  26. static enum drm_connector_status mdp4_lvds_connector_detect(
  27. struct drm_connector *connector, bool force)
  28. {
  29. struct mdp4_lvds_connector *mdp4_lvds_connector =
  30. to_mdp4_lvds_connector(connector);
  31. return mdp4_lvds_connector->panel ?
  32. connector_status_connected :
  33. connector_status_disconnected;
  34. }
  35. static void mdp4_lvds_connector_destroy(struct drm_connector *connector)
  36. {
  37. struct mdp4_lvds_connector *mdp4_lvds_connector =
  38. to_mdp4_lvds_connector(connector);
  39. struct drm_panel *panel = mdp4_lvds_connector->panel;
  40. if (panel)
  41. drm_panel_detach(panel);
  42. drm_connector_unregister(connector);
  43. drm_connector_cleanup(connector);
  44. kfree(mdp4_lvds_connector);
  45. }
  46. static int mdp4_lvds_connector_get_modes(struct drm_connector *connector)
  47. {
  48. struct mdp4_lvds_connector *mdp4_lvds_connector =
  49. to_mdp4_lvds_connector(connector);
  50. struct drm_panel *panel = mdp4_lvds_connector->panel;
  51. int ret = 0;
  52. if (panel)
  53. ret = panel->funcs->get_modes(panel);
  54. return ret;
  55. }
  56. static int mdp4_lvds_connector_mode_valid(struct drm_connector *connector,
  57. struct drm_display_mode *mode)
  58. {
  59. struct mdp4_lvds_connector *mdp4_lvds_connector =
  60. to_mdp4_lvds_connector(connector);
  61. struct drm_encoder *encoder = mdp4_lvds_connector->encoder;
  62. long actual, requested;
  63. requested = 1000 * mode->clock;
  64. actual = mdp4_lcdc_round_pixclk(encoder, requested);
  65. DBG("requested=%ld, actual=%ld", requested, actual);
  66. if (actual != requested)
  67. return MODE_CLOCK_RANGE;
  68. return MODE_OK;
  69. }
  70. static struct drm_encoder *
  71. mdp4_lvds_connector_best_encoder(struct drm_connector *connector)
  72. {
  73. struct mdp4_lvds_connector *mdp4_lvds_connector =
  74. to_mdp4_lvds_connector(connector);
  75. return mdp4_lvds_connector->encoder;
  76. }
  77. static const struct drm_connector_funcs mdp4_lvds_connector_funcs = {
  78. .dpms = drm_atomic_helper_connector_dpms,
  79. .detect = mdp4_lvds_connector_detect,
  80. .fill_modes = drm_helper_probe_single_connector_modes,
  81. .destroy = mdp4_lvds_connector_destroy,
  82. .reset = drm_atomic_helper_connector_reset,
  83. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  84. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  85. };
  86. static const struct drm_connector_helper_funcs mdp4_lvds_connector_helper_funcs = {
  87. .get_modes = mdp4_lvds_connector_get_modes,
  88. .mode_valid = mdp4_lvds_connector_mode_valid,
  89. .best_encoder = mdp4_lvds_connector_best_encoder,
  90. };
  91. /* initialize connector */
  92. struct drm_connector *mdp4_lvds_connector_init(struct drm_device *dev,
  93. struct drm_panel *panel, struct drm_encoder *encoder)
  94. {
  95. struct drm_connector *connector = NULL;
  96. struct mdp4_lvds_connector *mdp4_lvds_connector;
  97. int ret;
  98. mdp4_lvds_connector = kzalloc(sizeof(*mdp4_lvds_connector), GFP_KERNEL);
  99. if (!mdp4_lvds_connector) {
  100. ret = -ENOMEM;
  101. goto fail;
  102. }
  103. mdp4_lvds_connector->encoder = encoder;
  104. mdp4_lvds_connector->panel = panel;
  105. connector = &mdp4_lvds_connector->base;
  106. drm_connector_init(dev, connector, &mdp4_lvds_connector_funcs,
  107. DRM_MODE_CONNECTOR_LVDS);
  108. drm_connector_helper_add(connector, &mdp4_lvds_connector_helper_funcs);
  109. connector->polled = 0;
  110. connector->interlace_allowed = 0;
  111. connector->doublescan_allowed = 0;
  112. drm_connector_register(connector);
  113. drm_mode_connector_attach_encoder(connector, encoder);
  114. if (panel)
  115. drm_panel_attach(panel, connector);
  116. return connector;
  117. fail:
  118. if (connector)
  119. mdp4_lvds_connector_destroy(connector);
  120. return ERR_PTR(ret);
  121. }