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/drm_crtc_helper.h>
28 #include <drm/radeon_drm.h>
30 #include "radeon_asic.h"
32 #include <linux/backlight.h>
33 #ifdef CONFIG_PMAC_BACKLIGHT
34 #include <asm/backlight.h>
37 static void radeon_legacy_encoder_disable(struct drm_encoder
*encoder
)
39 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
40 const struct drm_encoder_helper_funcs
*encoder_funcs
;
42 encoder_funcs
= encoder
->helper_private
;
43 encoder_funcs
->dpms(encoder
, DRM_MODE_DPMS_OFF
);
44 radeon_encoder
->active_device
= 0;
47 static void radeon_legacy_lvds_update(struct drm_encoder
*encoder
, int mode
)
49 struct drm_device
*dev
= encoder
->dev
;
50 struct radeon_device
*rdev
= dev
->dev_private
;
51 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
52 uint32_t lvds_gen_cntl
, lvds_pll_cntl
, pixclks_cntl
, disp_pwr_man
;
53 int panel_pwr_delay
= 2000;
55 uint8_t backlight_level
;
58 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
59 backlight_level
= (lvds_gen_cntl
>> RADEON_LVDS_BL_MOD_LEVEL_SHIFT
) & 0xff;
61 if (radeon_encoder
->enc_priv
) {
62 if (rdev
->is_atom_bios
) {
63 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
64 panel_pwr_delay
= lvds
->panel_pwr_delay
;
66 backlight_level
= lvds
->backlight_level
;
68 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
69 panel_pwr_delay
= lvds
->panel_pwr_delay
;
71 backlight_level
= lvds
->backlight_level
;
75 /* macs (and possibly some x86 oem systems?) wire up LVDS strangely
76 * Taken from radeonfb.
78 if ((rdev
->mode_info
.connector_table
== CT_IBOOK
) ||
79 (rdev
->mode_info
.connector_table
== CT_POWERBOOK_EXTERNAL
) ||
80 (rdev
->mode_info
.connector_table
== CT_POWERBOOK_INTERNAL
) ||
81 (rdev
->mode_info
.connector_table
== CT_POWERBOOK_VGA
))
85 case DRM_MODE_DPMS_ON
:
86 disp_pwr_man
= RREG32(RADEON_DISP_PWR_MAN
);
87 disp_pwr_man
|= RADEON_AUTO_PWRUP_EN
;
88 WREG32(RADEON_DISP_PWR_MAN
, disp_pwr_man
);
89 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
90 lvds_pll_cntl
|= RADEON_LVDS_PLL_EN
;
91 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
94 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
95 lvds_pll_cntl
&= ~RADEON_LVDS_PLL_RESET
;
96 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
98 lvds_gen_cntl
&= ~(RADEON_LVDS_DISPLAY_DIS
|
99 RADEON_LVDS_BL_MOD_LEVEL_MASK
);
100 lvds_gen_cntl
|= (RADEON_LVDS_ON
| RADEON_LVDS_EN
|
101 RADEON_LVDS_DIGON
| RADEON_LVDS_BLON
|
102 (backlight_level
<< RADEON_LVDS_BL_MOD_LEVEL_SHIFT
));
104 lvds_gen_cntl
|= RADEON_LVDS_BL_MOD_EN
;
105 mdelay(panel_pwr_delay
);
106 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
108 case DRM_MODE_DPMS_STANDBY
:
109 case DRM_MODE_DPMS_SUSPEND
:
110 case DRM_MODE_DPMS_OFF
:
111 pixclks_cntl
= RREG32_PLL(RADEON_PIXCLKS_CNTL
);
112 WREG32_PLL_P(RADEON_PIXCLKS_CNTL
, 0, ~RADEON_PIXCLK_LVDS_ALWAYS_ONb
);
113 lvds_gen_cntl
|= RADEON_LVDS_DISPLAY_DIS
;
115 lvds_gen_cntl
&= ~RADEON_LVDS_BL_MOD_EN
;
116 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
117 lvds_gen_cntl
&= ~(RADEON_LVDS_ON
| RADEON_LVDS_EN
);
119 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
120 lvds_gen_cntl
&= ~(RADEON_LVDS_ON
| RADEON_LVDS_BLON
| RADEON_LVDS_EN
| RADEON_LVDS_DIGON
);
122 mdelay(panel_pwr_delay
);
123 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
124 WREG32_PLL(RADEON_PIXCLKS_CNTL
, pixclks_cntl
);
125 mdelay(panel_pwr_delay
);
129 if (rdev
->is_atom_bios
)
130 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
132 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
136 static void radeon_legacy_lvds_dpms(struct drm_encoder
*encoder
, int mode
)
138 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
139 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
142 if (radeon_encoder
->enc_priv
) {
143 if (rdev
->is_atom_bios
) {
144 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
145 lvds
->dpms_mode
= mode
;
147 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
148 lvds
->dpms_mode
= mode
;
152 radeon_legacy_lvds_update(encoder
, mode
);
155 static void radeon_legacy_lvds_prepare(struct drm_encoder
*encoder
)
157 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
159 if (rdev
->is_atom_bios
)
160 radeon_atom_output_lock(encoder
, true);
162 radeon_combios_output_lock(encoder
, true);
163 radeon_legacy_lvds_dpms(encoder
, DRM_MODE_DPMS_OFF
);
166 static void radeon_legacy_lvds_commit(struct drm_encoder
*encoder
)
168 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
170 radeon_legacy_lvds_dpms(encoder
, DRM_MODE_DPMS_ON
);
171 if (rdev
->is_atom_bios
)
172 radeon_atom_output_lock(encoder
, false);
174 radeon_combios_output_lock(encoder
, false);
177 static void radeon_legacy_lvds_mode_set(struct drm_encoder
*encoder
,
178 struct drm_display_mode
*mode
,
179 struct drm_display_mode
*adjusted_mode
)
181 struct drm_device
*dev
= encoder
->dev
;
182 struct radeon_device
*rdev
= dev
->dev_private
;
183 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
184 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
185 uint32_t lvds_pll_cntl
, lvds_gen_cntl
, lvds_ss_gen_cntl
;
189 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
190 lvds_pll_cntl
&= ~RADEON_LVDS_PLL_EN
;
192 lvds_ss_gen_cntl
= RREG32(RADEON_LVDS_SS_GEN_CNTL
);
193 if (rdev
->is_atom_bios
) {
194 /* LVDS_GEN_CNTL parameters are computed in LVDSEncoderControl
195 * need to call that on resume to set up the reg properly.
197 radeon_encoder
->pixel_clock
= adjusted_mode
->clock
;
198 atombios_digital_setup(encoder
, PANEL_ENCODER_ACTION_ENABLE
);
199 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
201 struct radeon_encoder_lvds
*lvds
= (struct radeon_encoder_lvds
*)radeon_encoder
->enc_priv
;
203 DRM_DEBUG_KMS("bios LVDS_GEN_CNTL: 0x%x\n", lvds
->lvds_gen_cntl
);
204 lvds_gen_cntl
= lvds
->lvds_gen_cntl
;
205 lvds_ss_gen_cntl
&= ~((0xf << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT
) |
206 (0xf << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT
));
207 lvds_ss_gen_cntl
|= ((lvds
->panel_digon_delay
<< RADEON_LVDS_PWRSEQ_DELAY1_SHIFT
) |
208 (lvds
->panel_blon_delay
<< RADEON_LVDS_PWRSEQ_DELAY2_SHIFT
));
210 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
212 lvds_gen_cntl
|= RADEON_LVDS_DISPLAY_DIS
;
213 lvds_gen_cntl
&= ~(RADEON_LVDS_ON
|
218 if (ASIC_IS_R300(rdev
))
219 lvds_pll_cntl
&= ~(R300_LVDS_SRC_SEL_MASK
);
221 if (radeon_crtc
->crtc_id
== 0) {
222 if (ASIC_IS_R300(rdev
)) {
223 if (radeon_encoder
->rmx_type
!= RMX_OFF
)
224 lvds_pll_cntl
|= R300_LVDS_SRC_SEL_RMX
;
226 lvds_gen_cntl
&= ~RADEON_LVDS_SEL_CRTC2
;
228 if (ASIC_IS_R300(rdev
))
229 lvds_pll_cntl
|= R300_LVDS_SRC_SEL_CRTC2
;
231 lvds_gen_cntl
|= RADEON_LVDS_SEL_CRTC2
;
234 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
235 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
236 WREG32(RADEON_LVDS_SS_GEN_CNTL
, lvds_ss_gen_cntl
);
238 if (rdev
->family
== CHIP_RV410
)
239 WREG32(RADEON_CLOCK_CNTL_INDEX
, 0);
241 if (rdev
->is_atom_bios
)
242 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
244 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
247 static bool radeon_legacy_mode_fixup(struct drm_encoder
*encoder
,
248 const struct drm_display_mode
*mode
,
249 struct drm_display_mode
*adjusted_mode
)
251 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
253 /* set the active encoder to connector routing */
254 radeon_encoder_set_active_device(encoder
);
255 drm_mode_set_crtcinfo(adjusted_mode
, 0);
257 /* get the native mode for LVDS */
258 if (radeon_encoder
->active_device
& (ATOM_DEVICE_LCD_SUPPORT
))
259 radeon_panel_mode_fixup(encoder
, adjusted_mode
);
264 static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs
= {
265 .dpms
= radeon_legacy_lvds_dpms
,
266 .mode_fixup
= radeon_legacy_mode_fixup
,
267 .prepare
= radeon_legacy_lvds_prepare
,
268 .mode_set
= radeon_legacy_lvds_mode_set
,
269 .commit
= radeon_legacy_lvds_commit
,
270 .disable
= radeon_legacy_encoder_disable
,
274 radeon_legacy_get_backlight_level(struct radeon_encoder
*radeon_encoder
)
276 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
277 struct radeon_device
*rdev
= dev
->dev_private
;
280 backlight_level
= (RREG32(RADEON_LVDS_GEN_CNTL
) >>
281 RADEON_LVDS_BL_MOD_LEVEL_SHIFT
) & 0xff;
283 return backlight_level
;
287 radeon_legacy_set_backlight_level(struct radeon_encoder
*radeon_encoder
, u8 level
)
289 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
290 struct radeon_device
*rdev
= dev
->dev_private
;
291 int dpms_mode
= DRM_MODE_DPMS_ON
;
293 if (radeon_encoder
->enc_priv
) {
294 if (rdev
->is_atom_bios
) {
295 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
296 if (lvds
->backlight_level
> 0)
297 dpms_mode
= lvds
->dpms_mode
;
299 dpms_mode
= DRM_MODE_DPMS_OFF
;
300 lvds
->backlight_level
= level
;
302 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
303 if (lvds
->backlight_level
> 0)
304 dpms_mode
= lvds
->dpms_mode
;
306 dpms_mode
= DRM_MODE_DPMS_OFF
;
307 lvds
->backlight_level
= level
;
311 radeon_legacy_lvds_update(&radeon_encoder
->base
, dpms_mode
);
314 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
316 static uint8_t radeon_legacy_lvds_level(struct backlight_device
*bd
)
318 struct radeon_backlight_privdata
*pdata
= bl_get_data(bd
);
321 /* Convert brightness to hardware level */
322 if (bd
->props
.brightness
< 0)
324 else if (bd
->props
.brightness
> RADEON_MAX_BL_LEVEL
)
325 level
= RADEON_MAX_BL_LEVEL
;
327 level
= bd
->props
.brightness
;
330 level
= RADEON_MAX_BL_LEVEL
- level
;
335 static int radeon_legacy_backlight_update_status(struct backlight_device
*bd
)
337 struct radeon_backlight_privdata
*pdata
= bl_get_data(bd
);
338 struct radeon_encoder
*radeon_encoder
= pdata
->encoder
;
340 radeon_legacy_set_backlight_level(radeon_encoder
,
341 radeon_legacy_lvds_level(bd
));
346 static int radeon_legacy_backlight_get_brightness(struct backlight_device
*bd
)
348 struct radeon_backlight_privdata
*pdata
= bl_get_data(bd
);
349 struct radeon_encoder
*radeon_encoder
= pdata
->encoder
;
350 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
351 struct radeon_device
*rdev
= dev
->dev_private
;
352 uint8_t backlight_level
;
354 backlight_level
= (RREG32(RADEON_LVDS_GEN_CNTL
) >>
355 RADEON_LVDS_BL_MOD_LEVEL_SHIFT
) & 0xff;
357 return pdata
->negative
? RADEON_MAX_BL_LEVEL
- backlight_level
: backlight_level
;
360 static const struct backlight_ops radeon_backlight_ops
= {
361 .get_brightness
= radeon_legacy_backlight_get_brightness
,
362 .update_status
= radeon_legacy_backlight_update_status
,
365 void radeon_legacy_backlight_init(struct radeon_encoder
*radeon_encoder
,
366 struct drm_connector
*drm_connector
)
368 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
369 struct radeon_device
*rdev
= dev
->dev_private
;
370 struct backlight_device
*bd
;
371 struct backlight_properties props
;
372 struct radeon_backlight_privdata
*pdata
;
373 uint8_t backlight_level
;
376 if (!radeon_encoder
->enc_priv
)
379 #ifdef CONFIG_PMAC_BACKLIGHT
380 if (!pmac_has_backlight_type("ati") &&
381 !pmac_has_backlight_type("mnca"))
385 pdata
= kmalloc(sizeof(struct radeon_backlight_privdata
), GFP_KERNEL
);
387 DRM_ERROR("Memory allocation failed\n");
391 memset(&props
, 0, sizeof(props
));
392 props
.max_brightness
= RADEON_MAX_BL_LEVEL
;
393 props
.type
= BACKLIGHT_RAW
;
394 snprintf(bl_name
, sizeof(bl_name
),
395 "radeon_bl%d", dev
->primary
->index
);
396 bd
= backlight_device_register(bl_name
, drm_connector
->kdev
,
397 pdata
, &radeon_backlight_ops
, &props
);
399 DRM_ERROR("Backlight registration failed\n");
403 pdata
->encoder
= radeon_encoder
;
405 backlight_level
= (RREG32(RADEON_LVDS_GEN_CNTL
) >>
406 RADEON_LVDS_BL_MOD_LEVEL_SHIFT
) & 0xff;
408 /* First, try to detect backlight level sense based on the assumption
409 * that firmware set it up at full brightness
411 if (backlight_level
== 0)
412 pdata
->negative
= true;
413 else if (backlight_level
== 0xff)
414 pdata
->negative
= false;
416 /* XXX hack... maybe some day we can figure out in what direction
417 * backlight should work on a given panel?
419 pdata
->negative
= (rdev
->family
!= CHIP_RV200
&&
420 rdev
->family
!= CHIP_RV250
&&
421 rdev
->family
!= CHIP_RV280
&&
422 rdev
->family
!= CHIP_RV350
);
424 #ifdef CONFIG_PMAC_BACKLIGHT
425 pdata
->negative
= (pdata
->negative
||
426 of_machine_is_compatible("PowerBook4,3") ||
427 of_machine_is_compatible("PowerBook6,3") ||
428 of_machine_is_compatible("PowerBook6,5"));
432 if (rdev
->is_atom_bios
) {
433 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
436 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
440 bd
->props
.brightness
= radeon_legacy_backlight_get_brightness(bd
);
441 bd
->props
.power
= FB_BLANK_UNBLANK
;
442 backlight_update_status(bd
);
444 DRM_INFO("radeon legacy LVDS backlight initialized\n");
445 rdev
->mode_info
.bl_encoder
= radeon_encoder
;
454 static void radeon_legacy_backlight_exit(struct radeon_encoder
*radeon_encoder
)
456 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
457 struct radeon_device
*rdev
= dev
->dev_private
;
458 struct backlight_device
*bd
= NULL
;
460 if (!radeon_encoder
->enc_priv
)
463 if (rdev
->is_atom_bios
) {
464 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
468 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
474 struct radeon_backlight_privdata
*pdata
;
476 pdata
= bl_get_data(bd
);
477 backlight_device_unregister(bd
);
480 DRM_INFO("radeon legacy LVDS backlight unloaded\n");
484 #else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */
486 void radeon_legacy_backlight_init(struct radeon_encoder
*encoder
)
490 static void radeon_legacy_backlight_exit(struct radeon_encoder
*encoder
)
497 static void radeon_lvds_enc_destroy(struct drm_encoder
*encoder
)
499 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
501 if (radeon_encoder
->enc_priv
) {
502 radeon_legacy_backlight_exit(radeon_encoder
);
503 kfree(radeon_encoder
->enc_priv
);
505 drm_encoder_cleanup(encoder
);
506 kfree(radeon_encoder
);
509 static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs
= {
510 .destroy
= radeon_lvds_enc_destroy
,
513 static void radeon_legacy_primary_dac_dpms(struct drm_encoder
*encoder
, int mode
)
515 struct drm_device
*dev
= encoder
->dev
;
516 struct radeon_device
*rdev
= dev
->dev_private
;
517 uint32_t crtc_ext_cntl
= RREG32(RADEON_CRTC_EXT_CNTL
);
518 uint32_t dac_cntl
= RREG32(RADEON_DAC_CNTL
);
519 uint32_t dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
524 case DRM_MODE_DPMS_ON
:
525 crtc_ext_cntl
|= RADEON_CRTC_CRT_ON
;
526 dac_cntl
&= ~RADEON_DAC_PDWN
;
527 dac_macro_cntl
&= ~(RADEON_DAC_PDWN_R
|
531 case DRM_MODE_DPMS_STANDBY
:
532 case DRM_MODE_DPMS_SUSPEND
:
533 case DRM_MODE_DPMS_OFF
:
534 crtc_ext_cntl
&= ~RADEON_CRTC_CRT_ON
;
535 dac_cntl
|= RADEON_DAC_PDWN
;
536 dac_macro_cntl
|= (RADEON_DAC_PDWN_R
|
542 /* handled in radeon_crtc_dpms() */
543 if (!(rdev
->flags
& RADEON_SINGLE_CRTC
))
544 WREG32(RADEON_CRTC_EXT_CNTL
, crtc_ext_cntl
);
545 WREG32(RADEON_DAC_CNTL
, dac_cntl
);
546 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
548 if (rdev
->is_atom_bios
)
549 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
551 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
555 static void radeon_legacy_primary_dac_prepare(struct drm_encoder
*encoder
)
557 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
559 if (rdev
->is_atom_bios
)
560 radeon_atom_output_lock(encoder
, true);
562 radeon_combios_output_lock(encoder
, true);
563 radeon_legacy_primary_dac_dpms(encoder
, DRM_MODE_DPMS_OFF
);
566 static void radeon_legacy_primary_dac_commit(struct drm_encoder
*encoder
)
568 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
570 radeon_legacy_primary_dac_dpms(encoder
, DRM_MODE_DPMS_ON
);
572 if (rdev
->is_atom_bios
)
573 radeon_atom_output_lock(encoder
, false);
575 radeon_combios_output_lock(encoder
, false);
578 static void radeon_legacy_primary_dac_mode_set(struct drm_encoder
*encoder
,
579 struct drm_display_mode
*mode
,
580 struct drm_display_mode
*adjusted_mode
)
582 struct drm_device
*dev
= encoder
->dev
;
583 struct radeon_device
*rdev
= dev
->dev_private
;
584 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
585 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
586 uint32_t disp_output_cntl
, dac_cntl
, dac2_cntl
, dac_macro_cntl
;
590 if (radeon_crtc
->crtc_id
== 0) {
591 if (rdev
->family
== CHIP_R200
|| ASIC_IS_R300(rdev
)) {
592 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
) &
593 ~(RADEON_DISP_DAC_SOURCE_MASK
);
594 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
596 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) & ~(RADEON_DAC2_DAC_CLK_SEL
);
597 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
600 if (rdev
->family
== CHIP_R200
|| ASIC_IS_R300(rdev
)) {
601 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
) &
602 ~(RADEON_DISP_DAC_SOURCE_MASK
);
603 disp_output_cntl
|= RADEON_DISP_DAC_SOURCE_CRTC2
;
604 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
606 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) | RADEON_DAC2_DAC_CLK_SEL
;
607 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
611 dac_cntl
= (RADEON_DAC_MASK_ALL
|
612 RADEON_DAC_VGA_ADR_EN
|
616 WREG32_P(RADEON_DAC_CNTL
,
618 RADEON_DAC_RANGE_CNTL
|
619 RADEON_DAC_BLANKING
);
621 if (radeon_encoder
->enc_priv
) {
622 struct radeon_encoder_primary_dac
*p_dac
= (struct radeon_encoder_primary_dac
*)radeon_encoder
->enc_priv
;
623 dac_macro_cntl
= p_dac
->ps2_pdac_adj
;
625 dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
626 dac_macro_cntl
|= RADEON_DAC_PDWN_R
| RADEON_DAC_PDWN_G
| RADEON_DAC_PDWN_B
;
627 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
629 if (rdev
->is_atom_bios
)
630 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
632 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
635 static enum drm_connector_status
radeon_legacy_primary_dac_detect(struct drm_encoder
*encoder
,
636 struct drm_connector
*connector
)
638 struct drm_device
*dev
= encoder
->dev
;
639 struct radeon_device
*rdev
= dev
->dev_private
;
640 uint32_t vclk_ecp_cntl
, crtc_ext_cntl
;
641 uint32_t dac_ext_cntl
, dac_cntl
, dac_macro_cntl
, tmp
;
642 enum drm_connector_status found
= connector_status_disconnected
;
645 /* just don't bother on RN50 those chip are often connected to remoting
646 * console hw and often we get failure to load detect those. So to make
647 * everyone happy report the encoder as always connected.
649 if (ASIC_IS_RN50(rdev
)) {
650 return connector_status_connected
;
653 /* save the regs we need */
654 vclk_ecp_cntl
= RREG32_PLL(RADEON_VCLK_ECP_CNTL
);
655 crtc_ext_cntl
= RREG32(RADEON_CRTC_EXT_CNTL
);
656 dac_ext_cntl
= RREG32(RADEON_DAC_EXT_CNTL
);
657 dac_cntl
= RREG32(RADEON_DAC_CNTL
);
658 dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
660 tmp
= vclk_ecp_cntl
&
661 ~(RADEON_PIXCLK_ALWAYS_ONb
| RADEON_PIXCLK_DAC_ALWAYS_ONb
);
662 WREG32_PLL(RADEON_VCLK_ECP_CNTL
, tmp
);
664 tmp
= crtc_ext_cntl
| RADEON_CRTC_CRT_ON
;
665 WREG32(RADEON_CRTC_EXT_CNTL
, tmp
);
667 tmp
= RADEON_DAC_FORCE_BLANK_OFF_EN
|
668 RADEON_DAC_FORCE_DATA_EN
;
671 tmp
|= RADEON_DAC_FORCE_DATA_SEL_RGB
;
673 tmp
|= RADEON_DAC_FORCE_DATA_SEL_G
;
675 if (ASIC_IS_R300(rdev
))
676 tmp
|= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT
);
677 else if (ASIC_IS_RV100(rdev
))
678 tmp
|= (0x1ac << RADEON_DAC_FORCE_DATA_SHIFT
);
680 tmp
|= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT
);
682 WREG32(RADEON_DAC_EXT_CNTL
, tmp
);
684 tmp
= dac_cntl
& ~(RADEON_DAC_RANGE_CNTL_MASK
| RADEON_DAC_PDWN
);
685 tmp
|= RADEON_DAC_RANGE_CNTL_PS2
| RADEON_DAC_CMP_EN
;
686 WREG32(RADEON_DAC_CNTL
, tmp
);
688 tmp
= dac_macro_cntl
;
689 tmp
&= ~(RADEON_DAC_PDWN_R
|
693 WREG32(RADEON_DAC_MACRO_CNTL
, tmp
);
697 if (RREG32(RADEON_DAC_CNTL
) & RADEON_DAC_CMP_OUTPUT
)
698 found
= connector_status_connected
;
700 /* restore the regs we used */
701 WREG32(RADEON_DAC_CNTL
, dac_cntl
);
702 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
703 WREG32(RADEON_DAC_EXT_CNTL
, dac_ext_cntl
);
704 WREG32(RADEON_CRTC_EXT_CNTL
, crtc_ext_cntl
);
705 WREG32_PLL(RADEON_VCLK_ECP_CNTL
, vclk_ecp_cntl
);
710 static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs
= {
711 .dpms
= radeon_legacy_primary_dac_dpms
,
712 .mode_fixup
= radeon_legacy_mode_fixup
,
713 .prepare
= radeon_legacy_primary_dac_prepare
,
714 .mode_set
= radeon_legacy_primary_dac_mode_set
,
715 .commit
= radeon_legacy_primary_dac_commit
,
716 .detect
= radeon_legacy_primary_dac_detect
,
717 .disable
= radeon_legacy_encoder_disable
,
721 static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs
= {
722 .destroy
= radeon_enc_destroy
,
725 static void radeon_legacy_tmds_int_dpms(struct drm_encoder
*encoder
, int mode
)
727 struct drm_device
*dev
= encoder
->dev
;
728 struct radeon_device
*rdev
= dev
->dev_private
;
729 uint32_t fp_gen_cntl
= RREG32(RADEON_FP_GEN_CNTL
);
733 case DRM_MODE_DPMS_ON
:
734 fp_gen_cntl
|= (RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
736 case DRM_MODE_DPMS_STANDBY
:
737 case DRM_MODE_DPMS_SUSPEND
:
738 case DRM_MODE_DPMS_OFF
:
739 fp_gen_cntl
&= ~(RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
743 WREG32(RADEON_FP_GEN_CNTL
, fp_gen_cntl
);
745 if (rdev
->is_atom_bios
)
746 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
748 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
752 static void radeon_legacy_tmds_int_prepare(struct drm_encoder
*encoder
)
754 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
756 if (rdev
->is_atom_bios
)
757 radeon_atom_output_lock(encoder
, true);
759 radeon_combios_output_lock(encoder
, true);
760 radeon_legacy_tmds_int_dpms(encoder
, DRM_MODE_DPMS_OFF
);
763 static void radeon_legacy_tmds_int_commit(struct drm_encoder
*encoder
)
765 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
767 radeon_legacy_tmds_int_dpms(encoder
, DRM_MODE_DPMS_ON
);
769 if (rdev
->is_atom_bios
)
770 radeon_atom_output_lock(encoder
, true);
772 radeon_combios_output_lock(encoder
, true);
775 static void radeon_legacy_tmds_int_mode_set(struct drm_encoder
*encoder
,
776 struct drm_display_mode
*mode
,
777 struct drm_display_mode
*adjusted_mode
)
779 struct drm_device
*dev
= encoder
->dev
;
780 struct radeon_device
*rdev
= dev
->dev_private
;
781 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
782 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
783 uint32_t tmp
, tmds_pll_cntl
, tmds_transmitter_cntl
, fp_gen_cntl
;
788 tmp
= tmds_pll_cntl
= RREG32(RADEON_TMDS_PLL_CNTL
);
790 if (rdev
->family
== CHIP_RV280
) {
791 /* bit 22 of TMDS_PLL_CNTL is read-back inverted */
793 tmds_pll_cntl
^= (1 << 22);
796 if (radeon_encoder
->enc_priv
) {
797 struct radeon_encoder_int_tmds
*tmds
= (struct radeon_encoder_int_tmds
*)radeon_encoder
->enc_priv
;
799 for (i
= 0; i
< 4; i
++) {
800 if (tmds
->tmds_pll
[i
].freq
== 0)
802 if ((uint32_t)(mode
->clock
/ 10) < tmds
->tmds_pll
[i
].freq
) {
803 tmp
= tmds
->tmds_pll
[i
].value
;
809 if (ASIC_IS_R300(rdev
) || (rdev
->family
== CHIP_RV280
)) {
810 if (tmp
& 0xfff00000)
813 tmds_pll_cntl
&= 0xfff00000;
814 tmds_pll_cntl
|= tmp
;
819 tmds_transmitter_cntl
= RREG32(RADEON_TMDS_TRANSMITTER_CNTL
) &
820 ~(RADEON_TMDS_TRANSMITTER_PLLRST
);
822 if (rdev
->family
== CHIP_R200
||
823 rdev
->family
== CHIP_R100
||
825 tmds_transmitter_cntl
&= ~(RADEON_TMDS_TRANSMITTER_PLLEN
);
826 else /* RV chips got this bit reversed */
827 tmds_transmitter_cntl
|= RADEON_TMDS_TRANSMITTER_PLLEN
;
829 fp_gen_cntl
= (RREG32(RADEON_FP_GEN_CNTL
) |
830 (RADEON_FP_CRTC_DONT_SHADOW_VPAR
|
831 RADEON_FP_CRTC_DONT_SHADOW_HEND
));
833 fp_gen_cntl
&= ~(RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
835 fp_gen_cntl
&= ~(RADEON_FP_RMX_HVSYNC_CONTROL_EN
|
836 RADEON_FP_DFP_SYNC_SEL
|
837 RADEON_FP_CRT_SYNC_SEL
|
838 RADEON_FP_CRTC_LOCK_8DOT
|
839 RADEON_FP_USE_SHADOW_EN
|
840 RADEON_FP_CRTC_USE_SHADOW_VEND
|
841 RADEON_FP_CRT_SYNC_ALT
);
843 if (1) /* FIXME rgbBits == 8 */
844 fp_gen_cntl
|= RADEON_FP_PANEL_FORMAT
; /* 24 bit format */
846 fp_gen_cntl
&= ~RADEON_FP_PANEL_FORMAT
;/* 18 bit format */
848 if (radeon_crtc
->crtc_id
== 0) {
849 if (ASIC_IS_R300(rdev
) || rdev
->family
== CHIP_R200
) {
850 fp_gen_cntl
&= ~R200_FP_SOURCE_SEL_MASK
;
851 if (radeon_encoder
->rmx_type
!= RMX_OFF
)
852 fp_gen_cntl
|= R200_FP_SOURCE_SEL_RMX
;
854 fp_gen_cntl
|= R200_FP_SOURCE_SEL_CRTC1
;
856 fp_gen_cntl
&= ~RADEON_FP_SEL_CRTC2
;
858 if (ASIC_IS_R300(rdev
) || rdev
->family
== CHIP_R200
) {
859 fp_gen_cntl
&= ~R200_FP_SOURCE_SEL_MASK
;
860 fp_gen_cntl
|= R200_FP_SOURCE_SEL_CRTC2
;
862 fp_gen_cntl
|= RADEON_FP_SEL_CRTC2
;
865 WREG32(RADEON_TMDS_PLL_CNTL
, tmds_pll_cntl
);
866 WREG32(RADEON_TMDS_TRANSMITTER_CNTL
, tmds_transmitter_cntl
);
867 WREG32(RADEON_FP_GEN_CNTL
, fp_gen_cntl
);
869 if (rdev
->is_atom_bios
)
870 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
872 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
875 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs
= {
876 .dpms
= radeon_legacy_tmds_int_dpms
,
877 .mode_fixup
= radeon_legacy_mode_fixup
,
878 .prepare
= radeon_legacy_tmds_int_prepare
,
879 .mode_set
= radeon_legacy_tmds_int_mode_set
,
880 .commit
= radeon_legacy_tmds_int_commit
,
881 .disable
= radeon_legacy_encoder_disable
,
885 static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs
= {
886 .destroy
= radeon_enc_destroy
,
889 static void radeon_legacy_tmds_ext_dpms(struct drm_encoder
*encoder
, int mode
)
891 struct drm_device
*dev
= encoder
->dev
;
892 struct radeon_device
*rdev
= dev
->dev_private
;
893 uint32_t fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
897 case DRM_MODE_DPMS_ON
:
898 fp2_gen_cntl
&= ~RADEON_FP2_BLANK_EN
;
899 fp2_gen_cntl
|= (RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
901 case DRM_MODE_DPMS_STANDBY
:
902 case DRM_MODE_DPMS_SUSPEND
:
903 case DRM_MODE_DPMS_OFF
:
904 fp2_gen_cntl
|= RADEON_FP2_BLANK_EN
;
905 fp2_gen_cntl
&= ~(RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
909 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
911 if (rdev
->is_atom_bios
)
912 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
914 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
918 static void radeon_legacy_tmds_ext_prepare(struct drm_encoder
*encoder
)
920 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
922 if (rdev
->is_atom_bios
)
923 radeon_atom_output_lock(encoder
, true);
925 radeon_combios_output_lock(encoder
, true);
926 radeon_legacy_tmds_ext_dpms(encoder
, DRM_MODE_DPMS_OFF
);
929 static void radeon_legacy_tmds_ext_commit(struct drm_encoder
*encoder
)
931 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
932 radeon_legacy_tmds_ext_dpms(encoder
, DRM_MODE_DPMS_ON
);
934 if (rdev
->is_atom_bios
)
935 radeon_atom_output_lock(encoder
, false);
937 radeon_combios_output_lock(encoder
, false);
940 static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder
*encoder
,
941 struct drm_display_mode
*mode
,
942 struct drm_display_mode
*adjusted_mode
)
944 struct drm_device
*dev
= encoder
->dev
;
945 struct radeon_device
*rdev
= dev
->dev_private
;
946 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
947 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
948 uint32_t fp2_gen_cntl
;
952 if (rdev
->is_atom_bios
) {
953 radeon_encoder
->pixel_clock
= adjusted_mode
->clock
;
954 atombios_dvo_setup(encoder
, ATOM_ENABLE
);
955 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
957 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
959 if (1) /* FIXME rgbBits == 8 */
960 fp2_gen_cntl
|= RADEON_FP2_PANEL_FORMAT
; /* 24 bit format, */
962 fp2_gen_cntl
&= ~RADEON_FP2_PANEL_FORMAT
;/* 18 bit format, */
964 fp2_gen_cntl
&= ~(RADEON_FP2_ON
|
966 RADEON_FP2_DVO_RATE_SEL_SDR
);
968 /* XXX: these are oem specific */
969 if (ASIC_IS_R300(rdev
)) {
970 if ((dev
->pdev
->device
== 0x4850) &&
971 (dev
->pdev
->subsystem_vendor
== 0x1028) &&
972 (dev
->pdev
->subsystem_device
== 0x2001)) /* Dell Inspiron 8600 */
973 fp2_gen_cntl
|= R300_FP2_DVO_CLOCK_MODE_SINGLE
;
975 fp2_gen_cntl
|= RADEON_FP2_PAD_FLOP_EN
| R300_FP2_DVO_CLOCK_MODE_SINGLE
;
977 /*if (mode->clock > 165000)
978 fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/
980 if (!radeon_combios_external_tmds_setup(encoder
))
981 radeon_external_tmds_setup(encoder
);
984 if (radeon_crtc
->crtc_id
== 0) {
985 if ((rdev
->family
== CHIP_R200
) || ASIC_IS_R300(rdev
)) {
986 fp2_gen_cntl
&= ~R200_FP2_SOURCE_SEL_MASK
;
987 if (radeon_encoder
->rmx_type
!= RMX_OFF
)
988 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_RMX
;
990 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC1
;
992 fp2_gen_cntl
&= ~RADEON_FP2_SRC_SEL_CRTC2
;
994 if ((rdev
->family
== CHIP_R200
) || ASIC_IS_R300(rdev
)) {
995 fp2_gen_cntl
&= ~R200_FP2_SOURCE_SEL_MASK
;
996 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC2
;
998 fp2_gen_cntl
|= RADEON_FP2_SRC_SEL_CRTC2
;
1001 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
1003 if (rdev
->is_atom_bios
)
1004 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1006 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1009 static void radeon_ext_tmds_enc_destroy(struct drm_encoder
*encoder
)
1011 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1012 /* don't destroy the i2c bus record here, this will be done in radeon_i2c_fini */
1013 kfree(radeon_encoder
->enc_priv
);
1014 drm_encoder_cleanup(encoder
);
1015 kfree(radeon_encoder
);
1018 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs
= {
1019 .dpms
= radeon_legacy_tmds_ext_dpms
,
1020 .mode_fixup
= radeon_legacy_mode_fixup
,
1021 .prepare
= radeon_legacy_tmds_ext_prepare
,
1022 .mode_set
= radeon_legacy_tmds_ext_mode_set
,
1023 .commit
= radeon_legacy_tmds_ext_commit
,
1024 .disable
= radeon_legacy_encoder_disable
,
1028 static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs
= {
1029 .destroy
= radeon_ext_tmds_enc_destroy
,
1032 static void radeon_legacy_tv_dac_dpms(struct drm_encoder
*encoder
, int mode
)
1034 struct drm_device
*dev
= encoder
->dev
;
1035 struct radeon_device
*rdev
= dev
->dev_private
;
1036 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1037 uint32_t fp2_gen_cntl
= 0, crtc2_gen_cntl
= 0, tv_dac_cntl
= 0;
1038 uint32_t tv_master_cntl
= 0;
1040 DRM_DEBUG_KMS("\n");
1042 is_tv
= radeon_encoder
->active_device
& ATOM_DEVICE_TV_SUPPORT
? true : false;
1044 if (rdev
->family
== CHIP_R200
)
1045 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
1048 tv_master_cntl
= RREG32(RADEON_TV_MASTER_CNTL
);
1050 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1051 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1055 case DRM_MODE_DPMS_ON
:
1056 if (rdev
->family
== CHIP_R200
) {
1057 fp2_gen_cntl
|= (RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
1060 tv_master_cntl
|= RADEON_TV_ON
;
1062 crtc2_gen_cntl
|= RADEON_CRTC2_CRT2_ON
;
1064 if (rdev
->family
== CHIP_R420
||
1065 rdev
->family
== CHIP_R423
||
1066 rdev
->family
== CHIP_RV410
)
1067 tv_dac_cntl
&= ~(R420_TV_DAC_RDACPD
|
1068 R420_TV_DAC_GDACPD
|
1069 R420_TV_DAC_BDACPD
|
1070 RADEON_TV_DAC_BGSLEEP
);
1072 tv_dac_cntl
&= ~(RADEON_TV_DAC_RDACPD
|
1073 RADEON_TV_DAC_GDACPD
|
1074 RADEON_TV_DAC_BDACPD
|
1075 RADEON_TV_DAC_BGSLEEP
);
1078 case DRM_MODE_DPMS_STANDBY
:
1079 case DRM_MODE_DPMS_SUSPEND
:
1080 case DRM_MODE_DPMS_OFF
:
1081 if (rdev
->family
== CHIP_R200
)
1082 fp2_gen_cntl
&= ~(RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
1085 tv_master_cntl
&= ~RADEON_TV_ON
;
1087 crtc2_gen_cntl
&= ~RADEON_CRTC2_CRT2_ON
;
1089 if (rdev
->family
== CHIP_R420
||
1090 rdev
->family
== CHIP_R423
||
1091 rdev
->family
== CHIP_RV410
)
1092 tv_dac_cntl
|= (R420_TV_DAC_RDACPD
|
1093 R420_TV_DAC_GDACPD
|
1094 R420_TV_DAC_BDACPD
|
1095 RADEON_TV_DAC_BGSLEEP
);
1097 tv_dac_cntl
|= (RADEON_TV_DAC_RDACPD
|
1098 RADEON_TV_DAC_GDACPD
|
1099 RADEON_TV_DAC_BDACPD
|
1100 RADEON_TV_DAC_BGSLEEP
);
1105 if (rdev
->family
== CHIP_R200
) {
1106 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
1109 WREG32(RADEON_TV_MASTER_CNTL
, tv_master_cntl
);
1110 /* handled in radeon_crtc_dpms() */
1111 else if (!(rdev
->flags
& RADEON_SINGLE_CRTC
))
1112 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1113 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1116 if (rdev
->is_atom_bios
)
1117 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
1119 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
1123 static void radeon_legacy_tv_dac_prepare(struct drm_encoder
*encoder
)
1125 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
1127 if (rdev
->is_atom_bios
)
1128 radeon_atom_output_lock(encoder
, true);
1130 radeon_combios_output_lock(encoder
, true);
1131 radeon_legacy_tv_dac_dpms(encoder
, DRM_MODE_DPMS_OFF
);
1134 static void radeon_legacy_tv_dac_commit(struct drm_encoder
*encoder
)
1136 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
1138 radeon_legacy_tv_dac_dpms(encoder
, DRM_MODE_DPMS_ON
);
1140 if (rdev
->is_atom_bios
)
1141 radeon_atom_output_lock(encoder
, true);
1143 radeon_combios_output_lock(encoder
, true);
1146 static void radeon_legacy_tv_dac_mode_set(struct drm_encoder
*encoder
,
1147 struct drm_display_mode
*mode
,
1148 struct drm_display_mode
*adjusted_mode
)
1150 struct drm_device
*dev
= encoder
->dev
;
1151 struct radeon_device
*rdev
= dev
->dev_private
;
1152 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1153 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1154 struct radeon_encoder_tv_dac
*tv_dac
= radeon_encoder
->enc_priv
;
1155 uint32_t tv_dac_cntl
, gpiopad_a
= 0, dac2_cntl
, disp_output_cntl
= 0;
1156 uint32_t disp_hw_debug
= 0, fp2_gen_cntl
= 0, disp_tv_out_cntl
= 0;
1159 DRM_DEBUG_KMS("\n");
1161 is_tv
= radeon_encoder
->active_device
& ATOM_DEVICE_TV_SUPPORT
? true : false;
1163 if (rdev
->family
!= CHIP_R200
) {
1164 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1165 if (rdev
->family
== CHIP_R420
||
1166 rdev
->family
== CHIP_R423
||
1167 rdev
->family
== CHIP_RV410
) {
1168 tv_dac_cntl
&= ~(RADEON_TV_DAC_STD_MASK
|
1169 RADEON_TV_DAC_BGADJ_MASK
|
1170 R420_TV_DAC_DACADJ_MASK
|
1171 R420_TV_DAC_RDACPD
|
1172 R420_TV_DAC_GDACPD
|
1173 R420_TV_DAC_BDACPD
|
1174 R420_TV_DAC_TVENABLE
);
1176 tv_dac_cntl
&= ~(RADEON_TV_DAC_STD_MASK
|
1177 RADEON_TV_DAC_BGADJ_MASK
|
1178 RADEON_TV_DAC_DACADJ_MASK
|
1179 RADEON_TV_DAC_RDACPD
|
1180 RADEON_TV_DAC_GDACPD
|
1181 RADEON_TV_DAC_BDACPD
);
1184 tv_dac_cntl
|= RADEON_TV_DAC_NBLANK
| RADEON_TV_DAC_NHOLD
;
1187 if (tv_dac
->tv_std
== TV_STD_NTSC
||
1188 tv_dac
->tv_std
== TV_STD_NTSC_J
||
1189 tv_dac
->tv_std
== TV_STD_PAL_M
||
1190 tv_dac
->tv_std
== TV_STD_PAL_60
)
1191 tv_dac_cntl
|= tv_dac
->ntsc_tvdac_adj
;
1193 tv_dac_cntl
|= tv_dac
->pal_tvdac_adj
;
1195 if (tv_dac
->tv_std
== TV_STD_NTSC
||
1196 tv_dac
->tv_std
== TV_STD_NTSC_J
)
1197 tv_dac_cntl
|= RADEON_TV_DAC_STD_NTSC
;
1199 tv_dac_cntl
|= RADEON_TV_DAC_STD_PAL
;
1201 tv_dac_cntl
|= (RADEON_TV_DAC_STD_PS2
|
1202 tv_dac
->ps2_tvdac_adj
);
1204 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1207 if (ASIC_IS_R300(rdev
)) {
1208 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
) | 1;
1209 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
);
1210 } else if (rdev
->family
!= CHIP_R200
)
1211 disp_hw_debug
= RREG32(RADEON_DISP_HW_DEBUG
);
1212 else if (rdev
->family
== CHIP_R200
)
1213 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
1215 if (rdev
->family
>= CHIP_R200
)
1216 disp_tv_out_cntl
= RREG32(RADEON_DISP_TV_OUT_CNTL
);
1221 dac_cntl
= RREG32(RADEON_DAC_CNTL
);
1222 dac_cntl
&= ~RADEON_DAC_TVO_EN
;
1223 WREG32(RADEON_DAC_CNTL
, dac_cntl
);
1225 if (ASIC_IS_R300(rdev
))
1226 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
) & ~1;
1228 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) & ~RADEON_DAC2_DAC2_CLK_SEL
;
1229 if (radeon_crtc
->crtc_id
== 0) {
1230 if (ASIC_IS_R300(rdev
)) {
1231 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1232 disp_output_cntl
|= (RADEON_DISP_TVDAC_SOURCE_CRTC
|
1233 RADEON_DISP_TV_SOURCE_CRTC
);
1235 if (rdev
->family
>= CHIP_R200
) {
1236 disp_tv_out_cntl
&= ~RADEON_DISP_TV_PATH_SRC_CRTC2
;
1238 disp_hw_debug
|= RADEON_CRT2_DISP1_SEL
;
1241 if (ASIC_IS_R300(rdev
)) {
1242 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1243 disp_output_cntl
|= RADEON_DISP_TV_SOURCE_CRTC
;
1245 if (rdev
->family
>= CHIP_R200
) {
1246 disp_tv_out_cntl
|= RADEON_DISP_TV_PATH_SRC_CRTC2
;
1248 disp_hw_debug
&= ~RADEON_CRT2_DISP1_SEL
;
1251 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
1254 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) | RADEON_DAC2_DAC2_CLK_SEL
;
1256 if (radeon_crtc
->crtc_id
== 0) {
1257 if (ASIC_IS_R300(rdev
)) {
1258 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1259 disp_output_cntl
|= RADEON_DISP_TVDAC_SOURCE_CRTC
;
1260 } else if (rdev
->family
== CHIP_R200
) {
1261 fp2_gen_cntl
&= ~(R200_FP2_SOURCE_SEL_MASK
|
1262 RADEON_FP2_DVO_RATE_SEL_SDR
);
1264 disp_hw_debug
|= RADEON_CRT2_DISP1_SEL
;
1266 if (ASIC_IS_R300(rdev
)) {
1267 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1268 disp_output_cntl
|= RADEON_DISP_TVDAC_SOURCE_CRTC2
;
1269 } else if (rdev
->family
== CHIP_R200
) {
1270 fp2_gen_cntl
&= ~(R200_FP2_SOURCE_SEL_MASK
|
1271 RADEON_FP2_DVO_RATE_SEL_SDR
);
1272 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC2
;
1274 disp_hw_debug
&= ~RADEON_CRT2_DISP1_SEL
;
1276 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
1279 if (ASIC_IS_R300(rdev
)) {
1280 WREG32_P(RADEON_GPIOPAD_A
, gpiopad_a
, ~1);
1281 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1282 } else if (rdev
->family
!= CHIP_R200
)
1283 WREG32(RADEON_DISP_HW_DEBUG
, disp_hw_debug
);
1284 else if (rdev
->family
== CHIP_R200
)
1285 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
1287 if (rdev
->family
>= CHIP_R200
)
1288 WREG32(RADEON_DISP_TV_OUT_CNTL
, disp_tv_out_cntl
);
1291 radeon_legacy_tv_mode_set(encoder
, mode
, adjusted_mode
);
1293 if (rdev
->is_atom_bios
)
1294 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1296 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1300 static bool r300_legacy_tv_detect(struct drm_encoder
*encoder
,
1301 struct drm_connector
*connector
)
1303 struct drm_device
*dev
= encoder
->dev
;
1304 struct radeon_device
*rdev
= dev
->dev_private
;
1305 uint32_t crtc2_gen_cntl
, tv_dac_cntl
, dac_cntl2
, dac_ext_cntl
;
1306 uint32_t disp_output_cntl
, gpiopad_a
, tmp
;
1309 /* save regs needed */
1310 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
);
1311 dac_cntl2
= RREG32(RADEON_DAC_CNTL2
);
1312 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1313 dac_ext_cntl
= RREG32(RADEON_DAC_EXT_CNTL
);
1314 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1315 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
);
1317 WREG32_P(RADEON_GPIOPAD_A
, 0, ~1);
1319 WREG32(RADEON_DAC_CNTL2
, RADEON_DAC2_DAC2_CLK_SEL
);
1321 WREG32(RADEON_CRTC2_GEN_CNTL
,
1322 RADEON_CRTC2_CRT2_ON
| RADEON_CRTC2_VSYNC_TRISTAT
);
1324 tmp
= disp_output_cntl
& ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1325 tmp
|= RADEON_DISP_TVDAC_SOURCE_CRTC2
;
1326 WREG32(RADEON_DISP_OUTPUT_CNTL
, tmp
);
1328 WREG32(RADEON_DAC_EXT_CNTL
,
1329 RADEON_DAC2_FORCE_BLANK_OFF_EN
|
1330 RADEON_DAC2_FORCE_DATA_EN
|
1331 RADEON_DAC_FORCE_DATA_SEL_RGB
|
1332 (0xec << RADEON_DAC_FORCE_DATA_SHIFT
));
1334 WREG32(RADEON_TV_DAC_CNTL
,
1335 RADEON_TV_DAC_STD_NTSC
|
1336 (8 << RADEON_TV_DAC_BGADJ_SHIFT
) |
1337 (6 << RADEON_TV_DAC_DACADJ_SHIFT
));
1339 RREG32(RADEON_TV_DAC_CNTL
);
1342 WREG32(RADEON_TV_DAC_CNTL
,
1343 RADEON_TV_DAC_NBLANK
|
1344 RADEON_TV_DAC_NHOLD
|
1345 RADEON_TV_MONITOR_DETECT_EN
|
1346 RADEON_TV_DAC_STD_NTSC
|
1347 (8 << RADEON_TV_DAC_BGADJ_SHIFT
) |
1348 (6 << RADEON_TV_DAC_DACADJ_SHIFT
));
1350 RREG32(RADEON_TV_DAC_CNTL
);
1353 tmp
= RREG32(RADEON_TV_DAC_CNTL
);
1354 if ((tmp
& RADEON_TV_DAC_GDACDET
) != 0) {
1356 DRM_DEBUG_KMS("S-video TV connection detected\n");
1357 } else if ((tmp
& RADEON_TV_DAC_BDACDET
) != 0) {
1359 DRM_DEBUG_KMS("Composite TV connection detected\n");
1362 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1363 WREG32(RADEON_DAC_EXT_CNTL
, dac_ext_cntl
);
1364 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1365 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1366 WREG32(RADEON_DAC_CNTL2
, dac_cntl2
);
1367 WREG32_P(RADEON_GPIOPAD_A
, gpiopad_a
, ~1);
1371 static bool radeon_legacy_tv_detect(struct drm_encoder
*encoder
,
1372 struct drm_connector
*connector
)
1374 struct drm_device
*dev
= encoder
->dev
;
1375 struct radeon_device
*rdev
= dev
->dev_private
;
1376 uint32_t tv_dac_cntl
, dac_cntl2
;
1377 uint32_t config_cntl
, tv_pre_dac_mux_cntl
, tv_master_cntl
, tmp
;
1380 if (ASIC_IS_R300(rdev
))
1381 return r300_legacy_tv_detect(encoder
, connector
);
1383 dac_cntl2
= RREG32(RADEON_DAC_CNTL2
);
1384 tv_master_cntl
= RREG32(RADEON_TV_MASTER_CNTL
);
1385 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1386 config_cntl
= RREG32(RADEON_CONFIG_CNTL
);
1387 tv_pre_dac_mux_cntl
= RREG32(RADEON_TV_PRE_DAC_MUX_CNTL
);
1389 tmp
= dac_cntl2
& ~RADEON_DAC2_DAC2_CLK_SEL
;
1390 WREG32(RADEON_DAC_CNTL2
, tmp
);
1392 tmp
= tv_master_cntl
| RADEON_TV_ON
;
1393 tmp
&= ~(RADEON_TV_ASYNC_RST
|
1394 RADEON_RESTART_PHASE_FIX
|
1395 RADEON_CRT_FIFO_CE_EN
|
1396 RADEON_TV_FIFO_CE_EN
|
1397 RADEON_RE_SYNC_NOW_SEL_MASK
);
1398 tmp
|= RADEON_TV_FIFO_ASYNC_RST
| RADEON_CRT_ASYNC_RST
;
1399 WREG32(RADEON_TV_MASTER_CNTL
, tmp
);
1401 tmp
= RADEON_TV_DAC_NBLANK
| RADEON_TV_DAC_NHOLD
|
1402 RADEON_TV_MONITOR_DETECT_EN
| RADEON_TV_DAC_STD_NTSC
|
1403 (8 << RADEON_TV_DAC_BGADJ_SHIFT
);
1405 if (config_cntl
& RADEON_CFG_ATI_REV_ID_MASK
)
1406 tmp
|= (4 << RADEON_TV_DAC_DACADJ_SHIFT
);
1408 tmp
|= (8 << RADEON_TV_DAC_DACADJ_SHIFT
);
1409 WREG32(RADEON_TV_DAC_CNTL
, tmp
);
1411 tmp
= RADEON_C_GRN_EN
| RADEON_CMP_BLU_EN
|
1412 RADEON_RED_MX_FORCE_DAC_DATA
|
1413 RADEON_GRN_MX_FORCE_DAC_DATA
|
1414 RADEON_BLU_MX_FORCE_DAC_DATA
|
1415 (0x109 << RADEON_TV_FORCE_DAC_DATA_SHIFT
);
1416 WREG32(RADEON_TV_PRE_DAC_MUX_CNTL
, tmp
);
1419 tmp
= RREG32(RADEON_TV_DAC_CNTL
);
1420 if (tmp
& RADEON_TV_DAC_GDACDET
) {
1422 DRM_DEBUG_KMS("S-video TV connection detected\n");
1423 } else if ((tmp
& RADEON_TV_DAC_BDACDET
) != 0) {
1425 DRM_DEBUG_KMS("Composite TV connection detected\n");
1428 WREG32(RADEON_TV_PRE_DAC_MUX_CNTL
, tv_pre_dac_mux_cntl
);
1429 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1430 WREG32(RADEON_TV_MASTER_CNTL
, tv_master_cntl
);
1431 WREG32(RADEON_DAC_CNTL2
, dac_cntl2
);
1435 static bool radeon_legacy_ext_dac_detect(struct drm_encoder
*encoder
,
1436 struct drm_connector
*connector
)
1438 struct drm_device
*dev
= encoder
->dev
;
1439 struct radeon_device
*rdev
= dev
->dev_private
;
1440 uint32_t gpio_monid
, fp2_gen_cntl
, disp_output_cntl
, crtc2_gen_cntl
;
1441 uint32_t disp_lin_trans_grph_a
, disp_lin_trans_grph_b
, disp_lin_trans_grph_c
;
1442 uint32_t disp_lin_trans_grph_d
, disp_lin_trans_grph_e
, disp_lin_trans_grph_f
;
1443 uint32_t tmp
, crtc2_h_total_disp
, crtc2_v_total_disp
;
1444 uint32_t crtc2_h_sync_strt_wid
, crtc2_v_sync_strt_wid
;
1448 /* save the regs we need */
1449 gpio_monid
= RREG32(RADEON_GPIO_MONID
);
1450 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
1451 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
);
1452 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1453 disp_lin_trans_grph_a
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_A
);
1454 disp_lin_trans_grph_b
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_B
);
1455 disp_lin_trans_grph_c
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_C
);
1456 disp_lin_trans_grph_d
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_D
);
1457 disp_lin_trans_grph_e
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_E
);
1458 disp_lin_trans_grph_f
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_F
);
1459 crtc2_h_total_disp
= RREG32(RADEON_CRTC2_H_TOTAL_DISP
);
1460 crtc2_v_total_disp
= RREG32(RADEON_CRTC2_V_TOTAL_DISP
);
1461 crtc2_h_sync_strt_wid
= RREG32(RADEON_CRTC2_H_SYNC_STRT_WID
);
1462 crtc2_v_sync_strt_wid
= RREG32(RADEON_CRTC2_V_SYNC_STRT_WID
);
1464 tmp
= RREG32(RADEON_GPIO_MONID
);
1465 tmp
&= ~RADEON_GPIO_A_0
;
1466 WREG32(RADEON_GPIO_MONID
, tmp
);
1468 WREG32(RADEON_FP2_GEN_CNTL
, (RADEON_FP2_ON
|
1469 RADEON_FP2_PANEL_FORMAT
|
1470 R200_FP2_SOURCE_SEL_TRANS_UNIT
|
1472 R200_FP2_DVO_RATE_SEL_SDR
));
1474 WREG32(RADEON_DISP_OUTPUT_CNTL
, (RADEON_DISP_DAC_SOURCE_RMX
|
1475 RADEON_DISP_TRANS_MATRIX_GRAPHICS
));
1477 WREG32(RADEON_CRTC2_GEN_CNTL
, (RADEON_CRTC2_EN
|
1478 RADEON_CRTC2_DISP_REQ_EN_B
));
1480 WREG32(RADEON_DISP_LIN_TRANS_GRPH_A
, 0x00000000);
1481 WREG32(RADEON_DISP_LIN_TRANS_GRPH_B
, 0x000003f0);
1482 WREG32(RADEON_DISP_LIN_TRANS_GRPH_C
, 0x00000000);
1483 WREG32(RADEON_DISP_LIN_TRANS_GRPH_D
, 0x000003f0);
1484 WREG32(RADEON_DISP_LIN_TRANS_GRPH_E
, 0x00000000);
1485 WREG32(RADEON_DISP_LIN_TRANS_GRPH_F
, 0x000003f0);
1487 WREG32(RADEON_CRTC2_H_TOTAL_DISP
, 0x01000008);
1488 WREG32(RADEON_CRTC2_H_SYNC_STRT_WID
, 0x00000800);
1489 WREG32(RADEON_CRTC2_V_TOTAL_DISP
, 0x00080001);
1490 WREG32(RADEON_CRTC2_V_SYNC_STRT_WID
, 0x00000080);
1492 for (i
= 0; i
< 200; i
++) {
1493 tmp
= RREG32(RADEON_GPIO_MONID
);
1494 if (tmp
& RADEON_GPIO_Y_0
)
1500 if (!drm_can_sleep())
1506 /* restore the regs we used */
1507 WREG32(RADEON_DISP_LIN_TRANS_GRPH_A
, disp_lin_trans_grph_a
);
1508 WREG32(RADEON_DISP_LIN_TRANS_GRPH_B
, disp_lin_trans_grph_b
);
1509 WREG32(RADEON_DISP_LIN_TRANS_GRPH_C
, disp_lin_trans_grph_c
);
1510 WREG32(RADEON_DISP_LIN_TRANS_GRPH_D
, disp_lin_trans_grph_d
);
1511 WREG32(RADEON_DISP_LIN_TRANS_GRPH_E
, disp_lin_trans_grph_e
);
1512 WREG32(RADEON_DISP_LIN_TRANS_GRPH_F
, disp_lin_trans_grph_f
);
1513 WREG32(RADEON_CRTC2_H_TOTAL_DISP
, crtc2_h_total_disp
);
1514 WREG32(RADEON_CRTC2_V_TOTAL_DISP
, crtc2_v_total_disp
);
1515 WREG32(RADEON_CRTC2_H_SYNC_STRT_WID
, crtc2_h_sync_strt_wid
);
1516 WREG32(RADEON_CRTC2_V_SYNC_STRT_WID
, crtc2_v_sync_strt_wid
);
1517 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1518 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1519 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
1520 WREG32(RADEON_GPIO_MONID
, gpio_monid
);
1525 static enum drm_connector_status
radeon_legacy_tv_dac_detect(struct drm_encoder
*encoder
,
1526 struct drm_connector
*connector
)
1528 struct drm_device
*dev
= encoder
->dev
;
1529 struct radeon_device
*rdev
= dev
->dev_private
;
1530 uint32_t crtc2_gen_cntl
= 0, tv_dac_cntl
, dac_cntl2
, dac_ext_cntl
;
1531 uint32_t gpiopad_a
= 0, pixclks_cntl
, tmp
;
1532 uint32_t disp_output_cntl
= 0, disp_hw_debug
= 0, crtc_ext_cntl
= 0;
1533 enum drm_connector_status found
= connector_status_disconnected
;
1534 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1535 struct radeon_encoder_tv_dac
*tv_dac
= radeon_encoder
->enc_priv
;
1537 struct drm_crtc
*crtc
;
1539 /* find out if crtc2 is in use or if this encoder is using it */
1540 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
1541 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(crtc
);
1542 if ((radeon_crtc
->crtc_id
== 1) && crtc
->enabled
) {
1543 if (encoder
->crtc
!= crtc
) {
1544 return connector_status_disconnected
;
1549 if (connector
->connector_type
== DRM_MODE_CONNECTOR_SVIDEO
||
1550 connector
->connector_type
== DRM_MODE_CONNECTOR_Composite
||
1551 connector
->connector_type
== DRM_MODE_CONNECTOR_9PinDIN
) {
1554 if (radeon_encoder
->active_device
&& !(radeon_encoder
->active_device
& ATOM_DEVICE_TV_SUPPORT
))
1555 return connector_status_disconnected
;
1557 tv_detect
= radeon_legacy_tv_detect(encoder
, connector
);
1558 if (tv_detect
&& tv_dac
)
1559 found
= connector_status_connected
;
1563 /* don't probe if the encoder is being used for something else not CRT related */
1564 if (radeon_encoder
->active_device
&& !(radeon_encoder
->active_device
& ATOM_DEVICE_CRT_SUPPORT
)) {
1565 DRM_INFO("not detecting due to %08x\n", radeon_encoder
->active_device
);
1566 return connector_status_disconnected
;
1569 /* R200 uses an external DAC for secondary DAC */
1570 if (rdev
->family
== CHIP_R200
) {
1571 if (radeon_legacy_ext_dac_detect(encoder
, connector
))
1572 found
= connector_status_connected
;
1576 /* save the regs we need */
1577 pixclks_cntl
= RREG32_PLL(RADEON_PIXCLKS_CNTL
);
1579 if (rdev
->flags
& RADEON_SINGLE_CRTC
) {
1580 crtc_ext_cntl
= RREG32(RADEON_CRTC_EXT_CNTL
);
1582 if (ASIC_IS_R300(rdev
)) {
1583 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
);
1584 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
);
1586 disp_hw_debug
= RREG32(RADEON_DISP_HW_DEBUG
);
1588 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1590 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1591 dac_ext_cntl
= RREG32(RADEON_DAC_EXT_CNTL
);
1592 dac_cntl2
= RREG32(RADEON_DAC_CNTL2
);
1594 tmp
= pixclks_cntl
& ~(RADEON_PIX2CLK_ALWAYS_ONb
1595 | RADEON_PIX2CLK_DAC_ALWAYS_ONb
);
1596 WREG32_PLL(RADEON_PIXCLKS_CNTL
, tmp
);
1598 if (rdev
->flags
& RADEON_SINGLE_CRTC
) {
1599 tmp
= crtc_ext_cntl
| RADEON_CRTC_CRT_ON
;
1600 WREG32(RADEON_CRTC_EXT_CNTL
, tmp
);
1602 tmp
= crtc2_gen_cntl
& ~RADEON_CRTC2_PIX_WIDTH_MASK
;
1603 tmp
|= RADEON_CRTC2_CRT2_ON
|
1604 (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT
);
1605 WREG32(RADEON_CRTC2_GEN_CNTL
, tmp
);
1607 if (ASIC_IS_R300(rdev
)) {
1608 WREG32_P(RADEON_GPIOPAD_A
, 1, ~1);
1609 tmp
= disp_output_cntl
& ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1610 tmp
|= RADEON_DISP_TVDAC_SOURCE_CRTC2
;
1611 WREG32(RADEON_DISP_OUTPUT_CNTL
, tmp
);
1613 tmp
= disp_hw_debug
& ~RADEON_CRT2_DISP1_SEL
;
1614 WREG32(RADEON_DISP_HW_DEBUG
, tmp
);
1618 tmp
= RADEON_TV_DAC_NBLANK
|
1619 RADEON_TV_DAC_NHOLD
|
1620 RADEON_TV_MONITOR_DETECT_EN
|
1621 RADEON_TV_DAC_STD_PS2
;
1623 WREG32(RADEON_TV_DAC_CNTL
, tmp
);
1625 tmp
= RADEON_DAC2_FORCE_BLANK_OFF_EN
|
1626 RADEON_DAC2_FORCE_DATA_EN
;
1629 tmp
|= RADEON_DAC_FORCE_DATA_SEL_RGB
;
1631 tmp
|= RADEON_DAC_FORCE_DATA_SEL_G
;
1633 if (ASIC_IS_R300(rdev
))
1634 tmp
|= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT
);
1636 tmp
|= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT
);
1638 WREG32(RADEON_DAC_EXT_CNTL
, tmp
);
1640 tmp
= dac_cntl2
| RADEON_DAC2_DAC2_CLK_SEL
| RADEON_DAC2_CMP_EN
;
1641 WREG32(RADEON_DAC_CNTL2
, tmp
);
1645 if (ASIC_IS_R300(rdev
)) {
1646 if (RREG32(RADEON_DAC_CNTL2
) & RADEON_DAC2_CMP_OUT_B
)
1647 found
= connector_status_connected
;
1649 if (RREG32(RADEON_DAC_CNTL2
) & RADEON_DAC2_CMP_OUTPUT
)
1650 found
= connector_status_connected
;
1653 /* restore regs we used */
1654 WREG32(RADEON_DAC_CNTL2
, dac_cntl2
);
1655 WREG32(RADEON_DAC_EXT_CNTL
, dac_ext_cntl
);
1656 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1658 if (rdev
->flags
& RADEON_SINGLE_CRTC
) {
1659 WREG32(RADEON_CRTC_EXT_CNTL
, crtc_ext_cntl
);
1661 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1662 if (ASIC_IS_R300(rdev
)) {
1663 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1664 WREG32_P(RADEON_GPIOPAD_A
, gpiopad_a
, ~1);
1666 WREG32(RADEON_DISP_HW_DEBUG
, disp_hw_debug
);
1670 WREG32_PLL(RADEON_PIXCLKS_CNTL
, pixclks_cntl
);
1676 static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs
= {
1677 .dpms
= radeon_legacy_tv_dac_dpms
,
1678 .mode_fixup
= radeon_legacy_mode_fixup
,
1679 .prepare
= radeon_legacy_tv_dac_prepare
,
1680 .mode_set
= radeon_legacy_tv_dac_mode_set
,
1681 .commit
= radeon_legacy_tv_dac_commit
,
1682 .detect
= radeon_legacy_tv_dac_detect
,
1683 .disable
= radeon_legacy_encoder_disable
,
1687 static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs
= {
1688 .destroy
= radeon_enc_destroy
,
1692 static struct radeon_encoder_int_tmds
*radeon_legacy_get_tmds_info(struct radeon_encoder
*encoder
)
1694 struct drm_device
*dev
= encoder
->base
.dev
;
1695 struct radeon_device
*rdev
= dev
->dev_private
;
1696 struct radeon_encoder_int_tmds
*tmds
= NULL
;
1699 tmds
= kzalloc(sizeof(struct radeon_encoder_int_tmds
), GFP_KERNEL
);
1704 if (rdev
->is_atom_bios
)
1705 ret
= radeon_atombios_get_tmds_info(encoder
, tmds
);
1707 ret
= radeon_legacy_get_tmds_info_from_combios(encoder
, tmds
);
1710 radeon_legacy_get_tmds_info_from_table(encoder
, tmds
);
1715 static struct radeon_encoder_ext_tmds
*radeon_legacy_get_ext_tmds_info(struct radeon_encoder
*encoder
)
1717 struct drm_device
*dev
= encoder
->base
.dev
;
1718 struct radeon_device
*rdev
= dev
->dev_private
;
1719 struct radeon_encoder_ext_tmds
*tmds
= NULL
;
1722 if (rdev
->is_atom_bios
)
1725 tmds
= kzalloc(sizeof(struct radeon_encoder_ext_tmds
), GFP_KERNEL
);
1730 ret
= radeon_legacy_get_ext_tmds_info_from_combios(encoder
, tmds
);
1733 radeon_legacy_get_ext_tmds_info_from_table(encoder
, tmds
);
1739 radeon_add_legacy_encoder(struct drm_device
*dev
, uint32_t encoder_enum
, uint32_t supported_device
)
1741 struct radeon_device
*rdev
= dev
->dev_private
;
1742 struct drm_encoder
*encoder
;
1743 struct radeon_encoder
*radeon_encoder
;
1745 /* see if we already added it */
1746 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
1747 radeon_encoder
= to_radeon_encoder(encoder
);
1748 if (radeon_encoder
->encoder_enum
== encoder_enum
) {
1749 radeon_encoder
->devices
|= supported_device
;
1756 radeon_encoder
= kzalloc(sizeof(struct radeon_encoder
), GFP_KERNEL
);
1757 if (!radeon_encoder
)
1760 encoder
= &radeon_encoder
->base
;
1761 if (rdev
->flags
& RADEON_SINGLE_CRTC
)
1762 encoder
->possible_crtcs
= 0x1;
1764 encoder
->possible_crtcs
= 0x3;
1766 radeon_encoder
->enc_priv
= NULL
;
1768 radeon_encoder
->encoder_enum
= encoder_enum
;
1769 radeon_encoder
->encoder_id
= (encoder_enum
& OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
1770 radeon_encoder
->devices
= supported_device
;
1771 radeon_encoder
->rmx_type
= RMX_OFF
;
1773 switch (radeon_encoder
->encoder_id
) {
1774 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1775 encoder
->possible_crtcs
= 0x1;
1776 drm_encoder_init(dev
, encoder
, &radeon_legacy_lvds_enc_funcs
,
1777 DRM_MODE_ENCODER_LVDS
, NULL
);
1778 drm_encoder_helper_add(encoder
, &radeon_legacy_lvds_helper_funcs
);
1779 if (rdev
->is_atom_bios
)
1780 radeon_encoder
->enc_priv
= radeon_atombios_get_lvds_info(radeon_encoder
);
1782 radeon_encoder
->enc_priv
= radeon_combios_get_lvds_info(radeon_encoder
);
1783 radeon_encoder
->rmx_type
= RMX_FULL
;
1785 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1786 drm_encoder_init(dev
, encoder
, &radeon_legacy_tmds_int_enc_funcs
,
1787 DRM_MODE_ENCODER_TMDS
, NULL
);
1788 drm_encoder_helper_add(encoder
, &radeon_legacy_tmds_int_helper_funcs
);
1789 radeon_encoder
->enc_priv
= radeon_legacy_get_tmds_info(radeon_encoder
);
1791 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1792 drm_encoder_init(dev
, encoder
, &radeon_legacy_primary_dac_enc_funcs
,
1793 DRM_MODE_ENCODER_DAC
, NULL
);
1794 drm_encoder_helper_add(encoder
, &radeon_legacy_primary_dac_helper_funcs
);
1795 if (rdev
->is_atom_bios
)
1796 radeon_encoder
->enc_priv
= radeon_atombios_get_primary_dac_info(radeon_encoder
);
1798 radeon_encoder
->enc_priv
= radeon_combios_get_primary_dac_info(radeon_encoder
);
1800 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1801 drm_encoder_init(dev
, encoder
, &radeon_legacy_tv_dac_enc_funcs
,
1802 DRM_MODE_ENCODER_TVDAC
, NULL
);
1803 drm_encoder_helper_add(encoder
, &radeon_legacy_tv_dac_helper_funcs
);
1804 if (rdev
->is_atom_bios
)
1805 radeon_encoder
->enc_priv
= radeon_atombios_get_tv_dac_info(radeon_encoder
);
1807 radeon_encoder
->enc_priv
= radeon_combios_get_tv_dac_info(radeon_encoder
);
1809 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1810 drm_encoder_init(dev
, encoder
, &radeon_legacy_tmds_ext_enc_funcs
,
1811 DRM_MODE_ENCODER_TMDS
, NULL
);
1812 drm_encoder_helper_add(encoder
, &radeon_legacy_tmds_ext_helper_funcs
);
1813 if (!rdev
->is_atom_bios
)
1814 radeon_encoder
->enc_priv
= radeon_legacy_get_ext_tmds_info(radeon_encoder
);