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 <linux/backlight.h>
28 #include <linux/pci.h>
30 #include <drm/drm_crtc_helper.h>
31 #include <drm/drm_device.h>
32 #include <drm/drm_file.h>
33 #include <drm/drm_util.h>
34 #include <drm/radeon_drm.h>
37 #include "radeon_asic.h"
39 #ifdef CONFIG_PMAC_BACKLIGHT
40 #include <asm/backlight.h>
43 static void radeon_legacy_encoder_disable(struct drm_encoder
*encoder
)
45 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
46 const struct drm_encoder_helper_funcs
*encoder_funcs
;
48 encoder_funcs
= encoder
->helper_private
;
49 encoder_funcs
->dpms(encoder
, DRM_MODE_DPMS_OFF
);
50 radeon_encoder
->active_device
= 0;
53 static void radeon_legacy_lvds_update(struct drm_encoder
*encoder
, int mode
)
55 struct drm_device
*dev
= encoder
->dev
;
56 struct radeon_device
*rdev
= dev
->dev_private
;
57 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
58 uint32_t lvds_gen_cntl
, lvds_pll_cntl
, pixclks_cntl
, disp_pwr_man
;
59 int panel_pwr_delay
= 2000;
61 uint8_t backlight_level
;
64 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
65 backlight_level
= (lvds_gen_cntl
>> RADEON_LVDS_BL_MOD_LEVEL_SHIFT
) & 0xff;
67 if (radeon_encoder
->enc_priv
) {
68 if (rdev
->is_atom_bios
) {
69 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
70 panel_pwr_delay
= lvds
->panel_pwr_delay
;
72 backlight_level
= lvds
->backlight_level
;
74 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
75 panel_pwr_delay
= lvds
->panel_pwr_delay
;
77 backlight_level
= lvds
->backlight_level
;
81 /* macs (and possibly some x86 oem systems?) wire up LVDS strangely
82 * Taken from radeonfb.
84 if ((rdev
->mode_info
.connector_table
== CT_IBOOK
) ||
85 (rdev
->mode_info
.connector_table
== CT_POWERBOOK_EXTERNAL
) ||
86 (rdev
->mode_info
.connector_table
== CT_POWERBOOK_INTERNAL
) ||
87 (rdev
->mode_info
.connector_table
== CT_POWERBOOK_VGA
))
91 case DRM_MODE_DPMS_ON
:
92 disp_pwr_man
= RREG32(RADEON_DISP_PWR_MAN
);
93 disp_pwr_man
|= RADEON_AUTO_PWRUP_EN
;
94 WREG32(RADEON_DISP_PWR_MAN
, disp_pwr_man
);
95 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
96 lvds_pll_cntl
|= RADEON_LVDS_PLL_EN
;
97 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
100 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
101 lvds_pll_cntl
&= ~RADEON_LVDS_PLL_RESET
;
102 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
104 lvds_gen_cntl
&= ~(RADEON_LVDS_DISPLAY_DIS
|
105 RADEON_LVDS_BL_MOD_LEVEL_MASK
);
106 lvds_gen_cntl
|= (RADEON_LVDS_ON
| RADEON_LVDS_EN
|
107 RADEON_LVDS_DIGON
| RADEON_LVDS_BLON
|
108 (backlight_level
<< RADEON_LVDS_BL_MOD_LEVEL_SHIFT
));
110 lvds_gen_cntl
|= RADEON_LVDS_BL_MOD_EN
;
111 mdelay(panel_pwr_delay
);
112 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
114 case DRM_MODE_DPMS_STANDBY
:
115 case DRM_MODE_DPMS_SUSPEND
:
116 case DRM_MODE_DPMS_OFF
:
117 pixclks_cntl
= RREG32_PLL(RADEON_PIXCLKS_CNTL
);
118 WREG32_PLL_P(RADEON_PIXCLKS_CNTL
, 0, ~RADEON_PIXCLK_LVDS_ALWAYS_ONb
);
119 lvds_gen_cntl
|= RADEON_LVDS_DISPLAY_DIS
;
121 lvds_gen_cntl
&= ~RADEON_LVDS_BL_MOD_EN
;
122 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
123 lvds_gen_cntl
&= ~(RADEON_LVDS_ON
| RADEON_LVDS_EN
);
125 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
126 lvds_gen_cntl
&= ~(RADEON_LVDS_ON
| RADEON_LVDS_BLON
| RADEON_LVDS_EN
| RADEON_LVDS_DIGON
);
128 mdelay(panel_pwr_delay
);
129 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
130 WREG32_PLL(RADEON_PIXCLKS_CNTL
, pixclks_cntl
);
131 mdelay(panel_pwr_delay
);
135 if (rdev
->is_atom_bios
)
136 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
138 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
142 static void radeon_legacy_lvds_dpms(struct drm_encoder
*encoder
, int mode
)
144 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
145 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
148 if (radeon_encoder
->enc_priv
) {
149 if (rdev
->is_atom_bios
) {
150 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
151 lvds
->dpms_mode
= mode
;
153 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
154 lvds
->dpms_mode
= mode
;
158 radeon_legacy_lvds_update(encoder
, mode
);
161 static void radeon_legacy_lvds_prepare(struct drm_encoder
*encoder
)
163 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
165 if (rdev
->is_atom_bios
)
166 radeon_atom_output_lock(encoder
, true);
168 radeon_combios_output_lock(encoder
, true);
169 radeon_legacy_lvds_dpms(encoder
, DRM_MODE_DPMS_OFF
);
172 static void radeon_legacy_lvds_commit(struct drm_encoder
*encoder
)
174 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
176 radeon_legacy_lvds_dpms(encoder
, DRM_MODE_DPMS_ON
);
177 if (rdev
->is_atom_bios
)
178 radeon_atom_output_lock(encoder
, false);
180 radeon_combios_output_lock(encoder
, false);
183 static void radeon_legacy_lvds_mode_set(struct drm_encoder
*encoder
,
184 struct drm_display_mode
*mode
,
185 struct drm_display_mode
*adjusted_mode
)
187 struct drm_device
*dev
= encoder
->dev
;
188 struct radeon_device
*rdev
= dev
->dev_private
;
189 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
190 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
191 uint32_t lvds_pll_cntl
, lvds_gen_cntl
, lvds_ss_gen_cntl
;
195 lvds_pll_cntl
= RREG32(RADEON_LVDS_PLL_CNTL
);
196 lvds_pll_cntl
&= ~RADEON_LVDS_PLL_EN
;
198 lvds_ss_gen_cntl
= RREG32(RADEON_LVDS_SS_GEN_CNTL
);
199 if (rdev
->is_atom_bios
) {
200 /* LVDS_GEN_CNTL parameters are computed in LVDSEncoderControl
201 * need to call that on resume to set up the reg properly.
203 radeon_encoder
->pixel_clock
= adjusted_mode
->clock
;
204 atombios_digital_setup(encoder
, PANEL_ENCODER_ACTION_ENABLE
);
205 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
207 struct radeon_encoder_lvds
*lvds
= (struct radeon_encoder_lvds
*)radeon_encoder
->enc_priv
;
209 DRM_DEBUG_KMS("bios LVDS_GEN_CNTL: 0x%x\n", lvds
->lvds_gen_cntl
);
210 lvds_gen_cntl
= lvds
->lvds_gen_cntl
;
211 lvds_ss_gen_cntl
&= ~((0xf << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT
) |
212 (0xf << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT
));
213 lvds_ss_gen_cntl
|= ((lvds
->panel_digon_delay
<< RADEON_LVDS_PWRSEQ_DELAY1_SHIFT
) |
214 (lvds
->panel_blon_delay
<< RADEON_LVDS_PWRSEQ_DELAY2_SHIFT
));
216 lvds_gen_cntl
= RREG32(RADEON_LVDS_GEN_CNTL
);
218 lvds_gen_cntl
|= RADEON_LVDS_DISPLAY_DIS
;
219 lvds_gen_cntl
&= ~(RADEON_LVDS_ON
|
224 if (ASIC_IS_R300(rdev
))
225 lvds_pll_cntl
&= ~(R300_LVDS_SRC_SEL_MASK
);
227 if (radeon_crtc
->crtc_id
== 0) {
228 if (ASIC_IS_R300(rdev
)) {
229 if (radeon_encoder
->rmx_type
!= RMX_OFF
)
230 lvds_pll_cntl
|= R300_LVDS_SRC_SEL_RMX
;
232 lvds_gen_cntl
&= ~RADEON_LVDS_SEL_CRTC2
;
234 if (ASIC_IS_R300(rdev
))
235 lvds_pll_cntl
|= R300_LVDS_SRC_SEL_CRTC2
;
237 lvds_gen_cntl
|= RADEON_LVDS_SEL_CRTC2
;
240 WREG32(RADEON_LVDS_GEN_CNTL
, lvds_gen_cntl
);
241 WREG32(RADEON_LVDS_PLL_CNTL
, lvds_pll_cntl
);
242 WREG32(RADEON_LVDS_SS_GEN_CNTL
, lvds_ss_gen_cntl
);
244 if (rdev
->family
== CHIP_RV410
)
245 WREG32(RADEON_CLOCK_CNTL_INDEX
, 0);
247 if (rdev
->is_atom_bios
)
248 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
250 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
253 static bool radeon_legacy_mode_fixup(struct drm_encoder
*encoder
,
254 const struct drm_display_mode
*mode
,
255 struct drm_display_mode
*adjusted_mode
)
257 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
259 /* set the active encoder to connector routing */
260 radeon_encoder_set_active_device(encoder
);
261 drm_mode_set_crtcinfo(adjusted_mode
, 0);
263 /* get the native mode for LVDS */
264 if (radeon_encoder
->active_device
& (ATOM_DEVICE_LCD_SUPPORT
))
265 radeon_panel_mode_fixup(encoder
, adjusted_mode
);
270 static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs
= {
271 .dpms
= radeon_legacy_lvds_dpms
,
272 .mode_fixup
= radeon_legacy_mode_fixup
,
273 .prepare
= radeon_legacy_lvds_prepare
,
274 .mode_set
= radeon_legacy_lvds_mode_set
,
275 .commit
= radeon_legacy_lvds_commit
,
276 .disable
= radeon_legacy_encoder_disable
,
280 radeon_legacy_get_backlight_level(struct radeon_encoder
*radeon_encoder
)
282 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
283 struct radeon_device
*rdev
= dev
->dev_private
;
286 backlight_level
= (RREG32(RADEON_LVDS_GEN_CNTL
) >>
287 RADEON_LVDS_BL_MOD_LEVEL_SHIFT
) & 0xff;
289 return backlight_level
;
293 radeon_legacy_set_backlight_level(struct radeon_encoder
*radeon_encoder
, u8 level
)
295 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
296 struct radeon_device
*rdev
= dev
->dev_private
;
297 int dpms_mode
= DRM_MODE_DPMS_ON
;
299 if (radeon_encoder
->enc_priv
) {
300 if (rdev
->is_atom_bios
) {
301 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
302 if (lvds
->backlight_level
> 0)
303 dpms_mode
= lvds
->dpms_mode
;
305 dpms_mode
= DRM_MODE_DPMS_OFF
;
306 lvds
->backlight_level
= level
;
308 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
309 if (lvds
->backlight_level
> 0)
310 dpms_mode
= lvds
->dpms_mode
;
312 dpms_mode
= DRM_MODE_DPMS_OFF
;
313 lvds
->backlight_level
= level
;
317 radeon_legacy_lvds_update(&radeon_encoder
->base
, dpms_mode
);
320 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
322 static uint8_t radeon_legacy_lvds_level(struct backlight_device
*bd
)
324 struct radeon_backlight_privdata
*pdata
= bl_get_data(bd
);
327 /* Convert brightness to hardware level */
328 if (bd
->props
.brightness
< 0)
330 else if (bd
->props
.brightness
> RADEON_MAX_BL_LEVEL
)
331 level
= RADEON_MAX_BL_LEVEL
;
333 level
= bd
->props
.brightness
;
336 level
= RADEON_MAX_BL_LEVEL
- level
;
341 static int radeon_legacy_backlight_update_status(struct backlight_device
*bd
)
343 struct radeon_backlight_privdata
*pdata
= bl_get_data(bd
);
344 struct radeon_encoder
*radeon_encoder
= pdata
->encoder
;
346 radeon_legacy_set_backlight_level(radeon_encoder
,
347 radeon_legacy_lvds_level(bd
));
352 static int radeon_legacy_backlight_get_brightness(struct backlight_device
*bd
)
354 struct radeon_backlight_privdata
*pdata
= bl_get_data(bd
);
355 struct radeon_encoder
*radeon_encoder
= pdata
->encoder
;
356 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
357 struct radeon_device
*rdev
= dev
->dev_private
;
358 uint8_t backlight_level
;
360 backlight_level
= (RREG32(RADEON_LVDS_GEN_CNTL
) >>
361 RADEON_LVDS_BL_MOD_LEVEL_SHIFT
) & 0xff;
363 return pdata
->negative
? RADEON_MAX_BL_LEVEL
- backlight_level
: backlight_level
;
366 static const struct backlight_ops radeon_backlight_ops
= {
367 .get_brightness
= radeon_legacy_backlight_get_brightness
,
368 .update_status
= radeon_legacy_backlight_update_status
,
371 void radeon_legacy_backlight_init(struct radeon_encoder
*radeon_encoder
,
372 struct drm_connector
*drm_connector
)
374 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
375 struct radeon_device
*rdev
= dev
->dev_private
;
376 struct backlight_device
*bd
;
377 struct backlight_properties props
;
378 struct radeon_backlight_privdata
*pdata
;
379 uint8_t backlight_level
;
382 if (!radeon_encoder
->enc_priv
)
385 #ifdef CONFIG_PMAC_BACKLIGHT
386 if (!pmac_has_backlight_type("ati") &&
387 !pmac_has_backlight_type("mnca"))
391 pdata
= kmalloc(sizeof(struct radeon_backlight_privdata
), GFP_KERNEL
);
393 DRM_ERROR("Memory allocation failed\n");
397 memset(&props
, 0, sizeof(props
));
398 props
.max_brightness
= RADEON_MAX_BL_LEVEL
;
399 props
.type
= BACKLIGHT_RAW
;
400 snprintf(bl_name
, sizeof(bl_name
),
401 "radeon_bl%d", dev
->primary
->index
);
402 bd
= backlight_device_register(bl_name
, drm_connector
->kdev
,
403 pdata
, &radeon_backlight_ops
, &props
);
405 DRM_ERROR("Backlight registration failed\n");
409 pdata
->encoder
= radeon_encoder
;
411 backlight_level
= (RREG32(RADEON_LVDS_GEN_CNTL
) >>
412 RADEON_LVDS_BL_MOD_LEVEL_SHIFT
) & 0xff;
414 /* First, try to detect backlight level sense based on the assumption
415 * that firmware set it up at full brightness
417 if (backlight_level
== 0)
418 pdata
->negative
= true;
419 else if (backlight_level
== 0xff)
420 pdata
->negative
= false;
422 /* XXX hack... maybe some day we can figure out in what direction
423 * backlight should work on a given panel?
425 pdata
->negative
= (rdev
->family
!= CHIP_RV200
&&
426 rdev
->family
!= CHIP_RV250
&&
427 rdev
->family
!= CHIP_RV280
&&
428 rdev
->family
!= CHIP_RV350
);
430 #ifdef CONFIG_PMAC_BACKLIGHT
431 pdata
->negative
= (pdata
->negative
||
432 of_machine_is_compatible("PowerBook4,3") ||
433 of_machine_is_compatible("PowerBook6,3") ||
434 of_machine_is_compatible("PowerBook6,5"));
438 if (rdev
->is_atom_bios
) {
439 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
442 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
446 bd
->props
.brightness
= radeon_legacy_backlight_get_brightness(bd
);
447 bd
->props
.power
= FB_BLANK_UNBLANK
;
448 backlight_update_status(bd
);
450 DRM_INFO("radeon legacy LVDS backlight initialized\n");
451 rdev
->mode_info
.bl_encoder
= radeon_encoder
;
460 static void radeon_legacy_backlight_exit(struct radeon_encoder
*radeon_encoder
)
462 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
463 struct radeon_device
*rdev
= dev
->dev_private
;
464 struct backlight_device
*bd
= NULL
;
466 if (!radeon_encoder
->enc_priv
)
469 if (rdev
->is_atom_bios
) {
470 struct radeon_encoder_atom_dig
*lvds
= radeon_encoder
->enc_priv
;
474 struct radeon_encoder_lvds
*lvds
= radeon_encoder
->enc_priv
;
480 struct radeon_backlight_privdata
*pdata
;
482 pdata
= bl_get_data(bd
);
483 backlight_device_unregister(bd
);
486 DRM_INFO("radeon legacy LVDS backlight unloaded\n");
490 #else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */
492 void radeon_legacy_backlight_init(struct radeon_encoder
*encoder
)
496 static void radeon_legacy_backlight_exit(struct radeon_encoder
*encoder
)
503 static void radeon_lvds_enc_destroy(struct drm_encoder
*encoder
)
505 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
507 if (radeon_encoder
->enc_priv
) {
508 radeon_legacy_backlight_exit(radeon_encoder
);
509 kfree(radeon_encoder
->enc_priv
);
511 drm_encoder_cleanup(encoder
);
512 kfree(radeon_encoder
);
515 static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs
= {
516 .destroy
= radeon_lvds_enc_destroy
,
519 static void radeon_legacy_primary_dac_dpms(struct drm_encoder
*encoder
, int mode
)
521 struct drm_device
*dev
= encoder
->dev
;
522 struct radeon_device
*rdev
= dev
->dev_private
;
523 uint32_t crtc_ext_cntl
= RREG32(RADEON_CRTC_EXT_CNTL
);
524 uint32_t dac_cntl
= RREG32(RADEON_DAC_CNTL
);
525 uint32_t dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
530 case DRM_MODE_DPMS_ON
:
531 crtc_ext_cntl
|= RADEON_CRTC_CRT_ON
;
532 dac_cntl
&= ~RADEON_DAC_PDWN
;
533 dac_macro_cntl
&= ~(RADEON_DAC_PDWN_R
|
537 case DRM_MODE_DPMS_STANDBY
:
538 case DRM_MODE_DPMS_SUSPEND
:
539 case DRM_MODE_DPMS_OFF
:
540 crtc_ext_cntl
&= ~RADEON_CRTC_CRT_ON
;
541 dac_cntl
|= RADEON_DAC_PDWN
;
542 dac_macro_cntl
|= (RADEON_DAC_PDWN_R
|
548 /* handled in radeon_crtc_dpms() */
549 if (!(rdev
->flags
& RADEON_SINGLE_CRTC
))
550 WREG32(RADEON_CRTC_EXT_CNTL
, crtc_ext_cntl
);
551 WREG32(RADEON_DAC_CNTL
, dac_cntl
);
552 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
554 if (rdev
->is_atom_bios
)
555 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
557 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
561 static void radeon_legacy_primary_dac_prepare(struct drm_encoder
*encoder
)
563 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
565 if (rdev
->is_atom_bios
)
566 radeon_atom_output_lock(encoder
, true);
568 radeon_combios_output_lock(encoder
, true);
569 radeon_legacy_primary_dac_dpms(encoder
, DRM_MODE_DPMS_OFF
);
572 static void radeon_legacy_primary_dac_commit(struct drm_encoder
*encoder
)
574 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
576 radeon_legacy_primary_dac_dpms(encoder
, DRM_MODE_DPMS_ON
);
578 if (rdev
->is_atom_bios
)
579 radeon_atom_output_lock(encoder
, false);
581 radeon_combios_output_lock(encoder
, false);
584 static void radeon_legacy_primary_dac_mode_set(struct drm_encoder
*encoder
,
585 struct drm_display_mode
*mode
,
586 struct drm_display_mode
*adjusted_mode
)
588 struct drm_device
*dev
= encoder
->dev
;
589 struct radeon_device
*rdev
= dev
->dev_private
;
590 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
591 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
592 uint32_t disp_output_cntl
, dac_cntl
, dac2_cntl
, dac_macro_cntl
;
596 if (radeon_crtc
->crtc_id
== 0) {
597 if (rdev
->family
== CHIP_R200
|| ASIC_IS_R300(rdev
)) {
598 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
) &
599 ~(RADEON_DISP_DAC_SOURCE_MASK
);
600 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
602 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) & ~(RADEON_DAC2_DAC_CLK_SEL
);
603 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
606 if (rdev
->family
== CHIP_R200
|| ASIC_IS_R300(rdev
)) {
607 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
) &
608 ~(RADEON_DISP_DAC_SOURCE_MASK
);
609 disp_output_cntl
|= RADEON_DISP_DAC_SOURCE_CRTC2
;
610 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
612 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) | RADEON_DAC2_DAC_CLK_SEL
;
613 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
617 dac_cntl
= (RADEON_DAC_MASK_ALL
|
618 RADEON_DAC_VGA_ADR_EN
|
622 WREG32_P(RADEON_DAC_CNTL
,
624 RADEON_DAC_RANGE_CNTL
|
625 RADEON_DAC_BLANKING
);
627 if (radeon_encoder
->enc_priv
) {
628 struct radeon_encoder_primary_dac
*p_dac
= (struct radeon_encoder_primary_dac
*)radeon_encoder
->enc_priv
;
629 dac_macro_cntl
= p_dac
->ps2_pdac_adj
;
631 dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
632 dac_macro_cntl
|= RADEON_DAC_PDWN_R
| RADEON_DAC_PDWN_G
| RADEON_DAC_PDWN_B
;
633 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
635 if (rdev
->is_atom_bios
)
636 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
638 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
641 static enum drm_connector_status
radeon_legacy_primary_dac_detect(struct drm_encoder
*encoder
,
642 struct drm_connector
*connector
)
644 struct drm_device
*dev
= encoder
->dev
;
645 struct radeon_device
*rdev
= dev
->dev_private
;
646 uint32_t vclk_ecp_cntl
, crtc_ext_cntl
;
647 uint32_t dac_ext_cntl
, dac_cntl
, dac_macro_cntl
, tmp
;
648 enum drm_connector_status found
= connector_status_disconnected
;
651 /* just don't bother on RN50 those chip are often connected to remoting
652 * console hw and often we get failure to load detect those. So to make
653 * everyone happy report the encoder as always connected.
655 if (ASIC_IS_RN50(rdev
)) {
656 return connector_status_connected
;
659 /* save the regs we need */
660 vclk_ecp_cntl
= RREG32_PLL(RADEON_VCLK_ECP_CNTL
);
661 crtc_ext_cntl
= RREG32(RADEON_CRTC_EXT_CNTL
);
662 dac_ext_cntl
= RREG32(RADEON_DAC_EXT_CNTL
);
663 dac_cntl
= RREG32(RADEON_DAC_CNTL
);
664 dac_macro_cntl
= RREG32(RADEON_DAC_MACRO_CNTL
);
666 tmp
= vclk_ecp_cntl
&
667 ~(RADEON_PIXCLK_ALWAYS_ONb
| RADEON_PIXCLK_DAC_ALWAYS_ONb
);
668 WREG32_PLL(RADEON_VCLK_ECP_CNTL
, tmp
);
670 tmp
= crtc_ext_cntl
| RADEON_CRTC_CRT_ON
;
671 WREG32(RADEON_CRTC_EXT_CNTL
, tmp
);
673 tmp
= RADEON_DAC_FORCE_BLANK_OFF_EN
|
674 RADEON_DAC_FORCE_DATA_EN
;
677 tmp
|= RADEON_DAC_FORCE_DATA_SEL_RGB
;
679 tmp
|= RADEON_DAC_FORCE_DATA_SEL_G
;
681 if (ASIC_IS_R300(rdev
))
682 tmp
|= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT
);
683 else if (ASIC_IS_RV100(rdev
))
684 tmp
|= (0x1ac << RADEON_DAC_FORCE_DATA_SHIFT
);
686 tmp
|= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT
);
688 WREG32(RADEON_DAC_EXT_CNTL
, tmp
);
690 tmp
= dac_cntl
& ~(RADEON_DAC_RANGE_CNTL_MASK
| RADEON_DAC_PDWN
);
691 tmp
|= RADEON_DAC_RANGE_CNTL_PS2
| RADEON_DAC_CMP_EN
;
692 WREG32(RADEON_DAC_CNTL
, tmp
);
694 tmp
= dac_macro_cntl
;
695 tmp
&= ~(RADEON_DAC_PDWN_R
|
699 WREG32(RADEON_DAC_MACRO_CNTL
, tmp
);
703 if (RREG32(RADEON_DAC_CNTL
) & RADEON_DAC_CMP_OUTPUT
)
704 found
= connector_status_connected
;
706 /* restore the regs we used */
707 WREG32(RADEON_DAC_CNTL
, dac_cntl
);
708 WREG32(RADEON_DAC_MACRO_CNTL
, dac_macro_cntl
);
709 WREG32(RADEON_DAC_EXT_CNTL
, dac_ext_cntl
);
710 WREG32(RADEON_CRTC_EXT_CNTL
, crtc_ext_cntl
);
711 WREG32_PLL(RADEON_VCLK_ECP_CNTL
, vclk_ecp_cntl
);
716 static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs
= {
717 .dpms
= radeon_legacy_primary_dac_dpms
,
718 .mode_fixup
= radeon_legacy_mode_fixup
,
719 .prepare
= radeon_legacy_primary_dac_prepare
,
720 .mode_set
= radeon_legacy_primary_dac_mode_set
,
721 .commit
= radeon_legacy_primary_dac_commit
,
722 .detect
= radeon_legacy_primary_dac_detect
,
723 .disable
= radeon_legacy_encoder_disable
,
727 static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs
= {
728 .destroy
= radeon_enc_destroy
,
731 static void radeon_legacy_tmds_int_dpms(struct drm_encoder
*encoder
, int mode
)
733 struct drm_device
*dev
= encoder
->dev
;
734 struct radeon_device
*rdev
= dev
->dev_private
;
735 uint32_t fp_gen_cntl
= RREG32(RADEON_FP_GEN_CNTL
);
739 case DRM_MODE_DPMS_ON
:
740 fp_gen_cntl
|= (RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
742 case DRM_MODE_DPMS_STANDBY
:
743 case DRM_MODE_DPMS_SUSPEND
:
744 case DRM_MODE_DPMS_OFF
:
745 fp_gen_cntl
&= ~(RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
749 WREG32(RADEON_FP_GEN_CNTL
, fp_gen_cntl
);
751 if (rdev
->is_atom_bios
)
752 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
754 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
758 static void radeon_legacy_tmds_int_prepare(struct drm_encoder
*encoder
)
760 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
762 if (rdev
->is_atom_bios
)
763 radeon_atom_output_lock(encoder
, true);
765 radeon_combios_output_lock(encoder
, true);
766 radeon_legacy_tmds_int_dpms(encoder
, DRM_MODE_DPMS_OFF
);
769 static void radeon_legacy_tmds_int_commit(struct drm_encoder
*encoder
)
771 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
773 radeon_legacy_tmds_int_dpms(encoder
, DRM_MODE_DPMS_ON
);
775 if (rdev
->is_atom_bios
)
776 radeon_atom_output_lock(encoder
, true);
778 radeon_combios_output_lock(encoder
, true);
781 static void radeon_legacy_tmds_int_mode_set(struct drm_encoder
*encoder
,
782 struct drm_display_mode
*mode
,
783 struct drm_display_mode
*adjusted_mode
)
785 struct drm_device
*dev
= encoder
->dev
;
786 struct radeon_device
*rdev
= dev
->dev_private
;
787 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
788 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
789 uint32_t tmp
, tmds_pll_cntl
, tmds_transmitter_cntl
, fp_gen_cntl
;
794 tmp
= tmds_pll_cntl
= RREG32(RADEON_TMDS_PLL_CNTL
);
796 if (rdev
->family
== CHIP_RV280
) {
797 /* bit 22 of TMDS_PLL_CNTL is read-back inverted */
799 tmds_pll_cntl
^= (1 << 22);
802 if (radeon_encoder
->enc_priv
) {
803 struct radeon_encoder_int_tmds
*tmds
= (struct radeon_encoder_int_tmds
*)radeon_encoder
->enc_priv
;
805 for (i
= 0; i
< 4; i
++) {
806 if (tmds
->tmds_pll
[i
].freq
== 0)
808 if ((uint32_t)(mode
->clock
/ 10) < tmds
->tmds_pll
[i
].freq
) {
809 tmp
= tmds
->tmds_pll
[i
].value
;
815 if (ASIC_IS_R300(rdev
) || (rdev
->family
== CHIP_RV280
)) {
816 if (tmp
& 0xfff00000)
819 tmds_pll_cntl
&= 0xfff00000;
820 tmds_pll_cntl
|= tmp
;
825 tmds_transmitter_cntl
= RREG32(RADEON_TMDS_TRANSMITTER_CNTL
) &
826 ~(RADEON_TMDS_TRANSMITTER_PLLRST
);
828 if (rdev
->family
== CHIP_R200
||
829 rdev
->family
== CHIP_R100
||
831 tmds_transmitter_cntl
&= ~(RADEON_TMDS_TRANSMITTER_PLLEN
);
832 else /* RV chips got this bit reversed */
833 tmds_transmitter_cntl
|= RADEON_TMDS_TRANSMITTER_PLLEN
;
835 fp_gen_cntl
= (RREG32(RADEON_FP_GEN_CNTL
) |
836 (RADEON_FP_CRTC_DONT_SHADOW_VPAR
|
837 RADEON_FP_CRTC_DONT_SHADOW_HEND
));
839 fp_gen_cntl
&= ~(RADEON_FP_FPON
| RADEON_FP_TMDS_EN
);
841 fp_gen_cntl
&= ~(RADEON_FP_RMX_HVSYNC_CONTROL_EN
|
842 RADEON_FP_DFP_SYNC_SEL
|
843 RADEON_FP_CRT_SYNC_SEL
|
844 RADEON_FP_CRTC_LOCK_8DOT
|
845 RADEON_FP_USE_SHADOW_EN
|
846 RADEON_FP_CRTC_USE_SHADOW_VEND
|
847 RADEON_FP_CRT_SYNC_ALT
);
849 if (1) /* FIXME rgbBits == 8 */
850 fp_gen_cntl
|= RADEON_FP_PANEL_FORMAT
; /* 24 bit format */
852 fp_gen_cntl
&= ~RADEON_FP_PANEL_FORMAT
;/* 18 bit format */
854 if (radeon_crtc
->crtc_id
== 0) {
855 if (ASIC_IS_R300(rdev
) || rdev
->family
== CHIP_R200
) {
856 fp_gen_cntl
&= ~R200_FP_SOURCE_SEL_MASK
;
857 if (radeon_encoder
->rmx_type
!= RMX_OFF
)
858 fp_gen_cntl
|= R200_FP_SOURCE_SEL_RMX
;
860 fp_gen_cntl
|= R200_FP_SOURCE_SEL_CRTC1
;
862 fp_gen_cntl
&= ~RADEON_FP_SEL_CRTC2
;
864 if (ASIC_IS_R300(rdev
) || rdev
->family
== CHIP_R200
) {
865 fp_gen_cntl
&= ~R200_FP_SOURCE_SEL_MASK
;
866 fp_gen_cntl
|= R200_FP_SOURCE_SEL_CRTC2
;
868 fp_gen_cntl
|= RADEON_FP_SEL_CRTC2
;
871 WREG32(RADEON_TMDS_PLL_CNTL
, tmds_pll_cntl
);
872 WREG32(RADEON_TMDS_TRANSMITTER_CNTL
, tmds_transmitter_cntl
);
873 WREG32(RADEON_FP_GEN_CNTL
, fp_gen_cntl
);
875 if (rdev
->is_atom_bios
)
876 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
878 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
881 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs
= {
882 .dpms
= radeon_legacy_tmds_int_dpms
,
883 .mode_fixup
= radeon_legacy_mode_fixup
,
884 .prepare
= radeon_legacy_tmds_int_prepare
,
885 .mode_set
= radeon_legacy_tmds_int_mode_set
,
886 .commit
= radeon_legacy_tmds_int_commit
,
887 .disable
= radeon_legacy_encoder_disable
,
891 static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs
= {
892 .destroy
= radeon_enc_destroy
,
895 static void radeon_legacy_tmds_ext_dpms(struct drm_encoder
*encoder
, int mode
)
897 struct drm_device
*dev
= encoder
->dev
;
898 struct radeon_device
*rdev
= dev
->dev_private
;
899 uint32_t fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
903 case DRM_MODE_DPMS_ON
:
904 fp2_gen_cntl
&= ~RADEON_FP2_BLANK_EN
;
905 fp2_gen_cntl
|= (RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
907 case DRM_MODE_DPMS_STANDBY
:
908 case DRM_MODE_DPMS_SUSPEND
:
909 case DRM_MODE_DPMS_OFF
:
910 fp2_gen_cntl
|= RADEON_FP2_BLANK_EN
;
911 fp2_gen_cntl
&= ~(RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
915 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
917 if (rdev
->is_atom_bios
)
918 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
920 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
924 static void radeon_legacy_tmds_ext_prepare(struct drm_encoder
*encoder
)
926 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
928 if (rdev
->is_atom_bios
)
929 radeon_atom_output_lock(encoder
, true);
931 radeon_combios_output_lock(encoder
, true);
932 radeon_legacy_tmds_ext_dpms(encoder
, DRM_MODE_DPMS_OFF
);
935 static void radeon_legacy_tmds_ext_commit(struct drm_encoder
*encoder
)
937 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
938 radeon_legacy_tmds_ext_dpms(encoder
, DRM_MODE_DPMS_ON
);
940 if (rdev
->is_atom_bios
)
941 radeon_atom_output_lock(encoder
, false);
943 radeon_combios_output_lock(encoder
, false);
946 static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder
*encoder
,
947 struct drm_display_mode
*mode
,
948 struct drm_display_mode
*adjusted_mode
)
950 struct drm_device
*dev
= encoder
->dev
;
951 struct radeon_device
*rdev
= dev
->dev_private
;
952 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
953 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
954 uint32_t fp2_gen_cntl
;
958 if (rdev
->is_atom_bios
) {
959 radeon_encoder
->pixel_clock
= adjusted_mode
->clock
;
960 atombios_dvo_setup(encoder
, ATOM_ENABLE
);
961 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
963 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
965 if (1) /* FIXME rgbBits == 8 */
966 fp2_gen_cntl
|= RADEON_FP2_PANEL_FORMAT
; /* 24 bit format, */
968 fp2_gen_cntl
&= ~RADEON_FP2_PANEL_FORMAT
;/* 18 bit format, */
970 fp2_gen_cntl
&= ~(RADEON_FP2_ON
|
972 RADEON_FP2_DVO_RATE_SEL_SDR
);
974 /* XXX: these are oem specific */
975 if (ASIC_IS_R300(rdev
)) {
976 if ((dev
->pdev
->device
== 0x4850) &&
977 (dev
->pdev
->subsystem_vendor
== 0x1028) &&
978 (dev
->pdev
->subsystem_device
== 0x2001)) /* Dell Inspiron 8600 */
979 fp2_gen_cntl
|= R300_FP2_DVO_CLOCK_MODE_SINGLE
;
981 fp2_gen_cntl
|= RADEON_FP2_PAD_FLOP_EN
| R300_FP2_DVO_CLOCK_MODE_SINGLE
;
983 /*if (mode->clock > 165000)
984 fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/
986 if (!radeon_combios_external_tmds_setup(encoder
))
987 radeon_external_tmds_setup(encoder
);
990 if (radeon_crtc
->crtc_id
== 0) {
991 if ((rdev
->family
== CHIP_R200
) || ASIC_IS_R300(rdev
)) {
992 fp2_gen_cntl
&= ~R200_FP2_SOURCE_SEL_MASK
;
993 if (radeon_encoder
->rmx_type
!= RMX_OFF
)
994 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_RMX
;
996 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC1
;
998 fp2_gen_cntl
&= ~RADEON_FP2_SRC_SEL_CRTC2
;
1000 if ((rdev
->family
== CHIP_R200
) || ASIC_IS_R300(rdev
)) {
1001 fp2_gen_cntl
&= ~R200_FP2_SOURCE_SEL_MASK
;
1002 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC2
;
1004 fp2_gen_cntl
|= RADEON_FP2_SRC_SEL_CRTC2
;
1007 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
1009 if (rdev
->is_atom_bios
)
1010 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1012 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1015 static void radeon_ext_tmds_enc_destroy(struct drm_encoder
*encoder
)
1017 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1018 /* don't destroy the i2c bus record here, this will be done in radeon_i2c_fini */
1019 kfree(radeon_encoder
->enc_priv
);
1020 drm_encoder_cleanup(encoder
);
1021 kfree(radeon_encoder
);
1024 static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs
= {
1025 .dpms
= radeon_legacy_tmds_ext_dpms
,
1026 .mode_fixup
= radeon_legacy_mode_fixup
,
1027 .prepare
= radeon_legacy_tmds_ext_prepare
,
1028 .mode_set
= radeon_legacy_tmds_ext_mode_set
,
1029 .commit
= radeon_legacy_tmds_ext_commit
,
1030 .disable
= radeon_legacy_encoder_disable
,
1034 static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs
= {
1035 .destroy
= radeon_ext_tmds_enc_destroy
,
1038 static void radeon_legacy_tv_dac_dpms(struct drm_encoder
*encoder
, int mode
)
1040 struct drm_device
*dev
= encoder
->dev
;
1041 struct radeon_device
*rdev
= dev
->dev_private
;
1042 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1043 uint32_t fp2_gen_cntl
= 0, crtc2_gen_cntl
= 0, tv_dac_cntl
= 0;
1044 uint32_t tv_master_cntl
= 0;
1046 DRM_DEBUG_KMS("\n");
1048 is_tv
= radeon_encoder
->active_device
& ATOM_DEVICE_TV_SUPPORT
? true : false;
1050 if (rdev
->family
== CHIP_R200
)
1051 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
1054 tv_master_cntl
= RREG32(RADEON_TV_MASTER_CNTL
);
1056 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1057 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1061 case DRM_MODE_DPMS_ON
:
1062 if (rdev
->family
== CHIP_R200
) {
1063 fp2_gen_cntl
|= (RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
1066 tv_master_cntl
|= RADEON_TV_ON
;
1068 crtc2_gen_cntl
|= RADEON_CRTC2_CRT2_ON
;
1070 if (rdev
->family
== CHIP_R420
||
1071 rdev
->family
== CHIP_R423
||
1072 rdev
->family
== CHIP_RV410
)
1073 tv_dac_cntl
&= ~(R420_TV_DAC_RDACPD
|
1074 R420_TV_DAC_GDACPD
|
1075 R420_TV_DAC_BDACPD
|
1076 RADEON_TV_DAC_BGSLEEP
);
1078 tv_dac_cntl
&= ~(RADEON_TV_DAC_RDACPD
|
1079 RADEON_TV_DAC_GDACPD
|
1080 RADEON_TV_DAC_BDACPD
|
1081 RADEON_TV_DAC_BGSLEEP
);
1084 case DRM_MODE_DPMS_STANDBY
:
1085 case DRM_MODE_DPMS_SUSPEND
:
1086 case DRM_MODE_DPMS_OFF
:
1087 if (rdev
->family
== CHIP_R200
)
1088 fp2_gen_cntl
&= ~(RADEON_FP2_ON
| RADEON_FP2_DVO_EN
);
1091 tv_master_cntl
&= ~RADEON_TV_ON
;
1093 crtc2_gen_cntl
&= ~RADEON_CRTC2_CRT2_ON
;
1095 if (rdev
->family
== CHIP_R420
||
1096 rdev
->family
== CHIP_R423
||
1097 rdev
->family
== CHIP_RV410
)
1098 tv_dac_cntl
|= (R420_TV_DAC_RDACPD
|
1099 R420_TV_DAC_GDACPD
|
1100 R420_TV_DAC_BDACPD
|
1101 RADEON_TV_DAC_BGSLEEP
);
1103 tv_dac_cntl
|= (RADEON_TV_DAC_RDACPD
|
1104 RADEON_TV_DAC_GDACPD
|
1105 RADEON_TV_DAC_BDACPD
|
1106 RADEON_TV_DAC_BGSLEEP
);
1111 if (rdev
->family
== CHIP_R200
) {
1112 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
1115 WREG32(RADEON_TV_MASTER_CNTL
, tv_master_cntl
);
1116 /* handled in radeon_crtc_dpms() */
1117 else if (!(rdev
->flags
& RADEON_SINGLE_CRTC
))
1118 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1119 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1122 if (rdev
->is_atom_bios
)
1123 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
1125 radeon_combios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
1129 static void radeon_legacy_tv_dac_prepare(struct drm_encoder
*encoder
)
1131 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
1133 if (rdev
->is_atom_bios
)
1134 radeon_atom_output_lock(encoder
, true);
1136 radeon_combios_output_lock(encoder
, true);
1137 radeon_legacy_tv_dac_dpms(encoder
, DRM_MODE_DPMS_OFF
);
1140 static void radeon_legacy_tv_dac_commit(struct drm_encoder
*encoder
)
1142 struct radeon_device
*rdev
= encoder
->dev
->dev_private
;
1144 radeon_legacy_tv_dac_dpms(encoder
, DRM_MODE_DPMS_ON
);
1146 if (rdev
->is_atom_bios
)
1147 radeon_atom_output_lock(encoder
, true);
1149 radeon_combios_output_lock(encoder
, true);
1152 static void radeon_legacy_tv_dac_mode_set(struct drm_encoder
*encoder
,
1153 struct drm_display_mode
*mode
,
1154 struct drm_display_mode
*adjusted_mode
)
1156 struct drm_device
*dev
= encoder
->dev
;
1157 struct radeon_device
*rdev
= dev
->dev_private
;
1158 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1159 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1160 struct radeon_encoder_tv_dac
*tv_dac
= radeon_encoder
->enc_priv
;
1161 uint32_t tv_dac_cntl
, gpiopad_a
= 0, dac2_cntl
, disp_output_cntl
= 0;
1162 uint32_t disp_hw_debug
= 0, fp2_gen_cntl
= 0, disp_tv_out_cntl
= 0;
1165 DRM_DEBUG_KMS("\n");
1167 is_tv
= radeon_encoder
->active_device
& ATOM_DEVICE_TV_SUPPORT
? true : false;
1169 if (rdev
->family
!= CHIP_R200
) {
1170 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1171 if (rdev
->family
== CHIP_R420
||
1172 rdev
->family
== CHIP_R423
||
1173 rdev
->family
== CHIP_RV410
) {
1174 tv_dac_cntl
&= ~(RADEON_TV_DAC_STD_MASK
|
1175 RADEON_TV_DAC_BGADJ_MASK
|
1176 R420_TV_DAC_DACADJ_MASK
|
1177 R420_TV_DAC_RDACPD
|
1178 R420_TV_DAC_GDACPD
|
1179 R420_TV_DAC_BDACPD
|
1180 R420_TV_DAC_TVENABLE
);
1182 tv_dac_cntl
&= ~(RADEON_TV_DAC_STD_MASK
|
1183 RADEON_TV_DAC_BGADJ_MASK
|
1184 RADEON_TV_DAC_DACADJ_MASK
|
1185 RADEON_TV_DAC_RDACPD
|
1186 RADEON_TV_DAC_GDACPD
|
1187 RADEON_TV_DAC_BDACPD
);
1190 tv_dac_cntl
|= RADEON_TV_DAC_NBLANK
| RADEON_TV_DAC_NHOLD
;
1193 if (tv_dac
->tv_std
== TV_STD_NTSC
||
1194 tv_dac
->tv_std
== TV_STD_NTSC_J
||
1195 tv_dac
->tv_std
== TV_STD_PAL_M
||
1196 tv_dac
->tv_std
== TV_STD_PAL_60
)
1197 tv_dac_cntl
|= tv_dac
->ntsc_tvdac_adj
;
1199 tv_dac_cntl
|= tv_dac
->pal_tvdac_adj
;
1201 if (tv_dac
->tv_std
== TV_STD_NTSC
||
1202 tv_dac
->tv_std
== TV_STD_NTSC_J
)
1203 tv_dac_cntl
|= RADEON_TV_DAC_STD_NTSC
;
1205 tv_dac_cntl
|= RADEON_TV_DAC_STD_PAL
;
1207 tv_dac_cntl
|= (RADEON_TV_DAC_STD_PS2
|
1208 tv_dac
->ps2_tvdac_adj
);
1210 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1213 if (ASIC_IS_R300(rdev
)) {
1214 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
) | 1;
1215 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
);
1216 } else if (rdev
->family
!= CHIP_R200
)
1217 disp_hw_debug
= RREG32(RADEON_DISP_HW_DEBUG
);
1218 else if (rdev
->family
== CHIP_R200
)
1219 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
1221 if (rdev
->family
>= CHIP_R200
)
1222 disp_tv_out_cntl
= RREG32(RADEON_DISP_TV_OUT_CNTL
);
1227 dac_cntl
= RREG32(RADEON_DAC_CNTL
);
1228 dac_cntl
&= ~RADEON_DAC_TVO_EN
;
1229 WREG32(RADEON_DAC_CNTL
, dac_cntl
);
1231 if (ASIC_IS_R300(rdev
))
1232 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
) & ~1;
1234 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) & ~RADEON_DAC2_DAC2_CLK_SEL
;
1235 if (radeon_crtc
->crtc_id
== 0) {
1236 if (ASIC_IS_R300(rdev
)) {
1237 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1238 disp_output_cntl
|= (RADEON_DISP_TVDAC_SOURCE_CRTC
|
1239 RADEON_DISP_TV_SOURCE_CRTC
);
1241 if (rdev
->family
>= CHIP_R200
) {
1242 disp_tv_out_cntl
&= ~RADEON_DISP_TV_PATH_SRC_CRTC2
;
1244 disp_hw_debug
|= RADEON_CRT2_DISP1_SEL
;
1247 if (ASIC_IS_R300(rdev
)) {
1248 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1249 disp_output_cntl
|= RADEON_DISP_TV_SOURCE_CRTC
;
1251 if (rdev
->family
>= CHIP_R200
) {
1252 disp_tv_out_cntl
|= RADEON_DISP_TV_PATH_SRC_CRTC2
;
1254 disp_hw_debug
&= ~RADEON_CRT2_DISP1_SEL
;
1257 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
1260 dac2_cntl
= RREG32(RADEON_DAC_CNTL2
) | RADEON_DAC2_DAC2_CLK_SEL
;
1262 if (radeon_crtc
->crtc_id
== 0) {
1263 if (ASIC_IS_R300(rdev
)) {
1264 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1265 disp_output_cntl
|= RADEON_DISP_TVDAC_SOURCE_CRTC
;
1266 } else if (rdev
->family
== CHIP_R200
) {
1267 fp2_gen_cntl
&= ~(R200_FP2_SOURCE_SEL_MASK
|
1268 RADEON_FP2_DVO_RATE_SEL_SDR
);
1270 disp_hw_debug
|= RADEON_CRT2_DISP1_SEL
;
1272 if (ASIC_IS_R300(rdev
)) {
1273 disp_output_cntl
&= ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1274 disp_output_cntl
|= RADEON_DISP_TVDAC_SOURCE_CRTC2
;
1275 } else if (rdev
->family
== CHIP_R200
) {
1276 fp2_gen_cntl
&= ~(R200_FP2_SOURCE_SEL_MASK
|
1277 RADEON_FP2_DVO_RATE_SEL_SDR
);
1278 fp2_gen_cntl
|= R200_FP2_SOURCE_SEL_CRTC2
;
1280 disp_hw_debug
&= ~RADEON_CRT2_DISP1_SEL
;
1282 WREG32(RADEON_DAC_CNTL2
, dac2_cntl
);
1285 if (ASIC_IS_R300(rdev
)) {
1286 WREG32_P(RADEON_GPIOPAD_A
, gpiopad_a
, ~1);
1287 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1288 } else if (rdev
->family
!= CHIP_R200
)
1289 WREG32(RADEON_DISP_HW_DEBUG
, disp_hw_debug
);
1290 else if (rdev
->family
== CHIP_R200
)
1291 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
1293 if (rdev
->family
>= CHIP_R200
)
1294 WREG32(RADEON_DISP_TV_OUT_CNTL
, disp_tv_out_cntl
);
1297 radeon_legacy_tv_mode_set(encoder
, mode
, adjusted_mode
);
1299 if (rdev
->is_atom_bios
)
1300 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1302 radeon_combios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1306 static bool r300_legacy_tv_detect(struct drm_encoder
*encoder
,
1307 struct drm_connector
*connector
)
1309 struct drm_device
*dev
= encoder
->dev
;
1310 struct radeon_device
*rdev
= dev
->dev_private
;
1311 uint32_t crtc2_gen_cntl
, tv_dac_cntl
, dac_cntl2
, dac_ext_cntl
;
1312 uint32_t disp_output_cntl
, gpiopad_a
, tmp
;
1315 /* save regs needed */
1316 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
);
1317 dac_cntl2
= RREG32(RADEON_DAC_CNTL2
);
1318 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1319 dac_ext_cntl
= RREG32(RADEON_DAC_EXT_CNTL
);
1320 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1321 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
);
1323 WREG32_P(RADEON_GPIOPAD_A
, 0, ~1);
1325 WREG32(RADEON_DAC_CNTL2
, RADEON_DAC2_DAC2_CLK_SEL
);
1327 WREG32(RADEON_CRTC2_GEN_CNTL
,
1328 RADEON_CRTC2_CRT2_ON
| RADEON_CRTC2_VSYNC_TRISTAT
);
1330 tmp
= disp_output_cntl
& ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1331 tmp
|= RADEON_DISP_TVDAC_SOURCE_CRTC2
;
1332 WREG32(RADEON_DISP_OUTPUT_CNTL
, tmp
);
1334 WREG32(RADEON_DAC_EXT_CNTL
,
1335 RADEON_DAC2_FORCE_BLANK_OFF_EN
|
1336 RADEON_DAC2_FORCE_DATA_EN
|
1337 RADEON_DAC_FORCE_DATA_SEL_RGB
|
1338 (0xec << RADEON_DAC_FORCE_DATA_SHIFT
));
1340 WREG32(RADEON_TV_DAC_CNTL
,
1341 RADEON_TV_DAC_STD_NTSC
|
1342 (8 << RADEON_TV_DAC_BGADJ_SHIFT
) |
1343 (6 << RADEON_TV_DAC_DACADJ_SHIFT
));
1345 RREG32(RADEON_TV_DAC_CNTL
);
1348 WREG32(RADEON_TV_DAC_CNTL
,
1349 RADEON_TV_DAC_NBLANK
|
1350 RADEON_TV_DAC_NHOLD
|
1351 RADEON_TV_MONITOR_DETECT_EN
|
1352 RADEON_TV_DAC_STD_NTSC
|
1353 (8 << RADEON_TV_DAC_BGADJ_SHIFT
) |
1354 (6 << RADEON_TV_DAC_DACADJ_SHIFT
));
1356 RREG32(RADEON_TV_DAC_CNTL
);
1359 tmp
= RREG32(RADEON_TV_DAC_CNTL
);
1360 if ((tmp
& RADEON_TV_DAC_GDACDET
) != 0) {
1362 DRM_DEBUG_KMS("S-video TV connection detected\n");
1363 } else if ((tmp
& RADEON_TV_DAC_BDACDET
) != 0) {
1365 DRM_DEBUG_KMS("Composite TV connection detected\n");
1368 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1369 WREG32(RADEON_DAC_EXT_CNTL
, dac_ext_cntl
);
1370 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1371 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1372 WREG32(RADEON_DAC_CNTL2
, dac_cntl2
);
1373 WREG32_P(RADEON_GPIOPAD_A
, gpiopad_a
, ~1);
1377 static bool radeon_legacy_tv_detect(struct drm_encoder
*encoder
,
1378 struct drm_connector
*connector
)
1380 struct drm_device
*dev
= encoder
->dev
;
1381 struct radeon_device
*rdev
= dev
->dev_private
;
1382 uint32_t tv_dac_cntl
, dac_cntl2
;
1383 uint32_t config_cntl
, tv_pre_dac_mux_cntl
, tv_master_cntl
, tmp
;
1386 if (ASIC_IS_R300(rdev
))
1387 return r300_legacy_tv_detect(encoder
, connector
);
1389 dac_cntl2
= RREG32(RADEON_DAC_CNTL2
);
1390 tv_master_cntl
= RREG32(RADEON_TV_MASTER_CNTL
);
1391 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1392 config_cntl
= RREG32(RADEON_CONFIG_CNTL
);
1393 tv_pre_dac_mux_cntl
= RREG32(RADEON_TV_PRE_DAC_MUX_CNTL
);
1395 tmp
= dac_cntl2
& ~RADEON_DAC2_DAC2_CLK_SEL
;
1396 WREG32(RADEON_DAC_CNTL2
, tmp
);
1398 tmp
= tv_master_cntl
| RADEON_TV_ON
;
1399 tmp
&= ~(RADEON_TV_ASYNC_RST
|
1400 RADEON_RESTART_PHASE_FIX
|
1401 RADEON_CRT_FIFO_CE_EN
|
1402 RADEON_TV_FIFO_CE_EN
|
1403 RADEON_RE_SYNC_NOW_SEL_MASK
);
1404 tmp
|= RADEON_TV_FIFO_ASYNC_RST
| RADEON_CRT_ASYNC_RST
;
1405 WREG32(RADEON_TV_MASTER_CNTL
, tmp
);
1407 tmp
= RADEON_TV_DAC_NBLANK
| RADEON_TV_DAC_NHOLD
|
1408 RADEON_TV_MONITOR_DETECT_EN
| RADEON_TV_DAC_STD_NTSC
|
1409 (8 << RADEON_TV_DAC_BGADJ_SHIFT
);
1411 if (config_cntl
& RADEON_CFG_ATI_REV_ID_MASK
)
1412 tmp
|= (4 << RADEON_TV_DAC_DACADJ_SHIFT
);
1414 tmp
|= (8 << RADEON_TV_DAC_DACADJ_SHIFT
);
1415 WREG32(RADEON_TV_DAC_CNTL
, tmp
);
1417 tmp
= RADEON_C_GRN_EN
| RADEON_CMP_BLU_EN
|
1418 RADEON_RED_MX_FORCE_DAC_DATA
|
1419 RADEON_GRN_MX_FORCE_DAC_DATA
|
1420 RADEON_BLU_MX_FORCE_DAC_DATA
|
1421 (0x109 << RADEON_TV_FORCE_DAC_DATA_SHIFT
);
1422 WREG32(RADEON_TV_PRE_DAC_MUX_CNTL
, tmp
);
1425 tmp
= RREG32(RADEON_TV_DAC_CNTL
);
1426 if (tmp
& RADEON_TV_DAC_GDACDET
) {
1428 DRM_DEBUG_KMS("S-video TV connection detected\n");
1429 } else if ((tmp
& RADEON_TV_DAC_BDACDET
) != 0) {
1431 DRM_DEBUG_KMS("Composite TV connection detected\n");
1434 WREG32(RADEON_TV_PRE_DAC_MUX_CNTL
, tv_pre_dac_mux_cntl
);
1435 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1436 WREG32(RADEON_TV_MASTER_CNTL
, tv_master_cntl
);
1437 WREG32(RADEON_DAC_CNTL2
, dac_cntl2
);
1441 static bool radeon_legacy_ext_dac_detect(struct drm_encoder
*encoder
,
1442 struct drm_connector
*connector
)
1444 struct drm_device
*dev
= encoder
->dev
;
1445 struct radeon_device
*rdev
= dev
->dev_private
;
1446 uint32_t gpio_monid
, fp2_gen_cntl
, disp_output_cntl
, crtc2_gen_cntl
;
1447 uint32_t disp_lin_trans_grph_a
, disp_lin_trans_grph_b
, disp_lin_trans_grph_c
;
1448 uint32_t disp_lin_trans_grph_d
, disp_lin_trans_grph_e
, disp_lin_trans_grph_f
;
1449 uint32_t tmp
, crtc2_h_total_disp
, crtc2_v_total_disp
;
1450 uint32_t crtc2_h_sync_strt_wid
, crtc2_v_sync_strt_wid
;
1454 /* save the regs we need */
1455 gpio_monid
= RREG32(RADEON_GPIO_MONID
);
1456 fp2_gen_cntl
= RREG32(RADEON_FP2_GEN_CNTL
);
1457 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
);
1458 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1459 disp_lin_trans_grph_a
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_A
);
1460 disp_lin_trans_grph_b
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_B
);
1461 disp_lin_trans_grph_c
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_C
);
1462 disp_lin_trans_grph_d
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_D
);
1463 disp_lin_trans_grph_e
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_E
);
1464 disp_lin_trans_grph_f
= RREG32(RADEON_DISP_LIN_TRANS_GRPH_F
);
1465 crtc2_h_total_disp
= RREG32(RADEON_CRTC2_H_TOTAL_DISP
);
1466 crtc2_v_total_disp
= RREG32(RADEON_CRTC2_V_TOTAL_DISP
);
1467 crtc2_h_sync_strt_wid
= RREG32(RADEON_CRTC2_H_SYNC_STRT_WID
);
1468 crtc2_v_sync_strt_wid
= RREG32(RADEON_CRTC2_V_SYNC_STRT_WID
);
1470 tmp
= RREG32(RADEON_GPIO_MONID
);
1471 tmp
&= ~RADEON_GPIO_A_0
;
1472 WREG32(RADEON_GPIO_MONID
, tmp
);
1474 WREG32(RADEON_FP2_GEN_CNTL
, (RADEON_FP2_ON
|
1475 RADEON_FP2_PANEL_FORMAT
|
1476 R200_FP2_SOURCE_SEL_TRANS_UNIT
|
1478 R200_FP2_DVO_RATE_SEL_SDR
));
1480 WREG32(RADEON_DISP_OUTPUT_CNTL
, (RADEON_DISP_DAC_SOURCE_RMX
|
1481 RADEON_DISP_TRANS_MATRIX_GRAPHICS
));
1483 WREG32(RADEON_CRTC2_GEN_CNTL
, (RADEON_CRTC2_EN
|
1484 RADEON_CRTC2_DISP_REQ_EN_B
));
1486 WREG32(RADEON_DISP_LIN_TRANS_GRPH_A
, 0x00000000);
1487 WREG32(RADEON_DISP_LIN_TRANS_GRPH_B
, 0x000003f0);
1488 WREG32(RADEON_DISP_LIN_TRANS_GRPH_C
, 0x00000000);
1489 WREG32(RADEON_DISP_LIN_TRANS_GRPH_D
, 0x000003f0);
1490 WREG32(RADEON_DISP_LIN_TRANS_GRPH_E
, 0x00000000);
1491 WREG32(RADEON_DISP_LIN_TRANS_GRPH_F
, 0x000003f0);
1493 WREG32(RADEON_CRTC2_H_TOTAL_DISP
, 0x01000008);
1494 WREG32(RADEON_CRTC2_H_SYNC_STRT_WID
, 0x00000800);
1495 WREG32(RADEON_CRTC2_V_TOTAL_DISP
, 0x00080001);
1496 WREG32(RADEON_CRTC2_V_SYNC_STRT_WID
, 0x00000080);
1498 for (i
= 0; i
< 200; i
++) {
1499 tmp
= RREG32(RADEON_GPIO_MONID
);
1500 if (tmp
& RADEON_GPIO_Y_0
)
1506 if (!drm_can_sleep())
1512 /* restore the regs we used */
1513 WREG32(RADEON_DISP_LIN_TRANS_GRPH_A
, disp_lin_trans_grph_a
);
1514 WREG32(RADEON_DISP_LIN_TRANS_GRPH_B
, disp_lin_trans_grph_b
);
1515 WREG32(RADEON_DISP_LIN_TRANS_GRPH_C
, disp_lin_trans_grph_c
);
1516 WREG32(RADEON_DISP_LIN_TRANS_GRPH_D
, disp_lin_trans_grph_d
);
1517 WREG32(RADEON_DISP_LIN_TRANS_GRPH_E
, disp_lin_trans_grph_e
);
1518 WREG32(RADEON_DISP_LIN_TRANS_GRPH_F
, disp_lin_trans_grph_f
);
1519 WREG32(RADEON_CRTC2_H_TOTAL_DISP
, crtc2_h_total_disp
);
1520 WREG32(RADEON_CRTC2_V_TOTAL_DISP
, crtc2_v_total_disp
);
1521 WREG32(RADEON_CRTC2_H_SYNC_STRT_WID
, crtc2_h_sync_strt_wid
);
1522 WREG32(RADEON_CRTC2_V_SYNC_STRT_WID
, crtc2_v_sync_strt_wid
);
1523 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1524 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1525 WREG32(RADEON_FP2_GEN_CNTL
, fp2_gen_cntl
);
1526 WREG32(RADEON_GPIO_MONID
, gpio_monid
);
1531 static enum drm_connector_status
radeon_legacy_tv_dac_detect(struct drm_encoder
*encoder
,
1532 struct drm_connector
*connector
)
1534 struct drm_device
*dev
= encoder
->dev
;
1535 struct radeon_device
*rdev
= dev
->dev_private
;
1536 uint32_t crtc2_gen_cntl
= 0, tv_dac_cntl
, dac_cntl2
, dac_ext_cntl
;
1537 uint32_t gpiopad_a
= 0, pixclks_cntl
, tmp
;
1538 uint32_t disp_output_cntl
= 0, disp_hw_debug
= 0, crtc_ext_cntl
= 0;
1539 enum drm_connector_status found
= connector_status_disconnected
;
1540 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1541 struct radeon_encoder_tv_dac
*tv_dac
= radeon_encoder
->enc_priv
;
1543 struct drm_crtc
*crtc
;
1545 /* find out if crtc2 is in use or if this encoder is using it */
1546 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
1547 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(crtc
);
1548 if ((radeon_crtc
->crtc_id
== 1) && crtc
->enabled
) {
1549 if (encoder
->crtc
!= crtc
) {
1550 return connector_status_disconnected
;
1555 if (connector
->connector_type
== DRM_MODE_CONNECTOR_SVIDEO
||
1556 connector
->connector_type
== DRM_MODE_CONNECTOR_Composite
||
1557 connector
->connector_type
== DRM_MODE_CONNECTOR_9PinDIN
) {
1560 if (radeon_encoder
->active_device
&& !(radeon_encoder
->active_device
& ATOM_DEVICE_TV_SUPPORT
))
1561 return connector_status_disconnected
;
1563 tv_detect
= radeon_legacy_tv_detect(encoder
, connector
);
1564 if (tv_detect
&& tv_dac
)
1565 found
= connector_status_connected
;
1569 /* don't probe if the encoder is being used for something else not CRT related */
1570 if (radeon_encoder
->active_device
&& !(radeon_encoder
->active_device
& ATOM_DEVICE_CRT_SUPPORT
)) {
1571 DRM_INFO("not detecting due to %08x\n", radeon_encoder
->active_device
);
1572 return connector_status_disconnected
;
1575 /* R200 uses an external DAC for secondary DAC */
1576 if (rdev
->family
== CHIP_R200
) {
1577 if (radeon_legacy_ext_dac_detect(encoder
, connector
))
1578 found
= connector_status_connected
;
1582 /* save the regs we need */
1583 pixclks_cntl
= RREG32_PLL(RADEON_PIXCLKS_CNTL
);
1585 if (rdev
->flags
& RADEON_SINGLE_CRTC
) {
1586 crtc_ext_cntl
= RREG32(RADEON_CRTC_EXT_CNTL
);
1588 if (ASIC_IS_R300(rdev
)) {
1589 gpiopad_a
= RREG32(RADEON_GPIOPAD_A
);
1590 disp_output_cntl
= RREG32(RADEON_DISP_OUTPUT_CNTL
);
1592 disp_hw_debug
= RREG32(RADEON_DISP_HW_DEBUG
);
1594 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1596 tv_dac_cntl
= RREG32(RADEON_TV_DAC_CNTL
);
1597 dac_ext_cntl
= RREG32(RADEON_DAC_EXT_CNTL
);
1598 dac_cntl2
= RREG32(RADEON_DAC_CNTL2
);
1600 tmp
= pixclks_cntl
& ~(RADEON_PIX2CLK_ALWAYS_ONb
1601 | RADEON_PIX2CLK_DAC_ALWAYS_ONb
);
1602 WREG32_PLL(RADEON_PIXCLKS_CNTL
, tmp
);
1604 if (rdev
->flags
& RADEON_SINGLE_CRTC
) {
1605 tmp
= crtc_ext_cntl
| RADEON_CRTC_CRT_ON
;
1606 WREG32(RADEON_CRTC_EXT_CNTL
, tmp
);
1608 tmp
= crtc2_gen_cntl
& ~RADEON_CRTC2_PIX_WIDTH_MASK
;
1609 tmp
|= RADEON_CRTC2_CRT2_ON
|
1610 (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT
);
1611 WREG32(RADEON_CRTC2_GEN_CNTL
, tmp
);
1613 if (ASIC_IS_R300(rdev
)) {
1614 WREG32_P(RADEON_GPIOPAD_A
, 1, ~1);
1615 tmp
= disp_output_cntl
& ~RADEON_DISP_TVDAC_SOURCE_MASK
;
1616 tmp
|= RADEON_DISP_TVDAC_SOURCE_CRTC2
;
1617 WREG32(RADEON_DISP_OUTPUT_CNTL
, tmp
);
1619 tmp
= disp_hw_debug
& ~RADEON_CRT2_DISP1_SEL
;
1620 WREG32(RADEON_DISP_HW_DEBUG
, tmp
);
1624 tmp
= RADEON_TV_DAC_NBLANK
|
1625 RADEON_TV_DAC_NHOLD
|
1626 RADEON_TV_MONITOR_DETECT_EN
|
1627 RADEON_TV_DAC_STD_PS2
;
1629 WREG32(RADEON_TV_DAC_CNTL
, tmp
);
1631 tmp
= RADEON_DAC2_FORCE_BLANK_OFF_EN
|
1632 RADEON_DAC2_FORCE_DATA_EN
;
1635 tmp
|= RADEON_DAC_FORCE_DATA_SEL_RGB
;
1637 tmp
|= RADEON_DAC_FORCE_DATA_SEL_G
;
1639 if (ASIC_IS_R300(rdev
))
1640 tmp
|= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT
);
1642 tmp
|= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT
);
1644 WREG32(RADEON_DAC_EXT_CNTL
, tmp
);
1646 tmp
= dac_cntl2
| RADEON_DAC2_DAC2_CLK_SEL
| RADEON_DAC2_CMP_EN
;
1647 WREG32(RADEON_DAC_CNTL2
, tmp
);
1651 if (ASIC_IS_R300(rdev
)) {
1652 if (RREG32(RADEON_DAC_CNTL2
) & RADEON_DAC2_CMP_OUT_B
)
1653 found
= connector_status_connected
;
1655 if (RREG32(RADEON_DAC_CNTL2
) & RADEON_DAC2_CMP_OUTPUT
)
1656 found
= connector_status_connected
;
1659 /* restore regs we used */
1660 WREG32(RADEON_DAC_CNTL2
, dac_cntl2
);
1661 WREG32(RADEON_DAC_EXT_CNTL
, dac_ext_cntl
);
1662 WREG32(RADEON_TV_DAC_CNTL
, tv_dac_cntl
);
1664 if (rdev
->flags
& RADEON_SINGLE_CRTC
) {
1665 WREG32(RADEON_CRTC_EXT_CNTL
, crtc_ext_cntl
);
1667 WREG32(RADEON_CRTC2_GEN_CNTL
, crtc2_gen_cntl
);
1668 if (ASIC_IS_R300(rdev
)) {
1669 WREG32(RADEON_DISP_OUTPUT_CNTL
, disp_output_cntl
);
1670 WREG32_P(RADEON_GPIOPAD_A
, gpiopad_a
, ~1);
1672 WREG32(RADEON_DISP_HW_DEBUG
, disp_hw_debug
);
1676 WREG32_PLL(RADEON_PIXCLKS_CNTL
, pixclks_cntl
);
1682 static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs
= {
1683 .dpms
= radeon_legacy_tv_dac_dpms
,
1684 .mode_fixup
= radeon_legacy_mode_fixup
,
1685 .prepare
= radeon_legacy_tv_dac_prepare
,
1686 .mode_set
= radeon_legacy_tv_dac_mode_set
,
1687 .commit
= radeon_legacy_tv_dac_commit
,
1688 .detect
= radeon_legacy_tv_dac_detect
,
1689 .disable
= radeon_legacy_encoder_disable
,
1693 static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs
= {
1694 .destroy
= radeon_enc_destroy
,
1698 static struct radeon_encoder_int_tmds
*radeon_legacy_get_tmds_info(struct radeon_encoder
*encoder
)
1700 struct drm_device
*dev
= encoder
->base
.dev
;
1701 struct radeon_device
*rdev
= dev
->dev_private
;
1702 struct radeon_encoder_int_tmds
*tmds
= NULL
;
1705 tmds
= kzalloc(sizeof(struct radeon_encoder_int_tmds
), GFP_KERNEL
);
1710 if (rdev
->is_atom_bios
)
1711 ret
= radeon_atombios_get_tmds_info(encoder
, tmds
);
1713 ret
= radeon_legacy_get_tmds_info_from_combios(encoder
, tmds
);
1716 radeon_legacy_get_tmds_info_from_table(encoder
, tmds
);
1721 static struct radeon_encoder_ext_tmds
*radeon_legacy_get_ext_tmds_info(struct radeon_encoder
*encoder
)
1723 struct drm_device
*dev
= encoder
->base
.dev
;
1724 struct radeon_device
*rdev
= dev
->dev_private
;
1725 struct radeon_encoder_ext_tmds
*tmds
= NULL
;
1728 if (rdev
->is_atom_bios
)
1731 tmds
= kzalloc(sizeof(struct radeon_encoder_ext_tmds
), GFP_KERNEL
);
1736 ret
= radeon_legacy_get_ext_tmds_info_from_combios(encoder
, tmds
);
1739 radeon_legacy_get_ext_tmds_info_from_table(encoder
, tmds
);
1745 radeon_add_legacy_encoder(struct drm_device
*dev
, uint32_t encoder_enum
, uint32_t supported_device
)
1747 struct radeon_device
*rdev
= dev
->dev_private
;
1748 struct drm_encoder
*encoder
;
1749 struct radeon_encoder
*radeon_encoder
;
1751 /* see if we already added it */
1752 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
1753 radeon_encoder
= to_radeon_encoder(encoder
);
1754 if (radeon_encoder
->encoder_enum
== encoder_enum
) {
1755 radeon_encoder
->devices
|= supported_device
;
1762 radeon_encoder
= kzalloc(sizeof(struct radeon_encoder
), GFP_KERNEL
);
1763 if (!radeon_encoder
)
1766 encoder
= &radeon_encoder
->base
;
1767 if (rdev
->flags
& RADEON_SINGLE_CRTC
)
1768 encoder
->possible_crtcs
= 0x1;
1770 encoder
->possible_crtcs
= 0x3;
1772 radeon_encoder
->enc_priv
= NULL
;
1774 radeon_encoder
->encoder_enum
= encoder_enum
;
1775 radeon_encoder
->encoder_id
= (encoder_enum
& OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
1776 radeon_encoder
->devices
= supported_device
;
1777 radeon_encoder
->rmx_type
= RMX_OFF
;
1779 switch (radeon_encoder
->encoder_id
) {
1780 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1781 encoder
->possible_crtcs
= 0x1;
1782 drm_encoder_init(dev
, encoder
, &radeon_legacy_lvds_enc_funcs
,
1783 DRM_MODE_ENCODER_LVDS
, NULL
);
1784 drm_encoder_helper_add(encoder
, &radeon_legacy_lvds_helper_funcs
);
1785 if (rdev
->is_atom_bios
)
1786 radeon_encoder
->enc_priv
= radeon_atombios_get_lvds_info(radeon_encoder
);
1788 radeon_encoder
->enc_priv
= radeon_combios_get_lvds_info(radeon_encoder
);
1789 radeon_encoder
->rmx_type
= RMX_FULL
;
1791 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1792 drm_encoder_init(dev
, encoder
, &radeon_legacy_tmds_int_enc_funcs
,
1793 DRM_MODE_ENCODER_TMDS
, NULL
);
1794 drm_encoder_helper_add(encoder
, &radeon_legacy_tmds_int_helper_funcs
);
1795 radeon_encoder
->enc_priv
= radeon_legacy_get_tmds_info(radeon_encoder
);
1797 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1798 drm_encoder_init(dev
, encoder
, &radeon_legacy_primary_dac_enc_funcs
,
1799 DRM_MODE_ENCODER_DAC
, NULL
);
1800 drm_encoder_helper_add(encoder
, &radeon_legacy_primary_dac_helper_funcs
);
1801 if (rdev
->is_atom_bios
)
1802 radeon_encoder
->enc_priv
= radeon_atombios_get_primary_dac_info(radeon_encoder
);
1804 radeon_encoder
->enc_priv
= radeon_combios_get_primary_dac_info(radeon_encoder
);
1806 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1807 drm_encoder_init(dev
, encoder
, &radeon_legacy_tv_dac_enc_funcs
,
1808 DRM_MODE_ENCODER_TVDAC
, NULL
);
1809 drm_encoder_helper_add(encoder
, &radeon_legacy_tv_dac_helper_funcs
);
1810 if (rdev
->is_atom_bios
)
1811 radeon_encoder
->enc_priv
= radeon_atombios_get_tv_dac_info(radeon_encoder
);
1813 radeon_encoder
->enc_priv
= radeon_combios_get_tv_dac_info(radeon_encoder
);
1815 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1816 drm_encoder_init(dev
, encoder
, &radeon_legacy_tmds_ext_enc_funcs
,
1817 DRM_MODE_ENCODER_TMDS
, NULL
);
1818 drm_encoder_helper_add(encoder
, &radeon_legacy_tmds_ext_helper_funcs
);
1819 if (!rdev
->is_atom_bios
)
1820 radeon_encoder
->enc_priv
= radeon_legacy_get_ext_tmds_info(radeon_encoder
);