radeon_legacy_encoders.c 34 KB

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