2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
23 * Authors: Dave Airlie
27 #include "drm_crtc_helper.h"
28 #include "radeon_drm.h"
32 static void radeon_legacy_encoder_disable(struct drm_encoder *encoder)
34 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
35 struct drm_encoder_helper_funcs *encoder_funcs;
37 encoder_funcs = encoder->helper_private;
38 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
39 radeon_encoder->active_device = 0;
42 static void radeon_legacy_lvds_dpms(struct drm_encoder *encoder, int mode)
44 struct drm_device *dev = encoder->dev;
45 struct radeon_device *rdev = dev->dev_private;
46 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
47 uint32_t lvds_gen_cntl, lvds_pll_cntl, pixclks_cntl, disp_pwr_man;
48 int panel_pwr_delay = 2000;
52 if (radeon_encoder->enc_priv) {
53 if (rdev->is_atom_bios) {
54 struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
55 panel_pwr_delay = lvds->panel_pwr_delay;
57 struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
58 panel_pwr_delay = lvds->panel_pwr_delay;
62 /* macs (and possibly some x86 oem systems?) wire up LVDS strangely
63 * Taken from radeonfb.
65 if ((rdev->mode_info.connector_table == CT_IBOOK) ||
66 (rdev->mode_info.connector_table == CT_POWERBOOK_EXTERNAL) ||
67 (rdev->mode_info.connector_table == CT_POWERBOOK_INTERNAL) ||
68 (rdev->mode_info.connector_table == CT_POWERBOOK_VGA))
72 case DRM_MODE_DPMS_ON:
73 disp_pwr_man = RREG32(RADEON_DISP_PWR_MAN);
74 disp_pwr_man |= RADEON_AUTO_PWRUP_EN;
75 WREG32(RADEON_DISP_PWR_MAN, disp_pwr_man);
76 lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
77 lvds_pll_cntl |= RADEON_LVDS_PLL_EN;
78 WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
81 lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
82 lvds_pll_cntl &= ~RADEON_LVDS_PLL_RESET;
83 WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
85 lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
86 lvds_gen_cntl |= (RADEON_LVDS_ON | RADEON_LVDS_EN | RADEON_LVDS_DIGON | RADEON_LVDS_BLON);
88 lvds_gen_cntl |= RADEON_LVDS_BL_MOD_EN;
89 lvds_gen_cntl &= ~(RADEON_LVDS_DISPLAY_DIS);
90 udelay(panel_pwr_delay * 1000);
91 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
93 case DRM_MODE_DPMS_STANDBY:
94 case DRM_MODE_DPMS_SUSPEND:
95 case DRM_MODE_DPMS_OFF:
96 pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL);
97 WREG32_PLL_P(RADEON_PIXCLKS_CNTL, 0, ~RADEON_PIXCLK_LVDS_ALWAYS_ONb);
98 lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
99 lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
101 lvds_gen_cntl &= ~RADEON_LVDS_BL_MOD_EN;
102 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
103 lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_EN);
105 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
106 lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_BLON | RADEON_LVDS_EN | RADEON_LVDS_DIGON);
108 udelay(panel_pwr_delay * 1000);
109 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
110 WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
114 if (rdev->is_atom_bios)
115 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
117 radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
119 /* adjust pm to dpms change */
120 radeon_pm_compute_clocks(rdev);
123 static void radeon_legacy_lvds_prepare(struct drm_encoder *encoder)
125 struct radeon_device *rdev = encoder->dev->dev_private;
127 if (rdev->is_atom_bios)
128 radeon_atom_output_lock(encoder, true);
130 radeon_combios_output_lock(encoder, true);
131 radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_OFF);
134 static void radeon_legacy_lvds_commit(struct drm_encoder *encoder)
136 struct radeon_device *rdev = encoder->dev->dev_private;
138 radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_ON);
139 if (rdev->is_atom_bios)
140 radeon_atom_output_lock(encoder, false);
142 radeon_combios_output_lock(encoder, false);
145 static void radeon_legacy_lvds_mode_set(struct drm_encoder *encoder,
146 struct drm_display_mode *mode,
147 struct drm_display_mode *adjusted_mode)
149 struct drm_device *dev = encoder->dev;
150 struct radeon_device *rdev = dev->dev_private;
151 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
152 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
153 uint32_t lvds_pll_cntl, lvds_gen_cntl, lvds_ss_gen_cntl;
157 lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
158 lvds_pll_cntl &= ~RADEON_LVDS_PLL_EN;
160 lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
161 if (rdev->is_atom_bios) {
162 /* LVDS_GEN_CNTL parameters are computed in LVDSEncoderControl
163 * need to call that on resume to set up the reg properly.
165 radeon_encoder->pixel_clock = adjusted_mode->clock;
166 atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE);
167 lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
169 struct radeon_encoder_lvds *lvds = (struct radeon_encoder_lvds *)radeon_encoder->enc_priv;
171 DRM_DEBUG("bios LVDS_GEN_CNTL: 0x%x\n", lvds->lvds_gen_cntl);
172 lvds_gen_cntl = lvds->lvds_gen_cntl;
173 lvds_ss_gen_cntl &= ~((0xf << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
174 (0xf << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
175 lvds_ss_gen_cntl |= ((lvds->panel_digon_delay << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
176 (lvds->panel_blon_delay << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
178 lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
180 lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
181 lvds_gen_cntl &= ~(RADEON_LVDS_ON |
186 if (ASIC_IS_R300(rdev))
187 lvds_pll_cntl &= ~(R300_LVDS_SRC_SEL_MASK);
189 if (radeon_crtc->crtc_id == 0) {
190 if (ASIC_IS_R300(rdev)) {
191 if (radeon_encoder->rmx_type != RMX_OFF)
192 lvds_pll_cntl |= R300_LVDS_SRC_SEL_RMX;
194 lvds_gen_cntl &= ~RADEON_LVDS_SEL_CRTC2;
196 if (ASIC_IS_R300(rdev))
197 lvds_pll_cntl |= R300_LVDS_SRC_SEL_CRTC2;
199 lvds_gen_cntl |= RADEON_LVDS_SEL_CRTC2;
202 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
203 WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
204 WREG32(RADEON_LVDS_SS_GEN_CNTL, lvds_ss_gen_cntl);
206 if (rdev->family == CHIP_RV410)
207 WREG32(RADEON_CLOCK_CNTL_INDEX, 0);
209 if (rdev->is_atom_bios)
210 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
212 radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
215 static bool radeon_legacy_mode_fixup(struct drm_encoder *encoder,
216 struct drm_display_mode *mode,
217 struct drm_display_mode *adjusted_mode)
219 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
220 struct drm_device *dev = encoder->dev;
221 struct radeon_device *rdev = dev->dev_private;
223 /* adjust pm to upcoming mode change */
224 radeon_pm_compute_clocks(rdev);
226 /* set the active encoder to connector routing */
227 radeon_encoder_set_active_device(encoder);
228 drm_mode_set_crtcinfo(adjusted_mode, 0);
230 /* get the native mode for LVDS */
231 if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT)) {
232 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
233 int mode_id = adjusted_mode->base.id;
234 *adjusted_mode = *native_mode;
235 adjusted_mode->hdisplay = mode->hdisplay;
236 adjusted_mode->vdisplay = mode->vdisplay;
237 adjusted_mode->crtc_hdisplay = mode->hdisplay;
238 adjusted_mode->crtc_vdisplay = mode->vdisplay;
239 adjusted_mode->base.id = mode_id;
245 static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs = {
246 .dpms = radeon_legacy_lvds_dpms,
247 .mode_fixup = radeon_legacy_mode_fixup,
248 .prepare = radeon_legacy_lvds_prepare,
249 .mode_set = radeon_legacy_lvds_mode_set,
250 .commit = radeon_legacy_lvds_commit,
251 .disable = radeon_legacy_encoder_disable,
255 static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs = {
256 .destroy = radeon_enc_destroy,
259 static void radeon_legacy_primary_dac_dpms(struct drm_encoder *encoder, int mode)
261 struct drm_device *dev = encoder->dev;
262 struct radeon_device *rdev = dev->dev_private;
263 uint32_t crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
264 uint32_t dac_cntl = RREG32(RADEON_DAC_CNTL);
265 uint32_t dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
270 case DRM_MODE_DPMS_ON:
271 crtc_ext_cntl |= RADEON_CRTC_CRT_ON;
272 dac_cntl &= ~RADEON_DAC_PDWN;
273 dac_macro_cntl &= ~(RADEON_DAC_PDWN_R |
277 case DRM_MODE_DPMS_STANDBY:
278 case DRM_MODE_DPMS_SUSPEND:
279 case DRM_MODE_DPMS_OFF:
280 crtc_ext_cntl &= ~RADEON_CRTC_CRT_ON;
281 dac_cntl |= RADEON_DAC_PDWN;
282 dac_macro_cntl |= (RADEON_DAC_PDWN_R |
288 WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
289 WREG32(RADEON_DAC_CNTL, dac_cntl);
290 WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
292 if (rdev->is_atom_bios)
293 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
295 radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
297 /* adjust pm to dpms change */
298 radeon_pm_compute_clocks(rdev);
301 static void radeon_legacy_primary_dac_prepare(struct drm_encoder *encoder)
303 struct radeon_device *rdev = encoder->dev->dev_private;
305 if (rdev->is_atom_bios)
306 radeon_atom_output_lock(encoder, true);
308 radeon_combios_output_lock(encoder, true);
309 radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
312 static void radeon_legacy_primary_dac_commit(struct drm_encoder *encoder)
314 struct radeon_device *rdev = encoder->dev->dev_private;
316 radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_ON);
318 if (rdev->is_atom_bios)
319 radeon_atom_output_lock(encoder, false);
321 radeon_combios_output_lock(encoder, false);
324 static void radeon_legacy_primary_dac_mode_set(struct drm_encoder *encoder,
325 struct drm_display_mode *mode,
326 struct drm_display_mode *adjusted_mode)
328 struct drm_device *dev = encoder->dev;
329 struct radeon_device *rdev = dev->dev_private;
330 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
331 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
332 uint32_t disp_output_cntl, dac_cntl, dac2_cntl, dac_macro_cntl;
336 if (radeon_crtc->crtc_id == 0) {
337 if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) {
338 disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) &
339 ~(RADEON_DISP_DAC_SOURCE_MASK);
340 WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
342 dac2_cntl = RREG32(RADEON_DAC_CNTL2) & ~(RADEON_DAC2_DAC_CLK_SEL);
343 WREG32(RADEON_DAC_CNTL2, dac2_cntl);
346 if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) {
347 disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) &
348 ~(RADEON_DISP_DAC_SOURCE_MASK);
349 disp_output_cntl |= RADEON_DISP_DAC_SOURCE_CRTC2;
350 WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
352 dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC_CLK_SEL;
353 WREG32(RADEON_DAC_CNTL2, dac2_cntl);
357 dac_cntl = (RADEON_DAC_MASK_ALL |
358 RADEON_DAC_VGA_ADR_EN |
362 WREG32_P(RADEON_DAC_CNTL,
364 RADEON_DAC_RANGE_CNTL |
365 RADEON_DAC_BLANKING);
367 if (radeon_encoder->enc_priv) {
368 struct radeon_encoder_primary_dac *p_dac = (struct radeon_encoder_primary_dac *)radeon_encoder->enc_priv;
369 dac_macro_cntl = p_dac->ps2_pdac_adj;
371 dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
372 dac_macro_cntl |= RADEON_DAC_PDWN_R | RADEON_DAC_PDWN_G | RADEON_DAC_PDWN_B;
373 WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
375 if (rdev->is_atom_bios)
376 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
378 radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
381 static enum drm_connector_status radeon_legacy_primary_dac_detect(struct drm_encoder *encoder,
382 struct drm_connector *connector)
384 struct drm_device *dev = encoder->dev;
385 struct radeon_device *rdev = dev->dev_private;
386 uint32_t vclk_ecp_cntl, crtc_ext_cntl;
387 uint32_t dac_ext_cntl, dac_cntl, dac_macro_cntl, tmp;
388 enum drm_connector_status found = connector_status_disconnected;
391 /* save the regs we need */
392 vclk_ecp_cntl = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
393 crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
394 dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
395 dac_cntl = RREG32(RADEON_DAC_CNTL);
396 dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
398 tmp = vclk_ecp_cntl &
399 ~(RADEON_PIXCLK_ALWAYS_ONb | RADEON_PIXCLK_DAC_ALWAYS_ONb);
400 WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
402 tmp = crtc_ext_cntl | RADEON_CRTC_CRT_ON;
403 WREG32(RADEON_CRTC_EXT_CNTL, tmp);
405 tmp = RADEON_DAC_FORCE_BLANK_OFF_EN |
406 RADEON_DAC_FORCE_DATA_EN;
409 tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
411 tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
413 if (ASIC_IS_R300(rdev))
414 tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
416 tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
418 WREG32(RADEON_DAC_EXT_CNTL, tmp);
420 tmp = dac_cntl & ~(RADEON_DAC_RANGE_CNTL_MASK | RADEON_DAC_PDWN);
421 tmp |= RADEON_DAC_RANGE_CNTL_PS2 | RADEON_DAC_CMP_EN;
422 WREG32(RADEON_DAC_CNTL, tmp);
424 tmp &= ~(RADEON_DAC_PDWN_R |
428 WREG32(RADEON_DAC_MACRO_CNTL, tmp);
432 if (RREG32(RADEON_DAC_CNTL) & RADEON_DAC_CMP_OUTPUT)
433 found = connector_status_connected;
435 /* restore the regs we used */
436 WREG32(RADEON_DAC_CNTL, dac_cntl);
437 WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
438 WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
439 WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
440 WREG32_PLL(RADEON_VCLK_ECP_CNTL, vclk_ecp_cntl);
445 static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs = {
446 .dpms = radeon_legacy_primary_dac_dpms,
447 .mode_fixup = radeon_legacy_mode_fixup,
448 .prepare = radeon_legacy_primary_dac_prepare,
449 .mode_set = radeon_legacy_primary_dac_mode_set,
450 .commit = radeon_legacy_primary_dac_commit,
451 .detect = radeon_legacy_primary_dac_detect,
452 .disable = radeon_legacy_encoder_disable,
456 static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs = {
457 .destroy = radeon_enc_destroy,
460 static void radeon_legacy_tmds_int_dpms(struct drm_encoder *encoder, int mode)
462 struct drm_device *dev = encoder->dev;
463 struct radeon_device *rdev = dev->dev_private;
464 uint32_t fp_gen_cntl = RREG32(RADEON_FP_GEN_CNTL);
468 case DRM_MODE_DPMS_ON:
469 fp_gen_cntl |= (RADEON_FP_FPON | RADEON_FP_TMDS_EN);
471 case DRM_MODE_DPMS_STANDBY:
472 case DRM_MODE_DPMS_SUSPEND:
473 case DRM_MODE_DPMS_OFF:
474 fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
478 WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl);
480 if (rdev->is_atom_bios)
481 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
483 radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
485 /* adjust pm to dpms change */
486 radeon_pm_compute_clocks(rdev);
489 static void radeon_legacy_tmds_int_prepare(struct drm_encoder *encoder)
491 struct radeon_device *rdev = encoder->dev->dev_private;
493 if (rdev->is_atom_bios)
494 radeon_atom_output_lock(encoder, true);
496 radeon_combios_output_lock(encoder, true);
497 radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_OFF);
500 static void radeon_legacy_tmds_int_commit(struct drm_encoder *encoder)
502 struct radeon_device *rdev = encoder->dev->dev_private;
504 radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_ON);
506 if (rdev->is_atom_bios)
507 radeon_atom_output_lock(encoder, true);
509 radeon_combios_output_lock(encoder, true);
512 static void radeon_legacy_tmds_int_mode_set(struct drm_encoder *encoder,
513 struct drm_display_mode *mode,
514 struct drm_display_mode *adjusted_mode)
516 struct drm_device *dev = encoder->dev;
517 struct radeon_device *rdev = dev->dev_private;
518 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
519 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
520 uint32_t tmp, tmds_pll_cntl, tmds_transmitter_cntl, fp_gen_cntl;
525 tmp = tmds_pll_cntl = RREG32(RADEON_TMDS_PLL_CNTL);
527 if (rdev->family == CHIP_RV280) {
528 /* bit 22 of TMDS_PLL_CNTL is read-back inverted */
530 tmds_pll_cntl ^= (1 << 22);
533 if (radeon_encoder->enc_priv) {
534 struct radeon_encoder_int_tmds *tmds = (struct radeon_encoder_int_tmds *)radeon_encoder->enc_priv;
536 for (i = 0; i < 4; i++) {
537 if (tmds->tmds_pll[i].freq == 0)
539 if ((uint32_t)(mode->clock / 10) < tmds->tmds_pll[i].freq) {
540 tmp = tmds->tmds_pll[i].value ;
546 if (ASIC_IS_R300(rdev) || (rdev->family == CHIP_RV280)) {
547 if (tmp & 0xfff00000)
550 tmds_pll_cntl &= 0xfff00000;
551 tmds_pll_cntl |= tmp;
556 tmds_transmitter_cntl = RREG32(RADEON_TMDS_TRANSMITTER_CNTL) &
557 ~(RADEON_TMDS_TRANSMITTER_PLLRST);
559 if (rdev->family == CHIP_R200 ||
560 rdev->family == CHIP_R100 ||
562 tmds_transmitter_cntl &= ~(RADEON_TMDS_TRANSMITTER_PLLEN);
563 else /* RV chips got this bit reversed */
564 tmds_transmitter_cntl |= RADEON_TMDS_TRANSMITTER_PLLEN;
566 fp_gen_cntl = (RREG32(RADEON_FP_GEN_CNTL) |
567 (RADEON_FP_CRTC_DONT_SHADOW_VPAR |
568 RADEON_FP_CRTC_DONT_SHADOW_HEND));
570 fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
572 fp_gen_cntl &= ~(RADEON_FP_RMX_HVSYNC_CONTROL_EN |
573 RADEON_FP_DFP_SYNC_SEL |
574 RADEON_FP_CRT_SYNC_SEL |
575 RADEON_FP_CRTC_LOCK_8DOT |
576 RADEON_FP_USE_SHADOW_EN |
577 RADEON_FP_CRTC_USE_SHADOW_VEND |
578 RADEON_FP_CRT_SYNC_ALT);
580 if (1) /* FIXME rgbBits == 8 */
581 fp_gen_cntl |= RADEON_FP_PANEL_FORMAT; /* 24 bit format */
583 fp_gen_cntl &= ~RADEON_FP_PANEL_FORMAT;/* 18 bit format */
585 if (radeon_crtc->crtc_id == 0) {
586 if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) {
587 fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
588 if (radeon_encoder->rmx_type != RMX_OFF)
589 fp_gen_cntl |= R200_FP_SOURCE_SEL_RMX;
591 fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC1;
593 fp_gen_cntl &= ~RADEON_FP_SEL_CRTC2;
595 if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) {
596 fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
597 fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC2;
599 fp_gen_cntl |= RADEON_FP_SEL_CRTC2;
602 WREG32(RADEON_TMDS_PLL_CNTL, tmds_pll_cntl);
603 WREG32(RADEON_TMDS_TRANSMITTER_CNTL, tmds_transmitter_cntl);
604 WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl);
606 if (rdev->is_atom_bios)
607 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
609 radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
612 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs = {
613 .dpms = radeon_legacy_tmds_int_dpms,
614 .mode_fixup = radeon_legacy_mode_fixup,
615 .prepare = radeon_legacy_tmds_int_prepare,
616 .mode_set = radeon_legacy_tmds_int_mode_set,
617 .commit = radeon_legacy_tmds_int_commit,
618 .disable = radeon_legacy_encoder_disable,
622 static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs = {
623 .destroy = radeon_enc_destroy,
626 static void radeon_legacy_tmds_ext_dpms(struct drm_encoder *encoder, int mode)
628 struct drm_device *dev = encoder->dev;
629 struct radeon_device *rdev = dev->dev_private;
630 uint32_t fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
634 case DRM_MODE_DPMS_ON:
635 fp2_gen_cntl &= ~RADEON_FP2_BLANK_EN;
636 fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
638 case DRM_MODE_DPMS_STANDBY:
639 case DRM_MODE_DPMS_SUSPEND:
640 case DRM_MODE_DPMS_OFF:
641 fp2_gen_cntl |= RADEON_FP2_BLANK_EN;
642 fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
646 WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
648 if (rdev->is_atom_bios)
649 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
651 radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
653 /* adjust pm to dpms change */
654 radeon_pm_compute_clocks(rdev);
657 static void radeon_legacy_tmds_ext_prepare(struct drm_encoder *encoder)
659 struct radeon_device *rdev = encoder->dev->dev_private;
661 if (rdev->is_atom_bios)
662 radeon_atom_output_lock(encoder, true);
664 radeon_combios_output_lock(encoder, true);
665 radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_OFF);
668 static void radeon_legacy_tmds_ext_commit(struct drm_encoder *encoder)
670 struct radeon_device *rdev = encoder->dev->dev_private;
671 radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_ON);
673 if (rdev->is_atom_bios)
674 radeon_atom_output_lock(encoder, false);
676 radeon_combios_output_lock(encoder, false);
679 static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder *encoder,
680 struct drm_display_mode *mode,
681 struct drm_display_mode *adjusted_mode)
683 struct drm_device *dev = encoder->dev;
684 struct radeon_device *rdev = dev->dev_private;
685 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
686 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
687 uint32_t fp2_gen_cntl;
691 if (rdev->is_atom_bios) {
692 radeon_encoder->pixel_clock = adjusted_mode->clock;
693 atombios_external_tmds_setup(encoder, ATOM_ENABLE);
694 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
696 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
698 if (1) /* FIXME rgbBits == 8 */
699 fp2_gen_cntl |= RADEON_FP2_PANEL_FORMAT; /* 24 bit format, */
701 fp2_gen_cntl &= ~RADEON_FP2_PANEL_FORMAT;/* 18 bit format, */
703 fp2_gen_cntl &= ~(RADEON_FP2_ON |
705 RADEON_FP2_DVO_RATE_SEL_SDR);
707 /* XXX: these are oem specific */
708 if (ASIC_IS_R300(rdev)) {
709 if ((dev->pdev->device == 0x4850) &&
710 (dev->pdev->subsystem_vendor == 0x1028) &&
711 (dev->pdev->subsystem_device == 0x2001)) /* Dell Inspiron 8600 */
712 fp2_gen_cntl |= R300_FP2_DVO_CLOCK_MODE_SINGLE;
714 fp2_gen_cntl |= RADEON_FP2_PAD_FLOP_EN | R300_FP2_DVO_CLOCK_MODE_SINGLE;
716 /*if (mode->clock > 165000)
717 fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/
719 if (!radeon_combios_external_tmds_setup(encoder))
720 radeon_external_tmds_setup(encoder);
723 if (radeon_crtc->crtc_id == 0) {
724 if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) {
725 fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
726 if (radeon_encoder->rmx_type != RMX_OFF)
727 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_RMX;
729 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC1;
731 fp2_gen_cntl &= ~RADEON_FP2_SRC_SEL_CRTC2;
733 if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) {
734 fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
735 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
737 fp2_gen_cntl |= RADEON_FP2_SRC_SEL_CRTC2;
740 WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
742 if (rdev->is_atom_bios)
743 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
745 radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
748 static void radeon_ext_tmds_enc_destroy(struct drm_encoder *encoder)
750 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
751 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv;
754 radeon_i2c_destroy(tmds->i2c_bus);
756 kfree(radeon_encoder->enc_priv);
757 drm_encoder_cleanup(encoder);
758 kfree(radeon_encoder);
761 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs = {
762 .dpms = radeon_legacy_tmds_ext_dpms,
763 .mode_fixup = radeon_legacy_mode_fixup,
764 .prepare = radeon_legacy_tmds_ext_prepare,
765 .mode_set = radeon_legacy_tmds_ext_mode_set,
766 .commit = radeon_legacy_tmds_ext_commit,
767 .disable = radeon_legacy_encoder_disable,
771 static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs = {
772 .destroy = radeon_ext_tmds_enc_destroy,
775 static void radeon_legacy_tv_dac_dpms(struct drm_encoder *encoder, int mode)
777 struct drm_device *dev = encoder->dev;
778 struct radeon_device *rdev = dev->dev_private;
779 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
780 uint32_t fp2_gen_cntl = 0, crtc2_gen_cntl = 0, tv_dac_cntl = 0;
781 uint32_t tv_master_cntl = 0;
785 is_tv = radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT ? true : false;
787 if (rdev->family == CHIP_R200)
788 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
791 tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL);
793 crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
794 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
798 case DRM_MODE_DPMS_ON:
799 if (rdev->family == CHIP_R200) {
800 fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
803 tv_master_cntl |= RADEON_TV_ON;
805 crtc2_gen_cntl |= RADEON_CRTC2_CRT2_ON;
807 if (rdev->family == CHIP_R420 ||
808 rdev->family == CHIP_R423 ||
809 rdev->family == CHIP_RV410)
810 tv_dac_cntl &= ~(R420_TV_DAC_RDACPD |
813 RADEON_TV_DAC_BGSLEEP);
815 tv_dac_cntl &= ~(RADEON_TV_DAC_RDACPD |
816 RADEON_TV_DAC_GDACPD |
817 RADEON_TV_DAC_BDACPD |
818 RADEON_TV_DAC_BGSLEEP);
821 case DRM_MODE_DPMS_STANDBY:
822 case DRM_MODE_DPMS_SUSPEND:
823 case DRM_MODE_DPMS_OFF:
824 if (rdev->family == CHIP_R200)
825 fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
828 tv_master_cntl &= ~RADEON_TV_ON;
830 crtc2_gen_cntl &= ~RADEON_CRTC2_CRT2_ON;
832 if (rdev->family == CHIP_R420 ||
833 rdev->family == CHIP_R423 ||
834 rdev->family == CHIP_RV410)
835 tv_dac_cntl |= (R420_TV_DAC_RDACPD |
838 RADEON_TV_DAC_BGSLEEP);
840 tv_dac_cntl |= (RADEON_TV_DAC_RDACPD |
841 RADEON_TV_DAC_GDACPD |
842 RADEON_TV_DAC_BDACPD |
843 RADEON_TV_DAC_BGSLEEP);
848 if (rdev->family == CHIP_R200) {
849 WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
852 WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl);
854 WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
855 WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
858 if (rdev->is_atom_bios)
859 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
861 radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
863 /* adjust pm to dpms change */
864 radeon_pm_compute_clocks(rdev);
867 static void radeon_legacy_tv_dac_prepare(struct drm_encoder *encoder)
869 struct radeon_device *rdev = encoder->dev->dev_private;
871 if (rdev->is_atom_bios)
872 radeon_atom_output_lock(encoder, true);
874 radeon_combios_output_lock(encoder, true);
875 radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
878 static void radeon_legacy_tv_dac_commit(struct drm_encoder *encoder)
880 struct radeon_device *rdev = encoder->dev->dev_private;
882 radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_ON);
884 if (rdev->is_atom_bios)
885 radeon_atom_output_lock(encoder, true);
887 radeon_combios_output_lock(encoder, true);
890 static void radeon_legacy_tv_dac_mode_set(struct drm_encoder *encoder,
891 struct drm_display_mode *mode,
892 struct drm_display_mode *adjusted_mode)
894 struct drm_device *dev = encoder->dev;
895 struct radeon_device *rdev = dev->dev_private;
896 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
897 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
898 struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv;
899 uint32_t tv_dac_cntl, gpiopad_a = 0, dac2_cntl, disp_output_cntl = 0;
900 uint32_t disp_hw_debug = 0, fp2_gen_cntl = 0, disp_tv_out_cntl = 0;
905 is_tv = radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT ? true : false;
907 if (rdev->family != CHIP_R200) {
908 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
909 if (rdev->family == CHIP_R420 ||
910 rdev->family == CHIP_R423 ||
911 rdev->family == CHIP_RV410) {
912 tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
913 RADEON_TV_DAC_BGADJ_MASK |
914 R420_TV_DAC_DACADJ_MASK |
918 R420_TV_DAC_TVENABLE);
920 tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
921 RADEON_TV_DAC_BGADJ_MASK |
922 RADEON_TV_DAC_DACADJ_MASK |
923 RADEON_TV_DAC_RDACPD |
924 RADEON_TV_DAC_GDACPD |
925 RADEON_TV_DAC_BDACPD);
930 struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv;
931 tv_dac_cntl |= (RADEON_TV_DAC_NBLANK |
932 RADEON_TV_DAC_NHOLD |
933 RADEON_TV_DAC_STD_PS2 |
934 tv_dac->ps2_tvdac_adj);
936 tv_dac_cntl |= (RADEON_TV_DAC_NBLANK |
937 RADEON_TV_DAC_NHOLD |
938 RADEON_TV_DAC_STD_PS2);
940 WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
943 if (ASIC_IS_R300(rdev)) {
944 gpiopad_a = RREG32(RADEON_GPIOPAD_A) | 1;
945 disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
948 if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev))
949 disp_tv_out_cntl = RREG32(RADEON_DISP_TV_OUT_CNTL);
951 disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG);
953 if (rdev->family == CHIP_R200)
954 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
959 dac_cntl = RREG32(RADEON_DAC_CNTL);
960 dac_cntl &= ~RADEON_DAC_TVO_EN;
961 WREG32(RADEON_DAC_CNTL, dac_cntl);
963 if (ASIC_IS_R300(rdev))
964 gpiopad_a = RREG32(RADEON_GPIOPAD_A) & ~1;
966 dac2_cntl = RREG32(RADEON_DAC_CNTL2) & ~RADEON_DAC2_DAC2_CLK_SEL;
967 if (radeon_crtc->crtc_id == 0) {
968 if (ASIC_IS_R300(rdev)) {
969 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
970 disp_output_cntl |= (RADEON_DISP_TVDAC_SOURCE_CRTC |
971 RADEON_DISP_TV_SOURCE_CRTC);
973 if (rdev->family >= CHIP_R200) {
974 disp_tv_out_cntl &= ~RADEON_DISP_TV_PATH_SRC_CRTC2;
976 disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
979 if (ASIC_IS_R300(rdev)) {
980 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
981 disp_output_cntl |= RADEON_DISP_TV_SOURCE_CRTC;
983 if (rdev->family >= CHIP_R200) {
984 disp_tv_out_cntl |= RADEON_DISP_TV_PATH_SRC_CRTC2;
986 disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL;
989 WREG32(RADEON_DAC_CNTL2, dac2_cntl);
992 dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC2_CLK_SEL;
994 if (radeon_crtc->crtc_id == 0) {
995 if (ASIC_IS_R300(rdev)) {
996 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
997 disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC;
998 } else if (rdev->family == CHIP_R200) {
999 fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
1000 RADEON_FP2_DVO_RATE_SEL_SDR);
1002 disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
1004 if (ASIC_IS_R300(rdev)) {
1005 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
1006 disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
1007 } else if (rdev->family == CHIP_R200) {
1008 fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
1009 RADEON_FP2_DVO_RATE_SEL_SDR);
1010 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
1012 disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL;
1014 WREG32(RADEON_DAC_CNTL2, dac2_cntl);
1017 if (ASIC_IS_R300(rdev)) {
1018 WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
1019 WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
1022 if (rdev->family >= CHIP_R200)
1023 WREG32(RADEON_DISP_TV_OUT_CNTL, disp_tv_out_cntl);
1025 WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
1027 if (rdev->family == CHIP_R200)
1028 WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
1031 radeon_legacy_tv_mode_set(encoder, mode, adjusted_mode);
1033 if (rdev->is_atom_bios)
1034 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
1036 radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
1040 static bool r300_legacy_tv_detect(struct drm_encoder *encoder,
1041 struct drm_connector *connector)
1043 struct drm_device *dev = encoder->dev;
1044 struct radeon_device *rdev = dev->dev_private;
1045 uint32_t crtc2_gen_cntl, tv_dac_cntl, dac_cntl2, dac_ext_cntl;
1046 uint32_t disp_output_cntl, gpiopad_a, tmp;
1049 /* save regs needed */
1050 gpiopad_a = RREG32(RADEON_GPIOPAD_A);
1051 dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
1052 crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
1053 dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
1054 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
1055 disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
1057 WREG32_P(RADEON_GPIOPAD_A, 0, ~1);
1059 WREG32(RADEON_DAC_CNTL2, RADEON_DAC2_DAC2_CLK_SEL);
1061 WREG32(RADEON_CRTC2_GEN_CNTL,
1062 RADEON_CRTC2_CRT2_ON | RADEON_CRTC2_VSYNC_TRISTAT);
1064 tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK;
1065 tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
1066 WREG32(RADEON_DISP_OUTPUT_CNTL, tmp);
1068 WREG32(RADEON_DAC_EXT_CNTL,
1069 RADEON_DAC2_FORCE_BLANK_OFF_EN |
1070 RADEON_DAC2_FORCE_DATA_EN |
1071 RADEON_DAC_FORCE_DATA_SEL_RGB |
1072 (0xec << RADEON_DAC_FORCE_DATA_SHIFT));
1074 WREG32(RADEON_TV_DAC_CNTL,
1075 RADEON_TV_DAC_STD_NTSC |
1076 (8 << RADEON_TV_DAC_BGADJ_SHIFT) |
1077 (6 << RADEON_TV_DAC_DACADJ_SHIFT));
1079 RREG32(RADEON_TV_DAC_CNTL);
1082 WREG32(RADEON_TV_DAC_CNTL,
1083 RADEON_TV_DAC_NBLANK |
1084 RADEON_TV_DAC_NHOLD |
1085 RADEON_TV_MONITOR_DETECT_EN |
1086 RADEON_TV_DAC_STD_NTSC |
1087 (8 << RADEON_TV_DAC_BGADJ_SHIFT) |
1088 (6 << RADEON_TV_DAC_DACADJ_SHIFT));
1090 RREG32(RADEON_TV_DAC_CNTL);
1093 tmp = RREG32(RADEON_TV_DAC_CNTL);
1094 if ((tmp & RADEON_TV_DAC_GDACDET) != 0) {
1096 DRM_DEBUG("S-video TV connection detected\n");
1097 } else if ((tmp & RADEON_TV_DAC_BDACDET) != 0) {
1099 DRM_DEBUG("Composite TV connection detected\n");
1102 WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1103 WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
1104 WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
1105 WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
1106 WREG32(RADEON_DAC_CNTL2, dac_cntl2);
1107 WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
1111 static bool radeon_legacy_tv_detect(struct drm_encoder *encoder,
1112 struct drm_connector *connector)
1114 struct drm_device *dev = encoder->dev;
1115 struct radeon_device *rdev = dev->dev_private;
1116 uint32_t tv_dac_cntl, dac_cntl2;
1117 uint32_t config_cntl, tv_pre_dac_mux_cntl, tv_master_cntl, tmp;
1120 if (ASIC_IS_R300(rdev))
1121 return r300_legacy_tv_detect(encoder, connector);
1123 dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
1124 tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL);
1125 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
1126 config_cntl = RREG32(RADEON_CONFIG_CNTL);
1127 tv_pre_dac_mux_cntl = RREG32(RADEON_TV_PRE_DAC_MUX_CNTL);
1129 tmp = dac_cntl2 & ~RADEON_DAC2_DAC2_CLK_SEL;
1130 WREG32(RADEON_DAC_CNTL2, tmp);
1132 tmp = tv_master_cntl | RADEON_TV_ON;
1133 tmp &= ~(RADEON_TV_ASYNC_RST |
1134 RADEON_RESTART_PHASE_FIX |
1135 RADEON_CRT_FIFO_CE_EN |
1136 RADEON_TV_FIFO_CE_EN |
1137 RADEON_RE_SYNC_NOW_SEL_MASK);
1138 tmp |= RADEON_TV_FIFO_ASYNC_RST | RADEON_CRT_ASYNC_RST;
1139 WREG32(RADEON_TV_MASTER_CNTL, tmp);
1141 tmp = RADEON_TV_DAC_NBLANK | RADEON_TV_DAC_NHOLD |
1142 RADEON_TV_MONITOR_DETECT_EN | RADEON_TV_DAC_STD_NTSC |
1143 (8 << RADEON_TV_DAC_BGADJ_SHIFT);
1145 if (config_cntl & RADEON_CFG_ATI_REV_ID_MASK)
1146 tmp |= (4 << RADEON_TV_DAC_DACADJ_SHIFT);
1148 tmp |= (8 << RADEON_TV_DAC_DACADJ_SHIFT);
1149 WREG32(RADEON_TV_DAC_CNTL, tmp);
1151 tmp = RADEON_C_GRN_EN | RADEON_CMP_BLU_EN |
1152 RADEON_RED_MX_FORCE_DAC_DATA |
1153 RADEON_GRN_MX_FORCE_DAC_DATA |
1154 RADEON_BLU_MX_FORCE_DAC_DATA |
1155 (0x109 << RADEON_TV_FORCE_DAC_DATA_SHIFT);
1156 WREG32(RADEON_TV_PRE_DAC_MUX_CNTL, tmp);
1159 tmp = RREG32(RADEON_TV_DAC_CNTL);
1160 if (tmp & RADEON_TV_DAC_GDACDET) {
1162 DRM_DEBUG("S-video TV connection detected\n");
1163 } else if ((tmp & RADEON_TV_DAC_BDACDET) != 0) {
1165 DRM_DEBUG("Composite TV connection detected\n");
1168 WREG32(RADEON_TV_PRE_DAC_MUX_CNTL, tv_pre_dac_mux_cntl);
1169 WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1170 WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl);
1171 WREG32(RADEON_DAC_CNTL2, dac_cntl2);
1175 static enum drm_connector_status radeon_legacy_tv_dac_detect(struct drm_encoder *encoder,
1176 struct drm_connector *connector)
1178 struct drm_device *dev = encoder->dev;
1179 struct radeon_device *rdev = dev->dev_private;
1180 uint32_t crtc2_gen_cntl, tv_dac_cntl, dac_cntl2, dac_ext_cntl;
1181 uint32_t disp_hw_debug, disp_output_cntl, gpiopad_a, pixclks_cntl, tmp;
1182 enum drm_connector_status found = connector_status_disconnected;
1183 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1184 struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv;
1187 if (connector->connector_type == DRM_MODE_CONNECTOR_SVIDEO ||
1188 connector->connector_type == DRM_MODE_CONNECTOR_Composite ||
1189 connector->connector_type == DRM_MODE_CONNECTOR_9PinDIN) {
1192 if (radeon_encoder->active_device && !(radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT))
1193 return connector_status_disconnected;
1195 tv_detect = radeon_legacy_tv_detect(encoder, connector);
1196 if (tv_detect && tv_dac)
1197 found = connector_status_connected;
1201 /* don't probe if the encoder is being used for something else not CRT related */
1202 if (radeon_encoder->active_device && !(radeon_encoder->active_device & ATOM_DEVICE_CRT_SUPPORT)) {
1203 DRM_INFO("not detecting due to %08x\n", radeon_encoder->active_device);
1204 return connector_status_disconnected;
1207 /* save the regs we need */
1208 pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL);
1209 gpiopad_a = ASIC_IS_R300(rdev) ? RREG32(RADEON_GPIOPAD_A) : 0;
1210 disp_output_cntl = ASIC_IS_R300(rdev) ? RREG32(RADEON_DISP_OUTPUT_CNTL) : 0;
1211 disp_hw_debug = ASIC_IS_R300(rdev) ? 0 : RREG32(RADEON_DISP_HW_DEBUG);
1212 crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
1213 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
1214 dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
1215 dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
1217 tmp = pixclks_cntl & ~(RADEON_PIX2CLK_ALWAYS_ONb
1218 | RADEON_PIX2CLK_DAC_ALWAYS_ONb);
1219 WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
1221 if (ASIC_IS_R300(rdev))
1222 WREG32_P(RADEON_GPIOPAD_A, 1, ~1);
1224 tmp = crtc2_gen_cntl & ~RADEON_CRTC2_PIX_WIDTH_MASK;
1225 tmp |= RADEON_CRTC2_CRT2_ON |
1226 (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT);
1228 WREG32(RADEON_CRTC2_GEN_CNTL, tmp);
1230 if (ASIC_IS_R300(rdev)) {
1231 tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK;
1232 tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
1233 WREG32(RADEON_DISP_OUTPUT_CNTL, tmp);
1235 tmp = disp_hw_debug & ~RADEON_CRT2_DISP1_SEL;
1236 WREG32(RADEON_DISP_HW_DEBUG, tmp);
1239 tmp = RADEON_TV_DAC_NBLANK |
1240 RADEON_TV_DAC_NHOLD |
1241 RADEON_TV_MONITOR_DETECT_EN |
1242 RADEON_TV_DAC_STD_PS2;
1244 WREG32(RADEON_TV_DAC_CNTL, tmp);
1246 tmp = RADEON_DAC2_FORCE_BLANK_OFF_EN |
1247 RADEON_DAC2_FORCE_DATA_EN;
1250 tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
1252 tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
1254 if (ASIC_IS_R300(rdev))
1255 tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
1257 tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
1259 WREG32(RADEON_DAC_EXT_CNTL, tmp);
1261 tmp = dac_cntl2 | RADEON_DAC2_DAC2_CLK_SEL | RADEON_DAC2_CMP_EN;
1262 WREG32(RADEON_DAC_CNTL2, tmp);
1266 if (ASIC_IS_R300(rdev)) {
1267 if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUT_B)
1268 found = connector_status_connected;
1270 if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUTPUT)
1271 found = connector_status_connected;
1274 /* restore regs we used */
1275 WREG32(RADEON_DAC_CNTL2, dac_cntl2);
1276 WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
1277 WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1278 WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
1280 if (ASIC_IS_R300(rdev)) {
1281 WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
1282 WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
1284 WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
1286 WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
1292 static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs = {
1293 .dpms = radeon_legacy_tv_dac_dpms,
1294 .mode_fixup = radeon_legacy_mode_fixup,
1295 .prepare = radeon_legacy_tv_dac_prepare,
1296 .mode_set = radeon_legacy_tv_dac_mode_set,
1297 .commit = radeon_legacy_tv_dac_commit,
1298 .detect = radeon_legacy_tv_dac_detect,
1299 .disable = radeon_legacy_encoder_disable,
1303 static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs = {
1304 .destroy = radeon_enc_destroy,
1308 static struct radeon_encoder_int_tmds *radeon_legacy_get_tmds_info(struct radeon_encoder *encoder)
1310 struct drm_device *dev = encoder->base.dev;
1311 struct radeon_device *rdev = dev->dev_private;
1312 struct radeon_encoder_int_tmds *tmds = NULL;
1315 tmds = kzalloc(sizeof(struct radeon_encoder_int_tmds), GFP_KERNEL);
1320 if (rdev->is_atom_bios)
1321 ret = radeon_atombios_get_tmds_info(encoder, tmds);
1323 ret = radeon_legacy_get_tmds_info_from_combios(encoder, tmds);
1326 radeon_legacy_get_tmds_info_from_table(encoder, tmds);
1331 static struct radeon_encoder_ext_tmds *radeon_legacy_get_ext_tmds_info(struct radeon_encoder *encoder)
1333 struct drm_device *dev = encoder->base.dev;
1334 struct radeon_device *rdev = dev->dev_private;
1335 struct radeon_encoder_ext_tmds *tmds = NULL;
1338 if (rdev->is_atom_bios)
1341 tmds = kzalloc(sizeof(struct radeon_encoder_ext_tmds), GFP_KERNEL);
1346 ret = radeon_legacy_get_ext_tmds_info_from_combios(encoder, tmds);
1349 radeon_legacy_get_ext_tmds_info_from_table(encoder, tmds);
1355 radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_id, uint32_t supported_device)
1357 struct radeon_device *rdev = dev->dev_private;
1358 struct drm_encoder *encoder;
1359 struct radeon_encoder *radeon_encoder;
1361 /* see if we already added it */
1362 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1363 radeon_encoder = to_radeon_encoder(encoder);
1364 if (radeon_encoder->encoder_id == encoder_id) {
1365 radeon_encoder->devices |= supported_device;
1372 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
1373 if (!radeon_encoder)
1376 encoder = &radeon_encoder->base;
1377 if (rdev->flags & RADEON_SINGLE_CRTC)
1378 encoder->possible_crtcs = 0x1;
1380 encoder->possible_crtcs = 0x3;
1382 radeon_encoder->enc_priv = NULL;
1384 radeon_encoder->encoder_id = encoder_id;
1385 radeon_encoder->devices = supported_device;
1386 radeon_encoder->rmx_type = RMX_OFF;
1388 switch (radeon_encoder->encoder_id) {
1389 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1390 encoder->possible_crtcs = 0x1;
1391 drm_encoder_init(dev, encoder, &radeon_legacy_lvds_enc_funcs, DRM_MODE_ENCODER_LVDS);
1392 drm_encoder_helper_add(encoder, &radeon_legacy_lvds_helper_funcs);
1393 if (rdev->is_atom_bios)
1394 radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
1396 radeon_encoder->enc_priv = radeon_combios_get_lvds_info(radeon_encoder);
1397 radeon_encoder->rmx_type = RMX_FULL;
1399 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1400 drm_encoder_init(dev, encoder, &radeon_legacy_tmds_int_enc_funcs, DRM_MODE_ENCODER_TMDS);
1401 drm_encoder_helper_add(encoder, &radeon_legacy_tmds_int_helper_funcs);
1402 radeon_encoder->enc_priv = radeon_legacy_get_tmds_info(radeon_encoder);
1404 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1405 drm_encoder_init(dev, encoder, &radeon_legacy_primary_dac_enc_funcs, DRM_MODE_ENCODER_DAC);
1406 drm_encoder_helper_add(encoder, &radeon_legacy_primary_dac_helper_funcs);
1407 if (rdev->is_atom_bios)
1408 radeon_encoder->enc_priv = radeon_atombios_get_primary_dac_info(radeon_encoder);
1410 radeon_encoder->enc_priv = radeon_combios_get_primary_dac_info(radeon_encoder);
1412 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1413 drm_encoder_init(dev, encoder, &radeon_legacy_tv_dac_enc_funcs, DRM_MODE_ENCODER_TVDAC);
1414 drm_encoder_helper_add(encoder, &radeon_legacy_tv_dac_helper_funcs);
1415 if (rdev->is_atom_bios)
1416 radeon_encoder->enc_priv = radeon_atombios_get_tv_dac_info(radeon_encoder);
1418 radeon_encoder->enc_priv = radeon_combios_get_tv_dac_info(radeon_encoder);
1420 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1421 drm_encoder_init(dev, encoder, &radeon_legacy_tmds_ext_enc_funcs, DRM_MODE_ENCODER_TMDS);
1422 drm_encoder_helper_add(encoder, &radeon_legacy_tmds_ext_helper_funcs);
1423 if (!rdev->is_atom_bios)
1424 radeon_encoder->enc_priv = radeon_legacy_get_ext_tmds_info(radeon_encoder);