amdgpu_encoders.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 "amdgpu_display.h"
  32. #include "atom.h"
  33. #include "atombios_encoders.h"
  34. void
  35. amdgpu_link_encoder_connector(struct drm_device *dev)
  36. {
  37. struct amdgpu_device *adev = dev->dev_private;
  38. struct drm_connector *connector;
  39. struct amdgpu_connector *amdgpu_connector;
  40. struct drm_encoder *encoder;
  41. struct amdgpu_encoder *amdgpu_encoder;
  42. /* walk the list and link encoders to connectors */
  43. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  44. amdgpu_connector = to_amdgpu_connector(connector);
  45. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  46. amdgpu_encoder = to_amdgpu_encoder(encoder);
  47. if (amdgpu_encoder->devices & amdgpu_connector->devices) {
  48. drm_connector_attach_encoder(connector, encoder);
  49. if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  50. amdgpu_atombios_encoder_init_backlight(amdgpu_encoder, connector);
  51. adev->mode_info.bl_encoder = amdgpu_encoder;
  52. }
  53. }
  54. }
  55. }
  56. }
  57. void amdgpu_encoder_set_active_device(struct drm_encoder *encoder)
  58. {
  59. struct drm_device *dev = encoder->dev;
  60. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  61. struct drm_connector *connector;
  62. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  63. if (connector->encoder == encoder) {
  64. struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
  65. amdgpu_encoder->active_device = amdgpu_encoder->devices & amdgpu_connector->devices;
  66. DRM_DEBUG_KMS("setting active device to %08x from %08x %08x for encoder %d\n",
  67. amdgpu_encoder->active_device, amdgpu_encoder->devices,
  68. amdgpu_connector->devices, encoder->encoder_type);
  69. }
  70. }
  71. }
  72. struct drm_connector *
  73. amdgpu_get_connector_for_encoder(struct drm_encoder *encoder)
  74. {
  75. struct drm_device *dev = encoder->dev;
  76. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  77. struct drm_connector *connector;
  78. struct amdgpu_connector *amdgpu_connector;
  79. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  80. amdgpu_connector = to_amdgpu_connector(connector);
  81. if (amdgpu_encoder->active_device & amdgpu_connector->devices)
  82. return connector;
  83. }
  84. return NULL;
  85. }
  86. struct drm_connector *
  87. amdgpu_get_connector_for_encoder_init(struct drm_encoder *encoder)
  88. {
  89. struct drm_device *dev = encoder->dev;
  90. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  91. struct drm_connector *connector;
  92. struct amdgpu_connector *amdgpu_connector;
  93. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  94. amdgpu_connector = to_amdgpu_connector(connector);
  95. if (amdgpu_encoder->devices & amdgpu_connector->devices)
  96. return connector;
  97. }
  98. return NULL;
  99. }
  100. struct drm_encoder *amdgpu_get_external_encoder(struct drm_encoder *encoder)
  101. {
  102. struct drm_device *dev = encoder->dev;
  103. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  104. struct drm_encoder *other_encoder;
  105. struct amdgpu_encoder *other_amdgpu_encoder;
  106. if (amdgpu_encoder->is_ext_encoder)
  107. return NULL;
  108. list_for_each_entry(other_encoder, &dev->mode_config.encoder_list, head) {
  109. if (other_encoder == encoder)
  110. continue;
  111. other_amdgpu_encoder = to_amdgpu_encoder(other_encoder);
  112. if (other_amdgpu_encoder->is_ext_encoder &&
  113. (amdgpu_encoder->devices & other_amdgpu_encoder->devices))
  114. return other_encoder;
  115. }
  116. return NULL;
  117. }
  118. u16 amdgpu_encoder_get_dp_bridge_encoder_id(struct drm_encoder *encoder)
  119. {
  120. struct drm_encoder *other_encoder = amdgpu_get_external_encoder(encoder);
  121. if (other_encoder) {
  122. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(other_encoder);
  123. switch (amdgpu_encoder->encoder_id) {
  124. case ENCODER_OBJECT_ID_TRAVIS:
  125. case ENCODER_OBJECT_ID_NUTMEG:
  126. return amdgpu_encoder->encoder_id;
  127. default:
  128. return ENCODER_OBJECT_ID_NONE;
  129. }
  130. }
  131. return ENCODER_OBJECT_ID_NONE;
  132. }
  133. void amdgpu_panel_mode_fixup(struct drm_encoder *encoder,
  134. struct drm_display_mode *adjusted_mode)
  135. {
  136. struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
  137. struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
  138. unsigned hblank = native_mode->htotal - native_mode->hdisplay;
  139. unsigned vblank = native_mode->vtotal - native_mode->vdisplay;
  140. unsigned hover = native_mode->hsync_start - native_mode->hdisplay;
  141. unsigned vover = native_mode->vsync_start - native_mode->vdisplay;
  142. unsigned hsync_width = native_mode->hsync_end - native_mode->hsync_start;
  143. unsigned vsync_width = native_mode->vsync_end - native_mode->vsync_start;
  144. adjusted_mode->clock = native_mode->clock;
  145. adjusted_mode->flags = native_mode->flags;
  146. adjusted_mode->hdisplay = native_mode->hdisplay;
  147. adjusted_mode->vdisplay = native_mode->vdisplay;
  148. adjusted_mode->htotal = native_mode->hdisplay + hblank;
  149. adjusted_mode->hsync_start = native_mode->hdisplay + hover;
  150. adjusted_mode->hsync_end = adjusted_mode->hsync_start + hsync_width;
  151. adjusted_mode->vtotal = native_mode->vdisplay + vblank;
  152. adjusted_mode->vsync_start = native_mode->vdisplay + vover;
  153. adjusted_mode->vsync_end = adjusted_mode->vsync_start + vsync_width;
  154. drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
  155. adjusted_mode->crtc_hdisplay = native_mode->hdisplay;
  156. adjusted_mode->crtc_vdisplay = native_mode->vdisplay;
  157. adjusted_mode->crtc_htotal = adjusted_mode->crtc_hdisplay + hblank;
  158. adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hdisplay + hover;
  159. adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + hsync_width;
  160. adjusted_mode->crtc_vtotal = adjusted_mode->crtc_vdisplay + vblank;
  161. adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + vover;
  162. adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + vsync_width;
  163. }
  164. bool amdgpu_dig_monitor_is_duallink(struct drm_encoder *encoder,
  165. u32 pixel_clock)
  166. {
  167. struct drm_connector *connector;
  168. struct amdgpu_connector *amdgpu_connector;
  169. struct amdgpu_connector_atom_dig *dig_connector;
  170. connector = amdgpu_get_connector_for_encoder(encoder);
  171. /* if we don't have an active device yet, just use one of
  172. * the connectors tied to the encoder.
  173. */
  174. if (!connector)
  175. connector = amdgpu_get_connector_for_encoder_init(encoder);
  176. amdgpu_connector = to_amdgpu_connector(connector);
  177. switch (connector->connector_type) {
  178. case DRM_MODE_CONNECTOR_DVII:
  179. case DRM_MODE_CONNECTOR_HDMIB:
  180. if (amdgpu_connector->use_digital) {
  181. /* HDMI 1.3 supports up to 340 Mhz over single link */
  182. if (drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  183. if (pixel_clock > 340000)
  184. return true;
  185. else
  186. return false;
  187. } else {
  188. if (pixel_clock > 165000)
  189. return true;
  190. else
  191. return false;
  192. }
  193. } else
  194. return false;
  195. case DRM_MODE_CONNECTOR_DVID:
  196. case DRM_MODE_CONNECTOR_HDMIA:
  197. case DRM_MODE_CONNECTOR_DisplayPort:
  198. dig_connector = amdgpu_connector->con_priv;
  199. if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
  200. (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
  201. return false;
  202. else {
  203. /* HDMI 1.3 supports up to 340 Mhz over single link */
  204. if (drm_detect_hdmi_monitor(amdgpu_connector_edid(connector))) {
  205. if (pixel_clock > 340000)
  206. return true;
  207. else
  208. return false;
  209. } else {
  210. if (pixel_clock > 165000)
  211. return true;
  212. else
  213. return false;
  214. }
  215. }
  216. default:
  217. return false;
  218. }
  219. }