radeon_legacy_encoders.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include <drm/drmP.h>
  27. #include <drm/drm_crtc_helper.h>
  28. #include <drm/radeon_drm.h>
  29. #include "radeon.h"
  30. #include "atom.h"
  31. #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. const 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. const 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. u8
  240. radeon_legacy_get_backlight_level(struct radeon_encoder *radeon_encoder)
  241. {
  242. struct drm_device *dev = radeon_encoder->base.dev;
  243. struct radeon_device *rdev = dev->dev_private;
  244. u8 backlight_level;
  245. backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >>
  246. RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff;
  247. return backlight_level;
  248. }
  249. void
  250. radeon_legacy_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 level)
  251. {
  252. struct drm_device *dev = radeon_encoder->base.dev;
  253. struct radeon_device *rdev = dev->dev_private;
  254. int dpms_mode = DRM_MODE_DPMS_ON;
  255. if (radeon_encoder->enc_priv) {
  256. if (rdev->is_atom_bios) {
  257. struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
  258. if (lvds->backlight_level > 0)
  259. dpms_mode = lvds->dpms_mode;
  260. else
  261. dpms_mode = DRM_MODE_DPMS_OFF;
  262. lvds->backlight_level = level;
  263. } else {
  264. struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
  265. if (lvds->backlight_level > 0)
  266. dpms_mode = lvds->dpms_mode;
  267. else
  268. dpms_mode = DRM_MODE_DPMS_OFF;
  269. lvds->backlight_level = level;
  270. }
  271. }
  272. radeon_legacy_lvds_update(&radeon_encoder->base, dpms_mode);
  273. }
  274. #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
  275. static uint8_t radeon_legacy_lvds_level(struct backlight_device *bd)
  276. {
  277. struct radeon_backlight_privdata *pdata = bl_get_data(bd);
  278. uint8_t level;
  279. /* Convert brightness to hardware level */
  280. if (bd->props.brightness < 0)
  281. level = 0;
  282. else if (bd->props.brightness > RADEON_MAX_BL_LEVEL)
  283. level = RADEON_MAX_BL_LEVEL;
  284. else
  285. level = bd->props.brightness;
  286. if (pdata->negative)
  287. level = RADEON_MAX_BL_LEVEL - level;
  288. return level;
  289. }
  290. static int radeon_legacy_backlight_update_status(struct backlight_device *bd)
  291. {
  292. struct radeon_backlight_privdata *pdata = bl_get_data(bd);
  293. struct radeon_encoder *radeon_encoder = pdata->encoder;
  294. radeon_legacy_set_backlight_level(radeon_encoder,
  295. radeon_legacy_lvds_level(bd));
  296. return 0;
  297. }
  298. static int radeon_legacy_backlight_get_brightness(struct backlight_device *bd)
  299. {
  300. struct radeon_backlight_privdata *pdata = bl_get_data(bd);
  301. struct radeon_encoder *radeon_encoder = pdata->encoder;
  302. struct drm_device *dev = radeon_encoder->base.dev;
  303. struct radeon_device *rdev = dev->dev_private;
  304. uint8_t backlight_level;
  305. backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >>
  306. RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff;
  307. return pdata->negative ? RADEON_MAX_BL_LEVEL - backlight_level : backlight_level;
  308. }
  309. static const struct backlight_ops radeon_backlight_ops = {
  310. .get_brightness = radeon_legacy_backlight_get_brightness,
  311. .update_status = radeon_legacy_backlight_update_status,
  312. };
  313. void radeon_legacy_backlight_init(struct radeon_encoder *radeon_encoder,
  314. struct drm_connector *drm_connector)
  315. {
  316. struct drm_device *dev = radeon_encoder->base.dev;
  317. struct radeon_device *rdev = dev->dev_private;
  318. struct backlight_device *bd;
  319. struct backlight_properties props;
  320. struct radeon_backlight_privdata *pdata;
  321. uint8_t backlight_level;
  322. char bl_name[16];
  323. if (!radeon_encoder->enc_priv)
  324. return;
  325. #ifdef CONFIG_PMAC_BACKLIGHT
  326. if (!pmac_has_backlight_type("ati") &&
  327. !pmac_has_backlight_type("mnca"))
  328. return;
  329. #endif
  330. pdata = kmalloc(sizeof(struct radeon_backlight_privdata), GFP_KERNEL);
  331. if (!pdata) {
  332. DRM_ERROR("Memory allocation failed\n");
  333. goto error;
  334. }
  335. memset(&props, 0, sizeof(props));
  336. props.max_brightness = RADEON_MAX_BL_LEVEL;
  337. props.type = BACKLIGHT_RAW;
  338. snprintf(bl_name, sizeof(bl_name),
  339. "radeon_bl%d", dev->primary->index);
  340. bd = backlight_device_register(bl_name, drm_connector->kdev,
  341. pdata, &radeon_backlight_ops, &props);
  342. if (IS_ERR(bd)) {
  343. DRM_ERROR("Backlight registration failed\n");
  344. goto error;
  345. }
  346. pdata->encoder = radeon_encoder;
  347. backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >>
  348. RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff;
  349. /* First, try to detect backlight level sense based on the assumption
  350. * that firmware set it up at full brightness
  351. */
  352. if (backlight_level == 0)
  353. pdata->negative = true;
  354. else if (backlight_level == 0xff)
  355. pdata->negative = false;
  356. else {
  357. /* XXX hack... maybe some day we can figure out in what direction
  358. * backlight should work on a given panel?
  359. */
  360. pdata->negative = (rdev->family != CHIP_RV200 &&
  361. rdev->family != CHIP_RV250 &&
  362. rdev->family != CHIP_RV280 &&
  363. rdev->family != CHIP_RV350);
  364. #ifdef CONFIG_PMAC_BACKLIGHT
  365. pdata->negative = (pdata->negative ||
  366. of_machine_is_compatible("PowerBook4,3") ||
  367. of_machine_is_compatible("PowerBook6,3") ||
  368. of_machine_is_compatible("PowerBook6,5"));
  369. #endif
  370. }
  371. if (rdev->is_atom_bios) {
  372. struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
  373. lvds->bl_dev = bd;
  374. } else {
  375. struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
  376. lvds->bl_dev = bd;
  377. }
  378. bd->props.brightness = radeon_legacy_backlight_get_brightness(bd);
  379. bd->props.power = FB_BLANK_UNBLANK;
  380. backlight_update_status(bd);
  381. DRM_INFO("radeon legacy LVDS backlight initialized\n");
  382. rdev->mode_info.bl_encoder = radeon_encoder;
  383. return;
  384. error:
  385. kfree(pdata);
  386. return;
  387. }
  388. static void radeon_legacy_backlight_exit(struct radeon_encoder *radeon_encoder)
  389. {
  390. struct drm_device *dev = radeon_encoder->base.dev;
  391. struct radeon_device *rdev = dev->dev_private;
  392. struct backlight_device *bd = NULL;
  393. if (!radeon_encoder->enc_priv)
  394. return;
  395. if (rdev->is_atom_bios) {
  396. struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
  397. bd = lvds->bl_dev;
  398. lvds->bl_dev = NULL;
  399. } else {
  400. struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
  401. bd = lvds->bl_dev;
  402. lvds->bl_dev = NULL;
  403. }
  404. if (bd) {
  405. struct radeon_backlight_privdata *pdata;
  406. pdata = bl_get_data(bd);
  407. backlight_device_unregister(bd);
  408. kfree(pdata);
  409. DRM_INFO("radeon legacy LVDS backlight unloaded\n");
  410. }
  411. }
  412. #else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */
  413. void radeon_legacy_backlight_init(struct radeon_encoder *encoder)
  414. {
  415. }
  416. static void radeon_legacy_backlight_exit(struct radeon_encoder *encoder)
  417. {
  418. }
  419. #endif
  420. static void radeon_lvds_enc_destroy(struct drm_encoder *encoder)
  421. {
  422. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  423. if (radeon_encoder->enc_priv) {
  424. radeon_legacy_backlight_exit(radeon_encoder);
  425. kfree(radeon_encoder->enc_priv);
  426. }
  427. drm_encoder_cleanup(encoder);
  428. kfree(radeon_encoder);
  429. }
  430. static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs = {
  431. .destroy = radeon_lvds_enc_destroy,
  432. };
  433. static void radeon_legacy_primary_dac_dpms(struct drm_encoder *encoder, int mode)
  434. {
  435. struct drm_device *dev = encoder->dev;
  436. struct radeon_device *rdev = dev->dev_private;
  437. uint32_t crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
  438. uint32_t dac_cntl = RREG32(RADEON_DAC_CNTL);
  439. uint32_t dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
  440. DRM_DEBUG_KMS("\n");
  441. switch (mode) {
  442. case DRM_MODE_DPMS_ON:
  443. crtc_ext_cntl |= RADEON_CRTC_CRT_ON;
  444. dac_cntl &= ~RADEON_DAC_PDWN;
  445. dac_macro_cntl &= ~(RADEON_DAC_PDWN_R |
  446. RADEON_DAC_PDWN_G |
  447. RADEON_DAC_PDWN_B);
  448. break;
  449. case DRM_MODE_DPMS_STANDBY:
  450. case DRM_MODE_DPMS_SUSPEND:
  451. case DRM_MODE_DPMS_OFF:
  452. crtc_ext_cntl &= ~RADEON_CRTC_CRT_ON;
  453. dac_cntl |= RADEON_DAC_PDWN;
  454. dac_macro_cntl |= (RADEON_DAC_PDWN_R |
  455. RADEON_DAC_PDWN_G |
  456. RADEON_DAC_PDWN_B);
  457. break;
  458. }
  459. /* handled in radeon_crtc_dpms() */
  460. if (!(rdev->flags & RADEON_SINGLE_CRTC))
  461. WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
  462. WREG32(RADEON_DAC_CNTL, dac_cntl);
  463. WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
  464. if (rdev->is_atom_bios)
  465. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  466. else
  467. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  468. }
  469. static void radeon_legacy_primary_dac_prepare(struct drm_encoder *encoder)
  470. {
  471. struct radeon_device *rdev = encoder->dev->dev_private;
  472. if (rdev->is_atom_bios)
  473. radeon_atom_output_lock(encoder, true);
  474. else
  475. radeon_combios_output_lock(encoder, true);
  476. radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
  477. }
  478. static void radeon_legacy_primary_dac_commit(struct drm_encoder *encoder)
  479. {
  480. struct radeon_device *rdev = encoder->dev->dev_private;
  481. radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_ON);
  482. if (rdev->is_atom_bios)
  483. radeon_atom_output_lock(encoder, false);
  484. else
  485. radeon_combios_output_lock(encoder, false);
  486. }
  487. static void radeon_legacy_primary_dac_mode_set(struct drm_encoder *encoder,
  488. struct drm_display_mode *mode,
  489. struct drm_display_mode *adjusted_mode)
  490. {
  491. struct drm_device *dev = encoder->dev;
  492. struct radeon_device *rdev = dev->dev_private;
  493. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  494. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  495. uint32_t disp_output_cntl, dac_cntl, dac2_cntl, dac_macro_cntl;
  496. DRM_DEBUG_KMS("\n");
  497. if (radeon_crtc->crtc_id == 0) {
  498. if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) {
  499. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) &
  500. ~(RADEON_DISP_DAC_SOURCE_MASK);
  501. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  502. } else {
  503. dac2_cntl = RREG32(RADEON_DAC_CNTL2) & ~(RADEON_DAC2_DAC_CLK_SEL);
  504. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  505. }
  506. } else {
  507. if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) {
  508. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) &
  509. ~(RADEON_DISP_DAC_SOURCE_MASK);
  510. disp_output_cntl |= RADEON_DISP_DAC_SOURCE_CRTC2;
  511. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  512. } else {
  513. dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC_CLK_SEL;
  514. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  515. }
  516. }
  517. dac_cntl = (RADEON_DAC_MASK_ALL |
  518. RADEON_DAC_VGA_ADR_EN |
  519. /* TODO 6-bits */
  520. RADEON_DAC_8BIT_EN);
  521. WREG32_P(RADEON_DAC_CNTL,
  522. dac_cntl,
  523. RADEON_DAC_RANGE_CNTL |
  524. RADEON_DAC_BLANKING);
  525. if (radeon_encoder->enc_priv) {
  526. struct radeon_encoder_primary_dac *p_dac = (struct radeon_encoder_primary_dac *)radeon_encoder->enc_priv;
  527. dac_macro_cntl = p_dac->ps2_pdac_adj;
  528. } else
  529. dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
  530. dac_macro_cntl |= RADEON_DAC_PDWN_R | RADEON_DAC_PDWN_G | RADEON_DAC_PDWN_B;
  531. WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
  532. if (rdev->is_atom_bios)
  533. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  534. else
  535. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  536. }
  537. static enum drm_connector_status radeon_legacy_primary_dac_detect(struct drm_encoder *encoder,
  538. struct drm_connector *connector)
  539. {
  540. struct drm_device *dev = encoder->dev;
  541. struct radeon_device *rdev = dev->dev_private;
  542. uint32_t vclk_ecp_cntl, crtc_ext_cntl;
  543. uint32_t dac_ext_cntl, dac_cntl, dac_macro_cntl, tmp;
  544. enum drm_connector_status found = connector_status_disconnected;
  545. bool color = true;
  546. /* just don't bother on RN50 those chip are often connected to remoting
  547. * console hw and often we get failure to load detect those. So to make
  548. * everyone happy report the encoder as always connected.
  549. */
  550. if (ASIC_IS_RN50(rdev)) {
  551. return connector_status_connected;
  552. }
  553. /* save the regs we need */
  554. vclk_ecp_cntl = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
  555. crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
  556. dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
  557. dac_cntl = RREG32(RADEON_DAC_CNTL);
  558. dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
  559. tmp = vclk_ecp_cntl &
  560. ~(RADEON_PIXCLK_ALWAYS_ONb | RADEON_PIXCLK_DAC_ALWAYS_ONb);
  561. WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
  562. tmp = crtc_ext_cntl | RADEON_CRTC_CRT_ON;
  563. WREG32(RADEON_CRTC_EXT_CNTL, tmp);
  564. tmp = RADEON_DAC_FORCE_BLANK_OFF_EN |
  565. RADEON_DAC_FORCE_DATA_EN;
  566. if (color)
  567. tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
  568. else
  569. tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
  570. if (ASIC_IS_R300(rdev))
  571. tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
  572. else if (ASIC_IS_RV100(rdev))
  573. tmp |= (0x1ac << RADEON_DAC_FORCE_DATA_SHIFT);
  574. else
  575. tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
  576. WREG32(RADEON_DAC_EXT_CNTL, tmp);
  577. tmp = dac_cntl & ~(RADEON_DAC_RANGE_CNTL_MASK | RADEON_DAC_PDWN);
  578. tmp |= RADEON_DAC_RANGE_CNTL_PS2 | RADEON_DAC_CMP_EN;
  579. WREG32(RADEON_DAC_CNTL, tmp);
  580. tmp = dac_macro_cntl;
  581. tmp &= ~(RADEON_DAC_PDWN_R |
  582. RADEON_DAC_PDWN_G |
  583. RADEON_DAC_PDWN_B);
  584. WREG32(RADEON_DAC_MACRO_CNTL, tmp);
  585. mdelay(2);
  586. if (RREG32(RADEON_DAC_CNTL) & RADEON_DAC_CMP_OUTPUT)
  587. found = connector_status_connected;
  588. /* restore the regs we used */
  589. WREG32(RADEON_DAC_CNTL, dac_cntl);
  590. WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
  591. WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
  592. WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
  593. WREG32_PLL(RADEON_VCLK_ECP_CNTL, vclk_ecp_cntl);
  594. return found;
  595. }
  596. static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs = {
  597. .dpms = radeon_legacy_primary_dac_dpms,
  598. .mode_fixup = radeon_legacy_mode_fixup,
  599. .prepare = radeon_legacy_primary_dac_prepare,
  600. .mode_set = radeon_legacy_primary_dac_mode_set,
  601. .commit = radeon_legacy_primary_dac_commit,
  602. .detect = radeon_legacy_primary_dac_detect,
  603. .disable = radeon_legacy_encoder_disable,
  604. };
  605. static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs = {
  606. .destroy = radeon_enc_destroy,
  607. };
  608. static void radeon_legacy_tmds_int_dpms(struct drm_encoder *encoder, int mode)
  609. {
  610. struct drm_device *dev = encoder->dev;
  611. struct radeon_device *rdev = dev->dev_private;
  612. uint32_t fp_gen_cntl = RREG32(RADEON_FP_GEN_CNTL);
  613. DRM_DEBUG_KMS("\n");
  614. switch (mode) {
  615. case DRM_MODE_DPMS_ON:
  616. fp_gen_cntl |= (RADEON_FP_FPON | RADEON_FP_TMDS_EN);
  617. break;
  618. case DRM_MODE_DPMS_STANDBY:
  619. case DRM_MODE_DPMS_SUSPEND:
  620. case DRM_MODE_DPMS_OFF:
  621. fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
  622. break;
  623. }
  624. WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl);
  625. if (rdev->is_atom_bios)
  626. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  627. else
  628. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  629. }
  630. static void radeon_legacy_tmds_int_prepare(struct drm_encoder *encoder)
  631. {
  632. struct radeon_device *rdev = encoder->dev->dev_private;
  633. if (rdev->is_atom_bios)
  634. radeon_atom_output_lock(encoder, true);
  635. else
  636. radeon_combios_output_lock(encoder, true);
  637. radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_OFF);
  638. }
  639. static void radeon_legacy_tmds_int_commit(struct drm_encoder *encoder)
  640. {
  641. struct radeon_device *rdev = encoder->dev->dev_private;
  642. radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_ON);
  643. if (rdev->is_atom_bios)
  644. radeon_atom_output_lock(encoder, true);
  645. else
  646. radeon_combios_output_lock(encoder, true);
  647. }
  648. static void radeon_legacy_tmds_int_mode_set(struct drm_encoder *encoder,
  649. struct drm_display_mode *mode,
  650. struct drm_display_mode *adjusted_mode)
  651. {
  652. struct drm_device *dev = encoder->dev;
  653. struct radeon_device *rdev = dev->dev_private;
  654. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  655. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  656. uint32_t tmp, tmds_pll_cntl, tmds_transmitter_cntl, fp_gen_cntl;
  657. int i;
  658. DRM_DEBUG_KMS("\n");
  659. tmp = tmds_pll_cntl = RREG32(RADEON_TMDS_PLL_CNTL);
  660. tmp &= 0xfffff;
  661. if (rdev->family == CHIP_RV280) {
  662. /* bit 22 of TMDS_PLL_CNTL is read-back inverted */
  663. tmp ^= (1 << 22);
  664. tmds_pll_cntl ^= (1 << 22);
  665. }
  666. if (radeon_encoder->enc_priv) {
  667. struct radeon_encoder_int_tmds *tmds = (struct radeon_encoder_int_tmds *)radeon_encoder->enc_priv;
  668. for (i = 0; i < 4; i++) {
  669. if (tmds->tmds_pll[i].freq == 0)
  670. break;
  671. if ((uint32_t)(mode->clock / 10) < tmds->tmds_pll[i].freq) {
  672. tmp = tmds->tmds_pll[i].value ;
  673. break;
  674. }
  675. }
  676. }
  677. if (ASIC_IS_R300(rdev) || (rdev->family == CHIP_RV280)) {
  678. if (tmp & 0xfff00000)
  679. tmds_pll_cntl = tmp;
  680. else {
  681. tmds_pll_cntl &= 0xfff00000;
  682. tmds_pll_cntl |= tmp;
  683. }
  684. } else
  685. tmds_pll_cntl = tmp;
  686. tmds_transmitter_cntl = RREG32(RADEON_TMDS_TRANSMITTER_CNTL) &
  687. ~(RADEON_TMDS_TRANSMITTER_PLLRST);
  688. if (rdev->family == CHIP_R200 ||
  689. rdev->family == CHIP_R100 ||
  690. ASIC_IS_R300(rdev))
  691. tmds_transmitter_cntl &= ~(RADEON_TMDS_TRANSMITTER_PLLEN);
  692. else /* RV chips got this bit reversed */
  693. tmds_transmitter_cntl |= RADEON_TMDS_TRANSMITTER_PLLEN;
  694. fp_gen_cntl = (RREG32(RADEON_FP_GEN_CNTL) |
  695. (RADEON_FP_CRTC_DONT_SHADOW_VPAR |
  696. RADEON_FP_CRTC_DONT_SHADOW_HEND));
  697. fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
  698. fp_gen_cntl &= ~(RADEON_FP_RMX_HVSYNC_CONTROL_EN |
  699. RADEON_FP_DFP_SYNC_SEL |
  700. RADEON_FP_CRT_SYNC_SEL |
  701. RADEON_FP_CRTC_LOCK_8DOT |
  702. RADEON_FP_USE_SHADOW_EN |
  703. RADEON_FP_CRTC_USE_SHADOW_VEND |
  704. RADEON_FP_CRT_SYNC_ALT);
  705. if (1) /* FIXME rgbBits == 8 */
  706. fp_gen_cntl |= RADEON_FP_PANEL_FORMAT; /* 24 bit format */
  707. else
  708. fp_gen_cntl &= ~RADEON_FP_PANEL_FORMAT;/* 18 bit format */
  709. if (radeon_crtc->crtc_id == 0) {
  710. if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) {
  711. fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
  712. if (radeon_encoder->rmx_type != RMX_OFF)
  713. fp_gen_cntl |= R200_FP_SOURCE_SEL_RMX;
  714. else
  715. fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC1;
  716. } else
  717. fp_gen_cntl &= ~RADEON_FP_SEL_CRTC2;
  718. } else {
  719. if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) {
  720. fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
  721. fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC2;
  722. } else
  723. fp_gen_cntl |= RADEON_FP_SEL_CRTC2;
  724. }
  725. WREG32(RADEON_TMDS_PLL_CNTL, tmds_pll_cntl);
  726. WREG32(RADEON_TMDS_TRANSMITTER_CNTL, tmds_transmitter_cntl);
  727. WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl);
  728. if (rdev->is_atom_bios)
  729. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  730. else
  731. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  732. }
  733. static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs = {
  734. .dpms = radeon_legacy_tmds_int_dpms,
  735. .mode_fixup = radeon_legacy_mode_fixup,
  736. .prepare = radeon_legacy_tmds_int_prepare,
  737. .mode_set = radeon_legacy_tmds_int_mode_set,
  738. .commit = radeon_legacy_tmds_int_commit,
  739. .disable = radeon_legacy_encoder_disable,
  740. };
  741. static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs = {
  742. .destroy = radeon_enc_destroy,
  743. };
  744. static void radeon_legacy_tmds_ext_dpms(struct drm_encoder *encoder, int mode)
  745. {
  746. struct drm_device *dev = encoder->dev;
  747. struct radeon_device *rdev = dev->dev_private;
  748. uint32_t fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  749. DRM_DEBUG_KMS("\n");
  750. switch (mode) {
  751. case DRM_MODE_DPMS_ON:
  752. fp2_gen_cntl &= ~RADEON_FP2_BLANK_EN;
  753. fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  754. break;
  755. case DRM_MODE_DPMS_STANDBY:
  756. case DRM_MODE_DPMS_SUSPEND:
  757. case DRM_MODE_DPMS_OFF:
  758. fp2_gen_cntl |= RADEON_FP2_BLANK_EN;
  759. fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  760. break;
  761. }
  762. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  763. if (rdev->is_atom_bios)
  764. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  765. else
  766. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  767. }
  768. static void radeon_legacy_tmds_ext_prepare(struct drm_encoder *encoder)
  769. {
  770. struct radeon_device *rdev = encoder->dev->dev_private;
  771. if (rdev->is_atom_bios)
  772. radeon_atom_output_lock(encoder, true);
  773. else
  774. radeon_combios_output_lock(encoder, true);
  775. radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_OFF);
  776. }
  777. static void radeon_legacy_tmds_ext_commit(struct drm_encoder *encoder)
  778. {
  779. struct radeon_device *rdev = encoder->dev->dev_private;
  780. radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_ON);
  781. if (rdev->is_atom_bios)
  782. radeon_atom_output_lock(encoder, false);
  783. else
  784. radeon_combios_output_lock(encoder, false);
  785. }
  786. static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder *encoder,
  787. struct drm_display_mode *mode,
  788. struct drm_display_mode *adjusted_mode)
  789. {
  790. struct drm_device *dev = encoder->dev;
  791. struct radeon_device *rdev = dev->dev_private;
  792. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  793. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  794. uint32_t fp2_gen_cntl;
  795. DRM_DEBUG_KMS("\n");
  796. if (rdev->is_atom_bios) {
  797. radeon_encoder->pixel_clock = adjusted_mode->clock;
  798. atombios_dvo_setup(encoder, ATOM_ENABLE);
  799. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  800. } else {
  801. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  802. if (1) /* FIXME rgbBits == 8 */
  803. fp2_gen_cntl |= RADEON_FP2_PANEL_FORMAT; /* 24 bit format, */
  804. else
  805. fp2_gen_cntl &= ~RADEON_FP2_PANEL_FORMAT;/* 18 bit format, */
  806. fp2_gen_cntl &= ~(RADEON_FP2_ON |
  807. RADEON_FP2_DVO_EN |
  808. RADEON_FP2_DVO_RATE_SEL_SDR);
  809. /* XXX: these are oem specific */
  810. if (ASIC_IS_R300(rdev)) {
  811. if ((dev->pdev->device == 0x4850) &&
  812. (dev->pdev->subsystem_vendor == 0x1028) &&
  813. (dev->pdev->subsystem_device == 0x2001)) /* Dell Inspiron 8600 */
  814. fp2_gen_cntl |= R300_FP2_DVO_CLOCK_MODE_SINGLE;
  815. else
  816. fp2_gen_cntl |= RADEON_FP2_PAD_FLOP_EN | R300_FP2_DVO_CLOCK_MODE_SINGLE;
  817. /*if (mode->clock > 165000)
  818. fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/
  819. }
  820. if (!radeon_combios_external_tmds_setup(encoder))
  821. radeon_external_tmds_setup(encoder);
  822. }
  823. if (radeon_crtc->crtc_id == 0) {
  824. if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) {
  825. fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
  826. if (radeon_encoder->rmx_type != RMX_OFF)
  827. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_RMX;
  828. else
  829. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC1;
  830. } else
  831. fp2_gen_cntl &= ~RADEON_FP2_SRC_SEL_CRTC2;
  832. } else {
  833. if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) {
  834. fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
  835. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
  836. } else
  837. fp2_gen_cntl |= RADEON_FP2_SRC_SEL_CRTC2;
  838. }
  839. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  840. if (rdev->is_atom_bios)
  841. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  842. else
  843. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  844. }
  845. static void radeon_ext_tmds_enc_destroy(struct drm_encoder *encoder)
  846. {
  847. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  848. /* don't destroy the i2c bus record here, this will be done in radeon_i2c_fini */
  849. kfree(radeon_encoder->enc_priv);
  850. drm_encoder_cleanup(encoder);
  851. kfree(radeon_encoder);
  852. }
  853. static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs = {
  854. .dpms = radeon_legacy_tmds_ext_dpms,
  855. .mode_fixup = radeon_legacy_mode_fixup,
  856. .prepare = radeon_legacy_tmds_ext_prepare,
  857. .mode_set = radeon_legacy_tmds_ext_mode_set,
  858. .commit = radeon_legacy_tmds_ext_commit,
  859. .disable = radeon_legacy_encoder_disable,
  860. };
  861. static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs = {
  862. .destroy = radeon_ext_tmds_enc_destroy,
  863. };
  864. static void radeon_legacy_tv_dac_dpms(struct drm_encoder *encoder, int mode)
  865. {
  866. struct drm_device *dev = encoder->dev;
  867. struct radeon_device *rdev = dev->dev_private;
  868. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  869. uint32_t fp2_gen_cntl = 0, crtc2_gen_cntl = 0, tv_dac_cntl = 0;
  870. uint32_t tv_master_cntl = 0;
  871. bool is_tv;
  872. DRM_DEBUG_KMS("\n");
  873. is_tv = radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT ? true : false;
  874. if (rdev->family == CHIP_R200)
  875. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  876. else {
  877. if (is_tv)
  878. tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL);
  879. else
  880. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
  881. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  882. }
  883. switch (mode) {
  884. case DRM_MODE_DPMS_ON:
  885. if (rdev->family == CHIP_R200) {
  886. fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  887. } else {
  888. if (is_tv)
  889. tv_master_cntl |= RADEON_TV_ON;
  890. else
  891. crtc2_gen_cntl |= RADEON_CRTC2_CRT2_ON;
  892. if (rdev->family == CHIP_R420 ||
  893. rdev->family == CHIP_R423 ||
  894. rdev->family == CHIP_RV410)
  895. tv_dac_cntl &= ~(R420_TV_DAC_RDACPD |
  896. R420_TV_DAC_GDACPD |
  897. R420_TV_DAC_BDACPD |
  898. RADEON_TV_DAC_BGSLEEP);
  899. else
  900. tv_dac_cntl &= ~(RADEON_TV_DAC_RDACPD |
  901. RADEON_TV_DAC_GDACPD |
  902. RADEON_TV_DAC_BDACPD |
  903. RADEON_TV_DAC_BGSLEEP);
  904. }
  905. break;
  906. case DRM_MODE_DPMS_STANDBY:
  907. case DRM_MODE_DPMS_SUSPEND:
  908. case DRM_MODE_DPMS_OFF:
  909. if (rdev->family == CHIP_R200)
  910. fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
  911. else {
  912. if (is_tv)
  913. tv_master_cntl &= ~RADEON_TV_ON;
  914. else
  915. crtc2_gen_cntl &= ~RADEON_CRTC2_CRT2_ON;
  916. if (rdev->family == CHIP_R420 ||
  917. rdev->family == CHIP_R423 ||
  918. rdev->family == CHIP_RV410)
  919. tv_dac_cntl |= (R420_TV_DAC_RDACPD |
  920. R420_TV_DAC_GDACPD |
  921. R420_TV_DAC_BDACPD |
  922. RADEON_TV_DAC_BGSLEEP);
  923. else
  924. tv_dac_cntl |= (RADEON_TV_DAC_RDACPD |
  925. RADEON_TV_DAC_GDACPD |
  926. RADEON_TV_DAC_BDACPD |
  927. RADEON_TV_DAC_BGSLEEP);
  928. }
  929. break;
  930. }
  931. if (rdev->family == CHIP_R200) {
  932. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  933. } else {
  934. if (is_tv)
  935. WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl);
  936. /* handled in radeon_crtc_dpms() */
  937. else if (!(rdev->flags & RADEON_SINGLE_CRTC))
  938. WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
  939. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  940. }
  941. if (rdev->is_atom_bios)
  942. radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  943. else
  944. radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
  945. }
  946. static void radeon_legacy_tv_dac_prepare(struct drm_encoder *encoder)
  947. {
  948. struct radeon_device *rdev = encoder->dev->dev_private;
  949. if (rdev->is_atom_bios)
  950. radeon_atom_output_lock(encoder, true);
  951. else
  952. radeon_combios_output_lock(encoder, true);
  953. radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
  954. }
  955. static void radeon_legacy_tv_dac_commit(struct drm_encoder *encoder)
  956. {
  957. struct radeon_device *rdev = encoder->dev->dev_private;
  958. radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_ON);
  959. if (rdev->is_atom_bios)
  960. radeon_atom_output_lock(encoder, true);
  961. else
  962. radeon_combios_output_lock(encoder, true);
  963. }
  964. static void radeon_legacy_tv_dac_mode_set(struct drm_encoder *encoder,
  965. struct drm_display_mode *mode,
  966. struct drm_display_mode *adjusted_mode)
  967. {
  968. struct drm_device *dev = encoder->dev;
  969. struct radeon_device *rdev = dev->dev_private;
  970. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  971. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  972. struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv;
  973. uint32_t tv_dac_cntl, gpiopad_a = 0, dac2_cntl, disp_output_cntl = 0;
  974. uint32_t disp_hw_debug = 0, fp2_gen_cntl = 0, disp_tv_out_cntl = 0;
  975. bool is_tv = false;
  976. DRM_DEBUG_KMS("\n");
  977. is_tv = radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT ? true : false;
  978. if (rdev->family != CHIP_R200) {
  979. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  980. if (rdev->family == CHIP_R420 ||
  981. rdev->family == CHIP_R423 ||
  982. rdev->family == CHIP_RV410) {
  983. tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
  984. RADEON_TV_DAC_BGADJ_MASK |
  985. R420_TV_DAC_DACADJ_MASK |
  986. R420_TV_DAC_RDACPD |
  987. R420_TV_DAC_GDACPD |
  988. R420_TV_DAC_BDACPD |
  989. R420_TV_DAC_TVENABLE);
  990. } else {
  991. tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
  992. RADEON_TV_DAC_BGADJ_MASK |
  993. RADEON_TV_DAC_DACADJ_MASK |
  994. RADEON_TV_DAC_RDACPD |
  995. RADEON_TV_DAC_GDACPD |
  996. RADEON_TV_DAC_BDACPD);
  997. }
  998. tv_dac_cntl |= RADEON_TV_DAC_NBLANK | RADEON_TV_DAC_NHOLD;
  999. if (is_tv) {
  1000. if (tv_dac->tv_std == TV_STD_NTSC ||
  1001. tv_dac->tv_std == TV_STD_NTSC_J ||
  1002. tv_dac->tv_std == TV_STD_PAL_M ||
  1003. tv_dac->tv_std == TV_STD_PAL_60)
  1004. tv_dac_cntl |= tv_dac->ntsc_tvdac_adj;
  1005. else
  1006. tv_dac_cntl |= tv_dac->pal_tvdac_adj;
  1007. if (tv_dac->tv_std == TV_STD_NTSC ||
  1008. tv_dac->tv_std == TV_STD_NTSC_J)
  1009. tv_dac_cntl |= RADEON_TV_DAC_STD_NTSC;
  1010. else
  1011. tv_dac_cntl |= RADEON_TV_DAC_STD_PAL;
  1012. } else
  1013. tv_dac_cntl |= (RADEON_TV_DAC_STD_PS2 |
  1014. tv_dac->ps2_tvdac_adj);
  1015. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  1016. }
  1017. if (ASIC_IS_R300(rdev)) {
  1018. gpiopad_a = RREG32(RADEON_GPIOPAD_A) | 1;
  1019. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
  1020. } else if (rdev->family != CHIP_R200)
  1021. disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG);
  1022. else if (rdev->family == CHIP_R200)
  1023. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  1024. if (rdev->family >= CHIP_R200)
  1025. disp_tv_out_cntl = RREG32(RADEON_DISP_TV_OUT_CNTL);
  1026. if (is_tv) {
  1027. uint32_t dac_cntl;
  1028. dac_cntl = RREG32(RADEON_DAC_CNTL);
  1029. dac_cntl &= ~RADEON_DAC_TVO_EN;
  1030. WREG32(RADEON_DAC_CNTL, dac_cntl);
  1031. if (ASIC_IS_R300(rdev))
  1032. gpiopad_a = RREG32(RADEON_GPIOPAD_A) & ~1;
  1033. dac2_cntl = RREG32(RADEON_DAC_CNTL2) & ~RADEON_DAC2_DAC2_CLK_SEL;
  1034. if (radeon_crtc->crtc_id == 0) {
  1035. if (ASIC_IS_R300(rdev)) {
  1036. disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
  1037. disp_output_cntl |= (RADEON_DISP_TVDAC_SOURCE_CRTC |
  1038. RADEON_DISP_TV_SOURCE_CRTC);
  1039. }
  1040. if (rdev->family >= CHIP_R200) {
  1041. disp_tv_out_cntl &= ~RADEON_DISP_TV_PATH_SRC_CRTC2;
  1042. } else {
  1043. disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
  1044. }
  1045. } else {
  1046. if (ASIC_IS_R300(rdev)) {
  1047. disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
  1048. disp_output_cntl |= RADEON_DISP_TV_SOURCE_CRTC;
  1049. }
  1050. if (rdev->family >= CHIP_R200) {
  1051. disp_tv_out_cntl |= RADEON_DISP_TV_PATH_SRC_CRTC2;
  1052. } else {
  1053. disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL;
  1054. }
  1055. }
  1056. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  1057. } else {
  1058. dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC2_CLK_SEL;
  1059. if (radeon_crtc->crtc_id == 0) {
  1060. if (ASIC_IS_R300(rdev)) {
  1061. disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
  1062. disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC;
  1063. } else if (rdev->family == CHIP_R200) {
  1064. fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
  1065. RADEON_FP2_DVO_RATE_SEL_SDR);
  1066. } else
  1067. disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
  1068. } else {
  1069. if (ASIC_IS_R300(rdev)) {
  1070. disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
  1071. disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
  1072. } else if (rdev->family == CHIP_R200) {
  1073. fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
  1074. RADEON_FP2_DVO_RATE_SEL_SDR);
  1075. fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
  1076. } else
  1077. disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL;
  1078. }
  1079. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  1080. }
  1081. if (ASIC_IS_R300(rdev)) {
  1082. WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
  1083. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  1084. } else if (rdev->family != CHIP_R200)
  1085. WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
  1086. else if (rdev->family == CHIP_R200)
  1087. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  1088. if (rdev->family >= CHIP_R200)
  1089. WREG32(RADEON_DISP_TV_OUT_CNTL, disp_tv_out_cntl);
  1090. if (is_tv)
  1091. radeon_legacy_tv_mode_set(encoder, mode, adjusted_mode);
  1092. if (rdev->is_atom_bios)
  1093. radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  1094. else
  1095. radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
  1096. }
  1097. static bool r300_legacy_tv_detect(struct drm_encoder *encoder,
  1098. struct drm_connector *connector)
  1099. {
  1100. struct drm_device *dev = encoder->dev;
  1101. struct radeon_device *rdev = dev->dev_private;
  1102. uint32_t crtc2_gen_cntl, tv_dac_cntl, dac_cntl2, dac_ext_cntl;
  1103. uint32_t disp_output_cntl, gpiopad_a, tmp;
  1104. bool found = false;
  1105. /* save regs needed */
  1106. gpiopad_a = RREG32(RADEON_GPIOPAD_A);
  1107. dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
  1108. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
  1109. dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
  1110. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  1111. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
  1112. WREG32_P(RADEON_GPIOPAD_A, 0, ~1);
  1113. WREG32(RADEON_DAC_CNTL2, RADEON_DAC2_DAC2_CLK_SEL);
  1114. WREG32(RADEON_CRTC2_GEN_CNTL,
  1115. RADEON_CRTC2_CRT2_ON | RADEON_CRTC2_VSYNC_TRISTAT);
  1116. tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK;
  1117. tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
  1118. WREG32(RADEON_DISP_OUTPUT_CNTL, tmp);
  1119. WREG32(RADEON_DAC_EXT_CNTL,
  1120. RADEON_DAC2_FORCE_BLANK_OFF_EN |
  1121. RADEON_DAC2_FORCE_DATA_EN |
  1122. RADEON_DAC_FORCE_DATA_SEL_RGB |
  1123. (0xec << RADEON_DAC_FORCE_DATA_SHIFT));
  1124. WREG32(RADEON_TV_DAC_CNTL,
  1125. RADEON_TV_DAC_STD_NTSC |
  1126. (8 << RADEON_TV_DAC_BGADJ_SHIFT) |
  1127. (6 << RADEON_TV_DAC_DACADJ_SHIFT));
  1128. RREG32(RADEON_TV_DAC_CNTL);
  1129. mdelay(4);
  1130. WREG32(RADEON_TV_DAC_CNTL,
  1131. RADEON_TV_DAC_NBLANK |
  1132. RADEON_TV_DAC_NHOLD |
  1133. RADEON_TV_MONITOR_DETECT_EN |
  1134. RADEON_TV_DAC_STD_NTSC |
  1135. (8 << RADEON_TV_DAC_BGADJ_SHIFT) |
  1136. (6 << RADEON_TV_DAC_DACADJ_SHIFT));
  1137. RREG32(RADEON_TV_DAC_CNTL);
  1138. mdelay(6);
  1139. tmp = RREG32(RADEON_TV_DAC_CNTL);
  1140. if ((tmp & RADEON_TV_DAC_GDACDET) != 0) {
  1141. found = true;
  1142. DRM_DEBUG_KMS("S-video TV connection detected\n");
  1143. } else if ((tmp & RADEON_TV_DAC_BDACDET) != 0) {
  1144. found = true;
  1145. DRM_DEBUG_KMS("Composite TV connection detected\n");
  1146. }
  1147. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  1148. WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
  1149. WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
  1150. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  1151. WREG32(RADEON_DAC_CNTL2, dac_cntl2);
  1152. WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
  1153. return found;
  1154. }
  1155. static bool radeon_legacy_tv_detect(struct drm_encoder *encoder,
  1156. struct drm_connector *connector)
  1157. {
  1158. struct drm_device *dev = encoder->dev;
  1159. struct radeon_device *rdev = dev->dev_private;
  1160. uint32_t tv_dac_cntl, dac_cntl2;
  1161. uint32_t config_cntl, tv_pre_dac_mux_cntl, tv_master_cntl, tmp;
  1162. bool found = false;
  1163. if (ASIC_IS_R300(rdev))
  1164. return r300_legacy_tv_detect(encoder, connector);
  1165. dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
  1166. tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL);
  1167. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  1168. config_cntl = RREG32(RADEON_CONFIG_CNTL);
  1169. tv_pre_dac_mux_cntl = RREG32(RADEON_TV_PRE_DAC_MUX_CNTL);
  1170. tmp = dac_cntl2 & ~RADEON_DAC2_DAC2_CLK_SEL;
  1171. WREG32(RADEON_DAC_CNTL2, tmp);
  1172. tmp = tv_master_cntl | RADEON_TV_ON;
  1173. tmp &= ~(RADEON_TV_ASYNC_RST |
  1174. RADEON_RESTART_PHASE_FIX |
  1175. RADEON_CRT_FIFO_CE_EN |
  1176. RADEON_TV_FIFO_CE_EN |
  1177. RADEON_RE_SYNC_NOW_SEL_MASK);
  1178. tmp |= RADEON_TV_FIFO_ASYNC_RST | RADEON_CRT_ASYNC_RST;
  1179. WREG32(RADEON_TV_MASTER_CNTL, tmp);
  1180. tmp = RADEON_TV_DAC_NBLANK | RADEON_TV_DAC_NHOLD |
  1181. RADEON_TV_MONITOR_DETECT_EN | RADEON_TV_DAC_STD_NTSC |
  1182. (8 << RADEON_TV_DAC_BGADJ_SHIFT);
  1183. if (config_cntl & RADEON_CFG_ATI_REV_ID_MASK)
  1184. tmp |= (4 << RADEON_TV_DAC_DACADJ_SHIFT);
  1185. else
  1186. tmp |= (8 << RADEON_TV_DAC_DACADJ_SHIFT);
  1187. WREG32(RADEON_TV_DAC_CNTL, tmp);
  1188. tmp = RADEON_C_GRN_EN | RADEON_CMP_BLU_EN |
  1189. RADEON_RED_MX_FORCE_DAC_DATA |
  1190. RADEON_GRN_MX_FORCE_DAC_DATA |
  1191. RADEON_BLU_MX_FORCE_DAC_DATA |
  1192. (0x109 << RADEON_TV_FORCE_DAC_DATA_SHIFT);
  1193. WREG32(RADEON_TV_PRE_DAC_MUX_CNTL, tmp);
  1194. mdelay(3);
  1195. tmp = RREG32(RADEON_TV_DAC_CNTL);
  1196. if (tmp & RADEON_TV_DAC_GDACDET) {
  1197. found = true;
  1198. DRM_DEBUG_KMS("S-video TV connection detected\n");
  1199. } else if ((tmp & RADEON_TV_DAC_BDACDET) != 0) {
  1200. found = true;
  1201. DRM_DEBUG_KMS("Composite TV connection detected\n");
  1202. }
  1203. WREG32(RADEON_TV_PRE_DAC_MUX_CNTL, tv_pre_dac_mux_cntl);
  1204. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  1205. WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl);
  1206. WREG32(RADEON_DAC_CNTL2, dac_cntl2);
  1207. return found;
  1208. }
  1209. static bool radeon_legacy_ext_dac_detect(struct drm_encoder *encoder,
  1210. struct drm_connector *connector)
  1211. {
  1212. struct drm_device *dev = encoder->dev;
  1213. struct radeon_device *rdev = dev->dev_private;
  1214. uint32_t gpio_monid, fp2_gen_cntl, disp_output_cntl, crtc2_gen_cntl;
  1215. uint32_t disp_lin_trans_grph_a, disp_lin_trans_grph_b, disp_lin_trans_grph_c;
  1216. uint32_t disp_lin_trans_grph_d, disp_lin_trans_grph_e, disp_lin_trans_grph_f;
  1217. uint32_t tmp, crtc2_h_total_disp, crtc2_v_total_disp;
  1218. uint32_t crtc2_h_sync_strt_wid, crtc2_v_sync_strt_wid;
  1219. bool found = false;
  1220. int i;
  1221. /* save the regs we need */
  1222. gpio_monid = RREG32(RADEON_GPIO_MONID);
  1223. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  1224. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
  1225. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
  1226. disp_lin_trans_grph_a = RREG32(RADEON_DISP_LIN_TRANS_GRPH_A);
  1227. disp_lin_trans_grph_b = RREG32(RADEON_DISP_LIN_TRANS_GRPH_B);
  1228. disp_lin_trans_grph_c = RREG32(RADEON_DISP_LIN_TRANS_GRPH_C);
  1229. disp_lin_trans_grph_d = RREG32(RADEON_DISP_LIN_TRANS_GRPH_D);
  1230. disp_lin_trans_grph_e = RREG32(RADEON_DISP_LIN_TRANS_GRPH_E);
  1231. disp_lin_trans_grph_f = RREG32(RADEON_DISP_LIN_TRANS_GRPH_F);
  1232. crtc2_h_total_disp = RREG32(RADEON_CRTC2_H_TOTAL_DISP);
  1233. crtc2_v_total_disp = RREG32(RADEON_CRTC2_V_TOTAL_DISP);
  1234. crtc2_h_sync_strt_wid = RREG32(RADEON_CRTC2_H_SYNC_STRT_WID);
  1235. crtc2_v_sync_strt_wid = RREG32(RADEON_CRTC2_V_SYNC_STRT_WID);
  1236. tmp = RREG32(RADEON_GPIO_MONID);
  1237. tmp &= ~RADEON_GPIO_A_0;
  1238. WREG32(RADEON_GPIO_MONID, tmp);
  1239. WREG32(RADEON_FP2_GEN_CNTL, (RADEON_FP2_ON |
  1240. RADEON_FP2_PANEL_FORMAT |
  1241. R200_FP2_SOURCE_SEL_TRANS_UNIT |
  1242. RADEON_FP2_DVO_EN |
  1243. R200_FP2_DVO_RATE_SEL_SDR));
  1244. WREG32(RADEON_DISP_OUTPUT_CNTL, (RADEON_DISP_DAC_SOURCE_RMX |
  1245. RADEON_DISP_TRANS_MATRIX_GRAPHICS));
  1246. WREG32(RADEON_CRTC2_GEN_CNTL, (RADEON_CRTC2_EN |
  1247. RADEON_CRTC2_DISP_REQ_EN_B));
  1248. WREG32(RADEON_DISP_LIN_TRANS_GRPH_A, 0x00000000);
  1249. WREG32(RADEON_DISP_LIN_TRANS_GRPH_B, 0x000003f0);
  1250. WREG32(RADEON_DISP_LIN_TRANS_GRPH_C, 0x00000000);
  1251. WREG32(RADEON_DISP_LIN_TRANS_GRPH_D, 0x000003f0);
  1252. WREG32(RADEON_DISP_LIN_TRANS_GRPH_E, 0x00000000);
  1253. WREG32(RADEON_DISP_LIN_TRANS_GRPH_F, 0x000003f0);
  1254. WREG32(RADEON_CRTC2_H_TOTAL_DISP, 0x01000008);
  1255. WREG32(RADEON_CRTC2_H_SYNC_STRT_WID, 0x00000800);
  1256. WREG32(RADEON_CRTC2_V_TOTAL_DISP, 0x00080001);
  1257. WREG32(RADEON_CRTC2_V_SYNC_STRT_WID, 0x00000080);
  1258. for (i = 0; i < 200; i++) {
  1259. tmp = RREG32(RADEON_GPIO_MONID);
  1260. if (tmp & RADEON_GPIO_Y_0)
  1261. found = true;
  1262. if (found)
  1263. break;
  1264. if (!drm_can_sleep())
  1265. mdelay(1);
  1266. else
  1267. msleep(1);
  1268. }
  1269. /* restore the regs we used */
  1270. WREG32(RADEON_DISP_LIN_TRANS_GRPH_A, disp_lin_trans_grph_a);
  1271. WREG32(RADEON_DISP_LIN_TRANS_GRPH_B, disp_lin_trans_grph_b);
  1272. WREG32(RADEON_DISP_LIN_TRANS_GRPH_C, disp_lin_trans_grph_c);
  1273. WREG32(RADEON_DISP_LIN_TRANS_GRPH_D, disp_lin_trans_grph_d);
  1274. WREG32(RADEON_DISP_LIN_TRANS_GRPH_E, disp_lin_trans_grph_e);
  1275. WREG32(RADEON_DISP_LIN_TRANS_GRPH_F, disp_lin_trans_grph_f);
  1276. WREG32(RADEON_CRTC2_H_TOTAL_DISP, crtc2_h_total_disp);
  1277. WREG32(RADEON_CRTC2_V_TOTAL_DISP, crtc2_v_total_disp);
  1278. WREG32(RADEON_CRTC2_H_SYNC_STRT_WID, crtc2_h_sync_strt_wid);
  1279. WREG32(RADEON_CRTC2_V_SYNC_STRT_WID, crtc2_v_sync_strt_wid);
  1280. WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
  1281. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  1282. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  1283. WREG32(RADEON_GPIO_MONID, gpio_monid);
  1284. return found;
  1285. }
  1286. static enum drm_connector_status radeon_legacy_tv_dac_detect(struct drm_encoder *encoder,
  1287. struct drm_connector *connector)
  1288. {
  1289. struct drm_device *dev = encoder->dev;
  1290. struct radeon_device *rdev = dev->dev_private;
  1291. uint32_t crtc2_gen_cntl = 0, tv_dac_cntl, dac_cntl2, dac_ext_cntl;
  1292. uint32_t gpiopad_a = 0, pixclks_cntl, tmp;
  1293. uint32_t disp_output_cntl = 0, disp_hw_debug = 0, crtc_ext_cntl = 0;
  1294. enum drm_connector_status found = connector_status_disconnected;
  1295. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1296. struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv;
  1297. bool color = true;
  1298. struct drm_crtc *crtc;
  1299. /* find out if crtc2 is in use or if this encoder is using it */
  1300. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1301. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  1302. if ((radeon_crtc->crtc_id == 1) && crtc->enabled) {
  1303. if (encoder->crtc != crtc) {
  1304. return connector_status_disconnected;
  1305. }
  1306. }
  1307. }
  1308. if (connector->connector_type == DRM_MODE_CONNECTOR_SVIDEO ||
  1309. connector->connector_type == DRM_MODE_CONNECTOR_Composite ||
  1310. connector->connector_type == DRM_MODE_CONNECTOR_9PinDIN) {
  1311. bool tv_detect;
  1312. if (radeon_encoder->active_device && !(radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT))
  1313. return connector_status_disconnected;
  1314. tv_detect = radeon_legacy_tv_detect(encoder, connector);
  1315. if (tv_detect && tv_dac)
  1316. found = connector_status_connected;
  1317. return found;
  1318. }
  1319. /* don't probe if the encoder is being used for something else not CRT related */
  1320. if (radeon_encoder->active_device && !(radeon_encoder->active_device & ATOM_DEVICE_CRT_SUPPORT)) {
  1321. DRM_INFO("not detecting due to %08x\n", radeon_encoder->active_device);
  1322. return connector_status_disconnected;
  1323. }
  1324. /* R200 uses an external DAC for secondary DAC */
  1325. if (rdev->family == CHIP_R200) {
  1326. if (radeon_legacy_ext_dac_detect(encoder, connector))
  1327. found = connector_status_connected;
  1328. return found;
  1329. }
  1330. /* save the regs we need */
  1331. pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  1332. if (rdev->flags & RADEON_SINGLE_CRTC) {
  1333. crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
  1334. } else {
  1335. if (ASIC_IS_R300(rdev)) {
  1336. gpiopad_a = RREG32(RADEON_GPIOPAD_A);
  1337. disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
  1338. } else {
  1339. disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG);
  1340. }
  1341. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
  1342. }
  1343. tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  1344. dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
  1345. dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
  1346. tmp = pixclks_cntl & ~(RADEON_PIX2CLK_ALWAYS_ONb
  1347. | RADEON_PIX2CLK_DAC_ALWAYS_ONb);
  1348. WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
  1349. if (rdev->flags & RADEON_SINGLE_CRTC) {
  1350. tmp = crtc_ext_cntl | RADEON_CRTC_CRT_ON;
  1351. WREG32(RADEON_CRTC_EXT_CNTL, tmp);
  1352. } else {
  1353. tmp = crtc2_gen_cntl & ~RADEON_CRTC2_PIX_WIDTH_MASK;
  1354. tmp |= RADEON_CRTC2_CRT2_ON |
  1355. (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT);
  1356. WREG32(RADEON_CRTC2_GEN_CNTL, tmp);
  1357. if (ASIC_IS_R300(rdev)) {
  1358. WREG32_P(RADEON_GPIOPAD_A, 1, ~1);
  1359. tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK;
  1360. tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
  1361. WREG32(RADEON_DISP_OUTPUT_CNTL, tmp);
  1362. } else {
  1363. tmp = disp_hw_debug & ~RADEON_CRT2_DISP1_SEL;
  1364. WREG32(RADEON_DISP_HW_DEBUG, tmp);
  1365. }
  1366. }
  1367. tmp = RADEON_TV_DAC_NBLANK |
  1368. RADEON_TV_DAC_NHOLD |
  1369. RADEON_TV_MONITOR_DETECT_EN |
  1370. RADEON_TV_DAC_STD_PS2;
  1371. WREG32(RADEON_TV_DAC_CNTL, tmp);
  1372. tmp = RADEON_DAC2_FORCE_BLANK_OFF_EN |
  1373. RADEON_DAC2_FORCE_DATA_EN;
  1374. if (color)
  1375. tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
  1376. else
  1377. tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
  1378. if (ASIC_IS_R300(rdev))
  1379. tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
  1380. else
  1381. tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
  1382. WREG32(RADEON_DAC_EXT_CNTL, tmp);
  1383. tmp = dac_cntl2 | RADEON_DAC2_DAC2_CLK_SEL | RADEON_DAC2_CMP_EN;
  1384. WREG32(RADEON_DAC_CNTL2, tmp);
  1385. mdelay(10);
  1386. if (ASIC_IS_R300(rdev)) {
  1387. if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUT_B)
  1388. found = connector_status_connected;
  1389. } else {
  1390. if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUTPUT)
  1391. found = connector_status_connected;
  1392. }
  1393. /* restore regs we used */
  1394. WREG32(RADEON_DAC_CNTL2, dac_cntl2);
  1395. WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
  1396. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  1397. if (rdev->flags & RADEON_SINGLE_CRTC) {
  1398. WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
  1399. } else {
  1400. WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
  1401. if (ASIC_IS_R300(rdev)) {
  1402. WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
  1403. WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
  1404. } else {
  1405. WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
  1406. }
  1407. }
  1408. WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
  1409. return found;
  1410. }
  1411. static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs = {
  1412. .dpms = radeon_legacy_tv_dac_dpms,
  1413. .mode_fixup = radeon_legacy_mode_fixup,
  1414. .prepare = radeon_legacy_tv_dac_prepare,
  1415. .mode_set = radeon_legacy_tv_dac_mode_set,
  1416. .commit = radeon_legacy_tv_dac_commit,
  1417. .detect = radeon_legacy_tv_dac_detect,
  1418. .disable = radeon_legacy_encoder_disable,
  1419. };
  1420. static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs = {
  1421. .destroy = radeon_enc_destroy,
  1422. };
  1423. static struct radeon_encoder_int_tmds *radeon_legacy_get_tmds_info(struct radeon_encoder *encoder)
  1424. {
  1425. struct drm_device *dev = encoder->base.dev;
  1426. struct radeon_device *rdev = dev->dev_private;
  1427. struct radeon_encoder_int_tmds *tmds = NULL;
  1428. bool ret;
  1429. tmds = kzalloc(sizeof(struct radeon_encoder_int_tmds), GFP_KERNEL);
  1430. if (!tmds)
  1431. return NULL;
  1432. if (rdev->is_atom_bios)
  1433. ret = radeon_atombios_get_tmds_info(encoder, tmds);
  1434. else
  1435. ret = radeon_legacy_get_tmds_info_from_combios(encoder, tmds);
  1436. if (ret == false)
  1437. radeon_legacy_get_tmds_info_from_table(encoder, tmds);
  1438. return tmds;
  1439. }
  1440. static struct radeon_encoder_ext_tmds *radeon_legacy_get_ext_tmds_info(struct radeon_encoder *encoder)
  1441. {
  1442. struct drm_device *dev = encoder->base.dev;
  1443. struct radeon_device *rdev = dev->dev_private;
  1444. struct radeon_encoder_ext_tmds *tmds = NULL;
  1445. bool ret;
  1446. if (rdev->is_atom_bios)
  1447. return NULL;
  1448. tmds = kzalloc(sizeof(struct radeon_encoder_ext_tmds), GFP_KERNEL);
  1449. if (!tmds)
  1450. return NULL;
  1451. ret = radeon_legacy_get_ext_tmds_info_from_combios(encoder, tmds);
  1452. if (ret == false)
  1453. radeon_legacy_get_ext_tmds_info_from_table(encoder, tmds);
  1454. return tmds;
  1455. }
  1456. void
  1457. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum, uint32_t supported_device)
  1458. {
  1459. struct radeon_device *rdev = dev->dev_private;
  1460. struct drm_encoder *encoder;
  1461. struct radeon_encoder *radeon_encoder;
  1462. /* see if we already added it */
  1463. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1464. radeon_encoder = to_radeon_encoder(encoder);
  1465. if (radeon_encoder->encoder_enum == encoder_enum) {
  1466. radeon_encoder->devices |= supported_device;
  1467. return;
  1468. }
  1469. }
  1470. /* add a new one */
  1471. radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
  1472. if (!radeon_encoder)
  1473. return;
  1474. encoder = &radeon_encoder->base;
  1475. if (rdev->flags & RADEON_SINGLE_CRTC)
  1476. encoder->possible_crtcs = 0x1;
  1477. else
  1478. encoder->possible_crtcs = 0x3;
  1479. radeon_encoder->enc_priv = NULL;
  1480. radeon_encoder->encoder_enum = encoder_enum;
  1481. radeon_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  1482. radeon_encoder->devices = supported_device;
  1483. radeon_encoder->rmx_type = RMX_OFF;
  1484. switch (radeon_encoder->encoder_id) {
  1485. case ENCODER_OBJECT_ID_INTERNAL_LVDS:
  1486. encoder->possible_crtcs = 0x1;
  1487. drm_encoder_init(dev, encoder, &radeon_legacy_lvds_enc_funcs, DRM_MODE_ENCODER_LVDS);
  1488. drm_encoder_helper_add(encoder, &radeon_legacy_lvds_helper_funcs);
  1489. if (rdev->is_atom_bios)
  1490. radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
  1491. else
  1492. radeon_encoder->enc_priv = radeon_combios_get_lvds_info(radeon_encoder);
  1493. radeon_encoder->rmx_type = RMX_FULL;
  1494. break;
  1495. case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
  1496. drm_encoder_init(dev, encoder, &radeon_legacy_tmds_int_enc_funcs, DRM_MODE_ENCODER_TMDS);
  1497. drm_encoder_helper_add(encoder, &radeon_legacy_tmds_int_helper_funcs);
  1498. radeon_encoder->enc_priv = radeon_legacy_get_tmds_info(radeon_encoder);
  1499. break;
  1500. case ENCODER_OBJECT_ID_INTERNAL_DAC1:
  1501. drm_encoder_init(dev, encoder, &radeon_legacy_primary_dac_enc_funcs, DRM_MODE_ENCODER_DAC);
  1502. drm_encoder_helper_add(encoder, &radeon_legacy_primary_dac_helper_funcs);
  1503. if (rdev->is_atom_bios)
  1504. radeon_encoder->enc_priv = radeon_atombios_get_primary_dac_info(radeon_encoder);
  1505. else
  1506. radeon_encoder->enc_priv = radeon_combios_get_primary_dac_info(radeon_encoder);
  1507. break;
  1508. case ENCODER_OBJECT_ID_INTERNAL_DAC2:
  1509. drm_encoder_init(dev, encoder, &radeon_legacy_tv_dac_enc_funcs, DRM_MODE_ENCODER_TVDAC);
  1510. drm_encoder_helper_add(encoder, &radeon_legacy_tv_dac_helper_funcs);
  1511. if (rdev->is_atom_bios)
  1512. radeon_encoder->enc_priv = radeon_atombios_get_tv_dac_info(radeon_encoder);
  1513. else
  1514. radeon_encoder->enc_priv = radeon_combios_get_tv_dac_info(radeon_encoder);
  1515. break;
  1516. case ENCODER_OBJECT_ID_INTERNAL_DVO1:
  1517. drm_encoder_init(dev, encoder, &radeon_legacy_tmds_ext_enc_funcs, DRM_MODE_ENCODER_TMDS);
  1518. drm_encoder_helper_add(encoder, &radeon_legacy_tmds_ext_helper_funcs);
  1519. if (!rdev->is_atom_bios)
  1520. radeon_encoder->enc_priv = radeon_legacy_get_ext_tmds_info(radeon_encoder);
  1521. break;
  1522. }
  1523. }