radeon_legacy_encoders.c 44 KB

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