radeon_legacy_encoders.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  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_encoder_disable(struct drm_encoder *encoder)
  32. {
  33. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  34. struct drm_encoder_helper_funcs *encoder_funcs;
  35. encoder_funcs = encoder->helper_private;
  36. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
  37. radeon_encoder->active_device = 0;
  38. }
  39. static void radeon_legacy_lvds_dpms(struct drm_encoder *encoder, int mode)
  40. {
  41. struct drm_device *dev = encoder->dev;
  42. struct radeon_device *rdev = dev->dev_private;
  43. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  44. uint32_t lvds_gen_cntl, lvds_pll_cntl, pixclks_cntl, disp_pwr_man;
  45. int panel_pwr_delay = 2000;
  46. bool is_mac = false;
  47. DRM_DEBUG("\n");
  48. if (radeon_encoder->enc_priv) {
  49. if (rdev->is_atom_bios) {
  50. struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
  51. panel_pwr_delay = lvds->panel_pwr_delay;
  52. } else {
  53. struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
  54. panel_pwr_delay = lvds->panel_pwr_delay;
  55. }
  56. }
  57. /* macs (and possibly some x86 oem systems?) wire up LVDS strangely
  58. * Taken from radeonfb.
  59. */
  60. if ((rdev->mode_info.connector_table == CT_IBOOK) ||
  61. (rdev->mode_info.connector_table == CT_POWERBOOK_EXTERNAL) ||
  62. (rdev->mode_info.connector_table == CT_POWERBOOK_INTERNAL) ||
  63. (rdev->mode_info.connector_table == CT_POWERBOOK_VGA))
  64. is_mac = true;
  65. switch (mode) {
  66. case DRM_MODE_DPMS_ON:
  67. disp_pwr_man = RREG32(RADEON_DISP_PWR_MAN);
  68. disp_pwr_man |= RADEON_AUTO_PWRUP_EN;
  69. WREG32(RADEON_DISP_PWR_MAN, disp_pwr_man);
  70. lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
  71. lvds_pll_cntl |= RADEON_LVDS_PLL_EN;
  72. WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
  73. udelay(1000);
  74. lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
  75. lvds_pll_cntl &= ~RADEON_LVDS_PLL_RESET;
  76. WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
  77. lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
  78. lvds_gen_cntl |= (RADEON_LVDS_ON | RADEON_LVDS_EN | RADEON_LVDS_DIGON | RADEON_LVDS_BLON);
  79. if (is_mac)
  80. lvds_gen_cntl |= RADEON_LVDS_BL_MOD_EN;
  81. lvds_gen_cntl &= ~(RADEON_LVDS_DISPLAY_DIS);
  82. udelay(panel_pwr_delay * 1000);
  83. WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
  84. break;
  85. case DRM_MODE_DPMS_STANDBY:
  86. case DRM_MODE_DPMS_SUSPEND:
  87. case DRM_MODE_DPMS_OFF:
  88. pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  89. WREG32_PLL_P(RADEON_PIXCLKS_CNTL, 0, ~RADEON_PIXCLK_LVDS_ALWAYS_ONb);
  90. lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
  91. lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
  92. if (is_mac) {
  93. lvds_gen_cntl &= ~RADEON_LVDS_BL_MOD_EN;
  94. WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
  95. lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_EN);
  96. } else {
  97. WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
  98. lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_BLON | RADEON_LVDS_EN | RADEON_LVDS_DIGON);
  99. }
  100. udelay(panel_pwr_delay * 1000);
  101. WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
  102. WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
  103. break;
  104. }
  105. if (rdev->is_atom_bios)
  106. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  107. else
  108. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  109. /* adjust pm to dpms change */
  110. radeon_pm_compute_clocks(rdev);
  111. }
  112. static void radeon_legacy_lvds_prepare(struct drm_encoder *encoder)
  113. {
  114. struct radeon_device *rdev = encoder->dev->dev_private;
  115. if (rdev->is_atom_bios)
  116. radeon_atom_output_lock(encoder, true);
  117. else
  118. radeon_combios_output_lock(encoder, true);
  119. radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_OFF);
  120. }
  121. static void radeon_legacy_lvds_commit(struct drm_encoder *encoder)
  122. {
  123. struct radeon_device *rdev = encoder->dev->dev_private;
  124. radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_ON);
  125. if (rdev->is_atom_bios)
  126. radeon_atom_output_lock(encoder, false);
  127. else
  128. radeon_combios_output_lock(encoder, false);
  129. }
  130. static void radeon_legacy_lvds_mode_set(struct drm_encoder *encoder,
  131. struct drm_display_mode *mode,
  132. struct drm_display_mode *adjusted_mode)
  133. {
  134. struct drm_device *dev = encoder->dev;
  135. struct radeon_device *rdev = dev->dev_private;
  136. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  137. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  138. uint32_t lvds_pll_cntl, lvds_gen_cntl, lvds_ss_gen_cntl;
  139. DRM_DEBUG("\n");
  140. lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
  141. lvds_pll_cntl &= ~RADEON_LVDS_PLL_EN;
  142. lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
  143. if (rdev->is_atom_bios) {
  144. /* LVDS_GEN_CNTL parameters are computed in LVDSEncoderControl
  145. * need to call that on resume to set up the reg properly.
  146. */
  147. radeon_encoder->pixel_clock = adjusted_mode->clock;
  148. atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE);
  149. lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
  150. } else {
  151. struct radeon_encoder_lvds *lvds = (struct radeon_encoder_lvds *)radeon_encoder->enc_priv;
  152. if (lvds) {
  153. DRM_DEBUG("bios LVDS_GEN_CNTL: 0x%x\n", lvds->lvds_gen_cntl);
  154. lvds_gen_cntl = lvds->lvds_gen_cntl;
  155. lvds_ss_gen_cntl &= ~((0xf << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
  156. (0xf << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
  157. lvds_ss_gen_cntl |= ((lvds->panel_digon_delay << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
  158. (lvds->panel_blon_delay << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
  159. } else
  160. lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
  161. }
  162. lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
  163. lvds_gen_cntl &= ~(RADEON_LVDS_ON |
  164. RADEON_LVDS_BLON |
  165. RADEON_LVDS_EN |
  166. RADEON_LVDS_RST_FM);
  167. if (ASIC_IS_R300(rdev))
  168. lvds_pll_cntl &= ~(R300_LVDS_SRC_SEL_MASK);
  169. if (radeon_crtc->crtc_id == 0) {
  170. if (ASIC_IS_R300(rdev)) {
  171. if (radeon_encoder->rmx_type != RMX_OFF)
  172. lvds_pll_cntl |= R300_LVDS_SRC_SEL_RMX;
  173. } else
  174. lvds_gen_cntl &= ~RADEON_LVDS_SEL_CRTC2;
  175. } else {
  176. if (ASIC_IS_R300(rdev))
  177. lvds_pll_cntl |= R300_LVDS_SRC_SEL_CRTC2;
  178. else
  179. lvds_gen_cntl |= RADEON_LVDS_SEL_CRTC2;
  180. }
  181. WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
  182. WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
  183. WREG32(RADEON_LVDS_SS_GEN_CNTL, lvds_ss_gen_cntl);
  184. if (rdev->family == CHIP_RV410)
  185. WREG32(RADEON_CLOCK_CNTL_INDEX, 0);
  186. if (rdev->is_atom_bios)
  187. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  188. else
  189. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  190. }
  191. static bool radeon_legacy_mode_fixup(struct drm_encoder *encoder,
  192. struct drm_display_mode *mode,
  193. struct drm_display_mode *adjusted_mode)
  194. {
  195. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  196. struct drm_device *dev = encoder->dev;
  197. struct radeon_device *rdev = dev->dev_private;
  198. /* adjust pm to upcoming mode change */
  199. radeon_pm_compute_clocks(rdev);
  200. /* set the active encoder to connector routing */
  201. radeon_encoder_set_active_device(encoder);
  202. drm_mode_set_crtcinfo(adjusted_mode, 0);
  203. /* get the native mode for LVDS */
  204. if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT)) {
  205. struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
  206. int mode_id = adjusted_mode->base.id;
  207. *adjusted_mode = *native_mode;
  208. adjusted_mode->hdisplay = mode->hdisplay;
  209. adjusted_mode->vdisplay = mode->vdisplay;
  210. adjusted_mode->crtc_hdisplay = mode->hdisplay;
  211. adjusted_mode->crtc_vdisplay = mode->vdisplay;
  212. adjusted_mode->base.id = mode_id;
  213. }
  214. return true;
  215. }
  216. static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs = {
  217. .dpms = radeon_legacy_lvds_dpms,
  218. .mode_fixup = radeon_legacy_mode_fixup,
  219. .prepare = radeon_legacy_lvds_prepare,
  220. .mode_set = radeon_legacy_lvds_mode_set,
  221. .commit = radeon_legacy_lvds_commit,
  222. .disable = radeon_legacy_encoder_disable,
  223. };
  224. static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs = {
  225. .destroy = radeon_enc_destroy,
  226. };
  227. static void radeon_legacy_primary_dac_dpms(struct drm_encoder *encoder, int mode)
  228. {
  229. struct drm_device *dev = encoder->dev;
  230. struct radeon_device *rdev = dev->dev_private;
  231. uint32_t crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
  232. uint32_t dac_cntl = RREG32(RADEON_DAC_CNTL);
  233. uint32_t dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
  234. DRM_DEBUG("\n");
  235. switch (mode) {
  236. case DRM_MODE_DPMS_ON:
  237. crtc_ext_cntl |= RADEON_CRTC_CRT_ON;
  238. dac_cntl &= ~RADEON_DAC_PDWN;
  239. dac_macro_cntl &= ~(RADEON_DAC_PDWN_R |
  240. RADEON_DAC_PDWN_G |
  241. RADEON_DAC_PDWN_B);
  242. break;
  243. case DRM_MODE_DPMS_STANDBY:
  244. case DRM_MODE_DPMS_SUSPEND:
  245. case DRM_MODE_DPMS_OFF:
  246. crtc_ext_cntl &= ~RADEON_CRTC_CRT_ON;
  247. dac_cntl |= RADEON_DAC_PDWN;
  248. dac_macro_cntl |= (RADEON_DAC_PDWN_R |
  249. RADEON_DAC_PDWN_G |
  250. RADEON_DAC_PDWN_B);
  251. break;
  252. }
  253. WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
  254. WREG32(RADEON_DAC_CNTL, dac_cntl);
  255. WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
  256. if (rdev->is_atom_bios)
  257. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  258. else
  259. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  260. /* adjust pm to dpms change */
  261. radeon_pm_compute_clocks(rdev);
  262. }
  263. static void radeon_legacy_primary_dac_prepare(struct drm_encoder *encoder)
  264. {
  265. struct radeon_device *rdev = encoder->dev->dev_private;
  266. if (rdev->is_atom_bios)
  267. radeon_atom_output_lock(encoder, true);
  268. else
  269. radeon_combios_output_lock(encoder, true);
  270. radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
  271. }
  272. static void radeon_legacy_primary_dac_commit(struct drm_encoder *encoder)
  273. {
  274. struct radeon_device *rdev = encoder->dev->dev_private;
  275. radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_ON);
  276. if (rdev->is_atom_bios)
  277. radeon_atom_output_lock(encoder, false);
  278. else
  279. radeon_combios_output_lock(encoder, false);
  280. }
  281. static void radeon_legacy_primary_dac_mode_set(struct drm_encoder *encoder,
  282. struct drm_display_mode *mode,
  283. struct drm_display_mode *adjusted_mode)
  284. {
  285. struct drm_device *dev = encoder->dev;
  286. struct radeon_device *rdev = dev->dev_private;
  287. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  288. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  289. uint32_t disp_output_cntl, dac_cntl, dac2_cntl, dac_macro_cntl;
  290. DRM_DEBUG("\n");
  291. if (radeon_crtc->crtc_id == 0) {
  292. if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) {
  293. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) &
  294. ~(RADEON_DISP_DAC_SOURCE_MASK);
  295. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  296. } else {
  297. dac2_cntl = RREG32(RADEON_DAC_CNTL2) & ~(RADEON_DAC2_DAC_CLK_SEL);
  298. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  299. }
  300. } else {
  301. if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) {
  302. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) &
  303. ~(RADEON_DISP_DAC_SOURCE_MASK);
  304. disp_output_cntl |= RADEON_DISP_DAC_SOURCE_CRTC2;
  305. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  306. } else {
  307. dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC_CLK_SEL;
  308. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  309. }
  310. }
  311. dac_cntl = (RADEON_DAC_MASK_ALL |
  312. RADEON_DAC_VGA_ADR_EN |
  313. /* TODO 6-bits */
  314. RADEON_DAC_8BIT_EN);
  315. WREG32_P(RADEON_DAC_CNTL,
  316. dac_cntl,
  317. RADEON_DAC_RANGE_CNTL |
  318. RADEON_DAC_BLANKING);
  319. if (radeon_encoder->enc_priv) {
  320. struct radeon_encoder_primary_dac *p_dac = (struct radeon_encoder_primary_dac *)radeon_encoder->enc_priv;
  321. dac_macro_cntl = p_dac->ps2_pdac_adj;
  322. } else
  323. dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
  324. dac_macro_cntl |= RADEON_DAC_PDWN_R | RADEON_DAC_PDWN_G | RADEON_DAC_PDWN_B;
  325. WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
  326. if (rdev->is_atom_bios)
  327. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  328. else
  329. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  330. }
  331. static enum drm_connector_status radeon_legacy_primary_dac_detect(struct drm_encoder *encoder,
  332. struct drm_connector *connector)
  333. {
  334. struct drm_device *dev = encoder->dev;
  335. struct radeon_device *rdev = dev->dev_private;
  336. uint32_t vclk_ecp_cntl, crtc_ext_cntl;
  337. uint32_t dac_ext_cntl, dac_cntl, dac_macro_cntl, tmp;
  338. enum drm_connector_status found = connector_status_disconnected;
  339. bool color = true;
  340. /* save the regs we need */
  341. vclk_ecp_cntl = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
  342. crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
  343. dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
  344. dac_cntl = RREG32(RADEON_DAC_CNTL);
  345. dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
  346. tmp = vclk_ecp_cntl &
  347. ~(RADEON_PIXCLK_ALWAYS_ONb | RADEON_PIXCLK_DAC_ALWAYS_ONb);
  348. WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
  349. tmp = crtc_ext_cntl | RADEON_CRTC_CRT_ON;
  350. WREG32(RADEON_CRTC_EXT_CNTL, tmp);
  351. tmp = RADEON_DAC_FORCE_BLANK_OFF_EN |
  352. RADEON_DAC_FORCE_DATA_EN;
  353. if (color)
  354. tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
  355. else
  356. tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
  357. if (ASIC_IS_R300(rdev))
  358. tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
  359. else
  360. tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
  361. WREG32(RADEON_DAC_EXT_CNTL, tmp);
  362. tmp = dac_cntl & ~(RADEON_DAC_RANGE_CNTL_MASK | RADEON_DAC_PDWN);
  363. tmp |= RADEON_DAC_RANGE_CNTL_PS2 | RADEON_DAC_CMP_EN;
  364. WREG32(RADEON_DAC_CNTL, tmp);
  365. tmp &= ~(RADEON_DAC_PDWN_R |
  366. RADEON_DAC_PDWN_G |
  367. RADEON_DAC_PDWN_B);
  368. WREG32(RADEON_DAC_MACRO_CNTL, tmp);
  369. udelay(2000);
  370. if (RREG32(RADEON_DAC_CNTL) & RADEON_DAC_CMP_OUTPUT)
  371. found = connector_status_connected;
  372. /* restore the regs we used */
  373. WREG32(RADEON_DAC_CNTL, dac_cntl);
  374. WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
  375. WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
  376. WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
  377. WREG32_PLL(RADEON_VCLK_ECP_CNTL, vclk_ecp_cntl);
  378. return found;
  379. }
  380. static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs = {
  381. .dpms = radeon_legacy_primary_dac_dpms,
  382. .mode_fixup = radeon_legacy_mode_fixup,
  383. .prepare = radeon_legacy_primary_dac_prepare,
  384. .mode_set = radeon_legacy_primary_dac_mode_set,
  385. .commit = radeon_legacy_primary_dac_commit,
  386. .detect = radeon_legacy_primary_dac_detect,
  387. .disable = radeon_legacy_encoder_disable,
  388. };
  389. static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs = {
  390. .destroy = radeon_enc_destroy,
  391. };
  392. static void radeon_legacy_tmds_int_dpms(struct drm_encoder *encoder, int mode)
  393. {
  394. struct drm_device *dev = encoder->dev;
  395. struct radeon_device *rdev = dev->dev_private;
  396. uint32_t fp_gen_cntl = RREG32(RADEON_FP_GEN_CNTL);
  397. DRM_DEBUG("\n");
  398. switch (mode) {
  399. case DRM_MODE_DPMS_ON:
  400. fp_gen_cntl |= (RADEON_FP_FPON | RADEON_FP_TMDS_EN);
  401. break;
  402. case DRM_MODE_DPMS_STANDBY:
  403. case DRM_MODE_DPMS_SUSPEND:
  404. case DRM_MODE_DPMS_OFF:
  405. fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
  406. break;
  407. }
  408. WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl);
  409. if (rdev->is_atom_bios)
  410. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  411. else
  412. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  413. /* adjust pm to dpms change */
  414. radeon_pm_compute_clocks(rdev);
  415. }
  416. static void radeon_legacy_tmds_int_prepare(struct drm_encoder *encoder)
  417. {
  418. struct radeon_device *rdev = encoder->dev->dev_private;
  419. if (rdev->is_atom_bios)
  420. radeon_atom_output_lock(encoder, true);
  421. else
  422. radeon_combios_output_lock(encoder, true);
  423. radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_OFF);
  424. }
  425. static void radeon_legacy_tmds_int_commit(struct drm_encoder *encoder)
  426. {
  427. struct radeon_device *rdev = encoder->dev->dev_private;
  428. radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_ON);
  429. if (rdev->is_atom_bios)
  430. radeon_atom_output_lock(encoder, true);
  431. else
  432. radeon_combios_output_lock(encoder, true);
  433. }
  434. static void radeon_legacy_tmds_int_mode_set(struct drm_encoder *encoder,
  435. struct drm_display_mode *mode,
  436. struct drm_display_mode *adjusted_mode)
  437. {
  438. struct drm_device *dev = encoder->dev;
  439. struct radeon_device *rdev = dev->dev_private;
  440. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  441. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  442. uint32_t tmp, tmds_pll_cntl, tmds_transmitter_cntl, fp_gen_cntl;
  443. int i;
  444. DRM_DEBUG("\n");
  445. tmp = tmds_pll_cntl = RREG32(RADEON_TMDS_PLL_CNTL);
  446. tmp &= 0xfffff;
  447. if (rdev->family == CHIP_RV280) {
  448. /* bit 22 of TMDS_PLL_CNTL is read-back inverted */
  449. tmp ^= (1 << 22);
  450. tmds_pll_cntl ^= (1 << 22);
  451. }
  452. if (radeon_encoder->enc_priv) {
  453. struct radeon_encoder_int_tmds *tmds = (struct radeon_encoder_int_tmds *)radeon_encoder->enc_priv;
  454. for (i = 0; i < 4; i++) {
  455. if (tmds->tmds_pll[i].freq == 0)
  456. break;
  457. if ((uint32_t)(mode->clock / 10) < tmds->tmds_pll[i].freq) {
  458. tmp = tmds->tmds_pll[i].value ;
  459. break;
  460. }
  461. }
  462. }
  463. if (ASIC_IS_R300(rdev) || (rdev->family == CHIP_RV280)) {
  464. if (tmp & 0xfff00000)
  465. tmds_pll_cntl = tmp;
  466. else {
  467. tmds_pll_cntl &= 0xfff00000;
  468. tmds_pll_cntl |= tmp;
  469. }
  470. } else
  471. tmds_pll_cntl = tmp;
  472. tmds_transmitter_cntl = RREG32(RADEON_TMDS_TRANSMITTER_CNTL) &
  473. ~(RADEON_TMDS_TRANSMITTER_PLLRST);
  474. if (rdev->family == CHIP_R200 ||
  475. rdev->family == CHIP_R100 ||
  476. ASIC_IS_R300(rdev))
  477. tmds_transmitter_cntl &= ~(RADEON_TMDS_TRANSMITTER_PLLEN);
  478. else /* RV chips got this bit reversed */
  479. tmds_transmitter_cntl |= RADEON_TMDS_TRANSMITTER_PLLEN;
  480. fp_gen_cntl = (RREG32(RADEON_FP_GEN_CNTL) |
  481. (RADEON_FP_CRTC_DONT_SHADOW_VPAR |
  482. RADEON_FP_CRTC_DONT_SHADOW_HEND));
  483. fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
  484. fp_gen_cntl &= ~(RADEON_FP_RMX_HVSYNC_CONTROL_EN |
  485. RADEON_FP_DFP_SYNC_SEL |
  486. RADEON_FP_CRT_SYNC_SEL |
  487. RADEON_FP_CRTC_LOCK_8DOT |
  488. RADEON_FP_USE_SHADOW_EN |
  489. RADEON_FP_CRTC_USE_SHADOW_VEND |
  490. RADEON_FP_CRT_SYNC_ALT);
  491. if (1) /* FIXME rgbBits == 8 */
  492. fp_gen_cntl |= RADEON_FP_PANEL_FORMAT; /* 24 bit format */
  493. else
  494. fp_gen_cntl &= ~RADEON_FP_PANEL_FORMAT;/* 18 bit format */
  495. if (radeon_crtc->crtc_id == 0) {
  496. if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) {
  497. fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
  498. if (radeon_encoder->rmx_type != RMX_OFF)
  499. fp_gen_cntl |= R200_FP_SOURCE_SEL_RMX;
  500. else
  501. fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC1;
  502. } else
  503. fp_gen_cntl &= ~RADEON_FP_SEL_CRTC2;
  504. } else {
  505. if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) {
  506. fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
  507. fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC2;
  508. } else
  509. fp_gen_cntl |= RADEON_FP_SEL_CRTC2;
  510. }
  511. WREG32(RADEON_TMDS_PLL_CNTL, tmds_pll_cntl);
  512. WREG32(RADEON_TMDS_TRANSMITTER_CNTL, tmds_transmitter_cntl);
  513. WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl);
  514. if (rdev->is_atom_bios)
  515. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  516. else
  517. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  518. }
  519. static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs = {
  520. .dpms = radeon_legacy_tmds_int_dpms,
  521. .mode_fixup = radeon_legacy_mode_fixup,
  522. .prepare = radeon_legacy_tmds_int_prepare,
  523. .mode_set = radeon_legacy_tmds_int_mode_set,
  524. .commit = radeon_legacy_tmds_int_commit,
  525. .disable = radeon_legacy_encoder_disable,
  526. };
  527. static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs = {
  528. .destroy = radeon_enc_destroy,
  529. };
  530. static void radeon_legacy_tmds_ext_dpms(struct drm_encoder *encoder, int mode)
  531. {
  532. struct drm_device *dev = encoder->dev;
  533. struct radeon_device *rdev = dev->dev_private;
  534. uint32_t fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  535. DRM_DEBUG("\n");
  536. switch (mode) {
  537. case DRM_MODE_DPMS_ON:
  538. fp2_gen_cntl &= ~RADEON_FP2_BLANK_EN;
  539. fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  540. break;
  541. case DRM_MODE_DPMS_STANDBY:
  542. case DRM_MODE_DPMS_SUSPEND:
  543. case DRM_MODE_DPMS_OFF:
  544. fp2_gen_cntl |= RADEON_FP2_BLANK_EN;
  545. fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  546. break;
  547. }
  548. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  549. if (rdev->is_atom_bios)
  550. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  551. else
  552. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  553. /* adjust pm to dpms change */
  554. radeon_pm_compute_clocks(rdev);
  555. }
  556. static void radeon_legacy_tmds_ext_prepare(struct drm_encoder *encoder)
  557. {
  558. struct radeon_device *rdev = encoder->dev->dev_private;
  559. if (rdev->is_atom_bios)
  560. radeon_atom_output_lock(encoder, true);
  561. else
  562. radeon_combios_output_lock(encoder, true);
  563. radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_OFF);
  564. }
  565. static void radeon_legacy_tmds_ext_commit(struct drm_encoder *encoder)
  566. {
  567. struct radeon_device *rdev = encoder->dev->dev_private;
  568. radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_ON);
  569. if (rdev->is_atom_bios)
  570. radeon_atom_output_lock(encoder, false);
  571. else
  572. radeon_combios_output_lock(encoder, false);
  573. }
  574. static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder *encoder,
  575. struct drm_display_mode *mode,
  576. struct drm_display_mode *adjusted_mode)
  577. {
  578. struct drm_device *dev = encoder->dev;
  579. struct radeon_device *rdev = dev->dev_private;
  580. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  581. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  582. uint32_t fp2_gen_cntl;
  583. DRM_DEBUG("\n");
  584. if (rdev->is_atom_bios) {
  585. radeon_encoder->pixel_clock = adjusted_mode->clock;
  586. atombios_external_tmds_setup(encoder, ATOM_ENABLE);
  587. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  588. } else {
  589. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  590. if (1) /* FIXME rgbBits == 8 */
  591. fp2_gen_cntl |= RADEON_FP2_PANEL_FORMAT; /* 24 bit format, */
  592. else
  593. fp2_gen_cntl &= ~RADEON_FP2_PANEL_FORMAT;/* 18 bit format, */
  594. fp2_gen_cntl &= ~(RADEON_FP2_ON |
  595. RADEON_FP2_DVO_EN |
  596. RADEON_FP2_DVO_RATE_SEL_SDR);
  597. /* XXX: these are oem specific */
  598. if (ASIC_IS_R300(rdev)) {
  599. if ((dev->pdev->device == 0x4850) &&
  600. (dev->pdev->subsystem_vendor == 0x1028) &&
  601. (dev->pdev->subsystem_device == 0x2001)) /* Dell Inspiron 8600 */
  602. fp2_gen_cntl |= R300_FP2_DVO_CLOCK_MODE_SINGLE;
  603. else
  604. fp2_gen_cntl |= RADEON_FP2_PAD_FLOP_EN | R300_FP2_DVO_CLOCK_MODE_SINGLE;
  605. /*if (mode->clock > 165000)
  606. fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/
  607. }
  608. if (!radeon_combios_external_tmds_setup(encoder))
  609. radeon_external_tmds_setup(encoder);
  610. }
  611. if (radeon_crtc->crtc_id == 0) {
  612. if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) {
  613. fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
  614. if (radeon_encoder->rmx_type != RMX_OFF)
  615. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_RMX;
  616. else
  617. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC1;
  618. } else
  619. fp2_gen_cntl &= ~RADEON_FP2_SRC_SEL_CRTC2;
  620. } else {
  621. if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) {
  622. fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
  623. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
  624. } else
  625. fp2_gen_cntl |= RADEON_FP2_SRC_SEL_CRTC2;
  626. }
  627. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  628. if (rdev->is_atom_bios)
  629. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  630. else
  631. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  632. }
  633. static void radeon_ext_tmds_enc_destroy(struct drm_encoder *encoder)
  634. {
  635. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  636. struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
  637. if (tmds) {
  638. if (tmds->i2c_bus)
  639. radeon_i2c_destroy(tmds->i2c_bus);
  640. }
  641. kfree(radeon_encoder->enc_priv);
  642. drm_encoder_cleanup(encoder);
  643. kfree(radeon_encoder);
  644. }
  645. static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs = {
  646. .dpms = radeon_legacy_tmds_ext_dpms,
  647. .mode_fixup = radeon_legacy_mode_fixup,
  648. .prepare = radeon_legacy_tmds_ext_prepare,
  649. .mode_set = radeon_legacy_tmds_ext_mode_set,
  650. .commit = radeon_legacy_tmds_ext_commit,
  651. .disable = radeon_legacy_encoder_disable,
  652. };
  653. static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs = {
  654. .destroy = radeon_ext_tmds_enc_destroy,
  655. };
  656. static void radeon_legacy_tv_dac_dpms(struct drm_encoder *encoder, int mode)
  657. {
  658. struct drm_device *dev = encoder->dev;
  659. struct radeon_device *rdev = dev->dev_private;
  660. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  661. uint32_t fp2_gen_cntl = 0, crtc2_gen_cntl = 0, tv_dac_cntl = 0;
  662. uint32_t tv_master_cntl = 0;
  663. bool is_tv;
  664. DRM_DEBUG("\n");
  665. is_tv = radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT ? true : false;
  666. if (rdev->family == CHIP_R200)
  667. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  668. else {
  669. if (is_tv)
  670. tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL);
  671. else
  672. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
  673. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  674. }
  675. switch (mode) {
  676. case DRM_MODE_DPMS_ON:
  677. if (rdev->family == CHIP_R200) {
  678. fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  679. } else {
  680. if (is_tv)
  681. tv_master_cntl |= RADEON_TV_ON;
  682. else
  683. crtc2_gen_cntl |= RADEON_CRTC2_CRT2_ON;
  684. if (rdev->family == CHIP_R420 ||
  685. rdev->family == CHIP_R423 ||
  686. rdev->family == CHIP_RV410)
  687. tv_dac_cntl &= ~(R420_TV_DAC_RDACPD |
  688. R420_TV_DAC_GDACPD |
  689. R420_TV_DAC_BDACPD |
  690. RADEON_TV_DAC_BGSLEEP);
  691. else
  692. tv_dac_cntl &= ~(RADEON_TV_DAC_RDACPD |
  693. RADEON_TV_DAC_GDACPD |
  694. RADEON_TV_DAC_BDACPD |
  695. RADEON_TV_DAC_BGSLEEP);
  696. }
  697. break;
  698. case DRM_MODE_DPMS_STANDBY:
  699. case DRM_MODE_DPMS_SUSPEND:
  700. case DRM_MODE_DPMS_OFF:
  701. if (rdev->family == CHIP_R200)
  702. fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  703. else {
  704. if (is_tv)
  705. tv_master_cntl &= ~RADEON_TV_ON;
  706. else
  707. crtc2_gen_cntl &= ~RADEON_CRTC2_CRT2_ON;
  708. if (rdev->family == CHIP_R420 ||
  709. rdev->family == CHIP_R423 ||
  710. rdev->family == CHIP_RV410)
  711. tv_dac_cntl |= (R420_TV_DAC_RDACPD |
  712. R420_TV_DAC_GDACPD |
  713. R420_TV_DAC_BDACPD |
  714. RADEON_TV_DAC_BGSLEEP);
  715. else
  716. tv_dac_cntl |= (RADEON_TV_DAC_RDACPD |
  717. RADEON_TV_DAC_GDACPD |
  718. RADEON_TV_DAC_BDACPD |
  719. RADEON_TV_DAC_BGSLEEP);
  720. }
  721. break;
  722. }
  723. if (rdev->family == CHIP_R200) {
  724. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  725. } else {
  726. if (is_tv)
  727. WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl);
  728. else
  729. WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
  730. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  731. }
  732. if (rdev->is_atom_bios)
  733. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  734. else
  735. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  736. /* adjust pm to dpms change */
  737. radeon_pm_compute_clocks(rdev);
  738. }
  739. static void radeon_legacy_tv_dac_prepare(struct drm_encoder *encoder)
  740. {
  741. struct radeon_device *rdev = encoder->dev->dev_private;
  742. if (rdev->is_atom_bios)
  743. radeon_atom_output_lock(encoder, true);
  744. else
  745. radeon_combios_output_lock(encoder, true);
  746. radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
  747. }
  748. static void radeon_legacy_tv_dac_commit(struct drm_encoder *encoder)
  749. {
  750. struct radeon_device *rdev = encoder->dev->dev_private;
  751. radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_ON);
  752. if (rdev->is_atom_bios)
  753. radeon_atom_output_lock(encoder, true);
  754. else
  755. radeon_combios_output_lock(encoder, true);
  756. }
  757. static void radeon_legacy_tv_dac_mode_set(struct drm_encoder *encoder,
  758. struct drm_display_mode *mode,
  759. struct drm_display_mode *adjusted_mode)
  760. {
  761. struct drm_device *dev = encoder->dev;
  762. struct radeon_device *rdev = dev->dev_private;
  763. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  764. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  765. struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv;
  766. uint32_t tv_dac_cntl, gpiopad_a = 0, dac2_cntl, disp_output_cntl = 0;
  767. uint32_t disp_hw_debug = 0, fp2_gen_cntl = 0, disp_tv_out_cntl = 0;
  768. bool is_tv = false;
  769. DRM_DEBUG("\n");
  770. is_tv = radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT ? true : false;
  771. if (rdev->family != CHIP_R200) {
  772. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  773. if (rdev->family == CHIP_R420 ||
  774. rdev->family == CHIP_R423 ||
  775. rdev->family == CHIP_RV410) {
  776. tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
  777. RADEON_TV_DAC_BGADJ_MASK |
  778. R420_TV_DAC_DACADJ_MASK |
  779. R420_TV_DAC_RDACPD |
  780. R420_TV_DAC_GDACPD |
  781. R420_TV_DAC_BDACPD |
  782. R420_TV_DAC_TVENABLE);
  783. } else {
  784. tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
  785. RADEON_TV_DAC_BGADJ_MASK |
  786. RADEON_TV_DAC_DACADJ_MASK |
  787. RADEON_TV_DAC_RDACPD |
  788. RADEON_TV_DAC_GDACPD |
  789. RADEON_TV_DAC_BDACPD);
  790. }
  791. tv_dac_cntl |= RADEON_TV_DAC_NBLANK | RADEON_TV_DAC_NHOLD;
  792. if (is_tv) {
  793. if (tv_dac->tv_std == TV_STD_NTSC ||
  794. tv_dac->tv_std == TV_STD_NTSC_J ||
  795. tv_dac->tv_std == TV_STD_PAL_M ||
  796. tv_dac->tv_std == TV_STD_PAL_60)
  797. tv_dac_cntl |= tv_dac->ntsc_tvdac_adj;
  798. else
  799. tv_dac_cntl |= tv_dac->pal_tvdac_adj;
  800. if (tv_dac->tv_std == TV_STD_NTSC ||
  801. tv_dac->tv_std == TV_STD_NTSC_J)
  802. tv_dac_cntl |= RADEON_TV_DAC_STD_NTSC;
  803. else
  804. tv_dac_cntl |= RADEON_TV_DAC_STD_PAL;
  805. } else
  806. tv_dac_cntl |= (RADEON_TV_DAC_STD_PS2 |
  807. tv_dac->ps2_tvdac_adj);
  808. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  809. }
  810. if (ASIC_IS_R300(rdev)) {
  811. gpiopad_a = RREG32(RADEON_GPIOPAD_A) | 1;
  812. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
  813. }
  814. if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev))
  815. disp_tv_out_cntl = RREG32(RADEON_DISP_TV_OUT_CNTL);
  816. else
  817. disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG);
  818. if (rdev->family == CHIP_R200)
  819. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  820. if (is_tv) {
  821. uint32_t dac_cntl;
  822. dac_cntl = RREG32(RADEON_DAC_CNTL);
  823. dac_cntl &= ~RADEON_DAC_TVO_EN;
  824. WREG32(RADEON_DAC_CNTL, dac_cntl);
  825. if (ASIC_IS_R300(rdev))
  826. gpiopad_a = RREG32(RADEON_GPIOPAD_A) & ~1;
  827. dac2_cntl = RREG32(RADEON_DAC_CNTL2) & ~RADEON_DAC2_DAC2_CLK_SEL;
  828. if (radeon_crtc->crtc_id == 0) {
  829. if (ASIC_IS_R300(rdev)) {
  830. disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
  831. disp_output_cntl |= (RADEON_DISP_TVDAC_SOURCE_CRTC |
  832. RADEON_DISP_TV_SOURCE_CRTC);
  833. }
  834. if (rdev->family >= CHIP_R200) {
  835. disp_tv_out_cntl &= ~RADEON_DISP_TV_PATH_SRC_CRTC2;
  836. } else {
  837. disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
  838. }
  839. } else {
  840. if (ASIC_IS_R300(rdev)) {
  841. disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
  842. disp_output_cntl |= RADEON_DISP_TV_SOURCE_CRTC;
  843. }
  844. if (rdev->family >= CHIP_R200) {
  845. disp_tv_out_cntl |= RADEON_DISP_TV_PATH_SRC_CRTC2;
  846. } else {
  847. disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL;
  848. }
  849. }
  850. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  851. } else {
  852. dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC2_CLK_SEL;
  853. if (radeon_crtc->crtc_id == 0) {
  854. if (ASIC_IS_R300(rdev)) {
  855. disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
  856. disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC;
  857. } else if (rdev->family == CHIP_R200) {
  858. fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
  859. RADEON_FP2_DVO_RATE_SEL_SDR);
  860. } else
  861. disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
  862. } else {
  863. if (ASIC_IS_R300(rdev)) {
  864. disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
  865. disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
  866. } else if (rdev->family == CHIP_R200) {
  867. fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
  868. RADEON_FP2_DVO_RATE_SEL_SDR);
  869. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
  870. } else
  871. disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL;
  872. }
  873. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  874. }
  875. if (ASIC_IS_R300(rdev)) {
  876. WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
  877. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  878. }
  879. if (rdev->family >= CHIP_R200)
  880. WREG32(RADEON_DISP_TV_OUT_CNTL, disp_tv_out_cntl);
  881. else
  882. WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
  883. if (rdev->family == CHIP_R200)
  884. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  885. if (is_tv)
  886. radeon_legacy_tv_mode_set(encoder, mode, adjusted_mode);
  887. if (rdev->is_atom_bios)
  888. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  889. else
  890. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  891. }
  892. static bool r300_legacy_tv_detect(struct drm_encoder *encoder,
  893. struct drm_connector *connector)
  894. {
  895. struct drm_device *dev = encoder->dev;
  896. struct radeon_device *rdev = dev->dev_private;
  897. uint32_t crtc2_gen_cntl, tv_dac_cntl, dac_cntl2, dac_ext_cntl;
  898. uint32_t disp_output_cntl, gpiopad_a, tmp;
  899. bool found = false;
  900. /* save regs needed */
  901. gpiopad_a = RREG32(RADEON_GPIOPAD_A);
  902. dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
  903. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
  904. dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
  905. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  906. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
  907. WREG32_P(RADEON_GPIOPAD_A, 0, ~1);
  908. WREG32(RADEON_DAC_CNTL2, RADEON_DAC2_DAC2_CLK_SEL);
  909. WREG32(RADEON_CRTC2_GEN_CNTL,
  910. RADEON_CRTC2_CRT2_ON | RADEON_CRTC2_VSYNC_TRISTAT);
  911. tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK;
  912. tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
  913. WREG32(RADEON_DISP_OUTPUT_CNTL, tmp);
  914. WREG32(RADEON_DAC_EXT_CNTL,
  915. RADEON_DAC2_FORCE_BLANK_OFF_EN |
  916. RADEON_DAC2_FORCE_DATA_EN |
  917. RADEON_DAC_FORCE_DATA_SEL_RGB |
  918. (0xec << RADEON_DAC_FORCE_DATA_SHIFT));
  919. WREG32(RADEON_TV_DAC_CNTL,
  920. RADEON_TV_DAC_STD_NTSC |
  921. (8 << RADEON_TV_DAC_BGADJ_SHIFT) |
  922. (6 << RADEON_TV_DAC_DACADJ_SHIFT));
  923. RREG32(RADEON_TV_DAC_CNTL);
  924. mdelay(4);
  925. WREG32(RADEON_TV_DAC_CNTL,
  926. RADEON_TV_DAC_NBLANK |
  927. RADEON_TV_DAC_NHOLD |
  928. RADEON_TV_MONITOR_DETECT_EN |
  929. RADEON_TV_DAC_STD_NTSC |
  930. (8 << RADEON_TV_DAC_BGADJ_SHIFT) |
  931. (6 << RADEON_TV_DAC_DACADJ_SHIFT));
  932. RREG32(RADEON_TV_DAC_CNTL);
  933. mdelay(6);
  934. tmp = RREG32(RADEON_TV_DAC_CNTL);
  935. if ((tmp & RADEON_TV_DAC_GDACDET) != 0) {
  936. found = true;
  937. DRM_DEBUG("S-video TV connection detected\n");
  938. } else if ((tmp & RADEON_TV_DAC_BDACDET) != 0) {
  939. found = true;
  940. DRM_DEBUG("Composite TV connection detected\n");
  941. }
  942. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  943. WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
  944. WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
  945. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  946. WREG32(RADEON_DAC_CNTL2, dac_cntl2);
  947. WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
  948. return found;
  949. }
  950. static bool radeon_legacy_tv_detect(struct drm_encoder *encoder,
  951. struct drm_connector *connector)
  952. {
  953. struct drm_device *dev = encoder->dev;
  954. struct radeon_device *rdev = dev->dev_private;
  955. uint32_t tv_dac_cntl, dac_cntl2;
  956. uint32_t config_cntl, tv_pre_dac_mux_cntl, tv_master_cntl, tmp;
  957. bool found = false;
  958. if (ASIC_IS_R300(rdev))
  959. return r300_legacy_tv_detect(encoder, connector);
  960. dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
  961. tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL);
  962. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  963. config_cntl = RREG32(RADEON_CONFIG_CNTL);
  964. tv_pre_dac_mux_cntl = RREG32(RADEON_TV_PRE_DAC_MUX_CNTL);
  965. tmp = dac_cntl2 & ~RADEON_DAC2_DAC2_CLK_SEL;
  966. WREG32(RADEON_DAC_CNTL2, tmp);
  967. tmp = tv_master_cntl | RADEON_TV_ON;
  968. tmp &= ~(RADEON_TV_ASYNC_RST |
  969. RADEON_RESTART_PHASE_FIX |
  970. RADEON_CRT_FIFO_CE_EN |
  971. RADEON_TV_FIFO_CE_EN |
  972. RADEON_RE_SYNC_NOW_SEL_MASK);
  973. tmp |= RADEON_TV_FIFO_ASYNC_RST | RADEON_CRT_ASYNC_RST;
  974. WREG32(RADEON_TV_MASTER_CNTL, tmp);
  975. tmp = RADEON_TV_DAC_NBLANK | RADEON_TV_DAC_NHOLD |
  976. RADEON_TV_MONITOR_DETECT_EN | RADEON_TV_DAC_STD_NTSC |
  977. (8 << RADEON_TV_DAC_BGADJ_SHIFT);
  978. if (config_cntl & RADEON_CFG_ATI_REV_ID_MASK)
  979. tmp |= (4 << RADEON_TV_DAC_DACADJ_SHIFT);
  980. else
  981. tmp |= (8 << RADEON_TV_DAC_DACADJ_SHIFT);
  982. WREG32(RADEON_TV_DAC_CNTL, tmp);
  983. tmp = RADEON_C_GRN_EN | RADEON_CMP_BLU_EN |
  984. RADEON_RED_MX_FORCE_DAC_DATA |
  985. RADEON_GRN_MX_FORCE_DAC_DATA |
  986. RADEON_BLU_MX_FORCE_DAC_DATA |
  987. (0x109 << RADEON_TV_FORCE_DAC_DATA_SHIFT);
  988. WREG32(RADEON_TV_PRE_DAC_MUX_CNTL, tmp);
  989. mdelay(3);
  990. tmp = RREG32(RADEON_TV_DAC_CNTL);
  991. if (tmp & RADEON_TV_DAC_GDACDET) {
  992. found = true;
  993. DRM_DEBUG("S-video TV connection detected\n");
  994. } else if ((tmp & RADEON_TV_DAC_BDACDET) != 0) {
  995. found = true;
  996. DRM_DEBUG("Composite TV connection detected\n");
  997. }
  998. WREG32(RADEON_TV_PRE_DAC_MUX_CNTL, tv_pre_dac_mux_cntl);
  999. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  1000. WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl);
  1001. WREG32(RADEON_DAC_CNTL2, dac_cntl2);
  1002. return found;
  1003. }
  1004. static enum drm_connector_status radeon_legacy_tv_dac_detect(struct drm_encoder *encoder,
  1005. struct drm_connector *connector)
  1006. {
  1007. struct drm_device *dev = encoder->dev;
  1008. struct radeon_device *rdev = dev->dev_private;
  1009. uint32_t crtc2_gen_cntl, tv_dac_cntl, dac_cntl2, dac_ext_cntl;
  1010. uint32_t disp_hw_debug, disp_output_cntl, gpiopad_a, pixclks_cntl, tmp;
  1011. enum drm_connector_status found = connector_status_disconnected;
  1012. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1013. struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv;
  1014. bool color = true;
  1015. if (connector->connector_type == DRM_MODE_CONNECTOR_SVIDEO ||
  1016. connector->connector_type == DRM_MODE_CONNECTOR_Composite ||
  1017. connector->connector_type == DRM_MODE_CONNECTOR_9PinDIN) {
  1018. bool tv_detect;
  1019. if (radeon_encoder->active_device && !(radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT))
  1020. return connector_status_disconnected;
  1021. tv_detect = radeon_legacy_tv_detect(encoder, connector);
  1022. if (tv_detect && tv_dac)
  1023. found = connector_status_connected;
  1024. return found;
  1025. }
  1026. /* don't probe if the encoder is being used for something else not CRT related */
  1027. if (radeon_encoder->active_device && !(radeon_encoder->active_device & ATOM_DEVICE_CRT_SUPPORT)) {
  1028. DRM_INFO("not detecting due to %08x\n", radeon_encoder->active_device);
  1029. return connector_status_disconnected;
  1030. }
  1031. /* save the regs we need */
  1032. pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  1033. gpiopad_a = ASIC_IS_R300(rdev) ? RREG32(RADEON_GPIOPAD_A) : 0;
  1034. disp_output_cntl = ASIC_IS_R300(rdev) ? RREG32(RADEON_DISP_OUTPUT_CNTL) : 0;
  1035. disp_hw_debug = ASIC_IS_R300(rdev) ? 0 : RREG32(RADEON_DISP_HW_DEBUG);
  1036. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
  1037. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  1038. dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
  1039. dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
  1040. tmp = pixclks_cntl & ~(RADEON_PIX2CLK_ALWAYS_ONb
  1041. | RADEON_PIX2CLK_DAC_ALWAYS_ONb);
  1042. WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
  1043. if (ASIC_IS_R300(rdev))
  1044. WREG32_P(RADEON_GPIOPAD_A, 1, ~1);
  1045. tmp = crtc2_gen_cntl & ~RADEON_CRTC2_PIX_WIDTH_MASK;
  1046. tmp |= RADEON_CRTC2_CRT2_ON |
  1047. (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT);
  1048. WREG32(RADEON_CRTC2_GEN_CNTL, tmp);
  1049. if (ASIC_IS_R300(rdev)) {
  1050. tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK;
  1051. tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
  1052. WREG32(RADEON_DISP_OUTPUT_CNTL, tmp);
  1053. } else {
  1054. tmp = disp_hw_debug & ~RADEON_CRT2_DISP1_SEL;
  1055. WREG32(RADEON_DISP_HW_DEBUG, tmp);
  1056. }
  1057. tmp = RADEON_TV_DAC_NBLANK |
  1058. RADEON_TV_DAC_NHOLD |
  1059. RADEON_TV_MONITOR_DETECT_EN |
  1060. RADEON_TV_DAC_STD_PS2;
  1061. WREG32(RADEON_TV_DAC_CNTL, tmp);
  1062. tmp = RADEON_DAC2_FORCE_BLANK_OFF_EN |
  1063. RADEON_DAC2_FORCE_DATA_EN;
  1064. if (color)
  1065. tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
  1066. else
  1067. tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
  1068. if (ASIC_IS_R300(rdev))
  1069. tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
  1070. else
  1071. tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
  1072. WREG32(RADEON_DAC_EXT_CNTL, tmp);
  1073. tmp = dac_cntl2 | RADEON_DAC2_DAC2_CLK_SEL | RADEON_DAC2_CMP_EN;
  1074. WREG32(RADEON_DAC_CNTL2, tmp);
  1075. udelay(10000);
  1076. if (ASIC_IS_R300(rdev)) {
  1077. if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUT_B)
  1078. found = connector_status_connected;
  1079. } else {
  1080. if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUTPUT)
  1081. found = connector_status_connected;
  1082. }
  1083. /* restore regs we used */
  1084. WREG32(RADEON_DAC_CNTL2, dac_cntl2);
  1085. WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
  1086. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  1087. WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
  1088. if (ASIC_IS_R300(rdev)) {
  1089. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  1090. WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
  1091. } else {
  1092. WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
  1093. }
  1094. WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
  1095. return found;
  1096. }
  1097. static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs = {
  1098. .dpms = radeon_legacy_tv_dac_dpms,
  1099. .mode_fixup = radeon_legacy_mode_fixup,
  1100. .prepare = radeon_legacy_tv_dac_prepare,
  1101. .mode_set = radeon_legacy_tv_dac_mode_set,
  1102. .commit = radeon_legacy_tv_dac_commit,
  1103. .detect = radeon_legacy_tv_dac_detect,
  1104. .disable = radeon_legacy_encoder_disable,
  1105. };
  1106. static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs = {
  1107. .destroy = radeon_enc_destroy,
  1108. };
  1109. static struct radeon_encoder_int_tmds *radeon_legacy_get_tmds_info(struct radeon_encoder *encoder)
  1110. {
  1111. struct drm_device *dev = encoder->base.dev;
  1112. struct radeon_device *rdev = dev->dev_private;
  1113. struct radeon_encoder_int_tmds *tmds = NULL;
  1114. bool ret;
  1115. tmds = kzalloc(sizeof(struct radeon_encoder_int_tmds), GFP_KERNEL);
  1116. if (!tmds)
  1117. return NULL;
  1118. if (rdev->is_atom_bios)
  1119. ret = radeon_atombios_get_tmds_info(encoder, tmds);
  1120. else
  1121. ret = radeon_legacy_get_tmds_info_from_combios(encoder, tmds);
  1122. if (ret == false)
  1123. radeon_legacy_get_tmds_info_from_table(encoder, tmds);
  1124. return tmds;
  1125. }
  1126. static struct radeon_encoder_ext_tmds *radeon_legacy_get_ext_tmds_info(struct radeon_encoder *encoder)
  1127. {
  1128. struct drm_device *dev = encoder->base.dev;
  1129. struct radeon_device *rdev = dev->dev_private;
  1130. struct radeon_encoder_ext_tmds *tmds = NULL;
  1131. bool ret;
  1132. if (rdev->is_atom_bios)
  1133. return NULL;
  1134. tmds = kzalloc(sizeof(struct radeon_encoder_ext_tmds), GFP_KERNEL);
  1135. if (!tmds)
  1136. return NULL;
  1137. ret = radeon_legacy_get_ext_tmds_info_from_combios(encoder, tmds);
  1138. if (ret == false)
  1139. radeon_legacy_get_ext_tmds_info_from_table(encoder, tmds);
  1140. return tmds;
  1141. }
  1142. void
  1143. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id, uint32_t supported_device)
  1144. {
  1145. struct radeon_device *rdev = dev->dev_private;
  1146. struct drm_encoder *encoder;
  1147. struct radeon_encoder *radeon_encoder;
  1148. /* see if we already added it */
  1149. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1150. radeon_encoder = to_radeon_encoder(encoder);
  1151. if (radeon_encoder->encoder_id == encoder_id) {
  1152. radeon_encoder->devices |= supported_device;
  1153. return;
  1154. }
  1155. }
  1156. /* add a new one */
  1157. radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
  1158. if (!radeon_encoder)
  1159. return;
  1160. encoder = &radeon_encoder->base;
  1161. if (rdev->flags & RADEON_SINGLE_CRTC)
  1162. encoder->possible_crtcs = 0x1;
  1163. else
  1164. encoder->possible_crtcs = 0x3;
  1165. radeon_encoder->enc_priv = NULL;
  1166. radeon_encoder->encoder_id = encoder_id;
  1167. radeon_encoder->devices = supported_device;
  1168. radeon_encoder->rmx_type = RMX_OFF;
  1169. switch (radeon_encoder->encoder_id) {
  1170. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  1171. encoder->possible_crtcs = 0x1;
  1172. drm_encoder_init(dev, encoder, &radeon_legacy_lvds_enc_funcs, DRM_MODE_ENCODER_LVDS);
  1173. drm_encoder_helper_add(encoder, &radeon_legacy_lvds_helper_funcs);
  1174. if (rdev->is_atom_bios)
  1175. radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
  1176. else
  1177. radeon_encoder->enc_priv = radeon_combios_get_lvds_info(radeon_encoder);
  1178. radeon_encoder->rmx_type = RMX_FULL;
  1179. break;
  1180. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  1181. drm_encoder_init(dev, encoder, &radeon_legacy_tmds_int_enc_funcs, DRM_MODE_ENCODER_TMDS);
  1182. drm_encoder_helper_add(encoder, &radeon_legacy_tmds_int_helper_funcs);
  1183. radeon_encoder->enc_priv = radeon_legacy_get_tmds_info(radeon_encoder);
  1184. break;
  1185. case ENCODER_OBJECT_ID_INTERNAL_DAC1:
  1186. drm_encoder_init(dev, encoder, &radeon_legacy_primary_dac_enc_funcs, DRM_MODE_ENCODER_DAC);
  1187. drm_encoder_helper_add(encoder, &radeon_legacy_primary_dac_helper_funcs);
  1188. if (rdev->is_atom_bios)
  1189. radeon_encoder->enc_priv = radeon_atombios_get_primary_dac_info(radeon_encoder);
  1190. else
  1191. radeon_encoder->enc_priv = radeon_combios_get_primary_dac_info(radeon_encoder);
  1192. break;
  1193. case ENCODER_OBJECT_ID_INTERNAL_DAC2:
  1194. drm_encoder_init(dev, encoder, &radeon_legacy_tv_dac_enc_funcs, DRM_MODE_ENCODER_TVDAC);
  1195. drm_encoder_helper_add(encoder, &radeon_legacy_tv_dac_helper_funcs);
  1196. if (rdev->is_atom_bios)
  1197. radeon_encoder->enc_priv = radeon_atombios_get_tv_dac_info(radeon_encoder);
  1198. else
  1199. radeon_encoder->enc_priv = radeon_combios_get_tv_dac_info(radeon_encoder);
  1200. break;
  1201. case ENCODER_OBJECT_ID_INTERNAL_DVO1:
  1202. drm_encoder_init(dev, encoder, &radeon_legacy_tmds_ext_enc_funcs, DRM_MODE_ENCODER_TMDS);
  1203. drm_encoder_helper_add(encoder, &radeon_legacy_tmds_ext_helper_funcs);
  1204. if (!rdev->is_atom_bios)
  1205. radeon_encoder->enc_priv = radeon_legacy_get_ext_tmds_info(radeon_encoder);
  1206. break;
  1207. }
  1208. }