omap_encoder.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * drivers/gpu/drm/omapdrm/omap_encoder.c
  3. *
  4. * Copyright (C) 2011 Texas Instruments
  5. * Author: Rob Clark <rob@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "omap_drv.h"
  20. #include "drm_crtc.h"
  21. #include "drm_crtc_helper.h"
  22. #include <linux/list.h>
  23. /*
  24. * encoder funcs
  25. */
  26. #define to_omap_encoder(x) container_of(x, struct omap_encoder, base)
  27. /* The encoder and connector both map to same dssdev.. the encoder
  28. * handles the 'active' parts, ie. anything the modifies the state
  29. * of the hw, and the connector handles the 'read-only' parts, like
  30. * detecting connection and reading edid.
  31. */
  32. struct omap_encoder {
  33. struct drm_encoder base;
  34. struct omap_dss_device *dssdev;
  35. };
  36. static void omap_encoder_destroy(struct drm_encoder *encoder)
  37. {
  38. struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
  39. drm_encoder_cleanup(encoder);
  40. kfree(omap_encoder);
  41. }
  42. static const struct drm_encoder_funcs omap_encoder_funcs = {
  43. .destroy = omap_encoder_destroy,
  44. };
  45. /*
  46. * The CRTC drm_crtc_helper_set_mode() doesn't really give us the right
  47. * order.. the easiest way to work around this for now is to make all
  48. * the encoder-helper's no-op's and have the omap_crtc code take care
  49. * of the sequencing and call us in the right points.
  50. *
  51. * Eventually to handle connecting CRTCs to different encoders properly,
  52. * either the CRTC helpers need to change or we need to replace
  53. * drm_crtc_helper_set_mode(), but lets wait until atomic-modeset for
  54. * that.
  55. */
  56. static void omap_encoder_dpms(struct drm_encoder *encoder, int mode)
  57. {
  58. }
  59. static bool omap_encoder_mode_fixup(struct drm_encoder *encoder,
  60. const struct drm_display_mode *mode,
  61. struct drm_display_mode *adjusted_mode)
  62. {
  63. return true;
  64. }
  65. static void omap_encoder_mode_set(struct drm_encoder *encoder,
  66. struct drm_display_mode *mode,
  67. struct drm_display_mode *adjusted_mode)
  68. {
  69. }
  70. static void omap_encoder_prepare(struct drm_encoder *encoder)
  71. {
  72. }
  73. static void omap_encoder_commit(struct drm_encoder *encoder)
  74. {
  75. }
  76. static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs = {
  77. .dpms = omap_encoder_dpms,
  78. .mode_fixup = omap_encoder_mode_fixup,
  79. .mode_set = omap_encoder_mode_set,
  80. .prepare = omap_encoder_prepare,
  81. .commit = omap_encoder_commit,
  82. };
  83. /*
  84. * Instead of relying on the helpers for modeset, the omap_crtc code
  85. * calls these functions in the proper sequence.
  86. */
  87. int omap_encoder_set_enabled(struct drm_encoder *encoder, bool enabled)
  88. {
  89. struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
  90. struct omap_dss_device *dssdev = omap_encoder->dssdev;
  91. struct omap_dss_driver *dssdrv = dssdev->driver;
  92. if (enabled) {
  93. return dssdrv->enable(dssdev);
  94. } else {
  95. dssdrv->disable(dssdev);
  96. return 0;
  97. }
  98. }
  99. int omap_encoder_update(struct drm_encoder *encoder,
  100. struct omap_overlay_manager *mgr,
  101. struct omap_video_timings *timings)
  102. {
  103. struct drm_device *dev = encoder->dev;
  104. struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
  105. struct omap_dss_device *dssdev = omap_encoder->dssdev;
  106. struct omap_dss_driver *dssdrv = dssdev->driver;
  107. int ret;
  108. dssdev->output->manager = mgr;
  109. ret = dssdrv->check_timings(dssdev, timings);
  110. if (ret) {
  111. dev_err(dev->dev, "could not set timings: %d\n", ret);
  112. return ret;
  113. }
  114. dssdrv->set_timings(dssdev, timings);
  115. return 0;
  116. }
  117. /* initialize encoder */
  118. struct drm_encoder *omap_encoder_init(struct drm_device *dev,
  119. struct omap_dss_device *dssdev)
  120. {
  121. struct drm_encoder *encoder = NULL;
  122. struct omap_encoder *omap_encoder;
  123. omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL);
  124. if (!omap_encoder) {
  125. dev_err(dev->dev, "could not allocate encoder\n");
  126. goto fail;
  127. }
  128. omap_encoder->dssdev = dssdev;
  129. encoder = &omap_encoder->base;
  130. drm_encoder_init(dev, encoder, &omap_encoder_funcs,
  131. DRM_MODE_ENCODER_TMDS);
  132. drm_encoder_helper_add(encoder, &omap_encoder_helper_funcs);
  133. return encoder;
  134. fail:
  135. if (encoder)
  136. omap_encoder_destroy(encoder);
  137. return NULL;
  138. }