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"
31 #include <linux/backlight.h>
32 #ifdef CONFIG_PMAC_BACKLIGHT
33 #include <asm/backlight.h>
36 static void radeon_legacy_encoder_disable(struct drm_encoder
*encoder
)
38 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
39 struct drm_encoder_helper_funcs
*encoder_funcs
;
41 encoder_funcs
= encoder
->helper_private
;
42 encoder_funcs
->dpms(encoder
, DRM_MODE_DPMS_OFF
);
43 radeon_encoder
->active_device
= 0;
46 static void radeon_legacy_lvds_update(struct drm_encoder
*encoder
, int mode
)
48 struct drm_device
*dev
= encoder
->dev
;
49 struct radeon_device
*rdev
= dev
->dev_private
;
50 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
51 uint32_t lvds_gen_cntl
, lvds_pll_cntl
, pixclks_cntl
, disp_pwr_man
;
52 int panel_pwr_delay
= 2000;
54 uint8_t backlight_level
;
57 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
58 backlight_level
= (lvds_gen_cntl
>> RADEON_LVDS_BL_MOD_LEVEL_SHIFT
) & 0xff;
60 if (radeon_encoder
->enc_priv
) {
61 if (rdev
->is_atom_bios
) {
62 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
63 panel_pwr_delay
= lvds
->panel_pwr_delay
;
65 backlight_level
= lvds
->backlight_level
;
67 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
68 panel_pwr_delay
= lvds
->panel_pwr_delay
;
70 backlight_level
= lvds
->backlight_level
;
74 /* macs (and possibly some x86 oem systems?) wire up LVDS strangely
75 * Taken from radeonfb.
77 if ((rdev
->mode_info
.connector_table
== CT_IBOOK
) ||
78 (rdev
->mode_info
.connector_table
== CT_POWERBOOK_EXTERNAL
) ||
79 (rdev
->mode_info
.connector_table
== CT_POWERBOOK_INTERNAL
) ||
80 (rdev
->mode_info
.connector_table
== CT_POWERBOOK_VGA
))
84 case DRM_MODE_DPMS_ON
:
85 disp_pwr_man
= RREG32(RADEON_DISP_PWR_MAN
);
86 disp_pwr_man
|= RADEON_AUTO_PWRUP_EN
;
87 WREG32(RADEON_DISP_PWR_MAN
, disp_pwr_man
);
88 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
89 lvds_pll_cntl
|= RADEON_LVDS_PLL_EN
;
90 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
93 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
94 lvds_pll_cntl
&= ~RADEON_LVDS_PLL_RESET
;
95 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
97 lvds_gen_cntl
&= ~(RADEON_LVDS_DISPLAY_DIS
|
98 RADEON_LVDS_BL_MOD_LEVEL_MASK
);
99 lvds_gen_cntl
|= (RADEON_LVDS_ON
| RADEON_LVDS_EN
|
100 RADEON_LVDS_DIGON
| RADEON_LVDS_BLON
|
101 (backlight_level
<< RADEON_LVDS_BL_MOD_LEVEL_SHIFT
));
103 lvds_gen_cntl
|= RADEON_LVDS_BL_MOD_EN
;
104 mdelay(panel_pwr_delay
);
105 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
107 case DRM_MODE_DPMS_STANDBY
:
108 case DRM_MODE_DPMS_SUSPEND
:
109 case DRM_MODE_DPMS_OFF
:
110 pixclks_cntl
= RREG32_PLL(RADEON_PIXCLKS_CNTL
);
111 WREG32_PLL_P(RADEON_PIXCLKS_CNTL
, 0, ~RADEON_PIXCLK_LVDS_ALWAYS_ONb
);
112 lvds_gen_cntl
|= RADEON_LVDS_DISPLAY_DIS
;
114 lvds_gen_cntl
&= ~RADEON_LVDS_BL_MOD_EN
;
115 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
116 lvds_gen_cntl
&= ~(RADEON_LVDS_ON
| RADEON_LVDS_EN
);
118 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
119 lvds_gen_cntl
&= ~(RADEON_LVDS_ON
| RADEON_LVDS_BLON
| RADEON_LVDS_EN
| RADEON_LVDS_DIGON
);
121 mdelay(panel_pwr_delay
);
122 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
123 WREG32_PLL(RADEON_PIXCLKS_CNTL
, pixclks_cntl
);
124 mdelay(panel_pwr_delay
);
128 if (rdev
->is_atom_bios
)
129 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
131 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
135 static void radeon_legacy_lvds_dpms(struct drm_encoder
*encoder
, int mode
)
137 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
138 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
141 if (radeon_encoder
->enc_priv
) {
142 if (rdev
->is_atom_bios
) {
143 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
144 lvds
->dpms_mode
= mode
;
146 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
147 lvds
->dpms_mode
= mode
;
151 radeon_legacy_lvds_update(encoder
, mode
);
154 static void radeon_legacy_lvds_prepare(struct drm_encoder
*encoder
)
156 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
158 if (rdev
->is_atom_bios
)
159 radeon_atom_output_lock(encoder
, true);
161 radeon_combios_output_lock(encoder
, true);
162 radeon_legacy_lvds_dpms(encoder
, DRM_MODE_DPMS_OFF
);
165 static void radeon_legacy_lvds_commit(struct drm_encoder
*encoder
)
167 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
169 radeon_legacy_lvds_dpms(encoder
, DRM_MODE_DPMS_ON
);
170 if (rdev
->is_atom_bios
)
171 radeon_atom_output_lock(encoder
, false);
173 radeon_combios_output_lock(encoder
, false);
176 static void radeon_legacy_lvds_mode_set(struct drm_encoder
*encoder
,
177 struct drm_display_mode
*mode
,
178 struct drm_display_mode
*adjusted_mode
)
180 struct drm_device
*dev
= encoder
->dev
;
181 struct radeon_device
*rdev
= dev
->dev_private
;
182 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
183 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
184 uint32_t lvds_pll_cntl
, lvds_gen_cntl
, lvds_ss_gen_cntl
;
188 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
189 lvds_pll_cntl
&= ~RADEON_LVDS_PLL_EN
;
191 lvds_ss_gen_cntl
= RREG32(RADEON_LVDS_SS_GEN_CNTL
);
192 if (rdev
->is_atom_bios
) {
193 /* LVDS_GEN_CNTL parameters are computed in LVDSEncoderControl
194 * need to call that on resume to set up the reg properly.
196 radeon_encoder
->pixel_clock
= adjusted_mode
->clock
;
197 atombios_digital_setup(encoder
, PANEL_ENCODER_ACTION_ENABLE
);
198 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
200 struct radeon_encoder_lvds
*lvds
= (struct radeon_encoder_lvds
*)radeon_encoder
->enc_priv
;
202 DRM_DEBUG_KMS("bios LVDS_GEN_CNTL: 0x%x\n", lvds
->lvds_gen_cntl
);
203 lvds_gen_cntl
= lvds
->lvds_gen_cntl
;
204 lvds_ss_gen_cntl
&= ~((0xf << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT
) |
205 (0xf << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT
));
206 lvds_ss_gen_cntl
|= ((lvds
->panel_digon_delay
<< RADEON_LVDS_PWRSEQ_DELAY1_SHIFT
) |
207 (lvds
->panel_blon_delay
<< RADEON_LVDS_PWRSEQ_DELAY2_SHIFT
));
209 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
211 lvds_gen_cntl
|= RADEON_LVDS_DISPLAY_DIS
;
212 lvds_gen_cntl
&= ~(RADEON_LVDS_ON
|
217 if (ASIC_IS_R300(rdev
))
218 lvds_pll_cntl
&= ~(R300_LVDS_SRC_SEL_MASK
);
220 if (radeon_crtc
->crtc_id
== 0) {
221 if (ASIC_IS_R300(rdev
)) {
222 if (radeon_encoder
->rmx_type
!= RMX_OFF
)
223 lvds_pll_cntl
|= R300_LVDS_SRC_SEL_RMX
;
225 lvds_gen_cntl
&= ~RADEON_LVDS_SEL_CRTC2
;
227 if (ASIC_IS_R300(rdev
))
228 lvds_pll_cntl
|= R300_LVDS_SRC_SEL_CRTC2
;
230 lvds_gen_cntl
|= RADEON_LVDS_SEL_CRTC2
;
233 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
234 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
235 WREG32(RADEON_LVDS_SS_GEN_CNTL
, lvds_ss_gen_cntl
);
237 if (rdev
->family
== CHIP_RV410
)
238 WREG32(RADEON_CLOCK_CNTL_INDEX
, 0);
240 if (rdev
->is_atom_bios
)
241 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
243 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
246 static bool radeon_legacy_mode_fixup(struct drm_encoder
*encoder
,
247 const struct drm_display_mode
*mode
,
248 struct drm_display_mode
*adjusted_mode
)
250 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
252 /* set the active encoder to connector routing */
253 radeon_encoder_set_active_device(encoder
);
254 drm_mode_set_crtcinfo(adjusted_mode
, 0);
256 /* get the native mode for LVDS */
257 if (radeon_encoder
->active_device
& (ATOM_DEVICE_LCD_SUPPORT
))
258 radeon_panel_mode_fixup(encoder
, adjusted_mode
);
263 static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs
= {
264 .dpms
= radeon_legacy_lvds_dpms
,
265 .mode_fixup
= radeon_legacy_mode_fixup
,
266 .prepare
= radeon_legacy_lvds_prepare
,
267 .mode_set
= radeon_legacy_lvds_mode_set
,
268 .commit
= radeon_legacy_lvds_commit
,
269 .disable
= radeon_legacy_encoder_disable
,
272 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
274 #define MAX_RADEON_LEVEL 0xFF
276 struct radeon_backlight_privdata
{
277 struct radeon_encoder
*encoder
;
281 static uint8_t radeon_legacy_lvds_level(struct backlight_device
*bd
)
283 struct radeon_backlight_privdata
*pdata
= bl_get_data(bd
);
286 /* Convert brightness to hardware level */
287 if (bd
->props
.brightness
< 0)
289 else if (bd
->props
.brightness
> MAX_RADEON_LEVEL
)
290 level
= MAX_RADEON_LEVEL
;
292 level
= bd
->props
.brightness
;
295 level
= MAX_RADEON_LEVEL
- level
;
300 static int radeon_legacy_backlight_update_status(struct backlight_device
*bd
)
302 struct radeon_backlight_privdata
*pdata
= bl_get_data(bd
);
303 struct radeon_encoder
*radeon_encoder
= pdata
->encoder
;
304 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
305 struct radeon_device
*rdev
= dev
->dev_private
;
306 int dpms_mode
= DRM_MODE_DPMS_ON
;
308 if (radeon_encoder
->enc_priv
) {
309 if (rdev
->is_atom_bios
) {
310 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
311 dpms_mode
= lvds
->dpms_mode
;
312 lvds
->backlight_level
= radeon_legacy_lvds_level(bd
);
314 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
315 dpms_mode
= lvds
->dpms_mode
;
316 lvds
->backlight_level
= radeon_legacy_lvds_level(bd
);
320 if (bd
->props
.brightness
> 0)
321 radeon_legacy_lvds_update(&radeon_encoder
->base
, dpms_mode
);
323 radeon_legacy_lvds_update(&radeon_encoder
->base
, DRM_MODE_DPMS_OFF
);
328 static int radeon_legacy_backlight_get_brightness(struct backlight_device
*bd
)
330 struct radeon_backlight_privdata
*pdata
= bl_get_data(bd
);
331 struct radeon_encoder
*radeon_encoder
= pdata
->encoder
;
332 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
333 struct radeon_device
*rdev
= dev
->dev_private
;
334 uint8_t backlight_level
;
336 backlight_level
= (RREG32(RADEON_LVDS_GEN_CNTL
) >>
337 RADEON_LVDS_BL_MOD_LEVEL_SHIFT
) & 0xff;
339 return pdata
->negative
? MAX_RADEON_LEVEL
- backlight_level
: backlight_level
;
342 static const struct backlight_ops radeon_backlight_ops
= {
343 .get_brightness
= radeon_legacy_backlight_get_brightness
,
344 .update_status
= radeon_legacy_backlight_update_status
,
347 void radeon_legacy_backlight_init(struct radeon_encoder
*radeon_encoder
,
348 struct drm_connector
*drm_connector
)
350 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
351 struct radeon_device
*rdev
= dev
->dev_private
;
352 struct backlight_device
*bd
;
353 struct backlight_properties props
;
354 struct radeon_backlight_privdata
*pdata
;
355 uint8_t backlight_level
;
357 if (!radeon_encoder
->enc_priv
)
360 #ifdef CONFIG_PMAC_BACKLIGHT
361 if (!pmac_has_backlight_type("ati") &&
362 !pmac_has_backlight_type("mnca"))
366 pdata
= kmalloc(sizeof(struct radeon_backlight_privdata
), GFP_KERNEL
);
368 DRM_ERROR("Memory allocation failed\n");
372 memset(&props
, 0, sizeof(props
));
373 props
.max_brightness
= MAX_RADEON_LEVEL
;
374 props
.type
= BACKLIGHT_RAW
;
375 bd
= backlight_device_register("radeon_bl", &drm_connector
->kdev
,
376 pdata
, &radeon_backlight_ops
, &props
);
378 DRM_ERROR("Backlight registration failed\n");
382 pdata
->encoder
= radeon_encoder
;
384 backlight_level
= (RREG32(RADEON_LVDS_GEN_CNTL
) >>
385 RADEON_LVDS_BL_MOD_LEVEL_SHIFT
) & 0xff;
387 /* First, try to detect backlight level sense based on the assumption
388 * that firmware set it up at full brightness
390 if (backlight_level
== 0)
391 pdata
->negative
= true;
392 else if (backlight_level
== 0xff)
393 pdata
->negative
= false;
395 /* XXX hack... maybe some day we can figure out in what direction
396 * backlight should work on a given panel?
398 pdata
->negative
= (rdev
->family
!= CHIP_RV200
&&
399 rdev
->family
!= CHIP_RV250
&&
400 rdev
->family
!= CHIP_RV280
&&
401 rdev
->family
!= CHIP_RV350
);
403 #ifdef CONFIG_PMAC_BACKLIGHT
404 pdata
->negative
= (pdata
->negative
||
405 of_machine_is_compatible("PowerBook4,3") ||
406 of_machine_is_compatible("PowerBook6,3") ||
407 of_machine_is_compatible("PowerBook6,5"));
411 if (rdev
->is_atom_bios
) {
412 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
415 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
419 bd
->props
.brightness
= radeon_legacy_backlight_get_brightness(bd
);
420 bd
->props
.power
= FB_BLANK_UNBLANK
;
421 backlight_update_status(bd
);
423 DRM_INFO("radeon legacy LVDS backlight initialized\n");
432 static void radeon_legacy_backlight_exit(struct radeon_encoder
*radeon_encoder
)
434 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
435 struct radeon_device
*rdev
= dev
->dev_private
;
436 struct backlight_device
*bd
= NULL
;
438 if (!radeon_encoder
->enc_priv
)
441 if (rdev
->is_atom_bios
) {
442 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
446 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
452 struct radeon_legacy_backlight_privdata
*pdata
;
454 pdata
= bl_get_data(bd
);
455 backlight_device_unregister(bd
);
458 DRM_INFO("radeon legacy LVDS backlight unloaded\n");
462 #else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */
464 void radeon_legacy_backlight_init(struct radeon_encoder
*encoder
)
468 static void radeon_legacy_backlight_exit(struct radeon_encoder
*encoder
)
475 static void radeon_lvds_enc_destroy(struct drm_encoder
*encoder
)
477 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
479 if (radeon_encoder
->enc_priv
) {
480 radeon_legacy_backlight_exit(radeon_encoder
);
481 kfree(radeon_encoder
->enc_priv
);
483 drm_encoder_cleanup(encoder
);
484 kfree(radeon_encoder
);
487 static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs
= {
488 .destroy
= radeon_lvds_enc_destroy
,
491 static void radeon_legacy_primary_dac_dpms(struct drm_encoder
*encoder
, int mode
)
493 struct drm_device
*dev
= encoder
->dev
;
494 struct radeon_device
*rdev
= dev
->dev_private
;
495 uint32_t crtc_ext_cntl
= RREG32(RADEON_CRTC_EXT_CNTL
);
496 uint32_t dac_cntl
= RREG32(RADEON_DAC_CNTL
);
497 uint32_t dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
502 case DRM_MODE_DPMS_ON
:
503 crtc_ext_cntl
|= RADEON_CRTC_CRT_ON
;
504 dac_cntl
&= ~RADEON_DAC_PDWN
;
505 dac_macro_cntl
&= ~(RADEON_DAC_PDWN_R
|
509 case DRM_MODE_DPMS_STANDBY
:
510 case DRM_MODE_DPMS_SUSPEND
:
511 case DRM_MODE_DPMS_OFF
:
512 crtc_ext_cntl
&= ~RADEON_CRTC_CRT_ON
;
513 dac_cntl
|= RADEON_DAC_PDWN
;
514 dac_macro_cntl
|= (RADEON_DAC_PDWN_R
|
520 WREG32(RADEON_CRTC_EXT_CNTL
, crtc_ext_cntl
);
521 WREG32(RADEON_DAC_CNTL
, dac_cntl
);
522 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
524 if (rdev
->is_atom_bios
)
525 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
527 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
531 static void radeon_legacy_primary_dac_prepare(struct drm_encoder
*encoder
)
533 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
535 if (rdev
->is_atom_bios
)
536 radeon_atom_output_lock(encoder
, true);
538 radeon_combios_output_lock(encoder
, true);
539 radeon_legacy_primary_dac_dpms(encoder
, DRM_MODE_DPMS_OFF
);
542 static void radeon_legacy_primary_dac_commit(struct drm_encoder
*encoder
)
544 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
546 radeon_legacy_primary_dac_dpms(encoder
, DRM_MODE_DPMS_ON
);
548 if (rdev
->is_atom_bios
)
549 radeon_atom_output_lock(encoder
, false);
551 radeon_combios_output_lock(encoder
, false);
554 static void radeon_legacy_primary_dac_mode_set(struct drm_encoder
*encoder
,
555 struct drm_display_mode
*mode
,
556 struct drm_display_mode
*adjusted_mode
)
558 struct drm_device
*dev
= encoder
->dev
;
559 struct radeon_device
*rdev
= dev
->dev_private
;
560 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
561 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
562 uint32_t disp_output_cntl
, dac_cntl
, dac2_cntl
, dac_macro_cntl
;
566 if (radeon_crtc
->crtc_id
== 0) {
567 if (rdev
->family
== CHIP_R200
|| ASIC_IS_R300(rdev
)) {
568 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
) &
569 ~(RADEON_DISP_DAC_SOURCE_MASK
);
570 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
572 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) & ~(RADEON_DAC2_DAC_CLK_SEL
);
573 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
576 if (rdev
->family
== CHIP_R200
|| ASIC_IS_R300(rdev
)) {
577 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
) &
578 ~(RADEON_DISP_DAC_SOURCE_MASK
);
579 disp_output_cntl
|= RADEON_DISP_DAC_SOURCE_CRTC2
;
580 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
582 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) | RADEON_DAC2_DAC_CLK_SEL
;
583 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
587 dac_cntl
= (RADEON_DAC_MASK_ALL
|
588 RADEON_DAC_VGA_ADR_EN
|
592 WREG32_P(RADEON_DAC_CNTL
,
594 RADEON_DAC_RANGE_CNTL
|
595 RADEON_DAC_BLANKING
);
597 if (radeon_encoder
->enc_priv
) {
598 struct radeon_encoder_primary_dac
*p_dac
= (struct radeon_encoder_primary_dac
*)radeon_encoder
->enc_priv
;
599 dac_macro_cntl
= p_dac
->ps2_pdac_adj
;
601 dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
602 dac_macro_cntl
|= RADEON_DAC_PDWN_R
| RADEON_DAC_PDWN_G
| RADEON_DAC_PDWN_B
;
603 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
605 if (rdev
->is_atom_bios
)
606 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
608 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
611 static enum drm_connector_status
radeon_legacy_primary_dac_detect(struct drm_encoder
*encoder
,
612 struct drm_connector
*connector
)
614 struct drm_device
*dev
= encoder
->dev
;
615 struct radeon_device
*rdev
= dev
->dev_private
;
616 uint32_t vclk_ecp_cntl
, crtc_ext_cntl
;
617 uint32_t dac_ext_cntl
, dac_cntl
, dac_macro_cntl
, tmp
;
618 enum drm_connector_status found
= connector_status_disconnected
;
621 /* save the regs we need */
622 vclk_ecp_cntl
= RREG32_PLL(RADEON_VCLK_ECP_CNTL
);
623 crtc_ext_cntl
= RREG32(RADEON_CRTC_EXT_CNTL
);
624 dac_ext_cntl
= RREG32(RADEON_DAC_EXT_CNTL
);
625 dac_cntl
= RREG32(RADEON_DAC_CNTL
);
626 dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
628 tmp
= vclk_ecp_cntl
&
629 ~(RADEON_PIXCLK_ALWAYS_ONb
| RADEON_PIXCLK_DAC_ALWAYS_ONb
);
630 WREG32_PLL(RADEON_VCLK_ECP_CNTL
, tmp
);
632 tmp
= crtc_ext_cntl
| RADEON_CRTC_CRT_ON
;
633 WREG32(RADEON_CRTC_EXT_CNTL
, tmp
);
635 tmp
= RADEON_DAC_FORCE_BLANK_OFF_EN
|
636 RADEON_DAC_FORCE_DATA_EN
;
639 tmp
|= RADEON_DAC_FORCE_DATA_SEL_RGB
;
641 tmp
|= RADEON_DAC_FORCE_DATA_SEL_G
;
643 if (ASIC_IS_R300(rdev
))
644 tmp
|= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT
);
646 tmp
|= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT
);
648 WREG32(RADEON_DAC_EXT_CNTL
, tmp
);
650 tmp
= dac_cntl
& ~(RADEON_DAC_RANGE_CNTL_MASK
| RADEON_DAC_PDWN
);
651 tmp
|= RADEON_DAC_RANGE_CNTL_PS2
| RADEON_DAC_CMP_EN
;
652 WREG32(RADEON_DAC_CNTL
, tmp
);
654 tmp
= dac_macro_cntl
;
655 tmp
&= ~(RADEON_DAC_PDWN_R
|
659 WREG32(RADEON_DAC_MACRO_CNTL
, tmp
);
663 if (RREG32(RADEON_DAC_CNTL
) & RADEON_DAC_CMP_OUTPUT
)
664 found
= connector_status_connected
;
666 /* restore the regs we used */
667 WREG32(RADEON_DAC_CNTL
, dac_cntl
);
668 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
669 WREG32(RADEON_DAC_EXT_CNTL
, dac_ext_cntl
);
670 WREG32(RADEON_CRTC_EXT_CNTL
, crtc_ext_cntl
);
671 WREG32_PLL(RADEON_VCLK_ECP_CNTL
, vclk_ecp_cntl
);
676 static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs
= {
677 .dpms
= radeon_legacy_primary_dac_dpms
,
678 .mode_fixup
= radeon_legacy_mode_fixup
,
679 .prepare
= radeon_legacy_primary_dac_prepare
,
680 .mode_set
= radeon_legacy_primary_dac_mode_set
,
681 .commit
= radeon_legacy_primary_dac_commit
,
682 .detect
= radeon_legacy_primary_dac_detect
,
683 .disable
= radeon_legacy_encoder_disable
,
687 static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs
= {
688 .destroy
= radeon_enc_destroy
,
691 static void radeon_legacy_tmds_int_dpms(struct drm_encoder
*encoder
, int mode
)
693 struct drm_device
*dev
= encoder
->dev
;
694 struct radeon_device
*rdev
= dev
->dev_private
;
695 uint32_t fp_gen_cntl
= RREG32(RADEON_FP_GEN_CNTL
);
699 case DRM_MODE_DPMS_ON
:
700 fp_gen_cntl
|= (RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
702 case DRM_MODE_DPMS_STANDBY
:
703 case DRM_MODE_DPMS_SUSPEND
:
704 case DRM_MODE_DPMS_OFF
:
705 fp_gen_cntl
&= ~(RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
709 WREG32(RADEON_FP_GEN_CNTL
, fp_gen_cntl
);
711 if (rdev
->is_atom_bios
)
712 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
714 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
718 static void radeon_legacy_tmds_int_prepare(struct drm_encoder
*encoder
)
720 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
722 if (rdev
->is_atom_bios
)
723 radeon_atom_output_lock(encoder
, true);
725 radeon_combios_output_lock(encoder
, true);
726 radeon_legacy_tmds_int_dpms(encoder
, DRM_MODE_DPMS_OFF
);
729 static void radeon_legacy_tmds_int_commit(struct drm_encoder
*encoder
)
731 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
733 radeon_legacy_tmds_int_dpms(encoder
, DRM_MODE_DPMS_ON
);
735 if (rdev
->is_atom_bios
)
736 radeon_atom_output_lock(encoder
, true);
738 radeon_combios_output_lock(encoder
, true);
741 static void radeon_legacy_tmds_int_mode_set(struct drm_encoder
*encoder
,
742 struct drm_display_mode
*mode
,
743 struct drm_display_mode
*adjusted_mode
)
745 struct drm_device
*dev
= encoder
->dev
;
746 struct radeon_device
*rdev
= dev
->dev_private
;
747 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
748 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
749 uint32_t tmp
, tmds_pll_cntl
, tmds_transmitter_cntl
, fp_gen_cntl
;
754 tmp
= tmds_pll_cntl
= RREG32(RADEON_TMDS_PLL_CNTL
);
756 if (rdev
->family
== CHIP_RV280
) {
757 /* bit 22 of TMDS_PLL_CNTL is read-back inverted */
759 tmds_pll_cntl
^= (1 << 22);
762 if (radeon_encoder
->enc_priv
) {
763 struct radeon_encoder_int_tmds
*tmds
= (struct radeon_encoder_int_tmds
*)radeon_encoder
->enc_priv
;
765 for (i
= 0; i
< 4; i
++) {
766 if (tmds
->tmds_pll
[i
].freq
== 0)
768 if ((uint32_t)(mode
->clock
/ 10) < tmds
->tmds_pll
[i
].freq
) {
769 tmp
= tmds
->tmds_pll
[i
].value
;
775 if (ASIC_IS_R300(rdev
) || (rdev
->family
== CHIP_RV280
)) {
776 if (tmp
& 0xfff00000)
779 tmds_pll_cntl
&= 0xfff00000;
780 tmds_pll_cntl
|= tmp
;
785 tmds_transmitter_cntl
= RREG32(RADEON_TMDS_TRANSMITTER_CNTL
) &
786 ~(RADEON_TMDS_TRANSMITTER_PLLRST
);
788 if (rdev
->family
== CHIP_R200
||
789 rdev
->family
== CHIP_R100
||
791 tmds_transmitter_cntl
&= ~(RADEON_TMDS_TRANSMITTER_PLLEN
);
792 else /* RV chips got this bit reversed */
793 tmds_transmitter_cntl
|= RADEON_TMDS_TRANSMITTER_PLLEN
;
795 fp_gen_cntl
= (RREG32(RADEON_FP_GEN_CNTL
) |
796 (RADEON_FP_CRTC_DONT_SHADOW_VPAR
|
797 RADEON_FP_CRTC_DONT_SHADOW_HEND
));
799 fp_gen_cntl
&= ~(RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
801 fp_gen_cntl
&= ~(RADEON_FP_RMX_HVSYNC_CONTROL_EN
|
802 RADEON_FP_DFP_SYNC_SEL
|
803 RADEON_FP_CRT_SYNC_SEL
|
804 RADEON_FP_CRTC_LOCK_8DOT
|
805 RADEON_FP_USE_SHADOW_EN
|
806 RADEON_FP_CRTC_USE_SHADOW_VEND
|
807 RADEON_FP_CRT_SYNC_ALT
);
809 if (1) /* FIXME rgbBits == 8 */
810 fp_gen_cntl
|= RADEON_FP_PANEL_FORMAT
; /* 24 bit format */
812 fp_gen_cntl
&= ~RADEON_FP_PANEL_FORMAT
;/* 18 bit format */
814 if (radeon_crtc
->crtc_id
== 0) {
815 if (ASIC_IS_R300(rdev
) || rdev
->family
== CHIP_R200
) {
816 fp_gen_cntl
&= ~R200_FP_SOURCE_SEL_MASK
;
817 if (radeon_encoder
->rmx_type
!= RMX_OFF
)
818 fp_gen_cntl
|= R200_FP_SOURCE_SEL_RMX
;
820 fp_gen_cntl
|= R200_FP_SOURCE_SEL_CRTC1
;
822 fp_gen_cntl
&= ~RADEON_FP_SEL_CRTC2
;
824 if (ASIC_IS_R300(rdev
) || rdev
->family
== CHIP_R200
) {
825 fp_gen_cntl
&= ~R200_FP_SOURCE_SEL_MASK
;
826 fp_gen_cntl
|= R200_FP_SOURCE_SEL_CRTC2
;
828 fp_gen_cntl
|= RADEON_FP_SEL_CRTC2
;
831 WREG32(RADEON_TMDS_PLL_CNTL
, tmds_pll_cntl
);
832 WREG32(RADEON_TMDS_TRANSMITTER_CNTL
, tmds_transmitter_cntl
);
833 WREG32(RADEON_FP_GEN_CNTL
, fp_gen_cntl
);
835 if (rdev
->is_atom_bios
)
836 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
838 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
841 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs
= {
842 .dpms
= radeon_legacy_tmds_int_dpms
,
843 .mode_fixup
= radeon_legacy_mode_fixup
,
844 .prepare
= radeon_legacy_tmds_int_prepare
,
845 .mode_set
= radeon_legacy_tmds_int_mode_set
,
846 .commit
= radeon_legacy_tmds_int_commit
,
847 .disable
= radeon_legacy_encoder_disable
,
851 static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs
= {
852 .destroy
= radeon_enc_destroy
,
855 static void radeon_legacy_tmds_ext_dpms(struct drm_encoder
*encoder
, int mode
)
857 struct drm_device
*dev
= encoder
->dev
;
858 struct radeon_device
*rdev
= dev
->dev_private
;
859 uint32_t fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
863 case DRM_MODE_DPMS_ON
:
864 fp2_gen_cntl
&= ~RADEON_FP2_BLANK_EN
;
865 fp2_gen_cntl
|= (RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
867 case DRM_MODE_DPMS_STANDBY
:
868 case DRM_MODE_DPMS_SUSPEND
:
869 case DRM_MODE_DPMS_OFF
:
870 fp2_gen_cntl
|= RADEON_FP2_BLANK_EN
;
871 fp2_gen_cntl
&= ~(RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
875 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
877 if (rdev
->is_atom_bios
)
878 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
880 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
884 static void radeon_legacy_tmds_ext_prepare(struct drm_encoder
*encoder
)
886 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
888 if (rdev
->is_atom_bios
)
889 radeon_atom_output_lock(encoder
, true);
891 radeon_combios_output_lock(encoder
, true);
892 radeon_legacy_tmds_ext_dpms(encoder
, DRM_MODE_DPMS_OFF
);
895 static void radeon_legacy_tmds_ext_commit(struct drm_encoder
*encoder
)
897 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
898 radeon_legacy_tmds_ext_dpms(encoder
, DRM_MODE_DPMS_ON
);
900 if (rdev
->is_atom_bios
)
901 radeon_atom_output_lock(encoder
, false);
903 radeon_combios_output_lock(encoder
, false);
906 static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder
*encoder
,
907 struct drm_display_mode
*mode
,
908 struct drm_display_mode
*adjusted_mode
)
910 struct drm_device
*dev
= encoder
->dev
;
911 struct radeon_device
*rdev
= dev
->dev_private
;
912 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
913 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
914 uint32_t fp2_gen_cntl
;
918 if (rdev
->is_atom_bios
) {
919 radeon_encoder
->pixel_clock
= adjusted_mode
->clock
;
920 atombios_dvo_setup(encoder
, ATOM_ENABLE
);
921 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
923 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
925 if (1) /* FIXME rgbBits == 8 */
926 fp2_gen_cntl
|= RADEON_FP2_PANEL_FORMAT
; /* 24 bit format, */
928 fp2_gen_cntl
&= ~RADEON_FP2_PANEL_FORMAT
;/* 18 bit format, */
930 fp2_gen_cntl
&= ~(RADEON_FP2_ON
|
932 RADEON_FP2_DVO_RATE_SEL_SDR
);
934 /* XXX: these are oem specific */
935 if (ASIC_IS_R300(rdev
)) {
936 if ((dev
->pdev
->device
== 0x4850) &&
937 (dev
->pdev
->subsystem_vendor
== 0x1028) &&
938 (dev
->pdev
->subsystem_device
== 0x2001)) /* Dell Inspiron 8600 */
939 fp2_gen_cntl
|= R300_FP2_DVO_CLOCK_MODE_SINGLE
;
941 fp2_gen_cntl
|= RADEON_FP2_PAD_FLOP_EN
| R300_FP2_DVO_CLOCK_MODE_SINGLE
;
943 /*if (mode->clock > 165000)
944 fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/
946 if (!radeon_combios_external_tmds_setup(encoder
))
947 radeon_external_tmds_setup(encoder
);
950 if (radeon_crtc
->crtc_id
== 0) {
951 if ((rdev
->family
== CHIP_R200
) || ASIC_IS_R300(rdev
)) {
952 fp2_gen_cntl
&= ~R200_FP2_SOURCE_SEL_MASK
;
953 if (radeon_encoder
->rmx_type
!= RMX_OFF
)
954 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_RMX
;
956 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC1
;
958 fp2_gen_cntl
&= ~RADEON_FP2_SRC_SEL_CRTC2
;
960 if ((rdev
->family
== CHIP_R200
) || ASIC_IS_R300(rdev
)) {
961 fp2_gen_cntl
&= ~R200_FP2_SOURCE_SEL_MASK
;
962 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC2
;
964 fp2_gen_cntl
|= RADEON_FP2_SRC_SEL_CRTC2
;
967 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
969 if (rdev
->is_atom_bios
)
970 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
972 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
975 static void radeon_ext_tmds_enc_destroy(struct drm_encoder
*encoder
)
977 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
978 /* don't destroy the i2c bus record here, this will be done in radeon_i2c_fini */
979 kfree(radeon_encoder
->enc_priv
);
980 drm_encoder_cleanup(encoder
);
981 kfree(radeon_encoder
);
984 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs
= {
985 .dpms
= radeon_legacy_tmds_ext_dpms
,
986 .mode_fixup
= radeon_legacy_mode_fixup
,
987 .prepare
= radeon_legacy_tmds_ext_prepare
,
988 .mode_set
= radeon_legacy_tmds_ext_mode_set
,
989 .commit
= radeon_legacy_tmds_ext_commit
,
990 .disable
= radeon_legacy_encoder_disable
,
994 static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs
= {
995 .destroy
= radeon_ext_tmds_enc_destroy
,
998 static void radeon_legacy_tv_dac_dpms(struct drm_encoder
*encoder
, int mode
)
1000 struct drm_device
*dev
= encoder
->dev
;
1001 struct radeon_device
*rdev
= dev
->dev_private
;
1002 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1003 uint32_t fp2_gen_cntl
= 0, crtc2_gen_cntl
= 0, tv_dac_cntl
= 0;
1004 uint32_t tv_master_cntl
= 0;
1006 DRM_DEBUG_KMS("\n");
1008 is_tv
= radeon_encoder
->active_device
& ATOM_DEVICE_TV_SUPPORT
? true : false;
1010 if (rdev
->family
== CHIP_R200
)
1011 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
1014 tv_master_cntl
= RREG32(RADEON_TV_MASTER_CNTL
);
1016 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1017 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1021 case DRM_MODE_DPMS_ON
:
1022 if (rdev
->family
== CHIP_R200
) {
1023 fp2_gen_cntl
|= (RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
1026 tv_master_cntl
|= RADEON_TV_ON
;
1028 crtc2_gen_cntl
|= RADEON_CRTC2_CRT2_ON
;
1030 if (rdev
->family
== CHIP_R420
||
1031 rdev
->family
== CHIP_R423
||
1032 rdev
->family
== CHIP_RV410
)
1033 tv_dac_cntl
&= ~(R420_TV_DAC_RDACPD
|
1034 R420_TV_DAC_GDACPD
|
1035 R420_TV_DAC_BDACPD
|
1036 RADEON_TV_DAC_BGSLEEP
);
1038 tv_dac_cntl
&= ~(RADEON_TV_DAC_RDACPD
|
1039 RADEON_TV_DAC_GDACPD
|
1040 RADEON_TV_DAC_BDACPD
|
1041 RADEON_TV_DAC_BGSLEEP
);
1044 case DRM_MODE_DPMS_STANDBY
:
1045 case DRM_MODE_DPMS_SUSPEND
:
1046 case DRM_MODE_DPMS_OFF
:
1047 if (rdev
->family
== CHIP_R200
)
1048 fp2_gen_cntl
&= ~(RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
1051 tv_master_cntl
&= ~RADEON_TV_ON
;
1053 crtc2_gen_cntl
&= ~RADEON_CRTC2_CRT2_ON
;
1055 if (rdev
->family
== CHIP_R420
||
1056 rdev
->family
== CHIP_R423
||
1057 rdev
->family
== CHIP_RV410
)
1058 tv_dac_cntl
|= (R420_TV_DAC_RDACPD
|
1059 R420_TV_DAC_GDACPD
|
1060 R420_TV_DAC_BDACPD
|
1061 RADEON_TV_DAC_BGSLEEP
);
1063 tv_dac_cntl
|= (RADEON_TV_DAC_RDACPD
|
1064 RADEON_TV_DAC_GDACPD
|
1065 RADEON_TV_DAC_BDACPD
|
1066 RADEON_TV_DAC_BGSLEEP
);
1071 if (rdev
->family
== CHIP_R200
) {
1072 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
1075 WREG32(RADEON_TV_MASTER_CNTL
, tv_master_cntl
);
1077 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1078 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1081 if (rdev
->is_atom_bios
)
1082 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
1084 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
1088 static void radeon_legacy_tv_dac_prepare(struct drm_encoder
*encoder
)
1090 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
1092 if (rdev
->is_atom_bios
)
1093 radeon_atom_output_lock(encoder
, true);
1095 radeon_combios_output_lock(encoder
, true);
1096 radeon_legacy_tv_dac_dpms(encoder
, DRM_MODE_DPMS_OFF
);
1099 static void radeon_legacy_tv_dac_commit(struct drm_encoder
*encoder
)
1101 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
1103 radeon_legacy_tv_dac_dpms(encoder
, DRM_MODE_DPMS_ON
);
1105 if (rdev
->is_atom_bios
)
1106 radeon_atom_output_lock(encoder
, true);
1108 radeon_combios_output_lock(encoder
, true);
1111 static void radeon_legacy_tv_dac_mode_set(struct drm_encoder
*encoder
,
1112 struct drm_display_mode
*mode
,
1113 struct drm_display_mode
*adjusted_mode
)
1115 struct drm_device
*dev
= encoder
->dev
;
1116 struct radeon_device
*rdev
= dev
->dev_private
;
1117 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1118 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1119 struct radeon_encoder_tv_dac
*tv_dac
= radeon_encoder
->enc_priv
;
1120 uint32_t tv_dac_cntl
, gpiopad_a
= 0, dac2_cntl
, disp_output_cntl
= 0;
1121 uint32_t disp_hw_debug
= 0, fp2_gen_cntl
= 0, disp_tv_out_cntl
= 0;
1124 DRM_DEBUG_KMS("\n");
1126 is_tv
= radeon_encoder
->active_device
& ATOM_DEVICE_TV_SUPPORT
? true : false;
1128 if (rdev
->family
!= CHIP_R200
) {
1129 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1130 if (rdev
->family
== CHIP_R420
||
1131 rdev
->family
== CHIP_R423
||
1132 rdev
->family
== CHIP_RV410
) {
1133 tv_dac_cntl
&= ~(RADEON_TV_DAC_STD_MASK
|
1134 RADEON_TV_DAC_BGADJ_MASK
|
1135 R420_TV_DAC_DACADJ_MASK
|
1136 R420_TV_DAC_RDACPD
|
1137 R420_TV_DAC_GDACPD
|
1138 R420_TV_DAC_BDACPD
|
1139 R420_TV_DAC_TVENABLE
);
1141 tv_dac_cntl
&= ~(RADEON_TV_DAC_STD_MASK
|
1142 RADEON_TV_DAC_BGADJ_MASK
|
1143 RADEON_TV_DAC_DACADJ_MASK
|
1144 RADEON_TV_DAC_RDACPD
|
1145 RADEON_TV_DAC_GDACPD
|
1146 RADEON_TV_DAC_BDACPD
);
1149 tv_dac_cntl
|= RADEON_TV_DAC_NBLANK
| RADEON_TV_DAC_NHOLD
;
1152 if (tv_dac
->tv_std
== TV_STD_NTSC
||
1153 tv_dac
->tv_std
== TV_STD_NTSC_J
||
1154 tv_dac
->tv_std
== TV_STD_PAL_M
||
1155 tv_dac
->tv_std
== TV_STD_PAL_60
)
1156 tv_dac_cntl
|= tv_dac
->ntsc_tvdac_adj
;
1158 tv_dac_cntl
|= tv_dac
->pal_tvdac_adj
;
1160 if (tv_dac
->tv_std
== TV_STD_NTSC
||
1161 tv_dac
->tv_std
== TV_STD_NTSC_J
)
1162 tv_dac_cntl
|= RADEON_TV_DAC_STD_NTSC
;
1164 tv_dac_cntl
|= RADEON_TV_DAC_STD_PAL
;
1166 tv_dac_cntl
|= (RADEON_TV_DAC_STD_PS2
|
1167 tv_dac
->ps2_tvdac_adj
);
1169 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1172 if (ASIC_IS_R300(rdev
)) {
1173 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
) | 1;
1174 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
);
1175 } else if (rdev
->family
!= CHIP_R200
)
1176 disp_hw_debug
= RREG32(RADEON_DISP_HW_DEBUG
);
1177 else if (rdev
->family
== CHIP_R200
)
1178 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
1180 if (rdev
->family
>= CHIP_R200
)
1181 disp_tv_out_cntl
= RREG32(RADEON_DISP_TV_OUT_CNTL
);
1186 dac_cntl
= RREG32(RADEON_DAC_CNTL
);
1187 dac_cntl
&= ~RADEON_DAC_TVO_EN
;
1188 WREG32(RADEON_DAC_CNTL
, dac_cntl
);
1190 if (ASIC_IS_R300(rdev
))
1191 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
) & ~1;
1193 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) & ~RADEON_DAC2_DAC2_CLK_SEL
;
1194 if (radeon_crtc
->crtc_id
== 0) {
1195 if (ASIC_IS_R300(rdev
)) {
1196 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1197 disp_output_cntl
|= (RADEON_DISP_TVDAC_SOURCE_CRTC
|
1198 RADEON_DISP_TV_SOURCE_CRTC
);
1200 if (rdev
->family
>= CHIP_R200
) {
1201 disp_tv_out_cntl
&= ~RADEON_DISP_TV_PATH_SRC_CRTC2
;
1203 disp_hw_debug
|= RADEON_CRT2_DISP1_SEL
;
1206 if (ASIC_IS_R300(rdev
)) {
1207 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1208 disp_output_cntl
|= RADEON_DISP_TV_SOURCE_CRTC
;
1210 if (rdev
->family
>= CHIP_R200
) {
1211 disp_tv_out_cntl
|= RADEON_DISP_TV_PATH_SRC_CRTC2
;
1213 disp_hw_debug
&= ~RADEON_CRT2_DISP1_SEL
;
1216 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
1219 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) | RADEON_DAC2_DAC2_CLK_SEL
;
1221 if (radeon_crtc
->crtc_id
== 0) {
1222 if (ASIC_IS_R300(rdev
)) {
1223 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1224 disp_output_cntl
|= RADEON_DISP_TVDAC_SOURCE_CRTC
;
1225 } else if (rdev
->family
== CHIP_R200
) {
1226 fp2_gen_cntl
&= ~(R200_FP2_SOURCE_SEL_MASK
|
1227 RADEON_FP2_DVO_RATE_SEL_SDR
);
1229 disp_hw_debug
|= RADEON_CRT2_DISP1_SEL
;
1231 if (ASIC_IS_R300(rdev
)) {
1232 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1233 disp_output_cntl
|= RADEON_DISP_TVDAC_SOURCE_CRTC2
;
1234 } else if (rdev
->family
== CHIP_R200
) {
1235 fp2_gen_cntl
&= ~(R200_FP2_SOURCE_SEL_MASK
|
1236 RADEON_FP2_DVO_RATE_SEL_SDR
);
1237 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC2
;
1239 disp_hw_debug
&= ~RADEON_CRT2_DISP1_SEL
;
1241 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
1244 if (ASIC_IS_R300(rdev
)) {
1245 WREG32_P(RADEON_GPIOPAD_A
, gpiopad_a
, ~1);
1246 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1247 } else if (rdev
->family
!= CHIP_R200
)
1248 WREG32(RADEON_DISP_HW_DEBUG
, disp_hw_debug
);
1249 else if (rdev
->family
== CHIP_R200
)
1250 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
1252 if (rdev
->family
>= CHIP_R200
)
1253 WREG32(RADEON_DISP_TV_OUT_CNTL
, disp_tv_out_cntl
);
1256 radeon_legacy_tv_mode_set(encoder
, mode
, adjusted_mode
);
1258 if (rdev
->is_atom_bios
)
1259 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1261 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1265 static bool r300_legacy_tv_detect(struct drm_encoder
*encoder
,
1266 struct drm_connector
*connector
)
1268 struct drm_device
*dev
= encoder
->dev
;
1269 struct radeon_device
*rdev
= dev
->dev_private
;
1270 uint32_t crtc2_gen_cntl
, tv_dac_cntl
, dac_cntl2
, dac_ext_cntl
;
1271 uint32_t disp_output_cntl
, gpiopad_a
, tmp
;
1274 /* save regs needed */
1275 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
);
1276 dac_cntl2
= RREG32(RADEON_DAC_CNTL2
);
1277 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1278 dac_ext_cntl
= RREG32(RADEON_DAC_EXT_CNTL
);
1279 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1280 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
);
1282 WREG32_P(RADEON_GPIOPAD_A
, 0, ~1);
1284 WREG32(RADEON_DAC_CNTL2
, RADEON_DAC2_DAC2_CLK_SEL
);
1286 WREG32(RADEON_CRTC2_GEN_CNTL
,
1287 RADEON_CRTC2_CRT2_ON
| RADEON_CRTC2_VSYNC_TRISTAT
);
1289 tmp
= disp_output_cntl
& ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1290 tmp
|= RADEON_DISP_TVDAC_SOURCE_CRTC2
;
1291 WREG32(RADEON_DISP_OUTPUT_CNTL
, tmp
);
1293 WREG32(RADEON_DAC_EXT_CNTL
,
1294 RADEON_DAC2_FORCE_BLANK_OFF_EN
|
1295 RADEON_DAC2_FORCE_DATA_EN
|
1296 RADEON_DAC_FORCE_DATA_SEL_RGB
|
1297 (0xec << RADEON_DAC_FORCE_DATA_SHIFT
));
1299 WREG32(RADEON_TV_DAC_CNTL
,
1300 RADEON_TV_DAC_STD_NTSC
|
1301 (8 << RADEON_TV_DAC_BGADJ_SHIFT
) |
1302 (6 << RADEON_TV_DAC_DACADJ_SHIFT
));
1304 RREG32(RADEON_TV_DAC_CNTL
);
1307 WREG32(RADEON_TV_DAC_CNTL
,
1308 RADEON_TV_DAC_NBLANK
|
1309 RADEON_TV_DAC_NHOLD
|
1310 RADEON_TV_MONITOR_DETECT_EN
|
1311 RADEON_TV_DAC_STD_NTSC
|
1312 (8 << RADEON_TV_DAC_BGADJ_SHIFT
) |
1313 (6 << RADEON_TV_DAC_DACADJ_SHIFT
));
1315 RREG32(RADEON_TV_DAC_CNTL
);
1318 tmp
= RREG32(RADEON_TV_DAC_CNTL
);
1319 if ((tmp
& RADEON_TV_DAC_GDACDET
) != 0) {
1321 DRM_DEBUG_KMS("S-video TV connection detected\n");
1322 } else if ((tmp
& RADEON_TV_DAC_BDACDET
) != 0) {
1324 DRM_DEBUG_KMS("Composite TV connection detected\n");
1327 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1328 WREG32(RADEON_DAC_EXT_CNTL
, dac_ext_cntl
);
1329 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1330 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1331 WREG32(RADEON_DAC_CNTL2
, dac_cntl2
);
1332 WREG32_P(RADEON_GPIOPAD_A
, gpiopad_a
, ~1);
1336 static bool radeon_legacy_tv_detect(struct drm_encoder
*encoder
,
1337 struct drm_connector
*connector
)
1339 struct drm_device
*dev
= encoder
->dev
;
1340 struct radeon_device
*rdev
= dev
->dev_private
;
1341 uint32_t tv_dac_cntl
, dac_cntl2
;
1342 uint32_t config_cntl
, tv_pre_dac_mux_cntl
, tv_master_cntl
, tmp
;
1345 if (ASIC_IS_R300(rdev
))
1346 return r300_legacy_tv_detect(encoder
, connector
);
1348 dac_cntl2
= RREG32(RADEON_DAC_CNTL2
);
1349 tv_master_cntl
= RREG32(RADEON_TV_MASTER_CNTL
);
1350 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1351 config_cntl
= RREG32(RADEON_CONFIG_CNTL
);
1352 tv_pre_dac_mux_cntl
= RREG32(RADEON_TV_PRE_DAC_MUX_CNTL
);
1354 tmp
= dac_cntl2
& ~RADEON_DAC2_DAC2_CLK_SEL
;
1355 WREG32(RADEON_DAC_CNTL2
, tmp
);
1357 tmp
= tv_master_cntl
| RADEON_TV_ON
;
1358 tmp
&= ~(RADEON_TV_ASYNC_RST
|
1359 RADEON_RESTART_PHASE_FIX
|
1360 RADEON_CRT_FIFO_CE_EN
|
1361 RADEON_TV_FIFO_CE_EN
|
1362 RADEON_RE_SYNC_NOW_SEL_MASK
);
1363 tmp
|= RADEON_TV_FIFO_ASYNC_RST
| RADEON_CRT_ASYNC_RST
;
1364 WREG32(RADEON_TV_MASTER_CNTL
, tmp
);
1366 tmp
= RADEON_TV_DAC_NBLANK
| RADEON_TV_DAC_NHOLD
|
1367 RADEON_TV_MONITOR_DETECT_EN
| RADEON_TV_DAC_STD_NTSC
|
1368 (8 << RADEON_TV_DAC_BGADJ_SHIFT
);
1370 if (config_cntl
& RADEON_CFG_ATI_REV_ID_MASK
)
1371 tmp
|= (4 << RADEON_TV_DAC_DACADJ_SHIFT
);
1373 tmp
|= (8 << RADEON_TV_DAC_DACADJ_SHIFT
);
1374 WREG32(RADEON_TV_DAC_CNTL
, tmp
);
1376 tmp
= RADEON_C_GRN_EN
| RADEON_CMP_BLU_EN
|
1377 RADEON_RED_MX_FORCE_DAC_DATA
|
1378 RADEON_GRN_MX_FORCE_DAC_DATA
|
1379 RADEON_BLU_MX_FORCE_DAC_DATA
|
1380 (0x109 << RADEON_TV_FORCE_DAC_DATA_SHIFT
);
1381 WREG32(RADEON_TV_PRE_DAC_MUX_CNTL
, tmp
);
1384 tmp
= RREG32(RADEON_TV_DAC_CNTL
);
1385 if (tmp
& RADEON_TV_DAC_GDACDET
) {
1387 DRM_DEBUG_KMS("S-video TV connection detected\n");
1388 } else if ((tmp
& RADEON_TV_DAC_BDACDET
) != 0) {
1390 DRM_DEBUG_KMS("Composite TV connection detected\n");
1393 WREG32(RADEON_TV_PRE_DAC_MUX_CNTL
, tv_pre_dac_mux_cntl
);
1394 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1395 WREG32(RADEON_TV_MASTER_CNTL
, tv_master_cntl
);
1396 WREG32(RADEON_DAC_CNTL2
, dac_cntl2
);
1400 static enum drm_connector_status
radeon_legacy_tv_dac_detect(struct drm_encoder
*encoder
,
1401 struct drm_connector
*connector
)
1403 struct drm_device
*dev
= encoder
->dev
;
1404 struct radeon_device
*rdev
= dev
->dev_private
;
1405 uint32_t crtc2_gen_cntl
, tv_dac_cntl
, dac_cntl2
, dac_ext_cntl
;
1406 uint32_t disp_hw_debug
, disp_output_cntl
, gpiopad_a
, pixclks_cntl
, tmp
;
1407 enum drm_connector_status found
= connector_status_disconnected
;
1408 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1409 struct radeon_encoder_tv_dac
*tv_dac
= radeon_encoder
->enc_priv
;
1411 struct drm_crtc
*crtc
;
1413 /* find out if crtc2 is in use or if this encoder is using it */
1414 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
1415 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(crtc
);
1416 if ((radeon_crtc
->crtc_id
== 1) && crtc
->enabled
) {
1417 if (encoder
->crtc
!= crtc
) {
1418 return connector_status_disconnected
;
1423 if (connector
->connector_type
== DRM_MODE_CONNECTOR_SVIDEO
||
1424 connector
->connector_type
== DRM_MODE_CONNECTOR_Composite
||
1425 connector
->connector_type
== DRM_MODE_CONNECTOR_9PinDIN
) {
1428 if (radeon_encoder
->active_device
&& !(radeon_encoder
->active_device
& ATOM_DEVICE_TV_SUPPORT
))
1429 return connector_status_disconnected
;
1431 tv_detect
= radeon_legacy_tv_detect(encoder
, connector
);
1432 if (tv_detect
&& tv_dac
)
1433 found
= connector_status_connected
;
1437 /* don't probe if the encoder is being used for something else not CRT related */
1438 if (radeon_encoder
->active_device
&& !(radeon_encoder
->active_device
& ATOM_DEVICE_CRT_SUPPORT
)) {
1439 DRM_INFO("not detecting due to %08x\n", radeon_encoder
->active_device
);
1440 return connector_status_disconnected
;
1443 /* save the regs we need */
1444 pixclks_cntl
= RREG32_PLL(RADEON_PIXCLKS_CNTL
);
1445 gpiopad_a
= ASIC_IS_R300(rdev
) ? RREG32(RADEON_GPIOPAD_A
) : 0;
1446 disp_output_cntl
= ASIC_IS_R300(rdev
) ? RREG32(RADEON_DISP_OUTPUT_CNTL
) : 0;
1447 disp_hw_debug
= ASIC_IS_R300(rdev
) ? 0 : RREG32(RADEON_DISP_HW_DEBUG
);
1448 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1449 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1450 dac_ext_cntl
= RREG32(RADEON_DAC_EXT_CNTL
);
1451 dac_cntl2
= RREG32(RADEON_DAC_CNTL2
);
1453 tmp
= pixclks_cntl
& ~(RADEON_PIX2CLK_ALWAYS_ONb
1454 | RADEON_PIX2CLK_DAC_ALWAYS_ONb
);
1455 WREG32_PLL(RADEON_PIXCLKS_CNTL
, tmp
);
1457 if (ASIC_IS_R300(rdev
))
1458 WREG32_P(RADEON_GPIOPAD_A
, 1, ~1);
1460 tmp
= crtc2_gen_cntl
& ~RADEON_CRTC2_PIX_WIDTH_MASK
;
1461 tmp
|= RADEON_CRTC2_CRT2_ON
|
1462 (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT
);
1464 WREG32(RADEON_CRTC2_GEN_CNTL
, tmp
);
1466 if (ASIC_IS_R300(rdev
)) {
1467 tmp
= disp_output_cntl
& ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1468 tmp
|= RADEON_DISP_TVDAC_SOURCE_CRTC2
;
1469 WREG32(RADEON_DISP_OUTPUT_CNTL
, tmp
);
1471 tmp
= disp_hw_debug
& ~RADEON_CRT2_DISP1_SEL
;
1472 WREG32(RADEON_DISP_HW_DEBUG
, tmp
);
1475 tmp
= RADEON_TV_DAC_NBLANK
|
1476 RADEON_TV_DAC_NHOLD
|
1477 RADEON_TV_MONITOR_DETECT_EN
|
1478 RADEON_TV_DAC_STD_PS2
;
1480 WREG32(RADEON_TV_DAC_CNTL
, tmp
);
1482 tmp
= RADEON_DAC2_FORCE_BLANK_OFF_EN
|
1483 RADEON_DAC2_FORCE_DATA_EN
;
1486 tmp
|= RADEON_DAC_FORCE_DATA_SEL_RGB
;
1488 tmp
|= RADEON_DAC_FORCE_DATA_SEL_G
;
1490 if (ASIC_IS_R300(rdev
))
1491 tmp
|= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT
);
1493 tmp
|= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT
);
1495 WREG32(RADEON_DAC_EXT_CNTL
, tmp
);
1497 tmp
= dac_cntl2
| RADEON_DAC2_DAC2_CLK_SEL
| RADEON_DAC2_CMP_EN
;
1498 WREG32(RADEON_DAC_CNTL2
, tmp
);
1502 if (ASIC_IS_R300(rdev
)) {
1503 if (RREG32(RADEON_DAC_CNTL2
) & RADEON_DAC2_CMP_OUT_B
)
1504 found
= connector_status_connected
;
1506 if (RREG32(RADEON_DAC_CNTL2
) & RADEON_DAC2_CMP_OUTPUT
)
1507 found
= connector_status_connected
;
1510 /* restore regs we used */
1511 WREG32(RADEON_DAC_CNTL2
, dac_cntl2
);
1512 WREG32(RADEON_DAC_EXT_CNTL
, dac_ext_cntl
);
1513 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1514 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1516 if (ASIC_IS_R300(rdev
)) {
1517 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1518 WREG32_P(RADEON_GPIOPAD_A
, gpiopad_a
, ~1);
1520 WREG32(RADEON_DISP_HW_DEBUG
, disp_hw_debug
);
1522 WREG32_PLL(RADEON_PIXCLKS_CNTL
, pixclks_cntl
);
1528 static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs
= {
1529 .dpms
= radeon_legacy_tv_dac_dpms
,
1530 .mode_fixup
= radeon_legacy_mode_fixup
,
1531 .prepare
= radeon_legacy_tv_dac_prepare
,
1532 .mode_set
= radeon_legacy_tv_dac_mode_set
,
1533 .commit
= radeon_legacy_tv_dac_commit
,
1534 .detect
= radeon_legacy_tv_dac_detect
,
1535 .disable
= radeon_legacy_encoder_disable
,
1539 static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs
= {
1540 .destroy
= radeon_enc_destroy
,
1544 static struct radeon_encoder_int_tmds
*radeon_legacy_get_tmds_info(struct radeon_encoder
*encoder
)
1546 struct drm_device
*dev
= encoder
->base
.dev
;
1547 struct radeon_device
*rdev
= dev
->dev_private
;
1548 struct radeon_encoder_int_tmds
*tmds
= NULL
;
1551 tmds
= kzalloc(sizeof(struct radeon_encoder_int_tmds
), GFP_KERNEL
);
1556 if (rdev
->is_atom_bios
)
1557 ret
= radeon_atombios_get_tmds_info(encoder
, tmds
);
1559 ret
= radeon_legacy_get_tmds_info_from_combios(encoder
, tmds
);
1562 radeon_legacy_get_tmds_info_from_table(encoder
, tmds
);
1567 static struct radeon_encoder_ext_tmds
*radeon_legacy_get_ext_tmds_info(struct radeon_encoder
*encoder
)
1569 struct drm_device
*dev
= encoder
->base
.dev
;
1570 struct radeon_device
*rdev
= dev
->dev_private
;
1571 struct radeon_encoder_ext_tmds
*tmds
= NULL
;
1574 if (rdev
->is_atom_bios
)
1577 tmds
= kzalloc(sizeof(struct radeon_encoder_ext_tmds
), GFP_KERNEL
);
1582 ret
= radeon_legacy_get_ext_tmds_info_from_combios(encoder
, tmds
);
1585 radeon_legacy_get_ext_tmds_info_from_table(encoder
, tmds
);
1591 radeon_add_legacy_encoder(struct drm_device
*dev
, uint32_t encoder_enum
, uint32_t supported_device
)
1593 struct radeon_device
*rdev
= dev
->dev_private
;
1594 struct drm_encoder
*encoder
;
1595 struct radeon_encoder
*radeon_encoder
;
1597 /* see if we already added it */
1598 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
1599 radeon_encoder
= to_radeon_encoder(encoder
);
1600 if (radeon_encoder
->encoder_enum
== encoder_enum
) {
1601 radeon_encoder
->devices
|= supported_device
;
1608 radeon_encoder
= kzalloc(sizeof(struct radeon_encoder
), GFP_KERNEL
);
1609 if (!radeon_encoder
)
1612 encoder
= &radeon_encoder
->base
;
1613 if (rdev
->flags
& RADEON_SINGLE_CRTC
)
1614 encoder
->possible_crtcs
= 0x1;
1616 encoder
->possible_crtcs
= 0x3;
1618 radeon_encoder
->enc_priv
= NULL
;
1620 radeon_encoder
->encoder_enum
= encoder_enum
;
1621 radeon_encoder
->encoder_id
= (encoder_enum
& OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
1622 radeon_encoder
->devices
= supported_device
;
1623 radeon_encoder
->rmx_type
= RMX_OFF
;
1625 switch (radeon_encoder
->encoder_id
) {
1626 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1627 encoder
->possible_crtcs
= 0x1;
1628 drm_encoder_init(dev
, encoder
, &radeon_legacy_lvds_enc_funcs
, DRM_MODE_ENCODER_LVDS
);
1629 drm_encoder_helper_add(encoder
, &radeon_legacy_lvds_helper_funcs
);
1630 if (rdev
->is_atom_bios
)
1631 radeon_encoder
->enc_priv
= radeon_atombios_get_lvds_info(radeon_encoder
);
1633 radeon_encoder
->enc_priv
= radeon_combios_get_lvds_info(radeon_encoder
);
1634 radeon_encoder
->rmx_type
= RMX_FULL
;
1636 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1637 drm_encoder_init(dev
, encoder
, &radeon_legacy_tmds_int_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
1638 drm_encoder_helper_add(encoder
, &radeon_legacy_tmds_int_helper_funcs
);
1639 radeon_encoder
->enc_priv
= radeon_legacy_get_tmds_info(radeon_encoder
);
1641 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1642 drm_encoder_init(dev
, encoder
, &radeon_legacy_primary_dac_enc_funcs
, DRM_MODE_ENCODER_DAC
);
1643 drm_encoder_helper_add(encoder
, &radeon_legacy_primary_dac_helper_funcs
);
1644 if (rdev
->is_atom_bios
)
1645 radeon_encoder
->enc_priv
= radeon_atombios_get_primary_dac_info(radeon_encoder
);
1647 radeon_encoder
->enc_priv
= radeon_combios_get_primary_dac_info(radeon_encoder
);
1649 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1650 drm_encoder_init(dev
, encoder
, &radeon_legacy_tv_dac_enc_funcs
, DRM_MODE_ENCODER_TVDAC
);
1651 drm_encoder_helper_add(encoder
, &radeon_legacy_tv_dac_helper_funcs
);
1652 if (rdev
->is_atom_bios
)
1653 radeon_encoder
->enc_priv
= radeon_atombios_get_tv_dac_info(radeon_encoder
);
1655 radeon_encoder
->enc_priv
= radeon_combios_get_tv_dac_info(radeon_encoder
);
1657 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1658 drm_encoder_init(dev
, encoder
, &radeon_legacy_tmds_ext_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
1659 drm_encoder_helper_add(encoder
, &radeon_legacy_tmds_ext_helper_funcs
);
1660 if (!rdev
->is_atom_bios
)
1661 radeon_encoder
->enc_priv
= radeon_legacy_get_ext_tmds_info(radeon_encoder
);