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 static uint32_t radeon_encoder_clones(struct drm_encoder
*encoder
)
34 struct drm_device
*dev
= encoder
->dev
;
35 struct radeon_device
*rdev
= dev
->dev_private
;
36 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
37 struct drm_encoder
*clone_encoder
;
38 uint32_t index_mask
= 0;
41 /* DIG routing gets problematic */
42 if (rdev
->family
>= CHIP_R600
)
44 /* LVDS/TV are too wacky */
45 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD_SUPPORT
)
47 /* DVO requires 2x ppll clocks depending on tmds chip */
48 if (radeon_encoder
->devices
& ATOM_DEVICE_DFP2_SUPPORT
)
52 list_for_each_entry(clone_encoder
, &dev
->mode_config
.encoder_list
, head
) {
53 struct radeon_encoder
*radeon_clone
= to_radeon_encoder(clone_encoder
);
56 if (clone_encoder
== encoder
)
58 if (radeon_clone
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
60 if (radeon_clone
->devices
& ATOM_DEVICE_DFP2_SUPPORT
)
63 index_mask
|= (1 << count
);
68 void radeon_setup_encoder_clones(struct drm_device
*dev
)
70 struct drm_encoder
*encoder
;
72 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
73 encoder
->possible_clones
= radeon_encoder_clones(encoder
);
78 radeon_get_encoder_enum(struct drm_device
*dev
, uint32_t supported_device
, uint8_t dac
)
80 struct radeon_device
*rdev
= dev
->dev_private
;
83 switch (supported_device
) {
84 case ATOM_DEVICE_CRT1_SUPPORT
:
85 case ATOM_DEVICE_TV1_SUPPORT
:
86 case ATOM_DEVICE_TV2_SUPPORT
:
87 case ATOM_DEVICE_CRT2_SUPPORT
:
88 case ATOM_DEVICE_CV_SUPPORT
:
91 if ((rdev
->family
== CHIP_RS300
) ||
92 (rdev
->family
== CHIP_RS400
) ||
93 (rdev
->family
== CHIP_RS480
))
94 ret
= ENCODER_INTERNAL_DAC2_ENUM_ID1
;
95 else if (ASIC_IS_AVIVO(rdev
))
96 ret
= ENCODER_INTERNAL_KLDSCP_DAC1_ENUM_ID1
;
98 ret
= ENCODER_INTERNAL_DAC1_ENUM_ID1
;
101 if (ASIC_IS_AVIVO(rdev
))
102 ret
= ENCODER_INTERNAL_KLDSCP_DAC2_ENUM_ID1
;
104 /*if (rdev->family == CHIP_R200)
105 ret = ENCODER_INTERNAL_DVO1_ENUM_ID1;
107 ret
= ENCODER_INTERNAL_DAC2_ENUM_ID1
;
110 case 3: /* external dac */
111 if (ASIC_IS_AVIVO(rdev
))
112 ret
= ENCODER_INTERNAL_KLDSCP_DVO1_ENUM_ID1
;
114 ret
= ENCODER_INTERNAL_DVO1_ENUM_ID1
;
118 case ATOM_DEVICE_LCD1_SUPPORT
:
119 if (ASIC_IS_AVIVO(rdev
))
120 ret
= ENCODER_INTERNAL_LVTM1_ENUM_ID1
;
122 ret
= ENCODER_INTERNAL_LVDS_ENUM_ID1
;
124 case ATOM_DEVICE_DFP1_SUPPORT
:
125 if ((rdev
->family
== CHIP_RS300
) ||
126 (rdev
->family
== CHIP_RS400
) ||
127 (rdev
->family
== CHIP_RS480
))
128 ret
= ENCODER_INTERNAL_DVO1_ENUM_ID1
;
129 else if (ASIC_IS_AVIVO(rdev
))
130 ret
= ENCODER_INTERNAL_KLDSCP_TMDS1_ENUM_ID1
;
132 ret
= ENCODER_INTERNAL_TMDS1_ENUM_ID1
;
134 case ATOM_DEVICE_LCD2_SUPPORT
:
135 case ATOM_DEVICE_DFP2_SUPPORT
:
136 if ((rdev
->family
== CHIP_RS600
) ||
137 (rdev
->family
== CHIP_RS690
) ||
138 (rdev
->family
== CHIP_RS740
))
139 ret
= ENCODER_INTERNAL_DDI_ENUM_ID1
;
140 else if (ASIC_IS_AVIVO(rdev
))
141 ret
= ENCODER_INTERNAL_KLDSCP_DVO1_ENUM_ID1
;
143 ret
= ENCODER_INTERNAL_DVO1_ENUM_ID1
;
145 case ATOM_DEVICE_DFP3_SUPPORT
:
146 ret
= ENCODER_INTERNAL_LVTM1_ENUM_ID1
;
154 radeon_link_encoder_connector(struct drm_device
*dev
)
156 struct drm_connector
*connector
;
157 struct radeon_connector
*radeon_connector
;
158 struct drm_encoder
*encoder
;
159 struct radeon_encoder
*radeon_encoder
;
161 /* walk the list and link encoders to connectors */
162 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
163 radeon_connector
= to_radeon_connector(connector
);
164 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
165 radeon_encoder
= to_radeon_encoder(encoder
);
166 if (radeon_encoder
->devices
& radeon_connector
->devices
)
167 drm_mode_connector_attach_encoder(connector
, encoder
);
172 void radeon_encoder_set_active_device(struct drm_encoder
*encoder
)
174 struct drm_device
*dev
= encoder
->dev
;
175 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
176 struct drm_connector
*connector
;
178 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
179 if (connector
->encoder
== encoder
) {
180 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
181 radeon_encoder
->active_device
= radeon_encoder
->devices
& radeon_connector
->devices
;
182 DRM_DEBUG_KMS("setting active device to %08x from %08x %08x for encoder %d\n",
183 radeon_encoder
->active_device
, radeon_encoder
->devices
,
184 radeon_connector
->devices
, encoder
->encoder_type
);
189 struct drm_connector
*
190 radeon_get_connector_for_encoder(struct drm_encoder
*encoder
)
192 struct drm_device
*dev
= encoder
->dev
;
193 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
194 struct drm_connector
*connector
;
195 struct radeon_connector
*radeon_connector
;
197 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
198 radeon_connector
= to_radeon_connector(connector
);
199 if (radeon_encoder
->active_device
& radeon_connector
->devices
)
205 struct drm_encoder
*radeon_get_external_encoder(struct drm_encoder
*encoder
)
207 struct drm_device
*dev
= encoder
->dev
;
208 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
209 struct drm_encoder
*other_encoder
;
210 struct radeon_encoder
*other_radeon_encoder
;
212 if (radeon_encoder
->is_ext_encoder
)
215 list_for_each_entry(other_encoder
, &dev
->mode_config
.encoder_list
, head
) {
216 if (other_encoder
== encoder
)
218 other_radeon_encoder
= to_radeon_encoder(other_encoder
);
219 if (other_radeon_encoder
->is_ext_encoder
&&
220 (radeon_encoder
->devices
& other_radeon_encoder
->devices
))
221 return other_encoder
;
226 u16
radeon_encoder_get_dp_bridge_encoder_id(struct drm_encoder
*encoder
)
228 struct drm_encoder
*other_encoder
= radeon_get_external_encoder(encoder
);
231 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(other_encoder
);
233 switch (radeon_encoder
->encoder_id
) {
234 case ENCODER_OBJECT_ID_TRAVIS
:
235 case ENCODER_OBJECT_ID_NUTMEG
:
245 void radeon_panel_mode_fixup(struct drm_encoder
*encoder
,
246 struct drm_display_mode
*adjusted_mode
)
248 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
249 struct drm_device
*dev
= encoder
->dev
;
250 struct radeon_device
*rdev
= dev
->dev_private
;
251 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
252 unsigned hblank
= native_mode
->htotal
- native_mode
->hdisplay
;
253 unsigned vblank
= native_mode
->vtotal
- native_mode
->vdisplay
;
254 unsigned hover
= native_mode
->hsync_start
- native_mode
->hdisplay
;
255 unsigned vover
= native_mode
->vsync_start
- native_mode
->vdisplay
;
256 unsigned hsync_width
= native_mode
->hsync_end
- native_mode
->hsync_start
;
257 unsigned vsync_width
= native_mode
->vsync_end
- native_mode
->vsync_start
;
259 adjusted_mode
->clock
= native_mode
->clock
;
260 adjusted_mode
->flags
= native_mode
->flags
;
262 if (ASIC_IS_AVIVO(rdev
)) {
263 adjusted_mode
->hdisplay
= native_mode
->hdisplay
;
264 adjusted_mode
->vdisplay
= native_mode
->vdisplay
;
267 adjusted_mode
->htotal
= native_mode
->hdisplay
+ hblank
;
268 adjusted_mode
->hsync_start
= native_mode
->hdisplay
+ hover
;
269 adjusted_mode
->hsync_end
= adjusted_mode
->hsync_start
+ hsync_width
;
271 adjusted_mode
->vtotal
= native_mode
->vdisplay
+ vblank
;
272 adjusted_mode
->vsync_start
= native_mode
->vdisplay
+ vover
;
273 adjusted_mode
->vsync_end
= adjusted_mode
->vsync_start
+ vsync_width
;
275 drm_mode_set_crtcinfo(adjusted_mode
, CRTC_INTERLACE_HALVE_V
);
277 if (ASIC_IS_AVIVO(rdev
)) {
278 adjusted_mode
->crtc_hdisplay
= native_mode
->hdisplay
;
279 adjusted_mode
->crtc_vdisplay
= native_mode
->vdisplay
;
282 adjusted_mode
->crtc_htotal
= adjusted_mode
->crtc_hdisplay
+ hblank
;
283 adjusted_mode
->crtc_hsync_start
= adjusted_mode
->crtc_hdisplay
+ hover
;
284 adjusted_mode
->crtc_hsync_end
= adjusted_mode
->crtc_hsync_start
+ hsync_width
;
286 adjusted_mode
->crtc_vtotal
= adjusted_mode
->crtc_vdisplay
+ vblank
;
287 adjusted_mode
->crtc_vsync_start
= adjusted_mode
->crtc_vdisplay
+ vover
;
288 adjusted_mode
->crtc_vsync_end
= adjusted_mode
->crtc_vsync_start
+ vsync_width
;