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_enum(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_INTERNAL_DAC2_ENUM_ID1
;
101 else if (ASIC_IS_AVIVO(rdev
))
102 ret
= ENCODER_INTERNAL_KLDSCP_DAC1_ENUM_ID1
;
104 ret
= ENCODER_INTERNAL_DAC1_ENUM_ID1
;
107 if (ASIC_IS_AVIVO(rdev
))
108 ret
= ENCODER_INTERNAL_KLDSCP_DAC2_ENUM_ID1
;
110 /*if (rdev->family == CHIP_R200)
111 ret = ENCODER_INTERNAL_DVO1_ENUM_ID1;
113 ret
= ENCODER_INTERNAL_DAC2_ENUM_ID1
;
116 case 3: /* external dac */
117 if (ASIC_IS_AVIVO(rdev
))
118 ret
= ENCODER_INTERNAL_KLDSCP_DVO1_ENUM_ID1
;
120 ret
= ENCODER_INTERNAL_DVO1_ENUM_ID1
;
124 case ATOM_DEVICE_LCD1_SUPPORT
:
125 if (ASIC_IS_AVIVO(rdev
))
126 ret
= ENCODER_INTERNAL_LVTM1_ENUM_ID1
;
128 ret
= ENCODER_INTERNAL_LVDS_ENUM_ID1
;
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_INTERNAL_DVO1_ENUM_ID1
;
135 else if (ASIC_IS_AVIVO(rdev
))
136 ret
= ENCODER_INTERNAL_KLDSCP_TMDS1_ENUM_ID1
;
138 ret
= ENCODER_INTERNAL_TMDS1_ENUM_ID1
;
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_INTERNAL_DDI_ENUM_ID1
;
146 else if (ASIC_IS_AVIVO(rdev
))
147 ret
= ENCODER_INTERNAL_KLDSCP_DVO1_ENUM_ID1
;
149 ret
= ENCODER_INTERNAL_DVO1_ENUM_ID1
;
151 case ATOM_DEVICE_DFP3_SUPPORT
:
152 ret
= ENCODER_INTERNAL_LVTM1_ENUM_ID1
;
159 static inline bool radeon_encoder_is_digital(struct drm_encoder
*encoder
)
161 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
162 switch (radeon_encoder
->encoder_id
) {
163 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
164 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
165 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
166 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
167 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
168 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
169 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
170 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
171 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
172 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
173 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
181 radeon_link_encoder_connector(struct drm_device
*dev
)
183 struct drm_connector
*connector
;
184 struct radeon_connector
*radeon_connector
;
185 struct drm_encoder
*encoder
;
186 struct radeon_encoder
*radeon_encoder
;
188 /* walk the list and link encoders to connectors */
189 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
190 radeon_connector
= to_radeon_connector(connector
);
191 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
192 radeon_encoder
= to_radeon_encoder(encoder
);
193 if (radeon_encoder
->devices
& radeon_connector
->devices
)
194 drm_mode_connector_attach_encoder(connector
, encoder
);
199 void radeon_encoder_set_active_device(struct drm_encoder
*encoder
)
201 struct drm_device
*dev
= encoder
->dev
;
202 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
203 struct drm_connector
*connector
;
205 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
206 if (connector
->encoder
== encoder
) {
207 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
208 radeon_encoder
->active_device
= radeon_encoder
->devices
& radeon_connector
->devices
;
209 DRM_DEBUG_KMS("setting active device to %08x from %08x %08x for encoder %d\n",
210 radeon_encoder
->active_device
, radeon_encoder
->devices
,
211 radeon_connector
->devices
, encoder
->encoder_type
);
216 struct drm_connector
*
217 radeon_get_connector_for_encoder(struct drm_encoder
*encoder
)
219 struct drm_device
*dev
= encoder
->dev
;
220 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
221 struct drm_connector
*connector
;
222 struct radeon_connector
*radeon_connector
;
224 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
225 radeon_connector
= to_radeon_connector(connector
);
226 if (radeon_encoder
->active_device
& radeon_connector
->devices
)
232 static struct drm_connector
*
233 radeon_get_connector_for_encoder_init(struct drm_encoder
*encoder
)
235 struct drm_device
*dev
= encoder
->dev
;
236 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
237 struct drm_connector
*connector
;
238 struct radeon_connector
*radeon_connector
;
240 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
241 radeon_connector
= to_radeon_connector(connector
);
242 if (radeon_encoder
->devices
& radeon_connector
->devices
)
248 struct drm_encoder
*radeon_atom_get_external_encoder(struct drm_encoder
*encoder
)
250 struct drm_device
*dev
= encoder
->dev
;
251 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
252 struct drm_encoder
*other_encoder
;
253 struct radeon_encoder
*other_radeon_encoder
;
255 if (radeon_encoder
->is_ext_encoder
)
258 list_for_each_entry(other_encoder
, &dev
->mode_config
.encoder_list
, head
) {
259 if (other_encoder
== encoder
)
261 other_radeon_encoder
= to_radeon_encoder(other_encoder
);
262 if (other_radeon_encoder
->is_ext_encoder
&&
263 (radeon_encoder
->devices
& other_radeon_encoder
->devices
))
264 return other_encoder
;
269 bool radeon_encoder_is_dp_bridge(struct drm_encoder
*encoder
)
271 struct drm_encoder
*other_encoder
= radeon_atom_get_external_encoder(encoder
);
274 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(other_encoder
);
276 switch (radeon_encoder
->encoder_id
) {
277 case ENCODER_OBJECT_ID_TRAVIS
:
278 case ENCODER_OBJECT_ID_NUTMEG
:
288 void radeon_panel_mode_fixup(struct drm_encoder
*encoder
,
289 struct drm_display_mode
*adjusted_mode
)
291 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
292 struct drm_device
*dev
= encoder
->dev
;
293 struct radeon_device
*rdev
= dev
->dev_private
;
294 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
295 unsigned hblank
= native_mode
->htotal
- native_mode
->hdisplay
;
296 unsigned vblank
= native_mode
->vtotal
- native_mode
->vdisplay
;
297 unsigned hover
= native_mode
->hsync_start
- native_mode
->hdisplay
;
298 unsigned vover
= native_mode
->vsync_start
- native_mode
->vdisplay
;
299 unsigned hsync_width
= native_mode
->hsync_end
- native_mode
->hsync_start
;
300 unsigned vsync_width
= native_mode
->vsync_end
- native_mode
->vsync_start
;
302 adjusted_mode
->clock
= native_mode
->clock
;
303 adjusted_mode
->flags
= native_mode
->flags
;
305 if (ASIC_IS_AVIVO(rdev
)) {
306 adjusted_mode
->hdisplay
= native_mode
->hdisplay
;
307 adjusted_mode
->vdisplay
= native_mode
->vdisplay
;
310 adjusted_mode
->htotal
= native_mode
->hdisplay
+ hblank
;
311 adjusted_mode
->hsync_start
= native_mode
->hdisplay
+ hover
;
312 adjusted_mode
->hsync_end
= adjusted_mode
->hsync_start
+ hsync_width
;
314 adjusted_mode
->vtotal
= native_mode
->vdisplay
+ vblank
;
315 adjusted_mode
->vsync_start
= native_mode
->vdisplay
+ vover
;
316 adjusted_mode
->vsync_end
= adjusted_mode
->vsync_start
+ vsync_width
;
318 drm_mode_set_crtcinfo(adjusted_mode
, CRTC_INTERLACE_HALVE_V
);
320 if (ASIC_IS_AVIVO(rdev
)) {
321 adjusted_mode
->crtc_hdisplay
= native_mode
->hdisplay
;
322 adjusted_mode
->crtc_vdisplay
= native_mode
->vdisplay
;
325 adjusted_mode
->crtc_htotal
= adjusted_mode
->crtc_hdisplay
+ hblank
;
326 adjusted_mode
->crtc_hsync_start
= adjusted_mode
->crtc_hdisplay
+ hover
;
327 adjusted_mode
->crtc_hsync_end
= adjusted_mode
->crtc_hsync_start
+ hsync_width
;
329 adjusted_mode
->crtc_vtotal
= adjusted_mode
->crtc_vdisplay
+ vblank
;
330 adjusted_mode
->crtc_vsync_start
= adjusted_mode
->crtc_vdisplay
+ vover
;
331 adjusted_mode
->crtc_vsync_end
= adjusted_mode
->crtc_vsync_start
+ vsync_width
;
335 static bool radeon_atom_mode_fixup(struct drm_encoder
*encoder
,
336 struct drm_display_mode
*mode
,
337 struct drm_display_mode
*adjusted_mode
)
339 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
340 struct drm_device
*dev
= encoder
->dev
;
341 struct radeon_device
*rdev
= dev
->dev_private
;
343 /* set the active encoder to connector routing */
344 radeon_encoder_set_active_device(encoder
);
345 drm_mode_set_crtcinfo(adjusted_mode
, 0);
348 if ((mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
349 && (mode
->crtc_vsync_start
< (mode
->crtc_vdisplay
+ 2)))
350 adjusted_mode
->crtc_vsync_start
= adjusted_mode
->crtc_vdisplay
+ 2;
352 /* get the native mode for LVDS */
353 if (radeon_encoder
->active_device
& (ATOM_DEVICE_LCD_SUPPORT
))
354 radeon_panel_mode_fixup(encoder
, adjusted_mode
);
356 /* get the native mode for TV */
357 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
)) {
358 struct radeon_encoder_atom_dac
*tv_dac
= radeon_encoder
->enc_priv
;
360 if (tv_dac
->tv_std
== TV_STD_NTSC
||
361 tv_dac
->tv_std
== TV_STD_NTSC_J
||
362 tv_dac
->tv_std
== TV_STD_PAL_M
)
363 radeon_atom_get_tv_timings(rdev
, 0, adjusted_mode
);
365 radeon_atom_get_tv_timings(rdev
, 1, adjusted_mode
);
369 if (ASIC_IS_DCE3(rdev
) &&
370 (radeon_encoder
->active_device
& (ATOM_DEVICE_DFP_SUPPORT
| ATOM_DEVICE_LCD_SUPPORT
))) {
371 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
372 radeon_dp_set_link_config(connector
, mode
);
379 atombios_dac_setup(struct drm_encoder
*encoder
, int action
)
381 struct drm_device
*dev
= encoder
->dev
;
382 struct radeon_device
*rdev
= dev
->dev_private
;
383 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
384 DAC_ENCODER_CONTROL_PS_ALLOCATION args
;
386 struct radeon_encoder_atom_dac
*dac_info
= radeon_encoder
->enc_priv
;
388 memset(&args
, 0, sizeof(args
));
390 switch (radeon_encoder
->encoder_id
) {
391 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
392 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
393 index
= GetIndexIntoMasterTable(COMMAND
, DAC1EncoderControl
);
395 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
396 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
397 index
= GetIndexIntoMasterTable(COMMAND
, DAC2EncoderControl
);
401 args
.ucAction
= action
;
403 if (radeon_encoder
->active_device
& (ATOM_DEVICE_CRT_SUPPORT
))
404 args
.ucDacStandard
= ATOM_DAC1_PS2
;
405 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
406 args
.ucDacStandard
= ATOM_DAC1_CV
;
408 switch (dac_info
->tv_std
) {
411 case TV_STD_SCART_PAL
:
414 args
.ucDacStandard
= ATOM_DAC1_PAL
;
420 args
.ucDacStandard
= ATOM_DAC1_NTSC
;
424 args
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
426 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
431 atombios_tv_setup(struct drm_encoder
*encoder
, int action
)
433 struct drm_device
*dev
= encoder
->dev
;
434 struct radeon_device
*rdev
= dev
->dev_private
;
435 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
436 TV_ENCODER_CONTROL_PS_ALLOCATION args
;
438 struct radeon_encoder_atom_dac
*dac_info
= radeon_encoder
->enc_priv
;
440 memset(&args
, 0, sizeof(args
));
442 index
= GetIndexIntoMasterTable(COMMAND
, TVEncoderControl
);
444 args
.sTVEncoder
.ucAction
= action
;
446 if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
447 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_CV
;
449 switch (dac_info
->tv_std
) {
451 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSC
;
454 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL
;
457 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PALM
;
460 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL60
;
463 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSCJ
;
465 case TV_STD_SCART_PAL
:
466 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL
; /* ??? */
469 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_SECAM
;
472 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PALCN
;
475 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSC
;
480 args
.sTVEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
482 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
486 union dvo_encoder_control
{
487 ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION ext_tmds
;
488 DVO_ENCODER_CONTROL_PS_ALLOCATION dvo
;
489 DVO_ENCODER_CONTROL_PS_ALLOCATION_V3 dvo_v3
;
493 atombios_dvo_setup(struct drm_encoder
*encoder
, int action
)
495 struct drm_device
*dev
= encoder
->dev
;
496 struct radeon_device
*rdev
= dev
->dev_private
;
497 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
498 union dvo_encoder_control args
;
499 int index
= GetIndexIntoMasterTable(COMMAND
, DVOEncoderControl
);
501 memset(&args
, 0, sizeof(args
));
503 if (ASIC_IS_DCE3(rdev
)) {
505 args
.dvo_v3
.ucAction
= action
;
506 args
.dvo_v3
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
507 args
.dvo_v3
.ucDVOConfig
= 0; /* XXX */
508 } else if (ASIC_IS_DCE2(rdev
)) {
509 /* DCE2 (pre-DCE3 R6xx, RS600/690/740 */
510 args
.dvo
.sDVOEncoder
.ucAction
= action
;
511 args
.dvo
.sDVOEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
512 /* DFP1, CRT1, TV1 depending on the type of port */
513 args
.dvo
.sDVOEncoder
.ucDeviceType
= ATOM_DEVICE_DFP1_INDEX
;
515 if (radeon_encoder
->pixel_clock
> 165000)
516 args
.dvo
.sDVOEncoder
.usDevAttr
.sDigAttrib
.ucAttribute
|= PANEL_ENCODER_MISC_DUAL
;
519 args
.ext_tmds
.sXTmdsEncoder
.ucEnable
= action
;
521 if (radeon_encoder
->pixel_clock
> 165000)
522 args
.ext_tmds
.sXTmdsEncoder
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
524 /*if (pScrn->rgbBits == 8)*/
525 args
.ext_tmds
.sXTmdsEncoder
.ucMisc
|= ATOM_PANEL_MISC_888RGB
;
528 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
531 union lvds_encoder_control
{
532 LVDS_ENCODER_CONTROL_PS_ALLOCATION v1
;
533 LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2
;
537 atombios_digital_setup(struct drm_encoder
*encoder
, int action
)
539 struct drm_device
*dev
= encoder
->dev
;
540 struct radeon_device
*rdev
= dev
->dev_private
;
541 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
542 struct radeon_encoder_atom_dig
*dig
= radeon_encoder
->enc_priv
;
543 union lvds_encoder_control args
;
545 int hdmi_detected
= 0;
551 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_HDMI
)
554 memset(&args
, 0, sizeof(args
));
556 switch (radeon_encoder
->encoder_id
) {
557 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
558 index
= GetIndexIntoMasterTable(COMMAND
, LVDSEncoderControl
);
560 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
561 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
562 index
= GetIndexIntoMasterTable(COMMAND
, TMDS1EncoderControl
);
564 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
565 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
566 index
= GetIndexIntoMasterTable(COMMAND
, LVDSEncoderControl
);
568 index
= GetIndexIntoMasterTable(COMMAND
, TMDS2EncoderControl
);
572 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
581 args
.v1
.ucAction
= action
;
583 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_HDMI_TYPE
;
584 args
.v1
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
585 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
586 if (dig
->lcd_misc
& ATOM_PANEL_MISC_DUAL
)
587 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
588 if (dig
->lcd_misc
& ATOM_PANEL_MISC_888RGB
)
589 args
.v1
.ucMisc
|= ATOM_PANEL_MISC_888RGB
;
592 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_TMDS_LINKB
;
593 if (radeon_encoder
->pixel_clock
> 165000)
594 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
595 /*if (pScrn->rgbBits == 8) */
596 args
.v1
.ucMisc
|= ATOM_PANEL_MISC_888RGB
;
602 args
.v2
.ucAction
= action
;
604 if (dig
->coherent_mode
)
605 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_COHERENT
;
608 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_HDMI_TYPE
;
609 args
.v2
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
610 args
.v2
.ucTruncate
= 0;
611 args
.v2
.ucSpatial
= 0;
612 args
.v2
.ucTemporal
= 0;
614 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
615 if (dig
->lcd_misc
& ATOM_PANEL_MISC_DUAL
)
616 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
617 if (dig
->lcd_misc
& ATOM_PANEL_MISC_SPATIAL
) {
618 args
.v2
.ucSpatial
= PANEL_ENCODER_SPATIAL_DITHER_EN
;
619 if (dig
->lcd_misc
& ATOM_PANEL_MISC_888RGB
)
620 args
.v2
.ucSpatial
|= PANEL_ENCODER_SPATIAL_DITHER_DEPTH
;
622 if (dig
->lcd_misc
& ATOM_PANEL_MISC_TEMPORAL
) {
623 args
.v2
.ucTemporal
= PANEL_ENCODER_TEMPORAL_DITHER_EN
;
624 if (dig
->lcd_misc
& ATOM_PANEL_MISC_888RGB
)
625 args
.v2
.ucTemporal
|= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH
;
626 if (((dig
->lcd_misc
>> ATOM_PANEL_MISC_GREY_LEVEL_SHIFT
) & 0x3) == 2)
627 args
.v2
.ucTemporal
|= PANEL_ENCODER_TEMPORAL_LEVEL_4
;
631 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_TMDS_LINKB
;
632 if (radeon_encoder
->pixel_clock
> 165000)
633 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
637 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
642 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
646 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
650 atombios_get_encoder_mode(struct drm_encoder
*encoder
)
652 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
653 struct drm_device
*dev
= encoder
->dev
;
654 struct radeon_device
*rdev
= dev
->dev_private
;
655 struct drm_connector
*connector
;
656 struct radeon_connector
*radeon_connector
;
657 struct radeon_connector_atom_dig
*dig_connector
;
659 /* dp bridges are always DP */
660 if (radeon_encoder_is_dp_bridge(encoder
))
661 return ATOM_ENCODER_MODE_DP
;
663 connector
= radeon_get_connector_for_encoder(encoder
);
665 switch (radeon_encoder
->encoder_id
) {
666 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
667 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
668 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
669 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
670 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
671 return ATOM_ENCODER_MODE_DVI
;
672 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
673 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
675 return ATOM_ENCODER_MODE_CRT
;
678 radeon_connector
= to_radeon_connector(connector
);
680 switch (connector
->connector_type
) {
681 case DRM_MODE_CONNECTOR_DVII
:
682 case DRM_MODE_CONNECTOR_HDMIB
: /* HDMI-B is basically DL-DVI; analog works fine */
683 if (drm_detect_monitor_audio(radeon_connector
->edid
) && radeon_audio
) {
685 if (ASIC_IS_DCE4(rdev
))
686 return ATOM_ENCODER_MODE_DVI
;
688 return ATOM_ENCODER_MODE_HDMI
;
689 } else if (radeon_connector
->use_digital
)
690 return ATOM_ENCODER_MODE_DVI
;
692 return ATOM_ENCODER_MODE_CRT
;
694 case DRM_MODE_CONNECTOR_DVID
:
695 case DRM_MODE_CONNECTOR_HDMIA
:
697 if (drm_detect_monitor_audio(radeon_connector
->edid
) && radeon_audio
) {
699 if (ASIC_IS_DCE4(rdev
))
700 return ATOM_ENCODER_MODE_DVI
;
702 return ATOM_ENCODER_MODE_HDMI
;
704 return ATOM_ENCODER_MODE_DVI
;
706 case DRM_MODE_CONNECTOR_LVDS
:
707 return ATOM_ENCODER_MODE_LVDS
;
709 case DRM_MODE_CONNECTOR_DisplayPort
:
710 dig_connector
= radeon_connector
->con_priv
;
711 if ((dig_connector
->dp_sink_type
== CONNECTOR_OBJECT_ID_DISPLAYPORT
) ||
712 (dig_connector
->dp_sink_type
== CONNECTOR_OBJECT_ID_eDP
))
713 return ATOM_ENCODER_MODE_DP
;
714 else if (drm_detect_monitor_audio(radeon_connector
->edid
) && radeon_audio
) {
716 if (ASIC_IS_DCE4(rdev
))
717 return ATOM_ENCODER_MODE_DVI
;
719 return ATOM_ENCODER_MODE_HDMI
;
721 return ATOM_ENCODER_MODE_DVI
;
723 case DRM_MODE_CONNECTOR_eDP
:
724 return ATOM_ENCODER_MODE_DP
;
725 case DRM_MODE_CONNECTOR_DVIA
:
726 case DRM_MODE_CONNECTOR_VGA
:
727 return ATOM_ENCODER_MODE_CRT
;
729 case DRM_MODE_CONNECTOR_Composite
:
730 case DRM_MODE_CONNECTOR_SVIDEO
:
731 case DRM_MODE_CONNECTOR_9PinDIN
:
733 return ATOM_ENCODER_MODE_TV
;
734 /*return ATOM_ENCODER_MODE_CV;*/
740 * DIG Encoder/Transmitter Setup
743 * - 2 DIG transmitter blocks. UNIPHY (links A and B) and LVTMA.
744 * Supports up to 3 digital outputs
745 * - 2 DIG encoder blocks.
746 * DIG1 can drive UNIPHY link A or link B
747 * DIG2 can drive UNIPHY link B or LVTMA
750 * - 3 DIG transmitter blocks. UNIPHY0/1/2 (links A and B).
751 * Supports up to 5 digital outputs
752 * - 2 DIG encoder blocks.
753 * DIG1/2 can drive UNIPHY0/1/2 link A or link B
756 * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
757 * Supports up to 6 digital outputs
758 * - 6 DIG encoder blocks.
759 * - DIG to PHY mapping is hardcoded
760 * DIG1 drives UNIPHY0 link A, A+B
761 * DIG2 drives UNIPHY0 link B
762 * DIG3 drives UNIPHY1 link A, A+B
763 * DIG4 drives UNIPHY1 link B
764 * DIG5 drives UNIPHY2 link A, A+B
765 * DIG6 drives UNIPHY2 link B
768 * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
769 * Supports up to 6 digital outputs
770 * - 2 DIG encoder blocks.
771 * DIG1/2 can drive UNIPHY0/1/2 link A or link B
774 * crtc -> dig encoder -> UNIPHY/LVTMA (1 or 2 links)
776 * crtc0 -> dig2 -> LVTMA links A+B -> TMDS/HDMI
777 * crtc1 -> dig1 -> UNIPHY0 link B -> DP
778 * crtc0 -> dig1 -> UNIPHY2 link A -> LVDS
779 * crtc1 -> dig2 -> UNIPHY1 link B+A -> TMDS/HDMI
782 union dig_encoder_control
{
783 DIG_ENCODER_CONTROL_PS_ALLOCATION v1
;
784 DIG_ENCODER_CONTROL_PARAMETERS_V2 v2
;
785 DIG_ENCODER_CONTROL_PARAMETERS_V3 v3
;
786 DIG_ENCODER_CONTROL_PARAMETERS_V4 v4
;
790 atombios_dig_encoder_setup(struct drm_encoder
*encoder
, int action
, int panel_mode
)
792 struct drm_device
*dev
= encoder
->dev
;
793 struct radeon_device
*rdev
= dev
->dev_private
;
794 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
795 struct radeon_encoder_atom_dig
*dig
= radeon_encoder
->enc_priv
;
796 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
797 union dig_encoder_control args
;
801 int dp_lane_count
= 0;
802 int hpd_id
= RADEON_HPD_NONE
;
806 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
807 struct radeon_connector_atom_dig
*dig_connector
=
808 radeon_connector
->con_priv
;
810 dp_clock
= dig_connector
->dp_clock
;
811 dp_lane_count
= dig_connector
->dp_lane_count
;
812 hpd_id
= radeon_connector
->hpd
.hpd
;
813 bpc
= connector
->display_info
.bpc
;
816 /* no dig encoder assigned */
817 if (dig
->dig_encoder
== -1)
820 memset(&args
, 0, sizeof(args
));
822 if (ASIC_IS_DCE4(rdev
))
823 index
= GetIndexIntoMasterTable(COMMAND
, DIGxEncoderControl
);
825 if (dig
->dig_encoder
)
826 index
= GetIndexIntoMasterTable(COMMAND
, DIG2EncoderControl
);
828 index
= GetIndexIntoMasterTable(COMMAND
, DIG1EncoderControl
);
831 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
834 args
.v1
.ucAction
= action
;
835 args
.v1
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
836 if (action
== ATOM_ENCODER_CMD_SETUP_PANEL_MODE
)
837 args
.v3
.ucPanelMode
= panel_mode
;
839 args
.v1
.ucEncoderMode
= atombios_get_encoder_mode(encoder
);
841 if ((args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) ||
842 (args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP_MST
))
843 args
.v1
.ucLaneNum
= dp_lane_count
;
844 else if (radeon_encoder
->pixel_clock
> 165000)
845 args
.v1
.ucLaneNum
= 8;
847 args
.v1
.ucLaneNum
= 4;
849 if (ASIC_IS_DCE5(rdev
)) {
850 if ((args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) ||
851 (args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP_MST
)) {
852 if (dp_clock
== 270000)
853 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_2_70GHZ
;
854 else if (dp_clock
== 540000)
855 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_5_40GHZ
;
857 args
.v4
.acConfig
.ucDigSel
= dig
->dig_encoder
;
860 args
.v4
.ucBitPerColor
= PANEL_BPC_UNDEFINE
;
863 args
.v4
.ucBitPerColor
= PANEL_6BIT_PER_COLOR
;
867 args
.v4
.ucBitPerColor
= PANEL_8BIT_PER_COLOR
;
870 args
.v4
.ucBitPerColor
= PANEL_10BIT_PER_COLOR
;
873 args
.v4
.ucBitPerColor
= PANEL_12BIT_PER_COLOR
;
876 args
.v4
.ucBitPerColor
= PANEL_16BIT_PER_COLOR
;
879 if (hpd_id
== RADEON_HPD_NONE
)
880 args
.v4
.ucHPD_ID
= 0;
882 args
.v4
.ucHPD_ID
= hpd_id
+ 1;
883 } else if (ASIC_IS_DCE4(rdev
)) {
884 if ((args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) && (dp_clock
== 270000))
885 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ
;
886 args
.v3
.acConfig
.ucDigSel
= dig
->dig_encoder
;
889 args
.v3
.ucBitPerColor
= PANEL_BPC_UNDEFINE
;
892 args
.v3
.ucBitPerColor
= PANEL_6BIT_PER_COLOR
;
896 args
.v3
.ucBitPerColor
= PANEL_8BIT_PER_COLOR
;
899 args
.v3
.ucBitPerColor
= PANEL_10BIT_PER_COLOR
;
902 args
.v3
.ucBitPerColor
= PANEL_12BIT_PER_COLOR
;
905 args
.v3
.ucBitPerColor
= PANEL_16BIT_PER_COLOR
;
909 if ((args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) && (dp_clock
== 270000))
910 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ
;
911 switch (radeon_encoder
->encoder_id
) {
912 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
913 args
.v1
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER1
;
915 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
916 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
917 args
.v1
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER2
;
919 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
920 args
.v1
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER3
;
924 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_LINKB
;
926 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_LINKA
;
929 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
933 union dig_transmitter_control
{
934 DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1
;
935 DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2
;
936 DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 v3
;
937 DIG_TRANSMITTER_CONTROL_PARAMETERS_V4 v4
;
941 atombios_dig_transmitter_setup(struct drm_encoder
*encoder
, int action
, uint8_t lane_num
, uint8_t lane_set
)
943 struct drm_device
*dev
= encoder
->dev
;
944 struct radeon_device
*rdev
= dev
->dev_private
;
945 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
946 struct radeon_encoder_atom_dig
*dig
= radeon_encoder
->enc_priv
;
947 struct drm_connector
*connector
;
948 union dig_transmitter_control args
;
954 int dp_lane_count
= 0;
955 int connector_object_id
= 0;
956 int igp_lane_info
= 0;
958 if (action
== ATOM_TRANSMITTER_ACTION_INIT
)
959 connector
= radeon_get_connector_for_encoder_init(encoder
);
961 connector
= radeon_get_connector_for_encoder(encoder
);
964 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
965 struct radeon_connector_atom_dig
*dig_connector
=
966 radeon_connector
->con_priv
;
968 dp_clock
= dig_connector
->dp_clock
;
969 dp_lane_count
= dig_connector
->dp_lane_count
;
970 connector_object_id
=
971 (radeon_connector
->connector_object_id
& OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
972 igp_lane_info
= dig_connector
->igp_lane_info
;
975 /* no dig encoder assigned */
976 if (dig
->dig_encoder
== -1)
979 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_DP
)
982 memset(&args
, 0, sizeof(args
));
984 switch (radeon_encoder
->encoder_id
) {
985 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
986 index
= GetIndexIntoMasterTable(COMMAND
, DVOOutputControl
);
988 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
989 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
990 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
991 index
= GetIndexIntoMasterTable(COMMAND
, UNIPHYTransmitterControl
);
993 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
994 index
= GetIndexIntoMasterTable(COMMAND
, LVTMATransmitterControl
);
998 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
1001 args
.v1
.ucAction
= action
;
1002 if (action
== ATOM_TRANSMITTER_ACTION_INIT
) {
1003 args
.v1
.usInitInfo
= cpu_to_le16(connector_object_id
);
1004 } else if (action
== ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH
) {
1005 args
.v1
.asMode
.ucLaneSel
= lane_num
;
1006 args
.v1
.asMode
.ucLaneSet
= lane_set
;
1009 args
.v1
.usPixelClock
=
1010 cpu_to_le16(dp_clock
/ 10);
1011 else if (radeon_encoder
->pixel_clock
> 165000)
1012 args
.v1
.usPixelClock
= cpu_to_le16((radeon_encoder
->pixel_clock
/ 2) / 10);
1014 args
.v1
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
1016 if (ASIC_IS_DCE4(rdev
)) {
1018 args
.v3
.ucLaneNum
= dp_lane_count
;
1019 else if (radeon_encoder
->pixel_clock
> 165000)
1020 args
.v3
.ucLaneNum
= 8;
1022 args
.v3
.ucLaneNum
= 4;
1025 args
.v3
.acConfig
.ucLinkSel
= 1;
1026 if (dig
->dig_encoder
& 1)
1027 args
.v3
.acConfig
.ucEncoderSel
= 1;
1029 /* Select the PLL for the PHY
1030 * DP PHY should be clocked from external src if there is
1033 if (encoder
->crtc
) {
1034 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1035 pll_id
= radeon_crtc
->pll_id
;
1038 if (ASIC_IS_DCE5(rdev
)) {
1039 /* On DCE5 DCPLL usually generates the DP ref clock */
1041 if (rdev
->clock
.dp_extclk
)
1042 args
.v4
.acConfig
.ucRefClkSource
= ENCODER_REFCLK_SRC_EXTCLK
;
1044 args
.v4
.acConfig
.ucRefClkSource
= ENCODER_REFCLK_SRC_DCPLL
;
1046 args
.v4
.acConfig
.ucRefClkSource
= pll_id
;
1048 /* On DCE4, if there is an external clock, it generates the DP ref clock */
1049 if (is_dp
&& rdev
->clock
.dp_extclk
)
1050 args
.v3
.acConfig
.ucRefClkSource
= 2; /* external src */
1052 args
.v3
.acConfig
.ucRefClkSource
= pll_id
;
1055 switch (radeon_encoder
->encoder_id
) {
1056 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1057 args
.v3
.acConfig
.ucTransmitterSel
= 0;
1059 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1060 args
.v3
.acConfig
.ucTransmitterSel
= 1;
1062 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1063 args
.v3
.acConfig
.ucTransmitterSel
= 2;
1068 args
.v3
.acConfig
.fCoherentMode
= 1; /* DP requires coherent */
1069 else if (radeon_encoder
->devices
& (ATOM_DEVICE_DFP_SUPPORT
)) {
1070 if (dig
->coherent_mode
)
1071 args
.v3
.acConfig
.fCoherentMode
= 1;
1072 if (radeon_encoder
->pixel_clock
> 165000)
1073 args
.v3
.acConfig
.fDualLinkConnector
= 1;
1075 } else if (ASIC_IS_DCE32(rdev
)) {
1076 args
.v2
.acConfig
.ucEncoderSel
= dig
->dig_encoder
;
1078 args
.v2
.acConfig
.ucLinkSel
= 1;
1080 switch (radeon_encoder
->encoder_id
) {
1081 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1082 args
.v2
.acConfig
.ucTransmitterSel
= 0;
1084 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1085 args
.v2
.acConfig
.ucTransmitterSel
= 1;
1087 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1088 args
.v2
.acConfig
.ucTransmitterSel
= 2;
1093 args
.v2
.acConfig
.fCoherentMode
= 1;
1094 else if (radeon_encoder
->devices
& (ATOM_DEVICE_DFP_SUPPORT
)) {
1095 if (dig
->coherent_mode
)
1096 args
.v2
.acConfig
.fCoherentMode
= 1;
1097 if (radeon_encoder
->pixel_clock
> 165000)
1098 args
.v2
.acConfig
.fDualLinkConnector
= 1;
1101 args
.v1
.ucConfig
= ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL
;
1103 if (dig
->dig_encoder
)
1104 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER
;
1106 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER
;
1108 if ((rdev
->flags
& RADEON_IS_IGP
) &&
1109 (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_UNIPHY
)) {
1110 if (is_dp
|| (radeon_encoder
->pixel_clock
<= 165000)) {
1111 if (igp_lane_info
& 0x1)
1112 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_0_3
;
1113 else if (igp_lane_info
& 0x2)
1114 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_4_7
;
1115 else if (igp_lane_info
& 0x4)
1116 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_8_11
;
1117 else if (igp_lane_info
& 0x8)
1118 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_12_15
;
1120 if (igp_lane_info
& 0x3)
1121 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_0_7
;
1122 else if (igp_lane_info
& 0xc)
1123 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_8_15
;
1128 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LINKB
;
1130 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LINKA
;
1133 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_COHERENT
;
1134 else if (radeon_encoder
->devices
& (ATOM_DEVICE_DFP_SUPPORT
)) {
1135 if (dig
->coherent_mode
)
1136 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_COHERENT
;
1137 if (radeon_encoder
->pixel_clock
> 165000)
1138 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_8LANE_LINK
;
1142 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1146 atombios_set_edp_panel_power(struct drm_connector
*connector
, int action
)
1148 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1149 struct drm_device
*dev
= radeon_connector
->base
.dev
;
1150 struct radeon_device
*rdev
= dev
->dev_private
;
1151 union dig_transmitter_control args
;
1152 int index
= GetIndexIntoMasterTable(COMMAND
, UNIPHYTransmitterControl
);
1155 if (connector
->connector_type
!= DRM_MODE_CONNECTOR_eDP
)
1158 if (!ASIC_IS_DCE4(rdev
))
1161 if ((action
!= ATOM_TRANSMITTER_ACTION_POWER_ON
) &&
1162 (action
!= ATOM_TRANSMITTER_ACTION_POWER_OFF
))
1165 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
1168 memset(&args
, 0, sizeof(args
));
1170 args
.v1
.ucAction
= action
;
1172 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1174 /* wait for the panel to power up */
1175 if (action
== ATOM_TRANSMITTER_ACTION_POWER_ON
) {
1178 for (i
= 0; i
< 300; i
++) {
1179 if (radeon_hpd_sense(rdev
, radeon_connector
->hpd
.hpd
))
1189 union external_encoder_control
{
1190 EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION v1
;
1191 EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION_V3 v3
;
1195 atombios_external_encoder_setup(struct drm_encoder
*encoder
,
1196 struct drm_encoder
*ext_encoder
,
1199 struct drm_device
*dev
= encoder
->dev
;
1200 struct radeon_device
*rdev
= dev
->dev_private
;
1201 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1202 struct radeon_encoder
*ext_radeon_encoder
= to_radeon_encoder(ext_encoder
);
1203 union external_encoder_control args
;
1204 struct drm_connector
*connector
;
1205 int index
= GetIndexIntoMasterTable(COMMAND
, ExternalEncoderControl
);
1208 int dp_lane_count
= 0;
1209 int connector_object_id
= 0;
1210 u32 ext_enum
= (ext_radeon_encoder
->encoder_enum
& ENUM_ID_MASK
) >> ENUM_ID_SHIFT
;
1213 if (action
== EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT
)
1214 connector
= radeon_get_connector_for_encoder_init(encoder
);
1216 connector
= radeon_get_connector_for_encoder(encoder
);
1219 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1220 struct radeon_connector_atom_dig
*dig_connector
=
1221 radeon_connector
->con_priv
;
1223 dp_clock
= dig_connector
->dp_clock
;
1224 dp_lane_count
= dig_connector
->dp_lane_count
;
1225 connector_object_id
=
1226 (radeon_connector
->connector_object_id
& OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
1227 bpc
= connector
->display_info
.bpc
;
1230 memset(&args
, 0, sizeof(args
));
1232 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
1237 /* no params on frev 1 */
1243 args
.v1
.sDigEncoder
.ucAction
= action
;
1244 args
.v1
.sDigEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
1245 args
.v1
.sDigEncoder
.ucEncoderMode
= atombios_get_encoder_mode(encoder
);
1247 if (args
.v1
.sDigEncoder
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) {
1248 if (dp_clock
== 270000)
1249 args
.v1
.sDigEncoder
.ucConfig
|= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ
;
1250 args
.v1
.sDigEncoder
.ucLaneNum
= dp_lane_count
;
1251 } else if (radeon_encoder
->pixel_clock
> 165000)
1252 args
.v1
.sDigEncoder
.ucLaneNum
= 8;
1254 args
.v1
.sDigEncoder
.ucLaneNum
= 4;
1257 args
.v3
.sExtEncoder
.ucAction
= action
;
1258 if (action
== EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT
)
1259 args
.v3
.sExtEncoder
.usConnectorId
= cpu_to_le16(connector_object_id
);
1261 args
.v3
.sExtEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
1262 args
.v3
.sExtEncoder
.ucEncoderMode
= atombios_get_encoder_mode(encoder
);
1264 if (args
.v3
.sExtEncoder
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) {
1265 if (dp_clock
== 270000)
1266 args
.v3
.sExtEncoder
.ucConfig
|= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ
;
1267 else if (dp_clock
== 540000)
1268 args
.v3
.sExtEncoder
.ucConfig
|= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_5_40GHZ
;
1269 args
.v3
.sExtEncoder
.ucLaneNum
= dp_lane_count
;
1270 } else if (radeon_encoder
->pixel_clock
> 165000)
1271 args
.v3
.sExtEncoder
.ucLaneNum
= 8;
1273 args
.v3
.sExtEncoder
.ucLaneNum
= 4;
1275 case GRAPH_OBJECT_ENUM_ID1
:
1276 args
.v3
.sExtEncoder
.ucConfig
|= EXTERNAL_ENCODER_CONFIG_V3_ENCODER1
;
1278 case GRAPH_OBJECT_ENUM_ID2
:
1279 args
.v3
.sExtEncoder
.ucConfig
|= EXTERNAL_ENCODER_CONFIG_V3_ENCODER2
;
1281 case GRAPH_OBJECT_ENUM_ID3
:
1282 args
.v3
.sExtEncoder
.ucConfig
|= EXTERNAL_ENCODER_CONFIG_V3_ENCODER3
;
1287 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_BPC_UNDEFINE
;
1290 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_6BIT_PER_COLOR
;
1294 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_8BIT_PER_COLOR
;
1297 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_10BIT_PER_COLOR
;
1300 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_12BIT_PER_COLOR
;
1303 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_16BIT_PER_COLOR
;
1308 DRM_ERROR("Unknown table version: %d, %d\n", frev
, crev
);
1313 DRM_ERROR("Unknown table version: %d, %d\n", frev
, crev
);
1316 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1320 atombios_yuv_setup(struct drm_encoder
*encoder
, bool enable
)
1322 struct drm_device
*dev
= encoder
->dev
;
1323 struct radeon_device
*rdev
= dev
->dev_private
;
1324 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1325 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1326 ENABLE_YUV_PS_ALLOCATION args
;
1327 int index
= GetIndexIntoMasterTable(COMMAND
, EnableYUV
);
1330 memset(&args
, 0, sizeof(args
));
1332 if (rdev
->family
>= CHIP_R600
)
1333 reg
= R600_BIOS_3_SCRATCH
;
1335 reg
= RADEON_BIOS_3_SCRATCH
;
1337 /* XXX: fix up scratch reg handling */
1339 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1340 WREG32(reg
, (ATOM_S3_TV1_ACTIVE
|
1341 (radeon_crtc
->crtc_id
<< 18)));
1342 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1343 WREG32(reg
, (ATOM_S3_CV_ACTIVE
| (radeon_crtc
->crtc_id
<< 24)));
1348 args
.ucEnable
= ATOM_ENABLE
;
1349 args
.ucCRTC
= radeon_crtc
->crtc_id
;
1351 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1357 radeon_atom_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
1359 struct drm_device
*dev
= encoder
->dev
;
1360 struct radeon_device
*rdev
= dev
->dev_private
;
1361 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1362 struct drm_encoder
*ext_encoder
= radeon_atom_get_external_encoder(encoder
);
1363 DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args
;
1365 bool is_dig
= false;
1366 bool is_dce5_dac
= false;
1367 bool is_dce5_dvo
= false;
1369 memset(&args
, 0, sizeof(args
));
1371 DRM_DEBUG_KMS("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n",
1372 radeon_encoder
->encoder_id
, mode
, radeon_encoder
->devices
,
1373 radeon_encoder
->active_device
);
1374 switch (radeon_encoder
->encoder_id
) {
1375 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1376 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
1377 index
= GetIndexIntoMasterTable(COMMAND
, TMDSAOutputControl
);
1379 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1380 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1381 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1382 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1385 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1386 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
1387 index
= GetIndexIntoMasterTable(COMMAND
, DVOOutputControl
);
1389 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1390 if (ASIC_IS_DCE5(rdev
))
1392 else if (ASIC_IS_DCE3(rdev
))
1395 index
= GetIndexIntoMasterTable(COMMAND
, DVOOutputControl
);
1397 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1398 index
= GetIndexIntoMasterTable(COMMAND
, LCD1OutputControl
);
1400 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
1401 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
1402 index
= GetIndexIntoMasterTable(COMMAND
, LCD1OutputControl
);
1404 index
= GetIndexIntoMasterTable(COMMAND
, LVTMAOutputControl
);
1406 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1407 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1408 if (ASIC_IS_DCE5(rdev
))
1411 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1412 index
= GetIndexIntoMasterTable(COMMAND
, TV1OutputControl
);
1413 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1414 index
= GetIndexIntoMasterTable(COMMAND
, CV1OutputControl
);
1416 index
= GetIndexIntoMasterTable(COMMAND
, DAC1OutputControl
);
1419 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1420 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1421 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1422 index
= GetIndexIntoMasterTable(COMMAND
, TV1OutputControl
);
1423 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1424 index
= GetIndexIntoMasterTable(COMMAND
, CV1OutputControl
);
1426 index
= GetIndexIntoMasterTable(COMMAND
, DAC2OutputControl
);
1432 case DRM_MODE_DPMS_ON
:
1433 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT
, 0, 0);
1434 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_DP
) {
1435 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
1438 (connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
)) {
1439 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1440 struct radeon_connector_atom_dig
*radeon_dig_connector
=
1441 radeon_connector
->con_priv
;
1442 atombios_set_edp_panel_power(connector
,
1443 ATOM_TRANSMITTER_ACTION_POWER_ON
);
1444 radeon_dig_connector
->edp_on
= true;
1446 if (ASIC_IS_DCE4(rdev
))
1447 atombios_dig_encoder_setup(encoder
, ATOM_ENCODER_CMD_DP_VIDEO_OFF
, 0);
1448 radeon_dp_link_train(encoder
, connector
);
1449 if (ASIC_IS_DCE4(rdev
))
1450 atombios_dig_encoder_setup(encoder
, ATOM_ENCODER_CMD_DP_VIDEO_ON
, 0);
1452 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
1453 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_LCD_BLON
, 0, 0);
1455 case DRM_MODE_DPMS_STANDBY
:
1456 case DRM_MODE_DPMS_SUSPEND
:
1457 case DRM_MODE_DPMS_OFF
:
1458 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT
, 0, 0);
1459 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_DP
) {
1460 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
1462 if (ASIC_IS_DCE4(rdev
))
1463 atombios_dig_encoder_setup(encoder
, ATOM_ENCODER_CMD_DP_VIDEO_OFF
, 0);
1465 (connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
)) {
1466 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1467 struct radeon_connector_atom_dig
*radeon_dig_connector
=
1468 radeon_connector
->con_priv
;
1469 atombios_set_edp_panel_power(connector
,
1470 ATOM_TRANSMITTER_ACTION_POWER_OFF
);
1471 radeon_dig_connector
->edp_on
= false;
1474 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
1475 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_LCD_BLOFF
, 0, 0);
1478 } else if (is_dce5_dac
) {
1480 case DRM_MODE_DPMS_ON
:
1481 atombios_dac_setup(encoder
, ATOM_ENABLE
);
1483 case DRM_MODE_DPMS_STANDBY
:
1484 case DRM_MODE_DPMS_SUSPEND
:
1485 case DRM_MODE_DPMS_OFF
:
1486 atombios_dac_setup(encoder
, ATOM_DISABLE
);
1489 } else if (is_dce5_dvo
) {
1491 case DRM_MODE_DPMS_ON
:
1492 atombios_dvo_setup(encoder
, ATOM_ENABLE
);
1494 case DRM_MODE_DPMS_STANDBY
:
1495 case DRM_MODE_DPMS_SUSPEND
:
1496 case DRM_MODE_DPMS_OFF
:
1497 atombios_dvo_setup(encoder
, ATOM_DISABLE
);
1502 case DRM_MODE_DPMS_ON
:
1503 args
.ucAction
= ATOM_ENABLE
;
1504 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1505 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
1506 args
.ucAction
= ATOM_LCD_BLON
;
1507 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1510 case DRM_MODE_DPMS_STANDBY
:
1511 case DRM_MODE_DPMS_SUSPEND
:
1512 case DRM_MODE_DPMS_OFF
:
1513 args
.ucAction
= ATOM_DISABLE
;
1514 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1515 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
1516 args
.ucAction
= ATOM_LCD_BLOFF
;
1517 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1527 case DRM_MODE_DPMS_ON
:
1529 if (ASIC_IS_DCE41(rdev
))
1530 action
= EXTERNAL_ENCODER_ACTION_V3_ENABLE_OUTPUT
;
1532 action
= ATOM_ENABLE
;
1534 case DRM_MODE_DPMS_STANDBY
:
1535 case DRM_MODE_DPMS_SUSPEND
:
1536 case DRM_MODE_DPMS_OFF
:
1537 if (ASIC_IS_DCE41(rdev
))
1538 action
= EXTERNAL_ENCODER_ACTION_V3_DISABLE_OUTPUT
;
1540 action
= ATOM_DISABLE
;
1543 atombios_external_encoder_setup(encoder
, ext_encoder
, action
);
1546 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
1550 union crtc_source_param
{
1551 SELECT_CRTC_SOURCE_PS_ALLOCATION v1
;
1552 SELECT_CRTC_SOURCE_PARAMETERS_V2 v2
;
1556 atombios_set_encoder_crtc_source(struct drm_encoder
*encoder
)
1558 struct drm_device
*dev
= encoder
->dev
;
1559 struct radeon_device
*rdev
= dev
->dev_private
;
1560 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1561 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1562 union crtc_source_param args
;
1563 int index
= GetIndexIntoMasterTable(COMMAND
, SelectCRTC_Source
);
1565 struct radeon_encoder_atom_dig
*dig
;
1567 memset(&args
, 0, sizeof(args
));
1569 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
1577 if (ASIC_IS_AVIVO(rdev
))
1578 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
;
1580 if (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_DAC1
) {
1581 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
;
1583 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
<< 2;
1586 switch (radeon_encoder
->encoder_id
) {
1587 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1588 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
1589 args
.v1
.ucDevice
= ATOM_DEVICE_DFP1_INDEX
;
1591 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1592 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
1593 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
)
1594 args
.v1
.ucDevice
= ATOM_DEVICE_LCD1_INDEX
;
1596 args
.v1
.ucDevice
= ATOM_DEVICE_DFP3_INDEX
;
1598 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1599 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
1600 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1601 args
.v1
.ucDevice
= ATOM_DEVICE_DFP2_INDEX
;
1603 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1604 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1605 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1606 args
.v1
.ucDevice
= ATOM_DEVICE_TV1_INDEX
;
1607 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1608 args
.v1
.ucDevice
= ATOM_DEVICE_CV_INDEX
;
1610 args
.v1
.ucDevice
= ATOM_DEVICE_CRT1_INDEX
;
1612 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1613 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1614 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1615 args
.v1
.ucDevice
= ATOM_DEVICE_TV1_INDEX
;
1616 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1617 args
.v1
.ucDevice
= ATOM_DEVICE_CV_INDEX
;
1619 args
.v1
.ucDevice
= ATOM_DEVICE_CRT2_INDEX
;
1624 args
.v2
.ucCRTC
= radeon_crtc
->crtc_id
;
1625 args
.v2
.ucEncodeMode
= atombios_get_encoder_mode(encoder
);
1626 switch (radeon_encoder
->encoder_id
) {
1627 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1628 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1629 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1630 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1631 dig
= radeon_encoder
->enc_priv
;
1632 switch (dig
->dig_encoder
) {
1634 args
.v2
.ucEncoderID
= ASIC_INT_DIG1_ENCODER_ID
;
1637 args
.v2
.ucEncoderID
= ASIC_INT_DIG2_ENCODER_ID
;
1640 args
.v2
.ucEncoderID
= ASIC_INT_DIG3_ENCODER_ID
;
1643 args
.v2
.ucEncoderID
= ASIC_INT_DIG4_ENCODER_ID
;
1646 args
.v2
.ucEncoderID
= ASIC_INT_DIG5_ENCODER_ID
;
1649 args
.v2
.ucEncoderID
= ASIC_INT_DIG6_ENCODER_ID
;
1653 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1654 args
.v2
.ucEncoderID
= ASIC_INT_DVO_ENCODER_ID
;
1656 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1657 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1658 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1659 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1660 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1662 args
.v2
.ucEncoderID
= ASIC_INT_DAC1_ENCODER_ID
;
1664 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1665 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1666 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1667 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1668 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1670 args
.v2
.ucEncoderID
= ASIC_INT_DAC2_ENCODER_ID
;
1677 DRM_ERROR("Unknown table version: %d, %d\n", frev
, crev
);
1681 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1683 /* update scratch regs with new routing */
1684 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1688 atombios_apply_encoder_quirks(struct drm_encoder
*encoder
,
1689 struct drm_display_mode
*mode
)
1691 struct drm_device
*dev
= encoder
->dev
;
1692 struct radeon_device
*rdev
= dev
->dev_private
;
1693 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1694 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1696 /* Funky macbooks */
1697 if ((dev
->pdev
->device
== 0x71C5) &&
1698 (dev
->pdev
->subsystem_vendor
== 0x106b) &&
1699 (dev
->pdev
->subsystem_device
== 0x0080)) {
1700 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) {
1701 uint32_t lvtma_bit_depth_control
= RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL
);
1703 lvtma_bit_depth_control
&= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN
;
1704 lvtma_bit_depth_control
&= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN
;
1706 WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL
, lvtma_bit_depth_control
);
1710 /* set scaler clears this on some chips */
1711 if (ASIC_IS_AVIVO(rdev
) &&
1712 (!(radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
)))) {
1713 if (ASIC_IS_DCE4(rdev
)) {
1714 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1715 WREG32(EVERGREEN_DATA_FORMAT
+ radeon_crtc
->crtc_offset
,
1716 EVERGREEN_INTERLEAVE_EN
);
1718 WREG32(EVERGREEN_DATA_FORMAT
+ radeon_crtc
->crtc_offset
, 0);
1720 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1721 WREG32(AVIVO_D1MODE_DATA_FORMAT
+ radeon_crtc
->crtc_offset
,
1722 AVIVO_D1MODE_INTERLEAVE_EN
);
1724 WREG32(AVIVO_D1MODE_DATA_FORMAT
+ radeon_crtc
->crtc_offset
, 0);
1729 static int radeon_atom_pick_dig_encoder(struct drm_encoder
*encoder
)
1731 struct drm_device
*dev
= encoder
->dev
;
1732 struct radeon_device
*rdev
= dev
->dev_private
;
1733 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1734 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1735 struct drm_encoder
*test_encoder
;
1736 struct radeon_encoder_atom_dig
*dig
;
1737 uint32_t dig_enc_in_use
= 0;
1740 if (ASIC_IS_DCE4(rdev
)) {
1741 dig
= radeon_encoder
->enc_priv
;
1742 if (ASIC_IS_DCE41(rdev
))
1743 return radeon_crtc
->crtc_id
;
1745 switch (radeon_encoder
->encoder_id
) {
1746 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1752 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1758 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1768 /* on DCE32 and encoder can driver any block so just crtc id */
1769 if (ASIC_IS_DCE32(rdev
)) {
1770 return radeon_crtc
->crtc_id
;
1773 /* on DCE3 - LVTMA can only be driven by DIGB */
1774 list_for_each_entry(test_encoder
, &dev
->mode_config
.encoder_list
, head
) {
1775 struct radeon_encoder
*radeon_test_encoder
;
1777 if (encoder
== test_encoder
)
1780 if (!radeon_encoder_is_digital(test_encoder
))
1783 radeon_test_encoder
= to_radeon_encoder(test_encoder
);
1784 dig
= radeon_test_encoder
->enc_priv
;
1786 if (dig
->dig_encoder
>= 0)
1787 dig_enc_in_use
|= (1 << dig
->dig_encoder
);
1790 if (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
) {
1791 if (dig_enc_in_use
& 0x2)
1792 DRM_ERROR("LVDS required digital encoder 2 but it was in use - stealing\n");
1795 if (!(dig_enc_in_use
& 1))
1800 /* This only needs to be called once at startup */
1802 radeon_atom_encoder_init(struct radeon_device
*rdev
)
1804 struct drm_device
*dev
= rdev
->ddev
;
1805 struct drm_encoder
*encoder
;
1807 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
1808 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1809 struct drm_encoder
*ext_encoder
= radeon_atom_get_external_encoder(encoder
);
1811 switch (radeon_encoder
->encoder_id
) {
1812 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1813 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1814 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1815 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1816 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_INIT
, 0, 0);
1822 if (ext_encoder
&& ASIC_IS_DCE41(rdev
))
1823 atombios_external_encoder_setup(encoder
, ext_encoder
,
1824 EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT
);
1829 radeon_atom_encoder_mode_set(struct drm_encoder
*encoder
,
1830 struct drm_display_mode
*mode
,
1831 struct drm_display_mode
*adjusted_mode
)
1833 struct drm_device
*dev
= encoder
->dev
;
1834 struct radeon_device
*rdev
= dev
->dev_private
;
1835 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1836 struct drm_encoder
*ext_encoder
= radeon_atom_get_external_encoder(encoder
);
1838 radeon_encoder
->pixel_clock
= adjusted_mode
->clock
;
1840 if (ASIC_IS_AVIVO(rdev
) && !ASIC_IS_DCE4(rdev
)) {
1841 if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
| ATOM_DEVICE_TV_SUPPORT
))
1842 atombios_yuv_setup(encoder
, true);
1844 atombios_yuv_setup(encoder
, false);
1847 switch (radeon_encoder
->encoder_id
) {
1848 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1849 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
1850 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1851 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
1852 atombios_digital_setup(encoder
, PANEL_ENCODER_ACTION_ENABLE
);
1854 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1855 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1856 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1857 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1858 if (ASIC_IS_DCE4(rdev
)) {
1859 /* disable the transmitter */
1860 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE
, 0, 0);
1861 /* setup and enable the encoder */
1862 atombios_dig_encoder_setup(encoder
, ATOM_ENCODER_CMD_SETUP
, 0);
1864 /* enable the transmitter */
1865 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_ENABLE
, 0, 0);
1867 /* disable the encoder and transmitter */
1868 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE
, 0, 0);
1869 atombios_dig_encoder_setup(encoder
, ATOM_DISABLE
, 0);
1871 /* setup and enable the encoder and transmitter */
1872 atombios_dig_encoder_setup(encoder
, ATOM_ENABLE
, 0);
1873 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_SETUP
, 0, 0);
1874 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_ENABLE
, 0, 0);
1877 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
1878 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1879 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1880 atombios_dvo_setup(encoder
, ATOM_ENABLE
);
1882 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1883 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1884 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1885 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1886 atombios_dac_setup(encoder
, ATOM_ENABLE
);
1887 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
)) {
1888 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
))
1889 atombios_tv_setup(encoder
, ATOM_ENABLE
);
1891 atombios_tv_setup(encoder
, ATOM_DISABLE
);
1897 if (ASIC_IS_DCE41(rdev
))
1898 atombios_external_encoder_setup(encoder
, ext_encoder
,
1899 EXTERNAL_ENCODER_ACTION_V3_ENCODER_SETUP
);
1901 atombios_external_encoder_setup(encoder
, ext_encoder
, ATOM_ENABLE
);
1904 atombios_apply_encoder_quirks(encoder
, adjusted_mode
);
1906 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_HDMI
) {
1907 r600_hdmi_enable(encoder
);
1908 r600_hdmi_setmode(encoder
, adjusted_mode
);
1913 atombios_dac_load_detect(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
1915 struct drm_device
*dev
= encoder
->dev
;
1916 struct radeon_device
*rdev
= dev
->dev_private
;
1917 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1918 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1920 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
|
1921 ATOM_DEVICE_CV_SUPPORT
|
1922 ATOM_DEVICE_CRT_SUPPORT
)) {
1923 DAC_LOAD_DETECTION_PS_ALLOCATION args
;
1924 int index
= GetIndexIntoMasterTable(COMMAND
, DAC_LoadDetection
);
1927 memset(&args
, 0, sizeof(args
));
1929 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
1932 args
.sDacload
.ucMisc
= 0;
1934 if ((radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_DAC1
) ||
1935 (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
))
1936 args
.sDacload
.ucDacType
= ATOM_DAC_A
;
1938 args
.sDacload
.ucDacType
= ATOM_DAC_B
;
1940 if (radeon_connector
->devices
& ATOM_DEVICE_CRT1_SUPPORT
)
1941 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT
);
1942 else if (radeon_connector
->devices
& ATOM_DEVICE_CRT2_SUPPORT
)
1943 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT
);
1944 else if (radeon_connector
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
1945 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CV_SUPPORT
);
1947 args
.sDacload
.ucMisc
= DAC_LOAD_MISC_YPrPb
;
1948 } else if (radeon_connector
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
1949 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT
);
1951 args
.sDacload
.ucMisc
= DAC_LOAD_MISC_YPrPb
;
1954 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1961 static enum drm_connector_status
1962 radeon_atom_dac_detect(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
1964 struct drm_device
*dev
= encoder
->dev
;
1965 struct radeon_device
*rdev
= dev
->dev_private
;
1966 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1967 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1968 uint32_t bios_0_scratch
;
1970 if (!atombios_dac_load_detect(encoder
, connector
)) {
1971 DRM_DEBUG_KMS("detect returned false \n");
1972 return connector_status_unknown
;
1975 if (rdev
->family
>= CHIP_R600
)
1976 bios_0_scratch
= RREG32(R600_BIOS_0_SCRATCH
);
1978 bios_0_scratch
= RREG32(RADEON_BIOS_0_SCRATCH
);
1980 DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch
, radeon_encoder
->devices
);
1981 if (radeon_connector
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) {
1982 if (bios_0_scratch
& ATOM_S0_CRT1_MASK
)
1983 return connector_status_connected
;
1985 if (radeon_connector
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) {
1986 if (bios_0_scratch
& ATOM_S0_CRT2_MASK
)
1987 return connector_status_connected
;
1989 if (radeon_connector
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
1990 if (bios_0_scratch
& (ATOM_S0_CV_MASK
|ATOM_S0_CV_MASK_A
))
1991 return connector_status_connected
;
1993 if (radeon_connector
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
1994 if (bios_0_scratch
& (ATOM_S0_TV1_COMPOSITE
| ATOM_S0_TV1_COMPOSITE_A
))
1995 return connector_status_connected
; /* CTV */
1996 else if (bios_0_scratch
& (ATOM_S0_TV1_SVIDEO
| ATOM_S0_TV1_SVIDEO_A
))
1997 return connector_status_connected
; /* STV */
1999 return connector_status_disconnected
;
2002 static void radeon_atom_encoder_prepare(struct drm_encoder
*encoder
)
2004 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
2005 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
2007 if ((radeon_encoder
->active_device
&
2008 (ATOM_DEVICE_DFP_SUPPORT
| ATOM_DEVICE_LCD_SUPPORT
)) ||
2009 radeon_encoder_is_dp_bridge(encoder
)) {
2010 struct radeon_encoder_atom_dig
*dig
= radeon_encoder
->enc_priv
;
2012 dig
->dig_encoder
= radeon_atom_pick_dig_encoder(encoder
);
2015 radeon_atom_output_lock(encoder
, true);
2016 radeon_atom_encoder_dpms(encoder
, DRM_MODE_DPMS_OFF
);
2019 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
2021 /* select the clock/data port if it uses a router */
2022 if (radeon_connector
->router
.cd_valid
)
2023 radeon_router_select_cd_port(radeon_connector
);
2025 /* turn eDP panel on for mode set */
2026 if (connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
)
2027 atombios_set_edp_panel_power(connector
,
2028 ATOM_TRANSMITTER_ACTION_POWER_ON
);
2031 /* this is needed for the pll/ss setup to work correctly in some cases */
2032 atombios_set_encoder_crtc_source(encoder
);
2035 static void radeon_atom_encoder_commit(struct drm_encoder
*encoder
)
2037 radeon_atom_encoder_dpms(encoder
, DRM_MODE_DPMS_ON
);
2038 radeon_atom_output_lock(encoder
, false);
2041 static void radeon_atom_encoder_disable(struct drm_encoder
*encoder
)
2043 struct drm_device
*dev
= encoder
->dev
;
2044 struct radeon_device
*rdev
= dev
->dev_private
;
2045 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
2046 struct radeon_encoder_atom_dig
*dig
;
2048 /* check for pre-DCE3 cards with shared encoders;
2049 * can't really use the links individually, so don't disable
2050 * the encoder if it's in use by another connector
2052 if (!ASIC_IS_DCE3(rdev
)) {
2053 struct drm_encoder
*other_encoder
;
2054 struct radeon_encoder
*other_radeon_encoder
;
2056 list_for_each_entry(other_encoder
, &dev
->mode_config
.encoder_list
, head
) {
2057 other_radeon_encoder
= to_radeon_encoder(other_encoder
);
2058 if ((radeon_encoder
->encoder_id
== other_radeon_encoder
->encoder_id
) &&
2059 drm_helper_encoder_in_use(other_encoder
))
2064 radeon_atom_encoder_dpms(encoder
, DRM_MODE_DPMS_OFF
);
2066 switch (radeon_encoder
->encoder_id
) {
2067 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
2068 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
2069 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
2070 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
2071 atombios_digital_setup(encoder
, PANEL_ENCODER_ACTION_DISABLE
);
2073 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
2074 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
2075 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
2076 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
2077 if (ASIC_IS_DCE4(rdev
))
2078 /* disable the transmitter */
2079 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE
, 0, 0);
2081 /* disable the encoder and transmitter */
2082 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE
, 0, 0);
2083 atombios_dig_encoder_setup(encoder
, ATOM_DISABLE
, 0);
2086 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
2087 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
2088 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
2089 atombios_dvo_setup(encoder
, ATOM_DISABLE
);
2091 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
2092 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
2093 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
2094 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
2095 atombios_dac_setup(encoder
, ATOM_DISABLE
);
2096 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
))
2097 atombios_tv_setup(encoder
, ATOM_DISABLE
);
2102 if (radeon_encoder_is_digital(encoder
)) {
2103 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_HDMI
)
2104 r600_hdmi_disable(encoder
);
2105 dig
= radeon_encoder
->enc_priv
;
2106 dig
->dig_encoder
= -1;
2108 radeon_encoder
->active_device
= 0;
2111 /* these are handled by the primary encoders */
2112 static void radeon_atom_ext_prepare(struct drm_encoder
*encoder
)
2117 static void radeon_atom_ext_commit(struct drm_encoder
*encoder
)
2123 radeon_atom_ext_mode_set(struct drm_encoder
*encoder
,
2124 struct drm_display_mode
*mode
,
2125 struct drm_display_mode
*adjusted_mode
)
2130 static void radeon_atom_ext_disable(struct drm_encoder
*encoder
)
2136 radeon_atom_ext_dpms(struct drm_encoder
*encoder
, int mode
)
2141 static bool radeon_atom_ext_mode_fixup(struct drm_encoder
*encoder
,
2142 struct drm_display_mode
*mode
,
2143 struct drm_display_mode
*adjusted_mode
)
2148 static const struct drm_encoder_helper_funcs radeon_atom_ext_helper_funcs
= {
2149 .dpms
= radeon_atom_ext_dpms
,
2150 .mode_fixup
= radeon_atom_ext_mode_fixup
,
2151 .prepare
= radeon_atom_ext_prepare
,
2152 .mode_set
= radeon_atom_ext_mode_set
,
2153 .commit
= radeon_atom_ext_commit
,
2154 .disable
= radeon_atom_ext_disable
,
2155 /* no detect for TMDS/LVDS yet */
2158 static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs
= {
2159 .dpms
= radeon_atom_encoder_dpms
,
2160 .mode_fixup
= radeon_atom_mode_fixup
,
2161 .prepare
= radeon_atom_encoder_prepare
,
2162 .mode_set
= radeon_atom_encoder_mode_set
,
2163 .commit
= radeon_atom_encoder_commit
,
2164 .disable
= radeon_atom_encoder_disable
,
2165 /* no detect for TMDS/LVDS yet */
2168 static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs
= {
2169 .dpms
= radeon_atom_encoder_dpms
,
2170 .mode_fixup
= radeon_atom_mode_fixup
,
2171 .prepare
= radeon_atom_encoder_prepare
,
2172 .mode_set
= radeon_atom_encoder_mode_set
,
2173 .commit
= radeon_atom_encoder_commit
,
2174 .detect
= radeon_atom_dac_detect
,
2177 void radeon_enc_destroy(struct drm_encoder
*encoder
)
2179 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
2180 kfree(radeon_encoder
->enc_priv
);
2181 drm_encoder_cleanup(encoder
);
2182 kfree(radeon_encoder
);
2185 static const struct drm_encoder_funcs radeon_atom_enc_funcs
= {
2186 .destroy
= radeon_enc_destroy
,
2189 struct radeon_encoder_atom_dac
*
2190 radeon_atombios_set_dac_info(struct radeon_encoder
*radeon_encoder
)
2192 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
2193 struct radeon_device
*rdev
= dev
->dev_private
;
2194 struct radeon_encoder_atom_dac
*dac
= kzalloc(sizeof(struct radeon_encoder_atom_dac
), GFP_KERNEL
);
2199 dac
->tv_std
= radeon_atombios_get_tv_info(rdev
);
2203 struct radeon_encoder_atom_dig
*
2204 radeon_atombios_set_dig_info(struct radeon_encoder
*radeon_encoder
)
2206 int encoder_enum
= (radeon_encoder
->encoder_enum
& ENUM_ID_MASK
) >> ENUM_ID_SHIFT
;
2207 struct radeon_encoder_atom_dig
*dig
= kzalloc(sizeof(struct radeon_encoder_atom_dig
), GFP_KERNEL
);
2212 /* coherent mode by default */
2213 dig
->coherent_mode
= true;
2214 dig
->dig_encoder
= -1;
2216 if (encoder_enum
== 2)
2225 radeon_add_atom_encoder(struct drm_device
*dev
,
2226 uint32_t encoder_enum
,
2227 uint32_t supported_device
,
2230 struct radeon_device
*rdev
= dev
->dev_private
;
2231 struct drm_encoder
*encoder
;
2232 struct radeon_encoder
*radeon_encoder
;
2234 /* see if we already added it */
2235 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
2236 radeon_encoder
= to_radeon_encoder(encoder
);
2237 if (radeon_encoder
->encoder_enum
== encoder_enum
) {
2238 radeon_encoder
->devices
|= supported_device
;
2245 radeon_encoder
= kzalloc(sizeof(struct radeon_encoder
), GFP_KERNEL
);
2246 if (!radeon_encoder
)
2249 encoder
= &radeon_encoder
->base
;
2250 switch (rdev
->num_crtc
) {
2252 encoder
->possible_crtcs
= 0x1;
2256 encoder
->possible_crtcs
= 0x3;
2259 encoder
->possible_crtcs
= 0x3f;
2263 radeon_encoder
->enc_priv
= NULL
;
2265 radeon_encoder
->encoder_enum
= encoder_enum
;
2266 radeon_encoder
->encoder_id
= (encoder_enum
& OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
2267 radeon_encoder
->devices
= supported_device
;
2268 radeon_encoder
->rmx_type
= RMX_OFF
;
2269 radeon_encoder
->underscan_type
= UNDERSCAN_OFF
;
2270 radeon_encoder
->is_ext_encoder
= false;
2271 radeon_encoder
->caps
= caps
;
2273 switch (radeon_encoder
->encoder_id
) {
2274 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
2275 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
2276 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
2277 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
2278 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
2279 radeon_encoder
->rmx_type
= RMX_FULL
;
2280 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_LVDS
);
2281 radeon_encoder
->enc_priv
= radeon_atombios_get_lvds_info(radeon_encoder
);
2283 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
2284 radeon_encoder
->enc_priv
= radeon_atombios_set_dig_info(radeon_encoder
);
2286 drm_encoder_helper_add(encoder
, &radeon_atom_dig_helper_funcs
);
2288 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
2289 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_DAC
);
2290 radeon_encoder
->enc_priv
= radeon_atombios_set_dac_info(radeon_encoder
);
2291 drm_encoder_helper_add(encoder
, &radeon_atom_dac_helper_funcs
);
2293 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
2294 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
2295 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
2296 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TVDAC
);
2297 radeon_encoder
->enc_priv
= radeon_atombios_set_dac_info(radeon_encoder
);
2298 drm_encoder_helper_add(encoder
, &radeon_atom_dac_helper_funcs
);
2300 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
2301 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
2302 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
2303 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
2304 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
2305 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
2306 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
2307 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
2308 radeon_encoder
->rmx_type
= RMX_FULL
;
2309 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_LVDS
);
2310 radeon_encoder
->enc_priv
= radeon_atombios_get_lvds_info(radeon_encoder
);
2311 } else if (radeon_encoder
->devices
& (ATOM_DEVICE_CRT_SUPPORT
)) {
2312 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_DAC
);
2313 radeon_encoder
->enc_priv
= radeon_atombios_set_dig_info(radeon_encoder
);
2315 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
2316 radeon_encoder
->enc_priv
= radeon_atombios_set_dig_info(radeon_encoder
);
2318 drm_encoder_helper_add(encoder
, &radeon_atom_dig_helper_funcs
);
2320 case ENCODER_OBJECT_ID_SI170B
:
2321 case ENCODER_OBJECT_ID_CH7303
:
2322 case ENCODER_OBJECT_ID_EXTERNAL_SDVOA
:
2323 case ENCODER_OBJECT_ID_EXTERNAL_SDVOB
:
2324 case ENCODER_OBJECT_ID_TITFP513
:
2325 case ENCODER_OBJECT_ID_VT1623
:
2326 case ENCODER_OBJECT_ID_HDMI_SI1930
:
2327 case ENCODER_OBJECT_ID_TRAVIS
:
2328 case ENCODER_OBJECT_ID_NUTMEG
:
2329 /* these are handled by the primary encoders */
2330 radeon_encoder
->is_ext_encoder
= true;
2331 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
2332 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_LVDS
);
2333 else if (radeon_encoder
->devices
& (ATOM_DEVICE_CRT_SUPPORT
))
2334 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_DAC
);
2336 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
2337 drm_encoder_helper_add(encoder
, &radeon_atom_ext_helper_funcs
);