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 radeon_encoder_is_dp_bridge(encoder
))) {
372 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
373 radeon_dp_set_link_config(connector
, mode
);
380 atombios_dac_setup(struct drm_encoder
*encoder
, int action
)
382 struct drm_device
*dev
= encoder
->dev
;
383 struct radeon_device
*rdev
= dev
->dev_private
;
384 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
385 DAC_ENCODER_CONTROL_PS_ALLOCATION args
;
387 struct radeon_encoder_atom_dac
*dac_info
= radeon_encoder
->enc_priv
;
389 memset(&args
, 0, sizeof(args
));
391 switch (radeon_encoder
->encoder_id
) {
392 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
393 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
394 index
= GetIndexIntoMasterTable(COMMAND
, DAC1EncoderControl
);
396 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
397 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
398 index
= GetIndexIntoMasterTable(COMMAND
, DAC2EncoderControl
);
402 args
.ucAction
= action
;
404 if (radeon_encoder
->active_device
& (ATOM_DEVICE_CRT_SUPPORT
))
405 args
.ucDacStandard
= ATOM_DAC1_PS2
;
406 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
407 args
.ucDacStandard
= ATOM_DAC1_CV
;
409 switch (dac_info
->tv_std
) {
412 case TV_STD_SCART_PAL
:
415 args
.ucDacStandard
= ATOM_DAC1_PAL
;
421 args
.ucDacStandard
= ATOM_DAC1_NTSC
;
425 args
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
427 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
432 atombios_tv_setup(struct drm_encoder
*encoder
, int action
)
434 struct drm_device
*dev
= encoder
->dev
;
435 struct radeon_device
*rdev
= dev
->dev_private
;
436 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
437 TV_ENCODER_CONTROL_PS_ALLOCATION args
;
439 struct radeon_encoder_atom_dac
*dac_info
= radeon_encoder
->enc_priv
;
441 memset(&args
, 0, sizeof(args
));
443 index
= GetIndexIntoMasterTable(COMMAND
, TVEncoderControl
);
445 args
.sTVEncoder
.ucAction
= action
;
447 if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
448 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_CV
;
450 switch (dac_info
->tv_std
) {
452 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSC
;
455 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL
;
458 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PALM
;
461 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL60
;
464 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSCJ
;
466 case TV_STD_SCART_PAL
:
467 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PAL
; /* ??? */
470 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_SECAM
;
473 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_PALCN
;
476 args
.sTVEncoder
.ucTvStandard
= ATOM_TV_NTSC
;
481 args
.sTVEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
483 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
487 union dvo_encoder_control
{
488 ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION ext_tmds
;
489 DVO_ENCODER_CONTROL_PS_ALLOCATION dvo
;
490 DVO_ENCODER_CONTROL_PS_ALLOCATION_V3 dvo_v3
;
494 atombios_dvo_setup(struct drm_encoder
*encoder
, int action
)
496 struct drm_device
*dev
= encoder
->dev
;
497 struct radeon_device
*rdev
= dev
->dev_private
;
498 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
499 union dvo_encoder_control args
;
500 int index
= GetIndexIntoMasterTable(COMMAND
, DVOEncoderControl
);
502 memset(&args
, 0, sizeof(args
));
504 if (ASIC_IS_DCE3(rdev
)) {
506 args
.dvo_v3
.ucAction
= action
;
507 args
.dvo_v3
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
508 args
.dvo_v3
.ucDVOConfig
= 0; /* XXX */
509 } else if (ASIC_IS_DCE2(rdev
)) {
510 /* DCE2 (pre-DCE3 R6xx, RS600/690/740 */
511 args
.dvo
.sDVOEncoder
.ucAction
= action
;
512 args
.dvo
.sDVOEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
513 /* DFP1, CRT1, TV1 depending on the type of port */
514 args
.dvo
.sDVOEncoder
.ucDeviceType
= ATOM_DEVICE_DFP1_INDEX
;
516 if (radeon_encoder
->pixel_clock
> 165000)
517 args
.dvo
.sDVOEncoder
.usDevAttr
.sDigAttrib
.ucAttribute
|= PANEL_ENCODER_MISC_DUAL
;
520 args
.ext_tmds
.sXTmdsEncoder
.ucEnable
= action
;
522 if (radeon_encoder
->pixel_clock
> 165000)
523 args
.ext_tmds
.sXTmdsEncoder
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
525 /*if (pScrn->rgbBits == 8)*/
526 args
.ext_tmds
.sXTmdsEncoder
.ucMisc
|= ATOM_PANEL_MISC_888RGB
;
529 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
532 union lvds_encoder_control
{
533 LVDS_ENCODER_CONTROL_PS_ALLOCATION v1
;
534 LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2
;
538 atombios_digital_setup(struct drm_encoder
*encoder
, int action
)
540 struct drm_device
*dev
= encoder
->dev
;
541 struct radeon_device
*rdev
= dev
->dev_private
;
542 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
543 struct radeon_encoder_atom_dig
*dig
= radeon_encoder
->enc_priv
;
544 union lvds_encoder_control args
;
546 int hdmi_detected
= 0;
552 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_HDMI
)
555 memset(&args
, 0, sizeof(args
));
557 switch (radeon_encoder
->encoder_id
) {
558 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
559 index
= GetIndexIntoMasterTable(COMMAND
, LVDSEncoderControl
);
561 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
562 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
563 index
= GetIndexIntoMasterTable(COMMAND
, TMDS1EncoderControl
);
565 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
566 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
567 index
= GetIndexIntoMasterTable(COMMAND
, LVDSEncoderControl
);
569 index
= GetIndexIntoMasterTable(COMMAND
, TMDS2EncoderControl
);
573 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
582 args
.v1
.ucAction
= action
;
584 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_HDMI_TYPE
;
585 args
.v1
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
586 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
587 if (dig
->lcd_misc
& ATOM_PANEL_MISC_DUAL
)
588 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
589 if (dig
->lcd_misc
& ATOM_PANEL_MISC_888RGB
)
590 args
.v1
.ucMisc
|= ATOM_PANEL_MISC_888RGB
;
593 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_TMDS_LINKB
;
594 if (radeon_encoder
->pixel_clock
> 165000)
595 args
.v1
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
596 /*if (pScrn->rgbBits == 8) */
597 args
.v1
.ucMisc
|= ATOM_PANEL_MISC_888RGB
;
603 args
.v2
.ucAction
= action
;
605 if (dig
->coherent_mode
)
606 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_COHERENT
;
609 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_HDMI_TYPE
;
610 args
.v2
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
611 args
.v2
.ucTruncate
= 0;
612 args
.v2
.ucSpatial
= 0;
613 args
.v2
.ucTemporal
= 0;
615 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
616 if (dig
->lcd_misc
& ATOM_PANEL_MISC_DUAL
)
617 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
618 if (dig
->lcd_misc
& ATOM_PANEL_MISC_SPATIAL
) {
619 args
.v2
.ucSpatial
= PANEL_ENCODER_SPATIAL_DITHER_EN
;
620 if (dig
->lcd_misc
& ATOM_PANEL_MISC_888RGB
)
621 args
.v2
.ucSpatial
|= PANEL_ENCODER_SPATIAL_DITHER_DEPTH
;
623 if (dig
->lcd_misc
& ATOM_PANEL_MISC_TEMPORAL
) {
624 args
.v2
.ucTemporal
= PANEL_ENCODER_TEMPORAL_DITHER_EN
;
625 if (dig
->lcd_misc
& ATOM_PANEL_MISC_888RGB
)
626 args
.v2
.ucTemporal
|= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH
;
627 if (((dig
->lcd_misc
>> ATOM_PANEL_MISC_GREY_LEVEL_SHIFT
) & 0x3) == 2)
628 args
.v2
.ucTemporal
|= PANEL_ENCODER_TEMPORAL_LEVEL_4
;
632 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_TMDS_LINKB
;
633 if (radeon_encoder
->pixel_clock
> 165000)
634 args
.v2
.ucMisc
|= PANEL_ENCODER_MISC_DUAL
;
638 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
643 DRM_ERROR("Unknown table version %d, %d\n", frev
, crev
);
647 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
651 atombios_get_encoder_mode(struct drm_encoder
*encoder
)
653 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
654 struct drm_device
*dev
= encoder
->dev
;
655 struct radeon_device
*rdev
= dev
->dev_private
;
656 struct drm_connector
*connector
;
657 struct radeon_connector
*radeon_connector
;
658 struct radeon_connector_atom_dig
*dig_connector
;
660 /* dp bridges are always DP */
661 if (radeon_encoder_is_dp_bridge(encoder
))
662 return ATOM_ENCODER_MODE_DP
;
664 /* DVO is always DVO */
665 if (radeon_encoder
->encoder_id
== ATOM_ENCODER_MODE_DVO
)
666 return ATOM_ENCODER_MODE_DVO
;
668 connector
= radeon_get_connector_for_encoder(encoder
);
669 /* if we don't have an active device yet, just use one of
670 * the connectors tied to the encoder.
673 connector
= radeon_get_connector_for_encoder_init(encoder
);
674 radeon_connector
= to_radeon_connector(connector
);
676 switch (connector
->connector_type
) {
677 case DRM_MODE_CONNECTOR_DVII
:
678 case DRM_MODE_CONNECTOR_HDMIB
: /* HDMI-B is basically DL-DVI; analog works fine */
679 if (drm_detect_monitor_audio(radeon_connector
->edid
) && radeon_audio
) {
681 if (ASIC_IS_DCE4(rdev
))
682 return ATOM_ENCODER_MODE_DVI
;
684 return ATOM_ENCODER_MODE_HDMI
;
685 } else if (radeon_connector
->use_digital
)
686 return ATOM_ENCODER_MODE_DVI
;
688 return ATOM_ENCODER_MODE_CRT
;
690 case DRM_MODE_CONNECTOR_DVID
:
691 case DRM_MODE_CONNECTOR_HDMIA
:
693 if (drm_detect_monitor_audio(radeon_connector
->edid
) && radeon_audio
) {
695 if (ASIC_IS_DCE4(rdev
))
696 return ATOM_ENCODER_MODE_DVI
;
698 return ATOM_ENCODER_MODE_HDMI
;
700 return ATOM_ENCODER_MODE_DVI
;
702 case DRM_MODE_CONNECTOR_LVDS
:
703 return ATOM_ENCODER_MODE_LVDS
;
705 case DRM_MODE_CONNECTOR_DisplayPort
:
706 dig_connector
= radeon_connector
->con_priv
;
707 if ((dig_connector
->dp_sink_type
== CONNECTOR_OBJECT_ID_DISPLAYPORT
) ||
708 (dig_connector
->dp_sink_type
== CONNECTOR_OBJECT_ID_eDP
))
709 return ATOM_ENCODER_MODE_DP
;
710 else if (drm_detect_monitor_audio(radeon_connector
->edid
) && radeon_audio
) {
712 if (ASIC_IS_DCE4(rdev
))
713 return ATOM_ENCODER_MODE_DVI
;
715 return ATOM_ENCODER_MODE_HDMI
;
717 return ATOM_ENCODER_MODE_DVI
;
719 case DRM_MODE_CONNECTOR_eDP
:
720 return ATOM_ENCODER_MODE_DP
;
721 case DRM_MODE_CONNECTOR_DVIA
:
722 case DRM_MODE_CONNECTOR_VGA
:
723 return ATOM_ENCODER_MODE_CRT
;
725 case DRM_MODE_CONNECTOR_Composite
:
726 case DRM_MODE_CONNECTOR_SVIDEO
:
727 case DRM_MODE_CONNECTOR_9PinDIN
:
729 return ATOM_ENCODER_MODE_TV
;
730 /*return ATOM_ENCODER_MODE_CV;*/
736 * DIG Encoder/Transmitter Setup
739 * - 2 DIG transmitter blocks. UNIPHY (links A and B) and LVTMA.
740 * Supports up to 3 digital outputs
741 * - 2 DIG encoder blocks.
742 * DIG1 can drive UNIPHY link A or link B
743 * DIG2 can drive UNIPHY link B or LVTMA
746 * - 3 DIG transmitter blocks. UNIPHY0/1/2 (links A and B).
747 * Supports up to 5 digital outputs
748 * - 2 DIG encoder blocks.
749 * DIG1/2 can drive UNIPHY0/1/2 link A or link B
752 * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
753 * Supports up to 6 digital outputs
754 * - 6 DIG encoder blocks.
755 * - DIG to PHY mapping is hardcoded
756 * DIG1 drives UNIPHY0 link A, A+B
757 * DIG2 drives UNIPHY0 link B
758 * DIG3 drives UNIPHY1 link A, A+B
759 * DIG4 drives UNIPHY1 link B
760 * DIG5 drives UNIPHY2 link A, A+B
761 * DIG6 drives UNIPHY2 link B
764 * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
765 * Supports up to 6 digital outputs
766 * - 2 DIG encoder blocks.
767 * DIG1/2 can drive UNIPHY0/1/2 link A or link B
770 * crtc -> dig encoder -> UNIPHY/LVTMA (1 or 2 links)
772 * crtc0 -> dig2 -> LVTMA links A+B -> TMDS/HDMI
773 * crtc1 -> dig1 -> UNIPHY0 link B -> DP
774 * crtc0 -> dig1 -> UNIPHY2 link A -> LVDS
775 * crtc1 -> dig2 -> UNIPHY1 link B+A -> TMDS/HDMI
778 union dig_encoder_control
{
779 DIG_ENCODER_CONTROL_PS_ALLOCATION v1
;
780 DIG_ENCODER_CONTROL_PARAMETERS_V2 v2
;
781 DIG_ENCODER_CONTROL_PARAMETERS_V3 v3
;
782 DIG_ENCODER_CONTROL_PARAMETERS_V4 v4
;
786 atombios_dig_encoder_setup(struct drm_encoder
*encoder
, int action
, int panel_mode
)
788 struct drm_device
*dev
= encoder
->dev
;
789 struct radeon_device
*rdev
= dev
->dev_private
;
790 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
791 struct radeon_encoder_atom_dig
*dig
= radeon_encoder
->enc_priv
;
792 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
793 union dig_encoder_control args
;
797 int dp_lane_count
= 0;
798 int hpd_id
= RADEON_HPD_NONE
;
802 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
803 struct radeon_connector_atom_dig
*dig_connector
=
804 radeon_connector
->con_priv
;
806 dp_clock
= dig_connector
->dp_clock
;
807 dp_lane_count
= dig_connector
->dp_lane_count
;
808 hpd_id
= radeon_connector
->hpd
.hpd
;
809 bpc
= connector
->display_info
.bpc
;
812 /* no dig encoder assigned */
813 if (dig
->dig_encoder
== -1)
816 memset(&args
, 0, sizeof(args
));
818 if (ASIC_IS_DCE4(rdev
))
819 index
= GetIndexIntoMasterTable(COMMAND
, DIGxEncoderControl
);
821 if (dig
->dig_encoder
)
822 index
= GetIndexIntoMasterTable(COMMAND
, DIG2EncoderControl
);
824 index
= GetIndexIntoMasterTable(COMMAND
, DIG1EncoderControl
);
827 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
830 args
.v1
.ucAction
= action
;
831 args
.v1
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
832 if (action
== ATOM_ENCODER_CMD_SETUP_PANEL_MODE
)
833 args
.v3
.ucPanelMode
= panel_mode
;
835 args
.v1
.ucEncoderMode
= atombios_get_encoder_mode(encoder
);
837 if ((args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) ||
838 (args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP_MST
))
839 args
.v1
.ucLaneNum
= dp_lane_count
;
840 else if (radeon_encoder
->pixel_clock
> 165000)
841 args
.v1
.ucLaneNum
= 8;
843 args
.v1
.ucLaneNum
= 4;
845 if (ASIC_IS_DCE5(rdev
)) {
846 if ((args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) ||
847 (args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP_MST
)) {
848 if (dp_clock
== 270000)
849 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_2_70GHZ
;
850 else if (dp_clock
== 540000)
851 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_5_40GHZ
;
853 args
.v4
.acConfig
.ucDigSel
= dig
->dig_encoder
;
856 args
.v4
.ucBitPerColor
= PANEL_BPC_UNDEFINE
;
859 args
.v4
.ucBitPerColor
= PANEL_6BIT_PER_COLOR
;
863 args
.v4
.ucBitPerColor
= PANEL_8BIT_PER_COLOR
;
866 args
.v4
.ucBitPerColor
= PANEL_10BIT_PER_COLOR
;
869 args
.v4
.ucBitPerColor
= PANEL_12BIT_PER_COLOR
;
872 args
.v4
.ucBitPerColor
= PANEL_16BIT_PER_COLOR
;
875 if (hpd_id
== RADEON_HPD_NONE
)
876 args
.v4
.ucHPD_ID
= 0;
878 args
.v4
.ucHPD_ID
= hpd_id
+ 1;
879 } else if (ASIC_IS_DCE4(rdev
)) {
880 if ((args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) && (dp_clock
== 270000))
881 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ
;
882 args
.v3
.acConfig
.ucDigSel
= dig
->dig_encoder
;
885 args
.v3
.ucBitPerColor
= PANEL_BPC_UNDEFINE
;
888 args
.v3
.ucBitPerColor
= PANEL_6BIT_PER_COLOR
;
892 args
.v3
.ucBitPerColor
= PANEL_8BIT_PER_COLOR
;
895 args
.v3
.ucBitPerColor
= PANEL_10BIT_PER_COLOR
;
898 args
.v3
.ucBitPerColor
= PANEL_12BIT_PER_COLOR
;
901 args
.v3
.ucBitPerColor
= PANEL_16BIT_PER_COLOR
;
905 if ((args
.v1
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) && (dp_clock
== 270000))
906 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ
;
907 switch (radeon_encoder
->encoder_id
) {
908 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
909 args
.v1
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER1
;
911 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
912 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
913 args
.v1
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER2
;
915 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
916 args
.v1
.ucConfig
= ATOM_ENCODER_CONFIG_V2_TRANSMITTER3
;
920 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_LINKB
;
922 args
.v1
.ucConfig
|= ATOM_ENCODER_CONFIG_LINKA
;
925 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
929 union dig_transmitter_control
{
930 DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1
;
931 DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2
;
932 DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 v3
;
933 DIG_TRANSMITTER_CONTROL_PARAMETERS_V4 v4
;
937 atombios_dig_transmitter_setup(struct drm_encoder
*encoder
, int action
, uint8_t lane_num
, uint8_t lane_set
)
939 struct drm_device
*dev
= encoder
->dev
;
940 struct radeon_device
*rdev
= dev
->dev_private
;
941 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
942 struct radeon_encoder_atom_dig
*dig
= radeon_encoder
->enc_priv
;
943 struct drm_connector
*connector
;
944 union dig_transmitter_control args
;
950 int dp_lane_count
= 0;
951 int connector_object_id
= 0;
952 int igp_lane_info
= 0;
953 int dig_encoder
= dig
->dig_encoder
;
955 if (action
== ATOM_TRANSMITTER_ACTION_INIT
) {
956 connector
= radeon_get_connector_for_encoder_init(encoder
);
957 /* just needed to avoid bailing in the encoder check. the encoder
958 * isn't used for init
962 connector
= radeon_get_connector_for_encoder(encoder
);
965 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
966 struct radeon_connector_atom_dig
*dig_connector
=
967 radeon_connector
->con_priv
;
969 dp_clock
= dig_connector
->dp_clock
;
970 dp_lane_count
= dig_connector
->dp_lane_count
;
971 connector_object_id
=
972 (radeon_connector
->connector_object_id
& OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
973 igp_lane_info
= dig_connector
->igp_lane_info
;
976 /* no dig encoder assigned */
977 if (dig_encoder
== -1)
980 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_DP
)
983 memset(&args
, 0, sizeof(args
));
985 switch (radeon_encoder
->encoder_id
) {
986 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
987 index
= GetIndexIntoMasterTable(COMMAND
, DVOOutputControl
);
989 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
990 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
991 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
992 index
= GetIndexIntoMasterTable(COMMAND
, UNIPHYTransmitterControl
);
994 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
995 index
= GetIndexIntoMasterTable(COMMAND
, LVTMATransmitterControl
);
999 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
1002 args
.v1
.ucAction
= action
;
1003 if (action
== ATOM_TRANSMITTER_ACTION_INIT
) {
1004 args
.v1
.usInitInfo
= cpu_to_le16(connector_object_id
);
1005 } else if (action
== ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH
) {
1006 args
.v1
.asMode
.ucLaneSel
= lane_num
;
1007 args
.v1
.asMode
.ucLaneSet
= lane_set
;
1010 args
.v1
.usPixelClock
=
1011 cpu_to_le16(dp_clock
/ 10);
1012 else if (radeon_encoder
->pixel_clock
> 165000)
1013 args
.v1
.usPixelClock
= cpu_to_le16((radeon_encoder
->pixel_clock
/ 2) / 10);
1015 args
.v1
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
1017 if (ASIC_IS_DCE4(rdev
)) {
1019 args
.v3
.ucLaneNum
= dp_lane_count
;
1020 else if (radeon_encoder
->pixel_clock
> 165000)
1021 args
.v3
.ucLaneNum
= 8;
1023 args
.v3
.ucLaneNum
= 4;
1026 args
.v3
.acConfig
.ucLinkSel
= 1;
1027 if (dig_encoder
& 1)
1028 args
.v3
.acConfig
.ucEncoderSel
= 1;
1030 /* Select the PLL for the PHY
1031 * DP PHY should be clocked from external src if there is
1034 if (encoder
->crtc
) {
1035 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1036 pll_id
= radeon_crtc
->pll_id
;
1039 if (ASIC_IS_DCE5(rdev
)) {
1040 /* On DCE5 DCPLL usually generates the DP ref clock */
1042 if (rdev
->clock
.dp_extclk
)
1043 args
.v4
.acConfig
.ucRefClkSource
= ENCODER_REFCLK_SRC_EXTCLK
;
1045 args
.v4
.acConfig
.ucRefClkSource
= ENCODER_REFCLK_SRC_DCPLL
;
1047 args
.v4
.acConfig
.ucRefClkSource
= pll_id
;
1049 /* On DCE4, if there is an external clock, it generates the DP ref clock */
1050 if (is_dp
&& rdev
->clock
.dp_extclk
)
1051 args
.v3
.acConfig
.ucRefClkSource
= 2; /* external src */
1053 args
.v3
.acConfig
.ucRefClkSource
= pll_id
;
1056 switch (radeon_encoder
->encoder_id
) {
1057 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1058 args
.v3
.acConfig
.ucTransmitterSel
= 0;
1060 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1061 args
.v3
.acConfig
.ucTransmitterSel
= 1;
1063 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1064 args
.v3
.acConfig
.ucTransmitterSel
= 2;
1069 args
.v3
.acConfig
.fCoherentMode
= 1; /* DP requires coherent */
1070 else if (radeon_encoder
->devices
& (ATOM_DEVICE_DFP_SUPPORT
)) {
1071 if (dig
->coherent_mode
)
1072 args
.v3
.acConfig
.fCoherentMode
= 1;
1073 if (radeon_encoder
->pixel_clock
> 165000)
1074 args
.v3
.acConfig
.fDualLinkConnector
= 1;
1076 } else if (ASIC_IS_DCE32(rdev
)) {
1077 args
.v2
.acConfig
.ucEncoderSel
= dig_encoder
;
1079 args
.v2
.acConfig
.ucLinkSel
= 1;
1081 switch (radeon_encoder
->encoder_id
) {
1082 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1083 args
.v2
.acConfig
.ucTransmitterSel
= 0;
1085 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1086 args
.v2
.acConfig
.ucTransmitterSel
= 1;
1088 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1089 args
.v2
.acConfig
.ucTransmitterSel
= 2;
1094 args
.v2
.acConfig
.fCoherentMode
= 1;
1095 args
.v2
.acConfig
.fDPConnector
= 1;
1096 } else if (radeon_encoder
->devices
& (ATOM_DEVICE_DFP_SUPPORT
)) {
1097 if (dig
->coherent_mode
)
1098 args
.v2
.acConfig
.fCoherentMode
= 1;
1099 if (radeon_encoder
->pixel_clock
> 165000)
1100 args
.v2
.acConfig
.fDualLinkConnector
= 1;
1103 args
.v1
.ucConfig
= ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL
;
1106 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER
;
1108 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER
;
1110 if ((rdev
->flags
& RADEON_IS_IGP
) &&
1111 (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_UNIPHY
)) {
1112 if (is_dp
|| (radeon_encoder
->pixel_clock
<= 165000)) {
1113 if (igp_lane_info
& 0x1)
1114 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_0_3
;
1115 else if (igp_lane_info
& 0x2)
1116 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_4_7
;
1117 else if (igp_lane_info
& 0x4)
1118 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_8_11
;
1119 else if (igp_lane_info
& 0x8)
1120 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_12_15
;
1122 if (igp_lane_info
& 0x3)
1123 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_0_7
;
1124 else if (igp_lane_info
& 0xc)
1125 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LANE_8_15
;
1130 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LINKB
;
1132 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_LINKA
;
1135 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_COHERENT
;
1136 else if (radeon_encoder
->devices
& (ATOM_DEVICE_DFP_SUPPORT
)) {
1137 if (dig
->coherent_mode
)
1138 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_COHERENT
;
1139 if (radeon_encoder
->pixel_clock
> 165000)
1140 args
.v1
.ucConfig
|= ATOM_TRANSMITTER_CONFIG_8LANE_LINK
;
1144 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1148 atombios_set_edp_panel_power(struct drm_connector
*connector
, int action
)
1150 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1151 struct drm_device
*dev
= radeon_connector
->base
.dev
;
1152 struct radeon_device
*rdev
= dev
->dev_private
;
1153 union dig_transmitter_control args
;
1154 int index
= GetIndexIntoMasterTable(COMMAND
, UNIPHYTransmitterControl
);
1157 if (connector
->connector_type
!= DRM_MODE_CONNECTOR_eDP
)
1160 if (!ASIC_IS_DCE4(rdev
))
1163 if ((action
!= ATOM_TRANSMITTER_ACTION_POWER_ON
) &&
1164 (action
!= ATOM_TRANSMITTER_ACTION_POWER_OFF
))
1167 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
1170 memset(&args
, 0, sizeof(args
));
1172 args
.v1
.ucAction
= action
;
1174 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1176 /* wait for the panel to power up */
1177 if (action
== ATOM_TRANSMITTER_ACTION_POWER_ON
) {
1180 for (i
= 0; i
< 300; i
++) {
1181 if (radeon_hpd_sense(rdev
, radeon_connector
->hpd
.hpd
))
1191 union external_encoder_control
{
1192 EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION v1
;
1193 EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION_V3 v3
;
1197 atombios_external_encoder_setup(struct drm_encoder
*encoder
,
1198 struct drm_encoder
*ext_encoder
,
1201 struct drm_device
*dev
= encoder
->dev
;
1202 struct radeon_device
*rdev
= dev
->dev_private
;
1203 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1204 struct radeon_encoder
*ext_radeon_encoder
= to_radeon_encoder(ext_encoder
);
1205 union external_encoder_control args
;
1206 struct drm_connector
*connector
;
1207 int index
= GetIndexIntoMasterTable(COMMAND
, ExternalEncoderControl
);
1210 int dp_lane_count
= 0;
1211 int connector_object_id
= 0;
1212 u32 ext_enum
= (ext_radeon_encoder
->encoder_enum
& ENUM_ID_MASK
) >> ENUM_ID_SHIFT
;
1215 if (action
== EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT
)
1216 connector
= radeon_get_connector_for_encoder_init(encoder
);
1218 connector
= radeon_get_connector_for_encoder(encoder
);
1221 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1222 struct radeon_connector_atom_dig
*dig_connector
=
1223 radeon_connector
->con_priv
;
1225 dp_clock
= dig_connector
->dp_clock
;
1226 dp_lane_count
= dig_connector
->dp_lane_count
;
1227 connector_object_id
=
1228 (radeon_connector
->connector_object_id
& OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
1229 bpc
= connector
->display_info
.bpc
;
1232 memset(&args
, 0, sizeof(args
));
1234 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
1239 /* no params on frev 1 */
1245 args
.v1
.sDigEncoder
.ucAction
= action
;
1246 args
.v1
.sDigEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
1247 args
.v1
.sDigEncoder
.ucEncoderMode
= atombios_get_encoder_mode(encoder
);
1249 if (args
.v1
.sDigEncoder
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) {
1250 if (dp_clock
== 270000)
1251 args
.v1
.sDigEncoder
.ucConfig
|= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ
;
1252 args
.v1
.sDigEncoder
.ucLaneNum
= dp_lane_count
;
1253 } else if (radeon_encoder
->pixel_clock
> 165000)
1254 args
.v1
.sDigEncoder
.ucLaneNum
= 8;
1256 args
.v1
.sDigEncoder
.ucLaneNum
= 4;
1259 args
.v3
.sExtEncoder
.ucAction
= action
;
1260 if (action
== EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT
)
1261 args
.v3
.sExtEncoder
.usConnectorId
= cpu_to_le16(connector_object_id
);
1263 args
.v3
.sExtEncoder
.usPixelClock
= cpu_to_le16(radeon_encoder
->pixel_clock
/ 10);
1264 args
.v3
.sExtEncoder
.ucEncoderMode
= atombios_get_encoder_mode(encoder
);
1266 if (args
.v3
.sExtEncoder
.ucEncoderMode
== ATOM_ENCODER_MODE_DP
) {
1267 if (dp_clock
== 270000)
1268 args
.v3
.sExtEncoder
.ucConfig
|= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ
;
1269 else if (dp_clock
== 540000)
1270 args
.v3
.sExtEncoder
.ucConfig
|= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_5_40GHZ
;
1271 args
.v3
.sExtEncoder
.ucLaneNum
= dp_lane_count
;
1272 } else if (radeon_encoder
->pixel_clock
> 165000)
1273 args
.v3
.sExtEncoder
.ucLaneNum
= 8;
1275 args
.v3
.sExtEncoder
.ucLaneNum
= 4;
1277 case GRAPH_OBJECT_ENUM_ID1
:
1278 args
.v3
.sExtEncoder
.ucConfig
|= EXTERNAL_ENCODER_CONFIG_V3_ENCODER1
;
1280 case GRAPH_OBJECT_ENUM_ID2
:
1281 args
.v3
.sExtEncoder
.ucConfig
|= EXTERNAL_ENCODER_CONFIG_V3_ENCODER2
;
1283 case GRAPH_OBJECT_ENUM_ID3
:
1284 args
.v3
.sExtEncoder
.ucConfig
|= EXTERNAL_ENCODER_CONFIG_V3_ENCODER3
;
1289 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_BPC_UNDEFINE
;
1292 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_6BIT_PER_COLOR
;
1296 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_8BIT_PER_COLOR
;
1299 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_10BIT_PER_COLOR
;
1302 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_12BIT_PER_COLOR
;
1305 args
.v3
.sExtEncoder
.ucBitPerColor
= PANEL_16BIT_PER_COLOR
;
1310 DRM_ERROR("Unknown table version: %d, %d\n", frev
, crev
);
1315 DRM_ERROR("Unknown table version: %d, %d\n", frev
, crev
);
1318 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1322 atombios_yuv_setup(struct drm_encoder
*encoder
, bool enable
)
1324 struct drm_device
*dev
= encoder
->dev
;
1325 struct radeon_device
*rdev
= dev
->dev_private
;
1326 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1327 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1328 ENABLE_YUV_PS_ALLOCATION args
;
1329 int index
= GetIndexIntoMasterTable(COMMAND
, EnableYUV
);
1332 memset(&args
, 0, sizeof(args
));
1334 if (rdev
->family
>= CHIP_R600
)
1335 reg
= R600_BIOS_3_SCRATCH
;
1337 reg
= RADEON_BIOS_3_SCRATCH
;
1339 /* XXX: fix up scratch reg handling */
1341 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1342 WREG32(reg
, (ATOM_S3_TV1_ACTIVE
|
1343 (radeon_crtc
->crtc_id
<< 18)));
1344 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1345 WREG32(reg
, (ATOM_S3_CV_ACTIVE
| (radeon_crtc
->crtc_id
<< 24)));
1350 args
.ucEnable
= ATOM_ENABLE
;
1351 args
.ucCRTC
= radeon_crtc
->crtc_id
;
1353 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1359 radeon_atom_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
1361 struct drm_device
*dev
= encoder
->dev
;
1362 struct radeon_device
*rdev
= dev
->dev_private
;
1363 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1364 struct drm_encoder
*ext_encoder
= radeon_atom_get_external_encoder(encoder
);
1365 DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args
;
1367 bool is_dig
= false;
1368 bool is_dce5_dac
= false;
1369 bool is_dce5_dvo
= false;
1371 memset(&args
, 0, sizeof(args
));
1373 DRM_DEBUG_KMS("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n",
1374 radeon_encoder
->encoder_id
, mode
, radeon_encoder
->devices
,
1375 radeon_encoder
->active_device
);
1376 switch (radeon_encoder
->encoder_id
) {
1377 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1378 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
1379 index
= GetIndexIntoMasterTable(COMMAND
, TMDSAOutputControl
);
1381 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1382 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1383 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1384 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1387 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1388 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
1389 index
= GetIndexIntoMasterTable(COMMAND
, DVOOutputControl
);
1391 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1392 if (ASIC_IS_DCE5(rdev
))
1394 else if (ASIC_IS_DCE3(rdev
))
1397 index
= GetIndexIntoMasterTable(COMMAND
, DVOOutputControl
);
1399 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1400 index
= GetIndexIntoMasterTable(COMMAND
, LCD1OutputControl
);
1402 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
1403 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
1404 index
= GetIndexIntoMasterTable(COMMAND
, LCD1OutputControl
);
1406 index
= GetIndexIntoMasterTable(COMMAND
, LVTMAOutputControl
);
1408 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1409 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1410 if (ASIC_IS_DCE5(rdev
))
1413 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1414 index
= GetIndexIntoMasterTable(COMMAND
, TV1OutputControl
);
1415 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1416 index
= GetIndexIntoMasterTable(COMMAND
, CV1OutputControl
);
1418 index
= GetIndexIntoMasterTable(COMMAND
, DAC1OutputControl
);
1421 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1422 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1423 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1424 index
= GetIndexIntoMasterTable(COMMAND
, TV1OutputControl
);
1425 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1426 index
= GetIndexIntoMasterTable(COMMAND
, CV1OutputControl
);
1428 index
= GetIndexIntoMasterTable(COMMAND
, DAC2OutputControl
);
1434 case DRM_MODE_DPMS_ON
:
1435 /* some early dce3.2 boards have a bug in their transmitter control table */
1436 if ((rdev
->family
== CHIP_RV710
) || (rdev
->family
== CHIP_RV730
))
1437 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_ENABLE
, 0, 0);
1439 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT
, 0, 0);
1440 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_DP
) {
1441 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
1444 (connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
)) {
1445 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1446 struct radeon_connector_atom_dig
*radeon_dig_connector
=
1447 radeon_connector
->con_priv
;
1448 atombios_set_edp_panel_power(connector
,
1449 ATOM_TRANSMITTER_ACTION_POWER_ON
);
1450 radeon_dig_connector
->edp_on
= true;
1452 if (ASIC_IS_DCE4(rdev
))
1453 atombios_dig_encoder_setup(encoder
, ATOM_ENCODER_CMD_DP_VIDEO_OFF
, 0);
1454 radeon_dp_link_train(encoder
, connector
);
1455 if (ASIC_IS_DCE4(rdev
))
1456 atombios_dig_encoder_setup(encoder
, ATOM_ENCODER_CMD_DP_VIDEO_ON
, 0);
1458 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
1459 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_LCD_BLON
, 0, 0);
1461 case DRM_MODE_DPMS_STANDBY
:
1462 case DRM_MODE_DPMS_SUSPEND
:
1463 case DRM_MODE_DPMS_OFF
:
1464 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT
, 0, 0);
1465 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_DP
) {
1466 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
1468 if (ASIC_IS_DCE4(rdev
))
1469 atombios_dig_encoder_setup(encoder
, ATOM_ENCODER_CMD_DP_VIDEO_OFF
, 0);
1471 (connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
)) {
1472 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1473 struct radeon_connector_atom_dig
*radeon_dig_connector
=
1474 radeon_connector
->con_priv
;
1475 atombios_set_edp_panel_power(connector
,
1476 ATOM_TRANSMITTER_ACTION_POWER_OFF
);
1477 radeon_dig_connector
->edp_on
= false;
1480 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
1481 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_LCD_BLOFF
, 0, 0);
1484 } else if (is_dce5_dac
) {
1486 case DRM_MODE_DPMS_ON
:
1487 atombios_dac_setup(encoder
, ATOM_ENABLE
);
1489 case DRM_MODE_DPMS_STANDBY
:
1490 case DRM_MODE_DPMS_SUSPEND
:
1491 case DRM_MODE_DPMS_OFF
:
1492 atombios_dac_setup(encoder
, ATOM_DISABLE
);
1495 } else if (is_dce5_dvo
) {
1497 case DRM_MODE_DPMS_ON
:
1498 atombios_dvo_setup(encoder
, ATOM_ENABLE
);
1500 case DRM_MODE_DPMS_STANDBY
:
1501 case DRM_MODE_DPMS_SUSPEND
:
1502 case DRM_MODE_DPMS_OFF
:
1503 atombios_dvo_setup(encoder
, ATOM_DISABLE
);
1508 case DRM_MODE_DPMS_ON
:
1509 args
.ucAction
= ATOM_ENABLE
;
1510 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1511 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
1512 args
.ucAction
= ATOM_LCD_BLON
;
1513 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1516 case DRM_MODE_DPMS_STANDBY
:
1517 case DRM_MODE_DPMS_SUSPEND
:
1518 case DRM_MODE_DPMS_OFF
:
1519 args
.ucAction
= ATOM_DISABLE
;
1520 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1521 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
1522 args
.ucAction
= ATOM_LCD_BLOFF
;
1523 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1531 case DRM_MODE_DPMS_ON
:
1533 if (ASIC_IS_DCE41(rdev
)) {
1534 atombios_external_encoder_setup(encoder
, ext_encoder
,
1535 EXTERNAL_ENCODER_ACTION_V3_ENABLE_OUTPUT
);
1536 atombios_external_encoder_setup(encoder
, ext_encoder
,
1537 EXTERNAL_ENCODER_ACTION_V3_ENCODER_BLANKING_OFF
);
1539 atombios_external_encoder_setup(encoder
, ext_encoder
, ATOM_ENABLE
);
1541 case DRM_MODE_DPMS_STANDBY
:
1542 case DRM_MODE_DPMS_SUSPEND
:
1543 case DRM_MODE_DPMS_OFF
:
1544 if (ASIC_IS_DCE41(rdev
)) {
1545 atombios_external_encoder_setup(encoder
, ext_encoder
,
1546 EXTERNAL_ENCODER_ACTION_V3_ENCODER_BLANKING
);
1547 atombios_external_encoder_setup(encoder
, ext_encoder
,
1548 EXTERNAL_ENCODER_ACTION_V3_DISABLE_OUTPUT
);
1550 atombios_external_encoder_setup(encoder
, ext_encoder
, ATOM_DISABLE
);
1555 radeon_atombios_encoder_dpms_scratch_regs(encoder
, (mode
== DRM_MODE_DPMS_ON
) ? true : false);
1559 union crtc_source_param
{
1560 SELECT_CRTC_SOURCE_PS_ALLOCATION v1
;
1561 SELECT_CRTC_SOURCE_PARAMETERS_V2 v2
;
1565 atombios_set_encoder_crtc_source(struct drm_encoder
*encoder
)
1567 struct drm_device
*dev
= encoder
->dev
;
1568 struct radeon_device
*rdev
= dev
->dev_private
;
1569 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1570 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1571 union crtc_source_param args
;
1572 int index
= GetIndexIntoMasterTable(COMMAND
, SelectCRTC_Source
);
1574 struct radeon_encoder_atom_dig
*dig
;
1576 memset(&args
, 0, sizeof(args
));
1578 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
1586 if (ASIC_IS_AVIVO(rdev
))
1587 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
;
1589 if (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_DAC1
) {
1590 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
;
1592 args
.v1
.ucCRTC
= radeon_crtc
->crtc_id
<< 2;
1595 switch (radeon_encoder
->encoder_id
) {
1596 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1597 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
1598 args
.v1
.ucDevice
= ATOM_DEVICE_DFP1_INDEX
;
1600 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1601 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
1602 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
)
1603 args
.v1
.ucDevice
= ATOM_DEVICE_LCD1_INDEX
;
1605 args
.v1
.ucDevice
= ATOM_DEVICE_DFP3_INDEX
;
1607 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1608 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
1609 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1610 args
.v1
.ucDevice
= ATOM_DEVICE_DFP2_INDEX
;
1612 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1613 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
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_CRT1_INDEX
;
1621 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1622 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1623 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1624 args
.v1
.ucDevice
= ATOM_DEVICE_TV1_INDEX
;
1625 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1626 args
.v1
.ucDevice
= ATOM_DEVICE_CV_INDEX
;
1628 args
.v1
.ucDevice
= ATOM_DEVICE_CRT2_INDEX
;
1633 args
.v2
.ucCRTC
= radeon_crtc
->crtc_id
;
1634 args
.v2
.ucEncodeMode
= atombios_get_encoder_mode(encoder
);
1635 switch (radeon_encoder
->encoder_id
) {
1636 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1637 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1638 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1639 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1640 dig
= radeon_encoder
->enc_priv
;
1641 switch (dig
->dig_encoder
) {
1643 args
.v2
.ucEncoderID
= ASIC_INT_DIG1_ENCODER_ID
;
1646 args
.v2
.ucEncoderID
= ASIC_INT_DIG2_ENCODER_ID
;
1649 args
.v2
.ucEncoderID
= ASIC_INT_DIG3_ENCODER_ID
;
1652 args
.v2
.ucEncoderID
= ASIC_INT_DIG4_ENCODER_ID
;
1655 args
.v2
.ucEncoderID
= ASIC_INT_DIG5_ENCODER_ID
;
1658 args
.v2
.ucEncoderID
= ASIC_INT_DIG6_ENCODER_ID
;
1662 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1663 args
.v2
.ucEncoderID
= ASIC_INT_DVO_ENCODER_ID
;
1665 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1666 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1667 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1668 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1669 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1671 args
.v2
.ucEncoderID
= ASIC_INT_DAC1_ENCODER_ID
;
1673 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1674 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
))
1675 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1676 else if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
))
1677 args
.v2
.ucEncoderID
= ASIC_INT_TV_ENCODER_ID
;
1679 args
.v2
.ucEncoderID
= ASIC_INT_DAC2_ENCODER_ID
;
1686 DRM_ERROR("Unknown table version: %d, %d\n", frev
, crev
);
1690 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1692 /* update scratch regs with new routing */
1693 radeon_atombios_encoder_crtc_scratch_regs(encoder
, radeon_crtc
->crtc_id
);
1697 atombios_apply_encoder_quirks(struct drm_encoder
*encoder
,
1698 struct drm_display_mode
*mode
)
1700 struct drm_device
*dev
= encoder
->dev
;
1701 struct radeon_device
*rdev
= dev
->dev_private
;
1702 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1703 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1705 /* Funky macbooks */
1706 if ((dev
->pdev
->device
== 0x71C5) &&
1707 (dev
->pdev
->subsystem_vendor
== 0x106b) &&
1708 (dev
->pdev
->subsystem_device
== 0x0080)) {
1709 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD1_SUPPORT
) {
1710 uint32_t lvtma_bit_depth_control
= RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL
);
1712 lvtma_bit_depth_control
&= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN
;
1713 lvtma_bit_depth_control
&= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN
;
1715 WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL
, lvtma_bit_depth_control
);
1719 /* set scaler clears this on some chips */
1720 if (ASIC_IS_AVIVO(rdev
) &&
1721 (!(radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
)))) {
1722 if (ASIC_IS_DCE4(rdev
)) {
1723 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1724 WREG32(EVERGREEN_DATA_FORMAT
+ radeon_crtc
->crtc_offset
,
1725 EVERGREEN_INTERLEAVE_EN
);
1727 WREG32(EVERGREEN_DATA_FORMAT
+ radeon_crtc
->crtc_offset
, 0);
1729 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1730 WREG32(AVIVO_D1MODE_DATA_FORMAT
+ radeon_crtc
->crtc_offset
,
1731 AVIVO_D1MODE_INTERLEAVE_EN
);
1733 WREG32(AVIVO_D1MODE_DATA_FORMAT
+ radeon_crtc
->crtc_offset
, 0);
1738 static int radeon_atom_pick_dig_encoder(struct drm_encoder
*encoder
)
1740 struct drm_device
*dev
= encoder
->dev
;
1741 struct radeon_device
*rdev
= dev
->dev_private
;
1742 struct radeon_crtc
*radeon_crtc
= to_radeon_crtc(encoder
->crtc
);
1743 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1744 struct drm_encoder
*test_encoder
;
1745 struct radeon_encoder_atom_dig
*dig
;
1746 uint32_t dig_enc_in_use
= 0;
1749 if (ASIC_IS_DCE4(rdev
)) {
1750 dig
= radeon_encoder
->enc_priv
;
1751 if (ASIC_IS_DCE41(rdev
))
1752 return radeon_crtc
->crtc_id
;
1754 switch (radeon_encoder
->encoder_id
) {
1755 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1761 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1767 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1777 /* on DCE32 and encoder can driver any block so just crtc id */
1778 if (ASIC_IS_DCE32(rdev
)) {
1779 return radeon_crtc
->crtc_id
;
1782 /* on DCE3 - LVTMA can only be driven by DIGB */
1783 list_for_each_entry(test_encoder
, &dev
->mode_config
.encoder_list
, head
) {
1784 struct radeon_encoder
*radeon_test_encoder
;
1786 if (encoder
== test_encoder
)
1789 if (!radeon_encoder_is_digital(test_encoder
))
1792 radeon_test_encoder
= to_radeon_encoder(test_encoder
);
1793 dig
= radeon_test_encoder
->enc_priv
;
1795 if (dig
->dig_encoder
>= 0)
1796 dig_enc_in_use
|= (1 << dig
->dig_encoder
);
1799 if (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
) {
1800 if (dig_enc_in_use
& 0x2)
1801 DRM_ERROR("LVDS required digital encoder 2 but it was in use - stealing\n");
1804 if (!(dig_enc_in_use
& 1))
1809 /* This only needs to be called once at startup */
1811 radeon_atom_encoder_init(struct radeon_device
*rdev
)
1813 struct drm_device
*dev
= rdev
->ddev
;
1814 struct drm_encoder
*encoder
;
1816 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
1817 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1818 struct drm_encoder
*ext_encoder
= radeon_atom_get_external_encoder(encoder
);
1820 switch (radeon_encoder
->encoder_id
) {
1821 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1822 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1823 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1824 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1825 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_INIT
, 0, 0);
1831 if (ext_encoder
&& ASIC_IS_DCE41(rdev
))
1832 atombios_external_encoder_setup(encoder
, ext_encoder
,
1833 EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT
);
1838 radeon_atom_encoder_mode_set(struct drm_encoder
*encoder
,
1839 struct drm_display_mode
*mode
,
1840 struct drm_display_mode
*adjusted_mode
)
1842 struct drm_device
*dev
= encoder
->dev
;
1843 struct radeon_device
*rdev
= dev
->dev_private
;
1844 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1845 struct drm_encoder
*ext_encoder
= radeon_atom_get_external_encoder(encoder
);
1847 radeon_encoder
->pixel_clock
= adjusted_mode
->clock
;
1849 if (ASIC_IS_AVIVO(rdev
) && !ASIC_IS_DCE4(rdev
)) {
1850 if (radeon_encoder
->active_device
& (ATOM_DEVICE_CV_SUPPORT
| ATOM_DEVICE_TV_SUPPORT
))
1851 atombios_yuv_setup(encoder
, true);
1853 atombios_yuv_setup(encoder
, false);
1856 switch (radeon_encoder
->encoder_id
) {
1857 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
1858 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
1859 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
1860 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
1861 atombios_digital_setup(encoder
, PANEL_ENCODER_ACTION_ENABLE
);
1863 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
1864 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
1865 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
1866 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
1867 if (ASIC_IS_DCE4(rdev
)) {
1868 /* disable the transmitter */
1869 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE
, 0, 0);
1870 /* setup and enable the encoder */
1871 atombios_dig_encoder_setup(encoder
, ATOM_ENCODER_CMD_SETUP
, 0);
1873 /* enable the transmitter */
1874 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_ENABLE
, 0, 0);
1876 /* disable the encoder and transmitter */
1877 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE
, 0, 0);
1878 atombios_dig_encoder_setup(encoder
, ATOM_DISABLE
, 0);
1880 /* setup and enable the encoder and transmitter */
1881 atombios_dig_encoder_setup(encoder
, ATOM_ENABLE
, 0);
1882 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_SETUP
, 0, 0);
1883 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_ENABLE
, 0, 0);
1886 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
1887 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
1888 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
1889 atombios_dvo_setup(encoder
, ATOM_ENABLE
);
1891 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
1892 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
1893 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
1894 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
1895 atombios_dac_setup(encoder
, ATOM_ENABLE
);
1896 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
)) {
1897 if (radeon_encoder
->active_device
& (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
))
1898 atombios_tv_setup(encoder
, ATOM_ENABLE
);
1900 atombios_tv_setup(encoder
, ATOM_DISABLE
);
1906 if (ASIC_IS_DCE41(rdev
))
1907 atombios_external_encoder_setup(encoder
, ext_encoder
,
1908 EXTERNAL_ENCODER_ACTION_V3_ENCODER_SETUP
);
1910 atombios_external_encoder_setup(encoder
, ext_encoder
, ATOM_ENABLE
);
1913 atombios_apply_encoder_quirks(encoder
, adjusted_mode
);
1915 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_HDMI
) {
1916 r600_hdmi_enable(encoder
);
1917 r600_hdmi_setmode(encoder
, adjusted_mode
);
1922 atombios_dac_load_detect(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
1924 struct drm_device
*dev
= encoder
->dev
;
1925 struct radeon_device
*rdev
= dev
->dev_private
;
1926 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1927 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1929 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
|
1930 ATOM_DEVICE_CV_SUPPORT
|
1931 ATOM_DEVICE_CRT_SUPPORT
)) {
1932 DAC_LOAD_DETECTION_PS_ALLOCATION args
;
1933 int index
= GetIndexIntoMasterTable(COMMAND
, DAC_LoadDetection
);
1936 memset(&args
, 0, sizeof(args
));
1938 if (!atom_parse_cmd_header(rdev
->mode_info
.atom_context
, index
, &frev
, &crev
))
1941 args
.sDacload
.ucMisc
= 0;
1943 if ((radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_DAC1
) ||
1944 (radeon_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
))
1945 args
.sDacload
.ucDacType
= ATOM_DAC_A
;
1947 args
.sDacload
.ucDacType
= ATOM_DAC_B
;
1949 if (radeon_connector
->devices
& ATOM_DEVICE_CRT1_SUPPORT
)
1950 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT
);
1951 else if (radeon_connector
->devices
& ATOM_DEVICE_CRT2_SUPPORT
)
1952 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT
);
1953 else if (radeon_connector
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
1954 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_CV_SUPPORT
);
1956 args
.sDacload
.ucMisc
= DAC_LOAD_MISC_YPrPb
;
1957 } else if (radeon_connector
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
1958 args
.sDacload
.usDeviceID
= cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT
);
1960 args
.sDacload
.ucMisc
= DAC_LOAD_MISC_YPrPb
;
1963 atom_execute_table(rdev
->mode_info
.atom_context
, index
, (uint32_t *)&args
);
1970 static enum drm_connector_status
1971 radeon_atom_dac_detect(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
1973 struct drm_device
*dev
= encoder
->dev
;
1974 struct radeon_device
*rdev
= dev
->dev_private
;
1975 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
1976 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
1977 uint32_t bios_0_scratch
;
1979 if (!atombios_dac_load_detect(encoder
, connector
)) {
1980 DRM_DEBUG_KMS("detect returned false \n");
1981 return connector_status_unknown
;
1984 if (rdev
->family
>= CHIP_R600
)
1985 bios_0_scratch
= RREG32(R600_BIOS_0_SCRATCH
);
1987 bios_0_scratch
= RREG32(RADEON_BIOS_0_SCRATCH
);
1989 DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch
, radeon_encoder
->devices
);
1990 if (radeon_connector
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) {
1991 if (bios_0_scratch
& ATOM_S0_CRT1_MASK
)
1992 return connector_status_connected
;
1994 if (radeon_connector
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) {
1995 if (bios_0_scratch
& ATOM_S0_CRT2_MASK
)
1996 return connector_status_connected
;
1998 if (radeon_connector
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
1999 if (bios_0_scratch
& (ATOM_S0_CV_MASK
|ATOM_S0_CV_MASK_A
))
2000 return connector_status_connected
;
2002 if (radeon_connector
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
2003 if (bios_0_scratch
& (ATOM_S0_TV1_COMPOSITE
| ATOM_S0_TV1_COMPOSITE_A
))
2004 return connector_status_connected
; /* CTV */
2005 else if (bios_0_scratch
& (ATOM_S0_TV1_SVIDEO
| ATOM_S0_TV1_SVIDEO_A
))
2006 return connector_status_connected
; /* STV */
2008 return connector_status_disconnected
;
2011 static enum drm_connector_status
2012 radeon_atom_dig_detect(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
2014 struct drm_device
*dev
= encoder
->dev
;
2015 struct radeon_device
*rdev
= dev
->dev_private
;
2016 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
2017 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
2018 struct drm_encoder
*ext_encoder
= radeon_atom_get_external_encoder(encoder
);
2021 if (!ASIC_IS_DCE4(rdev
))
2022 return connector_status_unknown
;
2025 return connector_status_unknown
;
2027 if ((radeon_connector
->devices
& ATOM_DEVICE_CRT_SUPPORT
) == 0)
2028 return connector_status_unknown
;
2030 /* load detect on the dp bridge */
2031 atombios_external_encoder_setup(encoder
, ext_encoder
,
2032 EXTERNAL_ENCODER_ACTION_V3_DACLOAD_DETECTION
);
2034 bios_0_scratch
= RREG32(R600_BIOS_0_SCRATCH
);
2036 DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch
, radeon_encoder
->devices
);
2037 if (radeon_connector
->devices
& ATOM_DEVICE_CRT1_SUPPORT
) {
2038 if (bios_0_scratch
& ATOM_S0_CRT1_MASK
)
2039 return connector_status_connected
;
2041 if (radeon_connector
->devices
& ATOM_DEVICE_CRT2_SUPPORT
) {
2042 if (bios_0_scratch
& ATOM_S0_CRT2_MASK
)
2043 return connector_status_connected
;
2045 if (radeon_connector
->devices
& ATOM_DEVICE_CV_SUPPORT
) {
2046 if (bios_0_scratch
& (ATOM_S0_CV_MASK
|ATOM_S0_CV_MASK_A
))
2047 return connector_status_connected
;
2049 if (radeon_connector
->devices
& ATOM_DEVICE_TV1_SUPPORT
) {
2050 if (bios_0_scratch
& (ATOM_S0_TV1_COMPOSITE
| ATOM_S0_TV1_COMPOSITE_A
))
2051 return connector_status_connected
; /* CTV */
2052 else if (bios_0_scratch
& (ATOM_S0_TV1_SVIDEO
| ATOM_S0_TV1_SVIDEO_A
))
2053 return connector_status_connected
; /* STV */
2055 return connector_status_disconnected
;
2059 radeon_atom_ext_encoder_setup_ddc(struct drm_encoder
*encoder
)
2061 struct drm_encoder
*ext_encoder
= radeon_atom_get_external_encoder(encoder
);
2064 /* ddc_setup on the dp bridge */
2065 atombios_external_encoder_setup(encoder
, ext_encoder
,
2066 EXTERNAL_ENCODER_ACTION_V3_DDC_SETUP
);
2070 static void radeon_atom_encoder_prepare(struct drm_encoder
*encoder
)
2072 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
2073 struct drm_connector
*connector
= radeon_get_connector_for_encoder(encoder
);
2075 if ((radeon_encoder
->active_device
&
2076 (ATOM_DEVICE_DFP_SUPPORT
| ATOM_DEVICE_LCD_SUPPORT
)) ||
2077 radeon_encoder_is_dp_bridge(encoder
)) {
2078 struct radeon_encoder_atom_dig
*dig
= radeon_encoder
->enc_priv
;
2080 dig
->dig_encoder
= radeon_atom_pick_dig_encoder(encoder
);
2083 radeon_atom_output_lock(encoder
, true);
2084 radeon_atom_encoder_dpms(encoder
, DRM_MODE_DPMS_OFF
);
2087 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
2089 /* select the clock/data port if it uses a router */
2090 if (radeon_connector
->router
.cd_valid
)
2091 radeon_router_select_cd_port(radeon_connector
);
2093 /* turn eDP panel on for mode set */
2094 if (connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
)
2095 atombios_set_edp_panel_power(connector
,
2096 ATOM_TRANSMITTER_ACTION_POWER_ON
);
2099 /* this is needed for the pll/ss setup to work correctly in some cases */
2100 atombios_set_encoder_crtc_source(encoder
);
2103 static void radeon_atom_encoder_commit(struct drm_encoder
*encoder
)
2105 radeon_atom_encoder_dpms(encoder
, DRM_MODE_DPMS_ON
);
2106 radeon_atom_output_lock(encoder
, false);
2109 static void radeon_atom_encoder_disable(struct drm_encoder
*encoder
)
2111 struct drm_device
*dev
= encoder
->dev
;
2112 struct radeon_device
*rdev
= dev
->dev_private
;
2113 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
2114 struct radeon_encoder_atom_dig
*dig
;
2116 /* check for pre-DCE3 cards with shared encoders;
2117 * can't really use the links individually, so don't disable
2118 * the encoder if it's in use by another connector
2120 if (!ASIC_IS_DCE3(rdev
)) {
2121 struct drm_encoder
*other_encoder
;
2122 struct radeon_encoder
*other_radeon_encoder
;
2124 list_for_each_entry(other_encoder
, &dev
->mode_config
.encoder_list
, head
) {
2125 other_radeon_encoder
= to_radeon_encoder(other_encoder
);
2126 if ((radeon_encoder
->encoder_id
== other_radeon_encoder
->encoder_id
) &&
2127 drm_helper_encoder_in_use(other_encoder
))
2132 radeon_atom_encoder_dpms(encoder
, DRM_MODE_DPMS_OFF
);
2134 switch (radeon_encoder
->encoder_id
) {
2135 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
2136 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
2137 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
2138 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
2139 atombios_digital_setup(encoder
, PANEL_ENCODER_ACTION_DISABLE
);
2141 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
2142 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
2143 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
2144 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
2145 if (ASIC_IS_DCE4(rdev
))
2146 /* disable the transmitter */
2147 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE
, 0, 0);
2149 /* disable the encoder and transmitter */
2150 atombios_dig_transmitter_setup(encoder
, ATOM_TRANSMITTER_ACTION_DISABLE
, 0, 0);
2151 atombios_dig_encoder_setup(encoder
, ATOM_DISABLE
, 0);
2154 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
2155 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
2156 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
2157 atombios_dvo_setup(encoder
, ATOM_DISABLE
);
2159 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
2160 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
2161 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
2162 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
2163 atombios_dac_setup(encoder
, ATOM_DISABLE
);
2164 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
| ATOM_DEVICE_CV_SUPPORT
))
2165 atombios_tv_setup(encoder
, ATOM_DISABLE
);
2170 if (radeon_encoder_is_digital(encoder
)) {
2171 if (atombios_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_HDMI
)
2172 r600_hdmi_disable(encoder
);
2173 dig
= radeon_encoder
->enc_priv
;
2174 dig
->dig_encoder
= -1;
2176 radeon_encoder
->active_device
= 0;
2179 /* these are handled by the primary encoders */
2180 static void radeon_atom_ext_prepare(struct drm_encoder
*encoder
)
2185 static void radeon_atom_ext_commit(struct drm_encoder
*encoder
)
2191 radeon_atom_ext_mode_set(struct drm_encoder
*encoder
,
2192 struct drm_display_mode
*mode
,
2193 struct drm_display_mode
*adjusted_mode
)
2198 static void radeon_atom_ext_disable(struct drm_encoder
*encoder
)
2204 radeon_atom_ext_dpms(struct drm_encoder
*encoder
, int mode
)
2209 static bool radeon_atom_ext_mode_fixup(struct drm_encoder
*encoder
,
2210 struct drm_display_mode
*mode
,
2211 struct drm_display_mode
*adjusted_mode
)
2216 static const struct drm_encoder_helper_funcs radeon_atom_ext_helper_funcs
= {
2217 .dpms
= radeon_atom_ext_dpms
,
2218 .mode_fixup
= radeon_atom_ext_mode_fixup
,
2219 .prepare
= radeon_atom_ext_prepare
,
2220 .mode_set
= radeon_atom_ext_mode_set
,
2221 .commit
= radeon_atom_ext_commit
,
2222 .disable
= radeon_atom_ext_disable
,
2223 /* no detect for TMDS/LVDS yet */
2226 static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs
= {
2227 .dpms
= radeon_atom_encoder_dpms
,
2228 .mode_fixup
= radeon_atom_mode_fixup
,
2229 .prepare
= radeon_atom_encoder_prepare
,
2230 .mode_set
= radeon_atom_encoder_mode_set
,
2231 .commit
= radeon_atom_encoder_commit
,
2232 .disable
= radeon_atom_encoder_disable
,
2233 .detect
= radeon_atom_dig_detect
,
2236 static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs
= {
2237 .dpms
= radeon_atom_encoder_dpms
,
2238 .mode_fixup
= radeon_atom_mode_fixup
,
2239 .prepare
= radeon_atom_encoder_prepare
,
2240 .mode_set
= radeon_atom_encoder_mode_set
,
2241 .commit
= radeon_atom_encoder_commit
,
2242 .detect
= radeon_atom_dac_detect
,
2245 void radeon_enc_destroy(struct drm_encoder
*encoder
)
2247 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
2248 kfree(radeon_encoder
->enc_priv
);
2249 drm_encoder_cleanup(encoder
);
2250 kfree(radeon_encoder
);
2253 static const struct drm_encoder_funcs radeon_atom_enc_funcs
= {
2254 .destroy
= radeon_enc_destroy
,
2257 struct radeon_encoder_atom_dac
*
2258 radeon_atombios_set_dac_info(struct radeon_encoder
*radeon_encoder
)
2260 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
2261 struct radeon_device
*rdev
= dev
->dev_private
;
2262 struct radeon_encoder_atom_dac
*dac
= kzalloc(sizeof(struct radeon_encoder_atom_dac
), GFP_KERNEL
);
2267 dac
->tv_std
= radeon_atombios_get_tv_info(rdev
);
2271 struct radeon_encoder_atom_dig
*
2272 radeon_atombios_set_dig_info(struct radeon_encoder
*radeon_encoder
)
2274 int encoder_enum
= (radeon_encoder
->encoder_enum
& ENUM_ID_MASK
) >> ENUM_ID_SHIFT
;
2275 struct radeon_encoder_atom_dig
*dig
= kzalloc(sizeof(struct radeon_encoder_atom_dig
), GFP_KERNEL
);
2280 /* coherent mode by default */
2281 dig
->coherent_mode
= true;
2282 dig
->dig_encoder
= -1;
2284 if (encoder_enum
== 2)
2293 radeon_add_atom_encoder(struct drm_device
*dev
,
2294 uint32_t encoder_enum
,
2295 uint32_t supported_device
,
2298 struct radeon_device
*rdev
= dev
->dev_private
;
2299 struct drm_encoder
*encoder
;
2300 struct radeon_encoder
*radeon_encoder
;
2302 /* see if we already added it */
2303 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
2304 radeon_encoder
= to_radeon_encoder(encoder
);
2305 if (radeon_encoder
->encoder_enum
== encoder_enum
) {
2306 radeon_encoder
->devices
|= supported_device
;
2313 radeon_encoder
= kzalloc(sizeof(struct radeon_encoder
), GFP_KERNEL
);
2314 if (!radeon_encoder
)
2317 encoder
= &radeon_encoder
->base
;
2318 switch (rdev
->num_crtc
) {
2320 encoder
->possible_crtcs
= 0x1;
2324 encoder
->possible_crtcs
= 0x3;
2327 encoder
->possible_crtcs
= 0xf;
2330 encoder
->possible_crtcs
= 0x3f;
2334 radeon_encoder
->enc_priv
= NULL
;
2336 radeon_encoder
->encoder_enum
= encoder_enum
;
2337 radeon_encoder
->encoder_id
= (encoder_enum
& OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
2338 radeon_encoder
->devices
= supported_device
;
2339 radeon_encoder
->rmx_type
= RMX_OFF
;
2340 radeon_encoder
->underscan_type
= UNDERSCAN_OFF
;
2341 radeon_encoder
->is_ext_encoder
= false;
2342 radeon_encoder
->caps
= caps
;
2344 switch (radeon_encoder
->encoder_id
) {
2345 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
2346 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
2347 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
2348 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
2349 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
2350 radeon_encoder
->rmx_type
= RMX_FULL
;
2351 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_LVDS
);
2352 radeon_encoder
->enc_priv
= radeon_atombios_get_lvds_info(radeon_encoder
);
2354 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
2355 radeon_encoder
->enc_priv
= radeon_atombios_set_dig_info(radeon_encoder
);
2357 drm_encoder_helper_add(encoder
, &radeon_atom_dig_helper_funcs
);
2359 case ENCODER_OBJECT_ID_INTERNAL_DAC1
:
2360 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_DAC
);
2361 radeon_encoder
->enc_priv
= radeon_atombios_set_dac_info(radeon_encoder
);
2362 drm_encoder_helper_add(encoder
, &radeon_atom_dac_helper_funcs
);
2364 case ENCODER_OBJECT_ID_INTERNAL_DAC2
:
2365 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
2366 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
2367 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TVDAC
);
2368 radeon_encoder
->enc_priv
= radeon_atombios_set_dac_info(radeon_encoder
);
2369 drm_encoder_helper_add(encoder
, &radeon_atom_dac_helper_funcs
);
2371 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
2372 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
2373 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
2374 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
2375 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
2376 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
2377 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
2378 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
2379 radeon_encoder
->rmx_type
= RMX_FULL
;
2380 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_LVDS
);
2381 radeon_encoder
->enc_priv
= radeon_atombios_get_lvds_info(radeon_encoder
);
2382 } else if (radeon_encoder
->devices
& (ATOM_DEVICE_CRT_SUPPORT
)) {
2383 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_DAC
);
2384 radeon_encoder
->enc_priv
= radeon_atombios_set_dig_info(radeon_encoder
);
2386 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
2387 radeon_encoder
->enc_priv
= radeon_atombios_set_dig_info(radeon_encoder
);
2389 drm_encoder_helper_add(encoder
, &radeon_atom_dig_helper_funcs
);
2391 case ENCODER_OBJECT_ID_SI170B
:
2392 case ENCODER_OBJECT_ID_CH7303
:
2393 case ENCODER_OBJECT_ID_EXTERNAL_SDVOA
:
2394 case ENCODER_OBJECT_ID_EXTERNAL_SDVOB
:
2395 case ENCODER_OBJECT_ID_TITFP513
:
2396 case ENCODER_OBJECT_ID_VT1623
:
2397 case ENCODER_OBJECT_ID_HDMI_SI1930
:
2398 case ENCODER_OBJECT_ID_TRAVIS
:
2399 case ENCODER_OBJECT_ID_NUTMEG
:
2400 /* these are handled by the primary encoders */
2401 radeon_encoder
->is_ext_encoder
= true;
2402 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
2403 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_LVDS
);
2404 else if (radeon_encoder
->devices
& (ATOM_DEVICE_CRT_SUPPORT
))
2405 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_DAC
);
2407 drm_encoder_init(dev
, encoder
, &radeon_atom_enc_funcs
, DRM_MODE_ENCODER_TMDS
);
2408 drm_encoder_helper_add(encoder
, &radeon_atom_ext_helper_funcs
);