radeon_legacy_encoders.c 34 KB

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