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>
34 #include "radeon_atombios.h"
35 #include "radeon_legacy_encoders.h"
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 void radeon_encoder_add_backlight(struct radeon_encoder
*radeon_encoder
,
160 struct drm_connector
*connector
)
162 struct drm_device
*dev
= radeon_encoder
->base
.dev
;
163 struct radeon_device
*rdev
= dev
->dev_private
;
166 if (!(radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)))
169 if (radeon_backlight
== 0) {
171 } else if (radeon_backlight
== 1) {
173 } else if (radeon_backlight
== -1) {
175 /* Amilo Xi 2550 only works with acpi bl */
176 if ((rdev
->pdev
->device
== 0x9583) &&
177 (rdev
->pdev
->subsystem_vendor
== 0x1734) &&
178 (rdev
->pdev
->subsystem_device
== 0x1107))
180 /* Older PPC macs use on-GPU backlight controller */
181 #ifndef CONFIG_PPC_PMAC
182 /* disable native backlight control on older asics */
183 else if (rdev
->family
< CHIP_R600
)
191 if (rdev
->is_atom_bios
)
192 radeon_atom_backlight_init(radeon_encoder
, connector
);
194 radeon_legacy_backlight_init(radeon_encoder
, connector
);
199 radeon_link_encoder_connector(struct drm_device
*dev
)
201 struct drm_connector
*connector
;
202 struct radeon_connector
*radeon_connector
;
203 struct drm_encoder
*encoder
;
204 struct radeon_encoder
*radeon_encoder
;
206 /* walk the list and link encoders to connectors */
207 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
208 radeon_connector
= to_radeon_connector(connector
);
209 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
210 radeon_encoder
= to_radeon_encoder(encoder
);
211 if (radeon_encoder
->devices
& radeon_connector
->devices
) {
212 drm_connector_attach_encoder(connector
, encoder
);
213 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
214 radeon_encoder_add_backlight(radeon_encoder
, connector
);
220 void radeon_encoder_set_active_device(struct drm_encoder
*encoder
)
222 struct drm_device
*dev
= encoder
->dev
;
223 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
224 struct drm_connector
*connector
;
226 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
227 if (connector
->encoder
== encoder
) {
228 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
229 radeon_encoder
->active_device
= radeon_encoder
->devices
& radeon_connector
->devices
;
230 DRM_DEBUG_KMS("setting active device to %08x from %08x %08x for encoder %d\n",
231 radeon_encoder
->active_device
, radeon_encoder
->devices
,
232 radeon_connector
->devices
, encoder
->encoder_type
);
237 struct drm_connector
*
238 radeon_get_connector_for_encoder(struct drm_encoder
*encoder
)
240 struct drm_device
*dev
= encoder
->dev
;
241 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
242 struct drm_connector
*connector
;
243 struct radeon_connector
*radeon_connector
;
245 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
246 radeon_connector
= to_radeon_connector(connector
);
247 if (radeon_encoder
->is_mst_encoder
) {
248 struct radeon_encoder_mst
*mst_enc
;
250 if (!radeon_connector
->is_mst_connector
)
253 mst_enc
= radeon_encoder
->enc_priv
;
254 if (mst_enc
->connector
== radeon_connector
->mst_port
)
256 } else if (radeon_encoder
->active_device
& radeon_connector
->devices
)
262 struct drm_connector
*
263 radeon_get_connector_for_encoder_init(struct drm_encoder
*encoder
)
265 struct drm_device
*dev
= encoder
->dev
;
266 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
267 struct drm_connector
*connector
;
268 struct radeon_connector
*radeon_connector
;
270 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
271 radeon_connector
= to_radeon_connector(connector
);
272 if (radeon_encoder
->devices
& radeon_connector
->devices
)
278 struct drm_encoder
*radeon_get_external_encoder(struct drm_encoder
*encoder
)
280 struct drm_device
*dev
= encoder
->dev
;
281 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
282 struct drm_encoder
*other_encoder
;
283 struct radeon_encoder
*other_radeon_encoder
;
285 if (radeon_encoder
->is_ext_encoder
)
288 list_for_each_entry(other_encoder
, &dev
->mode_config
.encoder_list
, head
) {
289 if (other_encoder
== encoder
)
291 other_radeon_encoder
= to_radeon_encoder(other_encoder
);
292 if (other_radeon_encoder
->is_ext_encoder
&&
293 (radeon_encoder
->devices
& other_radeon_encoder
->devices
))
294 return other_encoder
;
299 u16
radeon_encoder_get_dp_bridge_encoder_id(struct drm_encoder
*encoder
)
301 struct drm_encoder
*other_encoder
= radeon_get_external_encoder(encoder
);
304 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(other_encoder
);
306 switch (radeon_encoder
->encoder_id
) {
307 case ENCODER_OBJECT_ID_TRAVIS
:
308 case ENCODER_OBJECT_ID_NUTMEG
:
309 return radeon_encoder
->encoder_id
;
311 return ENCODER_OBJECT_ID_NONE
;
314 return ENCODER_OBJECT_ID_NONE
;
317 void radeon_panel_mode_fixup(struct drm_encoder
*encoder
,
318 struct drm_display_mode
*adjusted_mode
)
320 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
321 struct drm_device
*dev
= encoder
->dev
;
322 struct radeon_device
*rdev
= dev
->dev_private
;
323 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
324 unsigned hblank
= native_mode
->htotal
- native_mode
->hdisplay
;
325 unsigned vblank
= native_mode
->vtotal
- native_mode
->vdisplay
;
326 unsigned hover
= native_mode
->hsync_start
- native_mode
->hdisplay
;
327 unsigned vover
= native_mode
->vsync_start
- native_mode
->vdisplay
;
328 unsigned hsync_width
= native_mode
->hsync_end
- native_mode
->hsync_start
;
329 unsigned vsync_width
= native_mode
->vsync_end
- native_mode
->vsync_start
;
331 adjusted_mode
->clock
= native_mode
->clock
;
332 adjusted_mode
->flags
= native_mode
->flags
;
334 if (ASIC_IS_AVIVO(rdev
)) {
335 adjusted_mode
->hdisplay
= native_mode
->hdisplay
;
336 adjusted_mode
->vdisplay
= native_mode
->vdisplay
;
339 adjusted_mode
->htotal
= native_mode
->hdisplay
+ hblank
;
340 adjusted_mode
->hsync_start
= native_mode
->hdisplay
+ hover
;
341 adjusted_mode
->hsync_end
= adjusted_mode
->hsync_start
+ hsync_width
;
343 adjusted_mode
->vtotal
= native_mode
->vdisplay
+ vblank
;
344 adjusted_mode
->vsync_start
= native_mode
->vdisplay
+ vover
;
345 adjusted_mode
->vsync_end
= adjusted_mode
->vsync_start
+ vsync_width
;
347 drm_mode_set_crtcinfo(adjusted_mode
, CRTC_INTERLACE_HALVE_V
);
349 if (ASIC_IS_AVIVO(rdev
)) {
350 adjusted_mode
->crtc_hdisplay
= native_mode
->hdisplay
;
351 adjusted_mode
->crtc_vdisplay
= native_mode
->vdisplay
;
354 adjusted_mode
->crtc_htotal
= adjusted_mode
->crtc_hdisplay
+ hblank
;
355 adjusted_mode
->crtc_hsync_start
= adjusted_mode
->crtc_hdisplay
+ hover
;
356 adjusted_mode
->crtc_hsync_end
= adjusted_mode
->crtc_hsync_start
+ hsync_width
;
358 adjusted_mode
->crtc_vtotal
= adjusted_mode
->crtc_vdisplay
+ vblank
;
359 adjusted_mode
->crtc_vsync_start
= adjusted_mode
->crtc_vdisplay
+ vover
;
360 adjusted_mode
->crtc_vsync_end
= adjusted_mode
->crtc_vsync_start
+ vsync_width
;
364 bool radeon_dig_monitor_is_duallink(struct drm_encoder
*encoder
,
367 struct drm_device
*dev
= encoder
->dev
;
368 struct radeon_device
*rdev
= dev
->dev_private
;
369 struct drm_connector
*connector
;
370 struct radeon_connector
*radeon_connector
;
371 struct radeon_connector_atom_dig
*dig_connector
;
373 connector
= radeon_get_connector_for_encoder(encoder
);
374 /* if we don't have an active device yet, just use one of
375 * the connectors tied to the encoder.
378 connector
= radeon_get_connector_for_encoder_init(encoder
);
379 radeon_connector
= to_radeon_connector(connector
);
381 switch (connector
->connector_type
) {
382 case DRM_MODE_CONNECTOR_DVII
:
383 case DRM_MODE_CONNECTOR_HDMIB
:
384 if (radeon_connector
->use_digital
) {
385 /* HDMI 1.3 supports up to 340 Mhz over single link */
386 if (ASIC_IS_DCE6(rdev
) && drm_detect_hdmi_monitor(radeon_connector_edid(connector
))) {
387 if (pixel_clock
> 340000)
392 if (pixel_clock
> 165000)
399 case DRM_MODE_CONNECTOR_DVID
:
400 case DRM_MODE_CONNECTOR_HDMIA
:
401 case DRM_MODE_CONNECTOR_DisplayPort
:
402 if (radeon_connector
->is_mst_connector
)
405 dig_connector
= radeon_connector
->con_priv
;
406 if ((dig_connector
->dp_sink_type
== CONNECTOR_OBJECT_ID_DISPLAYPORT
) ||
407 (dig_connector
->dp_sink_type
== CONNECTOR_OBJECT_ID_eDP
))
410 /* HDMI 1.3 supports up to 340 Mhz over single link */
411 if (ASIC_IS_DCE6(rdev
) && drm_detect_hdmi_monitor(radeon_connector_edid(connector
))) {
412 if (pixel_clock
> 340000)
417 if (pixel_clock
> 165000)
428 bool radeon_encoder_is_digital(struct drm_encoder
*encoder
)
430 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
431 switch (radeon_encoder
->encoder_id
) {
432 case ENCODER_OBJECT_ID_INTERNAL_LVDS
:
433 case ENCODER_OBJECT_ID_INTERNAL_TMDS1
:
434 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1
:
435 case ENCODER_OBJECT_ID_INTERNAL_LVTM1
:
436 case ENCODER_OBJECT_ID_INTERNAL_DVO1
:
437 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
438 case ENCODER_OBJECT_ID_INTERNAL_DDI
:
439 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
440 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA
:
441 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
442 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
443 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3
: