radeon_legacy_encoders.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  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 "drmP.h"
  27. #include "drm_crtc_helper.h"
  28. #include "radeon_drm.h"
  29. #include "radeon.h"
  30. #include "atom.h"
  31. static void radeon_legacy_rmx_mode_set(struct drm_encoder *encoder,
  32. struct drm_display_mode *mode,
  33. struct drm_display_mode *adjusted_mode)
  34. {
  35. struct drm_device *dev = encoder->dev;
  36. struct radeon_device *rdev = dev->dev_private;
  37. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  38. int xres = mode->hdisplay;
  39. int yres = mode->vdisplay;
  40. bool hscale = true, vscale = true;
  41. int hsync_wid;
  42. int vsync_wid;
  43. int hsync_start;
  44. uint32_t scale, inc;
  45. uint32_t fp_horz_stretch, fp_vert_stretch, crtc_more_cntl, fp_horz_vert_active;
  46. uint32_t fp_h_sync_strt_wid, fp_v_sync_strt_wid, fp_crtc_h_total_disp, fp_crtc_v_total_disp;
  47. struct radeon_native_mode *native_mode = &radeon_encoder->native_mode;
  48. DRM_DEBUG("\n");
  49. fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH) &
  50. (RADEON_VERT_STRETCH_RESERVED |
  51. RADEON_VERT_AUTO_RATIO_INC);
  52. fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH) &
  53. (RADEON_HORZ_FP_LOOP_STRETCH |
  54. RADEON_HORZ_AUTO_RATIO_INC);
  55. crtc_more_cntl = 0;
  56. if ((rdev->family == CHIP_RS100) ||
  57. (rdev->family == CHIP_RS200)) {
  58. /* This is to workaround the asic bug for RMX, some versions
  59. of BIOS dosen't have this register initialized correctly. */
  60. crtc_more_cntl |= RADEON_CRTC_H_CUTOFF_ACTIVE_EN;
  61. }
  62. fp_crtc_h_total_disp = ((((mode->crtc_htotal / 8) - 1) & 0x3ff)
  63. | ((((mode->crtc_hdisplay / 8) - 1) & 0x1ff) << 16));
  64. hsync_wid = (mode->crtc_hsync_end - mode->crtc_hsync_start) / 8;
  65. if (!hsync_wid)
  66. hsync_wid = 1;
  67. hsync_start = mode->crtc_hsync_start - 8;
  68. fp_h_sync_strt_wid = ((hsync_start & 0x1fff)
  69. | ((hsync_wid & 0x3f) << 16)
  70. | ((mode->flags & DRM_MODE_FLAG_NHSYNC)
  71. ? RADEON_CRTC_H_SYNC_POL
  72. : 0));
  73. fp_crtc_v_total_disp = (((mode->crtc_vtotal - 1) & 0xffff)
  74. | ((mode->crtc_vdisplay - 1) << 16));
  75. vsync_wid = mode->crtc_vsync_end - mode->crtc_vsync_start;
  76. if (!vsync_wid)
  77. vsync_wid = 1;
  78. fp_v_sync_strt_wid = (((mode->crtc_vsync_start - 1) & 0xfff)
  79. | ((vsync_wid & 0x1f) << 16)
  80. | ((mode->flags & DRM_MODE_FLAG_NVSYNC)
  81. ? RADEON_CRTC_V_SYNC_POL
  82. : 0));
  83. fp_horz_vert_active = 0;
  84. if (native_mode->panel_xres == 0 ||
  85. native_mode->panel_yres == 0) {
  86. hscale = false;
  87. vscale = false;
  88. } else {
  89. if (xres > native_mode->panel_xres)
  90. xres = native_mode->panel_xres;
  91. if (yres > native_mode->panel_yres)
  92. yres = native_mode->panel_yres;
  93. if (xres == native_mode->panel_xres)
  94. hscale = false;
  95. if (yres == native_mode->panel_yres)
  96. vscale = false;
  97. }
  98. if (radeon_encoder->flags & RADEON_USE_RMX) {
  99. if (radeon_encoder->rmx_type != RMX_CENTER) {
  100. if (!hscale)
  101. fp_horz_stretch |= ((xres/8-1) << 16);
  102. else {
  103. inc = (fp_horz_stretch & RADEON_HORZ_AUTO_RATIO_INC) ? 1 : 0;
  104. scale = ((xres + inc) * RADEON_HORZ_STRETCH_RATIO_MAX)
  105. / native_mode->panel_xres + 1;
  106. fp_horz_stretch |= (((scale) & RADEON_HORZ_STRETCH_RATIO_MASK) |
  107. RADEON_HORZ_STRETCH_BLEND |
  108. RADEON_HORZ_STRETCH_ENABLE |
  109. ((native_mode->panel_xres/8-1) << 16));
  110. }
  111. if (!vscale)
  112. fp_vert_stretch |= ((yres-1) << 12);
  113. else {
  114. inc = (fp_vert_stretch & RADEON_VERT_AUTO_RATIO_INC) ? 1 : 0;
  115. scale = ((yres + inc) * RADEON_VERT_STRETCH_RATIO_MAX)
  116. / native_mode->panel_yres + 1;
  117. fp_vert_stretch |= (((scale) & RADEON_VERT_STRETCH_RATIO_MASK) |
  118. RADEON_VERT_STRETCH_ENABLE |
  119. RADEON_VERT_STRETCH_BLEND |
  120. ((native_mode->panel_yres-1) << 12));
  121. }
  122. } else if (radeon_encoder->rmx_type == RMX_CENTER) {
  123. int blank_width;
  124. fp_horz_stretch |= ((xres/8-1) << 16);
  125. fp_vert_stretch |= ((yres-1) << 12);
  126. crtc_more_cntl |= (RADEON_CRTC_AUTO_HORZ_CENTER_EN |
  127. RADEON_CRTC_AUTO_VERT_CENTER_EN);
  128. blank_width = (mode->crtc_hblank_end - mode->crtc_hblank_start) / 8;
  129. if (blank_width > 110)
  130. blank_width = 110;
  131. fp_crtc_h_total_disp = (((blank_width) & 0x3ff)
  132. | ((((mode->crtc_hdisplay / 8) - 1) & 0x1ff) << 16));
  133. hsync_wid = (mode->crtc_hsync_end - mode->crtc_hsync_start) / 8;
  134. if (!hsync_wid)
  135. hsync_wid = 1;
  136. fp_h_sync_strt_wid = ((((mode->crtc_hsync_start - mode->crtc_hblank_start) / 8) & 0x1fff)
  137. | ((hsync_wid & 0x3f) << 16)
  138. | ((mode->flags & DRM_MODE_FLAG_NHSYNC)
  139. ? RADEON_CRTC_H_SYNC_POL
  140. : 0));
  141. fp_crtc_v_total_disp = (((mode->crtc_vblank_end - mode->crtc_vblank_start) & 0xffff)
  142. | ((mode->crtc_vdisplay - 1) << 16));
  143. vsync_wid = mode->crtc_vsync_end - mode->crtc_vsync_start;
  144. if (!vsync_wid)
  145. vsync_wid = 1;
  146. fp_v_sync_strt_wid = ((((mode->crtc_vsync_start - mode->crtc_vblank_start) & 0xfff)
  147. | ((vsync_wid & 0x1f) << 16)
  148. | ((mode->flags & DRM_MODE_FLAG_NVSYNC)
  149. ? RADEON_CRTC_V_SYNC_POL
  150. : 0)));
  151. fp_horz_vert_active = (((native_mode->panel_yres) & 0xfff) |
  152. (((native_mode->panel_xres / 8) & 0x1ff) << 16));
  153. }
  154. } else {
  155. fp_horz_stretch |= ((xres/8-1) << 16);
  156. fp_vert_stretch |= ((yres-1) << 12);
  157. }
  158. WREG32(RADEON_FP_HORZ_STRETCH, fp_horz_stretch);
  159. WREG32(RADEON_FP_VERT_STRETCH, fp_vert_stretch);
  160. WREG32(RADEON_CRTC_MORE_CNTL, crtc_more_cntl);
  161. WREG32(RADEON_FP_HORZ_VERT_ACTIVE, fp_horz_vert_active);
  162. WREG32(RADEON_FP_H_SYNC_STRT_WID, fp_h_sync_strt_wid);
  163. WREG32(RADEON_FP_V_SYNC_STRT_WID, fp_v_sync_strt_wid);
  164. WREG32(RADEON_FP_CRTC_H_TOTAL_DISP, fp_crtc_h_total_disp);
  165. WREG32(RADEON_FP_CRTC_V_TOTAL_DISP, fp_crtc_v_total_disp);
  166. }
  167. static void radeon_legacy_lvds_dpms(struct drm_encoder *encoder, int mode)
  168. {
  169. struct drm_device *dev = encoder->dev;
  170. struct radeon_device *rdev = dev->dev_private;
  171. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  172. uint32_t lvds_gen_cntl, lvds_pll_cntl, pixclks_cntl, disp_pwr_man;
  173. int panel_pwr_delay = 2000;
  174. DRM_DEBUG("\n");
  175. if (radeon_encoder->enc_priv) {
  176. if (rdev->is_atom_bios) {
  177. struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
  178. panel_pwr_delay = lvds->panel_pwr_delay;
  179. } else {
  180. struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
  181. panel_pwr_delay = lvds->panel_pwr_delay;
  182. }
  183. }
  184. switch (mode) {
  185. case DRM_MODE_DPMS_ON:
  186. disp_pwr_man = RREG32(RADEON_DISP_PWR_MAN);
  187. disp_pwr_man |= RADEON_AUTO_PWRUP_EN;
  188. WREG32(RADEON_DISP_PWR_MAN, disp_pwr_man);
  189. lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
  190. lvds_pll_cntl |= RADEON_LVDS_PLL_EN;
  191. WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
  192. udelay(1000);
  193. lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
  194. lvds_pll_cntl &= ~RADEON_LVDS_PLL_RESET;
  195. WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
  196. lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
  197. lvds_gen_cntl |= (RADEON_LVDS_ON | RADEON_LVDS_EN | RADEON_LVDS_DIGON | RADEON_LVDS_BLON);
  198. lvds_gen_cntl &= ~(RADEON_LVDS_DISPLAY_DIS);
  199. udelay(panel_pwr_delay * 1000);
  200. WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
  201. break;
  202. case DRM_MODE_DPMS_STANDBY:
  203. case DRM_MODE_DPMS_SUSPEND:
  204. case DRM_MODE_DPMS_OFF:
  205. pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  206. WREG32_PLL_P(RADEON_PIXCLKS_CNTL, 0, ~RADEON_PIXCLK_LVDS_ALWAYS_ONb);
  207. lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
  208. lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
  209. lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_BLON | RADEON_LVDS_EN | RADEON_LVDS_DIGON);
  210. udelay(panel_pwr_delay * 1000);
  211. WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
  212. WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
  213. break;
  214. }
  215. if (rdev->is_atom_bios)
  216. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  217. else
  218. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  219. }
  220. static void radeon_legacy_lvds_prepare(struct drm_encoder *encoder)
  221. {
  222. struct radeon_device *rdev = encoder->dev->dev_private;
  223. if (rdev->is_atom_bios)
  224. radeon_atom_output_lock(encoder, true);
  225. else
  226. radeon_combios_output_lock(encoder, true);
  227. radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_OFF);
  228. }
  229. static void radeon_legacy_lvds_commit(struct drm_encoder *encoder)
  230. {
  231. struct radeon_device *rdev = encoder->dev->dev_private;
  232. radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_ON);
  233. if (rdev->is_atom_bios)
  234. radeon_atom_output_lock(encoder, false);
  235. else
  236. radeon_combios_output_lock(encoder, false);
  237. }
  238. static void radeon_legacy_lvds_mode_set(struct drm_encoder *encoder,
  239. struct drm_display_mode *mode,
  240. struct drm_display_mode *adjusted_mode)
  241. {
  242. struct drm_device *dev = encoder->dev;
  243. struct radeon_device *rdev = dev->dev_private;
  244. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  245. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  246. uint32_t lvds_pll_cntl, lvds_gen_cntl, lvds_ss_gen_cntl;
  247. DRM_DEBUG("\n");
  248. if (radeon_crtc->crtc_id == 0)
  249. radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
  250. lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
  251. lvds_pll_cntl &= ~RADEON_LVDS_PLL_EN;
  252. lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
  253. if ((!rdev->is_atom_bios)) {
  254. struct radeon_encoder_lvds *lvds = (struct radeon_encoder_lvds *)radeon_encoder->enc_priv;
  255. if (lvds) {
  256. DRM_DEBUG("bios LVDS_GEN_CNTL: 0x%x\n", lvds->lvds_gen_cntl);
  257. lvds_gen_cntl = lvds->lvds_gen_cntl;
  258. lvds_ss_gen_cntl &= ~((0xf << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
  259. (0xf << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
  260. lvds_ss_gen_cntl |= ((lvds->panel_digon_delay << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
  261. (lvds->panel_blon_delay << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
  262. } else
  263. lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
  264. } else
  265. lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
  266. lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
  267. lvds_gen_cntl &= ~(RADEON_LVDS_ON |
  268. RADEON_LVDS_BLON |
  269. RADEON_LVDS_EN |
  270. RADEON_LVDS_RST_FM);
  271. if (ASIC_IS_R300(rdev))
  272. lvds_pll_cntl &= ~(R300_LVDS_SRC_SEL_MASK);
  273. if (radeon_crtc->crtc_id == 0) {
  274. if (ASIC_IS_R300(rdev)) {
  275. if (radeon_encoder->flags & RADEON_USE_RMX)
  276. lvds_pll_cntl |= R300_LVDS_SRC_SEL_RMX;
  277. } else
  278. lvds_gen_cntl &= ~RADEON_LVDS_SEL_CRTC2;
  279. } else {
  280. if (ASIC_IS_R300(rdev))
  281. lvds_pll_cntl |= R300_LVDS_SRC_SEL_CRTC2;
  282. else
  283. lvds_gen_cntl |= RADEON_LVDS_SEL_CRTC2;
  284. }
  285. WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
  286. WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
  287. WREG32(RADEON_LVDS_SS_GEN_CNTL, lvds_ss_gen_cntl);
  288. if (rdev->family == CHIP_RV410)
  289. WREG32(RADEON_CLOCK_CNTL_INDEX, 0);
  290. if (rdev->is_atom_bios)
  291. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  292. else
  293. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  294. }
  295. static bool radeon_legacy_lvds_mode_fixup(struct drm_encoder *encoder,
  296. struct drm_display_mode *mode,
  297. struct drm_display_mode *adjusted_mode)
  298. {
  299. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  300. drm_mode_set_crtcinfo(adjusted_mode, 0);
  301. radeon_encoder->flags &= ~RADEON_USE_RMX;
  302. if (radeon_encoder->rmx_type != RMX_OFF)
  303. radeon_rmx_mode_fixup(encoder, mode, adjusted_mode);
  304. return true;
  305. }
  306. static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs = {
  307. .dpms = radeon_legacy_lvds_dpms,
  308. .mode_fixup = radeon_legacy_lvds_mode_fixup,
  309. .prepare = radeon_legacy_lvds_prepare,
  310. .mode_set = radeon_legacy_lvds_mode_set,
  311. .commit = radeon_legacy_lvds_commit,
  312. };
  313. static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs = {
  314. .destroy = radeon_enc_destroy,
  315. };
  316. static bool radeon_legacy_primary_dac_mode_fixup(struct drm_encoder *encoder,
  317. struct drm_display_mode *mode,
  318. struct drm_display_mode *adjusted_mode)
  319. {
  320. drm_mode_set_crtcinfo(adjusted_mode, 0);
  321. return true;
  322. }
  323. static void radeon_legacy_primary_dac_dpms(struct drm_encoder *encoder, int mode)
  324. {
  325. struct drm_device *dev = encoder->dev;
  326. struct radeon_device *rdev = dev->dev_private;
  327. uint32_t crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
  328. uint32_t dac_cntl = RREG32(RADEON_DAC_CNTL);
  329. uint32_t dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
  330. DRM_DEBUG("\n");
  331. switch (mode) {
  332. case DRM_MODE_DPMS_ON:
  333. crtc_ext_cntl |= RADEON_CRTC_CRT_ON;
  334. dac_cntl &= ~RADEON_DAC_PDWN;
  335. dac_macro_cntl &= ~(RADEON_DAC_PDWN_R |
  336. RADEON_DAC_PDWN_G |
  337. RADEON_DAC_PDWN_B);
  338. break;
  339. case DRM_MODE_DPMS_STANDBY:
  340. case DRM_MODE_DPMS_SUSPEND:
  341. case DRM_MODE_DPMS_OFF:
  342. crtc_ext_cntl &= ~RADEON_CRTC_CRT_ON;
  343. dac_cntl |= RADEON_DAC_PDWN;
  344. dac_macro_cntl |= (RADEON_DAC_PDWN_R |
  345. RADEON_DAC_PDWN_G |
  346. RADEON_DAC_PDWN_B);
  347. break;
  348. }
  349. WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
  350. WREG32(RADEON_DAC_CNTL, dac_cntl);
  351. WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
  352. if (rdev->is_atom_bios)
  353. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  354. else
  355. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  356. }
  357. static void radeon_legacy_primary_dac_prepare(struct drm_encoder *encoder)
  358. {
  359. struct radeon_device *rdev = encoder->dev->dev_private;
  360. if (rdev->is_atom_bios)
  361. radeon_atom_output_lock(encoder, true);
  362. else
  363. radeon_combios_output_lock(encoder, true);
  364. radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
  365. }
  366. static void radeon_legacy_primary_dac_commit(struct drm_encoder *encoder)
  367. {
  368. struct radeon_device *rdev = encoder->dev->dev_private;
  369. radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_ON);
  370. if (rdev->is_atom_bios)
  371. radeon_atom_output_lock(encoder, false);
  372. else
  373. radeon_combios_output_lock(encoder, false);
  374. }
  375. static void radeon_legacy_primary_dac_mode_set(struct drm_encoder *encoder,
  376. struct drm_display_mode *mode,
  377. struct drm_display_mode *adjusted_mode)
  378. {
  379. struct drm_device *dev = encoder->dev;
  380. struct radeon_device *rdev = dev->dev_private;
  381. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  382. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  383. uint32_t disp_output_cntl, dac_cntl, dac2_cntl, dac_macro_cntl;
  384. DRM_DEBUG("\n");
  385. if (radeon_crtc->crtc_id == 0)
  386. radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
  387. if (radeon_crtc->crtc_id == 0) {
  388. if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) {
  389. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) &
  390. ~(RADEON_DISP_DAC_SOURCE_MASK);
  391. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  392. } else {
  393. dac2_cntl = RREG32(RADEON_DAC_CNTL2) & ~(RADEON_DAC2_DAC_CLK_SEL);
  394. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  395. }
  396. } else {
  397. if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) {
  398. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) &
  399. ~(RADEON_DISP_DAC_SOURCE_MASK);
  400. disp_output_cntl |= RADEON_DISP_DAC_SOURCE_CRTC2;
  401. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  402. } else {
  403. dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC_CLK_SEL;
  404. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  405. }
  406. }
  407. dac_cntl = (RADEON_DAC_MASK_ALL |
  408. RADEON_DAC_VGA_ADR_EN |
  409. /* TODO 6-bits */
  410. RADEON_DAC_8BIT_EN);
  411. WREG32_P(RADEON_DAC_CNTL,
  412. dac_cntl,
  413. RADEON_DAC_RANGE_CNTL |
  414. RADEON_DAC_BLANKING);
  415. if (radeon_encoder->enc_priv) {
  416. struct radeon_encoder_primary_dac *p_dac = (struct radeon_encoder_primary_dac *)radeon_encoder->enc_priv;
  417. dac_macro_cntl = p_dac->ps2_pdac_adj;
  418. } else
  419. dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
  420. dac_macro_cntl |= RADEON_DAC_PDWN_R | RADEON_DAC_PDWN_G | RADEON_DAC_PDWN_B;
  421. WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
  422. if (rdev->is_atom_bios)
  423. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  424. else
  425. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  426. }
  427. static enum drm_connector_status radeon_legacy_primary_dac_detect(struct drm_encoder *encoder,
  428. struct drm_connector *connector)
  429. {
  430. struct drm_device *dev = encoder->dev;
  431. struct radeon_device *rdev = dev->dev_private;
  432. uint32_t vclk_ecp_cntl, crtc_ext_cntl;
  433. uint32_t dac_ext_cntl, dac_cntl, dac_macro_cntl, tmp;
  434. enum drm_connector_status found = connector_status_disconnected;
  435. bool color = true;
  436. /* save the regs we need */
  437. vclk_ecp_cntl = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
  438. crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
  439. dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
  440. dac_cntl = RREG32(RADEON_DAC_CNTL);
  441. dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
  442. tmp = vclk_ecp_cntl &
  443. ~(RADEON_PIXCLK_ALWAYS_ONb | RADEON_PIXCLK_DAC_ALWAYS_ONb);
  444. WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
  445. tmp = crtc_ext_cntl | RADEON_CRTC_CRT_ON;
  446. WREG32(RADEON_CRTC_EXT_CNTL, tmp);
  447. tmp = RADEON_DAC_FORCE_BLANK_OFF_EN |
  448. RADEON_DAC_FORCE_DATA_EN;
  449. if (color)
  450. tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
  451. else
  452. tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
  453. if (ASIC_IS_R300(rdev))
  454. tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
  455. else
  456. tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
  457. WREG32(RADEON_DAC_EXT_CNTL, tmp);
  458. tmp = dac_cntl & ~(RADEON_DAC_RANGE_CNTL_MASK | RADEON_DAC_PDWN);
  459. tmp |= RADEON_DAC_RANGE_CNTL_PS2 | RADEON_DAC_CMP_EN;
  460. WREG32(RADEON_DAC_CNTL, tmp);
  461. tmp &= ~(RADEON_DAC_PDWN_R |
  462. RADEON_DAC_PDWN_G |
  463. RADEON_DAC_PDWN_B);
  464. WREG32(RADEON_DAC_MACRO_CNTL, tmp);
  465. udelay(2000);
  466. if (RREG32(RADEON_DAC_CNTL) & RADEON_DAC_CMP_OUTPUT)
  467. found = connector_status_connected;
  468. /* restore the regs we used */
  469. WREG32(RADEON_DAC_CNTL, dac_cntl);
  470. WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
  471. WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
  472. WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
  473. WREG32_PLL(RADEON_VCLK_ECP_CNTL, vclk_ecp_cntl);
  474. return found;
  475. }
  476. static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs = {
  477. .dpms = radeon_legacy_primary_dac_dpms,
  478. .mode_fixup = radeon_legacy_primary_dac_mode_fixup,
  479. .prepare = radeon_legacy_primary_dac_prepare,
  480. .mode_set = radeon_legacy_primary_dac_mode_set,
  481. .commit = radeon_legacy_primary_dac_commit,
  482. .detect = radeon_legacy_primary_dac_detect,
  483. };
  484. static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs = {
  485. .destroy = radeon_enc_destroy,
  486. };
  487. static bool radeon_legacy_tmds_int_mode_fixup(struct drm_encoder *encoder,
  488. struct drm_display_mode *mode,
  489. struct drm_display_mode *adjusted_mode)
  490. {
  491. drm_mode_set_crtcinfo(adjusted_mode, 0);
  492. return true;
  493. }
  494. static void radeon_legacy_tmds_int_dpms(struct drm_encoder *encoder, int mode)
  495. {
  496. struct drm_device *dev = encoder->dev;
  497. struct radeon_device *rdev = dev->dev_private;
  498. uint32_t fp_gen_cntl = RREG32(RADEON_FP_GEN_CNTL);
  499. DRM_DEBUG("\n");
  500. switch (mode) {
  501. case DRM_MODE_DPMS_ON:
  502. fp_gen_cntl |= (RADEON_FP_FPON | RADEON_FP_TMDS_EN);
  503. break;
  504. case DRM_MODE_DPMS_STANDBY:
  505. case DRM_MODE_DPMS_SUSPEND:
  506. case DRM_MODE_DPMS_OFF:
  507. fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
  508. break;
  509. }
  510. WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl);
  511. if (rdev->is_atom_bios)
  512. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  513. else
  514. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  515. }
  516. static void radeon_legacy_tmds_int_prepare(struct drm_encoder *encoder)
  517. {
  518. struct radeon_device *rdev = encoder->dev->dev_private;
  519. if (rdev->is_atom_bios)
  520. radeon_atom_output_lock(encoder, true);
  521. else
  522. radeon_combios_output_lock(encoder, true);
  523. radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_OFF);
  524. }
  525. static void radeon_legacy_tmds_int_commit(struct drm_encoder *encoder)
  526. {
  527. struct radeon_device *rdev = encoder->dev->dev_private;
  528. radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_ON);
  529. if (rdev->is_atom_bios)
  530. radeon_atom_output_lock(encoder, true);
  531. else
  532. radeon_combios_output_lock(encoder, true);
  533. }
  534. static void radeon_legacy_tmds_int_mode_set(struct drm_encoder *encoder,
  535. struct drm_display_mode *mode,
  536. struct drm_display_mode *adjusted_mode)
  537. {
  538. struct drm_device *dev = encoder->dev;
  539. struct radeon_device *rdev = dev->dev_private;
  540. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  541. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  542. uint32_t tmp, tmds_pll_cntl, tmds_transmitter_cntl, fp_gen_cntl;
  543. int i;
  544. DRM_DEBUG("\n");
  545. if (radeon_crtc->crtc_id == 0)
  546. radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
  547. tmp = tmds_pll_cntl = RREG32(RADEON_TMDS_PLL_CNTL);
  548. tmp &= 0xfffff;
  549. if (rdev->family == CHIP_RV280) {
  550. /* bit 22 of TMDS_PLL_CNTL is read-back inverted */
  551. tmp ^= (1 << 22);
  552. tmds_pll_cntl ^= (1 << 22);
  553. }
  554. if (radeon_encoder->enc_priv) {
  555. struct radeon_encoder_int_tmds *tmds = (struct radeon_encoder_int_tmds *)radeon_encoder->enc_priv;
  556. for (i = 0; i < 4; i++) {
  557. if (tmds->tmds_pll[i].freq == 0)
  558. break;
  559. if ((uint32_t)(mode->clock / 10) < tmds->tmds_pll[i].freq) {
  560. tmp = tmds->tmds_pll[i].value ;
  561. break;
  562. }
  563. }
  564. }
  565. if (ASIC_IS_R300(rdev) || (rdev->family == CHIP_RV280)) {
  566. if (tmp & 0xfff00000)
  567. tmds_pll_cntl = tmp;
  568. else {
  569. tmds_pll_cntl &= 0xfff00000;
  570. tmds_pll_cntl |= tmp;
  571. }
  572. } else
  573. tmds_pll_cntl = tmp;
  574. tmds_transmitter_cntl = RREG32(RADEON_TMDS_TRANSMITTER_CNTL) &
  575. ~(RADEON_TMDS_TRANSMITTER_PLLRST);
  576. if (rdev->family == CHIP_R200 ||
  577. rdev->family == CHIP_R100 ||
  578. ASIC_IS_R300(rdev))
  579. tmds_transmitter_cntl &= ~(RADEON_TMDS_TRANSMITTER_PLLEN);
  580. else /* RV chips got this bit reversed */
  581. tmds_transmitter_cntl |= RADEON_TMDS_TRANSMITTER_PLLEN;
  582. fp_gen_cntl = (RREG32(RADEON_FP_GEN_CNTL) |
  583. (RADEON_FP_CRTC_DONT_SHADOW_VPAR |
  584. RADEON_FP_CRTC_DONT_SHADOW_HEND));
  585. fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
  586. if (1) /* FIXME rgbBits == 8 */
  587. fp_gen_cntl |= RADEON_FP_PANEL_FORMAT; /* 24 bit format */
  588. else
  589. fp_gen_cntl &= ~RADEON_FP_PANEL_FORMAT;/* 18 bit format */
  590. if (radeon_crtc->crtc_id == 0) {
  591. if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) {
  592. fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
  593. if (radeon_encoder->flags & RADEON_USE_RMX)
  594. fp_gen_cntl |= R200_FP_SOURCE_SEL_RMX;
  595. else
  596. fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC1;
  597. } else
  598. fp_gen_cntl |= RADEON_FP_SEL_CRTC1;
  599. } else {
  600. if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) {
  601. fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
  602. fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC2;
  603. } else
  604. fp_gen_cntl |= RADEON_FP_SEL_CRTC2;
  605. }
  606. WREG32(RADEON_TMDS_PLL_CNTL, tmds_pll_cntl);
  607. WREG32(RADEON_TMDS_TRANSMITTER_CNTL, tmds_transmitter_cntl);
  608. WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl);
  609. if (rdev->is_atom_bios)
  610. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  611. else
  612. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  613. }
  614. static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs = {
  615. .dpms = radeon_legacy_tmds_int_dpms,
  616. .mode_fixup = radeon_legacy_tmds_int_mode_fixup,
  617. .prepare = radeon_legacy_tmds_int_prepare,
  618. .mode_set = radeon_legacy_tmds_int_mode_set,
  619. .commit = radeon_legacy_tmds_int_commit,
  620. };
  621. static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs = {
  622. .destroy = radeon_enc_destroy,
  623. };
  624. static bool radeon_legacy_tmds_ext_mode_fixup(struct drm_encoder *encoder,
  625. struct drm_display_mode *mode,
  626. struct drm_display_mode *adjusted_mode)
  627. {
  628. drm_mode_set_crtcinfo(adjusted_mode, 0);
  629. return true;
  630. }
  631. static void radeon_legacy_tmds_ext_dpms(struct drm_encoder *encoder, int mode)
  632. {
  633. struct drm_device *dev = encoder->dev;
  634. struct radeon_device *rdev = dev->dev_private;
  635. uint32_t fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  636. DRM_DEBUG("\n");
  637. switch (mode) {
  638. case DRM_MODE_DPMS_ON:
  639. fp2_gen_cntl &= ~RADEON_FP2_BLANK_EN;
  640. fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  641. break;
  642. case DRM_MODE_DPMS_STANDBY:
  643. case DRM_MODE_DPMS_SUSPEND:
  644. case DRM_MODE_DPMS_OFF:
  645. fp2_gen_cntl |= RADEON_FP2_BLANK_EN;
  646. fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  647. break;
  648. }
  649. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  650. if (rdev->is_atom_bios)
  651. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  652. else
  653. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  654. }
  655. static void radeon_legacy_tmds_ext_prepare(struct drm_encoder *encoder)
  656. {
  657. struct radeon_device *rdev = encoder->dev->dev_private;
  658. if (rdev->is_atom_bios)
  659. radeon_atom_output_lock(encoder, true);
  660. else
  661. radeon_combios_output_lock(encoder, true);
  662. radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_OFF);
  663. }
  664. static void radeon_legacy_tmds_ext_commit(struct drm_encoder *encoder)
  665. {
  666. struct radeon_device *rdev = encoder->dev->dev_private;
  667. radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_ON);
  668. if (rdev->is_atom_bios)
  669. radeon_atom_output_lock(encoder, false);
  670. else
  671. radeon_combios_output_lock(encoder, false);
  672. }
  673. static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder *encoder,
  674. struct drm_display_mode *mode,
  675. struct drm_display_mode *adjusted_mode)
  676. {
  677. struct drm_device *dev = encoder->dev;
  678. struct radeon_device *rdev = dev->dev_private;
  679. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  680. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  681. uint32_t fp2_gen_cntl;
  682. DRM_DEBUG("\n");
  683. if (radeon_crtc->crtc_id == 0)
  684. radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
  685. if (rdev->is_atom_bios) {
  686. radeon_encoder->pixel_clock = adjusted_mode->clock;
  687. atombios_external_tmds_setup(encoder, ATOM_ENABLE);
  688. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  689. } else {
  690. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  691. if (1) /* FIXME rgbBits == 8 */
  692. fp2_gen_cntl |= RADEON_FP2_PANEL_FORMAT; /* 24 bit format, */
  693. else
  694. fp2_gen_cntl &= ~RADEON_FP2_PANEL_FORMAT;/* 18 bit format, */
  695. fp2_gen_cntl &= ~(RADEON_FP2_ON |
  696. RADEON_FP2_DVO_EN |
  697. RADEON_FP2_DVO_RATE_SEL_SDR);
  698. /* XXX: these are oem specific */
  699. if (ASIC_IS_R300(rdev)) {
  700. if ((dev->pdev->device == 0x4850) &&
  701. (dev->pdev->subsystem_vendor == 0x1028) &&
  702. (dev->pdev->subsystem_device == 0x2001)) /* Dell Inspiron 8600 */
  703. fp2_gen_cntl |= R300_FP2_DVO_CLOCK_MODE_SINGLE;
  704. else
  705. fp2_gen_cntl |= RADEON_FP2_PAD_FLOP_EN | R300_FP2_DVO_CLOCK_MODE_SINGLE;
  706. /*if (mode->clock > 165000)
  707. fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/
  708. }
  709. }
  710. if (radeon_crtc->crtc_id == 0) {
  711. if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) {
  712. fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
  713. if (radeon_encoder->flags & RADEON_USE_RMX)
  714. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_RMX;
  715. else
  716. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC1;
  717. } else
  718. fp2_gen_cntl &= ~RADEON_FP2_SRC_SEL_CRTC2;
  719. } else {
  720. if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) {
  721. fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
  722. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
  723. } else
  724. fp2_gen_cntl |= RADEON_FP2_SRC_SEL_CRTC2;
  725. }
  726. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  727. if (rdev->is_atom_bios)
  728. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  729. else
  730. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  731. }
  732. static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs = {
  733. .dpms = radeon_legacy_tmds_ext_dpms,
  734. .mode_fixup = radeon_legacy_tmds_ext_mode_fixup,
  735. .prepare = radeon_legacy_tmds_ext_prepare,
  736. .mode_set = radeon_legacy_tmds_ext_mode_set,
  737. .commit = radeon_legacy_tmds_ext_commit,
  738. };
  739. static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs = {
  740. .destroy = radeon_enc_destroy,
  741. };
  742. static bool radeon_legacy_tv_dac_mode_fixup(struct drm_encoder *encoder,
  743. struct drm_display_mode *mode,
  744. struct drm_display_mode *adjusted_mode)
  745. {
  746. drm_mode_set_crtcinfo(adjusted_mode, 0);
  747. return true;
  748. }
  749. static void radeon_legacy_tv_dac_dpms(struct drm_encoder *encoder, int mode)
  750. {
  751. struct drm_device *dev = encoder->dev;
  752. struct radeon_device *rdev = dev->dev_private;
  753. uint32_t fp2_gen_cntl = 0, crtc2_gen_cntl = 0, tv_dac_cntl = 0;
  754. /* uint32_t tv_master_cntl = 0; */
  755. DRM_DEBUG("\n");
  756. if (rdev->family == CHIP_R200)
  757. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  758. else {
  759. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
  760. /* FIXME TV */
  761. /* tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL); */
  762. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  763. }
  764. switch (mode) {
  765. case DRM_MODE_DPMS_ON:
  766. if (rdev->family == CHIP_R200) {
  767. fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  768. } else {
  769. crtc2_gen_cntl |= RADEON_CRTC2_CRT2_ON;
  770. /* tv_master_cntl |= RADEON_TV_ON; */
  771. if (rdev->family == CHIP_R420 ||
  772. rdev->family == CHIP_R423 ||
  773. rdev->family == CHIP_RV410)
  774. tv_dac_cntl &= ~(R420_TV_DAC_RDACPD |
  775. R420_TV_DAC_GDACPD |
  776. R420_TV_DAC_BDACPD |
  777. RADEON_TV_DAC_BGSLEEP);
  778. else
  779. tv_dac_cntl &= ~(RADEON_TV_DAC_RDACPD |
  780. RADEON_TV_DAC_GDACPD |
  781. RADEON_TV_DAC_BDACPD |
  782. RADEON_TV_DAC_BGSLEEP);
  783. }
  784. break;
  785. case DRM_MODE_DPMS_STANDBY:
  786. case DRM_MODE_DPMS_SUSPEND:
  787. case DRM_MODE_DPMS_OFF:
  788. if (rdev->family == CHIP_R200)
  789. fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  790. else {
  791. crtc2_gen_cntl &= ~RADEON_CRTC2_CRT2_ON;
  792. /* tv_master_cntl &= ~RADEON_TV_ON; */
  793. if (rdev->family == CHIP_R420 ||
  794. rdev->family == CHIP_R423 ||
  795. rdev->family == CHIP_RV410)
  796. tv_dac_cntl |= (R420_TV_DAC_RDACPD |
  797. R420_TV_DAC_GDACPD |
  798. R420_TV_DAC_BDACPD |
  799. RADEON_TV_DAC_BGSLEEP);
  800. else
  801. tv_dac_cntl |= (RADEON_TV_DAC_RDACPD |
  802. RADEON_TV_DAC_GDACPD |
  803. RADEON_TV_DAC_BDACPD |
  804. RADEON_TV_DAC_BGSLEEP);
  805. }
  806. break;
  807. }
  808. if (rdev->family == CHIP_R200) {
  809. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  810. } else {
  811. WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
  812. /* WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl); */
  813. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  814. }
  815. if (rdev->is_atom_bios)
  816. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  817. else
  818. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  819. }
  820. static void radeon_legacy_tv_dac_prepare(struct drm_encoder *encoder)
  821. {
  822. struct radeon_device *rdev = encoder->dev->dev_private;
  823. if (rdev->is_atom_bios)
  824. radeon_atom_output_lock(encoder, true);
  825. else
  826. radeon_combios_output_lock(encoder, true);
  827. radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
  828. }
  829. static void radeon_legacy_tv_dac_commit(struct drm_encoder *encoder)
  830. {
  831. struct radeon_device *rdev = encoder->dev->dev_private;
  832. radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_ON);
  833. if (rdev->is_atom_bios)
  834. radeon_atom_output_lock(encoder, true);
  835. else
  836. radeon_combios_output_lock(encoder, true);
  837. }
  838. static void radeon_legacy_tv_dac_mode_set(struct drm_encoder *encoder,
  839. struct drm_display_mode *mode,
  840. struct drm_display_mode *adjusted_mode)
  841. {
  842. struct drm_device *dev = encoder->dev;
  843. struct radeon_device *rdev = dev->dev_private;
  844. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  845. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  846. uint32_t tv_dac_cntl, gpiopad_a = 0, dac2_cntl, disp_output_cntl = 0;
  847. uint32_t disp_hw_debug = 0, fp2_gen_cntl = 0;
  848. DRM_DEBUG("\n");
  849. if (radeon_crtc->crtc_id == 0)
  850. radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
  851. if (rdev->family != CHIP_R200) {
  852. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  853. if (rdev->family == CHIP_R420 ||
  854. rdev->family == CHIP_R423 ||
  855. rdev->family == CHIP_RV410) {
  856. tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
  857. RADEON_TV_DAC_BGADJ_MASK |
  858. R420_TV_DAC_DACADJ_MASK |
  859. R420_TV_DAC_RDACPD |
  860. R420_TV_DAC_GDACPD |
  861. R420_TV_DAC_GDACPD |
  862. R420_TV_DAC_TVENABLE);
  863. } else {
  864. tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
  865. RADEON_TV_DAC_BGADJ_MASK |
  866. RADEON_TV_DAC_DACADJ_MASK |
  867. RADEON_TV_DAC_RDACPD |
  868. RADEON_TV_DAC_GDACPD |
  869. RADEON_TV_DAC_GDACPD);
  870. }
  871. /* FIXME TV */
  872. if (radeon_encoder->enc_priv) {
  873. struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv;
  874. tv_dac_cntl |= (RADEON_TV_DAC_NBLANK |
  875. RADEON_TV_DAC_NHOLD |
  876. RADEON_TV_DAC_STD_PS2 |
  877. tv_dac->ps2_tvdac_adj);
  878. } else
  879. tv_dac_cntl |= (RADEON_TV_DAC_NBLANK |
  880. RADEON_TV_DAC_NHOLD |
  881. RADEON_TV_DAC_STD_PS2);
  882. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  883. }
  884. if (ASIC_IS_R300(rdev)) {
  885. gpiopad_a = RREG32(RADEON_GPIOPAD_A) | 1;
  886. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
  887. } else if (rdev->family == CHIP_R200)
  888. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  889. else
  890. disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG);
  891. dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC2_CLK_SEL;
  892. if (radeon_crtc->crtc_id == 0) {
  893. if (ASIC_IS_R300(rdev)) {
  894. disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
  895. disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC;
  896. } else if (rdev->family == CHIP_R200) {
  897. fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
  898. RADEON_FP2_DVO_RATE_SEL_SDR);
  899. } else
  900. disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
  901. } else {
  902. if (ASIC_IS_R300(rdev)) {
  903. disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
  904. disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
  905. } else if (rdev->family == CHIP_R200) {
  906. fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
  907. RADEON_FP2_DVO_RATE_SEL_SDR);
  908. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
  909. } else
  910. disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL;
  911. }
  912. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  913. if (ASIC_IS_R300(rdev)) {
  914. WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
  915. WREG32(RADEON_DISP_TV_OUT_CNTL, disp_output_cntl);
  916. } else if (rdev->family == CHIP_R200)
  917. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  918. else
  919. WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
  920. if (rdev->is_atom_bios)
  921. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  922. else
  923. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  924. }
  925. static enum drm_connector_status radeon_legacy_tv_dac_detect(struct drm_encoder *encoder,
  926. struct drm_connector *connector)
  927. {
  928. struct drm_device *dev = encoder->dev;
  929. struct radeon_device *rdev = dev->dev_private;
  930. uint32_t crtc2_gen_cntl, tv_dac_cntl, dac_cntl2, dac_ext_cntl;
  931. uint32_t disp_hw_debug, disp_output_cntl, gpiopad_a, pixclks_cntl, tmp;
  932. enum drm_connector_status found = connector_status_disconnected;
  933. bool color = true;
  934. /* FIXME tv */
  935. /* save the regs we need */
  936. pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  937. gpiopad_a = ASIC_IS_R300(rdev) ? RREG32(RADEON_GPIOPAD_A) : 0;
  938. disp_output_cntl = ASIC_IS_R300(rdev) ? RREG32(RADEON_DISP_OUTPUT_CNTL) : 0;
  939. disp_hw_debug = ASIC_IS_R300(rdev) ? 0 : RREG32(RADEON_DISP_HW_DEBUG);
  940. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
  941. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  942. dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
  943. dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
  944. tmp = pixclks_cntl & ~(RADEON_PIX2CLK_ALWAYS_ONb
  945. | RADEON_PIX2CLK_DAC_ALWAYS_ONb);
  946. WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
  947. if (ASIC_IS_R300(rdev))
  948. WREG32_P(RADEON_GPIOPAD_A, 1, ~1);
  949. tmp = crtc2_gen_cntl & ~RADEON_CRTC2_PIX_WIDTH_MASK;
  950. tmp |= RADEON_CRTC2_CRT2_ON |
  951. (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT);
  952. WREG32(RADEON_CRTC2_GEN_CNTL, tmp);
  953. if (ASIC_IS_R300(rdev)) {
  954. tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK;
  955. tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
  956. WREG32(RADEON_DISP_OUTPUT_CNTL, tmp);
  957. } else {
  958. tmp = disp_hw_debug & ~RADEON_CRT2_DISP1_SEL;
  959. WREG32(RADEON_DISP_HW_DEBUG, tmp);
  960. }
  961. tmp = RADEON_TV_DAC_NBLANK |
  962. RADEON_TV_DAC_NHOLD |
  963. RADEON_TV_MONITOR_DETECT_EN |
  964. RADEON_TV_DAC_STD_PS2;
  965. WREG32(RADEON_TV_DAC_CNTL, tmp);
  966. tmp = RADEON_DAC2_FORCE_BLANK_OFF_EN |
  967. RADEON_DAC2_FORCE_DATA_EN;
  968. if (color)
  969. tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
  970. else
  971. tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
  972. if (ASIC_IS_R300(rdev))
  973. tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
  974. else
  975. tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
  976. WREG32(RADEON_DAC_EXT_CNTL, tmp);
  977. tmp = dac_cntl2 | RADEON_DAC2_DAC2_CLK_SEL | RADEON_DAC2_CMP_EN;
  978. WREG32(RADEON_DAC_CNTL2, tmp);
  979. udelay(10000);
  980. if (ASIC_IS_R300(rdev)) {
  981. if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUT_B)
  982. found = connector_status_connected;
  983. } else {
  984. if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUTPUT)
  985. found = connector_status_connected;
  986. }
  987. /* restore regs we used */
  988. WREG32(RADEON_DAC_CNTL2, dac_cntl2);
  989. WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
  990. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  991. WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
  992. if (ASIC_IS_R300(rdev)) {
  993. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  994. WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
  995. } else {
  996. WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
  997. }
  998. WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
  999. /* return found; */
  1000. return connector_status_disconnected;
  1001. }
  1002. static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs = {
  1003. .dpms = radeon_legacy_tv_dac_dpms,
  1004. .mode_fixup = radeon_legacy_tv_dac_mode_fixup,
  1005. .prepare = radeon_legacy_tv_dac_prepare,
  1006. .mode_set = radeon_legacy_tv_dac_mode_set,
  1007. .commit = radeon_legacy_tv_dac_commit,
  1008. .detect = radeon_legacy_tv_dac_detect,
  1009. };
  1010. static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs = {
  1011. .destroy = radeon_enc_destroy,
  1012. };
  1013. void
  1014. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id, uint32_t supported_device)
  1015. {
  1016. struct radeon_device *rdev = dev->dev_private;
  1017. struct drm_encoder *encoder;
  1018. struct radeon_encoder *radeon_encoder;
  1019. /* see if we already added it */
  1020. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1021. radeon_encoder = to_radeon_encoder(encoder);
  1022. if (radeon_encoder->encoder_id == encoder_id) {
  1023. radeon_encoder->devices |= supported_device;
  1024. return;
  1025. }
  1026. }
  1027. /* add a new one */
  1028. radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
  1029. if (!radeon_encoder)
  1030. return;
  1031. encoder = &radeon_encoder->base;
  1032. encoder->possible_crtcs = 0x3;
  1033. encoder->possible_clones = 0;
  1034. radeon_encoder->enc_priv = NULL;
  1035. radeon_encoder->encoder_id = encoder_id;
  1036. radeon_encoder->devices = supported_device;
  1037. switch (radeon_encoder->encoder_id) {
  1038. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  1039. drm_encoder_init(dev, encoder, &radeon_legacy_lvds_enc_funcs, DRM_MODE_ENCODER_LVDS);
  1040. drm_encoder_helper_add(encoder, &radeon_legacy_lvds_helper_funcs);
  1041. if (rdev->is_atom_bios)
  1042. radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
  1043. else
  1044. radeon_encoder->enc_priv = radeon_combios_get_lvds_info(radeon_encoder);
  1045. radeon_encoder->rmx_type = RMX_FULL;
  1046. break;
  1047. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  1048. drm_encoder_init(dev, encoder, &radeon_legacy_tmds_int_enc_funcs, DRM_MODE_ENCODER_TMDS);
  1049. drm_encoder_helper_add(encoder, &radeon_legacy_tmds_int_helper_funcs);
  1050. if (rdev->is_atom_bios)
  1051. radeon_encoder->enc_priv = radeon_atombios_get_tmds_info(radeon_encoder);
  1052. else
  1053. radeon_encoder->enc_priv = radeon_combios_get_tmds_info(radeon_encoder);
  1054. break;
  1055. case ENCODER_OBJECT_ID_INTERNAL_DAC1:
  1056. drm_encoder_init(dev, encoder, &radeon_legacy_primary_dac_enc_funcs, DRM_MODE_ENCODER_DAC);
  1057. drm_encoder_helper_add(encoder, &radeon_legacy_primary_dac_helper_funcs);
  1058. if (rdev->is_atom_bios)
  1059. radeon_encoder->enc_priv = radeon_atombios_get_primary_dac_info(radeon_encoder);
  1060. else
  1061. radeon_encoder->enc_priv = radeon_combios_get_primary_dac_info(radeon_encoder);
  1062. break;
  1063. case ENCODER_OBJECT_ID_INTERNAL_DAC2:
  1064. drm_encoder_init(dev, encoder, &radeon_legacy_tv_dac_enc_funcs, DRM_MODE_ENCODER_TVDAC);
  1065. drm_encoder_helper_add(encoder, &radeon_legacy_tv_dac_helper_funcs);
  1066. if (rdev->is_atom_bios)
  1067. radeon_encoder->enc_priv = radeon_atombios_get_tv_dac_info(radeon_encoder);
  1068. else
  1069. radeon_encoder->enc_priv = radeon_combios_get_tv_dac_info(radeon_encoder);
  1070. break;
  1071. case ENCODER_OBJECT_ID_INTERNAL_DVO1:
  1072. drm_encoder_init(dev, encoder, &radeon_legacy_tmds_ext_enc_funcs, DRM_MODE_ENCODER_TMDS);
  1073. drm_encoder_helper_add(encoder, &radeon_legacy_tmds_ext_helper_funcs);
  1074. if (!rdev->is_atom_bios)
  1075. radeon_combios_get_ext_tmds_info(radeon_encoder);
  1076. break;
  1077. }
  1078. }