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"
32 extern int atom_debug
;
34 /* evil but including atombios.h is much worse */
35 bool radeon_atom_get_tv_timings(struct radeon_device
*rdev
, int index
,
36 struct drm_display_mode
*mode
);
38 static uint32_t radeon_encoder_clones(struct drm_encoder
*encoder
)
40 struct drm_device
*dev
= encoder
->dev
;
41 struct radeon_device
*rdev
= dev
->dev_private
;
42 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
43 struct drm_encoder
*clone_encoder
;
44 uint32_t index_mask
= 0;
47 /* DIG routing gets problematic */
48 if (rdev
->family
>= CHIP_R600
)
50 /* LVDS/TV are too wacky */
51 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD_SUPPORT
)
53 /* DVO requires 2x ppll clocks depending on tmds chip */
54 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
)
58 list_for_each_entry(clone_encoder
, &dev
->mode_config
.encoder_list
, head
) {
59 struct radeon_encoder
*radeon_clone
= to_radeon_encoder(clone_encoder
);
62 if (clone_encoder
== encoder
)
64 if (radeon_clone
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
66 if (radeon_clone
->devices
& ATOM_DEVICE_DFP2_SUPPORT
)
69 index_mask
|= (1 << count
);
74 void radeon_setup_encoder_clones(struct drm_device
*dev
)
76 struct drm_encoder
*encoder
;
78 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
79 encoder
->possible_clones
= radeon_encoder_clones(encoder
);
84 radeon_get_encoder_id(struct drm_device
*dev
, uint32_t supported_device
, uint8_t dac
)
86 struct radeon_device
*rdev
= dev
->dev_private
;
89 switch (supported_device
) {
90 case ATOM_DEVICE_CRT1_SUPPORT
:
91 case ATOM_DEVICE_TV1_SUPPORT
:
92 case ATOM_DEVICE_TV2_SUPPORT
:
93 case ATOM_DEVICE_CRT2_SUPPORT
:
94 case ATOM_DEVICE_CV_SUPPORT
:
97 if ((rdev
->family
== CHIP_RS300
) ||
98 (rdev
->family
== CHIP_RS400
) ||
99 (rdev
->family
== CHIP_RS480
))
100 ret
= ENCODER_OBJECT_ID_INTERNAL_DAC2
;
101 else if (ASIC_IS_AVIVO(rdev
))
102 ret
= ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
;
104 ret
= ENCODER_OBJECT_ID_INTERNAL_DAC1
;
107 if (ASIC_IS_AVIVO(rdev
))
108 ret
= ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
;
110 /*if (rdev->family == CHIP_R200)
111 ret = ENCODER_OBJECT_ID_INTERNAL_DVO1;
113 ret
= ENCODER_OBJECT_ID_INTERNAL_DAC2
;
116 case 3: /* external dac */
117 if (ASIC_IS_AVIVO(rdev
))
118 ret
= ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
;
120 ret
= ENCODER_OBJECT_ID_INTERNAL_DVO1
;
124 case ATOM_DEVICE_LCD1_SUPPORT
:
125 if (ASIC_IS_AVIVO(rdev
))
126 ret
= ENCODER_OBJECT_ID_INTERNAL_LVTM1
;
128 ret
= ENCODER_OBJECT_ID_INTERNAL_LVDS
;
130 case ATOM_DEVICE_DFP1_SUPPORT
:
131 if ((rdev
->family
== CHIP_RS300
) ||
132 (rdev
->family
== CHIP_RS400
) ||
133 (rdev
->family
== CHIP_RS480
))
134 ret
= ENCODER_OBJECT_ID_INTERNAL_DVO1
;
135 else if (ASIC_IS_AVIVO(rdev
))
136 ret
= ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
;
138 ret
= ENCODER_OBJECT_ID_INTERNAL_TMDS1
;
140 case ATOM_DEVICE_LCD2_SUPPORT
:
141 case ATOM_DEVICE_DFP2_SUPPORT
:
142 if ((rdev
->family
== CHIP_RS600
) ||
143 (rdev
->family
== CHIP_RS690
) ||
144 (rdev
->family
== CHIP_RS740
))
145 ret
= ENCODER_OBJECT_ID_INTERNAL_DDI
;
146 else if (ASIC_IS_AVIVO(rdev
))
147 ret
= ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
;
149 ret
= ENCODER_OBJECT_ID_INTERNAL_DVO1
;
151 case ATOM_DEVICE_DFP3_SUPPORT
:
152 ret
= ENCODER_OBJECT_ID_INTERNAL_LVTM1
;
160 radeon_link_encoder_connector(struct drm_device
*dev
)
162 struct drm_connector
*connector
;
163 struct radeon_connector
*radeon_connector
;
164 struct drm_encoder
*encoder
;
165 struct radeon_encoder
*radeon_encoder
;
167 /* walk the list and link encoders to connectors */
168 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
169 radeon_connector
= to_radeon_connector(connector
);
170 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
171 radeon_encoder
= to_radeon_encoder(encoder
);
172 if (radeon_encoder
->devices
& radeon_connector
->devices
)
173 drm_mode_connector_attach_encoder(connector
, encoder
);
178 void radeon_encoder_set_active_device(struct drm_encoder
*encoder
)
180 struct drm_device
*dev
= encoder
->dev
;
181 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
182 struct drm_connector
*connector
;
184 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
185 if (connector
->encoder
== encoder
) {
186 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
187 radeon_encoder
->active_device
= radeon_encoder
->devices
& radeon_connector
->devices
;
188 DRM_DEBUG("setting active device to %08x from %08x %08x for encoder %d\n",
189 radeon_encoder
->active_device
, radeon_encoder
->devices
,
190 radeon_connector
->devices
, encoder
->encoder_type
);
195 static struct drm_connector
*
196 radeon_get_connector_for_encoder(struct drm_encoder
*encoder
)
198 struct drm_device
*dev
= encoder
->dev
;
199 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
200 struct drm_connector
*connector
;
201 struct radeon_connector
*radeon_connector
;
203 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
204 radeon_connector
= to_radeon_connector(connector
);
205 if (radeon_encoder
->devices
& radeon_connector
->devices
)
211 static bool radeon_atom_mode_fixup(struct drm_encoder
*encoder
,
212 struct drm_display_mode
*mode
,
213 struct drm_display_mode
*adjusted_mode
)
215 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
216 struct drm_device
*dev
= encoder
->dev
;
217 struct radeon_device
*rdev
= dev
->dev_private
;
219 /* set the active encoder to connector routing */
220 radeon_encoder_set_active_device(encoder
);
221 drm_mode_set_crtcinfo(adjusted_mode
, 0);
224 if ((mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
225 && (mode
->crtc_vsync_start
< (mode
->crtc_vdisplay
+ 2)))
226 adjusted_mode
->crtc_vsync_start
= adjusted_mode
->crtc_vdisplay
+ 2;
228 /* get the native mode for LVDS */
229 if (radeon_encoder
->active_device
& (ATOM_DEVICE_LCD_SUPPORT
)) {
230 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
231 int mode_id
= adjusted_mode
->base
.id
;
232 *adjusted_mode
= *native_mode
;
233 if (!ASIC_IS_AVIVO(rdev
)) {
234 adjusted_mode
->hdisplay
= mode
->hdisplay
;
235 adjusted_mode
->vdisplay
= mode
->vdisplay
;
236 adjusted_mode
->crtc_hdisplay
= mode
->hdisplay
;
237 adjusted_mode
->crtc_vdisplay
= mode
->vdisplay
;
239 adjusted_mode
->base
.id
= mode_id
;
242 /* get the native mode for TV */
243 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
)) {
244 struct radeon_encoder_atom_dac
*tv_dac
= radeon_encoder
->enc_priv
;
246 if (tv_dac
->tv_std
== TV_STD_NTSC
||
247 tv_dac
->tv_std
== TV_STD_NTSC_J
||
248 tv_dac
->tv_std
== TV_STD_PAL_M
)
249 radeon_atom_get_tv_timings(rdev
, 0, adjusted_mode
);
251 radeon_atom_get_tv_timings(rdev
, 1, adjusted_mode
);
255 if (ASIC_IS_DCE3(rdev
) &&
256 (radeon_encoder
->active_device
& (ATOM_DEVICE_DFP_SUPPORT
))) {
257 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
258 radeon_dp_set_link_config(connector
, mode
);
265 atombios_dac_setup(struct drm_encoder
*encoder
, int action
)
267 struct drm_device
*dev
= encoder
->dev
;
268 struct radeon_device
*rdev
= dev
->dev_private
;
269 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
270 DAC_ENCODER_CONTROL_PS_ALLOCATION args
;
271 int index
= 0, num
= 0;
272 struct radeon_encoder_atom_dac
*dac_info
= radeon_encoder
->enc_priv
;
273 enum radeon_tv_std tv_std
= TV_STD_NTSC
;
275 if (dac_info
->tv_std
)
276 tv_std
= dac_info
->tv_std
;
278 memset(&args
, 0, sizeof(args
));
280 switch (radeon_encoder
->encoder_id
) {
281 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
282 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
283 index
= GetIndexIntoMasterTable(COMMAND
, DAC1EncoderControl
);
286 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
287 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
288 index
= GetIndexIntoMasterTable(COMMAND
, DAC2EncoderControl
);
293 args
.ucAction
= action
;
295 if (radeon_encoder
->active_device
& (ATOM_DEVICE_CRT_SUPPORT
))
296 args
.ucDacStandard
= ATOM_DAC1_PS2
;
297 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
298 args
.ucDacStandard
= ATOM_DAC1_CV
;
303 case TV_STD_SCART_PAL
:
306 args
.ucDacStandard
= ATOM_DAC1_PAL
;
312 args
.ucDacStandard
= ATOM_DAC1_NTSC
;
316 args
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
318 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
323 atombios_tv_setup(struct drm_encoder
*encoder
, int action
)
325 struct drm_device
*dev
= encoder
->dev
;
326 struct radeon_device
*rdev
= dev
->dev_private
;
327 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
328 TV_ENCODER_CONTROL_PS_ALLOCATION args
;
330 struct radeon_encoder_atom_dac
*dac_info
= radeon_encoder
->enc_priv
;
331 enum radeon_tv_std tv_std
= TV_STD_NTSC
;
333 if (dac_info
->tv_std
)
334 tv_std
= dac_info
->tv_std
;
336 memset(&args
, 0, sizeof(args
));
338 index
= GetIndexIntoMasterTable(COMMAND
, TVEncoderControl
);
340 args
.sTVEncoder
.ucAction
= action
;
342 if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
343 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_CV
;
347 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSC
;
350 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL
;
353 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PALM
;
356 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL60
;
359 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSCJ
;
361 case TV_STD_SCART_PAL
:
362 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL
; /* ??? */
365 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_SECAM
;
368 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PALCN
;
371 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSC
;
376 args
.sTVEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
378 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
383 atombios_external_tmds_setup(struct drm_encoder
*encoder
, int action
)
385 struct drm_device
*dev
= encoder
->dev
;
386 struct radeon_device
*rdev
= dev
->dev_private
;
387 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
388 ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION args
;
391 memset(&args
, 0, sizeof(args
));
393 index
= GetIndexIntoMasterTable(COMMAND
, DVOEncoderControl
);
395 args
.sXTmdsEncoder
.ucEnable
= action
;
397 if (radeon_encoder
->pixel_clock
> 165000)
398 args
.sXTmdsEncoder
.ucMisc
= PANEL_ENCODER_MISC_DUAL
;
400 /*if (pScrn->rgbBits == 8)*/
401 args
.sXTmdsEncoder
.ucMisc
|= (1 << 1);
403 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
408 atombios_ddia_setup(struct drm_encoder
*encoder
, int action
)
410 struct drm_device
*dev
= encoder
->dev
;
411 struct radeon_device
*rdev
= dev
->dev_private
;
412 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
413 DVO_ENCODER_CONTROL_PS_ALLOCATION args
;
416 memset(&args
, 0, sizeof(args
));
418 index
= GetIndexIntoMasterTable(COMMAND
, DVOEncoderControl
);
420 args
.sDVOEncoder
.ucAction
= action
;
421 args
.sDVOEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
423 if (radeon_encoder
->pixel_clock
> 165000)
424 args
.sDVOEncoder
.usDevAttr
.sDigAttrib
.ucAttribute
= PANEL_ENCODER_MISC_DUAL
;
426 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
430 union lvds_encoder_control
{
431 LVDS_ENCODER_CONTROL_PS_ALLOCATION v1
;
432 LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2
;
436 atombios_digital_setup(struct drm_encoder
*encoder
, int action
)
438 struct drm_device
*dev
= encoder
->dev
;
439 struct radeon_device
*rdev
= dev
->dev_private
;
440 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
441 union lvds_encoder_control args
;
443 int hdmi_detected
= 0;
445 struct radeon_encoder_atom_dig
*dig
;
446 struct drm_connector
*connector
;
447 struct radeon_connector
*radeon_connector
;
448 struct radeon_connector_atom_dig
*dig_connector
;
450 connector
= radeon_get_connector_for_encoder(encoder
);
454 radeon_connector
= to_radeon_connector(connector
);
456 if (!radeon_encoder
->enc_priv
)
459 dig
= radeon_encoder
->enc_priv
;
461 if (!radeon_connector
->con_priv
)
464 if (drm_detect_hdmi_monitor(radeon_connector
->edid
))
467 dig_connector
= radeon_connector
->con_priv
;
469 memset(&args
, 0, sizeof(args
));
471 switch (radeon_encoder
->encoder_id
) {
472 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
473 index
= GetIndexIntoMasterTable(COMMAND
, LVDSEncoderControl
);
475 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
476 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
477 index
= GetIndexIntoMasterTable(COMMAND
, TMDS1EncoderControl
);
479 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
480 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
481 index
= GetIndexIntoMasterTable(COMMAND
, LVDSEncoderControl
);
483 index
= GetIndexIntoMasterTable(COMMAND
, TMDS2EncoderControl
);
487 atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
);
495 args
.v1
.ucAction
= action
;
497 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_HDMI_TYPE
;
498 args
.v1
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
499 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
500 if (dig
->lvds_misc
& ATOM_PANEL_MISC_DUAL
)
501 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
502 if (dig
->lvds_misc
& ATOM_PANEL_MISC_888RGB
)
503 args
.v1
.ucMisc
|= (1 << 1);
505 if (dig_connector
->linkb
)
506 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_TMDS_LINKB
;
507 if (radeon_encoder
->pixel_clock
> 165000)
508 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
509 /*if (pScrn->rgbBits == 8) */
510 args
.v1
.ucMisc
|= (1 << 1);
516 args
.v2
.ucAction
= action
;
518 if (dig
->coherent_mode
)
519 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_COHERENT
;
522 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_HDMI_TYPE
;
523 args
.v2
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
524 args
.v2
.ucTruncate
= 0;
525 args
.v2
.ucSpatial
= 0;
526 args
.v2
.ucTemporal
= 0;
528 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
529 if (dig
->lvds_misc
& ATOM_PANEL_MISC_DUAL
)
530 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
531 if (dig
->lvds_misc
& ATOM_PANEL_MISC_SPATIAL
) {
532 args
.v2
.ucSpatial
= PANEL_ENCODER_SPATIAL_DITHER_EN
;
533 if (dig
->lvds_misc
& ATOM_PANEL_MISC_888RGB
)
534 args
.v2
.ucSpatial
|= PANEL_ENCODER_SPATIAL_DITHER_DEPTH
;
536 if (dig
->lvds_misc
& ATOM_PANEL_MISC_TEMPORAL
) {
537 args
.v2
.ucTemporal
= PANEL_ENCODER_TEMPORAL_DITHER_EN
;
538 if (dig
->lvds_misc
& ATOM_PANEL_MISC_888RGB
)
539 args
.v2
.ucTemporal
|= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH
;
540 if (((dig
->lvds_misc
>> ATOM_PANEL_MISC_GREY_LEVEL_SHIFT
) & 0x3) == 2)
541 args
.v2
.ucTemporal
|= PANEL_ENCODER_TEMPORAL_LEVEL_4
;
544 if (dig_connector
->linkb
)
545 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_TMDS_LINKB
;
546 if (radeon_encoder
->pixel_clock
> 165000)
547 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
551 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
556 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
560 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
561 r600_hdmi_enable(encoder
, hdmi_detected
);
565 atombios_get_encoder_mode(struct drm_encoder
*encoder
)
567 struct drm_connector
*connector
;
568 struct radeon_connector
*radeon_connector
;
569 struct radeon_connector_atom_dig
*radeon_dig_connector
;
571 connector
= radeon_get_connector_for_encoder(encoder
);
575 radeon_connector
= to_radeon_connector(connector
);
577 switch (connector
->connector_type
) {
578 case DRM_MODE_CONNECTOR_DVII
:
579 case DRM_MODE_CONNECTOR_HDMIB
: /* HDMI-B is basically DL-DVI; analog works fine */
580 if (drm_detect_hdmi_monitor(radeon_connector
->edid
))
581 return ATOM_ENCODER_MODE_HDMI
;
582 else if (radeon_connector
->use_digital
)
583 return ATOM_ENCODER_MODE_DVI
;
585 return ATOM_ENCODER_MODE_CRT
;
587 case DRM_MODE_CONNECTOR_DVID
:
588 case DRM_MODE_CONNECTOR_HDMIA
:
590 if (drm_detect_hdmi_monitor(radeon_connector
->edid
))
591 return ATOM_ENCODER_MODE_HDMI
;
593 return ATOM_ENCODER_MODE_DVI
;
595 case DRM_MODE_CONNECTOR_LVDS
:
596 return ATOM_ENCODER_MODE_LVDS
;
598 case DRM_MODE_CONNECTOR_DisplayPort
:
599 case DRM_MODE_CONNECTOR_eDP
:
600 radeon_dig_connector
= radeon_connector
->con_priv
;
601 if ((radeon_dig_connector
->dp_sink_type
== CONNECTOR_OBJECT_ID_DISPLAYPORT
) ||
602 (radeon_dig_connector
->dp_sink_type
== CONNECTOR_OBJECT_ID_eDP
))
603 return ATOM_ENCODER_MODE_DP
;
604 else if (drm_detect_hdmi_monitor(radeon_connector
->edid
))
605 return ATOM_ENCODER_MODE_HDMI
;
607 return ATOM_ENCODER_MODE_DVI
;
609 case DRM_MODE_CONNECTOR_DVIA
:
610 case DRM_MODE_CONNECTOR_VGA
:
611 return ATOM_ENCODER_MODE_CRT
;
613 case DRM_MODE_CONNECTOR_Composite
:
614 case DRM_MODE_CONNECTOR_SVIDEO
:
615 case DRM_MODE_CONNECTOR_9PinDIN
:
617 return ATOM_ENCODER_MODE_TV
;
618 /*return ATOM_ENCODER_MODE_CV;*/
624 * DIG Encoder/Transmitter Setup
627 * - 2 DIG transmitter blocks. UNIPHY (links A and B) and LVTMA.
628 * Supports up to 3 digital outputs
629 * - 2 DIG encoder blocks.
630 * DIG1 can drive UNIPHY link A or link B
631 * DIG2 can drive UNIPHY link B or LVTMA
634 * - 3 DIG transmitter blocks. UNIPHY0/1/2 (links A and B).
635 * Supports up to 5 digital outputs
636 * - 2 DIG encoder blocks.
637 * DIG1/2 can drive UNIPHY0/1/2 link A or link B
640 * crtc -> dig encoder -> UNIPHY/LVTMA (1 or 2 links)
642 * crtc0 -> dig2 -> LVTMA links A+B -> TMDS/HDMI
643 * crtc1 -> dig1 -> UNIPHY0 link B -> DP
644 * crtc0 -> dig1 -> UNIPHY2 link A -> LVDS
645 * crtc1 -> dig2 -> UNIPHY1 link B+A -> TMDS/HDMI
648 atombios_dig_encoder_setup(struct drm_encoder
*encoder
, int action
)
650 struct drm_device
*dev
= encoder
->dev
;
651 struct radeon_device
*rdev
= dev
->dev_private
;
652 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
653 DIG_ENCODER_CONTROL_PS_ALLOCATION args
;
654 int index
= 0, num
= 0;
656 struct radeon_encoder_atom_dig
*dig
;
657 struct drm_connector
*connector
;
658 struct radeon_connector
*radeon_connector
;
659 struct radeon_connector_atom_dig
*dig_connector
;
661 connector
= radeon_get_connector_for_encoder(encoder
);
665 radeon_connector
= to_radeon_connector(connector
);
667 if (!radeon_connector
->con_priv
)
670 dig_connector
= radeon_connector
->con_priv
;
672 if (!radeon_encoder
->enc_priv
)
675 dig
= radeon_encoder
->enc_priv
;
677 memset(&args
, 0, sizeof(args
));
679 if (ASIC_IS_DCE32(rdev
)) {
681 index
= GetIndexIntoMasterTable(COMMAND
, DIG2EncoderControl
);
683 index
= GetIndexIntoMasterTable(COMMAND
, DIG1EncoderControl
);
684 num
= dig
->dig_block
+ 1;
686 switch (radeon_encoder
->encoder_id
) {
687 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
688 /* XXX doesn't really matter which dig encoder we pick as long as it's
691 if (dig_connector
->linkb
)
692 index
= GetIndexIntoMasterTable(COMMAND
, DIG2EncoderControl
);
694 index
= GetIndexIntoMasterTable(COMMAND
, DIG1EncoderControl
);
697 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
698 /* Only dig2 encoder can drive LVTMA */
699 index
= GetIndexIntoMasterTable(COMMAND
, DIG2EncoderControl
);
705 atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
);
707 args
.ucAction
= action
;
708 args
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
710 if (ASIC_IS_DCE32(rdev
)) {
711 switch (radeon_encoder
->encoder_id
) {
712 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
713 args
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER1
;
715 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
716 args
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER2
;
718 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
719 args
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER3
;
723 switch (radeon_encoder
->encoder_id
) {
724 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
725 args
.ucConfig
= ATOM_ENCODER_CONFIG_TRANSMITTER1
;
727 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
728 args
.ucConfig
= ATOM_ENCODER_CONFIG_TRANSMITTER2
;
733 args
.ucEncoderMode
= atombios_get_encoder_mode(encoder
);
735 if (args
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) {
736 if (dig_connector
->dp_clock
== 270000)
737 args
.ucConfig
|= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ
;
738 args
.ucLaneNum
= dig_connector
->dp_lane_count
;
739 } else if (radeon_encoder
->pixel_clock
> 165000)
744 if (dig_connector
->linkb
)
745 args
.ucConfig
|= ATOM_ENCODER_CONFIG_LINKB
;
747 args
.ucConfig
|= ATOM_ENCODER_CONFIG_LINKA
;
749 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
753 union dig_transmitter_control
{
754 DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1
;
755 DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2
;
759 atombios_dig_transmitter_setup(struct drm_encoder
*encoder
, int action
, uint8_t lane_num
, uint8_t lane_set
)
761 struct drm_device
*dev
= encoder
->dev
;
762 struct radeon_device
*rdev
= dev
->dev_private
;
763 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
764 union dig_transmitter_control args
;
765 int index
= 0, num
= 0;
767 struct radeon_encoder_atom_dig
*dig
;
768 struct drm_connector
*connector
;
769 struct radeon_connector
*radeon_connector
;
770 struct radeon_connector_atom_dig
*dig_connector
;
773 connector
= radeon_get_connector_for_encoder(encoder
);
777 radeon_connector
= to_radeon_connector(connector
);
779 if (!radeon_encoder
->enc_priv
)
782 dig
= radeon_encoder
->enc_priv
;
784 if (!radeon_connector
->con_priv
)
787 dig_connector
= radeon_connector
->con_priv
;
789 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_DP
)
792 memset(&args
, 0, sizeof(args
));
794 if (ASIC_IS_DCE32(rdev
))
795 index
= GetIndexIntoMasterTable(COMMAND
, UNIPHYTransmitterControl
);
797 switch (radeon_encoder
->encoder_id
) {
798 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
799 index
= GetIndexIntoMasterTable(COMMAND
, DIG1TransmitterControl
);
801 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
802 index
= GetIndexIntoMasterTable(COMMAND
, DIG2TransmitterControl
);
807 atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
);
809 args
.v1
.ucAction
= action
;
810 if (action
== ATOM_TRANSMITTER_ACTION_INIT
) {
811 args
.v1
.usInitInfo
= radeon_connector
->connector_object_id
;
812 } else if (action
== ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH
) {
813 args
.v1
.asMode
.ucLaneSel
= lane_num
;
814 args
.v1
.asMode
.ucLaneSet
= lane_set
;
817 args
.v1
.usPixelClock
=
818 cpu_to_le16(dig_connector
->dp_clock
/ 10);
819 else if (radeon_encoder
->pixel_clock
> 165000)
820 args
.v1
.usPixelClock
= cpu_to_le16((radeon_encoder
->pixel_clock
/ 2) / 10);
822 args
.v1
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
824 if (ASIC_IS_DCE32(rdev
)) {
826 args
.v2
.acConfig
.ucEncoderSel
= 1;
827 if (dig_connector
->linkb
)
828 args
.v2
.acConfig
.ucLinkSel
= 1;
830 switch (radeon_encoder
->encoder_id
) {
831 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
832 args
.v2
.acConfig
.ucTransmitterSel
= 0;
835 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
836 args
.v2
.acConfig
.ucTransmitterSel
= 1;
839 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
840 args
.v2
.acConfig
.ucTransmitterSel
= 2;
846 args
.v2
.acConfig
.fCoherentMode
= 1;
847 else if (radeon_encoder
->devices
& (ATOM_DEVICE_DFP_SUPPORT
)) {
848 if (dig
->coherent_mode
)
849 args
.v2
.acConfig
.fCoherentMode
= 1;
852 args
.v1
.ucConfig
= ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL
;
854 switch (radeon_encoder
->encoder_id
) {
855 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
856 /* XXX doesn't really matter which dig encoder we pick as long as it's
859 if (dig_connector
->linkb
)
860 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER
;
862 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER
;
863 if (rdev
->flags
& RADEON_IS_IGP
) {
864 if (radeon_encoder
->pixel_clock
> 165000) {
865 if (dig_connector
->igp_lane_info
& 0x3)
866 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_0_7
;
867 else if (dig_connector
->igp_lane_info
& 0xc)
868 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_8_15
;
870 if (dig_connector
->igp_lane_info
& 0x1)
871 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_0_3
;
872 else if (dig_connector
->igp_lane_info
& 0x2)
873 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_4_7
;
874 else if (dig_connector
->igp_lane_info
& 0x4)
875 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_8_11
;
876 else if (dig_connector
->igp_lane_info
& 0x8)
877 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_12_15
;
881 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
882 /* Only dig2 encoder can drive LVTMA */
883 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER
;
887 if (radeon_encoder
->pixel_clock
> 165000)
888 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_8LANE_LINK
;
890 if (dig_connector
->linkb
)
891 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LINKB
;
893 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LINKA
;
896 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_COHERENT
;
897 else if (radeon_encoder
->devices
& (ATOM_DEVICE_DFP_SUPPORT
)) {
898 if (dig
->coherent_mode
)
899 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_COHERENT
;
903 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
907 atombios_yuv_setup(struct drm_encoder
*encoder
, bool enable
)
909 struct drm_device
*dev
= encoder
->dev
;
910 struct radeon_device
*rdev
= dev
->dev_private
;
911 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
912 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
913 ENABLE_YUV_PS_ALLOCATION args
;
914 int index
= GetIndexIntoMasterTable(COMMAND
, EnableYUV
);
917 memset(&args
, 0, sizeof(args
));
919 if (rdev
->family
>= CHIP_R600
)
920 reg
= R600_BIOS_3_SCRATCH
;
922 reg
= RADEON_BIOS_3_SCRATCH
;
924 /* XXX: fix up scratch reg handling */
926 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
927 WREG32(reg
, (ATOM_S3_TV1_ACTIVE
|
928 (radeon_crtc
->crtc_id
<< 18)));
929 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
930 WREG32(reg
, (ATOM_S3_CV_ACTIVE
| (radeon_crtc
->crtc_id
<< 24)));
935 args
.ucEnable
= ATOM_ENABLE
;
936 args
.ucCRTC
= radeon_crtc
->crtc_id
;
938 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
944 radeon_atom_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
946 struct drm_device
*dev
= encoder
->dev
;
947 struct radeon_device
*rdev
= dev
->dev_private
;
948 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
949 DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args
;
953 memset(&args
, 0, sizeof(args
));
955 DRM_DEBUG("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n",
956 radeon_encoder
->encoder_id
, mode
, radeon_encoder
->devices
,
957 radeon_encoder
->active_device
);
958 switch (radeon_encoder
->encoder_id
) {
959 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
960 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
961 index
= GetIndexIntoMasterTable(COMMAND
, TMDSAOutputControl
);
963 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
964 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
965 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
966 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
969 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
970 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
971 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
972 index
= GetIndexIntoMasterTable(COMMAND
, DVOOutputControl
);
974 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
975 index
= GetIndexIntoMasterTable(COMMAND
, LCD1OutputControl
);
977 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
978 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
979 index
= GetIndexIntoMasterTable(COMMAND
, LCD1OutputControl
);
981 index
= GetIndexIntoMasterTable(COMMAND
, LVTMAOutputControl
);
983 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
984 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
985 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
986 index
= GetIndexIntoMasterTable(COMMAND
, TV1OutputControl
);
987 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
988 index
= GetIndexIntoMasterTable(COMMAND
, CV1OutputControl
);
990 index
= GetIndexIntoMasterTable(COMMAND
, DAC1OutputControl
);
992 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
993 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
994 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
995 index
= GetIndexIntoMasterTable(COMMAND
, TV1OutputControl
);
996 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
997 index
= GetIndexIntoMasterTable(COMMAND
, CV1OutputControl
);
999 index
= GetIndexIntoMasterTable(COMMAND
, DAC2OutputControl
);
1005 case DRM_MODE_DPMS_ON
:
1006 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT
, 0, 0);
1008 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
1009 dp_link_train(encoder
, connector
);
1012 case DRM_MODE_DPMS_STANDBY
:
1013 case DRM_MODE_DPMS_SUSPEND
:
1014 case DRM_MODE_DPMS_OFF
:
1015 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT
, 0, 0);
1020 case DRM_MODE_DPMS_ON
:
1021 args
.ucAction
= ATOM_ENABLE
;
1023 case DRM_MODE_DPMS_STANDBY
:
1024 case DRM_MODE_DPMS_SUSPEND
:
1025 case DRM_MODE_DPMS_OFF
:
1026 args
.ucAction
= ATOM_DISABLE
;
1029 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1031 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
1034 union crtc_sourc_param
{
1035 SELECT_CRTC_SOURCE_PS_ALLOCATION v1
;
1036 SELECT_CRTC_SOURCE_PARAMETERS_V2 v2
;
1040 atombios_set_encoder_crtc_source(struct drm_encoder
*encoder
)
1042 struct drm_device
*dev
= encoder
->dev
;
1043 struct radeon_device
*rdev
= dev
->dev_private
;
1044 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1045 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1046 union crtc_sourc_param args
;
1047 int index
= GetIndexIntoMasterTable(COMMAND
, SelectCRTC_Source
);
1050 memset(&args
, 0, sizeof(args
));
1052 atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
);
1059 if (ASIC_IS_AVIVO(rdev
))
1060 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
;
1062 if (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_DAC1
) {
1063 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
;
1065 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
<< 2;
1068 switch (radeon_encoder
->encoder_id
) {
1069 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1070 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
1071 args
.v1
.ucDevice
= ATOM_DEVICE_DFP1_INDEX
;
1073 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1074 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
1075 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
)
1076 args
.v1
.ucDevice
= ATOM_DEVICE_LCD1_INDEX
;
1078 args
.v1
.ucDevice
= ATOM_DEVICE_DFP3_INDEX
;
1080 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1081 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
1082 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1083 args
.v1
.ucDevice
= ATOM_DEVICE_DFP2_INDEX
;
1085 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1086 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1087 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1088 args
.v1
.ucDevice
= ATOM_DEVICE_TV1_INDEX
;
1089 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1090 args
.v1
.ucDevice
= ATOM_DEVICE_CV_INDEX
;
1092 args
.v1
.ucDevice
= ATOM_DEVICE_CRT1_INDEX
;
1094 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1095 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1096 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1097 args
.v1
.ucDevice
= ATOM_DEVICE_TV1_INDEX
;
1098 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1099 args
.v1
.ucDevice
= ATOM_DEVICE_CV_INDEX
;
1101 args
.v1
.ucDevice
= ATOM_DEVICE_CRT2_INDEX
;
1106 args
.v2
.ucCRTC
= radeon_crtc
->crtc_id
;
1107 args
.v2
.ucEncodeMode
= atombios_get_encoder_mode(encoder
);
1108 switch (radeon_encoder
->encoder_id
) {
1109 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1110 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1111 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1112 if (ASIC_IS_DCE32(rdev
)) {
1113 if (radeon_crtc
->crtc_id
)
1114 args
.v2
.ucEncoderID
= ASIC_INT_DIG2_ENCODER_ID
;
1116 args
.v2
.ucEncoderID
= ASIC_INT_DIG1_ENCODER_ID
;
1118 struct drm_connector
*connector
;
1119 struct radeon_connector
*radeon_connector
;
1120 struct radeon_connector_atom_dig
*dig_connector
;
1122 connector
= radeon_get_connector_for_encoder(encoder
);
1125 radeon_connector
= to_radeon_connector(connector
);
1126 if (!radeon_connector
->con_priv
)
1128 dig_connector
= radeon_connector
->con_priv
;
1130 /* XXX doesn't really matter which dig encoder we pick as long as it's
1131 * not already in use
1133 if (dig_connector
->linkb
)
1134 args
.v2
.ucEncoderID
= ASIC_INT_DIG2_ENCODER_ID
;
1136 args
.v2
.ucEncoderID
= ASIC_INT_DIG1_ENCODER_ID
;
1139 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1140 args
.v2
.ucEncoderID
= ASIC_INT_DVO_ENCODER_ID
;
1142 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1143 /* Only dig2 encoder can drive LVTMA */
1144 args
.v2
.ucEncoderID
= ASIC_INT_DIG2_ENCODER_ID
;
1146 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1147 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1148 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1149 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1150 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1152 args
.v2
.ucEncoderID
= ASIC_INT_DAC1_ENCODER_ID
;
1154 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1155 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1156 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1157 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1158 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1160 args
.v2
.ucEncoderID
= ASIC_INT_DAC2_ENCODER_ID
;
1167 DRM_ERROR("Unknown table version: %d, %d\n", frev
, crev
);
1171 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1175 atombios_apply_encoder_quirks(struct drm_encoder
*encoder
,
1176 struct drm_display_mode
*mode
)
1178 struct drm_device
*dev
= encoder
->dev
;
1179 struct radeon_device
*rdev
= dev
->dev_private
;
1180 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1181 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1183 /* Funky macbooks */
1184 if ((dev
->pdev
->device
== 0x71C5) &&
1185 (dev
->pdev
->subsystem_vendor
== 0x106b) &&
1186 (dev
->pdev
->subsystem_device
== 0x0080)) {
1187 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) {
1188 uint32_t lvtma_bit_depth_control
= RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL
);
1190 lvtma_bit_depth_control
&= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN
;
1191 lvtma_bit_depth_control
&= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN
;
1193 WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL
, lvtma_bit_depth_control
);
1197 /* set scaler clears this on some chips */
1198 if (!(radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))) {
1199 if (ASIC_IS_AVIVO(rdev
) && (mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
1200 WREG32(AVIVO_D1MODE_DATA_FORMAT
+ radeon_crtc
->crtc_offset
,
1201 AVIVO_D1MODE_INTERLEAVE_EN
);
1206 radeon_atom_encoder_mode_set(struct drm_encoder
*encoder
,
1207 struct drm_display_mode
*mode
,
1208 struct drm_display_mode
*adjusted_mode
)
1210 struct drm_device
*dev
= encoder
->dev
;
1211 struct radeon_device
*rdev
= dev
->dev_private
;
1212 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1213 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1215 if (radeon_encoder
->active_device
&
1216 (ATOM_DEVICE_DFP_SUPPORT
| ATOM_DEVICE_LCD_SUPPORT
)) {
1217 if (radeon_encoder
->enc_priv
) {
1218 struct radeon_encoder_atom_dig
*dig
;
1220 dig
= radeon_encoder
->enc_priv
;
1221 dig
->dig_block
= radeon_crtc
->crtc_id
;
1224 radeon_encoder
->pixel_clock
= adjusted_mode
->clock
;
1226 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1227 atombios_set_encoder_crtc_source(encoder
);
1229 if (ASIC_IS_AVIVO(rdev
)) {
1230 if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
| ATOM_DEVICE_TV_SUPPORT
))
1231 atombios_yuv_setup(encoder
, true);
1233 atombios_yuv_setup(encoder
, false);
1236 switch (radeon_encoder
->encoder_id
) {
1237 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1238 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
1239 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1240 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
1241 atombios_digital_setup(encoder
, PANEL_ENCODER_ACTION_ENABLE
);
1243 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1244 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1245 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1246 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1247 /* disable the encoder and transmitter */
1248 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE
, 0, 0);
1249 atombios_dig_encoder_setup(encoder
, ATOM_DISABLE
);
1251 /* setup and enable the encoder and transmitter */
1252 atombios_dig_encoder_setup(encoder
, ATOM_ENABLE
);
1253 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_INIT
, 0, 0);
1254 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_SETUP
, 0, 0);
1255 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_ENABLE
, 0, 0);
1257 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
1258 atombios_ddia_setup(encoder
, ATOM_ENABLE
);
1260 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1261 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1262 atombios_external_tmds_setup(encoder
, ATOM_ENABLE
);
1264 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1265 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1266 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1267 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1268 atombios_dac_setup(encoder
, ATOM_ENABLE
);
1269 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
))
1270 atombios_tv_setup(encoder
, ATOM_ENABLE
);
1273 atombios_apply_encoder_quirks(encoder
, adjusted_mode
);
1275 r600_hdmi_setmode(encoder
, adjusted_mode
);
1279 atombios_dac_load_detect(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
1281 struct drm_device
*dev
= encoder
->dev
;
1282 struct radeon_device
*rdev
= dev
->dev_private
;
1283 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1284 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1286 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
|
1287 ATOM_DEVICE_CV_SUPPORT
|
1288 ATOM_DEVICE_CRT_SUPPORT
)) {
1289 DAC_LOAD_DETECTION_PS_ALLOCATION args
;
1290 int index
= GetIndexIntoMasterTable(COMMAND
, DAC_LoadDetection
);
1293 memset(&args
, 0, sizeof(args
));
1295 atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
);
1297 args
.sDacload
.ucMisc
= 0;
1299 if ((radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_DAC1
) ||
1300 (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
))
1301 args
.sDacload
.ucDacType
= ATOM_DAC_A
;
1303 args
.sDacload
.ucDacType
= ATOM_DAC_B
;
1305 if (radeon_connector
->devices
& ATOM_DEVICE_CRT1_SUPPORT
)
1306 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT
);
1307 else if (radeon_connector
->devices
& ATOM_DEVICE_CRT2_SUPPORT
)
1308 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT
);
1309 else if (radeon_connector
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
1310 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CV_SUPPORT
);
1312 args
.sDacload
.ucMisc
= DAC_LOAD_MISC_YPrPb
;
1313 } else if (radeon_connector
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
1314 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT
);
1316 args
.sDacload
.ucMisc
= DAC_LOAD_MISC_YPrPb
;
1319 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1326 static enum drm_connector_status
1327 radeon_atom_dac_detect(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
1329 struct drm_device
*dev
= encoder
->dev
;
1330 struct radeon_device
*rdev
= dev
->dev_private
;
1331 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1332 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1333 uint32_t bios_0_scratch
;
1335 if (!atombios_dac_load_detect(encoder
, connector
)) {
1336 DRM_DEBUG("detect returned false \n");
1337 return connector_status_unknown
;
1340 if (rdev
->family
>= CHIP_R600
)
1341 bios_0_scratch
= RREG32(R600_BIOS_0_SCRATCH
);
1343 bios_0_scratch
= RREG32(RADEON_BIOS_0_SCRATCH
);
1345 DRM_DEBUG("Bios 0 scratch %x %08x\n", bios_0_scratch
, radeon_encoder
->devices
);
1346 if (radeon_connector
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) {
1347 if (bios_0_scratch
& ATOM_S0_CRT1_MASK
)
1348 return connector_status_connected
;
1350 if (radeon_connector
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) {
1351 if (bios_0_scratch
& ATOM_S0_CRT2_MASK
)
1352 return connector_status_connected
;
1354 if (radeon_connector
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
1355 if (bios_0_scratch
& (ATOM_S0_CV_MASK
|ATOM_S0_CV_MASK_A
))
1356 return connector_status_connected
;
1358 if (radeon_connector
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
1359 if (bios_0_scratch
& (ATOM_S0_TV1_COMPOSITE
| ATOM_S0_TV1_COMPOSITE_A
))
1360 return connector_status_connected
; /* CTV */
1361 else if (bios_0_scratch
& (ATOM_S0_TV1_SVIDEO
| ATOM_S0_TV1_SVIDEO_A
))
1362 return connector_status_connected
; /* STV */
1364 return connector_status_disconnected
;
1367 static void radeon_atom_encoder_prepare(struct drm_encoder
*encoder
)
1369 radeon_atom_output_lock(encoder
, true);
1370 radeon_atom_encoder_dpms(encoder
, DRM_MODE_DPMS_OFF
);
1373 static void radeon_atom_encoder_commit(struct drm_encoder
*encoder
)
1375 radeon_atom_encoder_dpms(encoder
, DRM_MODE_DPMS_ON
);
1376 radeon_atom_output_lock(encoder
, false);
1379 static void radeon_atom_encoder_disable(struct drm_encoder
*encoder
)
1381 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1382 radeon_atom_encoder_dpms(encoder
, DRM_MODE_DPMS_OFF
);
1383 radeon_encoder
->active_device
= 0;
1386 static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs
= {
1387 .dpms
= radeon_atom_encoder_dpms
,
1388 .mode_fixup
= radeon_atom_mode_fixup
,
1389 .prepare
= radeon_atom_encoder_prepare
,
1390 .mode_set
= radeon_atom_encoder_mode_set
,
1391 .commit
= radeon_atom_encoder_commit
,
1392 .disable
= radeon_atom_encoder_disable
,
1393 /* no detect for TMDS/LVDS yet */
1396 static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs
= {
1397 .dpms
= radeon_atom_encoder_dpms
,
1398 .mode_fixup
= radeon_atom_mode_fixup
,
1399 .prepare
= radeon_atom_encoder_prepare
,
1400 .mode_set
= radeon_atom_encoder_mode_set
,
1401 .commit
= radeon_atom_encoder_commit
,
1402 .detect
= radeon_atom_dac_detect
,
1405 void radeon_enc_destroy(struct drm_encoder
*encoder
)
1407 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1408 kfree(radeon_encoder
->enc_priv
);
1409 drm_encoder_cleanup(encoder
);
1410 kfree(radeon_encoder
);
1413 static const struct drm_encoder_funcs radeon_atom_enc_funcs
= {
1414 .destroy
= radeon_enc_destroy
,
1417 struct radeon_encoder_atom_dac
*
1418 radeon_atombios_set_dac_info(struct radeon_encoder
*radeon_encoder
)
1420 struct radeon_encoder_atom_dac
*dac
= kzalloc(sizeof(struct radeon_encoder_atom_dac
), GFP_KERNEL
);
1425 dac
->tv_std
= TV_STD_NTSC
;
1429 struct radeon_encoder_atom_dig
*
1430 radeon_atombios_set_dig_info(struct radeon_encoder
*radeon_encoder
)
1432 struct radeon_encoder_atom_dig
*dig
= kzalloc(sizeof(struct radeon_encoder_atom_dig
), GFP_KERNEL
);
1437 /* coherent mode by default */
1438 dig
->coherent_mode
= true;
1444 radeon_add_atom_encoder(struct drm_device
*dev
, uint32_t encoder_id
, uint32_t supported_device
)
1446 struct radeon_device
*rdev
= dev
->dev_private
;
1447 struct drm_encoder
*encoder
;
1448 struct radeon_encoder
*radeon_encoder
;
1450 /* see if we already added it */
1451 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
1452 radeon_encoder
= to_radeon_encoder(encoder
);
1453 if (radeon_encoder
->encoder_id
== encoder_id
) {
1454 radeon_encoder
->devices
|= supported_device
;
1461 radeon_encoder
= kzalloc(sizeof(struct radeon_encoder
), GFP_KERNEL
);
1462 if (!radeon_encoder
)
1465 encoder
= &radeon_encoder
->base
;
1466 if (rdev
->flags
& RADEON_SINGLE_CRTC
)
1467 encoder
->possible_crtcs
= 0x1;
1469 encoder
->possible_crtcs
= 0x3;
1471 radeon_encoder
->enc_priv
= NULL
;
1473 radeon_encoder
->encoder_id
= encoder_id
;
1474 radeon_encoder
->devices
= supported_device
;
1475 radeon_encoder
->rmx_type
= RMX_OFF
;
1477 switch (radeon_encoder
->encoder_id
) {
1478 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1479 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1480 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
1481 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
1482 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
1483 radeon_encoder
->rmx_type
= RMX_FULL
;
1484 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_LVDS
);
1485 radeon_encoder
->enc_priv
= radeon_atombios_get_lvds_info(radeon_encoder
);
1487 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
1488 radeon_encoder
->enc_priv
= radeon_atombios_set_dig_info(radeon_encoder
);
1490 drm_encoder_helper_add(encoder
, &radeon_atom_dig_helper_funcs
);
1492 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1493 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_DAC
);
1494 drm_encoder_helper_add(encoder
, &radeon_atom_dac_helper_funcs
);
1496 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1497 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1498 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1499 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TVDAC
);
1500 radeon_encoder
->enc_priv
= radeon_atombios_set_dac_info(radeon_encoder
);
1501 drm_encoder_helper_add(encoder
, &radeon_atom_dac_helper_funcs
);
1503 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1504 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1505 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
1506 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1507 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1508 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1509 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1510 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
1511 radeon_encoder
->rmx_type
= RMX_FULL
;
1512 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_LVDS
);
1513 radeon_encoder
->enc_priv
= radeon_atombios_get_lvds_info(radeon_encoder
);
1515 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
1516 radeon_encoder
->enc_priv
= radeon_atombios_set_dig_info(radeon_encoder
);
1518 drm_encoder_helper_add(encoder
, &radeon_atom_dig_helper_funcs
);
1522 r600_hdmi_init(encoder
);