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;
201 uint32_t lvds_gen_cntl, lvds_pll_cntl, pixclks_cntl, disp_pwr_man;
202 uint32_t bios_5_scratch, bios_6_scratch;
207 radeon_crtc = to_radeon_crtc(encoder->crtc);
208 crtc_id = radeon_crtc->crtc_id;
211 // FIXME atom/legacy cards like r4xx
212 bios_5_scratch = RADEON_READ(RADEON_BIOS_5_SCRATCH);
213 bios_6_scratch = RADEON_READ(RADEON_BIOS_6_SCRATCH);
215 bios_5_scratch &= ~RADEON_LCD1_CRTC_MASK;
216 bios_5_scratch |= (crtc_id << RADEON_LCD1_CRTC_SHIFT);
219 case DRM_MODE_DPMS_ON:
220 disp_pwr_man = RADEON_READ(RADEON_DISP_PWR_MAN);
221 disp_pwr_man |= RADEON_AUTO_PWRUP_EN;
222 RADEON_WRITE(RADEON_DISP_PWR_MAN, disp_pwr_man);
223 lvds_pll_cntl = RADEON_READ(RADEON_LVDS_PLL_CNTL);
224 lvds_pll_cntl |= RADEON_LVDS_PLL_EN;
225 RADEON_WRITE(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
228 lvds_pll_cntl = RADEON_READ(RADEON_LVDS_PLL_CNTL);
229 lvds_pll_cntl &= ~RADEON_LVDS_PLL_RESET;
230 RADEON_WRITE(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
232 lvds_gen_cntl = RADEON_READ(RADEON_LVDS_GEN_CNTL);
233 lvds_gen_cntl |= (RADEON_LVDS_ON | RADEON_LVDS_EN | RADEON_LVDS_DIGON | RADEON_LVDS_BLON);
234 lvds_gen_cntl &= ~(RADEON_LVDS_DISPLAY_DIS);
235 udelay(radeon_encoder->panel_pwr_delay * 1000);
236 RADEON_WRITE(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
238 /* update bios scratch regs */
239 bios_5_scratch |= RADEON_LCD1_ON;
240 bios_6_scratch |= RADEON_LCD_DPMS_ON;
243 case DRM_MODE_DPMS_STANDBY:
244 case DRM_MODE_DPMS_SUSPEND:
245 case DRM_MODE_DPMS_OFF:
246 pixclks_cntl = RADEON_READ_PLL(dev_priv, RADEON_PIXCLKS_CNTL);
247 RADEON_WRITE_PLL_P(dev_priv, RADEON_PIXCLKS_CNTL, 0, ~RADEON_PIXCLK_LVDS_ALWAYS_ONb);
248 lvds_gen_cntl = RADEON_READ(RADEON_LVDS_GEN_CNTL);
249 lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
250 lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_BLON | RADEON_LVDS_EN | RADEON_LVDS_DIGON);
251 udelay(radeon_encoder->panel_pwr_delay * 1000);
252 RADEON_WRITE(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
253 RADEON_WRITE_PLL(dev_priv, RADEON_PIXCLKS_CNTL, pixclks_cntl);
255 bios_5_scratch &= ~RADEON_LCD1_ON;
256 bios_6_scratch &= ~RADEON_LCD_DPMS_ON;
259 RADEON_WRITE(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
260 RADEON_WRITE(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
263 static void radeon_legacy_lvds_prepare(struct drm_encoder *encoder)
265 struct drm_radeon_private *dev_priv = encoder->dev->dev_private;
266 // fix me: atom/legacy r4xx
267 if (!dev_priv->is_atom_bios)
268 radeon_combios_output_lock(encoder, true);
269 radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_OFF);
272 static void radeon_legacy_lvds_commit(struct drm_encoder *encoder)
274 struct drm_radeon_private *dev_priv = encoder->dev->dev_private;
275 radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_ON);
276 // fix me: atom/legacy r4xx
277 if (!dev_priv->is_atom_bios)
278 radeon_combios_output_lock(encoder, false);
281 static void radeon_legacy_lvds_mode_set(struct drm_encoder *encoder,
282 struct drm_display_mode *mode,
283 struct drm_display_mode *adjusted_mode)
285 struct drm_device *dev = encoder->dev;
286 struct drm_radeon_private *dev_priv = dev->dev_private;
287 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
288 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
289 uint32_t lvds_pll_cntl, lvds_gen_cntl, lvds_ss_gen_cntl;
293 if (radeon_crtc->crtc_id == 0)
294 radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
296 lvds_pll_cntl = RADEON_READ(RADEON_LVDS_PLL_CNTL);
297 lvds_pll_cntl &= ~RADEON_LVDS_PLL_EN;
298 if (radeon_encoder->lvds_gen_cntl)
299 lvds_gen_cntl = radeon_encoder->lvds_gen_cntl;
301 lvds_gen_cntl = RADEON_READ(RADEON_LVDS_GEN_CNTL);
302 lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
303 lvds_gen_cntl &= ~(RADEON_LVDS_ON |
308 DRM_INFO("bios LVDS_GEN_CNTL: 0x%x\n", radeon_encoder->lvds_gen_cntl);
310 if (radeon_is_r300(dev_priv))
311 lvds_pll_cntl &= ~(R300_LVDS_SRC_SEL_MASK);
313 if (radeon_crtc->crtc_id == 0) {
314 if (radeon_is_r300(dev_priv)) {
315 if (radeon_encoder->flags & RADEON_USE_RMX)
316 lvds_pll_cntl |= R300_LVDS_SRC_SEL_RMX;
318 lvds_gen_cntl &= ~RADEON_LVDS_SEL_CRTC2;
320 if (radeon_is_r300(dev_priv))
321 lvds_pll_cntl |= R300_LVDS_SRC_SEL_CRTC2;
323 lvds_gen_cntl |= RADEON_LVDS_SEL_CRTC2;
326 RADEON_WRITE(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
327 RADEON_WRITE(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
329 lvds_ss_gen_cntl = RADEON_READ(RADEON_LVDS_SS_GEN_CNTL);
330 if (radeon_encoder->panel_digon_delay &&
331 radeon_encoder->panel_blon_delay) {
332 lvds_ss_gen_cntl &= ~((0xf << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
333 (0xf << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
334 lvds_ss_gen_cntl |= ((radeon_encoder->panel_digon_delay << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
335 (radeon_encoder->panel_blon_delay << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
336 RADEON_WRITE(RADEON_LVDS_SS_GEN_CNTL, lvds_ss_gen_cntl);
339 if (dev_priv->chip_family == CHIP_RV410)
340 RADEON_WRITE(RADEON_CLOCK_CNTL_INDEX, 0);
343 static bool radeon_legacy_lvds_mode_fixup(struct drm_encoder *encoder,
344 struct drm_display_mode *mode,
345 struct drm_display_mode *adjusted_mode)
347 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
349 radeon_encoder->flags &= ~RADEON_USE_RMX;
351 if (radeon_encoder->rmx_type != RMX_OFF)
352 radeon_rmx_mode_fixup(encoder, mode, adjusted_mode);
357 static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs = {
358 .dpms = radeon_legacy_lvds_dpms,
359 .mode_fixup = radeon_legacy_lvds_mode_fixup,
360 .prepare = radeon_legacy_lvds_prepare,
361 .mode_set = radeon_legacy_lvds_mode_set,
362 .commit = radeon_legacy_lvds_commit,
366 static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs = {
367 .destroy = radeon_enc_destroy,
371 struct drm_encoder *radeon_encoder_legacy_lvds_add(struct drm_device *dev, int bios_index)
373 struct drm_radeon_private *dev_priv = dev->dev_private;
374 struct radeon_encoder *radeon_encoder;
375 struct drm_encoder *encoder;
379 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
380 if (!radeon_encoder) {
384 encoder = &radeon_encoder->base;
386 /* Limit LVDS to crtc 0 for RMX */
387 encoder->possible_crtcs = 0x1;
388 encoder->possible_clones = 0;
389 drm_encoder_init(dev, encoder, &radeon_legacy_lvds_enc_funcs,
390 DRM_MODE_ENCODER_LVDS);
392 drm_encoder_helper_add(encoder, &radeon_legacy_lvds_helper_funcs);
394 /* get the lvds info from the bios */
395 if (dev_priv->is_atom_bios)
396 radeon_atombios_get_lvds_info(radeon_encoder);
398 radeon_combios_get_lvds_info(radeon_encoder);
400 /* LVDS gets default RMX full scaling */
401 radeon_encoder->rmx_type = RMX_FULL;
406 static bool radeon_legacy_primary_dac_mode_fixup(struct drm_encoder *encoder,
407 struct drm_display_mode *mode,
408 struct drm_display_mode *adjusted_mode)
413 static void radeon_legacy_primary_dac_dpms(struct drm_encoder *encoder, int mode)
415 struct drm_device *dev = encoder->dev;
416 struct drm_radeon_private *dev_priv = dev->dev_private;
417 struct radeon_crtc *radeon_crtc;
418 uint32_t crtc_ext_cntl = RADEON_READ(RADEON_CRTC_EXT_CNTL);
419 uint32_t dac_cntl = RADEON_READ(RADEON_DAC_CNTL);
420 uint32_t dac_macro_cntl = RADEON_READ(RADEON_DAC_MACRO_CNTL);
421 uint32_t bios_5_scratch, bios_6_scratch;
427 radeon_crtc = to_radeon_crtc(encoder->crtc);
428 crtc_id = radeon_crtc->crtc_id;
431 // FIXME atom/legacy cards like r4xx
432 bios_5_scratch = RADEON_READ(RADEON_BIOS_5_SCRATCH);
433 bios_6_scratch = RADEON_READ(RADEON_BIOS_6_SCRATCH);
435 bios_5_scratch &= ~RADEON_CRT1_CRTC_MASK;
436 bios_5_scratch |= (crtc_id << RADEON_CRT1_CRTC_SHIFT);
441 case DRM_MODE_DPMS_ON:
442 crtc_ext_cntl |= RADEON_CRTC_CRT_ON;
443 dac_cntl &= ~RADEON_DAC_PDWN;
444 dac_macro_cntl &= ~(RADEON_DAC_PDWN_R |
447 bios_5_scratch |= RADEON_CRT1_ON;
448 bios_6_scratch |= RADEON_CRT_DPMS_ON;
450 case DRM_MODE_DPMS_STANDBY:
451 case DRM_MODE_DPMS_SUSPEND:
452 case DRM_MODE_DPMS_OFF:
453 crtc_ext_cntl &= ~RADEON_CRTC_CRT_ON;
454 dac_cntl |= RADEON_DAC_PDWN;
455 dac_macro_cntl |= (RADEON_DAC_PDWN_R |
458 bios_5_scratch &= ~RADEON_CRT1_ON;
459 bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
463 RADEON_WRITE(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
464 RADEON_WRITE(RADEON_DAC_CNTL, dac_cntl);
465 RADEON_WRITE(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
467 RADEON_WRITE(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
468 RADEON_WRITE(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
471 static void radeon_legacy_primary_dac_prepare(struct drm_encoder *encoder)
473 struct drm_radeon_private *dev_priv = encoder->dev->dev_private;
474 // fix me: atom/legacy r4xx
475 if (!dev_priv->is_atom_bios)
476 radeon_combios_output_lock(encoder, true);
477 radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
480 static void radeon_legacy_primary_dac_commit(struct drm_encoder *encoder)
482 struct drm_radeon_private *dev_priv = encoder->dev->dev_private;
483 radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_ON);
484 // fix me: atom/legacy r4xx
485 if (!dev_priv->is_atom_bios)
486 radeon_combios_output_lock(encoder, false);
489 static void radeon_legacy_primary_dac_mode_set(struct drm_encoder *encoder,
490 struct drm_display_mode *mode,
491 struct drm_display_mode *adjusted_mode)
493 struct drm_device *dev = encoder->dev;
494 struct drm_radeon_private *dev_priv = dev->dev_private;
495 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
496 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
497 uint32_t disp_output_cntl, dac_cntl, dac2_cntl, dac_macro_cntl;
501 if (radeon_crtc->crtc_id == 0)
502 radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
504 if (radeon_crtc->crtc_id == 0) {
505 if (dev_priv->chip_family == CHIP_R200 || radeon_is_r300(dev_priv)) {
506 disp_output_cntl = RADEON_READ(RADEON_DISP_OUTPUT_CNTL) &
507 ~(RADEON_DISP_DAC_SOURCE_MASK);
508 RADEON_WRITE(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
510 dac2_cntl = RADEON_READ(RADEON_DAC_CNTL2) & ~(RADEON_DAC2_DAC_CLK_SEL);
511 RADEON_WRITE(RADEON_DAC_CNTL2, dac2_cntl);
514 if (dev_priv->chip_family == CHIP_R200 || radeon_is_r300(dev_priv)) {
515 disp_output_cntl = RADEON_READ(RADEON_DISP_OUTPUT_CNTL) &
516 ~(RADEON_DISP_DAC_SOURCE_MASK);
517 disp_output_cntl |= RADEON_DISP_DAC_SOURCE_CRTC2;
518 RADEON_WRITE(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
520 dac2_cntl = RADEON_READ(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC_CLK_SEL;
521 RADEON_WRITE(RADEON_DAC_CNTL2, dac2_cntl);
525 dac_cntl = (RADEON_DAC_MASK_ALL |
526 RADEON_DAC_VGA_ADR_EN |
530 RADEON_WRITE_P(RADEON_DAC_CNTL,
532 RADEON_DAC_RANGE_CNTL |
533 RADEON_DAC_BLANKING);
535 if (radeon_encoder->ps2_pdac_adj)
536 dac_macro_cntl = radeon_encoder->ps2_pdac_adj;
538 dac_macro_cntl = RADEON_READ(RADEON_DAC_MACRO_CNTL);
539 dac_macro_cntl |= RADEON_DAC_PDWN_R | RADEON_DAC_PDWN_G | RADEON_DAC_PDWN_B;
540 RADEON_WRITE(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
543 static enum drm_connector_status radeon_legacy_primary_dac_detect(struct drm_encoder *encoder,
544 struct drm_connector *connector)
546 struct drm_device *dev = encoder->dev;
547 struct drm_radeon_private *dev_priv = dev->dev_private;
548 uint32_t vclk_ecp_cntl, crtc_ext_cntl;
549 uint32_t dac_ext_cntl, dac_cntl, dac_macro_cntl, tmp;
550 enum drm_connector_status found = connector_status_disconnected;
553 /* save the regs we need */
554 vclk_ecp_cntl = RADEON_READ_PLL(dev_priv, RADEON_VCLK_ECP_CNTL);
555 crtc_ext_cntl = RADEON_READ(RADEON_CRTC_EXT_CNTL);
556 dac_ext_cntl = RADEON_READ(RADEON_DAC_EXT_CNTL);
557 dac_cntl = RADEON_READ(RADEON_DAC_CNTL);
558 dac_macro_cntl = RADEON_READ(RADEON_DAC_MACRO_CNTL);
560 tmp = vclk_ecp_cntl &
561 ~(RADEON_PIXCLK_ALWAYS_ONb | RADEON_PIXCLK_DAC_ALWAYS_ONb);
562 RADEON_WRITE_PLL(dev_priv, RADEON_VCLK_ECP_CNTL, tmp);
564 tmp = crtc_ext_cntl | RADEON_CRTC_CRT_ON;
565 RADEON_WRITE(RADEON_CRTC_EXT_CNTL, tmp);
567 tmp = RADEON_DAC_FORCE_BLANK_OFF_EN |
568 RADEON_DAC_FORCE_DATA_EN;
571 tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
573 tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
575 if (radeon_is_r300(dev_priv))
576 tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
578 tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
580 RADEON_WRITE(RADEON_DAC_EXT_CNTL, tmp);
582 tmp = dac_cntl & ~(RADEON_DAC_RANGE_CNTL_MASK | RADEON_DAC_PDWN);
583 tmp |= RADEON_DAC_RANGE_CNTL_PS2 | RADEON_DAC_CMP_EN;
584 RADEON_WRITE(RADEON_DAC_CNTL, tmp);
586 tmp &= ~(RADEON_DAC_PDWN_R |
590 RADEON_WRITE(RADEON_DAC_MACRO_CNTL, tmp);
594 if (RADEON_READ(RADEON_DAC_CNTL) & RADEON_DAC_CMP_OUTPUT)
595 found = connector_status_connected;
597 /* restore the regs we used */
598 RADEON_WRITE(RADEON_DAC_CNTL, dac_cntl);
599 RADEON_WRITE(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
600 RADEON_WRITE(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
601 RADEON_WRITE(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
602 RADEON_WRITE_PLL(dev_priv, RADEON_VCLK_ECP_CNTL, vclk_ecp_cntl);
607 static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs = {
608 .dpms = radeon_legacy_primary_dac_dpms,
609 .mode_fixup = radeon_legacy_primary_dac_mode_fixup,
610 .prepare = radeon_legacy_primary_dac_prepare,
611 .mode_set = radeon_legacy_primary_dac_mode_set,
612 .commit = radeon_legacy_primary_dac_commit,
613 .detect = radeon_legacy_primary_dac_detect,
617 static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs = {
618 .destroy = radeon_enc_destroy,
621 struct drm_encoder *radeon_encoder_legacy_primary_dac_add(struct drm_device *dev, int bios_index, int has_tv)
623 struct drm_radeon_private *dev_priv = dev->dev_private;
624 struct radeon_encoder *radeon_encoder;
625 struct drm_encoder *encoder;
629 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
630 if (!radeon_encoder) {
634 encoder = &radeon_encoder->base;
636 encoder->possible_crtcs = 0x3;
637 encoder->possible_clones = 0;
638 drm_encoder_init(dev, encoder, &radeon_legacy_primary_dac_enc_funcs,
639 DRM_MODE_ENCODER_DAC);
641 drm_encoder_helper_add(encoder, &radeon_legacy_primary_dac_helper_funcs);
643 /* get the primary dac bg/adj vals from bios tables */
644 if (!dev_priv->is_atom_bios)
645 radeon_combios_get_primary_dac_info(radeon_encoder);
651 static bool radeon_legacy_tmds_int_mode_fixup(struct drm_encoder *encoder,
652 struct drm_display_mode *mode,
653 struct drm_display_mode *adjusted_mode)
658 static void radeon_legacy_tmds_int_dpms(struct drm_encoder *encoder, int mode)
660 struct drm_device *dev = encoder->dev;
661 struct drm_radeon_private *dev_priv = dev->dev_private;
662 struct radeon_crtc *radeon_crtc;
663 uint32_t fp_gen_cntl = RADEON_READ(RADEON_FP_GEN_CNTL);
664 uint32_t bios_5_scratch, bios_6_scratch;
669 radeon_crtc = to_radeon_crtc(encoder->crtc);
670 crtc_id = radeon_crtc->crtc_id;
673 // FIXME atom/legacy cards like r4xx
674 bios_5_scratch = RADEON_READ(RADEON_BIOS_5_SCRATCH);
675 bios_6_scratch = RADEON_READ(RADEON_BIOS_6_SCRATCH);
677 bios_5_scratch &= ~RADEON_DFP1_CRTC_MASK;
678 bios_5_scratch |= (crtc_id << RADEON_DFP1_CRTC_SHIFT);
681 case DRM_MODE_DPMS_ON:
682 fp_gen_cntl |= (RADEON_FP_FPON | RADEON_FP_TMDS_EN);
683 bios_5_scratch |= RADEON_DFP1_ON;
684 bios_6_scratch |= RADEON_DFP_DPMS_ON;
686 case DRM_MODE_DPMS_STANDBY:
687 case DRM_MODE_DPMS_SUSPEND:
688 case DRM_MODE_DPMS_OFF:
689 fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
690 bios_5_scratch &= ~RADEON_DFP1_ON;
691 bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
695 RADEON_WRITE(RADEON_FP_GEN_CNTL, fp_gen_cntl);
697 RADEON_WRITE(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
698 RADEON_WRITE(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
701 static void radeon_legacy_tmds_int_prepare(struct drm_encoder *encoder)
703 struct drm_radeon_private *dev_priv = encoder->dev->dev_private;
704 // fix me: atom/legacy r4xx
705 if (!dev_priv->is_atom_bios)
706 radeon_combios_output_lock(encoder, true);
707 radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_OFF);
710 static void radeon_legacy_tmds_int_commit(struct drm_encoder *encoder)
712 struct drm_radeon_private *dev_priv = encoder->dev->dev_private;
713 radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_ON);
714 // fix me: atom/legacy r4xx
715 if (!dev_priv->is_atom_bios)
716 radeon_combios_output_lock(encoder, true);
719 static void radeon_legacy_tmds_int_mode_set(struct drm_encoder *encoder,
720 struct drm_display_mode *mode,
721 struct drm_display_mode *adjusted_mode)
723 struct drm_device *dev = encoder->dev;
724 struct drm_radeon_private *dev_priv = dev->dev_private;
725 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
726 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
727 uint32_t tmp, tmds_pll_cntl, tmds_transmitter_cntl, fp_gen_cntl;
732 if (radeon_crtc->crtc_id == 0)
733 radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
735 tmp = tmds_pll_cntl = RADEON_READ(RADEON_TMDS_PLL_CNTL);
737 if (dev_priv->chip_family == CHIP_RV280) {
738 /* bit 22 of TMDS_PLL_CNTL is read-back inverted */
740 tmds_pll_cntl ^= (1 << 22);
743 for (i = 0; i < 4; i++) {
744 if (radeon_encoder->tmds_pll[i].freq == 0)
746 if ((uint32_t)(mode->clock / 10) < radeon_encoder->tmds_pll[i].freq) {
747 tmp = radeon_encoder->tmds_pll[i].value ;
752 if (radeon_is_r300(dev_priv) || (dev_priv->chip_family == CHIP_RV280)) {
753 if (tmp & 0xfff00000)
756 tmds_pll_cntl &= 0xfff00000;
757 tmds_pll_cntl |= tmp;
762 tmds_transmitter_cntl = RADEON_READ(RADEON_TMDS_TRANSMITTER_CNTL) &
763 ~(RADEON_TMDS_TRANSMITTER_PLLRST);
765 if (dev_priv->chip_family == CHIP_R200 ||
766 dev_priv->chip_family == CHIP_R100 ||
767 radeon_is_r300(dev_priv))
768 tmds_transmitter_cntl &= ~(RADEON_TMDS_TRANSMITTER_PLLEN);
769 else /* RV chips got this bit reversed */
770 tmds_transmitter_cntl |= RADEON_TMDS_TRANSMITTER_PLLEN;
772 fp_gen_cntl = (RADEON_READ(RADEON_FP_GEN_CNTL) |
773 (RADEON_FP_CRTC_DONT_SHADOW_VPAR |
774 RADEON_FP_CRTC_DONT_SHADOW_HEND));
776 fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
778 if (1) // FIXME rgbBits == 8
779 fp_gen_cntl |= RADEON_FP_PANEL_FORMAT; /* 24 bit format */
781 fp_gen_cntl &= ~RADEON_FP_PANEL_FORMAT;/* 18 bit format */
783 if (radeon_crtc->crtc_id == 0) {
784 if (radeon_is_r300(dev_priv) || dev_priv->chip_family == CHIP_R200) {
785 fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
786 if (radeon_encoder->flags & RADEON_USE_RMX)
787 fp_gen_cntl |= R200_FP_SOURCE_SEL_RMX;
789 fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC1;
791 fp_gen_cntl |= RADEON_FP_SEL_CRTC1;
793 if (radeon_is_r300(dev_priv) || dev_priv->chip_family == CHIP_R200) {
794 fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
795 fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC2;
797 fp_gen_cntl |= RADEON_FP_SEL_CRTC2;
800 RADEON_WRITE(RADEON_TMDS_PLL_CNTL, tmds_pll_cntl);
801 RADEON_WRITE(RADEON_TMDS_TRANSMITTER_CNTL, tmds_transmitter_cntl);
802 RADEON_WRITE(RADEON_FP_GEN_CNTL, fp_gen_cntl);
805 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs = {
806 .dpms = radeon_legacy_tmds_int_dpms,
807 .mode_fixup = radeon_legacy_tmds_int_mode_fixup,
808 .prepare = radeon_legacy_tmds_int_prepare,
809 .mode_set = radeon_legacy_tmds_int_mode_set,
810 .commit = radeon_legacy_tmds_int_commit,
814 static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs = {
815 .destroy = radeon_enc_destroy,
818 struct drm_encoder *radeon_encoder_legacy_tmds_int_add(struct drm_device *dev, int bios_index)
820 struct drm_radeon_private *dev_priv = dev->dev_private;
821 struct radeon_encoder *radeon_encoder;
822 struct drm_encoder *encoder;
826 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
827 if (!radeon_encoder) {
831 encoder = &radeon_encoder->base;
833 encoder->possible_crtcs = 0x3;
834 encoder->possible_clones = 0;
835 drm_encoder_init(dev, encoder, &radeon_legacy_tmds_int_enc_funcs,
836 DRM_MODE_ENCODER_TMDS);
838 drm_encoder_helper_add(encoder, &radeon_legacy_tmds_int_helper_funcs);
840 if (dev_priv->is_atom_bios)
841 radeon_atombios_get_tmds_info(radeon_encoder);
843 radeon_combios_get_tmds_info(radeon_encoder);
848 static bool radeon_legacy_tmds_ext_mode_fixup(struct drm_encoder *encoder,
849 struct drm_display_mode *mode,
850 struct drm_display_mode *adjusted_mode)
855 static void radeon_legacy_tmds_ext_dpms(struct drm_encoder *encoder, int mode)
857 struct drm_device *dev = encoder->dev;
858 struct drm_radeon_private *dev_priv = dev->dev_private;
859 struct radeon_crtc *radeon_crtc;
860 uint32_t fp2_gen_cntl = RADEON_READ(RADEON_FP2_GEN_CNTL);
861 uint32_t bios_5_scratch, bios_6_scratch;
866 radeon_crtc = to_radeon_crtc(encoder->crtc);
867 crtc_id = radeon_crtc->crtc_id;
870 // FIXME atom/legacy cards like r4xx
871 bios_5_scratch = RADEON_READ(RADEON_BIOS_5_SCRATCH);
872 bios_6_scratch = RADEON_READ(RADEON_BIOS_6_SCRATCH);
874 bios_5_scratch &= ~RADEON_DFP2_CRTC_MASK;
875 bios_5_scratch |= (crtc_id << RADEON_DFP2_CRTC_SHIFT);
878 case DRM_MODE_DPMS_ON:
879 fp2_gen_cntl &= ~RADEON_FP2_BLANK_EN;
880 fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
881 bios_5_scratch |= RADEON_DFP2_ON;
882 bios_6_scratch |= RADEON_DFP_DPMS_ON;
884 case DRM_MODE_DPMS_STANDBY:
885 case DRM_MODE_DPMS_SUSPEND:
886 case DRM_MODE_DPMS_OFF:
887 fp2_gen_cntl |= RADEON_FP2_BLANK_EN;
888 fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
889 bios_5_scratch &= ~RADEON_DFP2_ON;
890 bios_6_scratch &= ~RADEON_DFP_DPMS_ON;
894 RADEON_WRITE(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
896 RADEON_WRITE(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
897 RADEON_WRITE(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
900 static void radeon_legacy_tmds_ext_prepare(struct drm_encoder *encoder)
902 struct drm_radeon_private *dev_priv = encoder->dev->dev_private;
903 // fix me: atom/legacy r4xx
904 if (!dev_priv->is_atom_bios)
905 radeon_combios_output_lock(encoder, true);
906 radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_OFF);
909 static void radeon_legacy_tmds_ext_commit(struct drm_encoder *encoder)
911 struct drm_radeon_private *dev_priv = encoder->dev->dev_private;
912 radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_ON);
913 // fix me: atom/legacy r4xx
914 if (!dev_priv->is_atom_bios)
915 radeon_combios_output_lock(encoder, false);
918 static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder *encoder,
919 struct drm_display_mode *mode,
920 struct drm_display_mode *adjusted_mode)
922 struct drm_device *dev = encoder->dev;
923 struct drm_radeon_private *dev_priv = dev->dev_private;
924 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
925 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
926 uint32_t fp2_gen_cntl;
930 if (radeon_crtc->crtc_id == 0)
931 radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
933 if (dev_priv->is_atom_bios) {
934 atombios_ext_tmds_setup(encoder, adjusted_mode);
935 fp2_gen_cntl = RADEON_READ(RADEON_FP2_GEN_CNTL);
937 fp2_gen_cntl = RADEON_READ(RADEON_FP2_GEN_CNTL);
939 if (1) // FIXME rgbBits == 8
940 fp2_gen_cntl |= RADEON_FP2_PANEL_FORMAT; /* 24 bit format, */
942 fp2_gen_cntl &= ~RADEON_FP2_PANEL_FORMAT;/* 18 bit format, */
944 fp2_gen_cntl &= ~(RADEON_FP2_ON |
946 RADEON_FP2_DVO_RATE_SEL_SDR);
948 /* XXX: these are oem specific */
949 if (radeon_is_r300(dev_priv)) {
950 if ((dev->pdev->device == 0x4850) &&
951 (dev->pdev->subsystem_vendor == 0x1028) &&
952 (dev->pdev->subsystem_device == 0x2001)) /* Dell Inspiron 8600 */
953 fp2_gen_cntl |= R300_FP2_DVO_CLOCK_MODE_SINGLE;
955 fp2_gen_cntl |= RADEON_FP2_PAD_FLOP_EN | R300_FP2_DVO_CLOCK_MODE_SINGLE;
957 /*if (mode->clock > 165000)
958 fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/
962 if (radeon_crtc->crtc_id == 0) {
963 if ((dev_priv->chip_family == CHIP_R200) || radeon_is_r300(dev_priv)) {
964 fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
965 if (radeon_encoder->flags & RADEON_USE_RMX)
966 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_RMX;
968 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC1;
970 fp2_gen_cntl &= ~RADEON_FP2_SRC_SEL_CRTC2;
972 if ((dev_priv->chip_family == CHIP_R200) || radeon_is_r300(dev_priv)) {
973 fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
974 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
976 fp2_gen_cntl |= RADEON_FP2_SRC_SEL_CRTC2;
979 RADEON_WRITE(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
982 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs = {
983 .dpms = radeon_legacy_tmds_ext_dpms,
984 .mode_fixup = radeon_legacy_tmds_ext_mode_fixup,
985 .prepare = radeon_legacy_tmds_ext_prepare,
986 .mode_set = radeon_legacy_tmds_ext_mode_set,
987 .commit = radeon_legacy_tmds_ext_commit,
991 static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs = {
992 .destroy = radeon_enc_destroy,
995 struct drm_encoder *radeon_encoder_legacy_tmds_ext_add(struct drm_device *dev, int bios_index)
997 struct drm_radeon_private *dev_priv = dev->dev_private;
998 struct radeon_encoder *radeon_encoder;
999 struct drm_encoder *encoder;
1003 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
1004 if (!radeon_encoder) {
1008 encoder = &radeon_encoder->base;
1010 encoder->possible_crtcs = 0x3;
1011 encoder->possible_clones = 0;
1012 drm_encoder_init(dev, encoder, &radeon_legacy_tmds_ext_enc_funcs,
1013 DRM_MODE_ENCODER_TMDS);
1015 drm_encoder_helper_add(encoder, &radeon_legacy_tmds_ext_helper_funcs);
1017 if (!dev_priv->is_atom_bios)
1018 radeon_combios_get_ext_tmds_info(radeon_encoder);
1022 static bool radeon_legacy_tv_dac_mode_fixup(struct drm_encoder *encoder,
1023 struct drm_display_mode *mode,
1024 struct drm_display_mode *adjusted_mode)
1029 static void radeon_legacy_tv_dac_dpms(struct drm_encoder *encoder, int mode)
1031 struct drm_device *dev = encoder->dev;
1032 struct drm_radeon_private *dev_priv = dev->dev_private;
1033 struct radeon_crtc *radeon_crtc;
1034 uint32_t fp2_gen_cntl = 0, crtc2_gen_cntl = 0, tv_dac_cntl = 0;
1035 //uint32_t tv_master_cntl = 0;
1036 uint32_t bios_5_scratch, bios_6_scratch;
1041 if (encoder->crtc) {
1042 radeon_crtc = to_radeon_crtc(encoder->crtc);
1043 crtc_id = radeon_crtc->crtc_id;
1046 // FIXME atom/legacy cards like r4xx
1047 bios_5_scratch = RADEON_READ(RADEON_BIOS_5_SCRATCH);
1048 bios_6_scratch = RADEON_READ(RADEON_BIOS_6_SCRATCH);
1050 bios_5_scratch &= ~RADEON_CRT2_CRTC_MASK;
1051 bios_5_scratch |= (crtc_id << RADEON_CRT2_CRTC_SHIFT);
1053 //bios_5_scratch &= ~RADEON_TV1_CRTC_MASK;
1054 //bios_5_scratch |= (crtc_id << RADEON_TV1_CRTC_SHIFT);
1056 if (dev_priv->chip_family == CHIP_R200)
1057 fp2_gen_cntl = RADEON_READ(RADEON_FP2_GEN_CNTL);
1059 crtc2_gen_cntl = RADEON_READ(RADEON_CRTC2_GEN_CNTL);
1061 //tv_master_cntl = RADEON_READ(RADEON_TV_MASTER_CNTL);
1062 tv_dac_cntl = RADEON_READ(RADEON_TV_DAC_CNTL);
1066 case DRM_MODE_DPMS_ON:
1067 if (dev_priv->chip_family == CHIP_R200)
1068 fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
1070 crtc2_gen_cntl |= RADEON_CRTC2_CRT2_ON;
1071 //tv_master_cntl |= RADEON_TV_ON;
1072 if (dev_priv->chip_family == CHIP_R420 ||
1073 dev_priv->chip_family == CHIP_RV410)
1074 tv_dac_cntl &= ~(R420_TV_DAC_RDACPD |
1075 R420_TV_DAC_GDACPD |
1076 R420_TV_DAC_BDACPD |
1077 RADEON_TV_DAC_BGSLEEP);
1079 tv_dac_cntl &= ~(RADEON_TV_DAC_RDACPD |
1080 RADEON_TV_DAC_GDACPD |
1081 RADEON_TV_DAC_BDACPD |
1082 RADEON_TV_DAC_BGSLEEP);
1084 //bios_5_scratch |= RADEON_TV1_ON;
1085 //bios_6_scratch |= RADEON_TV_DPMS_ON;
1086 bios_5_scratch |= RADEON_CRT2_ON;
1087 bios_6_scratch |= RADEON_CRT_DPMS_ON;
1089 case DRM_MODE_DPMS_STANDBY:
1090 case DRM_MODE_DPMS_SUSPEND:
1091 case DRM_MODE_DPMS_OFF:
1092 if (dev_priv->chip_family == CHIP_R200)
1093 fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
1095 crtc2_gen_cntl &= ~RADEON_CRTC2_CRT2_ON;
1096 //tv_master_cntl &= ~RADEON_TV_ON;
1097 if (dev_priv->chip_family == CHIP_R420 ||
1098 dev_priv->chip_family == CHIP_RV410)
1099 tv_dac_cntl |= (R420_TV_DAC_RDACPD |
1100 R420_TV_DAC_GDACPD |
1101 R420_TV_DAC_BDACPD |
1102 RADEON_TV_DAC_BGSLEEP);
1104 tv_dac_cntl |= (RADEON_TV_DAC_RDACPD |
1105 RADEON_TV_DAC_GDACPD |
1106 RADEON_TV_DAC_BDACPD |
1107 RADEON_TV_DAC_BGSLEEP);
1109 //bios_5_scratch &= ~RADEON_TV1_ON;
1110 //bios_6_scratch &= ~RADEON_TV_DPMS_ON;
1111 bios_5_scratch &= ~RADEON_CRT2_ON;
1112 bios_6_scratch &= ~RADEON_CRT_DPMS_ON;
1116 if (dev_priv->chip_family == CHIP_R200)
1117 RADEON_WRITE(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
1119 RADEON_WRITE(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
1120 //RADEON_WRITE(RADEON_TV_MASTER_CNTL, tv_master_cntl);
1121 RADEON_WRITE(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1124 RADEON_WRITE(RADEON_BIOS_5_SCRATCH, bios_5_scratch);
1125 RADEON_WRITE(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
1128 static void radeon_legacy_tv_dac_prepare(struct drm_encoder *encoder)
1130 // fix me: atom/legacy r4xx
1131 radeon_combios_output_lock(encoder, true);
1132 radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
1135 static void radeon_legacy_tv_dac_commit(struct drm_encoder *encoder)
1137 radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_ON);
1138 // fix me: atom/legacy r4xx
1139 radeon_combios_output_lock(encoder, false);
1142 static void radeon_legacy_tv_dac_mode_set(struct drm_encoder *encoder,
1143 struct drm_display_mode *mode,
1144 struct drm_display_mode *adjusted_mode)
1146 struct drm_device *dev = encoder->dev;
1147 struct drm_radeon_private *dev_priv = dev->dev_private;
1148 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1149 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1150 uint32_t tv_dac_cntl, gpiopad_a = 0, dac2_cntl, disp_output_cntl = 0;
1151 uint32_t disp_hw_debug = 0, fp2_gen_cntl = 0;
1155 if (radeon_crtc->crtc_id == 0)
1156 radeon_legacy_rmx_mode_set(encoder, mode, adjusted_mode);
1158 if (dev_priv->chip_family != CHIP_R200) {
1159 tv_dac_cntl = RADEON_READ(RADEON_TV_DAC_CNTL);
1160 if (dev_priv->chip_family == CHIP_R420 ||
1161 dev_priv->chip_family == CHIP_RV410) {
1162 tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
1163 RADEON_TV_DAC_BGADJ_MASK |
1164 R420_TV_DAC_DACADJ_MASK |
1165 R420_TV_DAC_RDACPD |
1166 R420_TV_DAC_GDACPD |
1167 R420_TV_DAC_GDACPD |
1168 R420_TV_DAC_TVENABLE);
1170 tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
1171 RADEON_TV_DAC_BGADJ_MASK |
1172 RADEON_TV_DAC_DACADJ_MASK |
1173 RADEON_TV_DAC_RDACPD |
1174 RADEON_TV_DAC_GDACPD |
1175 RADEON_TV_DAC_GDACPD);
1179 tv_dac_cntl |= (RADEON_TV_DAC_NBLANK |
1180 RADEON_TV_DAC_NHOLD |
1181 RADEON_TV_DAC_STD_PS2 |
1182 radeon_encoder->ps2_tvdac_adj);
1184 RADEON_WRITE(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1187 if (radeon_is_r300(dev_priv)) {
1188 gpiopad_a = RADEON_READ(RADEON_GPIOPAD_A) | 1;
1189 disp_output_cntl = RADEON_READ(RADEON_DISP_OUTPUT_CNTL);
1190 } else if (dev_priv->chip_family == CHIP_R200)
1191 fp2_gen_cntl = RADEON_READ(RADEON_FP2_GEN_CNTL);
1193 disp_hw_debug = RADEON_READ(RADEON_DISP_HW_DEBUG);
1195 dac2_cntl = RADEON_READ(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC2_CLK_SEL;
1197 if (radeon_crtc->crtc_id == 0) {
1198 if (radeon_is_r300(dev_priv)) {
1199 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
1200 disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC;
1201 } else if (dev_priv->chip_family == CHIP_R200) {
1202 fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
1203 RADEON_FP2_DVO_RATE_SEL_SDR);
1205 disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
1207 if (radeon_is_r300(dev_priv)) {
1208 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
1209 disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
1210 } else if (dev_priv->chip_family == CHIP_R200) {
1211 fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
1212 RADEON_FP2_DVO_RATE_SEL_SDR);
1213 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
1215 disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL;
1218 RADEON_WRITE(RADEON_DAC_CNTL2, dac2_cntl);
1220 if (radeon_is_r300(dev_priv)) {
1221 RADEON_WRITE_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
1222 RADEON_WRITE(RADEON_DISP_TV_OUT_CNTL, disp_output_cntl);
1223 } else if (dev_priv->chip_family == CHIP_R200)
1224 RADEON_WRITE(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
1226 RADEON_WRITE(RADEON_DISP_HW_DEBUG, disp_hw_debug);
1230 static enum drm_connector_status radeon_legacy_tv_dac_detect(struct drm_encoder *encoder,
1231 struct drm_connector *connector)
1233 struct drm_device *dev = encoder->dev;
1234 struct drm_radeon_private *dev_priv = dev->dev_private;
1235 uint32_t crtc2_gen_cntl, tv_dac_cntl, dac_cntl2, dac_ext_cntl;
1236 uint32_t disp_hw_debug, disp_output_cntl, gpiopad_a, pixclks_cntl, tmp;
1237 enum drm_connector_status found = connector_status_disconnected;
1242 /* save the regs we need */
1243 pixclks_cntl = RADEON_READ_PLL(dev_priv, RADEON_PIXCLKS_CNTL);
1244 gpiopad_a = radeon_is_r300(dev_priv) ? RADEON_READ(RADEON_GPIOPAD_A) : 0;
1245 disp_output_cntl = radeon_is_r300(dev_priv) ? RADEON_READ(RADEON_DISP_OUTPUT_CNTL) : 0;
1246 disp_hw_debug = radeon_is_r300(dev_priv) ? 0 : RADEON_READ(RADEON_DISP_HW_DEBUG);
1247 crtc2_gen_cntl = RADEON_READ(RADEON_CRTC2_GEN_CNTL);
1248 tv_dac_cntl = RADEON_READ(RADEON_TV_DAC_CNTL);
1249 dac_ext_cntl = RADEON_READ(RADEON_DAC_EXT_CNTL);
1250 dac_cntl2 = RADEON_READ(RADEON_DAC_CNTL2);
1252 tmp = pixclks_cntl & ~(RADEON_PIX2CLK_ALWAYS_ONb
1253 | RADEON_PIX2CLK_DAC_ALWAYS_ONb);
1254 RADEON_WRITE_PLL(dev_priv, RADEON_PIXCLKS_CNTL, tmp);
1256 if (radeon_is_r300(dev_priv))
1257 RADEON_WRITE_P(RADEON_GPIOPAD_A, 1, ~1);
1259 tmp = crtc2_gen_cntl & ~RADEON_CRTC2_PIX_WIDTH_MASK;
1260 tmp |= RADEON_CRTC2_CRT2_ON |
1261 (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT);
1263 RADEON_WRITE(RADEON_CRTC2_GEN_CNTL, tmp);
1265 if (radeon_is_r300(dev_priv)) {
1266 tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK;
1267 tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
1268 RADEON_WRITE(RADEON_DISP_OUTPUT_CNTL, tmp);
1270 tmp = disp_hw_debug & ~RADEON_CRT2_DISP1_SEL;
1271 RADEON_WRITE(RADEON_DISP_HW_DEBUG, tmp);
1274 tmp = RADEON_TV_DAC_NBLANK |
1275 RADEON_TV_DAC_NHOLD |
1276 RADEON_TV_MONITOR_DETECT_EN |
1277 RADEON_TV_DAC_STD_PS2;
1279 RADEON_WRITE(RADEON_TV_DAC_CNTL, tmp);
1281 tmp = RADEON_DAC2_FORCE_BLANK_OFF_EN |
1282 RADEON_DAC2_FORCE_DATA_EN;
1285 tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
1287 tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
1289 if (radeon_is_r300(dev_priv))
1290 tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
1292 tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
1294 RADEON_WRITE(RADEON_DAC_EXT_CNTL, tmp);
1296 tmp = dac_cntl2 | RADEON_DAC2_DAC2_CLK_SEL | RADEON_DAC2_CMP_EN;
1297 RADEON_WRITE(RADEON_DAC_CNTL2, tmp);
1301 if (radeon_is_r300(dev_priv)) {
1302 if (RADEON_READ(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUT_B)
1303 found = connector_status_connected;
1305 if (RADEON_READ(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUTPUT)
1306 found = connector_status_connected;
1309 /* restore regs we used */
1310 RADEON_WRITE(RADEON_DAC_CNTL2, dac_cntl2);
1311 RADEON_WRITE(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
1312 RADEON_WRITE(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1313 RADEON_WRITE(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
1315 if (radeon_is_r300(dev_priv)) {
1316 RADEON_WRITE(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
1317 RADEON_WRITE_P(RADEON_GPIOPAD_A, gpiopad_a, ~1 );
1319 RADEON_WRITE(RADEON_DISP_HW_DEBUG, disp_hw_debug);
1321 RADEON_WRITE_PLL(dev_priv, RADEON_PIXCLKS_CNTL, pixclks_cntl);
1324 return connector_status_disconnected;
1328 static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs = {
1329 .dpms = radeon_legacy_tv_dac_dpms,
1330 .mode_fixup = radeon_legacy_tv_dac_mode_fixup,
1331 .prepare = radeon_legacy_tv_dac_prepare,
1332 .mode_set = radeon_legacy_tv_dac_mode_set,
1333 .commit = radeon_legacy_tv_dac_commit,
1334 .detect = radeon_legacy_tv_dac_detect,
1338 static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs = {
1339 .destroy = radeon_enc_destroy,
1342 struct drm_encoder *radeon_encoder_legacy_tv_dac_add(struct drm_device *dev, int bios_index, int has_tv)
1344 struct radeon_encoder *radeon_encoder;
1345 struct drm_encoder *encoder;
1349 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
1350 if (!radeon_encoder) {
1354 encoder = &radeon_encoder->base;
1356 encoder->possible_crtcs = 0x3;
1357 encoder->possible_clones = 0;
1358 drm_encoder_init(dev, encoder, &radeon_legacy_tv_dac_enc_funcs,
1359 DRM_MODE_ENCODER_DAC);
1361 drm_encoder_helper_add(encoder, &radeon_legacy_tv_dac_helper_funcs);
1363 /* get the tv dac vals from bios tables */
1364 radeon_combios_get_tv_info(radeon_encoder);
1365 radeon_combios_get_tv_dac_info(radeon_encoder);