radeon_encoders.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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/radeon_drm.h>
  29. #include "radeon.h"
  30. #include "atom.h"
  31. extern void
  32. radeon_legacy_backlight_init(struct radeon_encoder *radeon_encoder,
  33. struct drm_connector *drm_connector);
  34. extern void
  35. radeon_atom_backlight_init(struct radeon_encoder *radeon_encoder,
  36. struct drm_connector *drm_connector);
  37. static uint32_t radeon_encoder_clones(struct drm_encoder *encoder)
  38. {
  39. struct drm_device *dev = encoder->dev;
  40. struct radeon_device *rdev = dev->dev_private;
  41. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  42. struct drm_encoder *clone_encoder;
  43. uint32_t index_mask = 0;
  44. int count;
  45. /* DIG routing gets problematic */
  46. if (rdev->family >= CHIP_R600)
  47. return index_mask;
  48. /* LVDS/TV are too wacky */
  49. if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
  50. return index_mask;
  51. /* DVO requires 2x ppll clocks depending on tmds chip */
  52. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT)
  53. return index_mask;
  54. count = -1;
  55. list_for_each_entry(clone_encoder, &dev->mode_config.encoder_list, head) {
  56. struct radeon_encoder *radeon_clone = to_radeon_encoder(clone_encoder);
  57. count++;
  58. if (clone_encoder == encoder)
  59. continue;
  60. if (radeon_clone->devices & (ATOM_DEVICE_LCD_SUPPORT))
  61. continue;
  62. if (radeon_clone->devices & ATOM_DEVICE_DFP2_SUPPORT)
  63. continue;
  64. else
  65. index_mask |= (1 << count);
  66. }
  67. return index_mask;
  68. }
  69. void radeon_setup_encoder_clones(struct drm_device *dev)
  70. {
  71. struct drm_encoder *encoder;
  72. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  73. encoder->possible_clones = radeon_encoder_clones(encoder);
  74. }
  75. }
  76. uint32_t
  77. radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device, uint8_t dac)
  78. {
  79. struct radeon_device *rdev = dev->dev_private;
  80. uint32_t ret = 0;
  81. switch (supported_device) {
  82. case ATOM_DEVICE_CRT1_SUPPORT:
  83. case ATOM_DEVICE_TV1_SUPPORT:
  84. case ATOM_DEVICE_TV2_SUPPORT:
  85. case ATOM_DEVICE_CRT2_SUPPORT:
  86. case ATOM_DEVICE_CV_SUPPORT:
  87. switch (dac) {
  88. case 1: /* dac a */
  89. if ((rdev->family == CHIP_RS300) ||
  90. (rdev->family == CHIP_RS400) ||
  91. (rdev->family == CHIP_RS480))
  92. ret = ENCODER_INTERNAL_DAC2_ENUM_ID1;
  93. else if (ASIC_IS_AVIVO(rdev))
  94. ret = ENCODER_INTERNAL_KLDSCP_DAC1_ENUM_ID1;
  95. else
  96. ret = ENCODER_INTERNAL_DAC1_ENUM_ID1;
  97. break;
  98. case 2: /* dac b */
  99. if (ASIC_IS_AVIVO(rdev))
  100. ret = ENCODER_INTERNAL_KLDSCP_DAC2_ENUM_ID1;
  101. else {
  102. /*if (rdev->family == CHIP_R200)
  103. ret = ENCODER_INTERNAL_DVO1_ENUM_ID1;
  104. else*/
  105. ret = ENCODER_INTERNAL_DAC2_ENUM_ID1;
  106. }
  107. break;
  108. case 3: /* external dac */
  109. if (ASIC_IS_AVIVO(rdev))
  110. ret = ENCODER_INTERNAL_KLDSCP_DVO1_ENUM_ID1;
  111. else
  112. ret = ENCODER_INTERNAL_DVO1_ENUM_ID1;
  113. break;
  114. }
  115. break;
  116. case ATOM_DEVICE_LCD1_SUPPORT:
  117. if (ASIC_IS_AVIVO(rdev))
  118. ret = ENCODER_INTERNAL_LVTM1_ENUM_ID1;
  119. else
  120. ret = ENCODER_INTERNAL_LVDS_ENUM_ID1;
  121. break;
  122. case ATOM_DEVICE_DFP1_SUPPORT:
  123. if ((rdev->family == CHIP_RS300) ||
  124. (rdev->family == CHIP_RS400) ||
  125. (rdev->family == CHIP_RS480))
  126. ret = ENCODER_INTERNAL_DVO1_ENUM_ID1;
  127. else if (ASIC_IS_AVIVO(rdev))
  128. ret = ENCODER_INTERNAL_KLDSCP_TMDS1_ENUM_ID1;
  129. else
  130. ret = ENCODER_INTERNAL_TMDS1_ENUM_ID1;
  131. break;
  132. case ATOM_DEVICE_LCD2_SUPPORT:
  133. case ATOM_DEVICE_DFP2_SUPPORT:
  134. if ((rdev->family == CHIP_RS600) ||
  135. (rdev->family == CHIP_RS690) ||
  136. (rdev->family == CHIP_RS740))
  137. ret = ENCODER_INTERNAL_DDI_ENUM_ID1;
  138. else if (ASIC_IS_AVIVO(rdev))
  139. ret = ENCODER_INTERNAL_KLDSCP_DVO1_ENUM_ID1;
  140. else
  141. ret = ENCODER_INTERNAL_DVO1_ENUM_ID1;
  142. break;
  143. case ATOM_DEVICE_DFP3_SUPPORT:
  144. ret = ENCODER_INTERNAL_LVTM1_ENUM_ID1;
  145. break;
  146. }
  147. return ret;
  148. }
  149. static void radeon_encoder_add_backlight(struct radeon_encoder *radeon_encoder,
  150. struct drm_connector *connector)
  151. {
  152. struct drm_device *dev = radeon_encoder->base.dev;
  153. struct radeon_device *rdev = dev->dev_private;
  154. bool use_bl = false;
  155. if (!(radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)))
  156. return;
  157. if (radeon_backlight == 0) {
  158. return;
  159. } else if (radeon_backlight == 1) {
  160. use_bl = true;
  161. } else if (radeon_backlight == -1) {
  162. /* Quirks */
  163. /* Amilo Xi 2550 only works with acpi bl */
  164. if ((rdev->pdev->device == 0x9583) &&
  165. (rdev->pdev->subsystem_vendor == 0x1734) &&
  166. (rdev->pdev->subsystem_device == 0x1107))
  167. use_bl = false;
  168. /* Older PPC macs use on-GPU backlight controller */
  169. #ifndef CONFIG_PPC_PMAC
  170. /* disable native backlight control on older asics */
  171. else if (rdev->family < CHIP_R600)
  172. use_bl = false;
  173. #endif
  174. else
  175. use_bl = true;
  176. }
  177. if (use_bl) {
  178. if (rdev->is_atom_bios)
  179. radeon_atom_backlight_init(radeon_encoder, connector);
  180. else
  181. radeon_legacy_backlight_init(radeon_encoder, connector);
  182. }
  183. }
  184. void
  185. radeon_link_encoder_connector(struct drm_device *dev)
  186. {
  187. struct drm_connector *connector;
  188. struct radeon_connector *radeon_connector;
  189. struct drm_encoder *encoder;
  190. struct radeon_encoder *radeon_encoder;
  191. /* walk the list and link encoders to connectors */
  192. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  193. radeon_connector = to_radeon_connector(connector);
  194. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  195. radeon_encoder = to_radeon_encoder(encoder);
  196. if (radeon_encoder->devices & radeon_connector->devices) {
  197. drm_mode_connector_attach_encoder(connector, encoder);
  198. if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
  199. radeon_encoder_add_backlight(radeon_encoder, connector);
  200. }
  201. }
  202. }
  203. }
  204. void radeon_encoder_set_active_device(struct drm_encoder *encoder)
  205. {
  206. struct drm_device *dev = encoder->dev;
  207. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  208. struct drm_connector *connector;
  209. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  210. if (connector->encoder == encoder) {
  211. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  212. radeon_encoder->active_device = radeon_encoder->devices & radeon_connector->devices;
  213. DRM_DEBUG_KMS("setting active device to %08x from %08x %08x for encoder %d\n",
  214. radeon_encoder->active_device, radeon_encoder->devices,
  215. radeon_connector->devices, encoder->encoder_type);
  216. }
  217. }
  218. }
  219. struct drm_connector *
  220. radeon_get_connector_for_encoder(struct drm_encoder *encoder)
  221. {
  222. struct drm_device *dev = encoder->dev;
  223. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  224. struct drm_connector *connector;
  225. struct radeon_connector *radeon_connector;
  226. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  227. radeon_connector = to_radeon_connector(connector);
  228. if (radeon_encoder->is_mst_encoder) {
  229. struct radeon_encoder_mst *mst_enc;
  230. if (!radeon_connector->is_mst_connector)
  231. continue;
  232. mst_enc = radeon_encoder->enc_priv;
  233. if (mst_enc->connector == radeon_connector->mst_port)
  234. return connector;
  235. } else if (radeon_encoder->active_device & radeon_connector->devices)
  236. return connector;
  237. }
  238. return NULL;
  239. }
  240. struct drm_connector *
  241. radeon_get_connector_for_encoder_init(struct drm_encoder *encoder)
  242. {
  243. struct drm_device *dev = encoder->dev;
  244. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  245. struct drm_connector *connector;
  246. struct radeon_connector *radeon_connector;
  247. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  248. radeon_connector = to_radeon_connector(connector);
  249. if (radeon_encoder->devices & radeon_connector->devices)
  250. return connector;
  251. }
  252. return NULL;
  253. }
  254. struct drm_encoder *radeon_get_external_encoder(struct drm_encoder *encoder)
  255. {
  256. struct drm_device *dev = encoder->dev;
  257. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  258. struct drm_encoder *other_encoder;
  259. struct radeon_encoder *other_radeon_encoder;
  260. if (radeon_encoder->is_ext_encoder)
  261. return NULL;
  262. list_for_each_entry(other_encoder, &dev->mode_config.encoder_list, head) {
  263. if (other_encoder == encoder)
  264. continue;
  265. other_radeon_encoder = to_radeon_encoder(other_encoder);
  266. if (other_radeon_encoder->is_ext_encoder &&
  267. (radeon_encoder->devices & other_radeon_encoder->devices))
  268. return other_encoder;
  269. }
  270. return NULL;
  271. }
  272. u16 radeon_encoder_get_dp_bridge_encoder_id(struct drm_encoder *encoder)
  273. {
  274. struct drm_encoder *other_encoder = radeon_get_external_encoder(encoder);
  275. if (other_encoder) {
  276. struct radeon_encoder *radeon_encoder = to_radeon_encoder(other_encoder);
  277. switch (radeon_encoder->encoder_id) {
  278. case ENCODER_OBJECT_ID_TRAVIS:
  279. case ENCODER_OBJECT_ID_NUTMEG:
  280. return radeon_encoder->encoder_id;
  281. default:
  282. return ENCODER_OBJECT_ID_NONE;
  283. }
  284. }
  285. return ENCODER_OBJECT_ID_NONE;
  286. }
  287. void radeon_panel_mode_fixup(struct drm_encoder *encoder,
  288. struct drm_display_mode *adjusted_mode)
  289. {
  290. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  291. struct drm_device *dev = encoder->dev;
  292. struct radeon_device *rdev = dev->dev_private;
  293. struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
  294. unsigned hblank = native_mode->htotal - native_mode->hdisplay;
  295. unsigned vblank = native_mode->vtotal - native_mode->vdisplay;
  296. unsigned hover = native_mode->hsync_start - native_mode->hdisplay;
  297. unsigned vover = native_mode->vsync_start - native_mode->vdisplay;
  298. unsigned hsync_width = native_mode->hsync_end - native_mode->hsync_start;
  299. unsigned vsync_width = native_mode->vsync_end - native_mode->vsync_start;
  300. adjusted_mode->clock = native_mode->clock;
  301. adjusted_mode->flags = native_mode->flags;
  302. if (ASIC_IS_AVIVO(rdev)) {
  303. adjusted_mode->hdisplay = native_mode->hdisplay;
  304. adjusted_mode->vdisplay = native_mode->vdisplay;
  305. }
  306. adjusted_mode->htotal = native_mode->hdisplay + hblank;
  307. adjusted_mode->hsync_start = native_mode->hdisplay + hover;
  308. adjusted_mode->hsync_end = adjusted_mode->hsync_start + hsync_width;
  309. adjusted_mode->vtotal = native_mode->vdisplay + vblank;
  310. adjusted_mode->vsync_start = native_mode->vdisplay + vover;
  311. adjusted_mode->vsync_end = adjusted_mode->vsync_start + vsync_width;
  312. drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
  313. if (ASIC_IS_AVIVO(rdev)) {
  314. adjusted_mode->crtc_hdisplay = native_mode->hdisplay;
  315. adjusted_mode->crtc_vdisplay = native_mode->vdisplay;
  316. }
  317. adjusted_mode->crtc_htotal = adjusted_mode->crtc_hdisplay + hblank;
  318. adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hdisplay + hover;
  319. adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + hsync_width;
  320. adjusted_mode->crtc_vtotal = adjusted_mode->crtc_vdisplay + vblank;
  321. adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + vover;
  322. adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + vsync_width;
  323. }
  324. bool radeon_dig_monitor_is_duallink(struct drm_encoder *encoder,
  325. u32 pixel_clock)
  326. {
  327. struct drm_device *dev = encoder->dev;
  328. struct radeon_device *rdev = dev->dev_private;
  329. struct drm_connector *connector;
  330. struct radeon_connector *radeon_connector;
  331. struct radeon_connector_atom_dig *dig_connector;
  332. connector = radeon_get_connector_for_encoder(encoder);
  333. /* if we don't have an active device yet, just use one of
  334. * the connectors tied to the encoder.
  335. */
  336. if (!connector)
  337. connector = radeon_get_connector_for_encoder_init(encoder);
  338. radeon_connector = to_radeon_connector(connector);
  339. switch (connector->connector_type) {
  340. case DRM_MODE_CONNECTOR_DVII:
  341. case DRM_MODE_CONNECTOR_HDMIB:
  342. if (radeon_connector->use_digital) {
  343. /* HDMI 1.3 supports up to 340 Mhz over single link */
  344. if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
  345. if (pixel_clock > 340000)
  346. return true;
  347. else
  348. return false;
  349. } else {
  350. if (pixel_clock > 165000)
  351. return true;
  352. else
  353. return false;
  354. }
  355. } else
  356. return false;
  357. case DRM_MODE_CONNECTOR_DVID:
  358. case DRM_MODE_CONNECTOR_HDMIA:
  359. case DRM_MODE_CONNECTOR_DisplayPort:
  360. if (radeon_connector->is_mst_connector)
  361. return false;
  362. dig_connector = radeon_connector->con_priv;
  363. if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
  364. (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
  365. return false;
  366. else {
  367. /* HDMI 1.3 supports up to 340 Mhz over single link */
  368. if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
  369. if (pixel_clock > 340000)
  370. return true;
  371. else
  372. return false;
  373. } else {
  374. if (pixel_clock > 165000)
  375. return true;
  376. else
  377. return false;
  378. }
  379. }
  380. default:
  381. return false;
  382. }
  383. }
  384. bool radeon_encoder_is_digital(struct drm_encoder *encoder)
  385. {
  386. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  387. switch (radeon_encoder->encoder_id) {
  388. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  389. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  390. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  391. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  392. case ENCODER_OBJECT_ID_INTERNAL_DVO1:
  393. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  394. case ENCODER_OBJECT_ID_INTERNAL_DDI:
  395. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
  396. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
  397. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
  398. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
  399. case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
  400. return true;
  401. default:
  402. return false;
  403. }
  404. }