radeon_legacy_encoders.c 51 KB

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