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
;
35 radeon_get_encoder_id(struct drm_device
*dev
, uint32_t supported_device
, uint8_t dac
)
37 struct radeon_device
*rdev
= dev
->dev_private
;
40 switch (supported_device
) {
41 case ATOM_DEVICE_CRT1_SUPPORT
:
42 case ATOM_DEVICE_TV1_SUPPORT
:
43 case ATOM_DEVICE_TV2_SUPPORT
:
44 case ATOM_DEVICE_CRT2_SUPPORT
:
45 case ATOM_DEVICE_CV_SUPPORT
:
48 if ((rdev
->family
== CHIP_RS300
) ||
49 (rdev
->family
== CHIP_RS400
) ||
50 (rdev
->family
== CHIP_RS480
))
51 ret
= ENCODER_OBJECT_ID_INTERNAL_DAC2
;
52 else if (ASIC_IS_AVIVO(rdev
))
53 ret
= ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
;
55 ret
= ENCODER_OBJECT_ID_INTERNAL_DAC1
;
58 if (ASIC_IS_AVIVO(rdev
))
59 ret
= ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
;
61 /*if (rdev->family == CHIP_R200)
62 ret = ENCODER_OBJECT_ID_INTERNAL_DVO1;
64 ret
= ENCODER_OBJECT_ID_INTERNAL_DAC2
;
67 case 3: /* external dac */
68 if (ASIC_IS_AVIVO(rdev
))
69 ret
= ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
;
71 ret
= ENCODER_OBJECT_ID_INTERNAL_DVO1
;
75 case ATOM_DEVICE_LCD1_SUPPORT
:
76 if (ASIC_IS_AVIVO(rdev
))
77 ret
= ENCODER_OBJECT_ID_INTERNAL_LVTM1
;
79 ret
= ENCODER_OBJECT_ID_INTERNAL_LVDS
;
81 case ATOM_DEVICE_DFP1_SUPPORT
:
82 if ((rdev
->family
== CHIP_RS300
) ||
83 (rdev
->family
== CHIP_RS400
) ||
84 (rdev
->family
== CHIP_RS480
))
85 ret
= ENCODER_OBJECT_ID_INTERNAL_DVO1
;
86 else if (ASIC_IS_AVIVO(rdev
))
87 ret
= ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
;
89 ret
= ENCODER_OBJECT_ID_INTERNAL_TMDS1
;
91 case ATOM_DEVICE_LCD2_SUPPORT
:
92 case ATOM_DEVICE_DFP2_SUPPORT
:
93 if ((rdev
->family
== CHIP_RS600
) ||
94 (rdev
->family
== CHIP_RS690
) ||
95 (rdev
->family
== CHIP_RS740
))
96 ret
= ENCODER_OBJECT_ID_INTERNAL_DDI
;
97 else if (ASIC_IS_AVIVO(rdev
))
98 ret
= ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
;
100 ret
= ENCODER_OBJECT_ID_INTERNAL_DVO1
;
102 case ATOM_DEVICE_DFP3_SUPPORT
:
103 ret
= ENCODER_OBJECT_ID_INTERNAL_LVTM1
;
111 radeon_link_encoder_connector(struct drm_device
*dev
)
113 struct drm_connector
*connector
;
114 struct radeon_connector
*radeon_connector
;
115 struct drm_encoder
*encoder
;
116 struct radeon_encoder
*radeon_encoder
;
118 /* walk the list and link encoders to connectors */
119 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
120 radeon_connector
= to_radeon_connector(connector
);
121 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
122 radeon_encoder
= to_radeon_encoder(encoder
);
123 if (radeon_encoder
->devices
& radeon_connector
->devices
)
124 drm_mode_connector_attach_encoder(connector
, encoder
);
129 static struct drm_connector
*
130 radeon_get_connector_for_encoder(struct drm_encoder
*encoder
)
132 struct drm_device
*dev
= encoder
->dev
;
133 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
134 struct drm_connector
*connector
;
135 struct radeon_connector
*radeon_connector
;
137 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
138 radeon_connector
= to_radeon_connector(connector
);
139 if (radeon_encoder
->devices
& radeon_connector
->devices
)
145 /* used for both atom and legacy */
146 void radeon_rmx_mode_fixup(struct drm_encoder
*encoder
,
147 struct drm_display_mode
*mode
,
148 struct drm_display_mode
*adjusted_mode
)
150 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
151 struct drm_device
*dev
= encoder
->dev
;
152 struct radeon_device
*rdev
= dev
->dev_private
;
153 struct radeon_native_mode
*native_mode
= &radeon_encoder
->native_mode
;
155 if (mode
->hdisplay
< native_mode
->panel_xres
||
156 mode
->vdisplay
< native_mode
->panel_yres
) {
157 if (ASIC_IS_AVIVO(rdev
)) {
158 adjusted_mode
->hdisplay
= native_mode
->panel_xres
;
159 adjusted_mode
->vdisplay
= native_mode
->panel_yres
;
160 adjusted_mode
->htotal
= native_mode
->panel_xres
+ native_mode
->hblank
;
161 adjusted_mode
->hsync_start
= native_mode
->panel_xres
+ native_mode
->hoverplus
;
162 adjusted_mode
->hsync_end
= adjusted_mode
->hsync_start
+ native_mode
->hsync_width
;
163 adjusted_mode
->vtotal
= native_mode
->panel_yres
+ native_mode
->vblank
;
164 adjusted_mode
->vsync_start
= native_mode
->panel_yres
+ native_mode
->voverplus
;
165 adjusted_mode
->vsync_end
= adjusted_mode
->vsync_start
+ native_mode
->vsync_width
;
166 /* update crtc values */
167 drm_mode_set_crtcinfo(adjusted_mode
, CRTC_INTERLACE_HALVE_V
);
168 /* adjust crtc values */
169 adjusted_mode
->crtc_hdisplay
= native_mode
->panel_xres
;
170 adjusted_mode
->crtc_vdisplay
= native_mode
->panel_yres
;
171 adjusted_mode
->crtc_htotal
= adjusted_mode
->crtc_hdisplay
+ native_mode
->hblank
;
172 adjusted_mode
->crtc_hsync_start
= adjusted_mode
->crtc_hdisplay
+ native_mode
->hoverplus
;
173 adjusted_mode
->crtc_hsync_end
= adjusted_mode
->crtc_hsync_start
+ native_mode
->hsync_width
;
174 adjusted_mode
->crtc_vtotal
= adjusted_mode
->crtc_vdisplay
+ native_mode
->vblank
;
175 adjusted_mode
->crtc_vsync_start
= adjusted_mode
->crtc_vdisplay
+ native_mode
->voverplus
;
176 adjusted_mode
->crtc_vsync_end
= adjusted_mode
->crtc_vsync_start
+ native_mode
->vsync_width
;
178 adjusted_mode
->htotal
= native_mode
->panel_xres
+ native_mode
->hblank
;
179 adjusted_mode
->hsync_start
= native_mode
->panel_xres
+ native_mode
->hoverplus
;
180 adjusted_mode
->hsync_end
= adjusted_mode
->hsync_start
+ native_mode
->hsync_width
;
181 adjusted_mode
->vtotal
= native_mode
->panel_yres
+ native_mode
->vblank
;
182 adjusted_mode
->vsync_start
= native_mode
->panel_yres
+ native_mode
->voverplus
;
183 adjusted_mode
->vsync_end
= adjusted_mode
->vsync_start
+ native_mode
->vsync_width
;
184 /* update crtc values */
185 drm_mode_set_crtcinfo(adjusted_mode
, CRTC_INTERLACE_HALVE_V
);
186 /* adjust crtc values */
187 adjusted_mode
->crtc_htotal
= adjusted_mode
->crtc_hdisplay
+ native_mode
->hblank
;
188 adjusted_mode
->crtc_hsync_start
= adjusted_mode
->crtc_hdisplay
+ native_mode
->hoverplus
;
189 adjusted_mode
->crtc_hsync_end
= adjusted_mode
->crtc_hsync_start
+ native_mode
->hsync_width
;
190 adjusted_mode
->crtc_vtotal
= adjusted_mode
->crtc_vdisplay
+ native_mode
->vblank
;
191 adjusted_mode
->crtc_vsync_start
= adjusted_mode
->crtc_vdisplay
+ native_mode
->voverplus
;
192 adjusted_mode
->crtc_vsync_end
= adjusted_mode
->crtc_vsync_start
+ native_mode
->vsync_width
;
194 adjusted_mode
->flags
= native_mode
->flags
;
195 adjusted_mode
->clock
= native_mode
->dotclock
;
200 static bool radeon_atom_mode_fixup(struct drm_encoder
*encoder
,
201 struct drm_display_mode
*mode
,
202 struct drm_display_mode
*adjusted_mode
)
204 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
206 drm_mode_set_crtcinfo(adjusted_mode
, 0);
208 if (radeon_encoder
->rmx_type
!= RMX_OFF
)
209 radeon_rmx_mode_fixup(encoder
, mode
, adjusted_mode
);
212 if ((mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
213 && (mode
->crtc_vsync_start
< (mode
->crtc_vdisplay
+ 2)))
214 adjusted_mode
->crtc_vsync_start
= adjusted_mode
->crtc_vdisplay
+ 2;
220 atombios_dac_setup(struct drm_encoder
*encoder
, int action
)
222 struct drm_device
*dev
= encoder
->dev
;
223 struct radeon_device
*rdev
= dev
->dev_private
;
224 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
225 DAC_ENCODER_CONTROL_PS_ALLOCATION args
;
226 int index
= 0, num
= 0;
227 /* fixme - fill in enc_priv for atom dac */
228 enum radeon_tv_std tv_std
= TV_STD_NTSC
;
230 memset(&args
, 0, sizeof(args
));
232 switch (radeon_encoder
->encoder_id
) {
233 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
234 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
235 index
= GetIndexIntoMasterTable(COMMAND
, DAC1EncoderControl
);
238 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
239 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
240 index
= GetIndexIntoMasterTable(COMMAND
, DAC2EncoderControl
);
245 args
.ucAction
= action
;
247 if (radeon_encoder
->devices
& (ATOM_DEVICE_CRT_SUPPORT
))
248 args
.ucDacStandard
= ATOM_DAC1_PS2
;
249 else if (radeon_encoder
->devices
& (ATOM_DEVICE_CV_SUPPORT
))
250 args
.ucDacStandard
= ATOM_DAC1_CV
;
255 case TV_STD_SCART_PAL
:
258 args
.ucDacStandard
= ATOM_DAC1_PAL
;
264 args
.ucDacStandard
= ATOM_DAC1_NTSC
;
268 args
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
270 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
275 atombios_tv_setup(struct drm_encoder
*encoder
, int action
)
277 struct drm_device
*dev
= encoder
->dev
;
278 struct radeon_device
*rdev
= dev
->dev_private
;
279 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
280 TV_ENCODER_CONTROL_PS_ALLOCATION args
;
282 /* fixme - fill in enc_priv for atom dac */
283 enum radeon_tv_std tv_std
= TV_STD_NTSC
;
285 memset(&args
, 0, sizeof(args
));
287 index
= GetIndexIntoMasterTable(COMMAND
, TVEncoderControl
);
289 args
.sTVEncoder
.ucAction
= action
;
291 if (radeon_encoder
->devices
& (ATOM_DEVICE_CV_SUPPORT
))
292 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_CV
;
296 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSC
;
299 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL
;
302 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PALM
;
305 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL60
;
308 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSCJ
;
310 case TV_STD_SCART_PAL
:
311 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL
; /* ??? */
314 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_SECAM
;
317 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PALCN
;
320 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSC
;
325 args
.sTVEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
327 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
332 atombios_external_tmds_setup(struct drm_encoder
*encoder
, int action
)
334 struct drm_device
*dev
= encoder
->dev
;
335 struct radeon_device
*rdev
= dev
->dev_private
;
336 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
337 ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION args
;
340 memset(&args
, 0, sizeof(args
));
342 index
= GetIndexIntoMasterTable(COMMAND
, DVOEncoderControl
);
344 args
.sXTmdsEncoder
.ucEnable
= action
;
346 if (radeon_encoder
->pixel_clock
> 165000)
347 args
.sXTmdsEncoder
.ucMisc
= PANEL_ENCODER_MISC_DUAL
;
349 /*if (pScrn->rgbBits == 8)*/
350 args
.sXTmdsEncoder
.ucMisc
|= (1 << 1);
352 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
357 atombios_ddia_setup(struct drm_encoder
*encoder
, int action
)
359 struct drm_device
*dev
= encoder
->dev
;
360 struct radeon_device
*rdev
= dev
->dev_private
;
361 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
362 DVO_ENCODER_CONTROL_PS_ALLOCATION args
;
365 memset(&args
, 0, sizeof(args
));
367 index
= GetIndexIntoMasterTable(COMMAND
, DVOEncoderControl
);
369 args
.sDVOEncoder
.ucAction
= action
;
370 args
.sDVOEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
372 if (radeon_encoder
->pixel_clock
> 165000)
373 args
.sDVOEncoder
.usDevAttr
.sDigAttrib
.ucAttribute
= PANEL_ENCODER_MISC_DUAL
;
375 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
379 union lvds_encoder_control
{
380 LVDS_ENCODER_CONTROL_PS_ALLOCATION v1
;
381 LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2
;
385 atombios_digital_setup(struct drm_encoder
*encoder
, int action
)
387 struct drm_device
*dev
= encoder
->dev
;
388 struct radeon_device
*rdev
= dev
->dev_private
;
389 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
390 union lvds_encoder_control args
;
393 struct radeon_encoder_atom_dig
*dig
;
394 struct drm_connector
*connector
;
395 struct radeon_connector
*radeon_connector
;
396 struct radeon_connector_atom_dig
*dig_connector
;
398 connector
= radeon_get_connector_for_encoder(encoder
);
402 radeon_connector
= to_radeon_connector(connector
);
404 if (!radeon_encoder
->enc_priv
)
407 dig
= radeon_encoder
->enc_priv
;
409 if (!radeon_connector
->con_priv
)
412 dig_connector
= radeon_connector
->con_priv
;
414 memset(&args
, 0, sizeof(args
));
416 switch (radeon_encoder
->encoder_id
) {
417 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
418 index
= GetIndexIntoMasterTable(COMMAND
, LVDSEncoderControl
);
420 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
421 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
422 index
= GetIndexIntoMasterTable(COMMAND
, TMDS1EncoderControl
);
424 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
425 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
426 index
= GetIndexIntoMasterTable(COMMAND
, LVDSEncoderControl
);
428 index
= GetIndexIntoMasterTable(COMMAND
, TMDS2EncoderControl
);
432 atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
);
440 args
.v1
.ucAction
= action
;
441 if (drm_detect_hdmi_monitor((struct edid
*)connector
->edid_blob_ptr
))
442 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_HDMI_TYPE
;
443 args
.v1
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
444 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
445 if (dig
->lvds_misc
& (1 << 0))
446 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
447 if (dig
->lvds_misc
& (1 << 1))
448 args
.v1
.ucMisc
|= (1 << 1);
450 if (dig_connector
->linkb
)
451 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_TMDS_LINKB
;
452 if (radeon_encoder
->pixel_clock
> 165000)
453 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
454 /*if (pScrn->rgbBits == 8) */
455 args
.v1
.ucMisc
|= (1 << 1);
461 args
.v2
.ucAction
= action
;
463 if (dig
->coherent_mode
)
464 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_COHERENT
;
466 if (drm_detect_hdmi_monitor((struct edid
*)connector
->edid_blob_ptr
))
467 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_HDMI_TYPE
;
468 args
.v2
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
469 args
.v2
.ucTruncate
= 0;
470 args
.v2
.ucSpatial
= 0;
471 args
.v2
.ucTemporal
= 0;
473 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
474 if (dig
->lvds_misc
& (1 << 0))
475 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
476 if (dig
->lvds_misc
& (1 << 5)) {
477 args
.v2
.ucSpatial
= PANEL_ENCODER_SPATIAL_DITHER_EN
;
478 if (dig
->lvds_misc
& (1 << 1))
479 args
.v2
.ucSpatial
|= PANEL_ENCODER_SPATIAL_DITHER_DEPTH
;
481 if (dig
->lvds_misc
& (1 << 6)) {
482 args
.v2
.ucTemporal
= PANEL_ENCODER_TEMPORAL_DITHER_EN
;
483 if (dig
->lvds_misc
& (1 << 1))
484 args
.v2
.ucTemporal
|= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH
;
485 if (((dig
->lvds_misc
>> 2) & 0x3) == 2)
486 args
.v2
.ucTemporal
|= PANEL_ENCODER_TEMPORAL_LEVEL_4
;
489 if (dig_connector
->linkb
)
490 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_TMDS_LINKB
;
491 if (radeon_encoder
->pixel_clock
> 165000)
492 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
496 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
501 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
505 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
510 atombios_get_encoder_mode(struct drm_encoder
*encoder
)
512 struct drm_connector
*connector
;
513 struct radeon_connector
*radeon_connector
;
515 connector
= radeon_get_connector_for_encoder(encoder
);
519 radeon_connector
= to_radeon_connector(connector
);
521 switch (connector
->connector_type
) {
522 case DRM_MODE_CONNECTOR_DVII
:
523 if (drm_detect_hdmi_monitor((struct edid
*)connector
->edid_blob_ptr
))
524 return ATOM_ENCODER_MODE_HDMI
;
525 else if (radeon_connector
->use_digital
)
526 return ATOM_ENCODER_MODE_DVI
;
528 return ATOM_ENCODER_MODE_CRT
;
530 case DRM_MODE_CONNECTOR_DVID
:
531 case DRM_MODE_CONNECTOR_HDMIA
:
532 case DRM_MODE_CONNECTOR_HDMIB
:
534 if (drm_detect_hdmi_monitor((struct edid
*)connector
->edid_blob_ptr
))
535 return ATOM_ENCODER_MODE_HDMI
;
537 return ATOM_ENCODER_MODE_DVI
;
539 case DRM_MODE_CONNECTOR_LVDS
:
540 return ATOM_ENCODER_MODE_LVDS
;
542 case DRM_MODE_CONNECTOR_DisplayPort
:
543 /*if (radeon_output->MonType == MT_DP)
544 return ATOM_ENCODER_MODE_DP;
546 if (drm_detect_hdmi_monitor((struct edid
*)connector
->edid_blob_ptr
))
547 return ATOM_ENCODER_MODE_HDMI
;
549 return ATOM_ENCODER_MODE_DVI
;
551 case CONNECTOR_DVI_A
:
553 return ATOM_ENCODER_MODE_CRT
;
559 return ATOM_ENCODER_MODE_TV
;
560 /*return ATOM_ENCODER_MODE_CV;*/
566 atombios_dig_encoder_setup(struct drm_encoder
*encoder
, int action
)
568 struct drm_device
*dev
= encoder
->dev
;
569 struct radeon_device
*rdev
= dev
->dev_private
;
570 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
571 DIG_ENCODER_CONTROL_PS_ALLOCATION args
;
572 int index
= 0, num
= 0;
574 struct radeon_encoder_atom_dig
*dig
;
575 struct drm_connector
*connector
;
576 struct radeon_connector
*radeon_connector
;
577 struct radeon_connector_atom_dig
*dig_connector
;
579 connector
= radeon_get_connector_for_encoder(encoder
);
583 radeon_connector
= to_radeon_connector(connector
);
585 if (!radeon_connector
->con_priv
)
588 dig_connector
= radeon_connector
->con_priv
;
590 if (!radeon_encoder
->enc_priv
)
593 dig
= radeon_encoder
->enc_priv
;
595 memset(&args
, 0, sizeof(args
));
597 if (ASIC_IS_DCE32(rdev
)) {
599 index
= GetIndexIntoMasterTable(COMMAND
, DIG2EncoderControl
);
601 index
= GetIndexIntoMasterTable(COMMAND
, DIG1EncoderControl
);
602 num
= dig
->dig_block
+ 1;
604 switch (radeon_encoder
->encoder_id
) {
605 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
606 index
= GetIndexIntoMasterTable(COMMAND
, DIG1EncoderControl
);
609 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
610 index
= GetIndexIntoMasterTable(COMMAND
, DIG2EncoderControl
);
616 atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
);
618 args
.ucAction
= action
;
619 args
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
621 if (ASIC_IS_DCE32(rdev
)) {
622 switch (radeon_encoder
->encoder_id
) {
623 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
624 args
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER1
;
626 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
627 args
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER2
;
629 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
630 args
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER3
;
634 switch (radeon_encoder
->encoder_id
) {
635 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
636 args
.ucConfig
= ATOM_ENCODER_CONFIG_TRANSMITTER1
;
638 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
639 args
.ucConfig
= ATOM_ENCODER_CONFIG_TRANSMITTER2
;
644 if (radeon_encoder
->pixel_clock
> 165000) {
645 args
.ucConfig
|= ATOM_ENCODER_CONFIG_LINKA_B
;
648 if (dig_connector
->linkb
)
649 args
.ucConfig
|= ATOM_ENCODER_CONFIG_LINKB
;
651 args
.ucConfig
|= ATOM_ENCODER_CONFIG_LINKA
;
655 args
.ucEncoderMode
= atombios_get_encoder_mode(encoder
);
657 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
661 union dig_transmitter_control
{
662 DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1
;
663 DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2
;
667 atombios_dig_transmitter_setup(struct drm_encoder
*encoder
, int action
)
669 struct drm_device
*dev
= encoder
->dev
;
670 struct radeon_device
*rdev
= dev
->dev_private
;
671 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
672 union dig_transmitter_control args
;
673 int index
= 0, num
= 0;
675 struct radeon_encoder_atom_dig
*dig
;
676 struct drm_connector
*connector
;
677 struct radeon_connector
*radeon_connector
;
678 struct radeon_connector_atom_dig
*dig_connector
;
680 connector
= radeon_get_connector_for_encoder(encoder
);
684 radeon_connector
= to_radeon_connector(connector
);
686 if (!radeon_encoder
->enc_priv
)
689 dig
= radeon_encoder
->enc_priv
;
691 if (!radeon_connector
->con_priv
)
694 dig_connector
= radeon_connector
->con_priv
;
696 memset(&args
, 0, sizeof(args
));
698 if (ASIC_IS_DCE32(rdev
))
699 index
= GetIndexIntoMasterTable(COMMAND
, UNIPHYTransmitterControl
);
701 switch (radeon_encoder
->encoder_id
) {
702 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
703 index
= GetIndexIntoMasterTable(COMMAND
, DIG1TransmitterControl
);
705 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
706 index
= GetIndexIntoMasterTable(COMMAND
, DIG2TransmitterControl
);
711 atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
);
713 args
.v1
.ucAction
= action
;
715 if (ASIC_IS_DCE32(rdev
)) {
716 if (radeon_encoder
->pixel_clock
> 165000) {
717 args
.v2
.usPixelClock
= cpu_to_le16((radeon_encoder
->pixel_clock
* 10 * 2) / 100);
718 args
.v2
.acConfig
.fDualLinkConnector
= 1;
720 args
.v2
.usPixelClock
= cpu_to_le16((radeon_encoder
->pixel_clock
* 10 * 4) / 100);
723 args
.v2
.acConfig
.ucEncoderSel
= 1;
725 switch (radeon_encoder
->encoder_id
) {
726 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
727 args
.v2
.acConfig
.ucTransmitterSel
= 0;
730 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
731 args
.v2
.acConfig
.ucTransmitterSel
= 1;
734 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
735 args
.v2
.acConfig
.ucTransmitterSel
= 2;
740 if (radeon_encoder
->devices
& (ATOM_DEVICE_DFP_SUPPORT
)) {
741 if (dig
->coherent_mode
)
742 args
.v2
.acConfig
.fCoherentMode
= 1;
745 args
.v1
.ucConfig
= ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL
;
746 args
.v1
.usPixelClock
= cpu_to_le16((radeon_encoder
->pixel_clock
) / 10);
748 switch (radeon_encoder
->encoder_id
) {
749 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
750 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER
;
751 if (rdev
->flags
& RADEON_IS_IGP
) {
752 if (radeon_encoder
->pixel_clock
> 165000) {
753 args
.v1
.ucConfig
|= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK
|
754 ATOM_TRANSMITTER_CONFIG_LINKA_B
);
755 if (dig_connector
->igp_lane_info
& 0x3)
756 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_0_7
;
757 else if (dig_connector
->igp_lane_info
& 0xc)
758 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_8_15
;
760 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LINKA
;
761 if (dig_connector
->igp_lane_info
& 0x1)
762 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_0_3
;
763 else if (dig_connector
->igp_lane_info
& 0x2)
764 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_4_7
;
765 else if (dig_connector
->igp_lane_info
& 0x4)
766 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_8_11
;
767 else if (dig_connector
->igp_lane_info
& 0x8)
768 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_12_15
;
771 if (radeon_encoder
->pixel_clock
> 165000)
772 args
.v1
.ucConfig
|= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK
|
773 ATOM_TRANSMITTER_CONFIG_LINKA_B
|
774 ATOM_TRANSMITTER_CONFIG_LANE_0_7
);
776 if (dig_connector
->linkb
)
777 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LINKB
| ATOM_TRANSMITTER_CONFIG_LANE_0_3
;
779 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LINKA
| ATOM_TRANSMITTER_CONFIG_LANE_0_3
;
783 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
784 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER
;
785 if (radeon_encoder
->pixel_clock
> 165000)
786 args
.v1
.ucConfig
|= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK
|
787 ATOM_TRANSMITTER_CONFIG_LINKA_B
|
788 ATOM_TRANSMITTER_CONFIG_LANE_0_7
);
790 if (dig_connector
->linkb
)
791 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LINKB
| ATOM_TRANSMITTER_CONFIG_LANE_0_3
;
793 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LINKA
| ATOM_TRANSMITTER_CONFIG_LANE_0_3
;
798 if (radeon_encoder
->devices
& (ATOM_DEVICE_DFP_SUPPORT
)) {
799 if (dig
->coherent_mode
)
800 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_COHERENT
;
804 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
809 atombios_yuv_setup(struct drm_encoder
*encoder
, bool enable
)
811 struct drm_device
*dev
= encoder
->dev
;
812 struct radeon_device
*rdev
= dev
->dev_private
;
813 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
814 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
815 ENABLE_YUV_PS_ALLOCATION args
;
816 int index
= GetIndexIntoMasterTable(COMMAND
, EnableYUV
);
819 memset(&args
, 0, sizeof(args
));
821 if (rdev
->family
>= CHIP_R600
)
822 reg
= R600_BIOS_3_SCRATCH
;
824 reg
= RADEON_BIOS_3_SCRATCH
;
826 /* XXX: fix up scratch reg handling */
828 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
))
829 WREG32(reg
, (ATOM_S3_TV1_ACTIVE
|
830 (radeon_crtc
->crtc_id
<< 18)));
831 else if (radeon_encoder
->devices
& (ATOM_DEVICE_CV_SUPPORT
))
832 WREG32(reg
, (ATOM_S3_CV_ACTIVE
| (radeon_crtc
->crtc_id
<< 24)));
837 args
.ucEnable
= ATOM_ENABLE
;
838 args
.ucCRTC
= radeon_crtc
->crtc_id
;
840 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
846 radeon_atom_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
848 struct drm_device
*dev
= encoder
->dev
;
849 struct radeon_device
*rdev
= dev
->dev_private
;
850 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
851 DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args
;
855 memset(&args
, 0, sizeof(args
));
857 switch (radeon_encoder
->encoder_id
) {
858 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
859 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
860 index
= GetIndexIntoMasterTable(COMMAND
, TMDSAOutputControl
);
862 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
863 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
864 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
865 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
868 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
869 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
870 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
871 index
= GetIndexIntoMasterTable(COMMAND
, DVOOutputControl
);
873 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
874 index
= GetIndexIntoMasterTable(COMMAND
, LCD1OutputControl
);
876 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
877 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
878 index
= GetIndexIntoMasterTable(COMMAND
, LCD1OutputControl
);
880 index
= GetIndexIntoMasterTable(COMMAND
, LVTMAOutputControl
);
882 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
883 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
884 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
))
885 index
= GetIndexIntoMasterTable(COMMAND
, TV1OutputControl
);
886 else if (radeon_encoder
->devices
& (ATOM_DEVICE_CV_SUPPORT
))
887 index
= GetIndexIntoMasterTable(COMMAND
, CV1OutputControl
);
889 index
= GetIndexIntoMasterTable(COMMAND
, DAC1OutputControl
);
891 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
892 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
893 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
))
894 index
= GetIndexIntoMasterTable(COMMAND
, TV1OutputControl
);
895 else if (radeon_encoder
->devices
& (ATOM_DEVICE_CV_SUPPORT
))
896 index
= GetIndexIntoMasterTable(COMMAND
, CV1OutputControl
);
898 index
= GetIndexIntoMasterTable(COMMAND
, DAC2OutputControl
);
904 case DRM_MODE_DPMS_ON
:
905 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_ENABLE
);
907 case DRM_MODE_DPMS_STANDBY
:
908 case DRM_MODE_DPMS_SUSPEND
:
909 case DRM_MODE_DPMS_OFF
:
910 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE
);
915 case DRM_MODE_DPMS_ON
:
916 args
.ucAction
= ATOM_ENABLE
;
918 case DRM_MODE_DPMS_STANDBY
:
919 case DRM_MODE_DPMS_SUSPEND
:
920 case DRM_MODE_DPMS_OFF
:
921 args
.ucAction
= ATOM_DISABLE
;
924 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
926 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
929 union crtc_sourc_param
{
930 SELECT_CRTC_SOURCE_PS_ALLOCATION v1
;
931 SELECT_CRTC_SOURCE_PARAMETERS_V2 v2
;
935 atombios_set_encoder_crtc_source(struct drm_encoder
*encoder
)
937 struct drm_device
*dev
= encoder
->dev
;
938 struct radeon_device
*rdev
= dev
->dev_private
;
939 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
940 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
941 union crtc_sourc_param args
;
942 int index
= GetIndexIntoMasterTable(COMMAND
, SelectCRTC_Source
);
945 memset(&args
, 0, sizeof(args
));
947 atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
);
954 if (ASIC_IS_AVIVO(rdev
))
955 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
;
957 if (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_DAC1
) {
958 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
;
960 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
<< 2;
963 switch (radeon_encoder
->encoder_id
) {
964 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
965 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
966 args
.v1
.ucDevice
= ATOM_DEVICE_DFP1_INDEX
;
968 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
969 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
970 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
)
971 args
.v1
.ucDevice
= ATOM_DEVICE_LCD1_INDEX
;
973 args
.v1
.ucDevice
= ATOM_DEVICE_DFP3_INDEX
;
975 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
976 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
977 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
978 args
.v1
.ucDevice
= ATOM_DEVICE_DFP2_INDEX
;
980 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
981 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
982 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
))
983 args
.v1
.ucDevice
= ATOM_DEVICE_TV1_INDEX
;
984 else if (radeon_encoder
->devices
& (ATOM_DEVICE_CV_SUPPORT
))
985 args
.v1
.ucDevice
= ATOM_DEVICE_CV_INDEX
;
987 args
.v1
.ucDevice
= ATOM_DEVICE_CRT1_INDEX
;
989 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
990 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
991 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
))
992 args
.v1
.ucDevice
= ATOM_DEVICE_TV1_INDEX
;
993 else if (radeon_encoder
->devices
& (ATOM_DEVICE_CV_SUPPORT
))
994 args
.v1
.ucDevice
= ATOM_DEVICE_CV_INDEX
;
996 args
.v1
.ucDevice
= ATOM_DEVICE_CRT2_INDEX
;
1001 args
.v2
.ucCRTC
= radeon_crtc
->crtc_id
;
1002 args
.v2
.ucEncodeMode
= atombios_get_encoder_mode(encoder
);
1003 switch (radeon_encoder
->encoder_id
) {
1004 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1005 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1006 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1007 if (ASIC_IS_DCE32(rdev
)) {
1008 if (radeon_crtc
->crtc_id
)
1009 args
.v2
.ucEncoderID
= ASIC_INT_DIG2_ENCODER_ID
;
1011 args
.v2
.ucEncoderID
= ASIC_INT_DIG1_ENCODER_ID
;
1013 args
.v2
.ucEncoderID
= ASIC_INT_DIG1_ENCODER_ID
;
1015 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1016 args
.v2
.ucEncoderID
= ASIC_INT_DVO_ENCODER_ID
;
1018 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1019 args
.v2
.ucEncoderID
= ASIC_INT_DIG2_ENCODER_ID
;
1021 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1022 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
))
1023 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1024 else if (radeon_encoder
->devices
& (ATOM_DEVICE_CV_SUPPORT
))
1025 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1027 args
.v2
.ucEncoderID
= ASIC_INT_DAC1_ENCODER_ID
;
1029 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1030 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
))
1031 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1032 else if (radeon_encoder
->devices
& (ATOM_DEVICE_CV_SUPPORT
))
1033 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1035 args
.v2
.ucEncoderID
= ASIC_INT_DAC2_ENCODER_ID
;
1042 DRM_ERROR("Unknown table version: %d, %d\n", frev
, crev
);
1046 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1051 atombios_apply_encoder_quirks(struct drm_encoder
*encoder
,
1052 struct drm_display_mode
*mode
)
1054 struct drm_device
*dev
= encoder
->dev
;
1055 struct radeon_device
*rdev
= dev
->dev_private
;
1056 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1057 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1059 /* Funky macbooks */
1060 if ((dev
->pdev
->device
== 0x71C5) &&
1061 (dev
->pdev
->subsystem_vendor
== 0x106b) &&
1062 (dev
->pdev
->subsystem_device
== 0x0080)) {
1063 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) {
1064 uint32_t lvtma_bit_depth_control
= RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL
);
1066 lvtma_bit_depth_control
&= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN
;
1067 lvtma_bit_depth_control
&= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN
;
1069 WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL
, lvtma_bit_depth_control
);
1073 /* set scaler clears this on some chips */
1074 if (ASIC_IS_AVIVO(rdev
) && (mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
1075 WREG32(AVIVO_D1MODE_DATA_FORMAT
+ radeon_crtc
->crtc_offset
, AVIVO_D1MODE_INTERLEAVE_EN
);
1079 radeon_atom_encoder_mode_set(struct drm_encoder
*encoder
,
1080 struct drm_display_mode
*mode
,
1081 struct drm_display_mode
*adjusted_mode
)
1083 struct drm_device
*dev
= encoder
->dev
;
1084 struct radeon_device
*rdev
= dev
->dev_private
;
1085 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1086 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1088 if (radeon_encoder
->enc_priv
) {
1089 struct radeon_encoder_atom_dig
*dig
;
1091 dig
= radeon_encoder
->enc_priv
;
1092 dig
->dig_block
= radeon_crtc
->crtc_id
;
1094 radeon_encoder
->pixel_clock
= adjusted_mode
->clock
;
1096 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1097 atombios_set_encoder_crtc_source(encoder
);
1099 if (ASIC_IS_AVIVO(rdev
)) {
1100 if (radeon_encoder
->devices
& (ATOM_DEVICE_CV_SUPPORT
| ATOM_DEVICE_TV_SUPPORT
))
1101 atombios_yuv_setup(encoder
, true);
1103 atombios_yuv_setup(encoder
, false);
1106 switch (radeon_encoder
->encoder_id
) {
1107 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1108 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
1109 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1110 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
1111 atombios_digital_setup(encoder
, PANEL_ENCODER_ACTION_ENABLE
);
1113 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1114 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1115 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1116 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1117 /* disable the encoder and transmitter */
1118 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE
);
1119 atombios_dig_encoder_setup(encoder
, ATOM_DISABLE
);
1121 /* setup and enable the encoder and transmitter */
1122 atombios_dig_encoder_setup(encoder
, ATOM_ENABLE
);
1123 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_SETUP
);
1124 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_ENABLE
);
1126 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
1127 atombios_ddia_setup(encoder
, ATOM_ENABLE
);
1129 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1130 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1131 atombios_external_tmds_setup(encoder
, ATOM_ENABLE
);
1133 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1134 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1135 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1136 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1137 atombios_dac_setup(encoder
, ATOM_ENABLE
);
1138 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
))
1139 atombios_tv_setup(encoder
, ATOM_ENABLE
);
1142 atombios_apply_encoder_quirks(encoder
, adjusted_mode
);
1146 atombios_dac_load_detect(struct drm_encoder
*encoder
)
1148 struct drm_device
*dev
= encoder
->dev
;
1149 struct radeon_device
*rdev
= dev
->dev_private
;
1150 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1152 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
|
1153 ATOM_DEVICE_CV_SUPPORT
|
1154 ATOM_DEVICE_CRT_SUPPORT
)) {
1155 DAC_LOAD_DETECTION_PS_ALLOCATION args
;
1156 int index
= GetIndexIntoMasterTable(COMMAND
, DAC_LoadDetection
);
1159 memset(&args
, 0, sizeof(args
));
1161 atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
);
1163 args
.sDacload
.ucMisc
= 0;
1165 if ((radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_DAC1
) ||
1166 (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
))
1167 args
.sDacload
.ucDacType
= ATOM_DAC_A
;
1169 args
.sDacload
.ucDacType
= ATOM_DAC_B
;
1171 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT1_SUPPORT
)
1172 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT
);
1173 else if (radeon_encoder
->devices
& ATOM_DEVICE_CRT2_SUPPORT
)
1174 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT
);
1175 else if (radeon_encoder
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
1176 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CV_SUPPORT
);
1178 args
.sDacload
.ucMisc
= DAC_LOAD_MISC_YPrPb
;
1179 } else if (radeon_encoder
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
1180 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT
);
1182 args
.sDacload
.ucMisc
= DAC_LOAD_MISC_YPrPb
;
1185 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1192 static enum drm_connector_status
1193 radeon_atom_dac_detect(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
1195 struct drm_device
*dev
= encoder
->dev
;
1196 struct radeon_device
*rdev
= dev
->dev_private
;
1197 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1198 uint32_t bios_0_scratch
;
1200 if (!atombios_dac_load_detect(encoder
)) {
1201 DRM_DEBUG("detect returned false \n");
1202 return connector_status_unknown
;
1205 if (rdev
->family
>= CHIP_R600
)
1206 bios_0_scratch
= RREG32(R600_BIOS_0_SCRATCH
);
1208 bios_0_scratch
= RREG32(RADEON_BIOS_0_SCRATCH
);
1210 DRM_DEBUG("Bios 0 scratch %x\n", bios_0_scratch
);
1211 if (radeon_encoder
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) {
1212 if (bios_0_scratch
& ATOM_S0_CRT1_MASK
)
1213 return connector_status_connected
;
1214 } else if (radeon_encoder
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) {
1215 if (bios_0_scratch
& ATOM_S0_CRT2_MASK
)
1216 return connector_status_connected
;
1217 } else if (radeon_encoder
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
1218 if (bios_0_scratch
& (ATOM_S0_CV_MASK
|ATOM_S0_CV_MASK_A
))
1219 return connector_status_connected
;
1220 } else if (radeon_encoder
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
1221 if (bios_0_scratch
& (ATOM_S0_TV1_COMPOSITE
| ATOM_S0_TV1_COMPOSITE_A
))
1222 return connector_status_connected
; /* CTV */
1223 else if (bios_0_scratch
& (ATOM_S0_TV1_SVIDEO
| ATOM_S0_TV1_SVIDEO_A
))
1224 return connector_status_connected
; /* STV */
1226 return connector_status_disconnected
;
1229 static void radeon_atom_encoder_prepare(struct drm_encoder
*encoder
)
1231 radeon_atom_output_lock(encoder
, true);
1232 radeon_atom_encoder_dpms(encoder
, DRM_MODE_DPMS_OFF
);
1235 static void radeon_atom_encoder_commit(struct drm_encoder
*encoder
)
1237 radeon_atom_encoder_dpms(encoder
, DRM_MODE_DPMS_ON
);
1238 radeon_atom_output_lock(encoder
, false);
1241 static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs
= {
1242 .dpms
= radeon_atom_encoder_dpms
,
1243 .mode_fixup
= radeon_atom_mode_fixup
,
1244 .prepare
= radeon_atom_encoder_prepare
,
1245 .mode_set
= radeon_atom_encoder_mode_set
,
1246 .commit
= radeon_atom_encoder_commit
,
1247 /* no detect for TMDS/LVDS yet */
1250 static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs
= {
1251 .dpms
= radeon_atom_encoder_dpms
,
1252 .mode_fixup
= radeon_atom_mode_fixup
,
1253 .prepare
= radeon_atom_encoder_prepare
,
1254 .mode_set
= radeon_atom_encoder_mode_set
,
1255 .commit
= radeon_atom_encoder_commit
,
1256 .detect
= radeon_atom_dac_detect
,
1259 void radeon_enc_destroy(struct drm_encoder
*encoder
)
1261 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1262 kfree(radeon_encoder
->enc_priv
);
1263 drm_encoder_cleanup(encoder
);
1264 kfree(radeon_encoder
);
1267 static const struct drm_encoder_funcs radeon_atom_enc_funcs
= {
1268 .destroy
= radeon_enc_destroy
,
1271 struct radeon_encoder_atom_dig
*
1272 radeon_atombios_set_dig_info(struct radeon_encoder
*radeon_encoder
)
1274 struct radeon_encoder_atom_dig
*dig
= kzalloc(sizeof(struct radeon_encoder_atom_dig
), GFP_KERNEL
);
1279 /* coherent mode by default */
1280 dig
->coherent_mode
= true;
1286 radeon_add_atom_encoder(struct drm_device
*dev
, uint32_t encoder_id
, uint32_t supported_device
)
1288 struct drm_encoder
*encoder
;
1289 struct radeon_encoder
*radeon_encoder
;
1291 /* see if we already added it */
1292 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
1293 radeon_encoder
= to_radeon_encoder(encoder
);
1294 if (radeon_encoder
->encoder_id
== encoder_id
) {
1295 radeon_encoder
->devices
|= supported_device
;
1302 radeon_encoder
= kzalloc(sizeof(struct radeon_encoder
), GFP_KERNEL
);
1303 if (!radeon_encoder
)
1306 encoder
= &radeon_encoder
->base
;
1307 encoder
->possible_crtcs
= 0x3;
1308 encoder
->possible_clones
= 0;
1310 radeon_encoder
->enc_priv
= NULL
;
1312 radeon_encoder
->encoder_id
= encoder_id
;
1313 radeon_encoder
->devices
= supported_device
;
1314 radeon_encoder
->rmx_type
= RMX_OFF
;
1316 switch (radeon_encoder
->encoder_id
) {
1317 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1318 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1319 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
1320 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
1321 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
1322 radeon_encoder
->rmx_type
= RMX_FULL
;
1323 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_LVDS
);
1324 radeon_encoder
->enc_priv
= radeon_atombios_get_lvds_info(radeon_encoder
);
1326 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
1327 radeon_encoder
->enc_priv
= radeon_atombios_set_dig_info(radeon_encoder
);
1329 drm_encoder_helper_add(encoder
, &radeon_atom_dig_helper_funcs
);
1331 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1332 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_DAC
);
1333 drm_encoder_helper_add(encoder
, &radeon_atom_dac_helper_funcs
);
1335 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1336 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1337 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1338 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TVDAC
);
1339 drm_encoder_helper_add(encoder
, &radeon_atom_dac_helper_funcs
);
1341 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1342 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1343 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
1344 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1345 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1346 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1347 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1348 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
1349 radeon_encoder
->enc_priv
= radeon_atombios_set_dig_info(radeon_encoder
);
1350 drm_encoder_helper_add(encoder
, &radeon_atom_dig_helper_funcs
);