amdgpu_encoders.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include <drm/drmP.h>
  27. #include <drm/drm_crtc_helper.h>
  28. #include <drm/amdgpu_drm.h>
  29. #include "amdgpu.h"
  30. #include "amdgpu_connectors.h"
  31. #include "atom.h"
  32. #include "atombios_encoders.h"
  33. void
  34. amdgpu_link_encoder_connector(struct drm_device *dev)
  35. {
  36. struct amdgpu_device *adev = dev->dev_private;
  37. struct drm_connector *connector;
  38. struct amdgpu_connector *amdgpu_connector;
  39. struct drm_encoder *encoder;
  40. struct amdgpu_encoder *amdgpu_encoder;
  41. /* walk the list and link encoders to connectors */
  42. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  43. amdgpu_connector = to_amdgpu_connector(connector);
  44. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  45. amdgpu_encoder = to_amdgpu_encoder(encoder);
  46. if (amdgpu_encoder->devices & amdgpu_connector->devices) {
  47. drm_mode_connector_attach_encoder(connector, encoder);
  48. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  49. amdgpu_atombios_encoder_init_backlight(amdgpu_encoder, connector);
  50. adev->mode_info.bl_encoder = amdgpu_encoder;
  51. }
  52. }
  53. }
  54. }
  55. }
  56. void amdgpu_encoder_set_active_device(struct drm_encoder *encoder)
  57. {
  58. struct drm_device *dev = encoder->dev;
  59. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  60. struct drm_connector *connector;
  61. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  62. if (connector->encoder == encoder) {
  63. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  64. amdgpu_encoder->active_device = amdgpu_encoder->devices & amdgpu_connector->devices;
  65. DRM_DEBUG_KMS("setting active device to %08x from %08x %08x for encoder %d\n",
  66. amdgpu_encoder->active_device, amdgpu_encoder->devices,
  67. amdgpu_connector->devices, encoder->encoder_type);
  68. }
  69. }
  70. }
  71. struct drm_connector *
  72. amdgpu_get_connector_for_encoder(struct drm_encoder *encoder)
  73. {
  74. struct drm_device *dev = encoder->dev;
  75. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  76. struct drm_connector *connector;
  77. struct amdgpu_connector *amdgpu_connector;
  78. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  79. amdgpu_connector = to_amdgpu_connector(connector);
  80. if (amdgpu_encoder->active_device & amdgpu_connector->devices)
  81. return connector;
  82. }
  83. return NULL;
  84. }
  85. struct drm_connector *
  86. amdgpu_get_connector_for_encoder_init(struct drm_encoder *encoder)
  87. {
  88. struct drm_device *dev = encoder->dev;
  89. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  90. struct drm_connector *connector;
  91. struct amdgpu_connector *amdgpu_connector;
  92. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  93. amdgpu_connector = to_amdgpu_connector(connector);
  94. if (amdgpu_encoder->devices & amdgpu_connector->devices)
  95. return connector;
  96. }
  97. return NULL;
  98. }
  99. struct drm_encoder *amdgpu_get_external_encoder(struct drm_encoder *encoder)
  100. {
  101. struct drm_device *dev = encoder->dev;
  102. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  103. struct drm_encoder *other_encoder;
  104. struct amdgpu_encoder *other_amdgpu_encoder;
  105. if (amdgpu_encoder->is_ext_encoder)
  106. return NULL;
  107. list_for_each_entry(other_encoder, &dev->mode_config.encoder_list, head) {
  108. if (other_encoder == encoder)
  109. continue;
  110. other_amdgpu_encoder = to_amdgpu_encoder(other_encoder);
  111. if (other_amdgpu_encoder->is_ext_encoder &&
  112. (amdgpu_encoder->devices & other_amdgpu_encoder->devices))
  113. return other_encoder;
  114. }
  115. return NULL;
  116. }
  117. u16 amdgpu_encoder_get_dp_bridge_encoder_id(struct drm_encoder *encoder)
  118. {
  119. struct drm_encoder *other_encoder = amdgpu_get_external_encoder(encoder);
  120. if (other_encoder) {
  121. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(other_encoder);
  122. switch (amdgpu_encoder->encoder_id) {
  123. case ENCODER_OBJECT_ID_TRAVIS:
  124. case ENCODER_OBJECT_ID_NUTMEG:
  125. return amdgpu_encoder->encoder_id;
  126. default:
  127. return ENCODER_OBJECT_ID_NONE;
  128. }
  129. }
  130. return ENCODER_OBJECT_ID_NONE;
  131. }
  132. void amdgpu_panel_mode_fixup(struct drm_encoder *encoder,
  133. struct drm_display_mode *adjusted_mode)
  134. {
  135. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  136. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  137. unsigned hblank = native_mode->htotal - native_mode->hdisplay;
  138. unsigned vblank = native_mode->vtotal - native_mode->vdisplay;
  139. unsigned hover = native_mode->hsync_start - native_mode->hdisplay;
  140. unsigned vover = native_mode->vsync_start - native_mode->vdisplay;
  141. unsigned hsync_width = native_mode->hsync_end - native_mode->hsync_start;
  142. unsigned vsync_width = native_mode->vsync_end - native_mode->vsync_start;
  143. adjusted_mode->clock = native_mode->clock;
  144. adjusted_mode->flags = native_mode->flags;
  145. adjusted_mode->hdisplay = native_mode->hdisplay;
  146. adjusted_mode->vdisplay = native_mode->vdisplay;
  147. adjusted_mode->htotal = native_mode->hdisplay + hblank;
  148. adjusted_mode->hsync_start = native_mode->hdisplay + hover;
  149. adjusted_mode->hsync_end = adjusted_mode->hsync_start + hsync_width;
  150. adjusted_mode->vtotal = native_mode->vdisplay + vblank;
  151. adjusted_mode->vsync_start = native_mode->vdisplay + vover;
  152. adjusted_mode->vsync_end = adjusted_mode->vsync_start + vsync_width;
  153. drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
  154. adjusted_mode->crtc_hdisplay = native_mode->hdisplay;
  155. adjusted_mode->crtc_vdisplay = native_mode->vdisplay;
  156. adjusted_mode->crtc_htotal = adjusted_mode->crtc_hdisplay + hblank;
  157. adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hdisplay + hover;
  158. adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + hsync_width;
  159. adjusted_mode->crtc_vtotal = adjusted_mode->crtc_vdisplay + vblank;
  160. adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + vover;
  161. adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + vsync_width;
  162. }
  163. bool amdgpu_dig_monitor_is_duallink(struct drm_encoder *encoder,
  164. u32 pixel_clock)
  165. {
  166. struct drm_connector *connector;
  167. struct amdgpu_connector *amdgpu_connector;
  168. struct amdgpu_connector_atom_dig *dig_connector;
  169. connector = amdgpu_get_connector_for_encoder(encoder);
  170. /* if we don't have an active device yet, just use one of
  171. * the connectors tied to the encoder.
  172. */
  173. if (!connector)
  174. connector = amdgpu_get_connector_for_encoder_init(encoder);
  175. amdgpu_connector = to_amdgpu_connector(connector);
  176. switch (connector->connector_type) {
  177. case DRM_MODE_CONNECTOR_DVII:
  178. case DRM_MODE_CONNECTOR_HDMIB:
  179. if (amdgpu_connector->use_digital) {
  180. /* HDMI 1.3 supports up to 340 Mhz over single link */
  181. if (drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  182. if (pixel_clock > 340000)
  183. return true;
  184. else
  185. return false;
  186. } else {
  187. if (pixel_clock > 165000)
  188. return true;
  189. else
  190. return false;
  191. }
  192. } else
  193. return false;
  194. case DRM_MODE_CONNECTOR_DVID:
  195. case DRM_MODE_CONNECTOR_HDMIA:
  196. case DRM_MODE_CONNECTOR_DisplayPort:
  197. dig_connector = amdgpu_connector->con_priv;
  198. if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
  199. (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
  200. return false;
  201. else {
  202. /* HDMI 1.3 supports up to 340 Mhz over single link */
  203. if (drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  204. if (pixel_clock > 340000)
  205. return true;
  206. else
  207. return false;
  208. } else {
  209. if (pixel_clock > 165000)
  210. return true;
  211. else
  212. return false;
  213. }
  214. }
  215. default:
  216. return false;
  217. }
  218. }