2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 * Authors: Dave Airlie
27 #include <linux/pci.h>
29 #include <drm/drm_crtc_helper.h>
30 #include <drm/drm_device.h>
31 #include <drm/radeon_drm.h>
37 radeon_legacy_backlight_init(struct radeon_encoder
*radeon_encoder
,
38 struct drm_connector
*drm_connector
);
40 radeon_atom_backlight_init(struct radeon_encoder
*radeon_encoder
,
41 struct drm_connector
*drm_connector
);
44 static uint32_t radeon_encoder_clones(struct drm_encoder
*encoder
)
46 struct drm_device
*dev
= encoder
->dev
;
47 struct radeon_device
*rdev
= dev
->dev_private
;
48 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
49 struct drm_encoder
*clone_encoder
;
50 uint32_t index_mask
= 0;
53 /* DIG routing gets problematic */
54 if (rdev
->family
>= CHIP_R600
)
56 /* LVDS/TV are too wacky */
57 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD_SUPPORT
)
59 /* DVO requires 2x ppll clocks depending on tmds chip */
60 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
)
64 list_for_each_entry(clone_encoder
, &dev
->mode_config
.encoder_list
, head
) {
65 struct radeon_encoder
*radeon_clone
= to_radeon_encoder(clone_encoder
);
68 if (clone_encoder
== encoder
)
70 if (radeon_clone
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
72 if (radeon_clone
->devices
& ATOM_DEVICE_DFP2_SUPPORT
)
75 index_mask
|= (1 << count
);
80 void radeon_setup_encoder_clones(struct drm_device
*dev
)
82 struct drm_encoder
*encoder
;
84 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
85 encoder
->possible_clones
= radeon_encoder_clones(encoder
);
90 radeon_get_encoder_enum(struct drm_device
*dev
, uint32_t supported_device
, uint8_t dac
)
92 struct radeon_device
*rdev
= dev
->dev_private
;
95 switch (supported_device
) {
96 case ATOM_DEVICE_CRT1_SUPPORT
:
97 case ATOM_DEVICE_TV1_SUPPORT
:
98 case ATOM_DEVICE_TV2_SUPPORT
:
99 case ATOM_DEVICE_CRT2_SUPPORT
:
100 case ATOM_DEVICE_CV_SUPPORT
:
103 if ((rdev
->family
== CHIP_RS300
) ||
104 (rdev
->family
== CHIP_RS400
) ||
105 (rdev
->family
== CHIP_RS480
))
106 ret
= ENCODER_INTERNAL_DAC2_ENUM_ID1
;
107 else if (ASIC_IS_AVIVO(rdev
))
108 ret
= ENCODER_INTERNAL_KLDSCP_DAC1_ENUM_ID1
;
110 ret
= ENCODER_INTERNAL_DAC1_ENUM_ID1
;
113 if (ASIC_IS_AVIVO(rdev
))
114 ret
= ENCODER_INTERNAL_KLDSCP_DAC2_ENUM_ID1
;
116 /*if (rdev->family == CHIP_R200)
117 ret = ENCODER_INTERNAL_DVO1_ENUM_ID1;
119 ret
= ENCODER_INTERNAL_DAC2_ENUM_ID1
;
122 case 3: /* external dac */
123 if (ASIC_IS_AVIVO(rdev
))
124 ret
= ENCODER_INTERNAL_KLDSCP_DVO1_ENUM_ID1
;
126 ret
= ENCODER_INTERNAL_DVO1_ENUM_ID1
;
130 case ATOM_DEVICE_LCD1_SUPPORT
:
131 if (ASIC_IS_AVIVO(rdev
))
132 ret
= ENCODER_INTERNAL_LVTM1_ENUM_ID1
;
134 ret
= ENCODER_INTERNAL_LVDS_ENUM_ID1
;
136 case ATOM_DEVICE_DFP1_SUPPORT
:
137 if ((rdev
->family
== CHIP_RS300
) ||
138 (rdev
->family
== CHIP_RS400
) ||
139 (rdev
->family
== CHIP_RS480
))
140 ret
= ENCODER_INTERNAL_DVO1_ENUM_ID1
;
141 else if (ASIC_IS_AVIVO(rdev
))
142 ret
= ENCODER_INTERNAL_KLDSCP_TMDS1_ENUM_ID1
;
144 ret
= ENCODER_INTERNAL_TMDS1_ENUM_ID1
;
146 case ATOM_DEVICE_LCD2_SUPPORT
:
147 case ATOM_DEVICE_DFP2_SUPPORT
:
148 if ((rdev
->family
== CHIP_RS600
) ||
149 (rdev
->family
== CHIP_RS690
) ||
150 (rdev
->family
== CHIP_RS740
))
151 ret
= ENCODER_INTERNAL_DDI_ENUM_ID1
;
152 else if (ASIC_IS_AVIVO(rdev
))
153 ret
= ENCODER_INTERNAL_KLDSCP_DVO1_ENUM_ID1
;
155 ret
= ENCODER_INTERNAL_DVO1_ENUM_ID1
;
157 case ATOM_DEVICE_DFP3_SUPPORT
:
158 ret
= ENCODER_INTERNAL_LVTM1_ENUM_ID1
;
165 static void radeon_encoder_add_backlight(struct radeon_encoder
*radeon_encoder
,
166 struct drm_connector
*connector
)
168 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
169 struct radeon_device
*rdev
= dev
->dev_private
;
172 if (!(radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)))
175 if (radeon_backlight
== 0) {
177 } else if (radeon_backlight
== 1) {
179 } else if (radeon_backlight
== -1) {
181 /* Amilo Xi 2550 only works with acpi bl */
182 if ((rdev
->pdev
->device
== 0x9583) &&
183 (rdev
->pdev
->subsystem_vendor
== 0x1734) &&
184 (rdev
->pdev
->subsystem_device
== 0x1107))
186 /* Older PPC macs use on-GPU backlight controller */
187 #ifndef CONFIG_PPC_PMAC
188 /* disable native backlight control on older asics */
189 else if (rdev
->family
< CHIP_R600
)
197 if (rdev
->is_atom_bios
)
198 radeon_atom_backlight_init(radeon_encoder
, connector
);
200 radeon_legacy_backlight_init(radeon_encoder
, connector
);
205 radeon_link_encoder_connector(struct drm_device
*dev
)
207 struct drm_connector
*connector
;
208 struct radeon_connector
*radeon_connector
;
209 struct drm_encoder
*encoder
;
210 struct radeon_encoder
*radeon_encoder
;
212 /* walk the list and link encoders to connectors */
213 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
214 radeon_connector
= to_radeon_connector(connector
);
215 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
216 radeon_encoder
= to_radeon_encoder(encoder
);
217 if (radeon_encoder
->devices
& radeon_connector
->devices
) {
218 drm_connector_attach_encoder(connector
, encoder
);
219 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
220 radeon_encoder_add_backlight(radeon_encoder
, connector
);
226 void radeon_encoder_set_active_device(struct drm_encoder
*encoder
)
228 struct drm_device
*dev
= encoder
->dev
;
229 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
230 struct drm_connector
*connector
;
232 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
233 if (connector
->encoder
== encoder
) {
234 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
235 radeon_encoder
->active_device
= radeon_encoder
->devices
& radeon_connector
->devices
;
236 DRM_DEBUG_KMS("setting active device to %08x from %08x %08x for encoder %d\n",
237 radeon_encoder
->active_device
, radeon_encoder
->devices
,
238 radeon_connector
->devices
, encoder
->encoder_type
);
243 struct drm_connector
*
244 radeon_get_connector_for_encoder(struct drm_encoder
*encoder
)
246 struct drm_device
*dev
= encoder
->dev
;
247 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
248 struct drm_connector
*connector
;
249 struct radeon_connector
*radeon_connector
;
251 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
252 radeon_connector
= to_radeon_connector(connector
);
253 if (radeon_encoder
->is_mst_encoder
) {
254 struct radeon_encoder_mst
*mst_enc
;
256 if (!radeon_connector
->is_mst_connector
)
259 mst_enc
= radeon_encoder
->enc_priv
;
260 if (mst_enc
->connector
== radeon_connector
->mst_port
)
262 } else if (radeon_encoder
->active_device
& radeon_connector
->devices
)
268 struct drm_connector
*
269 radeon_get_connector_for_encoder_init(struct drm_encoder
*encoder
)
271 struct drm_device
*dev
= encoder
->dev
;
272 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
273 struct drm_connector
*connector
;
274 struct radeon_connector
*radeon_connector
;
276 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
277 radeon_connector
= to_radeon_connector(connector
);
278 if (radeon_encoder
->devices
& radeon_connector
->devices
)
284 struct drm_encoder
*radeon_get_external_encoder(struct drm_encoder
*encoder
)
286 struct drm_device
*dev
= encoder
->dev
;
287 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
288 struct drm_encoder
*other_encoder
;
289 struct radeon_encoder
*other_radeon_encoder
;
291 if (radeon_encoder
->is_ext_encoder
)
294 list_for_each_entry(other_encoder
, &dev
->mode_config
.encoder_list
, head
) {
295 if (other_encoder
== encoder
)
297 other_radeon_encoder
= to_radeon_encoder(other_encoder
);
298 if (other_radeon_encoder
->is_ext_encoder
&&
299 (radeon_encoder
->devices
& other_radeon_encoder
->devices
))
300 return other_encoder
;
305 u16
radeon_encoder_get_dp_bridge_encoder_id(struct drm_encoder
*encoder
)
307 struct drm_encoder
*other_encoder
= radeon_get_external_encoder(encoder
);
310 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(other_encoder
);
312 switch (radeon_encoder
->encoder_id
) {
313 case ENCODER_OBJECT_ID_TRAVIS
:
314 case ENCODER_OBJECT_ID_NUTMEG
:
315 return radeon_encoder
->encoder_id
;
317 return ENCODER_OBJECT_ID_NONE
;
320 return ENCODER_OBJECT_ID_NONE
;
323 void radeon_panel_mode_fixup(struct drm_encoder
*encoder
,
324 struct drm_display_mode
*adjusted_mode
)
326 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
327 struct drm_device
*dev
= encoder
->dev
;
328 struct radeon_device
*rdev
= dev
->dev_private
;
329 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
330 unsigned hblank
= native_mode
->htotal
- native_mode
->hdisplay
;
331 unsigned vblank
= native_mode
->vtotal
- native_mode
->vdisplay
;
332 unsigned hover
= native_mode
->hsync_start
- native_mode
->hdisplay
;
333 unsigned vover
= native_mode
->vsync_start
- native_mode
->vdisplay
;
334 unsigned hsync_width
= native_mode
->hsync_end
- native_mode
->hsync_start
;
335 unsigned vsync_width
= native_mode
->vsync_end
- native_mode
->vsync_start
;
337 adjusted_mode
->clock
= native_mode
->clock
;
338 adjusted_mode
->flags
= native_mode
->flags
;
340 if (ASIC_IS_AVIVO(rdev
)) {
341 adjusted_mode
->hdisplay
= native_mode
->hdisplay
;
342 adjusted_mode
->vdisplay
= native_mode
->vdisplay
;
345 adjusted_mode
->htotal
= native_mode
->hdisplay
+ hblank
;
346 adjusted_mode
->hsync_start
= native_mode
->hdisplay
+ hover
;
347 adjusted_mode
->hsync_end
= adjusted_mode
->hsync_start
+ hsync_width
;
349 adjusted_mode
->vtotal
= native_mode
->vdisplay
+ vblank
;
350 adjusted_mode
->vsync_start
= native_mode
->vdisplay
+ vover
;
351 adjusted_mode
->vsync_end
= adjusted_mode
->vsync_start
+ vsync_width
;
353 drm_mode_set_crtcinfo(adjusted_mode
, CRTC_INTERLACE_HALVE_V
);
355 if (ASIC_IS_AVIVO(rdev
)) {
356 adjusted_mode
->crtc_hdisplay
= native_mode
->hdisplay
;
357 adjusted_mode
->crtc_vdisplay
= native_mode
->vdisplay
;
360 adjusted_mode
->crtc_htotal
= adjusted_mode
->crtc_hdisplay
+ hblank
;
361 adjusted_mode
->crtc_hsync_start
= adjusted_mode
->crtc_hdisplay
+ hover
;
362 adjusted_mode
->crtc_hsync_end
= adjusted_mode
->crtc_hsync_start
+ hsync_width
;
364 adjusted_mode
->crtc_vtotal
= adjusted_mode
->crtc_vdisplay
+ vblank
;
365 adjusted_mode
->crtc_vsync_start
= adjusted_mode
->crtc_vdisplay
+ vover
;
366 adjusted_mode
->crtc_vsync_end
= adjusted_mode
->crtc_vsync_start
+ vsync_width
;
370 bool radeon_dig_monitor_is_duallink(struct drm_encoder
*encoder
,
373 struct drm_device
*dev
= encoder
->dev
;
374 struct radeon_device
*rdev
= dev
->dev_private
;
375 struct drm_connector
*connector
;
376 struct radeon_connector
*radeon_connector
;
377 struct radeon_connector_atom_dig
*dig_connector
;
379 connector
= radeon_get_connector_for_encoder(encoder
);
380 /* if we don't have an active device yet, just use one of
381 * the connectors tied to the encoder.
384 connector
= radeon_get_connector_for_encoder_init(encoder
);
385 radeon_connector
= to_radeon_connector(connector
);
387 switch (connector
->connector_type
) {
388 case DRM_MODE_CONNECTOR_DVII
:
389 case DRM_MODE_CONNECTOR_HDMIB
:
390 if (radeon_connector
->use_digital
) {
391 /* HDMI 1.3 supports up to 340 Mhz over single link */
392 if (ASIC_IS_DCE6(rdev
) && drm_detect_hdmi_monitor(radeon_connector_edid(connector
))) {
393 if (pixel_clock
> 340000)
398 if (pixel_clock
> 165000)
405 case DRM_MODE_CONNECTOR_DVID
:
406 case DRM_MODE_CONNECTOR_HDMIA
:
407 case DRM_MODE_CONNECTOR_DisplayPort
:
408 if (radeon_connector
->is_mst_connector
)
411 dig_connector
= radeon_connector
->con_priv
;
412 if ((dig_connector
->dp_sink_type
== CONNECTOR_OBJECT_ID_DISPLAYPORT
) ||
413 (dig_connector
->dp_sink_type
== CONNECTOR_OBJECT_ID_eDP
))
416 /* HDMI 1.3 supports up to 340 Mhz over single link */
417 if (ASIC_IS_DCE6(rdev
) && drm_detect_hdmi_monitor(radeon_connector_edid(connector
))) {
418 if (pixel_clock
> 340000)
423 if (pixel_clock
> 165000)
434 bool radeon_encoder_is_digital(struct drm_encoder
*encoder
)
436 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
437 switch (radeon_encoder
->encoder_id
) {
438 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
439 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
440 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
441 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
442 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
443 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
444 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
445 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
446 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
447 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
448 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
449 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3
: