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"
33 static void radeon_legacy_rmx_mode_set(struct drm_encoder
*encoder
,
34 struct drm_display_mode
*mode
,
35 struct drm_display_mode
*adjusted_mode
)
37 struct drm_device
*dev
= encoder
->dev
;
38 struct radeon_device
*rdev
= dev
->dev_private
;
39 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
40 int xres
= mode
->hdisplay
;
41 int yres
= mode
->vdisplay
;
42 bool hscale
= true, vscale
= true;
47 uint32_t fp_horz_stretch
, fp_vert_stretch
, crtc_more_cntl
, fp_horz_vert_active
;
48 uint32_t fp_h_sync_strt_wid
, fp_v_sync_strt_wid
, fp_crtc_h_total_disp
, fp_crtc_v_total_disp
;
49 struct radeon_native_mode
*native_mode
= &radeon_encoder
->native_mode
;
53 fp_vert_stretch
= RREG32(RADEON_FP_VERT_STRETCH
) &
54 (RADEON_VERT_STRETCH_RESERVED
|
55 RADEON_VERT_AUTO_RATIO_INC
);
56 fp_horz_stretch
= RREG32(RADEON_FP_HORZ_STRETCH
) &
57 (RADEON_HORZ_FP_LOOP_STRETCH
|
58 RADEON_HORZ_AUTO_RATIO_INC
);
61 if ((rdev
->family
== CHIP_RS100
) ||
62 (rdev
->family
== CHIP_RS200
)) {
63 /* This is to workaround the asic bug for RMX, some versions
64 of BIOS dosen't have this register initialized correctly. */
65 crtc_more_cntl
|= RADEON_CRTC_H_CUTOFF_ACTIVE_EN
;
69 fp_crtc_h_total_disp
= ((((mode
->crtc_htotal
/ 8) - 1) & 0x3ff)
70 | ((((mode
->crtc_hdisplay
/ 8) - 1) & 0x1ff) << 16));
72 hsync_wid
= (mode
->crtc_hsync_end
- mode
->crtc_hsync_start
) / 8;
75 hsync_start
= mode
->crtc_hsync_start
- 8;
77 fp_h_sync_strt_wid
= ((hsync_start
& 0x1fff)
78 | ((hsync_wid
& 0x3f) << 16)
79 | ((mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
80 ? RADEON_CRTC_H_SYNC_POL
83 fp_crtc_v_total_disp
= (((mode
->crtc_vtotal
- 1) & 0xffff)
84 | ((mode
->crtc_vdisplay
- 1) << 16));
86 vsync_wid
= mode
->crtc_vsync_end
- mode
->crtc_vsync_start
;
90 fp_v_sync_strt_wid
= (((mode
->crtc_vsync_start
- 1) & 0xfff)
91 | ((vsync_wid
& 0x1f) << 16)
92 | ((mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
93 ? RADEON_CRTC_V_SYNC_POL
96 fp_horz_vert_active
= 0;
98 if (native_mode
->panel_xres
== 0 ||
99 native_mode
->panel_yres
== 0) {
103 if (xres
> native_mode
->panel_xres
)
104 xres
= native_mode
->panel_xres
;
105 if (yres
> native_mode
->panel_yres
)
106 yres
= native_mode
->panel_yres
;
108 if (xres
== native_mode
->panel_xres
)
110 if (yres
== native_mode
->panel_yres
)
114 if (radeon_encoder
->flags
& RADEON_USE_RMX
) {
115 if (radeon_encoder
->rmx_type
!= RMX_CENTER
) {
117 fp_horz_stretch
|= ((xres
/8-1) << 16);
119 inc
= (fp_horz_stretch
& RADEON_HORZ_AUTO_RATIO_INC
) ? 1 : 0;
120 scale
= ((xres
+ inc
) * RADEON_HORZ_STRETCH_RATIO_MAX
)
121 / native_mode
->panel_xres
+ 1;
122 fp_horz_stretch
|= (((scale
) & RADEON_HORZ_STRETCH_RATIO_MASK
) |
123 RADEON_HORZ_STRETCH_BLEND
|
124 RADEON_HORZ_STRETCH_ENABLE
|
125 ((native_mode
->panel_xres
/8-1) << 16));
129 fp_vert_stretch
|= ((yres
-1) << 12);
131 inc
= (fp_vert_stretch
& RADEON_VERT_AUTO_RATIO_INC
) ? 1 : 0;
132 scale
= ((yres
+ inc
) * RADEON_VERT_STRETCH_RATIO_MAX
)
133 / native_mode
->panel_yres
+ 1;
134 fp_vert_stretch
|= (((scale
) & RADEON_VERT_STRETCH_RATIO_MASK
) |
135 RADEON_VERT_STRETCH_ENABLE
|
136 RADEON_VERT_STRETCH_BLEND
|
137 ((native_mode
->panel_yres
-1) << 12));
139 } else if (radeon_encoder
->rmx_type
== RMX_CENTER
) {
142 fp_horz_stretch
|= ((xres
/8-1) << 16);
143 fp_vert_stretch
|= ((yres
-1) << 12);
145 crtc_more_cntl
|= (RADEON_CRTC_AUTO_HORZ_CENTER_EN
|
146 RADEON_CRTC_AUTO_VERT_CENTER_EN
);
148 blank_width
= (mode
->crtc_hblank_end
- mode
->crtc_hblank_start
) / 8;
149 if (blank_width
> 110)
152 fp_crtc_h_total_disp
= (((blank_width
) & 0x3ff)
153 | ((((mode
->crtc_hdisplay
/ 8) - 1) & 0x1ff) << 16));
155 hsync_wid
= (mode
->crtc_hsync_end
- mode
->crtc_hsync_start
) / 8;
159 fp_h_sync_strt_wid
= ((((mode
->crtc_hsync_start
- mode
->crtc_hblank_start
) / 8) & 0x1fff)
160 | ((hsync_wid
& 0x3f) << 16)
161 | ((mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
162 ? RADEON_CRTC_H_SYNC_POL
165 fp_crtc_v_total_disp
= (((mode
->crtc_vblank_end
- mode
->crtc_vblank_start
) & 0xffff)
166 | ((mode
->crtc_vdisplay
- 1) << 16));
168 vsync_wid
= mode
->crtc_vsync_end
- mode
->crtc_vsync_start
;
172 fp_v_sync_strt_wid
= ((((mode
->crtc_vsync_start
- mode
->crtc_vblank_start
) & 0xfff)
173 | ((vsync_wid
& 0x1f) << 16)
174 | ((mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
175 ? RADEON_CRTC_V_SYNC_POL
178 fp_horz_vert_active
= (((native_mode
->panel_yres
) & 0xfff) |
179 (((native_mode
->panel_xres
/ 8) & 0x1ff) << 16));
182 fp_horz_stretch
|= ((xres
/8-1) << 16);
183 fp_vert_stretch
|= ((yres
-1) << 12);
186 WREG32(RADEON_FP_HORZ_STRETCH
, fp_horz_stretch
);
187 WREG32(RADEON_FP_VERT_STRETCH
, fp_vert_stretch
);
188 WREG32(RADEON_CRTC_MORE_CNTL
, crtc_more_cntl
);
189 WREG32(RADEON_FP_HORZ_VERT_ACTIVE
, fp_horz_vert_active
);
190 WREG32(RADEON_FP_H_SYNC_STRT_WID
, fp_h_sync_strt_wid
);
191 WREG32(RADEON_FP_V_SYNC_STRT_WID
, fp_v_sync_strt_wid
);
192 WREG32(RADEON_FP_CRTC_H_TOTAL_DISP
, fp_crtc_h_total_disp
);
193 WREG32(RADEON_FP_CRTC_V_TOTAL_DISP
, fp_crtc_v_total_disp
);
197 static void radeon_legacy_lvds_dpms(struct drm_encoder
*encoder
, int mode
)
199 struct drm_device
*dev
= encoder
->dev
;
200 struct radeon_device
*rdev
= dev
->dev_private
;
201 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
202 uint32_t lvds_gen_cntl
, lvds_pll_cntl
, pixclks_cntl
, disp_pwr_man
;
203 int panel_pwr_delay
= 2000;
206 if (radeon_encoder
->enc_priv
) {
207 if (rdev
->is_atom_bios
) {
208 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
209 panel_pwr_delay
= lvds
->panel_pwr_delay
;
211 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
212 panel_pwr_delay
= lvds
->panel_pwr_delay
;
217 case DRM_MODE_DPMS_ON
:
218 disp_pwr_man
= RREG32(RADEON_DISP_PWR_MAN
);
219 disp_pwr_man
|= RADEON_AUTO_PWRUP_EN
;
220 WREG32(RADEON_DISP_PWR_MAN
, disp_pwr_man
);
221 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
222 lvds_pll_cntl
|= RADEON_LVDS_PLL_EN
;
223 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
226 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
227 lvds_pll_cntl
&= ~RADEON_LVDS_PLL_RESET
;
228 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
230 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
231 lvds_gen_cntl
|= (RADEON_LVDS_ON
| RADEON_LVDS_EN
| RADEON_LVDS_DIGON
| RADEON_LVDS_BLON
);
232 lvds_gen_cntl
&= ~(RADEON_LVDS_DISPLAY_DIS
);
233 udelay(panel_pwr_delay
* 1000);
234 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
236 case DRM_MODE_DPMS_STANDBY
:
237 case DRM_MODE_DPMS_SUSPEND
:
238 case DRM_MODE_DPMS_OFF
:
239 pixclks_cntl
= RREG32_PLL(RADEON_PIXCLKS_CNTL
);
240 WREG32_PLL_P(RADEON_PIXCLKS_CNTL
, 0, ~RADEON_PIXCLK_LVDS_ALWAYS_ONb
);
241 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
242 lvds_gen_cntl
|= RADEON_LVDS_DISPLAY_DIS
;
243 lvds_gen_cntl
&= ~(RADEON_LVDS_ON
| RADEON_LVDS_BLON
| RADEON_LVDS_EN
| RADEON_LVDS_DIGON
);
244 udelay(panel_pwr_delay
* 1000);
245 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
246 WREG32_PLL(RADEON_PIXCLKS_CNTL
, pixclks_cntl
);
250 if (rdev
->is_atom_bios
)
251 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
253 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
256 static void radeon_legacy_lvds_prepare(struct drm_encoder
*encoder
)
258 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
260 if (rdev
->is_atom_bios
)
261 radeon_atom_output_lock(encoder
, true);
263 radeon_combios_output_lock(encoder
, true);
264 radeon_legacy_lvds_dpms(encoder
, DRM_MODE_DPMS_OFF
);
267 static void radeon_legacy_lvds_commit(struct drm_encoder
*encoder
)
269 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
271 radeon_legacy_lvds_dpms(encoder
, DRM_MODE_DPMS_ON
);
272 if (rdev
->is_atom_bios
)
273 radeon_atom_output_lock(encoder
, false);
275 radeon_combios_output_lock(encoder
, false);
278 static void radeon_legacy_lvds_mode_set(struct drm_encoder
*encoder
,
279 struct drm_display_mode
*mode
,
280 struct drm_display_mode
*adjusted_mode
)
282 struct drm_device
*dev
= encoder
->dev
;
283 struct radeon_device
*rdev
= dev
->dev_private
;
284 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
285 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
286 uint32_t lvds_pll_cntl
, lvds_gen_cntl
, lvds_ss_gen_cntl
;
290 if (radeon_crtc
->crtc_id
== 0)
291 radeon_legacy_rmx_mode_set(encoder
, mode
, adjusted_mode
);
293 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
294 lvds_pll_cntl
&= ~RADEON_LVDS_PLL_EN
;
296 lvds_ss_gen_cntl
= RREG32(RADEON_LVDS_SS_GEN_CNTL
);
297 if ((!rdev
->is_atom_bios
)) {
298 struct radeon_encoder_lvds
*lvds
= (struct radeon_encoder_lvds
*)radeon_encoder
->enc_priv
;
300 DRM_DEBUG("bios LVDS_GEN_CNTL: 0x%x\n", lvds
->lvds_gen_cntl
);
301 lvds_gen_cntl
= lvds
->lvds_gen_cntl
;
302 lvds_ss_gen_cntl
&= ~((0xf << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT
) |
303 (0xf << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT
));
304 lvds_ss_gen_cntl
|= ((lvds
->panel_digon_delay
<< RADEON_LVDS_PWRSEQ_DELAY1_SHIFT
) |
305 (lvds
->panel_blon_delay
<< RADEON_LVDS_PWRSEQ_DELAY2_SHIFT
));
307 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
309 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
310 lvds_gen_cntl
|= RADEON_LVDS_DISPLAY_DIS
;
311 lvds_gen_cntl
&= ~(RADEON_LVDS_ON
|
316 if (ASIC_IS_R300(rdev
))
317 lvds_pll_cntl
&= ~(R300_LVDS_SRC_SEL_MASK
);
319 if (radeon_crtc
->crtc_id
== 0) {
320 if (ASIC_IS_R300(rdev
)) {
321 if (radeon_encoder
->flags
& RADEON_USE_RMX
)
322 lvds_pll_cntl
|= R300_LVDS_SRC_SEL_RMX
;
324 lvds_gen_cntl
&= ~RADEON_LVDS_SEL_CRTC2
;
326 if (ASIC_IS_R300(rdev
))
327 lvds_pll_cntl
|= R300_LVDS_SRC_SEL_CRTC2
;
329 lvds_gen_cntl
|= RADEON_LVDS_SEL_CRTC2
;
332 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
333 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
334 WREG32(RADEON_LVDS_SS_GEN_CNTL
, lvds_ss_gen_cntl
);
336 if (rdev
->family
== CHIP_RV410
)
337 WREG32(RADEON_CLOCK_CNTL_INDEX
, 0);
339 if (rdev
->is_atom_bios
)
340 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
342 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
345 static bool radeon_legacy_lvds_mode_fixup(struct drm_encoder
*encoder
,
346 struct drm_display_mode
*mode
,
347 struct drm_display_mode
*adjusted_mode
)
349 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
351 drm_mode_set_crtcinfo(adjusted_mode
, 0);
353 radeon_encoder
->flags
&= ~RADEON_USE_RMX
;
355 if (radeon_encoder
->rmx_type
!= RMX_OFF
)
356 radeon_rmx_mode_fixup(encoder
, mode
, adjusted_mode
);
361 static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs
= {
362 .dpms
= radeon_legacy_lvds_dpms
,
363 .mode_fixup
= radeon_legacy_lvds_mode_fixup
,
364 .prepare
= radeon_legacy_lvds_prepare
,
365 .mode_set
= radeon_legacy_lvds_mode_set
,
366 .commit
= radeon_legacy_lvds_commit
,
370 static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs
= {
371 .destroy
= radeon_enc_destroy
,
374 static bool radeon_legacy_primary_dac_mode_fixup(struct drm_encoder
*encoder
,
375 struct drm_display_mode
*mode
,
376 struct drm_display_mode
*adjusted_mode
)
379 drm_mode_set_crtcinfo(adjusted_mode
, 0);
384 static void radeon_legacy_primary_dac_dpms(struct drm_encoder
*encoder
, int mode
)
386 struct drm_device
*dev
= encoder
->dev
;
387 struct radeon_device
*rdev
= dev
->dev_private
;
388 uint32_t crtc_ext_cntl
= RREG32(RADEON_CRTC_EXT_CNTL
);
389 uint32_t dac_cntl
= RREG32(RADEON_DAC_CNTL
);
390 uint32_t dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
395 case DRM_MODE_DPMS_ON
:
396 crtc_ext_cntl
|= RADEON_CRTC_CRT_ON
;
397 dac_cntl
&= ~RADEON_DAC_PDWN
;
398 dac_macro_cntl
&= ~(RADEON_DAC_PDWN_R
|
402 case DRM_MODE_DPMS_STANDBY
:
403 case DRM_MODE_DPMS_SUSPEND
:
404 case DRM_MODE_DPMS_OFF
:
405 crtc_ext_cntl
&= ~RADEON_CRTC_CRT_ON
;
406 dac_cntl
|= RADEON_DAC_PDWN
;
407 dac_macro_cntl
|= (RADEON_DAC_PDWN_R
|
413 WREG32(RADEON_CRTC_EXT_CNTL
, crtc_ext_cntl
);
414 WREG32(RADEON_DAC_CNTL
, dac_cntl
);
415 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
417 if (rdev
->is_atom_bios
)
418 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
420 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
423 static void radeon_legacy_primary_dac_prepare(struct drm_encoder
*encoder
)
425 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
427 if (rdev
->is_atom_bios
)
428 radeon_atom_output_lock(encoder
, true);
430 radeon_combios_output_lock(encoder
, true);
431 radeon_legacy_primary_dac_dpms(encoder
, DRM_MODE_DPMS_OFF
);
434 static void radeon_legacy_primary_dac_commit(struct drm_encoder
*encoder
)
436 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
438 radeon_legacy_primary_dac_dpms(encoder
, DRM_MODE_DPMS_ON
);
440 if (rdev
->is_atom_bios
)
441 radeon_atom_output_lock(encoder
, false);
443 radeon_combios_output_lock(encoder
, false);
446 static void radeon_legacy_primary_dac_mode_set(struct drm_encoder
*encoder
,
447 struct drm_display_mode
*mode
,
448 struct drm_display_mode
*adjusted_mode
)
450 struct drm_device
*dev
= encoder
->dev
;
451 struct radeon_device
*rdev
= dev
->dev_private
;
452 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
453 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
454 uint32_t disp_output_cntl
, dac_cntl
, dac2_cntl
, dac_macro_cntl
;
458 if (radeon_crtc
->crtc_id
== 0)
459 radeon_legacy_rmx_mode_set(encoder
, mode
, adjusted_mode
);
461 if (radeon_crtc
->crtc_id
== 0) {
462 if (rdev
->family
== CHIP_R200
|| ASIC_IS_R300(rdev
)) {
463 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
) &
464 ~(RADEON_DISP_DAC_SOURCE_MASK
);
465 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
467 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) & ~(RADEON_DAC2_DAC_CLK_SEL
);
468 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
471 if (rdev
->family
== CHIP_R200
|| ASIC_IS_R300(rdev
)) {
472 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
) &
473 ~(RADEON_DISP_DAC_SOURCE_MASK
);
474 disp_output_cntl
|= RADEON_DISP_DAC_SOURCE_CRTC2
;
475 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
477 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) | RADEON_DAC2_DAC_CLK_SEL
;
478 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
482 dac_cntl
= (RADEON_DAC_MASK_ALL
|
483 RADEON_DAC_VGA_ADR_EN
|
487 WREG32_P(RADEON_DAC_CNTL
,
489 RADEON_DAC_RANGE_CNTL
|
490 RADEON_DAC_BLANKING
);
492 if (radeon_encoder
->enc_priv
) {
493 struct radeon_encoder_primary_dac
*p_dac
= (struct radeon_encoder_primary_dac
*)radeon_encoder
->enc_priv
;
494 dac_macro_cntl
= p_dac
->ps2_pdac_adj
;
496 dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
497 dac_macro_cntl
|= RADEON_DAC_PDWN_R
| RADEON_DAC_PDWN_G
| RADEON_DAC_PDWN_B
;
498 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
500 if (rdev
->is_atom_bios
)
501 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
503 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
506 static enum drm_connector_status
radeon_legacy_primary_dac_detect(struct drm_encoder
*encoder
,
507 struct drm_connector
*connector
)
509 struct drm_device
*dev
= encoder
->dev
;
510 struct radeon_device
*rdev
= dev
->dev_private
;
511 uint32_t vclk_ecp_cntl
, crtc_ext_cntl
;
512 uint32_t dac_ext_cntl
, dac_cntl
, dac_macro_cntl
, tmp
;
513 enum drm_connector_status found
= connector_status_disconnected
;
516 /* save the regs we need */
517 vclk_ecp_cntl
= RREG32_PLL(RADEON_VCLK_ECP_CNTL
);
518 crtc_ext_cntl
= RREG32(RADEON_CRTC_EXT_CNTL
);
519 dac_ext_cntl
= RREG32(RADEON_DAC_EXT_CNTL
);
520 dac_cntl
= RREG32(RADEON_DAC_CNTL
);
521 dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
523 tmp
= vclk_ecp_cntl
&
524 ~(RADEON_PIXCLK_ALWAYS_ONb
| RADEON_PIXCLK_DAC_ALWAYS_ONb
);
525 WREG32_PLL(RADEON_VCLK_ECP_CNTL
, tmp
);
527 tmp
= crtc_ext_cntl
| RADEON_CRTC_CRT_ON
;
528 WREG32(RADEON_CRTC_EXT_CNTL
, tmp
);
530 tmp
= RADEON_DAC_FORCE_BLANK_OFF_EN
|
531 RADEON_DAC_FORCE_DATA_EN
;
534 tmp
|= RADEON_DAC_FORCE_DATA_SEL_RGB
;
536 tmp
|= RADEON_DAC_FORCE_DATA_SEL_G
;
538 if (ASIC_IS_R300(rdev
))
539 tmp
|= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT
);
541 tmp
|= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT
);
543 WREG32(RADEON_DAC_EXT_CNTL
, tmp
);
545 tmp
= dac_cntl
& ~(RADEON_DAC_RANGE_CNTL_MASK
| RADEON_DAC_PDWN
);
546 tmp
|= RADEON_DAC_RANGE_CNTL_PS2
| RADEON_DAC_CMP_EN
;
547 WREG32(RADEON_DAC_CNTL
, tmp
);
549 tmp
&= ~(RADEON_DAC_PDWN_R
|
553 WREG32(RADEON_DAC_MACRO_CNTL
, tmp
);
557 if (RREG32(RADEON_DAC_CNTL
) & RADEON_DAC_CMP_OUTPUT
)
558 found
= connector_status_connected
;
560 /* restore the regs we used */
561 WREG32(RADEON_DAC_CNTL
, dac_cntl
);
562 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
563 WREG32(RADEON_DAC_EXT_CNTL
, dac_ext_cntl
);
564 WREG32(RADEON_CRTC_EXT_CNTL
, crtc_ext_cntl
);
565 WREG32_PLL(RADEON_VCLK_ECP_CNTL
, vclk_ecp_cntl
);
570 static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs
= {
571 .dpms
= radeon_legacy_primary_dac_dpms
,
572 .mode_fixup
= radeon_legacy_primary_dac_mode_fixup
,
573 .prepare
= radeon_legacy_primary_dac_prepare
,
574 .mode_set
= radeon_legacy_primary_dac_mode_set
,
575 .commit
= radeon_legacy_primary_dac_commit
,
576 .detect
= radeon_legacy_primary_dac_detect
,
580 static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs
= {
581 .destroy
= radeon_enc_destroy
,
584 static bool radeon_legacy_tmds_int_mode_fixup(struct drm_encoder
*encoder
,
585 struct drm_display_mode
*mode
,
586 struct drm_display_mode
*adjusted_mode
)
589 drm_mode_set_crtcinfo(adjusted_mode
, 0);
594 static void radeon_legacy_tmds_int_dpms(struct drm_encoder
*encoder
, int mode
)
596 struct drm_device
*dev
= encoder
->dev
;
597 struct radeon_device
*rdev
= dev
->dev_private
;
598 uint32_t fp_gen_cntl
= RREG32(RADEON_FP_GEN_CNTL
);
602 case DRM_MODE_DPMS_ON
:
603 fp_gen_cntl
|= (RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
605 case DRM_MODE_DPMS_STANDBY
:
606 case DRM_MODE_DPMS_SUSPEND
:
607 case DRM_MODE_DPMS_OFF
:
608 fp_gen_cntl
&= ~(RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
612 WREG32(RADEON_FP_GEN_CNTL
, fp_gen_cntl
);
614 if (rdev
->is_atom_bios
)
615 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
617 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
620 static void radeon_legacy_tmds_int_prepare(struct drm_encoder
*encoder
)
622 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
624 if (rdev
->is_atom_bios
)
625 radeon_atom_output_lock(encoder
, true);
627 radeon_combios_output_lock(encoder
, true);
628 radeon_legacy_tmds_int_dpms(encoder
, DRM_MODE_DPMS_OFF
);
631 static void radeon_legacy_tmds_int_commit(struct drm_encoder
*encoder
)
633 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
635 radeon_legacy_tmds_int_dpms(encoder
, DRM_MODE_DPMS_ON
);
637 if (rdev
->is_atom_bios
)
638 radeon_atom_output_lock(encoder
, true);
640 radeon_combios_output_lock(encoder
, true);
643 static void radeon_legacy_tmds_int_mode_set(struct drm_encoder
*encoder
,
644 struct drm_display_mode
*mode
,
645 struct drm_display_mode
*adjusted_mode
)
647 struct drm_device
*dev
= encoder
->dev
;
648 struct radeon_device
*rdev
= dev
->dev_private
;
649 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
650 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
651 uint32_t tmp
, tmds_pll_cntl
, tmds_transmitter_cntl
, fp_gen_cntl
;
656 if (radeon_crtc
->crtc_id
== 0)
657 radeon_legacy_rmx_mode_set(encoder
, mode
, adjusted_mode
);
659 tmp
= tmds_pll_cntl
= RREG32(RADEON_TMDS_PLL_CNTL
);
661 if (rdev
->family
== CHIP_RV280
) {
662 /* bit 22 of TMDS_PLL_CNTL is read-back inverted */
664 tmds_pll_cntl
^= (1 << 22);
667 if (radeon_encoder
->enc_priv
) {
668 struct radeon_encoder_int_tmds
*tmds
= (struct radeon_encoder_int_tmds
*)radeon_encoder
->enc_priv
;
670 for (i
= 0; i
< 4; i
++) {
671 if (tmds
->tmds_pll
[i
].freq
== 0)
673 if ((uint32_t)(mode
->clock
/ 10) < tmds
->tmds_pll
[i
].freq
) {
674 tmp
= tmds
->tmds_pll
[i
].value
;
680 if (ASIC_IS_R300(rdev
) || (rdev
->family
== CHIP_RV280
)) {
681 if (tmp
& 0xfff00000)
684 tmds_pll_cntl
&= 0xfff00000;
685 tmds_pll_cntl
|= tmp
;
690 tmds_transmitter_cntl
= RREG32(RADEON_TMDS_TRANSMITTER_CNTL
) &
691 ~(RADEON_TMDS_TRANSMITTER_PLLRST
);
693 if (rdev
->family
== CHIP_R200
||
694 rdev
->family
== CHIP_R100
||
696 tmds_transmitter_cntl
&= ~(RADEON_TMDS_TRANSMITTER_PLLEN
);
697 else /* RV chips got this bit reversed */
698 tmds_transmitter_cntl
|= RADEON_TMDS_TRANSMITTER_PLLEN
;
700 fp_gen_cntl
= (RREG32(RADEON_FP_GEN_CNTL
) |
701 (RADEON_FP_CRTC_DONT_SHADOW_VPAR
|
702 RADEON_FP_CRTC_DONT_SHADOW_HEND
));
704 fp_gen_cntl
&= ~(RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
706 if (1) /* FIXME rgbBits == 8 */
707 fp_gen_cntl
|= RADEON_FP_PANEL_FORMAT
; /* 24 bit format */
709 fp_gen_cntl
&= ~RADEON_FP_PANEL_FORMAT
;/* 18 bit format */
711 if (radeon_crtc
->crtc_id
== 0) {
712 if (ASIC_IS_R300(rdev
) || rdev
->family
== CHIP_R200
) {
713 fp_gen_cntl
&= ~R200_FP_SOURCE_SEL_MASK
;
714 if (radeon_encoder
->flags
& RADEON_USE_RMX
)
715 fp_gen_cntl
|= R200_FP_SOURCE_SEL_RMX
;
717 fp_gen_cntl
|= R200_FP_SOURCE_SEL_CRTC1
;
719 fp_gen_cntl
|= RADEON_FP_SEL_CRTC1
;
721 if (ASIC_IS_R300(rdev
) || rdev
->family
== CHIP_R200
) {
722 fp_gen_cntl
&= ~R200_FP_SOURCE_SEL_MASK
;
723 fp_gen_cntl
|= R200_FP_SOURCE_SEL_CRTC2
;
725 fp_gen_cntl
|= RADEON_FP_SEL_CRTC2
;
728 WREG32(RADEON_TMDS_PLL_CNTL
, tmds_pll_cntl
);
729 WREG32(RADEON_TMDS_TRANSMITTER_CNTL
, tmds_transmitter_cntl
);
730 WREG32(RADEON_FP_GEN_CNTL
, fp_gen_cntl
);
732 if (rdev
->is_atom_bios
)
733 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
735 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
738 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs
= {
739 .dpms
= radeon_legacy_tmds_int_dpms
,
740 .mode_fixup
= radeon_legacy_tmds_int_mode_fixup
,
741 .prepare
= radeon_legacy_tmds_int_prepare
,
742 .mode_set
= radeon_legacy_tmds_int_mode_set
,
743 .commit
= radeon_legacy_tmds_int_commit
,
747 static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs
= {
748 .destroy
= radeon_enc_destroy
,
751 static bool radeon_legacy_tmds_ext_mode_fixup(struct drm_encoder
*encoder
,
752 struct drm_display_mode
*mode
,
753 struct drm_display_mode
*adjusted_mode
)
756 drm_mode_set_crtcinfo(adjusted_mode
, 0);
761 static void radeon_legacy_tmds_ext_dpms(struct drm_encoder
*encoder
, int mode
)
763 struct drm_device
*dev
= encoder
->dev
;
764 struct radeon_device
*rdev
= dev
->dev_private
;
765 uint32_t fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
769 case DRM_MODE_DPMS_ON
:
770 fp2_gen_cntl
&= ~RADEON_FP2_BLANK_EN
;
771 fp2_gen_cntl
|= (RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
773 case DRM_MODE_DPMS_STANDBY
:
774 case DRM_MODE_DPMS_SUSPEND
:
775 case DRM_MODE_DPMS_OFF
:
776 fp2_gen_cntl
|= RADEON_FP2_BLANK_EN
;
777 fp2_gen_cntl
&= ~(RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
781 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
783 if (rdev
->is_atom_bios
)
784 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
786 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
789 static void radeon_legacy_tmds_ext_prepare(struct drm_encoder
*encoder
)
791 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
793 if (rdev
->is_atom_bios
)
794 radeon_atom_output_lock(encoder
, true);
796 radeon_combios_output_lock(encoder
, true);
797 radeon_legacy_tmds_ext_dpms(encoder
, DRM_MODE_DPMS_OFF
);
800 static void radeon_legacy_tmds_ext_commit(struct drm_encoder
*encoder
)
802 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
803 radeon_legacy_tmds_ext_dpms(encoder
, DRM_MODE_DPMS_ON
);
805 if (rdev
->is_atom_bios
)
806 radeon_atom_output_lock(encoder
, false);
808 radeon_combios_output_lock(encoder
, false);
811 static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder
*encoder
,
812 struct drm_display_mode
*mode
,
813 struct drm_display_mode
*adjusted_mode
)
815 struct drm_device
*dev
= encoder
->dev
;
816 struct radeon_device
*rdev
= dev
->dev_private
;
817 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
818 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
819 uint32_t fp2_gen_cntl
;
823 if (radeon_crtc
->crtc_id
== 0)
824 radeon_legacy_rmx_mode_set(encoder
, mode
, adjusted_mode
);
826 if (rdev
->is_atom_bios
) {
827 radeon_encoder
->pixel_clock
= adjusted_mode
->clock
;
828 atombios_external_tmds_setup(encoder
, ATOM_ENABLE
);
829 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
831 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
833 if (1) /* FIXME rgbBits == 8 */
834 fp2_gen_cntl
|= RADEON_FP2_PANEL_FORMAT
; /* 24 bit format, */
836 fp2_gen_cntl
&= ~RADEON_FP2_PANEL_FORMAT
;/* 18 bit format, */
838 fp2_gen_cntl
&= ~(RADEON_FP2_ON
|
840 RADEON_FP2_DVO_RATE_SEL_SDR
);
842 /* XXX: these are oem specific */
843 if (ASIC_IS_R300(rdev
)) {
844 if ((dev
->pdev
->device
== 0x4850) &&
845 (dev
->pdev
->subsystem_vendor
== 0x1028) &&
846 (dev
->pdev
->subsystem_device
== 0x2001)) /* Dell Inspiron 8600 */
847 fp2_gen_cntl
|= R300_FP2_DVO_CLOCK_MODE_SINGLE
;
849 fp2_gen_cntl
|= RADEON_FP2_PAD_FLOP_EN
| R300_FP2_DVO_CLOCK_MODE_SINGLE
;
851 /*if (mode->clock > 165000)
852 fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/
856 if (radeon_crtc
->crtc_id
== 0) {
857 if ((rdev
->family
== CHIP_R200
) || ASIC_IS_R300(rdev
)) {
858 fp2_gen_cntl
&= ~R200_FP2_SOURCE_SEL_MASK
;
859 if (radeon_encoder
->flags
& RADEON_USE_RMX
)
860 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_RMX
;
862 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC1
;
864 fp2_gen_cntl
&= ~RADEON_FP2_SRC_SEL_CRTC2
;
866 if ((rdev
->family
== CHIP_R200
) || ASIC_IS_R300(rdev
)) {
867 fp2_gen_cntl
&= ~R200_FP2_SOURCE_SEL_MASK
;
868 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC2
;
870 fp2_gen_cntl
|= RADEON_FP2_SRC_SEL_CRTC2
;
873 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
875 if (rdev
->is_atom_bios
)
876 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
878 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
881 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs
= {
882 .dpms
= radeon_legacy_tmds_ext_dpms
,
883 .mode_fixup
= radeon_legacy_tmds_ext_mode_fixup
,
884 .prepare
= radeon_legacy_tmds_ext_prepare
,
885 .mode_set
= radeon_legacy_tmds_ext_mode_set
,
886 .commit
= radeon_legacy_tmds_ext_commit
,
890 static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs
= {
891 .destroy
= radeon_enc_destroy
,
894 static bool radeon_legacy_tv_dac_mode_fixup(struct drm_encoder
*encoder
,
895 struct drm_display_mode
*mode
,
896 struct drm_display_mode
*adjusted_mode
)
899 drm_mode_set_crtcinfo(adjusted_mode
, 0);
904 static void radeon_legacy_tv_dac_dpms(struct drm_encoder
*encoder
, int mode
)
906 struct drm_device
*dev
= encoder
->dev
;
907 struct radeon_device
*rdev
= dev
->dev_private
;
908 uint32_t fp2_gen_cntl
= 0, crtc2_gen_cntl
= 0, tv_dac_cntl
= 0;
909 /* uint32_t tv_master_cntl = 0; */
913 if (rdev
->family
== CHIP_R200
)
914 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
916 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
918 /* tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL); */
919 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
923 case DRM_MODE_DPMS_ON
:
924 if (rdev
->family
== CHIP_R200
) {
925 fp2_gen_cntl
|= (RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
927 crtc2_gen_cntl
|= RADEON_CRTC2_CRT2_ON
;
928 /* tv_master_cntl |= RADEON_TV_ON; */
929 if (rdev
->family
== CHIP_R420
||
930 rdev
->family
== CHIP_R423
||
931 rdev
->family
== CHIP_RV410
)
932 tv_dac_cntl
&= ~(R420_TV_DAC_RDACPD
|
935 RADEON_TV_DAC_BGSLEEP
);
937 tv_dac_cntl
&= ~(RADEON_TV_DAC_RDACPD
|
938 RADEON_TV_DAC_GDACPD
|
939 RADEON_TV_DAC_BDACPD
|
940 RADEON_TV_DAC_BGSLEEP
);
943 case DRM_MODE_DPMS_STANDBY
:
944 case DRM_MODE_DPMS_SUSPEND
:
945 case DRM_MODE_DPMS_OFF
:
946 if (rdev
->family
== CHIP_R200
)
947 fp2_gen_cntl
&= ~(RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
949 crtc2_gen_cntl
&= ~RADEON_CRTC2_CRT2_ON
;
950 /* tv_master_cntl &= ~RADEON_TV_ON; */
951 if (rdev
->family
== CHIP_R420
||
952 rdev
->family
== CHIP_R423
||
953 rdev
->family
== CHIP_RV410
)
954 tv_dac_cntl
|= (R420_TV_DAC_RDACPD
|
957 RADEON_TV_DAC_BGSLEEP
);
959 tv_dac_cntl
|= (RADEON_TV_DAC_RDACPD
|
960 RADEON_TV_DAC_GDACPD
|
961 RADEON_TV_DAC_BDACPD
|
962 RADEON_TV_DAC_BGSLEEP
);
967 if (rdev
->family
== CHIP_R200
) {
968 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
970 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
971 /* WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl); */
972 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
975 if (rdev
->is_atom_bios
)
976 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
978 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
981 static void radeon_legacy_tv_dac_prepare(struct drm_encoder
*encoder
)
983 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
985 if (rdev
->is_atom_bios
)
986 radeon_atom_output_lock(encoder
, true);
988 radeon_combios_output_lock(encoder
, true);
989 radeon_legacy_tv_dac_dpms(encoder
, DRM_MODE_DPMS_OFF
);
992 static void radeon_legacy_tv_dac_commit(struct drm_encoder
*encoder
)
994 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
996 radeon_legacy_tv_dac_dpms(encoder
, DRM_MODE_DPMS_ON
);
998 if (rdev
->is_atom_bios
)
999 radeon_atom_output_lock(encoder
, true);
1001 radeon_combios_output_lock(encoder
, true);
1004 static void radeon_legacy_tv_dac_mode_set(struct drm_encoder
*encoder
,
1005 struct drm_display_mode
*mode
,
1006 struct drm_display_mode
*adjusted_mode
)
1008 struct drm_device
*dev
= encoder
->dev
;
1009 struct radeon_device
*rdev
= dev
->dev_private
;
1010 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1011 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1012 uint32_t tv_dac_cntl
, gpiopad_a
= 0, dac2_cntl
, disp_output_cntl
= 0;
1013 uint32_t disp_hw_debug
= 0, fp2_gen_cntl
= 0;
1017 if (radeon_crtc
->crtc_id
== 0)
1018 radeon_legacy_rmx_mode_set(encoder
, mode
, adjusted_mode
);
1020 if (rdev
->family
!= CHIP_R200
) {
1021 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1022 if (rdev
->family
== CHIP_R420
||
1023 rdev
->family
== CHIP_R423
||
1024 rdev
->family
== CHIP_RV410
) {
1025 tv_dac_cntl
&= ~(RADEON_TV_DAC_STD_MASK
|
1026 RADEON_TV_DAC_BGADJ_MASK
|
1027 R420_TV_DAC_DACADJ_MASK
|
1028 R420_TV_DAC_RDACPD
|
1029 R420_TV_DAC_GDACPD
|
1030 R420_TV_DAC_GDACPD
|
1031 R420_TV_DAC_TVENABLE
);
1033 tv_dac_cntl
&= ~(RADEON_TV_DAC_STD_MASK
|
1034 RADEON_TV_DAC_BGADJ_MASK
|
1035 RADEON_TV_DAC_DACADJ_MASK
|
1036 RADEON_TV_DAC_RDACPD
|
1037 RADEON_TV_DAC_GDACPD
|
1038 RADEON_TV_DAC_GDACPD
);
1042 if (radeon_encoder
->enc_priv
) {
1043 struct radeon_encoder_tv_dac
*tv_dac
= radeon_encoder
->enc_priv
;
1044 tv_dac_cntl
|= (RADEON_TV_DAC_NBLANK
|
1045 RADEON_TV_DAC_NHOLD
|
1046 RADEON_TV_DAC_STD_PS2
|
1047 tv_dac
->ps2_tvdac_adj
);
1049 tv_dac_cntl
|= (RADEON_TV_DAC_NBLANK
|
1050 RADEON_TV_DAC_NHOLD
|
1051 RADEON_TV_DAC_STD_PS2
);
1053 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1056 if (ASIC_IS_R300(rdev
)) {
1057 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
) | 1;
1058 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
);
1059 } else if (rdev
->family
== CHIP_R200
)
1060 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
1062 disp_hw_debug
= RREG32(RADEON_DISP_HW_DEBUG
);
1064 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) | RADEON_DAC2_DAC2_CLK_SEL
;
1066 if (radeon_crtc
->crtc_id
== 0) {
1067 if (ASIC_IS_R300(rdev
)) {
1068 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1069 disp_output_cntl
|= RADEON_DISP_TVDAC_SOURCE_CRTC
;
1070 } else if (rdev
->family
== CHIP_R200
) {
1071 fp2_gen_cntl
&= ~(R200_FP2_SOURCE_SEL_MASK
|
1072 RADEON_FP2_DVO_RATE_SEL_SDR
);
1074 disp_hw_debug
|= RADEON_CRT2_DISP1_SEL
;
1076 if (ASIC_IS_R300(rdev
)) {
1077 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1078 disp_output_cntl
|= RADEON_DISP_TVDAC_SOURCE_CRTC2
;
1079 } else if (rdev
->family
== CHIP_R200
) {
1080 fp2_gen_cntl
&= ~(R200_FP2_SOURCE_SEL_MASK
|
1081 RADEON_FP2_DVO_RATE_SEL_SDR
);
1082 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC2
;
1084 disp_hw_debug
&= ~RADEON_CRT2_DISP1_SEL
;
1087 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
1089 if (ASIC_IS_R300(rdev
)) {
1090 WREG32_P(RADEON_GPIOPAD_A
, gpiopad_a
, ~1);
1091 WREG32(RADEON_DISP_TV_OUT_CNTL
, disp_output_cntl
);
1092 } else if (rdev
->family
== CHIP_R200
)
1093 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
1095 WREG32(RADEON_DISP_HW_DEBUG
, disp_hw_debug
);
1097 if (rdev
->is_atom_bios
)
1098 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1100 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1104 static enum drm_connector_status
radeon_legacy_tv_dac_detect(struct drm_encoder
*encoder
,
1105 struct drm_connector
*connector
)
1107 struct drm_device
*dev
= encoder
->dev
;
1108 struct radeon_device
*rdev
= dev
->dev_private
;
1109 uint32_t crtc2_gen_cntl
, tv_dac_cntl
, dac_cntl2
, dac_ext_cntl
;
1110 uint32_t disp_hw_debug
, disp_output_cntl
, gpiopad_a
, pixclks_cntl
, tmp
;
1111 enum drm_connector_status found
= connector_status_disconnected
;
1116 /* save the regs we need */
1117 pixclks_cntl
= RREG32_PLL(RADEON_PIXCLKS_CNTL
);
1118 gpiopad_a
= ASIC_IS_R300(rdev
) ? RREG32(RADEON_GPIOPAD_A
) : 0;
1119 disp_output_cntl
= ASIC_IS_R300(rdev
) ? RREG32(RADEON_DISP_OUTPUT_CNTL
) : 0;
1120 disp_hw_debug
= ASIC_IS_R300(rdev
) ? 0 : RREG32(RADEON_DISP_HW_DEBUG
);
1121 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1122 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1123 dac_ext_cntl
= RREG32(RADEON_DAC_EXT_CNTL
);
1124 dac_cntl2
= RREG32(RADEON_DAC_CNTL2
);
1126 tmp
= pixclks_cntl
& ~(RADEON_PIX2CLK_ALWAYS_ONb
1127 | RADEON_PIX2CLK_DAC_ALWAYS_ONb
);
1128 WREG32_PLL(RADEON_PIXCLKS_CNTL
, tmp
);
1130 if (ASIC_IS_R300(rdev
))
1131 WREG32_P(RADEON_GPIOPAD_A
, 1, ~1);
1133 tmp
= crtc2_gen_cntl
& ~RADEON_CRTC2_PIX_WIDTH_MASK
;
1134 tmp
|= RADEON_CRTC2_CRT2_ON
|
1135 (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT
);
1137 WREG32(RADEON_CRTC2_GEN_CNTL
, tmp
);
1139 if (ASIC_IS_R300(rdev
)) {
1140 tmp
= disp_output_cntl
& ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1141 tmp
|= RADEON_DISP_TVDAC_SOURCE_CRTC2
;
1142 WREG32(RADEON_DISP_OUTPUT_CNTL
, tmp
);
1144 tmp
= disp_hw_debug
& ~RADEON_CRT2_DISP1_SEL
;
1145 WREG32(RADEON_DISP_HW_DEBUG
, tmp
);
1148 tmp
= RADEON_TV_DAC_NBLANK
|
1149 RADEON_TV_DAC_NHOLD
|
1150 RADEON_TV_MONITOR_DETECT_EN
|
1151 RADEON_TV_DAC_STD_PS2
;
1153 WREG32(RADEON_TV_DAC_CNTL
, tmp
);
1155 tmp
= RADEON_DAC2_FORCE_BLANK_OFF_EN
|
1156 RADEON_DAC2_FORCE_DATA_EN
;
1159 tmp
|= RADEON_DAC_FORCE_DATA_SEL_RGB
;
1161 tmp
|= RADEON_DAC_FORCE_DATA_SEL_G
;
1163 if (ASIC_IS_R300(rdev
))
1164 tmp
|= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT
);
1166 tmp
|= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT
);
1168 WREG32(RADEON_DAC_EXT_CNTL
, tmp
);
1170 tmp
= dac_cntl2
| RADEON_DAC2_DAC2_CLK_SEL
| RADEON_DAC2_CMP_EN
;
1171 WREG32(RADEON_DAC_CNTL2
, tmp
);
1175 if (ASIC_IS_R300(rdev
)) {
1176 if (RREG32(RADEON_DAC_CNTL2
) & RADEON_DAC2_CMP_OUT_B
)
1177 found
= connector_status_connected
;
1179 if (RREG32(RADEON_DAC_CNTL2
) & RADEON_DAC2_CMP_OUTPUT
)
1180 found
= connector_status_connected
;
1183 /* restore regs we used */
1184 WREG32(RADEON_DAC_CNTL2
, dac_cntl2
);
1185 WREG32(RADEON_DAC_EXT_CNTL
, dac_ext_cntl
);
1186 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1187 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1189 if (ASIC_IS_R300(rdev
)) {
1190 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1191 WREG32_P(RADEON_GPIOPAD_A
, gpiopad_a
, ~1);
1193 WREG32(RADEON_DISP_HW_DEBUG
, disp_hw_debug
);
1195 WREG32_PLL(RADEON_PIXCLKS_CNTL
, pixclks_cntl
);
1198 return connector_status_disconnected
;
1202 static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs
= {
1203 .dpms
= radeon_legacy_tv_dac_dpms
,
1204 .mode_fixup
= radeon_legacy_tv_dac_mode_fixup
,
1205 .prepare
= radeon_legacy_tv_dac_prepare
,
1206 .mode_set
= radeon_legacy_tv_dac_mode_set
,
1207 .commit
= radeon_legacy_tv_dac_commit
,
1208 .detect
= radeon_legacy_tv_dac_detect
,
1212 static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs
= {
1213 .destroy
= radeon_enc_destroy
,
1217 radeon_add_legacy_encoder(struct drm_device
*dev
, uint32_t encoder_id
, uint32_t supported_device
)
1219 struct radeon_device
*rdev
= dev
->dev_private
;
1220 struct drm_encoder
*encoder
;
1221 struct radeon_encoder
*radeon_encoder
;
1223 /* see if we already added it */
1224 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
1225 radeon_encoder
= to_radeon_encoder(encoder
);
1226 if (radeon_encoder
->encoder_id
== encoder_id
) {
1227 radeon_encoder
->devices
|= supported_device
;
1234 radeon_encoder
= kzalloc(sizeof(struct radeon_encoder
), GFP_KERNEL
);
1235 if (!radeon_encoder
)
1238 encoder
= &radeon_encoder
->base
;
1239 encoder
->possible_crtcs
= 0x3;
1240 encoder
->possible_clones
= 0;
1242 radeon_encoder
->enc_priv
= NULL
;
1244 radeon_encoder
->encoder_id
= encoder_id
;
1245 radeon_encoder
->devices
= supported_device
;
1247 switch (radeon_encoder
->encoder_id
) {
1248 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1249 drm_encoder_init(dev
, encoder
, &radeon_legacy_lvds_enc_funcs
, DRM_MODE_ENCODER_LVDS
);
1250 drm_encoder_helper_add(encoder
, &radeon_legacy_lvds_helper_funcs
);
1251 if (rdev
->is_atom_bios
)
1252 radeon_encoder
->enc_priv
= radeon_atombios_get_lvds_info(radeon_encoder
);
1254 radeon_encoder
->enc_priv
= radeon_combios_get_lvds_info(radeon_encoder
);
1255 radeon_encoder
->rmx_type
= RMX_FULL
;
1257 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1258 drm_encoder_init(dev
, encoder
, &radeon_legacy_tmds_int_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
1259 drm_encoder_helper_add(encoder
, &radeon_legacy_tmds_int_helper_funcs
);
1260 if (rdev
->is_atom_bios
)
1261 radeon_encoder
->enc_priv
= radeon_atombios_get_tmds_info(radeon_encoder
);
1263 radeon_encoder
->enc_priv
= radeon_combios_get_tmds_info(radeon_encoder
);
1265 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1266 drm_encoder_init(dev
, encoder
, &radeon_legacy_primary_dac_enc_funcs
, DRM_MODE_ENCODER_DAC
);
1267 drm_encoder_helper_add(encoder
, &radeon_legacy_primary_dac_helper_funcs
);
1268 if (rdev
->is_atom_bios
)
1269 radeon_encoder
->enc_priv
= radeon_atombios_get_primary_dac_info(radeon_encoder
);
1271 radeon_encoder
->enc_priv
= radeon_combios_get_primary_dac_info(radeon_encoder
);
1273 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1274 drm_encoder_init(dev
, encoder
, &radeon_legacy_tv_dac_enc_funcs
, DRM_MODE_ENCODER_TVDAC
);
1275 drm_encoder_helper_add(encoder
, &radeon_legacy_tv_dac_helper_funcs
);
1276 if (rdev
->is_atom_bios
)
1277 radeon_encoder
->enc_priv
= radeon_atombios_get_tv_dac_info(radeon_encoder
);
1279 radeon_encoder
->enc_priv
= radeon_combios_get_tv_dac_info(radeon_encoder
);
1281 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1282 drm_encoder_init(dev
, encoder
, &radeon_legacy_tmds_ext_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
1283 drm_encoder_helper_add(encoder
, &radeon_legacy_tmds_ext_helper_funcs
);
1284 if (!rdev
->is_atom_bios
)
1285 radeon_combios_get_ext_tmds_info(radeon_encoder
);