Rev 1630 | Rev 1986 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1123 | serge | 1 | /* |
2 | * Copyright 2007-8 Advanced Micro Devices, Inc. |
||
3 | * Copyright 2008 Red Hat Inc. |
||
4 | * |
||
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: |
||
11 | * |
||
12 | * The above copyright notice and this permission notice shall be included in |
||
13 | * all copies or substantial portions of the Software. |
||
14 | * |
||
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. |
||
22 | * |
||
23 | * Authors: Dave Airlie |
||
24 | * Alex Deucher |
||
25 | */ |
||
26 | #include "drmP.h" |
||
27 | #include "radeon_drm.h" |
||
28 | #include "radeon.h" |
||
29 | |||
30 | #include "atom.h" |
||
1963 | serge | 31 | #include |
1123 | serge | 32 | |
33 | #include "drm_crtc_helper.h" |
||
34 | #include "drm_edid.h" |
||
35 | |||
36 | static int radeon_ddc_dump(struct drm_connector *connector); |
||
37 | |||
38 | static void avivo_crtc_load_lut(struct drm_crtc *crtc) |
||
39 | { |
||
40 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
||
41 | struct drm_device *dev = crtc->dev; |
||
42 | struct radeon_device *rdev = dev->dev_private; |
||
43 | int i; |
||
44 | |||
1963 | serge | 45 | DRM_DEBUG_KMS("%d\n", radeon_crtc->crtc_id); |
1123 | serge | 46 | WREG32(AVIVO_DC_LUTA_CONTROL + radeon_crtc->crtc_offset, 0); |
47 | |||
48 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0); |
||
49 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0); |
||
50 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0); |
||
51 | |||
52 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff); |
||
53 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff); |
||
54 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff); |
||
55 | |||
56 | WREG32(AVIVO_DC_LUT_RW_SELECT, radeon_crtc->crtc_id); |
||
57 | WREG32(AVIVO_DC_LUT_RW_MODE, 0); |
||
58 | WREG32(AVIVO_DC_LUT_WRITE_EN_MASK, 0x0000003f); |
||
59 | |||
60 | WREG8(AVIVO_DC_LUT_RW_INDEX, 0); |
||
61 | for (i = 0; i < 256; i++) { |
||
62 | WREG32(AVIVO_DC_LUT_30_COLOR, |
||
63 | (radeon_crtc->lut_r[i] << 20) | |
||
64 | (radeon_crtc->lut_g[i] << 10) | |
||
65 | (radeon_crtc->lut_b[i] << 0)); |
||
66 | } |
||
67 | |||
68 | WREG32(AVIVO_D1GRPH_LUT_SEL + radeon_crtc->crtc_offset, radeon_crtc->crtc_id); |
||
69 | } |
||
70 | |||
1963 | serge | 71 | static void dce4_crtc_load_lut(struct drm_crtc *crtc) |
1430 | serge | 72 | { |
73 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
||
74 | struct drm_device *dev = crtc->dev; |
||
75 | struct radeon_device *rdev = dev->dev_private; |
||
76 | int i; |
||
77 | |||
1963 | serge | 78 | DRM_DEBUG_KMS("%d\n", radeon_crtc->crtc_id); |
1430 | serge | 79 | WREG32(EVERGREEN_DC_LUT_CONTROL + radeon_crtc->crtc_offset, 0); |
80 | |||
81 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0); |
||
82 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0); |
||
83 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0); |
||
84 | |||
85 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff); |
||
86 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff); |
||
87 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff); |
||
88 | |||
1963 | serge | 89 | WREG32(EVERGREEN_DC_LUT_RW_MODE + radeon_crtc->crtc_offset, 0); |
90 | WREG32(EVERGREEN_DC_LUT_WRITE_EN_MASK + radeon_crtc->crtc_offset, 0x00000007); |
||
1430 | serge | 91 | |
1963 | serge | 92 | WREG32(EVERGREEN_DC_LUT_RW_INDEX + radeon_crtc->crtc_offset, 0); |
1430 | serge | 93 | for (i = 0; i < 256; i++) { |
1963 | serge | 94 | WREG32(EVERGREEN_DC_LUT_30_COLOR + radeon_crtc->crtc_offset, |
1430 | serge | 95 | (radeon_crtc->lut_r[i] << 20) | |
96 | (radeon_crtc->lut_g[i] << 10) | |
||
97 | (radeon_crtc->lut_b[i] << 0)); |
||
98 | } |
||
99 | } |
||
100 | |||
1963 | serge | 101 | static void dce5_crtc_load_lut(struct drm_crtc *crtc) |
102 | { |
||
103 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
||
104 | struct drm_device *dev = crtc->dev; |
||
105 | struct radeon_device *rdev = dev->dev_private; |
||
106 | int i; |
||
107 | |||
108 | DRM_DEBUG_KMS("%d\n", radeon_crtc->crtc_id); |
||
109 | |||
110 | WREG32(NI_INPUT_CSC_CONTROL + radeon_crtc->crtc_offset, |
||
111 | (NI_INPUT_CSC_GRPH_MODE(NI_INPUT_CSC_BYPASS) | |
||
112 | NI_INPUT_CSC_OVL_MODE(NI_INPUT_CSC_BYPASS))); |
||
113 | WREG32(NI_PRESCALE_GRPH_CONTROL + radeon_crtc->crtc_offset, |
||
114 | NI_GRPH_PRESCALE_BYPASS); |
||
115 | WREG32(NI_PRESCALE_OVL_CONTROL + radeon_crtc->crtc_offset, |
||
116 | NI_OVL_PRESCALE_BYPASS); |
||
117 | WREG32(NI_INPUT_GAMMA_CONTROL + radeon_crtc->crtc_offset, |
||
118 | (NI_GRPH_INPUT_GAMMA_MODE(NI_INPUT_GAMMA_USE_LUT) | |
||
119 | NI_OVL_INPUT_GAMMA_MODE(NI_INPUT_GAMMA_USE_LUT))); |
||
120 | |||
121 | WREG32(EVERGREEN_DC_LUT_CONTROL + radeon_crtc->crtc_offset, 0); |
||
122 | |||
123 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0); |
||
124 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0); |
||
125 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0); |
||
126 | |||
127 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff); |
||
128 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff); |
||
129 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff); |
||
130 | |||
131 | WREG32(EVERGREEN_DC_LUT_RW_MODE + radeon_crtc->crtc_offset, 0); |
||
132 | WREG32(EVERGREEN_DC_LUT_WRITE_EN_MASK + radeon_crtc->crtc_offset, 0x00000007); |
||
133 | |||
134 | WREG32(EVERGREEN_DC_LUT_RW_INDEX + radeon_crtc->crtc_offset, 0); |
||
135 | for (i = 0; i < 256; i++) { |
||
136 | WREG32(EVERGREEN_DC_LUT_30_COLOR + radeon_crtc->crtc_offset, |
||
137 | (radeon_crtc->lut_r[i] << 20) | |
||
138 | (radeon_crtc->lut_g[i] << 10) | |
||
139 | (radeon_crtc->lut_b[i] << 0)); |
||
140 | } |
||
141 | |||
142 | WREG32(NI_DEGAMMA_CONTROL + radeon_crtc->crtc_offset, |
||
143 | (NI_GRPH_DEGAMMA_MODE(NI_DEGAMMA_BYPASS) | |
||
144 | NI_OVL_DEGAMMA_MODE(NI_DEGAMMA_BYPASS) | |
||
145 | NI_ICON_DEGAMMA_MODE(NI_DEGAMMA_BYPASS) | |
||
146 | NI_CURSOR_DEGAMMA_MODE(NI_DEGAMMA_BYPASS))); |
||
147 | WREG32(NI_GAMUT_REMAP_CONTROL + radeon_crtc->crtc_offset, |
||
148 | (NI_GRPH_GAMUT_REMAP_MODE(NI_GAMUT_REMAP_BYPASS) | |
||
149 | NI_OVL_GAMUT_REMAP_MODE(NI_GAMUT_REMAP_BYPASS))); |
||
150 | WREG32(NI_REGAMMA_CONTROL + radeon_crtc->crtc_offset, |
||
151 | (NI_GRPH_REGAMMA_MODE(NI_REGAMMA_BYPASS) | |
||
152 | NI_OVL_REGAMMA_MODE(NI_REGAMMA_BYPASS))); |
||
153 | WREG32(NI_OUTPUT_CSC_CONTROL + radeon_crtc->crtc_offset, |
||
154 | (NI_OUTPUT_CSC_GRPH_MODE(NI_OUTPUT_CSC_BYPASS) | |
||
155 | NI_OUTPUT_CSC_OVL_MODE(NI_OUTPUT_CSC_BYPASS))); |
||
156 | /* XXX match this to the depth of the crtc fmt block, move to modeset? */ |
||
157 | WREG32(0x6940 + radeon_crtc->crtc_offset, 0); |
||
158 | |||
159 | } |
||
160 | |||
1123 | serge | 161 | static void legacy_crtc_load_lut(struct drm_crtc *crtc) |
162 | { |
||
163 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
||
164 | struct drm_device *dev = crtc->dev; |
||
165 | struct radeon_device *rdev = dev->dev_private; |
||
166 | int i; |
||
167 | uint32_t dac2_cntl; |
||
168 | |||
169 | dac2_cntl = RREG32(RADEON_DAC_CNTL2); |
||
170 | if (radeon_crtc->crtc_id == 0) |
||
171 | dac2_cntl &= (uint32_t)~RADEON_DAC2_PALETTE_ACC_CTL; |
||
172 | else |
||
173 | dac2_cntl |= RADEON_DAC2_PALETTE_ACC_CTL; |
||
174 | WREG32(RADEON_DAC_CNTL2, dac2_cntl); |
||
175 | |||
176 | WREG8(RADEON_PALETTE_INDEX, 0); |
||
177 | for (i = 0; i < 256; i++) { |
||
178 | WREG32(RADEON_PALETTE_30_DATA, |
||
179 | (radeon_crtc->lut_r[i] << 20) | |
||
180 | (radeon_crtc->lut_g[i] << 10) | |
||
181 | (radeon_crtc->lut_b[i] << 0)); |
||
182 | } |
||
183 | } |
||
184 | |||
185 | void radeon_crtc_load_lut(struct drm_crtc *crtc) |
||
186 | { |
||
187 | struct drm_device *dev = crtc->dev; |
||
188 | struct radeon_device *rdev = dev->dev_private; |
||
189 | |||
190 | if (!crtc->enabled) |
||
191 | return; |
||
192 | |||
1963 | serge | 193 | if (ASIC_IS_DCE5(rdev)) |
194 | dce5_crtc_load_lut(crtc); |
||
195 | else if (ASIC_IS_DCE4(rdev)) |
||
196 | dce4_crtc_load_lut(crtc); |
||
1430 | serge | 197 | else if (ASIC_IS_AVIVO(rdev)) |
1123 | serge | 198 | avivo_crtc_load_lut(crtc); |
199 | else |
||
200 | legacy_crtc_load_lut(crtc); |
||
201 | } |
||
202 | |||
1221 | serge | 203 | /** Sets the color ramps on behalf of fbcon */ |
1123 | serge | 204 | void radeon_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
205 | u16 blue, int regno) |
||
206 | { |
||
207 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
||
208 | |||
209 | radeon_crtc->lut_r[regno] = red >> 6; |
||
210 | radeon_crtc->lut_g[regno] = green >> 6; |
||
211 | radeon_crtc->lut_b[regno] = blue >> 6; |
||
212 | } |
||
213 | |||
1221 | serge | 214 | /** Gets the color ramps on behalf of fbcon */ |
215 | void radeon_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
||
216 | u16 *blue, int regno) |
||
217 | { |
||
218 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
||
219 | |||
220 | *red = radeon_crtc->lut_r[regno] << 6; |
||
221 | *green = radeon_crtc->lut_g[regno] << 6; |
||
222 | *blue = radeon_crtc->lut_b[regno] << 6; |
||
223 | } |
||
224 | |||
1123 | serge | 225 | static void radeon_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
1963 | serge | 226 | u16 *blue, uint32_t start, uint32_t size) |
1123 | serge | 227 | { |
228 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
||
1963 | serge | 229 | int end = (start + size > 256) ? 256 : start + size, i; |
1123 | serge | 230 | |
1221 | serge | 231 | /* userspace palettes are always correct as is */ |
1963 | serge | 232 | for (i = start; i < end; i++) { |
1123 | serge | 233 | radeon_crtc->lut_r[i] = red[i] >> 6; |
234 | radeon_crtc->lut_g[i] = green[i] >> 6; |
||
235 | radeon_crtc->lut_b[i] = blue[i] >> 6; |
||
236 | } |
||
237 | radeon_crtc_load_lut(crtc); |
||
238 | } |
||
239 | |||
240 | static void radeon_crtc_destroy(struct drm_crtc *crtc) |
||
241 | { |
||
242 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
||
243 | |||
244 | drm_crtc_cleanup(crtc); |
||
245 | kfree(radeon_crtc); |
||
246 | } |
||
247 | |||
248 | static const struct drm_crtc_funcs radeon_crtc_funcs = { |
||
1221 | serge | 249 | .cursor_set = NULL, |
250 | .cursor_move = NULL, |
||
1123 | serge | 251 | .gamma_set = radeon_crtc_gamma_set, |
1126 | serge | 252 | .set_config = drm_crtc_helper_set_config, |
1123 | serge | 253 | .destroy = radeon_crtc_destroy, |
1963 | serge | 254 | .page_flip = NULL, |
1123 | serge | 255 | }; |
256 | |||
257 | static void radeon_crtc_init(struct drm_device *dev, int index) |
||
258 | { |
||
259 | struct radeon_device *rdev = dev->dev_private; |
||
260 | struct radeon_crtc *radeon_crtc; |
||
261 | int i; |
||
262 | |||
263 | radeon_crtc = kzalloc(sizeof(struct radeon_crtc) + (RADEONFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); |
||
264 | if (radeon_crtc == NULL) |
||
265 | return; |
||
266 | |||
267 | drm_crtc_init(dev, &radeon_crtc->base, &radeon_crtc_funcs); |
||
268 | |||
269 | drm_mode_crtc_set_gamma_size(&radeon_crtc->base, 256); |
||
270 | radeon_crtc->crtc_id = index; |
||
1179 | serge | 271 | rdev->mode_info.crtcs[index] = radeon_crtc; |
1123 | serge | 272 | |
1179 | serge | 273 | #if 0 |
1123 | serge | 274 | radeon_crtc->mode_set.crtc = &radeon_crtc->base; |
275 | radeon_crtc->mode_set.connectors = (struct drm_connector **)(radeon_crtc + 1); |
||
276 | radeon_crtc->mode_set.num_connectors = 0; |
||
1179 | serge | 277 | #endif |
1123 | serge | 278 | |
279 | for (i = 0; i < 256; i++) { |
||
280 | radeon_crtc->lut_r[i] = i << 2; |
||
281 | radeon_crtc->lut_g[i] = i << 2; |
||
282 | radeon_crtc->lut_b[i] = i << 2; |
||
283 | } |
||
284 | |||
285 | if (rdev->is_atom_bios && (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)) |
||
286 | radeon_atombios_init_crtc(dev, radeon_crtc); |
||
287 | else |
||
288 | radeon_legacy_init_crtc(dev, radeon_crtc); |
||
289 | } |
||
290 | |||
1963 | serge | 291 | static const char *encoder_names[36] = { |
1123 | serge | 292 | "NONE", |
293 | "INTERNAL_LVDS", |
||
294 | "INTERNAL_TMDS1", |
||
295 | "INTERNAL_TMDS2", |
||
296 | "INTERNAL_DAC1", |
||
297 | "INTERNAL_DAC2", |
||
298 | "INTERNAL_SDVOA", |
||
299 | "INTERNAL_SDVOB", |
||
300 | "SI170B", |
||
301 | "CH7303", |
||
302 | "CH7301", |
||
303 | "INTERNAL_DVO1", |
||
304 | "EXTERNAL_SDVOA", |
||
305 | "EXTERNAL_SDVOB", |
||
306 | "TITFP513", |
||
307 | "INTERNAL_LVTM1", |
||
308 | "VT1623", |
||
309 | "HDMI_SI1930", |
||
310 | "HDMI_INTERNAL", |
||
311 | "INTERNAL_KLDSCP_TMDS1", |
||
312 | "INTERNAL_KLDSCP_DVO1", |
||
313 | "INTERNAL_KLDSCP_DAC1", |
||
314 | "INTERNAL_KLDSCP_DAC2", |
||
315 | "SI178", |
||
316 | "MVPU_FPGA", |
||
317 | "INTERNAL_DDI", |
||
318 | "VT1625", |
||
319 | "HDMI_SI1932", |
||
320 | "DP_AN9801", |
||
321 | "DP_DP501", |
||
322 | "INTERNAL_UNIPHY", |
||
323 | "INTERNAL_KLDSCP_LVTMA", |
||
324 | "INTERNAL_UNIPHY1", |
||
325 | "INTERNAL_UNIPHY2", |
||
1963 | serge | 326 | "NUTMEG", |
327 | "TRAVIS", |
||
1123 | serge | 328 | }; |
329 | |||
1404 | serge | 330 | static const char *connector_names[15] = { |
1123 | serge | 331 | "Unknown", |
332 | "VGA", |
||
333 | "DVI-I", |
||
334 | "DVI-D", |
||
335 | "DVI-A", |
||
336 | "Composite", |
||
337 | "S-video", |
||
338 | "LVDS", |
||
339 | "Component", |
||
340 | "DIN", |
||
341 | "DisplayPort", |
||
342 | "HDMI-A", |
||
343 | "HDMI-B", |
||
1404 | serge | 344 | "TV", |
345 | "eDP", |
||
1123 | serge | 346 | }; |
347 | |||
1963 | serge | 348 | static const char *hpd_names[6] = { |
1404 | serge | 349 | "HPD1", |
350 | "HPD2", |
||
351 | "HPD3", |
||
352 | "HPD4", |
||
353 | "HPD5", |
||
354 | "HPD6", |
||
355 | }; |
||
356 | |||
1123 | serge | 357 | static void radeon_print_display_setup(struct drm_device *dev) |
358 | { |
||
359 | struct drm_connector *connector; |
||
360 | struct radeon_connector *radeon_connector; |
||
361 | struct drm_encoder *encoder; |
||
362 | struct radeon_encoder *radeon_encoder; |
||
363 | uint32_t devices; |
||
364 | int i = 0; |
||
365 | |||
366 | DRM_INFO("Radeon Display Connectors\n"); |
||
367 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
||
368 | radeon_connector = to_radeon_connector(connector); |
||
369 | DRM_INFO("Connector %d:\n", i); |
||
370 | DRM_INFO(" %s\n", connector_names[connector->connector_type]); |
||
1404 | serge | 371 | if (radeon_connector->hpd.hpd != RADEON_HPD_NONE) |
372 | DRM_INFO(" %s\n", hpd_names[radeon_connector->hpd.hpd]); |
||
373 | if (radeon_connector->ddc_bus) { |
||
1123 | serge | 374 | DRM_INFO(" DDC: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", |
375 | radeon_connector->ddc_bus->rec.mask_clk_reg, |
||
376 | radeon_connector->ddc_bus->rec.mask_data_reg, |
||
377 | radeon_connector->ddc_bus->rec.a_clk_reg, |
||
378 | radeon_connector->ddc_bus->rec.a_data_reg, |
||
1404 | serge | 379 | radeon_connector->ddc_bus->rec.en_clk_reg, |
380 | radeon_connector->ddc_bus->rec.en_data_reg, |
||
381 | radeon_connector->ddc_bus->rec.y_clk_reg, |
||
382 | radeon_connector->ddc_bus->rec.y_data_reg); |
||
1963 | serge | 383 | if (radeon_connector->router.ddc_valid) |
384 | DRM_INFO(" DDC Router 0x%x/0x%x\n", |
||
385 | radeon_connector->router.ddc_mux_control_pin, |
||
386 | radeon_connector->router.ddc_mux_state); |
||
387 | if (radeon_connector->router.cd_valid) |
||
388 | DRM_INFO(" Clock/Data Router 0x%x/0x%x\n", |
||
389 | radeon_connector->router.cd_mux_control_pin, |
||
390 | radeon_connector->router.cd_mux_state); |
||
1404 | serge | 391 | } else { |
392 | if (connector->connector_type == DRM_MODE_CONNECTOR_VGA || |
||
393 | connector->connector_type == DRM_MODE_CONNECTOR_DVII || |
||
394 | connector->connector_type == DRM_MODE_CONNECTOR_DVID || |
||
395 | connector->connector_type == DRM_MODE_CONNECTOR_DVIA || |
||
396 | connector->connector_type == DRM_MODE_CONNECTOR_HDMIA || |
||
397 | connector->connector_type == DRM_MODE_CONNECTOR_HDMIB) |
||
398 | DRM_INFO(" DDC: no ddc bus - possible BIOS bug - please report to xorg-driver-ati@lists.x.org\n"); |
||
399 | } |
||
1123 | serge | 400 | DRM_INFO(" Encoders:\n"); |
401 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
||
402 | radeon_encoder = to_radeon_encoder(encoder); |
||
403 | devices = radeon_encoder->devices & radeon_connector->devices; |
||
404 | if (devices) { |
||
405 | if (devices & ATOM_DEVICE_CRT1_SUPPORT) |
||
406 | DRM_INFO(" CRT1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
||
407 | if (devices & ATOM_DEVICE_CRT2_SUPPORT) |
||
408 | DRM_INFO(" CRT2: %s\n", encoder_names[radeon_encoder->encoder_id]); |
||
409 | if (devices & ATOM_DEVICE_LCD1_SUPPORT) |
||
410 | DRM_INFO(" LCD1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
||
411 | if (devices & ATOM_DEVICE_DFP1_SUPPORT) |
||
412 | DRM_INFO(" DFP1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
||
413 | if (devices & ATOM_DEVICE_DFP2_SUPPORT) |
||
414 | DRM_INFO(" DFP2: %s\n", encoder_names[radeon_encoder->encoder_id]); |
||
415 | if (devices & ATOM_DEVICE_DFP3_SUPPORT) |
||
416 | DRM_INFO(" DFP3: %s\n", encoder_names[radeon_encoder->encoder_id]); |
||
417 | if (devices & ATOM_DEVICE_DFP4_SUPPORT) |
||
418 | DRM_INFO(" DFP4: %s\n", encoder_names[radeon_encoder->encoder_id]); |
||
419 | if (devices & ATOM_DEVICE_DFP5_SUPPORT) |
||
420 | DRM_INFO(" DFP5: %s\n", encoder_names[radeon_encoder->encoder_id]); |
||
1963 | serge | 421 | if (devices & ATOM_DEVICE_DFP6_SUPPORT) |
422 | DRM_INFO(" DFP6: %s\n", encoder_names[radeon_encoder->encoder_id]); |
||
1123 | serge | 423 | if (devices & ATOM_DEVICE_TV1_SUPPORT) |
424 | DRM_INFO(" TV1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
||
425 | if (devices & ATOM_DEVICE_CV_SUPPORT) |
||
426 | DRM_INFO(" CV: %s\n", encoder_names[radeon_encoder->encoder_id]); |
||
427 | } |
||
428 | } |
||
429 | i++; |
||
430 | } |
||
431 | } |
||
432 | |||
1179 | serge | 433 | static bool radeon_setup_enc_conn(struct drm_device *dev) |
1123 | serge | 434 | { |
435 | struct radeon_device *rdev = dev->dev_private; |
||
436 | struct drm_connector *drm_connector; |
||
437 | bool ret = false; |
||
438 | |||
439 | if (rdev->bios) { |
||
440 | if (rdev->is_atom_bios) { |
||
1963 | serge | 441 | ret = radeon_get_atom_connector_info_from_supported_devices_table(dev); |
442 | if (ret == false) |
||
1123 | serge | 443 | ret = radeon_get_atom_connector_info_from_object_table(dev); |
1404 | serge | 444 | } else { |
1123 | serge | 445 | ret = radeon_get_legacy_connector_info_from_bios(dev); |
1404 | serge | 446 | if (ret == false) |
447 | ret = radeon_get_legacy_connector_info_from_table(dev); |
||
448 | } |
||
1123 | serge | 449 | } else { |
450 | if (!ASIC_IS_AVIVO(rdev)) |
||
451 | ret = radeon_get_legacy_connector_info_from_table(dev); |
||
452 | } |
||
453 | if (ret) { |
||
1404 | serge | 454 | radeon_setup_encoder_clones(dev); |
1123 | serge | 455 | radeon_print_display_setup(dev); |
1963 | serge | 456 | |
457 | // list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) |
||
458 | // radeon_ddc_dump(drm_connector); |
||
1123 | serge | 459 | } |
460 | |||
461 | return ret; |
||
462 | } |
||
463 | |||
464 | int radeon_ddc_get_modes(struct radeon_connector *radeon_connector) |
||
465 | { |
||
1430 | serge | 466 | struct drm_device *dev = radeon_connector->base.dev; |
467 | struct radeon_device *rdev = dev->dev_private; |
||
1123 | serge | 468 | int ret = 0; |
469 | |||
1963 | serge | 470 | /* on hw with routers, select right port */ |
471 | if (radeon_connector->router.ddc_valid) |
||
472 | radeon_router_select_ddc_port(radeon_connector); |
||
473 | |||
1404 | serge | 474 | if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) || |
475 | (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) { |
||
476 | struct radeon_connector_atom_dig *dig = radeon_connector->con_priv; |
||
477 | if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT || |
||
478 | dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) && dig->dp_i2c_bus) |
||
479 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, &dig->dp_i2c_bus->adapter); |
||
480 | } |
||
1123 | serge | 481 | if (!radeon_connector->ddc_bus) |
482 | return -1; |
||
1179 | serge | 483 | if (!radeon_connector->edid) { |
1268 | serge | 484 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter); |
485 | } |
||
1963 | serge | 486 | |
487 | if (!radeon_connector->edid) { |
||
488 | if (rdev->is_atom_bios) { |
||
489 | /* some laptops provide a hardcoded edid in rom for LCDs */ |
||
490 | if (((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_LVDS) || |
||
491 | (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP))) |
||
492 | radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev); |
||
493 | } else |
||
1430 | serge | 494 | /* some servers provide a hardcoded edid in rom for KVMs */ |
1963 | serge | 495 | radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev); |
496 | } |
||
1268 | serge | 497 | if (radeon_connector->edid) { |
498 | drm_mode_connector_update_edid_property(&radeon_connector->base, radeon_connector->edid); |
||
499 | ret = drm_add_edid_modes(&radeon_connector->base, radeon_connector->edid); |
||
1123 | serge | 500 | return ret; |
501 | } |
||
502 | drm_mode_connector_update_edid_property(&radeon_connector->base, NULL); |
||
1179 | serge | 503 | return 0; |
1123 | serge | 504 | } |
505 | |||
506 | static int radeon_ddc_dump(struct drm_connector *connector) |
||
507 | { |
||
508 | struct edid *edid; |
||
509 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
||
510 | int ret = 0; |
||
511 | |||
1963 | serge | 512 | /* on hw with routers, select right port */ |
513 | if (radeon_connector->router.ddc_valid) |
||
514 | radeon_router_select_ddc_port(radeon_connector); |
||
515 | |||
1123 | serge | 516 | if (!radeon_connector->ddc_bus) |
517 | return -1; |
||
518 | edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter); |
||
519 | if (edid) { |
||
520 | kfree(edid); |
||
521 | } |
||
522 | return ret; |
||
523 | } |
||
524 | |||
1963 | serge | 525 | /* avivo */ |
526 | static void avivo_get_fb_div(struct radeon_pll *pll, |
||
527 | u32 target_clock, |
||
528 | u32 post_div, |
||
529 | u32 ref_div, |
||
530 | u32 *fb_div, |
||
531 | u32 *frac_fb_div) |
||
532 | { |
||
533 | u32 tmp = post_div * ref_div; |
||
534 | |||
535 | tmp *= target_clock; |
||
536 | *fb_div = tmp / pll->reference_freq; |
||
537 | *frac_fb_div = tmp % pll->reference_freq; |
||
538 | |||
539 | if (*fb_div > pll->max_feedback_div) |
||
540 | *fb_div = pll->max_feedback_div; |
||
541 | else if (*fb_div < pll->min_feedback_div) |
||
542 | *fb_div = pll->min_feedback_div; |
||
543 | } |
||
544 | |||
545 | static u32 avivo_get_post_div(struct radeon_pll *pll, |
||
546 | u32 target_clock) |
||
547 | { |
||
548 | u32 vco, post_div, tmp; |
||
549 | |||
550 | if (pll->flags & RADEON_PLL_USE_POST_DIV) |
||
551 | return pll->post_div; |
||
552 | |||
553 | if (pll->flags & RADEON_PLL_PREFER_MINM_OVER_MAXP) { |
||
554 | if (pll->flags & RADEON_PLL_IS_LCD) |
||
555 | vco = pll->lcd_pll_out_min; |
||
556 | else |
||
557 | vco = pll->pll_out_min; |
||
558 | } else { |
||
559 | if (pll->flags & RADEON_PLL_IS_LCD) |
||
560 | vco = pll->lcd_pll_out_max; |
||
561 | else |
||
562 | vco = pll->pll_out_max; |
||
563 | } |
||
564 | |||
565 | post_div = vco / target_clock; |
||
566 | tmp = vco % target_clock; |
||
567 | |||
568 | if (pll->flags & RADEON_PLL_PREFER_MINM_OVER_MAXP) { |
||
569 | if (tmp) |
||
570 | post_div++; |
||
571 | } else { |
||
572 | if (!tmp) |
||
573 | post_div--; |
||
574 | } |
||
575 | |||
576 | if (post_div > pll->max_post_div) |
||
577 | post_div = pll->max_post_div; |
||
578 | else if (post_div < pll->min_post_div) |
||
579 | post_div = pll->min_post_div; |
||
580 | |||
581 | return post_div; |
||
582 | } |
||
583 | |||
584 | #define MAX_TOLERANCE 10 |
||
585 | |||
586 | void radeon_compute_pll_avivo(struct radeon_pll *pll, |
||
587 | u32 freq, |
||
588 | u32 *dot_clock_p, |
||
589 | u32 *fb_div_p, |
||
590 | u32 *frac_fb_div_p, |
||
591 | u32 *ref_div_p, |
||
592 | u32 *post_div_p) |
||
593 | { |
||
594 | u32 target_clock = freq / 10; |
||
595 | u32 post_div = avivo_get_post_div(pll, target_clock); |
||
596 | u32 ref_div = pll->min_ref_div; |
||
597 | u32 fb_div = 0, frac_fb_div = 0, tmp; |
||
598 | |||
599 | if (pll->flags & RADEON_PLL_USE_REF_DIV) |
||
600 | ref_div = pll->reference_div; |
||
601 | |||
602 | if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) { |
||
603 | avivo_get_fb_div(pll, target_clock, post_div, ref_div, &fb_div, &frac_fb_div); |
||
604 | frac_fb_div = (100 * frac_fb_div) / pll->reference_freq; |
||
605 | if (frac_fb_div >= 5) { |
||
606 | frac_fb_div -= 5; |
||
607 | frac_fb_div = frac_fb_div / 10; |
||
608 | frac_fb_div++; |
||
609 | } |
||
610 | if (frac_fb_div >= 10) { |
||
611 | fb_div++; |
||
612 | frac_fb_div = 0; |
||
613 | } |
||
614 | } else { |
||
615 | while (ref_div <= pll->max_ref_div) { |
||
616 | avivo_get_fb_div(pll, target_clock, post_div, ref_div, |
||
617 | &fb_div, &frac_fb_div); |
||
618 | if (frac_fb_div >= (pll->reference_freq / 2)) |
||
619 | fb_div++; |
||
620 | frac_fb_div = 0; |
||
621 | tmp = (pll->reference_freq * fb_div) / (post_div * ref_div); |
||
622 | tmp = (tmp * 10000) / target_clock; |
||
623 | |||
624 | if (tmp > (10000 + MAX_TOLERANCE)) |
||
625 | ref_div++; |
||
626 | else if (tmp >= (10000 - MAX_TOLERANCE)) |
||
627 | break; |
||
628 | else |
||
629 | ref_div++; |
||
630 | } |
||
631 | } |
||
632 | |||
633 | *dot_clock_p = ((pll->reference_freq * fb_div * 10) + (pll->reference_freq * frac_fb_div)) / |
||
634 | (ref_div * post_div * 10); |
||
635 | *fb_div_p = fb_div; |
||
636 | *frac_fb_div_p = frac_fb_div; |
||
637 | *ref_div_p = ref_div; |
||
638 | *post_div_p = post_div; |
||
639 | DRM_DEBUG_KMS("%d, pll dividers - fb: %d.%d ref: %d, post %d\n", |
||
640 | *dot_clock_p, fb_div, frac_fb_div, ref_div, post_div); |
||
641 | } |
||
642 | |||
643 | /* pre-avivo */ |
||
1123 | serge | 644 | static inline uint32_t radeon_div(uint64_t n, uint32_t d) |
645 | { |
||
646 | uint64_t mod; |
||
647 | |||
648 | n += d / 2; |
||
649 | |||
650 | mod = do_div(n, d); |
||
651 | return n; |
||
652 | } |
||
653 | |||
1963 | serge | 654 | void radeon_compute_pll_legacy(struct radeon_pll *pll, |
1123 | serge | 655 | uint64_t freq, |
656 | uint32_t *dot_clock_p, |
||
657 | uint32_t *fb_div_p, |
||
658 | uint32_t *frac_fb_div_p, |
||
659 | uint32_t *ref_div_p, |
||
1404 | serge | 660 | uint32_t *post_div_p) |
1123 | serge | 661 | { |
662 | uint32_t min_ref_div = pll->min_ref_div; |
||
663 | uint32_t max_ref_div = pll->max_ref_div; |
||
1404 | serge | 664 | uint32_t min_post_div = pll->min_post_div; |
665 | uint32_t max_post_div = pll->max_post_div; |
||
1123 | serge | 666 | uint32_t min_fractional_feed_div = 0; |
667 | uint32_t max_fractional_feed_div = 0; |
||
668 | uint32_t best_vco = pll->best_vco; |
||
669 | uint32_t best_post_div = 1; |
||
670 | uint32_t best_ref_div = 1; |
||
671 | uint32_t best_feedback_div = 1; |
||
672 | uint32_t best_frac_feedback_div = 0; |
||
673 | uint32_t best_freq = -1; |
||
674 | uint32_t best_error = 0xffffffff; |
||
675 | uint32_t best_vco_diff = 1; |
||
676 | uint32_t post_div; |
||
1963 | serge | 677 | u32 pll_out_min, pll_out_max; |
1123 | serge | 678 | |
1963 | serge | 679 | DRM_DEBUG_KMS("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div); |
1123 | serge | 680 | freq = freq * 1000; |
681 | |||
1963 | serge | 682 | if (pll->flags & RADEON_PLL_IS_LCD) { |
683 | pll_out_min = pll->lcd_pll_out_min; |
||
684 | pll_out_max = pll->lcd_pll_out_max; |
||
685 | } else { |
||
686 | pll_out_min = pll->pll_out_min; |
||
687 | pll_out_max = pll->pll_out_max; |
||
688 | } |
||
689 | |||
690 | if (pll_out_min > 64800) |
||
691 | pll_out_min = 64800; |
||
692 | |||
1404 | serge | 693 | if (pll->flags & RADEON_PLL_USE_REF_DIV) |
1123 | serge | 694 | min_ref_div = max_ref_div = pll->reference_div; |
695 | else { |
||
696 | while (min_ref_div < max_ref_div-1) { |
||
697 | uint32_t mid = (min_ref_div + max_ref_div) / 2; |
||
698 | uint32_t pll_in = pll->reference_freq / mid; |
||
699 | if (pll_in < pll->pll_in_min) |
||
700 | max_ref_div = mid; |
||
701 | else if (pll_in > pll->pll_in_max) |
||
702 | min_ref_div = mid; |
||
703 | else |
||
704 | break; |
||
705 | } |
||
706 | } |
||
707 | |||
1404 | serge | 708 | if (pll->flags & RADEON_PLL_USE_POST_DIV) |
709 | min_post_div = max_post_div = pll->post_div; |
||
710 | |||
711 | if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) { |
||
1123 | serge | 712 | min_fractional_feed_div = pll->min_frac_feedback_div; |
713 | max_fractional_feed_div = pll->max_frac_feedback_div; |
||
714 | } |
||
715 | |||
1963 | serge | 716 | for (post_div = max_post_div; post_div >= min_post_div; --post_div) { |
1123 | serge | 717 | uint32_t ref_div; |
718 | |||
1404 | serge | 719 | if ((pll->flags & RADEON_PLL_NO_ODD_POST_DIV) && (post_div & 1)) |
1123 | serge | 720 | continue; |
721 | |||
722 | /* legacy radeons only have a few post_divs */ |
||
1404 | serge | 723 | if (pll->flags & RADEON_PLL_LEGACY) { |
1123 | serge | 724 | if ((post_div == 5) || |
725 | (post_div == 7) || |
||
726 | (post_div == 9) || |
||
727 | (post_div == 10) || |
||
728 | (post_div == 11) || |
||
729 | (post_div == 13) || |
||
730 | (post_div == 14) || |
||
731 | (post_div == 15)) |
||
732 | continue; |
||
733 | } |
||
734 | |||
735 | for (ref_div = min_ref_div; ref_div <= max_ref_div; ++ref_div) { |
||
736 | uint32_t feedback_div, current_freq = 0, error, vco_diff; |
||
737 | uint32_t pll_in = pll->reference_freq / ref_div; |
||
738 | uint32_t min_feed_div = pll->min_feedback_div; |
||
739 | uint32_t max_feed_div = pll->max_feedback_div + 1; |
||
740 | |||
741 | if (pll_in < pll->pll_in_min || pll_in > pll->pll_in_max) |
||
742 | continue; |
||
743 | |||
744 | while (min_feed_div < max_feed_div) { |
||
745 | uint32_t vco; |
||
746 | uint32_t min_frac_feed_div = min_fractional_feed_div; |
||
747 | uint32_t max_frac_feed_div = max_fractional_feed_div + 1; |
||
748 | uint32_t frac_feedback_div; |
||
749 | uint64_t tmp; |
||
750 | |||
751 | feedback_div = (min_feed_div + max_feed_div) / 2; |
||
752 | |||
753 | tmp = (uint64_t)pll->reference_freq * feedback_div; |
||
754 | vco = radeon_div(tmp, ref_div); |
||
755 | |||
1963 | serge | 756 | if (vco < pll_out_min) { |
1123 | serge | 757 | min_feed_div = feedback_div + 1; |
758 | continue; |
||
1963 | serge | 759 | } else if (vco > pll_out_max) { |
1123 | serge | 760 | max_feed_div = feedback_div; |
761 | continue; |
||
762 | } |
||
763 | |||
764 | while (min_frac_feed_div < max_frac_feed_div) { |
||
765 | frac_feedback_div = (min_frac_feed_div + max_frac_feed_div) / 2; |
||
766 | tmp = (uint64_t)pll->reference_freq * 10000 * feedback_div; |
||
767 | tmp += (uint64_t)pll->reference_freq * 1000 * frac_feedback_div; |
||
768 | current_freq = radeon_div(tmp, ref_div * post_div); |
||
769 | |||
1404 | serge | 770 | if (pll->flags & RADEON_PLL_PREFER_CLOSEST_LOWER) { |
1963 | serge | 771 | if (freq < current_freq) |
772 | error = 0xffffffff; |
||
773 | else |
||
1179 | serge | 774 | error = freq - current_freq; |
775 | } else |
||
1123 | serge | 776 | error = abs(current_freq - freq); |
777 | vco_diff = abs(vco - best_vco); |
||
778 | |||
779 | if ((best_vco == 0 && error < best_error) || |
||
780 | (best_vco != 0 && |
||
1963 | serge | 781 | ((best_error > 100 && error < best_error - 100) || |
1123 | serge | 782 | (abs(error - best_error) < 100 && vco_diff < best_vco_diff)))) { |
783 | best_post_div = post_div; |
||
784 | best_ref_div = ref_div; |
||
785 | best_feedback_div = feedback_div; |
||
786 | best_frac_feedback_div = frac_feedback_div; |
||
787 | best_freq = current_freq; |
||
788 | best_error = error; |
||
789 | best_vco_diff = vco_diff; |
||
790 | } else if (current_freq == freq) { |
||
791 | if (best_freq == -1) { |
||
792 | best_post_div = post_div; |
||
793 | best_ref_div = ref_div; |
||
794 | best_feedback_div = feedback_div; |
||
795 | best_frac_feedback_div = frac_feedback_div; |
||
796 | best_freq = current_freq; |
||
797 | best_error = error; |
||
798 | best_vco_diff = vco_diff; |
||
1404 | serge | 799 | } else if (((pll->flags & RADEON_PLL_PREFER_LOW_REF_DIV) && (ref_div < best_ref_div)) || |
800 | ((pll->flags & RADEON_PLL_PREFER_HIGH_REF_DIV) && (ref_div > best_ref_div)) || |
||
801 | ((pll->flags & RADEON_PLL_PREFER_LOW_FB_DIV) && (feedback_div < best_feedback_div)) || |
||
802 | ((pll->flags & RADEON_PLL_PREFER_HIGH_FB_DIV) && (feedback_div > best_feedback_div)) || |
||
803 | ((pll->flags & RADEON_PLL_PREFER_LOW_POST_DIV) && (post_div < best_post_div)) || |
||
804 | ((pll->flags & RADEON_PLL_PREFER_HIGH_POST_DIV) && (post_div > best_post_div))) { |
||
1123 | serge | 805 | best_post_div = post_div; |
806 | best_ref_div = ref_div; |
||
807 | best_feedback_div = feedback_div; |
||
808 | best_frac_feedback_div = frac_feedback_div; |
||
809 | best_freq = current_freq; |
||
810 | best_error = error; |
||
811 | best_vco_diff = vco_diff; |
||
812 | } |
||
813 | } |
||
814 | if (current_freq < freq) |
||
815 | min_frac_feed_div = frac_feedback_div + 1; |
||
816 | else |
||
817 | max_frac_feed_div = frac_feedback_div; |
||
818 | } |
||
819 | if (current_freq < freq) |
||
820 | min_feed_div = feedback_div + 1; |
||
821 | else |
||
822 | max_feed_div = feedback_div; |
||
823 | } |
||
824 | } |
||
825 | } |
||
826 | |||
827 | *dot_clock_p = best_freq / 10000; |
||
828 | *fb_div_p = best_feedback_div; |
||
829 | *frac_fb_div_p = best_frac_feedback_div; |
||
830 | *ref_div_p = best_ref_div; |
||
831 | *post_div_p = best_post_div; |
||
1963 | serge | 832 | DRM_DEBUG_KMS("%lld %d, pll dividers - fb: %d.%d ref: %d, post %d\n", |
833 | (long long)freq, |
||
834 | best_freq / 1000, best_feedback_div, best_frac_feedback_div, |
||
835 | best_ref_div, best_post_div); |
||
1123 | serge | 836 | |
1430 | serge | 837 | } |
838 | |||
1123 | serge | 839 | static void radeon_user_framebuffer_destroy(struct drm_framebuffer *fb) |
840 | { |
||
841 | struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb); |
||
842 | |||
843 | drm_framebuffer_cleanup(fb); |
||
844 | kfree(radeon_fb); |
||
845 | } |
||
846 | |||
847 | static int radeon_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
||
848 | struct drm_file *file_priv, |
||
849 | unsigned int *handle) |
||
850 | { |
||
851 | struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb); |
||
852 | |||
853 | return NULL; |
||
854 | // return drm_gem_handle_create(file_priv, radeon_fb->obj, handle); |
||
855 | } |
||
856 | |||
857 | static const struct drm_framebuffer_funcs radeon_fb_funcs = { |
||
858 | .destroy = radeon_user_framebuffer_destroy, |
||
859 | .create_handle = radeon_user_framebuffer_create_handle, |
||
860 | }; |
||
861 | |||
1963 | serge | 862 | void |
863 | radeon_framebuffer_init(struct drm_device *dev, |
||
864 | struct radeon_framebuffer *rfb, |
||
1123 | serge | 865 | struct drm_mode_fb_cmd *mode_cmd, |
866 | struct drm_gem_object *obj) |
||
867 | { |
||
1963 | serge | 868 | rfb->obj = obj; |
869 | drm_framebuffer_init(dev, &rfb->base, &radeon_fb_funcs); |
||
870 | drm_helper_mode_fill_fb_struct(&rfb->base, mode_cmd); |
||
1123 | serge | 871 | } |
872 | |||
873 | static struct drm_framebuffer * |
||
874 | radeon_user_framebuffer_create(struct drm_device *dev, |
||
875 | struct drm_file *file_priv, |
||
876 | struct drm_mode_fb_cmd *mode_cmd) |
||
877 | { |
||
878 | struct drm_gem_object *obj; |
||
879 | |||
1125 | serge | 880 | return NULL; |
1123 | serge | 881 | |
1125 | serge | 882 | // obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle); |
883 | // |
||
884 | // return radeon_framebuffer_create(dev, mode_cmd, obj); |
||
1123 | serge | 885 | } |
886 | |||
1963 | serge | 887 | |
1123 | serge | 888 | static const struct drm_mode_config_funcs radeon_mode_funcs = { |
1963 | serge | 889 | // .fb_create = radeon_user_framebuffer_create, |
890 | // .output_poll_changed = radeon_output_poll_changed |
||
1123 | serge | 891 | }; |
892 | |||
1179 | serge | 893 | struct drm_prop_enum_list { |
894 | int type; |
||
895 | char *name; |
||
896 | }; |
||
897 | |||
898 | static struct drm_prop_enum_list radeon_tmds_pll_enum_list[] = |
||
899 | { { 0, "driver" }, |
||
900 | { 1, "bios" }, |
||
901 | }; |
||
902 | |||
903 | static struct drm_prop_enum_list radeon_tv_std_enum_list[] = |
||
904 | { { TV_STD_NTSC, "ntsc" }, |
||
905 | { TV_STD_PAL, "pal" }, |
||
906 | { TV_STD_PAL_M, "pal-m" }, |
||
907 | { TV_STD_PAL_60, "pal-60" }, |
||
908 | { TV_STD_NTSC_J, "ntsc-j" }, |
||
909 | { TV_STD_SCART_PAL, "scart-pal" }, |
||
910 | { TV_STD_PAL_CN, "pal-cn" }, |
||
911 | { TV_STD_SECAM, "secam" }, |
||
912 | }; |
||
913 | |||
1963 | serge | 914 | static struct drm_prop_enum_list radeon_underscan_enum_list[] = |
915 | { { UNDERSCAN_OFF, "off" }, |
||
916 | { UNDERSCAN_ON, "on" }, |
||
917 | { UNDERSCAN_AUTO, "auto" }, |
||
918 | }; |
||
919 | |||
1404 | serge | 920 | static int radeon_modeset_create_props(struct radeon_device *rdev) |
1123 | serge | 921 | { |
1179 | serge | 922 | int i, sz; |
1125 | serge | 923 | |
1179 | serge | 924 | if (rdev->is_atom_bios) { |
925 | rdev->mode_info.coherent_mode_property = |
||
926 | drm_property_create(rdev->ddev, |
||
927 | DRM_MODE_PROP_RANGE, |
||
928 | "coherent", 2); |
||
929 | if (!rdev->mode_info.coherent_mode_property) |
||
930 | return -ENOMEM; |
||
1125 | serge | 931 | |
1179 | serge | 932 | rdev->mode_info.coherent_mode_property->values[0] = 0; |
1404 | serge | 933 | rdev->mode_info.coherent_mode_property->values[1] = 1; |
1179 | serge | 934 | } |
935 | |||
936 | if (!ASIC_IS_AVIVO(rdev)) { |
||
937 | sz = ARRAY_SIZE(radeon_tmds_pll_enum_list); |
||
938 | rdev->mode_info.tmds_pll_property = |
||
939 | drm_property_create(rdev->ddev, |
||
940 | DRM_MODE_PROP_ENUM, |
||
941 | "tmds_pll", sz); |
||
942 | for (i = 0; i < sz; i++) { |
||
943 | drm_property_add_enum(rdev->mode_info.tmds_pll_property, |
||
944 | i, |
||
945 | radeon_tmds_pll_enum_list[i].type, |
||
946 | radeon_tmds_pll_enum_list[i].name); |
||
947 | } |
||
948 | } |
||
949 | |||
950 | rdev->mode_info.load_detect_property = |
||
951 | drm_property_create(rdev->ddev, |
||
952 | DRM_MODE_PROP_RANGE, |
||
953 | "load detection", 2); |
||
954 | if (!rdev->mode_info.load_detect_property) |
||
955 | return -ENOMEM; |
||
956 | rdev->mode_info.load_detect_property->values[0] = 0; |
||
1404 | serge | 957 | rdev->mode_info.load_detect_property->values[1] = 1; |
1179 | serge | 958 | |
959 | drm_mode_create_scaling_mode_property(rdev->ddev); |
||
960 | |||
961 | sz = ARRAY_SIZE(radeon_tv_std_enum_list); |
||
962 | rdev->mode_info.tv_std_property = |
||
963 | drm_property_create(rdev->ddev, |
||
964 | DRM_MODE_PROP_ENUM, |
||
965 | "tv standard", sz); |
||
966 | for (i = 0; i < sz; i++) { |
||
967 | drm_property_add_enum(rdev->mode_info.tv_std_property, |
||
968 | i, |
||
969 | radeon_tv_std_enum_list[i].type, |
||
970 | radeon_tv_std_enum_list[i].name); |
||
971 | } |
||
972 | |||
1963 | serge | 973 | sz = ARRAY_SIZE(radeon_underscan_enum_list); |
974 | rdev->mode_info.underscan_property = |
||
975 | drm_property_create(rdev->ddev, |
||
976 | DRM_MODE_PROP_ENUM, |
||
977 | "underscan", sz); |
||
978 | for (i = 0; i < sz; i++) { |
||
979 | drm_property_add_enum(rdev->mode_info.underscan_property, |
||
980 | i, |
||
981 | radeon_underscan_enum_list[i].type, |
||
982 | radeon_underscan_enum_list[i].name); |
||
983 | } |
||
984 | |||
985 | rdev->mode_info.underscan_hborder_property = |
||
986 | drm_property_create(rdev->ddev, |
||
987 | DRM_MODE_PROP_RANGE, |
||
988 | "underscan hborder", 2); |
||
989 | if (!rdev->mode_info.underscan_hborder_property) |
||
990 | return -ENOMEM; |
||
991 | rdev->mode_info.underscan_hborder_property->values[0] = 0; |
||
992 | rdev->mode_info.underscan_hborder_property->values[1] = 128; |
||
993 | |||
994 | rdev->mode_info.underscan_vborder_property = |
||
995 | drm_property_create(rdev->ddev, |
||
996 | DRM_MODE_PROP_RANGE, |
||
997 | "underscan vborder", 2); |
||
998 | if (!rdev->mode_info.underscan_vborder_property) |
||
999 | return -ENOMEM; |
||
1000 | rdev->mode_info.underscan_vborder_property->values[0] = 0; |
||
1001 | rdev->mode_info.underscan_vborder_property->values[1] = 128; |
||
1002 | |||
1179 | serge | 1003 | return 0; |
1004 | } |
||
1005 | |||
1963 | serge | 1006 | void radeon_update_display_priority(struct radeon_device *rdev) |
1007 | { |
||
1008 | /* adjustment options for the display watermarks */ |
||
1009 | if ((radeon_disp_priority == 0) || (radeon_disp_priority > 2)) { |
||
1010 | /* set display priority to high for r3xx, rv515 chips |
||
1011 | * this avoids flickering due to underflow to the |
||
1012 | * display controllers during heavy acceleration. |
||
1013 | * Don't force high on rs4xx igp chips as it seems to |
||
1014 | * affect the sound card. See kernel bug 15982. |
||
1015 | */ |
||
1016 | if ((ASIC_IS_R300(rdev) || (rdev->family == CHIP_RV515)) && |
||
1017 | !(rdev->flags & RADEON_IS_IGP)) |
||
1018 | rdev->disp_priority = 2; |
||
1019 | else |
||
1020 | rdev->disp_priority = 0; |
||
1021 | } else |
||
1022 | rdev->disp_priority = radeon_disp_priority; |
||
1023 | |||
1024 | } |
||
1025 | |||
1179 | serge | 1026 | int radeon_modeset_init(struct radeon_device *rdev) |
1027 | { |
||
1430 | serge | 1028 | int i; |
1123 | serge | 1029 | int ret; |
1030 | |||
1963 | serge | 1031 | ENTER(); |
1032 | |||
1123 | serge | 1033 | drm_mode_config_init(rdev->ddev); |
1034 | rdev->mode_info.mode_config_initialized = true; |
||
1035 | |||
1125 | serge | 1036 | rdev->ddev->mode_config.funcs = (void *)&radeon_mode_funcs; |
1123 | serge | 1037 | |
1963 | serge | 1038 | if (ASIC_IS_DCE5(rdev)) { |
1039 | rdev->ddev->mode_config.max_width = 16384; |
||
1040 | rdev->ddev->mode_config.max_height = 16384; |
||
1041 | } else if (ASIC_IS_AVIVO(rdev)) { |
||
1123 | serge | 1042 | rdev->ddev->mode_config.max_width = 8192; |
1043 | rdev->ddev->mode_config.max_height = 8192; |
||
1044 | } else { |
||
1045 | rdev->ddev->mode_config.max_width = 4096; |
||
1046 | rdev->ddev->mode_config.max_height = 4096; |
||
1047 | } |
||
1048 | |||
1049 | rdev->ddev->mode_config.fb_base = rdev->mc.aper_base; |
||
1050 | |||
1179 | serge | 1051 | ret = radeon_modeset_create_props(rdev); |
1052 | if (ret) { |
||
1053 | return ret; |
||
1054 | } |
||
1221 | serge | 1055 | |
1963 | serge | 1056 | /* init i2c buses */ |
1057 | radeon_i2c_init(rdev); |
||
1058 | |||
1430 | serge | 1059 | /* check combios for a valid hardcoded EDID - Sun servers */ |
1060 | if (!rdev->is_atom_bios) { |
||
1061 | /* check for hardcoded EDID in BIOS */ |
||
1062 | radeon_combios_check_hardcoded_edid(rdev); |
||
1063 | } |
||
1064 | |||
1221 | serge | 1065 | /* allocate crtcs */ |
1430 | serge | 1066 | for (i = 0; i < rdev->num_crtc; i++) { |
1123 | serge | 1067 | radeon_crtc_init(rdev->ddev, i); |
1068 | } |
||
1069 | |||
1070 | /* okay we should have all the bios connectors */ |
||
1071 | ret = radeon_setup_enc_conn(rdev->ddev); |
||
1072 | if (!ret) { |
||
1073 | return ret; |
||
1074 | } |
||
1963 | serge | 1075 | |
1076 | /* init dig PHYs */ |
||
1077 | if (rdev->is_atom_bios) |
||
1078 | radeon_atom_encoder_init(rdev); |
||
1079 | |||
1404 | serge | 1080 | /* initialize hpd */ |
1963 | serge | 1081 | // radeon_hpd_init(rdev); |
1082 | |||
1083 | /* Initialize power management */ |
||
1084 | // radeon_pm_init(rdev); |
||
1085 | |||
1086 | radeon_fbdev_init(rdev); |
||
1087 | // drm_kms_helper_poll_init(rdev->ddev); |
||
1088 | |||
1089 | LEAVE(); |
||
1090 | |||
1123 | serge | 1091 | return 0; |
1092 | } |
||
1093 | |||
1094 | void radeon_modeset_fini(struct radeon_device *rdev) |
||
1095 | { |
||
1430 | serge | 1096 | kfree(rdev->mode_info.bios_hardcoded_edid); |
1097 | |||
1123 | serge | 1098 | if (rdev->mode_info.mode_config_initialized) { |
1963 | serge | 1099 | // drm_kms_helper_poll_fini(rdev->ddev); |
1100 | // radeon_hpd_fini(rdev); |
||
1123 | serge | 1101 | drm_mode_config_cleanup(rdev->ddev); |
1102 | rdev->mode_info.mode_config_initialized = false; |
||
1103 | } |
||
1963 | serge | 1104 | /* free i2c buses */ |
1105 | radeon_i2c_fini(rdev); |
||
1123 | serge | 1106 | } |
1107 | |||
1963 | serge | 1108 | static bool is_hdtv_mode(struct drm_display_mode *mode) |
1109 | { |
||
1110 | /* try and guess if this is a tv or a monitor */ |
||
1111 | if ((mode->vdisplay == 480 && mode->hdisplay == 720) || /* 480p */ |
||
1112 | (mode->vdisplay == 576) || /* 576p */ |
||
1113 | (mode->vdisplay == 720) || /* 720p */ |
||
1114 | (mode->vdisplay == 1080)) /* 1080p */ |
||
1115 | return true; |
||
1116 | else |
||
1117 | return false; |
||
1118 | } |
||
1119 | |||
1179 | serge | 1120 | bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc, |
1121 | struct drm_display_mode *mode, |
||
1122 | struct drm_display_mode *adjusted_mode) |
||
1123 | serge | 1123 | { |
1179 | serge | 1124 | struct drm_device *dev = crtc->dev; |
1963 | serge | 1125 | struct radeon_device *rdev = dev->dev_private; |
1179 | serge | 1126 | struct drm_encoder *encoder; |
1123 | serge | 1127 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
1179 | serge | 1128 | struct radeon_encoder *radeon_encoder; |
1963 | serge | 1129 | struct drm_connector *connector; |
1130 | struct radeon_connector *radeon_connector; |
||
1179 | serge | 1131 | bool first = true; |
1963 | serge | 1132 | u32 src_v = 1, dst_v = 1; |
1133 | u32 src_h = 1, dst_h = 1; |
||
1123 | serge | 1134 | |
1963 | serge | 1135 | radeon_crtc->h_border = 0; |
1136 | radeon_crtc->v_border = 0; |
||
1137 | |||
1179 | serge | 1138 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
1139 | if (encoder->crtc != crtc) |
||
1140 | continue; |
||
1963 | serge | 1141 | radeon_encoder = to_radeon_encoder(encoder); |
1142 | connector = radeon_get_connector_for_encoder(encoder); |
||
1143 | radeon_connector = to_radeon_connector(connector); |
||
1144 | |||
1179 | serge | 1145 | if (first) { |
1404 | serge | 1146 | /* set scaling */ |
1147 | if (radeon_encoder->rmx_type == RMX_OFF) |
||
1148 | radeon_crtc->rmx_type = RMX_OFF; |
||
1149 | else if (mode->hdisplay < radeon_encoder->native_mode.hdisplay || |
||
1150 | mode->vdisplay < radeon_encoder->native_mode.vdisplay) |
||
1179 | serge | 1151 | radeon_crtc->rmx_type = radeon_encoder->rmx_type; |
1404 | serge | 1152 | else |
1153 | radeon_crtc->rmx_type = RMX_OFF; |
||
1154 | /* copy native mode */ |
||
1179 | serge | 1155 | memcpy(&radeon_crtc->native_mode, |
1156 | &radeon_encoder->native_mode, |
||
1268 | serge | 1157 | sizeof(struct drm_display_mode)); |
1963 | serge | 1158 | src_v = crtc->mode.vdisplay; |
1159 | dst_v = radeon_crtc->native_mode.vdisplay; |
||
1160 | src_h = crtc->mode.hdisplay; |
||
1161 | dst_h = radeon_crtc->native_mode.hdisplay; |
||
1162 | |||
1163 | /* fix up for overscan on hdmi */ |
||
1164 | if (ASIC_IS_AVIVO(rdev) && |
||
1165 | (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) && |
||
1166 | ((radeon_encoder->underscan_type == UNDERSCAN_ON) || |
||
1167 | ((radeon_encoder->underscan_type == UNDERSCAN_AUTO) && |
||
1168 | drm_detect_hdmi_monitor(radeon_connector->edid) && |
||
1169 | is_hdtv_mode(mode)))) { |
||
1170 | if (radeon_encoder->underscan_hborder != 0) |
||
1171 | radeon_crtc->h_border = radeon_encoder->underscan_hborder; |
||
1172 | else |
||
1173 | radeon_crtc->h_border = (mode->hdisplay >> 5) + 16; |
||
1174 | if (radeon_encoder->underscan_vborder != 0) |
||
1175 | radeon_crtc->v_border = radeon_encoder->underscan_vborder; |
||
1176 | else |
||
1177 | radeon_crtc->v_border = (mode->vdisplay >> 5) + 16; |
||
1178 | radeon_crtc->rmx_type = RMX_FULL; |
||
1179 | src_v = crtc->mode.vdisplay; |
||
1180 | dst_v = crtc->mode.vdisplay - (radeon_crtc->v_border * 2); |
||
1181 | src_h = crtc->mode.hdisplay; |
||
1182 | dst_h = crtc->mode.hdisplay - (radeon_crtc->h_border * 2); |
||
1183 | } |
||
1179 | serge | 1184 | first = false; |
1185 | } else { |
||
1186 | if (radeon_crtc->rmx_type != radeon_encoder->rmx_type) { |
||
1187 | /* WARNING: Right now this can't happen but |
||
1188 | * in the future we need to check that scaling |
||
1963 | serge | 1189 | * are consistent across different encoder |
1179 | serge | 1190 | * (ie all encoder can work with the same |
1191 | * scaling). |
||
1192 | */ |
||
1963 | serge | 1193 | DRM_ERROR("Scaling not consistent across encoder.\n"); |
1179 | serge | 1194 | return false; |
1195 | } |
||
1123 | serge | 1196 | } |
1197 | } |
||
1179 | serge | 1198 | if (radeon_crtc->rmx_type != RMX_OFF) { |
1221 | serge | 1199 | fixed20_12 a, b; |
1963 | serge | 1200 | a.full = dfixed_const(src_v); |
1201 | b.full = dfixed_const(dst_v); |
||
1202 | radeon_crtc->vsc.full = dfixed_div(a, b); |
||
1203 | a.full = dfixed_const(src_h); |
||
1204 | b.full = dfixed_const(dst_h); |
||
1205 | radeon_crtc->hsc.full = dfixed_div(a, b); |
||
1123 | serge | 1206 | } else { |
1963 | serge | 1207 | radeon_crtc->vsc.full = dfixed_const(1); |
1208 | radeon_crtc->hsc.full = dfixed_const(1); |
||
1123 | serge | 1209 | } |
1179 | serge | 1210 | return true; |
1123 | serge | 1211 | } |
1963 | serge | 1212 | |
1213 | /* |
||
1214 | * Retrieve current video scanout position of crtc on a given gpu. |
||
1215 | * |
||
1216 | * \param dev Device to query. |
||
1217 | * \param crtc Crtc to query. |
||
1218 | * \param *vpos Location where vertical scanout position should be stored. |
||
1219 | * \param *hpos Location where horizontal scanout position should go. |
||
1220 | * |
||
1221 | * Returns vpos as a positive number while in active scanout area. |
||
1222 | * Returns vpos as a negative number inside vblank, counting the number |
||
1223 | * of scanlines to go until end of vblank, e.g., -1 means "one scanline |
||
1224 | * until start of active scanout / end of vblank." |
||
1225 | * |
||
1226 | * \return Flags, or'ed together as follows: |
||
1227 | * |
||
1228 | * DRM_SCANOUTPOS_VALID = Query successful. |
||
1229 | * DRM_SCANOUTPOS_INVBL = Inside vblank. |
||
1230 | * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of |
||
1231 | * this flag means that returned position may be offset by a constant but |
||
1232 | * unknown small number of scanlines wrt. real scanout position. |
||
1233 | * |
||
1234 | */ |
||
1235 | int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc, int *vpos, int *hpos) |
||
1236 | { |
||
1237 | u32 stat_crtc = 0, vbl = 0, position = 0; |
||
1238 | int vbl_start, vbl_end, vtotal, ret = 0; |
||
1239 | bool in_vbl = true; |
||
1240 | |||
1241 | struct radeon_device *rdev = dev->dev_private; |
||
1242 | |||
1243 | if (ASIC_IS_DCE4(rdev)) { |
||
1244 | if (crtc == 0) { |
||
1245 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
||
1246 | EVERGREEN_CRTC0_REGISTER_OFFSET); |
||
1247 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
||
1248 | EVERGREEN_CRTC0_REGISTER_OFFSET); |
||
1249 | ret |= DRM_SCANOUTPOS_VALID; |
||
1250 | } |
||
1251 | if (crtc == 1) { |
||
1252 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
||
1253 | EVERGREEN_CRTC1_REGISTER_OFFSET); |
||
1254 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
||
1255 | EVERGREEN_CRTC1_REGISTER_OFFSET); |
||
1256 | ret |= DRM_SCANOUTPOS_VALID; |
||
1257 | } |
||
1258 | if (crtc == 2) { |
||
1259 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
||
1260 | EVERGREEN_CRTC2_REGISTER_OFFSET); |
||
1261 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
||
1262 | EVERGREEN_CRTC2_REGISTER_OFFSET); |
||
1263 | ret |= DRM_SCANOUTPOS_VALID; |
||
1264 | } |
||
1265 | if (crtc == 3) { |
||
1266 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
||
1267 | EVERGREEN_CRTC3_REGISTER_OFFSET); |
||
1268 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
||
1269 | EVERGREEN_CRTC3_REGISTER_OFFSET); |
||
1270 | ret |= DRM_SCANOUTPOS_VALID; |
||
1271 | } |
||
1272 | if (crtc == 4) { |
||
1273 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
||
1274 | EVERGREEN_CRTC4_REGISTER_OFFSET); |
||
1275 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
||
1276 | EVERGREEN_CRTC4_REGISTER_OFFSET); |
||
1277 | ret |= DRM_SCANOUTPOS_VALID; |
||
1278 | } |
||
1279 | if (crtc == 5) { |
||
1280 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
||
1281 | EVERGREEN_CRTC5_REGISTER_OFFSET); |
||
1282 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
||
1283 | EVERGREEN_CRTC5_REGISTER_OFFSET); |
||
1284 | ret |= DRM_SCANOUTPOS_VALID; |
||
1285 | } |
||
1286 | } else if (ASIC_IS_AVIVO(rdev)) { |
||
1287 | if (crtc == 0) { |
||
1288 | vbl = RREG32(AVIVO_D1CRTC_V_BLANK_START_END); |
||
1289 | position = RREG32(AVIVO_D1CRTC_STATUS_POSITION); |
||
1290 | ret |= DRM_SCANOUTPOS_VALID; |
||
1291 | } |
||
1292 | if (crtc == 1) { |
||
1293 | vbl = RREG32(AVIVO_D2CRTC_V_BLANK_START_END); |
||
1294 | position = RREG32(AVIVO_D2CRTC_STATUS_POSITION); |
||
1295 | ret |= DRM_SCANOUTPOS_VALID; |
||
1296 | } |
||
1297 | } else { |
||
1298 | /* Pre-AVIVO: Different encoding of scanout pos and vblank interval. */ |
||
1299 | if (crtc == 0) { |
||
1300 | /* Assume vbl_end == 0, get vbl_start from |
||
1301 | * upper 16 bits. |
||
1302 | */ |
||
1303 | vbl = (RREG32(RADEON_CRTC_V_TOTAL_DISP) & |
||
1304 | RADEON_CRTC_V_DISP) >> RADEON_CRTC_V_DISP_SHIFT; |
||
1305 | /* Only retrieve vpos from upper 16 bits, set hpos == 0. */ |
||
1306 | position = (RREG32(RADEON_CRTC_VLINE_CRNT_VLINE) >> 16) & RADEON_CRTC_V_TOTAL; |
||
1307 | stat_crtc = RREG32(RADEON_CRTC_STATUS); |
||
1308 | if (!(stat_crtc & 1)) |
||
1309 | in_vbl = false; |
||
1310 | |||
1311 | ret |= DRM_SCANOUTPOS_VALID; |
||
1312 | } |
||
1313 | if (crtc == 1) { |
||
1314 | vbl = (RREG32(RADEON_CRTC2_V_TOTAL_DISP) & |
||
1315 | RADEON_CRTC_V_DISP) >> RADEON_CRTC_V_DISP_SHIFT; |
||
1316 | position = (RREG32(RADEON_CRTC2_VLINE_CRNT_VLINE) >> 16) & RADEON_CRTC_V_TOTAL; |
||
1317 | stat_crtc = RREG32(RADEON_CRTC2_STATUS); |
||
1318 | if (!(stat_crtc & 1)) |
||
1319 | in_vbl = false; |
||
1320 | |||
1321 | ret |= DRM_SCANOUTPOS_VALID; |
||
1322 | } |
||
1323 | } |
||
1324 | |||
1325 | /* Decode into vertical and horizontal scanout position. */ |
||
1326 | *vpos = position & 0x1fff; |
||
1327 | *hpos = (position >> 16) & 0x1fff; |
||
1328 | |||
1329 | /* Valid vblank area boundaries from gpu retrieved? */ |
||
1330 | if (vbl > 0) { |
||
1331 | /* Yes: Decode. */ |
||
1332 | ret |= DRM_SCANOUTPOS_ACCURATE; |
||
1333 | vbl_start = vbl & 0x1fff; |
||
1334 | vbl_end = (vbl >> 16) & 0x1fff; |
||
1335 | } |
||
1336 | else { |
||
1337 | /* No: Fake something reasonable which gives at least ok results. */ |
||
1338 | vbl_start = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vdisplay; |
||
1339 | vbl_end = 0; |
||
1340 | } |
||
1341 | |||
1342 | /* Test scanout position against vblank region. */ |
||
1343 | if ((*vpos < vbl_start) && (*vpos >= vbl_end)) |
||
1344 | in_vbl = false; |
||
1345 | |||
1346 | /* Check if inside vblank area and apply corrective offsets: |
||
1347 | * vpos will then be >=0 in video scanout area, but negative |
||
1348 | * within vblank area, counting down the number of lines until |
||
1349 | * start of scanout. |
||
1350 | */ |
||
1351 | |||
1352 | /* Inside "upper part" of vblank area? Apply corrective offset if so: */ |
||
1353 | if (in_vbl && (*vpos >= vbl_start)) { |
||
1354 | vtotal = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vtotal; |
||
1355 | *vpos = *vpos - vtotal; |
||
1356 | } |
||
1357 | |||
1358 | /* Correct for shifted end of vbl at vbl_end. */ |
||
1359 | *vpos = *vpos - vbl_end; |
||
1360 | |||
1361 | /* In vblank? */ |
||
1362 | if (in_vbl) |
||
1363 | ret |= DRM_SCANOUTPOS_INVBL; |
||
1364 | |||
1365 | return ret; |
||
1366 | }>>>>>>>>>>>>>>>>>>>>>=>>>=>>>><>><>><>>>><>><>><>><>><>><>>><>><>><>>><>><>><>>><>><>><>> |