edp_connector.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  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 "drm/drm_edid.h"
  14. #include "msm_kms.h"
  15. #include "edp.h"
  16. struct edp_connector {
  17. struct drm_connector base;
  18. struct msm_edp *edp;
  19. };
  20. #define to_edp_connector(x) container_of(x, struct edp_connector, base)
  21. static enum drm_connector_status edp_connector_detect(
  22. struct drm_connector *connector, bool force)
  23. {
  24. struct edp_connector *edp_connector = to_edp_connector(connector);
  25. struct msm_edp *edp = edp_connector->edp;
  26. DBG("");
  27. return msm_edp_ctrl_panel_connected(edp->ctrl) ?
  28. connector_status_connected : connector_status_disconnected;
  29. }
  30. static void edp_connector_destroy(struct drm_connector *connector)
  31. {
  32. struct edp_connector *edp_connector = to_edp_connector(connector);
  33. DBG("");
  34. drm_connector_unregister(connector);
  35. drm_connector_cleanup(connector);
  36. kfree(edp_connector);
  37. }
  38. static int edp_connector_get_modes(struct drm_connector *connector)
  39. {
  40. struct edp_connector *edp_connector = to_edp_connector(connector);
  41. struct msm_edp *edp = edp_connector->edp;
  42. struct edid *drm_edid = NULL;
  43. int ret = 0;
  44. DBG("");
  45. ret = msm_edp_ctrl_get_panel_info(edp->ctrl, connector, &drm_edid);
  46. if (ret)
  47. return ret;
  48. drm_mode_connector_update_edid_property(connector, drm_edid);
  49. if (drm_edid)
  50. ret = drm_add_edid_modes(connector, drm_edid);
  51. return ret;
  52. }
  53. static int edp_connector_mode_valid(struct drm_connector *connector,
  54. struct drm_display_mode *mode)
  55. {
  56. struct edp_connector *edp_connector = to_edp_connector(connector);
  57. struct msm_edp *edp = edp_connector->edp;
  58. struct msm_drm_private *priv = connector->dev->dev_private;
  59. struct msm_kms *kms = priv->kms;
  60. long actual, requested;
  61. requested = 1000 * mode->clock;
  62. actual = kms->funcs->round_pixclk(kms,
  63. requested, edp_connector->edp->encoder);
  64. DBG("requested=%ld, actual=%ld", requested, actual);
  65. if (actual != requested)
  66. return MODE_CLOCK_RANGE;
  67. if (!msm_edp_ctrl_pixel_clock_valid(
  68. edp->ctrl, mode->clock, NULL, NULL))
  69. return MODE_CLOCK_RANGE;
  70. /* Invalidate all modes if color format is not supported */
  71. if (connector->display_info.bpc > 8)
  72. return MODE_BAD;
  73. return MODE_OK;
  74. }
  75. static struct drm_encoder *
  76. edp_connector_best_encoder(struct drm_connector *connector)
  77. {
  78. struct edp_connector *edp_connector = to_edp_connector(connector);
  79. DBG("");
  80. return edp_connector->edp->encoder;
  81. }
  82. static const struct drm_connector_funcs edp_connector_funcs = {
  83. .dpms = drm_atomic_helper_connector_dpms,
  84. .detect = edp_connector_detect,
  85. .fill_modes = drm_helper_probe_single_connector_modes,
  86. .destroy = edp_connector_destroy,
  87. .reset = drm_atomic_helper_connector_reset,
  88. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  89. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  90. };
  91. static const struct drm_connector_helper_funcs edp_connector_helper_funcs = {
  92. .get_modes = edp_connector_get_modes,
  93. .mode_valid = edp_connector_mode_valid,
  94. .best_encoder = edp_connector_best_encoder,
  95. };
  96. /* initialize connector */
  97. struct drm_connector *msm_edp_connector_init(struct msm_edp *edp)
  98. {
  99. struct drm_connector *connector = NULL;
  100. struct edp_connector *edp_connector;
  101. int ret;
  102. edp_connector = kzalloc(sizeof(*edp_connector), GFP_KERNEL);
  103. if (!edp_connector) {
  104. ret = -ENOMEM;
  105. goto fail;
  106. }
  107. edp_connector->edp = edp;
  108. connector = &edp_connector->base;
  109. ret = drm_connector_init(edp->dev, connector, &edp_connector_funcs,
  110. DRM_MODE_CONNECTOR_eDP);
  111. if (ret)
  112. goto fail;
  113. drm_connector_helper_add(connector, &edp_connector_helper_funcs);
  114. /* We don't support HPD, so only poll status until connected. */
  115. connector->polled = DRM_CONNECTOR_POLL_CONNECT;
  116. /* Display driver doesn't support interlace now. */
  117. connector->interlace_allowed = false;
  118. connector->doublescan_allowed = false;
  119. ret = drm_connector_register(connector);
  120. if (ret)
  121. goto fail;
  122. drm_mode_connector_attach_encoder(connector, edp->encoder);
  123. return connector;
  124. fail:
  125. if (connector)
  126. edp_connector_destroy(connector);
  127. return ERR_PTR(ret);
  128. }