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"
29 #include "radeon_drv.h"
32 static void radeon_legacy_rmx_mode_set(struct drm_encoder *encoder,
33 struct drm_display_mode *mode,
34 struct drm_display_mode *adjusted_mode)
36 struct drm_device *dev = encoder->dev;
37 struct drm_radeon_private *dev_priv = dev->dev_private;
38 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
39 int xres = mode->hdisplay;
40 int yres = mode->vdisplay;
41 bool hscale = true, vscale = true;
46 uint32_t fp_horz_stretch, fp_vert_stretch, crtc_more_cntl, fp_horz_vert_active;
47 uint32_t fp_h_sync_strt_wid, fp_v_sync_strt_wid, fp_crtc_h_total_disp, fp_crtc_v_total_disp;
51 fp_vert_stretch = RADEON_READ(RADEON_FP_VERT_STRETCH) &
52 (RADEON_VERT_STRETCH_RESERVED |
53 RADEON_VERT_AUTO_RATIO_INC);
54 fp_horz_stretch = RADEON_READ(RADEON_FP_HORZ_STRETCH) &
55 (RADEON_HORZ_FP_LOOP_STRETCH |
56 RADEON_HORZ_AUTO_RATIO_INC);
59 if ((dev_priv->chip_family == CHIP_RS100) ||
60 (dev_priv->chip_family == CHIP_RS200)) {
61 /* This is to workaround the asic bug for RMX, some versions
62 of BIOS dosen't have this register initialized correctly. */
63 crtc_more_cntl |= RADEON_CRTC_H_CUTOFF_ACTIVE_EN;
67 fp_crtc_h_total_disp = ((((mode->crtc_htotal / 8) - 1) & 0x3ff)
68 | ((((mode->crtc_hdisplay / 8) - 1) & 0x1ff) << 16));
70 hsync_wid = (mode->crtc_hsync_end - mode->crtc_hsync_start) / 8;
73 hsync_start = mode->crtc_hsync_start - 8;
75 fp_h_sync_strt_wid = ((hsync_start & 0x1fff)
76 | ((hsync_wid & 0x3f) << 16)
77 | ((mode->flags & DRM_MODE_FLAG_NHSYNC)
78 ? RADEON_CRTC_H_SYNC_POL
81 fp_crtc_v_total_disp = (((mode->crtc_vtotal - 1) & 0xffff)
82 | ((mode->crtc_vdisplay - 1) << 16));
84 vsync_wid = mode->crtc_vsync_end - mode->crtc_vsync_start;
88 fp_v_sync_strt_wid = (((mode->crtc_vsync_start - 1) & 0xfff)
89 | ((vsync_wid & 0x1f) << 16)
90 | ((mode->flags & DRM_MODE_FLAG_NVSYNC)
91 ? RADEON_CRTC_V_SYNC_POL
94 fp_horz_vert_active = 0;
96 if (radeon_encoder->panel_xres == 0 ||
97 radeon_encoder->panel_yres == 0) {
101 if (xres > radeon_encoder->panel_xres)
102 xres = radeon_encoder->panel_xres;
103 if (yres > radeon_encoder->panel_yres)
104 yres = radeon_encoder->panel_yres;
106 if (xres == radeon_encoder->panel_xres)
108 if (yres == radeon_encoder->panel_yres)
112 if (radeon_encoder->flags & RADEON_USE_RMX) {
113 if (radeon_encoder->rmx_type != RMX_CENTER) {
115 fp_horz_stretch |= ((xres/8-1) << 16);
117 inc = (fp_horz_stretch & RADEON_HORZ_AUTO_RATIO_INC) ? 1 : 0;
118 scale = ((xres + inc) * RADEON_HORZ_STRETCH_RATIO_MAX)
119 / radeon_encoder->panel_xres + 1;
120 fp_horz_stretch |= (((scale) & RADEON_HORZ_STRETCH_RATIO_MASK) |
121 RADEON_HORZ_STRETCH_BLEND |
122 RADEON_HORZ_STRETCH_ENABLE |
123 ((radeon_encoder->panel_xres/8-1) << 16));
127 fp_vert_stretch |= ((yres-1) << 12);
129 inc = (fp_vert_stretch & RADEON_VERT_AUTO_RATIO_INC) ? 1 : 0;
130 scale = ((yres + inc) * RADEON_VERT_STRETCH_RATIO_MAX)
131 / radeon_encoder->panel_yres + 1;
132 fp_vert_stretch |= (((scale) & RADEON_VERT_STRETCH_RATIO_MASK) |
133 RADEON_VERT_STRETCH_ENABLE |
134 RADEON_VERT_STRETCH_BLEND |
135 ((radeon_encoder->panel_yres-1) << 12));
137 } else if (radeon_encoder->rmx_type == RMX_CENTER) {
140 fp_horz_stretch |= ((xres/8-1) << 16);
141 fp_vert_stretch |= ((yres-1) << 12);
143 crtc_more_cntl |= (RADEON_CRTC_AUTO_HORZ_CENTER_EN |
144 RADEON_CRTC_AUTO_VERT_CENTER_EN);
146 blank_width = (mode->crtc_hblank_end - mode->crtc_hblank_start) / 8;
147 if (blank_width > 110)
150 fp_crtc_h_total_disp = (((blank_width) & 0x3ff)
151 | ((((mode->crtc_hdisplay / 8) - 1) & 0x1ff) << 16));
153 hsync_wid = (mode->crtc_hsync_end - mode->crtc_hsync_start) / 8;
157 fp_h_sync_strt_wid = ((((mode->crtc_hsync_start - mode->crtc_hblank_start) / 8) & 0x1fff)
158 | ((hsync_wid & 0x3f) << 16)
159 | ((mode->flags & DRM_MODE_FLAG_NHSYNC)
160 ? RADEON_CRTC_H_SYNC_POL
163 fp_crtc_v_total_disp = (((mode->crtc_vblank_end - mode->crtc_vblank_start) & 0xffff)
164 | ((mode->crtc_vdisplay - 1) << 16));
166 vsync_wid = mode->crtc_vsync_end - mode->crtc_vsync_start;
170 fp_v_sync_strt_wid = ((((mode->crtc_vsync_start - mode->crtc_vblank_start) & 0xfff)
171 | ((vsync_wid & 0x1f) << 16)
172 | ((mode->flags & DRM_MODE_FLAG_NVSYNC)
173 ? RADEON_CRTC_V_SYNC_POL
176 fp_horz_vert_active = (((radeon_encoder->panel_yres) & 0xfff) |
177 (((radeon_encoder->panel_xres / 8) & 0x1ff) << 16));
180 fp_horz_stretch |= ((xres/8-1) << 16);
181 fp_vert_stretch |= ((yres-1) << 12);
184 RADEON_WRITE(RADEON_FP_HORZ_STRETCH, fp_horz_stretch);
185 RADEON_WRITE(RADEON_FP_VERT_STRETCH, fp_vert_stretch);
186 RADEON_WRITE(RADEON_CRTC_MORE_CNTL, crtc_more_cntl);
187 RADEON_WRITE(RADEON_FP_HORZ_VERT_ACTIVE, fp_horz_vert_active);
188 RADEON_WRITE(RADEON_FP_H_SYNC_STRT_WID, fp_h_sync_strt_wid);
189 RADEON_WRITE(RADEON_FP_V_SYNC_STRT_WID, fp_v_sync_strt_wid);
190 RADEON_WRITE(RADEON_FP_CRTC_H_TOTAL_DISP, fp_crtc_h_total_disp);
191 RADEON_WRITE(RADEON_FP_CRTC_V_TOTAL_DISP, fp_crtc_v_total_disp);
195 static void radeon_legacy_lvds_dpms(struct drm_encoder *encoder, int mode)
197 struct drm_device *dev = encoder->dev;
198 struct drm_radeon_private *dev_priv = dev->dev_private;
199 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
200 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
201 uint32_t lvds_gen_cntl, lvds_pll_cntl, pixclks_cntl, disp_pwr_man;
202 uint32_t bios_5_scratch, bios_6_scratch;
206 // FIXME atom/legacy cards like r4xx
207 bios_5_scratch = RADEON_READ(RADEON_BIOS_5_SCRATCH);
208 bios_6_scratch = RADEON_READ(RADEON_BIOS_6_SCRATCH);
210 bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
211 bios_5_scratch |= (radeon_crtc->crtc_id << RADEON_LCD1_CRTC_SHIFT);
214 case DRM_MODE_DPMS_ON:
215 disp_pwr_man = RADEON_READ(RADEON_DISP_PWR_MAN);
216 disp_pwr_man |= RADEON_AUTO_PWRUP_EN;
217 RADEON_WRITE(RADEON_DISP_PWR_MAN, disp_pwr_man);
218 lvds_pll_cntl = RADEON_READ(RADEON_LVDS_PLL_CNTL);
219 lvds_pll_cntl |= RADEON_LVDS_PLL_EN;
220 RADEON_WRITE(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
222 lvds_pll_cntl = RADEON_READ(RADEON_LVDS_PLL_CNTL);
223 lvds_pll_cntl &= ~RADEON_LVDS_PLL_RESET;
224 RADEON_WRITE(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
226 lvds_gen_cntl = RADEON_READ(RADEON_LVDS_GEN_CNTL);
227 lvds_gen_cntl |= (RADEON_LVDS_ON | RADEON_LVDS_EN | RADEON_LVDS_DIGON | RADEON_LVDS_BLON);
228 lvds_gen_cntl &= ~(RADEON_LVDS_DISPLAY_DIS);
229 udelay(radeon_encoder->panel_pwr_delay);
230 RADEON_WRITE(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
232 /* update bios scratch regs */
233 bios_5_scratch |= RADEON_LCD1_ON;
234 bios_6_scratch |= RADEON_LCD_DPMS_ON;
237 case DRM_MODE_DPMS_STANDBY:
238 case DRM_MODE_DPMS_SUSPEND:
239 case DRM_MODE_DPMS_OFF:
240 pixclks_cntl = RADEON_READ_PLL(dev_priv, RADEON_PIXCLKS_CNTL);
241 RADEON_WRITE_PLL_P(dev_priv, RADEON_PIXCLKS_CNTL, 0, ~RADEON_PIXCLK_LVDS_ALWAYS_ONb);
242 lvds_gen_cntl = RADEON_READ(RADEON_LVDS_GEN_CNTL);
243 lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
244 lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_BLON | RADEON_LVDS_EN | RADEON_LVDS_DIGON);
245 udelay(radeon_encoder->panel_pwr_delay);
246 RADEON_WRITE(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
247 RADEON_WRITE_PLL(dev_priv, RADEON_PIXCLKS_CNTL, pixclks_cntl);
249 bios_5_scratch &= ~RADEON_LCD1_ON;
250 bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
253 RADEON_WRITE(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
254 RADEON_WRITE(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
257 static void radeon_legacy_lvds_prepare(struct drm_encoder *encoder)
259 // fix me: atom/legacy r4xx
260 radeon_combios_output_lock(encoder, true);
261 radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_OFF);
264 static void radeon_legacy_lvds_commit(struct drm_encoder *encoder)
266 radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_ON);
267 // fix me: atom/legacy r4xx
268 radeon_combios_output_lock(encoder, false);
271 static void radeon_legacy_lvds_mode_set(struct drm_encoder *encoder,
272 struct drm_display_mode *mode,
273 struct drm_display_mode *adjusted_mode)
275 struct drm_device *dev = encoder->dev;
276 struct drm_radeon_private *dev_priv = dev->dev_private;
277 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
278 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
279 uint32_t lvds_pll_cntl, lvds_gen_cntl, lvds_ss_gen_cntl;
283 if (radeon_crtc->crtc_id == 0)
284 radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
286 lvds_pll_cntl = RADEON_READ(RADEON_LVDS_PLL_CNTL);
287 lvds_pll_cntl &= ~RADEON_LVDS_PLL_EN;
288 if (radeon_encoder->lvds_gen_cntl)
289 lvds_gen_cntl = radeon_encoder->lvds_gen_cntl;
291 lvds_gen_cntl = RADEON_READ(RADEON_LVDS_GEN_CNTL);
292 lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
293 lvds_gen_cntl &= ~(RADEON_LVDS_ON |
298 if (radeon_is_r300(dev_priv))
299 lvds_pll_cntl &= ~(R300_LVDS_SRC_SEL_MASK);
301 if (radeon_crtc->crtc_id == 0) {
302 if (radeon_is_r300(dev_priv)) {
303 if (radeon_encoder->flags & RADEON_USE_RMX)
304 lvds_pll_cntl |= R300_LVDS_SRC_SEL_RMX;
306 lvds_gen_cntl &= ~RADEON_LVDS_SEL_CRTC2;
308 if (radeon_is_r300(dev_priv)) {
309 lvds_pll_cntl |= R300_LVDS_SRC_SEL_CRTC2;
311 lvds_gen_cntl |= RADEON_LVDS_SEL_CRTC2;
314 RADEON_WRITE(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
315 RADEON_WRITE(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
317 lvds_ss_gen_cntl = RADEON_READ(RADEON_LVDS_SS_GEN_CNTL);
318 if (radeon_encoder->panel_digon_delay &&
319 radeon_encoder->panel_blon_delay) {
320 lvds_ss_gen_cntl &= ~((0xf << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
321 (0xf << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
322 lvds_ss_gen_cntl |= ((radeon_encoder->panel_digon_delay << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
323 (radeon_encoder->panel_blon_delay << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
326 if (dev_priv->chip_family == CHIP_RV410)
327 RADEON_WRITE(RADEON_CLOCK_CNTL_INDEX, 0);
330 static bool radeon_legacy_lvds_mode_fixup(struct drm_encoder *encoder,
331 struct drm_display_mode *mode,
332 struct drm_display_mode *adjusted_mode)
334 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
336 radeon_encoder->flags &= ~RADEON_USE_RMX;
338 if (radeon_encoder->rmx_type != RMX_OFF)
339 radeon_rmx_mode_fixup(encoder, mode, adjusted_mode);
344 static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs = {
345 .dpms = radeon_legacy_lvds_dpms,
346 .mode_fixup = radeon_legacy_lvds_mode_fixup,
347 .prepare = radeon_legacy_lvds_prepare,
348 .mode_set = radeon_legacy_lvds_mode_set,
349 .commit = radeon_legacy_lvds_commit,
353 static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs = {
354 .destroy = radeon_enc_destroy,
358 struct drm_encoder *radeon_encoder_legacy_lvds_add(struct drm_device *dev, int bios_index)
360 struct radeon_encoder *radeon_encoder;
361 struct drm_encoder *encoder;
365 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
366 if (!radeon_encoder) {
370 encoder = &radeon_encoder->base;
372 encoder->possible_crtcs = 0x3;
373 encoder->possible_clones = 0;
374 drm_encoder_init(dev, encoder, &radeon_legacy_lvds_enc_funcs,
375 DRM_MODE_ENCODER_LVDS);
377 drm_encoder_helper_add(encoder, &radeon_legacy_lvds_helper_funcs);
379 /* get the lvds info from the bios */
380 radeon_combios_get_lvds_info(radeon_encoder);
382 /* LVDS gets default RMX full scaling */
383 radeon_encoder->rmx_type = RMX_FULL;
388 static bool radeon_legacy_primary_dac_mode_fixup(struct drm_encoder *encoder,
389 struct drm_display_mode *mode,
390 struct drm_display_mode *adjusted_mode)
395 static void radeon_legacy_primary_dac_dpms(struct drm_encoder *encoder, int mode)
397 struct drm_device *dev = encoder->dev;
398 struct drm_radeon_private *dev_priv = dev->dev_private;
399 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
400 uint32_t crtc_ext_cntl = RADEON_READ(RADEON_CRTC_EXT_CNTL);
401 uint32_t dac_cntl = RADEON_READ(RADEON_DAC_CNTL);
402 uint32_t dac_macro_cntl = RADEON_READ(RADEON_DAC_MACRO_CNTL);
403 uint32_t bios_5_scratch, bios_6_scratch;
407 // FIXME atom/legacy cards like r4xx
408 bios_5_scratch = RADEON_READ(RADEON_BIOS_5_SCRATCH);
409 bios_6_scratch = RADEON_READ(RADEON_BIOS_6_SCRATCH);
411 bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
412 bios_5_scratch |= (radeon_crtc->crtc_id << RADEON_CRT1_CRTC_SHIFT);
417 case DRM_MODE_DPMS_ON:
418 crtc_ext_cntl |= RADEON_CRTC_CRT_ON;
419 dac_cntl &= ~RADEON_DAC_PDWN;
420 dac_macro_cntl &= ~(RADEON_DAC_PDWN_R |
423 bios_5_scratch |= RADEON_CRT1_ON;
424 bios_6_scratch |= RADEON_CRT_DPMS_ON;
426 case DRM_MODE_DPMS_STANDBY:
427 case DRM_MODE_DPMS_SUSPEND:
428 case DRM_MODE_DPMS_OFF:
429 crtc_ext_cntl &= ~RADEON_CRTC_CRT_ON;
430 dac_cntl |= RADEON_DAC_PDWN;
431 dac_macro_cntl |= (RADEON_DAC_PDWN_R |
434 bios_5_scratch &= ~RADEON_CRT1_ON;
435 bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
439 RADEON_WRITE(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
440 RADEON_WRITE(RADEON_DAC_CNTL, dac_cntl);
441 RADEON_WRITE(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
443 RADEON_WRITE(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
444 RADEON_WRITE(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
447 static void radeon_legacy_primary_dac_prepare(struct drm_encoder *encoder)
449 // fix me: atom/legacy r4xx
450 radeon_combios_output_lock(encoder, true);
451 radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
454 static void radeon_legacy_primary_dac_commit(struct drm_encoder *encoder)
456 radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_ON);
457 // fix me: atom/legacy r4xx
458 radeon_combios_output_lock(encoder, false);
461 static void radeon_legacy_primary_dac_mode_set(struct drm_encoder *encoder,
462 struct drm_display_mode *mode,
463 struct drm_display_mode *adjusted_mode)
465 struct drm_device *dev = encoder->dev;
466 struct drm_radeon_private *dev_priv = dev->dev_private;
467 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
468 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
469 uint32_t disp_output_cntl, dac_cntl, dac2_cntl, dac_macro_cntl;
473 if (radeon_crtc->crtc_id == 0)
474 radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
476 if (radeon_crtc->crtc_id == 0) {
477 if (dev_priv->chip_family == CHIP_R200 || radeon_is_r300(dev_priv)) {
478 disp_output_cntl = RADEON_READ(RADEON_DISP_OUTPUT_CNTL) &
479 ~(RADEON_DISP_DAC_SOURCE_MASK);
480 RADEON_WRITE(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
482 dac2_cntl = RADEON_READ(RADEON_DAC_CNTL2) & ~(RADEON_DAC2_DAC_CLK_SEL);
483 RADEON_WRITE(RADEON_DAC_CNTL2, dac2_cntl);
486 if (dev_priv->chip_family == CHIP_R200 || radeon_is_r300(dev_priv)) {
487 disp_output_cntl = RADEON_READ(RADEON_DISP_OUTPUT_CNTL) &
488 ~(RADEON_DISP_DAC_SOURCE_MASK);
489 disp_output_cntl |= RADEON_DISP_DAC_SOURCE_CRTC2;
490 RADEON_WRITE(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
492 dac2_cntl = RADEON_READ(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC_CLK_SEL;
493 RADEON_WRITE(RADEON_DAC_CNTL2, dac2_cntl);
497 dac_cntl = (RADEON_DAC_MASK_ALL |
498 RADEON_DAC_VGA_ADR_EN |
502 RADEON_WRITE_P(RADEON_DAC_CNTL,
504 RADEON_DAC_RANGE_CNTL |
505 RADEON_DAC_BLANKING);
507 if (radeon_encoder->ps2_pdac_adj)
508 dac_macro_cntl = radeon_encoder->ps2_pdac_adj;
510 dac_macro_cntl = RADEON_READ(RADEON_DAC_MACRO_CNTL);
511 dac_macro_cntl |= RADEON_DAC_PDWN_R | RADEON_DAC_PDWN_G | RADEON_DAC_PDWN_B;
512 RADEON_WRITE(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
515 static enum drm_connector_status radeon_legacy_primary_dac_detect(struct drm_encoder *encoder,
516 struct drm_connector *connector)
518 struct drm_device *dev = encoder->dev;
519 struct drm_radeon_private *dev_priv = dev->dev_private;
520 uint32_t vclk_ecp_cntl, crtc_ext_cntl;
521 uint32_t dac_ext_cntl, dac_cntl, dac_macro_cntl, tmp;
522 enum drm_connector_status found = connector_status_disconnected;
525 /* save the regs we need */
526 vclk_ecp_cntl = RADEON_READ_PLL(dev_priv, RADEON_VCLK_ECP_CNTL);
527 crtc_ext_cntl = RADEON_READ(RADEON_CRTC_EXT_CNTL);
528 dac_ext_cntl = RADEON_READ(RADEON_DAC_EXT_CNTL);
529 dac_cntl = RADEON_READ(RADEON_DAC_CNTL);
530 dac_macro_cntl = RADEON_READ(RADEON_DAC_MACRO_CNTL);
532 tmp = vclk_ecp_cntl &
533 ~(RADEON_PIXCLK_ALWAYS_ONb | RADEON_PIXCLK_DAC_ALWAYS_ONb);
534 RADEON_WRITE_PLL(dev_priv, RADEON_VCLK_ECP_CNTL, tmp);
536 tmp = crtc_ext_cntl | RADEON_CRTC_CRT_ON;
537 RADEON_WRITE(RADEON_CRTC_EXT_CNTL, tmp);
539 tmp = RADEON_DAC_FORCE_BLANK_OFF_EN |
540 RADEON_DAC_FORCE_DATA_EN;
543 tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
545 tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
547 if (radeon_is_r300(dev_priv))
548 tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
550 tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
552 RADEON_WRITE(RADEON_DAC_EXT_CNTL, tmp);
554 tmp = dac_cntl & ~(RADEON_DAC_RANGE_CNTL_MASK | RADEON_DAC_PDWN);
555 tmp |= RADEON_DAC_RANGE_CNTL_PS2 | RADEON_DAC_CMP_EN;
556 RADEON_WRITE(RADEON_DAC_CNTL, tmp);
558 tmp &= ~(RADEON_DAC_PDWN_R |
562 RADEON_WRITE(RADEON_DAC_MACRO_CNTL, tmp);
566 if (RADEON_READ(RADEON_DAC_CNTL) & RADEON_DAC_CMP_OUTPUT)
567 found = connector_status_connected;
569 /* restore the regs we used */
570 RADEON_WRITE(RADEON_DAC_CNTL, dac_cntl);
571 RADEON_WRITE(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
572 RADEON_WRITE(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
573 RADEON_WRITE(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
574 RADEON_WRITE_PLL(dev_priv, RADEON_VCLK_ECP_CNTL, vclk_ecp_cntl);
579 static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs = {
580 .dpms = radeon_legacy_primary_dac_dpms,
581 .mode_fixup = radeon_legacy_primary_dac_mode_fixup,
582 .prepare = radeon_legacy_primary_dac_prepare,
583 .mode_set = radeon_legacy_primary_dac_mode_set,
584 .commit = radeon_legacy_primary_dac_commit,
585 .detect = radeon_legacy_primary_dac_detect,
589 static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs = {
590 .destroy = radeon_enc_destroy,
593 struct drm_encoder *radeon_encoder_legacy_primary_dac_add(struct drm_device *dev, int bios_index, int has_tv)
595 struct radeon_encoder *radeon_encoder;
596 struct drm_encoder *encoder;
600 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
601 if (!radeon_encoder) {
605 encoder = &radeon_encoder->base;
607 encoder->possible_crtcs = 0x3;
608 encoder->possible_clones = 0;
609 drm_encoder_init(dev, encoder, &radeon_legacy_primary_dac_enc_funcs,
610 DRM_MODE_ENCODER_DAC);
612 drm_encoder_helper_add(encoder, &radeon_legacy_primary_dac_helper_funcs);
614 /* get the primary dac bg/adj vals from bios tables */
615 radeon_combios_get_primary_dac_info(radeon_encoder);
621 static bool radeon_legacy_tmds_int_mode_fixup(struct drm_encoder *encoder,
622 struct drm_display_mode *mode,
623 struct drm_display_mode *adjusted_mode)
628 static void radeon_legacy_tmds_int_dpms(struct drm_encoder *encoder, int mode)
630 struct drm_device *dev = encoder->dev;
631 struct drm_radeon_private *dev_priv = dev->dev_private;
632 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
633 uint32_t fp_gen_cntl = RADEON_READ(RADEON_FP_GEN_CNTL);
634 uint32_t bios_5_scratch, bios_6_scratch;
638 // FIXME atom/legacy cards like r4xx
639 bios_5_scratch = RADEON_READ(RADEON_BIOS_5_SCRATCH);
640 bios_6_scratch = RADEON_READ(RADEON_BIOS_6_SCRATCH);
642 bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
643 bios_5_scratch |= (radeon_crtc->crtc_id << RADEON_DFP1_CRTC_SHIFT);
646 case DRM_MODE_DPMS_ON:
647 fp_gen_cntl |= (RADEON_FP_FPON | RADEON_FP_TMDS_EN);
648 bios_5_scratch |= RADEON_DFP1_ON;
649 bios_6_scratch |= RADEON_DFP_DPMS_ON;
651 case DRM_MODE_DPMS_STANDBY:
652 case DRM_MODE_DPMS_SUSPEND:
653 case DRM_MODE_DPMS_OFF:
654 fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
655 bios_5_scratch &= ~RADEON_DFP1_ON;
656 bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
660 RADEON_WRITE(RADEON_FP_GEN_CNTL, fp_gen_cntl);
662 RADEON_WRITE(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
663 RADEON_WRITE(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
666 static void radeon_legacy_tmds_int_prepare(struct drm_encoder *encoder)
668 // fix me: atom/legacy r4xx
669 radeon_combios_output_lock(encoder, true);
670 radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_OFF);
673 static void radeon_legacy_tmds_int_commit(struct drm_encoder *encoder)
675 radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_ON);
676 // fix me: atom/legacy r4xx
677 radeon_combios_output_lock(encoder, true);
680 static void radeon_legacy_tmds_int_mode_set(struct drm_encoder *encoder,
681 struct drm_display_mode *mode,
682 struct drm_display_mode *adjusted_mode)
684 struct drm_device *dev = encoder->dev;
685 struct drm_radeon_private *dev_priv = dev->dev_private;
686 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
687 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
688 uint32_t tmp, tmds_pll_cntl, tmds_transmitter_cntl, fp_gen_cntl;
693 if (radeon_crtc->crtc_id == 0)
694 radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
696 tmp = tmds_pll_cntl = RADEON_READ(RADEON_TMDS_PLL_CNTL);
698 if (dev_priv->chip_family == CHIP_RV280) {
699 /* bit 22 of TMDS_PLL_CNTL is read-back inverted */
701 tmds_pll_cntl ^= (1 << 22);
704 for (i = 0; i < 4; i++) {
705 if (radeon_encoder->tmds_pll[i].freq == 0)
707 if ((uint32_t)(mode->clock / 10) < radeon_encoder->tmds_pll[i].freq) {
708 tmp = radeon_encoder->tmds_pll[i].value ;
713 if (radeon_is_r300(dev_priv) || (dev_priv->chip_family == CHIP_RV280)) {
714 if (tmp & 0xfff00000)
717 tmds_pll_cntl &= 0xfff00000;
718 tmds_pll_cntl |= tmp;
723 tmds_transmitter_cntl = RADEON_READ(RADEON_TMDS_TRANSMITTER_CNTL) &
724 ~(RADEON_TMDS_TRANSMITTER_PLLRST);
726 if (dev_priv->chip_family == CHIP_R200 ||
727 dev_priv->chip_family == CHIP_R100 ||
728 radeon_is_r300(dev_priv))
729 tmds_transmitter_cntl &= ~(RADEON_TMDS_TRANSMITTER_PLLEN);
730 else /* RV chips got this bit reversed */
731 tmds_transmitter_cntl |= RADEON_TMDS_TRANSMITTER_PLLEN;
733 fp_gen_cntl = (RADEON_READ(RADEON_FP_GEN_CNTL) |
734 (RADEON_FP_CRTC_DONT_SHADOW_VPAR |
735 RADEON_FP_CRTC_DONT_SHADOW_HEND));
737 fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
739 if (1) // FIXME rgbBits == 8
740 fp_gen_cntl |= RADEON_FP_PANEL_FORMAT; /* 24 bit format */
742 fp_gen_cntl &= ~RADEON_FP_PANEL_FORMAT;/* 18 bit format */
744 if (radeon_crtc->crtc_id == 0) {
745 if (radeon_is_r300(dev_priv) || dev_priv->chip_family == CHIP_R200) {
746 fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
747 if (radeon_encoder->flags & RADEON_USE_RMX)
748 fp_gen_cntl |= R200_FP_SOURCE_SEL_RMX;
750 fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC1;
752 fp_gen_cntl |= RADEON_FP_SEL_CRTC1;
754 if (radeon_is_r300(dev_priv) || dev_priv->chip_family == CHIP_R200) {
755 fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
756 fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC2;
758 fp_gen_cntl |= RADEON_FP_SEL_CRTC2;
761 RADEON_WRITE(RADEON_TMDS_PLL_CNTL, tmds_pll_cntl);
762 RADEON_WRITE(RADEON_TMDS_TRANSMITTER_CNTL, tmds_transmitter_cntl);
763 RADEON_WRITE(RADEON_FP_GEN_CNTL, fp_gen_cntl);
766 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs = {
767 .dpms = radeon_legacy_tmds_int_dpms,
768 .mode_fixup = radeon_legacy_tmds_int_mode_fixup,
769 .prepare = radeon_legacy_tmds_int_prepare,
770 .mode_set = radeon_legacy_tmds_int_mode_set,
771 .commit = radeon_legacy_tmds_int_commit,
775 static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs = {
776 .destroy = radeon_enc_destroy,
779 struct drm_encoder *radeon_encoder_legacy_tmds_int_add(struct drm_device *dev, int bios_index)
781 struct radeon_encoder *radeon_encoder;
782 struct drm_encoder *encoder;
786 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
787 if (!radeon_encoder) {
791 encoder = &radeon_encoder->base;
793 encoder->possible_crtcs = 0x3;
794 encoder->possible_clones = 0;
795 drm_encoder_init(dev, encoder, &radeon_legacy_tmds_int_enc_funcs,
796 DRM_MODE_ENCODER_TMDS);
798 drm_encoder_helper_add(encoder, &radeon_legacy_tmds_int_helper_funcs);
800 radeon_combios_get_tmds_info(radeon_encoder);
805 static bool radeon_legacy_tmds_ext_mode_fixup(struct drm_encoder *encoder,
806 struct drm_display_mode *mode,
807 struct drm_display_mode *adjusted_mode)
812 static void radeon_legacy_tmds_ext_dpms(struct drm_encoder *encoder, int mode)
814 struct drm_device *dev = encoder->dev;
815 struct drm_radeon_private *dev_priv = dev->dev_private;
816 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
817 uint32_t fp2_gen_cntl = RADEON_READ(RADEON_FP2_GEN_CNTL);
818 uint32_t bios_5_scratch, bios_6_scratch;
822 // FIXME atom/legacy cards like r4xx
823 bios_5_scratch = RADEON_READ(RADEON_BIOS_5_SCRATCH);
824 bios_6_scratch = RADEON_READ(RADEON_BIOS_6_SCRATCH);
826 bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
827 bios_5_scratch |= (radeon_crtc->crtc_id << RADEON_DFP2_CRTC_SHIFT);
830 case DRM_MODE_DPMS_ON:
831 fp2_gen_cntl &= ~RADEON_FP2_BLANK_EN;
832 fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
833 bios_5_scratch |= RADEON_DFP2_ON;
834 bios_6_scratch |= RADEON_DFP_DPMS_ON;
836 case DRM_MODE_DPMS_STANDBY:
837 case DRM_MODE_DPMS_SUSPEND:
838 case DRM_MODE_DPMS_OFF:
839 fp2_gen_cntl |= RADEON_FP2_BLANK_EN;
840 fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
841 bios_5_scratch &= ~RADEON_DFP2_ON;
842 bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
846 RADEON_WRITE(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
848 RADEON_WRITE(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
849 RADEON_WRITE(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
852 static void radeon_legacy_tmds_ext_prepare(struct drm_encoder *encoder)
854 // fix me: atom/legacy r4xx
855 radeon_combios_output_lock(encoder, true);
856 radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_OFF);
859 static void radeon_legacy_tmds_ext_commit(struct drm_encoder *encoder)
861 radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_ON);
862 // fix me: atom/legacy r4xx
863 radeon_combios_output_lock(encoder, false);
866 static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder *encoder,
867 struct drm_display_mode *mode,
868 struct drm_display_mode *adjusted_mode)
870 struct drm_device *dev = encoder->dev;
871 struct drm_radeon_private *dev_priv = dev->dev_private;
872 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
873 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
874 uint32_t fp2_gen_cntl = RADEON_READ(RADEON_FP2_GEN_CNTL);
878 if (radeon_crtc->crtc_id == 0)
879 radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
881 if (1) // FIXME rgbBits == 8
882 fp2_gen_cntl |= RADEON_FP2_PANEL_FORMAT; /* 24 bit format, */
884 fp2_gen_cntl &= ~RADEON_FP2_PANEL_FORMAT;/* 18 bit format, */
886 fp2_gen_cntl &= ~(RADEON_FP2_ON |
888 RADEON_FP2_DVO_RATE_SEL_SDR);
890 /* XXX: these are oem specific */
891 if (radeon_is_r300(dev_priv)) {
892 if ((dev->pdev->device == 0x4850) &&
893 (dev->pdev->subsystem_vendor == 0x1028) &&
894 (dev->pdev->subsystem_device == 0x2001)) /* Dell Inspiron 8600 */
895 fp2_gen_cntl |= R300_FP2_DVO_CLOCK_MODE_SINGLE;
897 fp2_gen_cntl |= RADEON_FP2_PAD_FLOP_EN | R300_FP2_DVO_CLOCK_MODE_SINGLE;
899 /*if (mode->clock > 165000)
900 fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/
903 if (radeon_crtc->crtc_id == 0) {
904 if ((dev_priv->chip_family == CHIP_R200) || radeon_is_r300(dev_priv)) {
905 fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
906 if (radeon_encoder->flags & RADEON_USE_RMX)
907 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_RMX;
909 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC1;
911 fp2_gen_cntl &= ~RADEON_FP2_SRC_SEL_CRTC2;
913 if ((dev_priv->chip_family == CHIP_R200) || radeon_is_r300(dev_priv)) {
914 fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
915 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
917 fp2_gen_cntl |= RADEON_FP2_SRC_SEL_CRTC2;
920 RADEON_WRITE(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
923 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs = {
924 .dpms = radeon_legacy_tmds_ext_dpms,
925 .mode_fixup = radeon_legacy_tmds_ext_mode_fixup,
926 .prepare = radeon_legacy_tmds_ext_prepare,
927 .mode_set = radeon_legacy_tmds_ext_mode_set,
928 .commit = radeon_legacy_tmds_ext_commit,
932 static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs = {
933 .destroy = radeon_enc_destroy,
936 struct drm_encoder *radeon_encoder_legacy_tmds_ext_add(struct drm_device *dev, int bios_index)
938 struct radeon_encoder *radeon_encoder;
939 struct drm_encoder *encoder;
943 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
944 if (!radeon_encoder) {
948 encoder = &radeon_encoder->base;
950 encoder->possible_crtcs = 0x3;
951 encoder->possible_clones = 0;
952 drm_encoder_init(dev, encoder, &radeon_legacy_tmds_ext_enc_funcs,
953 DRM_MODE_ENCODER_TMDS);
955 drm_encoder_helper_add(encoder, &radeon_legacy_tmds_ext_helper_funcs);
957 //radeon_combios_get_tmds_info(radeon_encoder);
961 static bool radeon_legacy_tv_dac_mode_fixup(struct drm_encoder *encoder,
962 struct drm_display_mode *mode,
963 struct drm_display_mode *adjusted_mode)
968 static void radeon_legacy_tv_dac_dpms(struct drm_encoder *encoder, int mode)
970 struct drm_device *dev = encoder->dev;
971 struct drm_radeon_private *dev_priv = dev->dev_private;
972 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
973 uint32_t fp2_gen_cntl = 0, crtc2_gen_cntl = 0, tv_dac_cntl = 0;
974 //uint32_t tv_master_cntl = 0;
975 uint32_t bios_5_scratch, bios_6_scratch;
979 // FIXME atom/legacy cards like r4xx
980 bios_5_scratch = RADEON_READ(RADEON_BIOS_5_SCRATCH);
981 bios_6_scratch = RADEON_READ(RADEON_BIOS_6_SCRATCH);
983 bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
984 bios_5_scratch |= (radeon_crtc->crtc_id << RADEON_CRT2_CRTC_SHIFT);
986 //bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
987 //bios_5_scratch |= (radeon_crtc->crtc_id << RADEON_TV1_CRTC_SHIFT);
989 if (dev_priv->chip_family == CHIP_R200)
990 fp2_gen_cntl = RADEON_READ(RADEON_FP2_GEN_CNTL);
992 crtc2_gen_cntl = RADEON_READ(RADEON_CRTC2_GEN_CNTL);
994 //tv_master_cntl = RADEON_READ(RADEON_TV_MASTER_CNTL);
995 tv_dac_cntl = RADEON_READ(RADEON_TV_DAC_CNTL);
999 case DRM_MODE_DPMS_ON:
1000 if (dev_priv->chip_family == CHIP_R200)
1001 fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
1003 crtc2_gen_cntl |= RADEON_CRTC2_CRT2_ON;
1004 //tv_master_cntl |= RADEON_TV_ON;
1005 if (dev_priv->chip_family == CHIP_R420 ||
1006 dev_priv->chip_family == CHIP_RV410)
1007 tv_dac_cntl &= ~(R420_TV_DAC_RDACPD |
1008 R420_TV_DAC_GDACPD |
1009 R420_TV_DAC_BDACPD |
1010 RADEON_TV_DAC_BGSLEEP);
1012 tv_dac_cntl &= ~(RADEON_TV_DAC_RDACPD |
1013 RADEON_TV_DAC_GDACPD |
1014 RADEON_TV_DAC_BDACPD |
1015 RADEON_TV_DAC_BGSLEEP);
1017 //bios_5_scratch |= RADEON_TV1_ON;
1018 //bios_6_scratch |= RADEON_TV_DPMS_ON;
1019 bios_5_scratch |= RADEON_CRT2_ON;
1020 bios_6_scratch |= RADEON_CRT_DPMS_ON;
1022 case DRM_MODE_DPMS_STANDBY:
1023 case DRM_MODE_DPMS_SUSPEND:
1024 case DRM_MODE_DPMS_OFF:
1025 if (dev_priv->chip_family == CHIP_R200)
1026 fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
1028 crtc2_gen_cntl &= ~RADEON_CRTC2_CRT2_ON;
1029 //tv_master_cntl &= ~RADEON_TV_ON;
1030 if (dev_priv->chip_family == CHIP_R420 ||
1031 dev_priv->chip_family == CHIP_RV410)
1032 tv_dac_cntl |= (R420_TV_DAC_RDACPD |
1033 R420_TV_DAC_GDACPD |
1034 R420_TV_DAC_BDACPD |
1035 RADEON_TV_DAC_BGSLEEP);
1037 tv_dac_cntl |= (RADEON_TV_DAC_RDACPD |
1038 RADEON_TV_DAC_GDACPD |
1039 RADEON_TV_DAC_BDACPD |
1040 RADEON_TV_DAC_BGSLEEP);
1042 //bios_5_scratch &= ~RADEON_TV1_ON;
1043 //bios_6_scratch &= ~RADEON_TV_DPMS_ON;
1044 bios_5_scratch &= ~RADEON_CRT2_ON;
1045 bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
1049 if (dev_priv->chip_family == CHIP_R200)
1050 RADEON_WRITE(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
1052 RADEON_WRITE(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
1053 //RADEON_WRITE(RADEON_TV_MASTER_CNTL, tv_master_cntl);
1054 RADEON_WRITE(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1057 RADEON_WRITE(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
1058 RADEON_WRITE(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1061 static void radeon_legacy_tv_dac_prepare(struct drm_encoder *encoder)
1063 // fix me: atom/legacy r4xx
1064 radeon_combios_output_lock(encoder, true);
1065 radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
1068 static void radeon_legacy_tv_dac_commit(struct drm_encoder *encoder)
1070 radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_ON);
1071 // fix me: atom/legacy r4xx
1072 radeon_combios_output_lock(encoder, false);
1075 static void radeon_legacy_tv_dac_mode_set(struct drm_encoder *encoder,
1076 struct drm_display_mode *mode,
1077 struct drm_display_mode *adjusted_mode)
1079 struct drm_device *dev = encoder->dev;
1080 struct drm_radeon_private *dev_priv = dev->dev_private;
1081 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1082 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1083 uint32_t tv_dac_cntl, gpiopad_a = 0, dac2_cntl, disp_output_cntl = 0;
1084 uint32_t disp_hw_debug = 0, fp2_gen_cntl = 0;
1088 if (radeon_crtc->crtc_id == 0)
1089 radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
1091 if (dev_priv->chip_family != CHIP_R200) {
1092 tv_dac_cntl = RADEON_READ(RADEON_TV_DAC_CNTL);
1093 if (dev_priv->chip_family == CHIP_R420 ||
1094 dev_priv->chip_family == CHIP_RV410) {
1095 tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
1096 RADEON_TV_DAC_BGADJ_MASK |
1097 R420_TV_DAC_DACADJ_MASK |
1098 R420_TV_DAC_RDACPD |
1099 R420_TV_DAC_GDACPD |
1100 R420_TV_DAC_GDACPD |
1101 R420_TV_DAC_TVENABLE);
1103 tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
1104 RADEON_TV_DAC_BGADJ_MASK |
1105 RADEON_TV_DAC_DACADJ_MASK |
1106 RADEON_TV_DAC_RDACPD |
1107 RADEON_TV_DAC_GDACPD |
1108 RADEON_TV_DAC_GDACPD);
1112 tv_dac_cntl |= (RADEON_TV_DAC_NBLANK |
1113 RADEON_TV_DAC_NHOLD |
1114 RADEON_TV_DAC_STD_PS2 |
1115 radeon_encoder->ps2_tvdac_adj);
1117 RADEON_WRITE(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1120 if (radeon_is_r300(dev_priv)) {
1121 gpiopad_a = RADEON_READ(RADEON_GPIOPAD_A) | 1;
1122 disp_output_cntl = RADEON_READ(RADEON_DISP_OUTPUT_CNTL);
1123 } else if (dev_priv->chip_family == CHIP_R200)
1124 fp2_gen_cntl = RADEON_READ(RADEON_FP2_GEN_CNTL);
1126 disp_hw_debug = RADEON_READ(RADEON_DISP_HW_DEBUG);
1128 dac2_cntl = RADEON_READ(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC2_CLK_SEL;
1130 if (radeon_crtc->crtc_id == 0) {
1131 if (radeon_is_r300(dev_priv)) {
1132 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
1133 disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC;
1134 } else if (dev_priv->chip_family == CHIP_R200) {
1135 fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
1136 RADEON_FP2_DVO_RATE_SEL_SDR);
1138 disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
1140 if (radeon_is_r300(dev_priv)) {
1141 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
1142 disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
1143 } else if (dev_priv->chip_family == CHIP_R200) {
1144 fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
1145 RADEON_FP2_DVO_RATE_SEL_SDR);
1146 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
1148 disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL;
1151 RADEON_WRITE(RADEON_DAC_CNTL2, dac2_cntl);
1153 if (radeon_is_r300(dev_priv)) {
1154 RADEON_WRITE_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
1155 RADEON_WRITE(RADEON_DISP_TV_OUT_CNTL, disp_output_cntl);
1156 } else if (dev_priv->chip_family == CHIP_R200)
1157 RADEON_WRITE(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
1159 RADEON_WRITE(RADEON_DISP_HW_DEBUG, disp_hw_debug);
1163 static enum drm_connector_status radeon_legacy_tv_dac_detect(struct drm_encoder *encoder,
1164 struct drm_connector *connector)
1166 struct drm_device *dev = encoder->dev;
1167 struct drm_radeon_private *dev_priv = dev->dev_private;
1168 uint32_t crtc2_gen_cntl, tv_dac_cntl, dac_cntl2, dac_ext_cntl;
1169 uint32_t disp_hw_debug, disp_output_cntl, gpiopad_a, pixclks_cntl, tmp;
1170 enum drm_connector_status found = connector_status_disconnected;
1175 /* save the regs we need */
1176 pixclks_cntl = RADEON_READ_PLL(dev_priv, RADEON_PIXCLKS_CNTL);
1177 gpiopad_a = radeon_is_r300(dev_priv) ? RADEON_READ(RADEON_GPIOPAD_A) : 0;
1178 disp_output_cntl = radeon_is_r300(dev_priv) ? RADEON_READ(RADEON_DISP_OUTPUT_CNTL) : 0;
1179 disp_hw_debug = radeon_is_r300(dev_priv) ? 0 : RADEON_READ(RADEON_DISP_HW_DEBUG);
1180 crtc2_gen_cntl = RADEON_READ(RADEON_CRTC2_GEN_CNTL);
1181 tv_dac_cntl = RADEON_READ(RADEON_TV_DAC_CNTL);
1182 dac_ext_cntl = RADEON_READ(RADEON_DAC_EXT_CNTL);
1183 dac_cntl2 = RADEON_READ(RADEON_DAC_CNTL2);
1185 tmp = pixclks_cntl & ~(RADEON_PIX2CLK_ALWAYS_ONb
1186 | RADEON_PIX2CLK_DAC_ALWAYS_ONb);
1187 RADEON_WRITE_PLL(dev_priv, RADEON_PIXCLKS_CNTL, tmp);
1189 if (radeon_is_r300(dev_priv))
1190 RADEON_WRITE_P(RADEON_GPIOPAD_A, 1, ~1);
1192 tmp = crtc2_gen_cntl & ~RADEON_CRTC2_PIX_WIDTH_MASK;
1193 tmp |= RADEON_CRTC2_CRT2_ON |
1194 (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT);
1196 RADEON_WRITE(RADEON_CRTC2_GEN_CNTL, tmp);
1198 if (radeon_is_r300(dev_priv)) {
1199 tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK;
1200 tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
1201 RADEON_WRITE(RADEON_DISP_OUTPUT_CNTL, tmp);
1203 tmp = disp_hw_debug & ~RADEON_CRT2_DISP1_SEL;
1204 RADEON_WRITE(RADEON_DISP_HW_DEBUG, tmp);
1207 tmp = RADEON_TV_DAC_NBLANK |
1208 RADEON_TV_DAC_NHOLD |
1209 RADEON_TV_MONITOR_DETECT_EN |
1210 RADEON_TV_DAC_STD_PS2;
1212 RADEON_WRITE(RADEON_TV_DAC_CNTL, tmp);
1214 tmp = RADEON_DAC2_FORCE_BLANK_OFF_EN |
1215 RADEON_DAC2_FORCE_DATA_EN;
1218 tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
1220 tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
1222 if (radeon_is_r300(dev_priv))
1223 tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
1225 tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
1227 RADEON_WRITE(RADEON_DAC_EXT_CNTL, tmp);
1229 tmp = dac_cntl2 | RADEON_DAC2_DAC2_CLK_SEL | RADEON_DAC2_CMP_EN;
1230 RADEON_WRITE(RADEON_DAC_CNTL2, tmp);
1234 if (radeon_is_r300(dev_priv)) {
1235 if (RADEON_READ(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUT_B)
1236 found = connector_status_connected;
1238 if (RADEON_READ(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUTPUT)
1239 found = connector_status_connected;
1242 /* restore regs we used */
1243 RADEON_WRITE(RADEON_DAC_CNTL2, dac_cntl2);
1244 RADEON_WRITE(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
1245 RADEON_WRITE(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1246 RADEON_WRITE(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
1248 if (radeon_is_r300(dev_priv)) {
1249 RADEON_WRITE(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
1250 RADEON_WRITE_P(RADEON_GPIOPAD_A, gpiopad_a, ~1 );
1252 RADEON_WRITE(RADEON_DISP_HW_DEBUG, disp_hw_debug);
1254 RADEON_WRITE_PLL(dev_priv, RADEON_PIXCLKS_CNTL, pixclks_cntl);
1257 return connector_status_disconnected;
1261 static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs = {
1262 .dpms = radeon_legacy_tv_dac_dpms,
1263 .mode_fixup = radeon_legacy_tv_dac_mode_fixup,
1264 .prepare = radeon_legacy_tv_dac_prepare,
1265 .mode_set = radeon_legacy_tv_dac_mode_set,
1266 .commit = radeon_legacy_tv_dac_commit,
1267 .detect = radeon_legacy_tv_dac_detect,
1271 static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs = {
1272 .destroy = radeon_enc_destroy,
1275 struct drm_encoder *radeon_encoder_legacy_tv_dac_add(struct drm_device *dev, int bios_index, int has_tv)
1277 struct radeon_encoder *radeon_encoder;
1278 struct drm_encoder *encoder;
1282 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
1283 if (!radeon_encoder) {
1287 encoder = &radeon_encoder->base;
1289 encoder->possible_crtcs = 0x3;
1290 encoder->possible_clones = 0;
1291 drm_encoder_init(dev, encoder, &radeon_legacy_tv_dac_enc_funcs,
1292 DRM_MODE_ENCODER_DAC);
1294 drm_encoder_helper_add(encoder, &radeon_legacy_tv_dac_helper_funcs);
1296 /* get the tv dac vals from bios tables */
1297 radeon_combios_get_tv_info(radeon_encoder);
1298 radeon_combios_get_tv_dac_info(radeon_encoder);