Commit | Line | Data |
---|---|---|
771fe6b9 JG |
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 <drm/drmP.h> | |
27 | #include <drm/drm_crtc_helper.h> | |
28 | #include <drm/radeon_drm.h> | |
29 | #include "radeon_fixed.h" | |
30 | #include "radeon.h" | |
31 | #include "atom.h" | |
32 | #include "atom-bits.h" | |
33 | ||
c93bb85b JG |
34 | static void atombios_overscan_setup(struct drm_crtc *crtc, |
35 | struct drm_display_mode *mode, | |
36 | struct drm_display_mode *adjusted_mode) | |
37 | { | |
38 | struct drm_device *dev = crtc->dev; | |
39 | struct radeon_device *rdev = dev->dev_private; | |
40 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
41 | SET_CRTC_OVERSCAN_PS_ALLOCATION args; | |
42 | int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_OverScan); | |
43 | int a1, a2; | |
44 | ||
45 | memset(&args, 0, sizeof(args)); | |
46 | ||
47 | args.usOverscanRight = 0; | |
48 | args.usOverscanLeft = 0; | |
49 | args.usOverscanBottom = 0; | |
50 | args.usOverscanTop = 0; | |
51 | args.ucCRTC = radeon_crtc->crtc_id; | |
52 | ||
53 | switch (radeon_crtc->rmx_type) { | |
54 | case RMX_CENTER: | |
55 | args.usOverscanTop = (adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2; | |
56 | args.usOverscanBottom = (adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2; | |
57 | args.usOverscanLeft = (adjusted_mode->crtc_hdisplay - mode->crtc_hdisplay) / 2; | |
58 | args.usOverscanRight = (adjusted_mode->crtc_hdisplay - mode->crtc_hdisplay) / 2; | |
59 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
60 | break; | |
61 | case RMX_ASPECT: | |
62 | a1 = mode->crtc_vdisplay * adjusted_mode->crtc_hdisplay; | |
63 | a2 = adjusted_mode->crtc_vdisplay * mode->crtc_hdisplay; | |
64 | ||
65 | if (a1 > a2) { | |
66 | args.usOverscanLeft = (adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2; | |
67 | args.usOverscanRight = (adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2; | |
68 | } else if (a2 > a1) { | |
69 | args.usOverscanLeft = (adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2; | |
70 | args.usOverscanRight = (adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2; | |
71 | } | |
72 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
73 | break; | |
74 | case RMX_FULL: | |
75 | default: | |
76 | args.usOverscanRight = 0; | |
77 | args.usOverscanLeft = 0; | |
78 | args.usOverscanBottom = 0; | |
79 | args.usOverscanTop = 0; | |
80 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
81 | break; | |
82 | } | |
83 | } | |
84 | ||
85 | static void atombios_scaler_setup(struct drm_crtc *crtc) | |
86 | { | |
87 | struct drm_device *dev = crtc->dev; | |
88 | struct radeon_device *rdev = dev->dev_private; | |
89 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
90 | ENABLE_SCALER_PS_ALLOCATION args; | |
91 | int index = GetIndexIntoMasterTable(COMMAND, EnableScaler); | |
4ce001ab | 92 | |
c93bb85b JG |
93 | /* fixme - fill in enc_priv for atom dac */ |
94 | enum radeon_tv_std tv_std = TV_STD_NTSC; | |
4ce001ab DA |
95 | bool is_tv = false, is_cv = false; |
96 | struct drm_encoder *encoder; | |
c93bb85b JG |
97 | |
98 | if (!ASIC_IS_AVIVO(rdev) && radeon_crtc->crtc_id) | |
99 | return; | |
100 | ||
4ce001ab DA |
101 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
102 | /* find tv std */ | |
103 | if (encoder->crtc == crtc) { | |
104 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); | |
105 | if (radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT) { | |
106 | struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv; | |
107 | tv_std = tv_dac->tv_std; | |
108 | is_tv = true; | |
109 | } | |
110 | } | |
111 | } | |
112 | ||
c93bb85b JG |
113 | memset(&args, 0, sizeof(args)); |
114 | ||
115 | args.ucScaler = radeon_crtc->crtc_id; | |
116 | ||
4ce001ab | 117 | if (is_tv) { |
c93bb85b JG |
118 | switch (tv_std) { |
119 | case TV_STD_NTSC: | |
120 | default: | |
121 | args.ucTVStandard = ATOM_TV_NTSC; | |
122 | break; | |
123 | case TV_STD_PAL: | |
124 | args.ucTVStandard = ATOM_TV_PAL; | |
125 | break; | |
126 | case TV_STD_PAL_M: | |
127 | args.ucTVStandard = ATOM_TV_PALM; | |
128 | break; | |
129 | case TV_STD_PAL_60: | |
130 | args.ucTVStandard = ATOM_TV_PAL60; | |
131 | break; | |
132 | case TV_STD_NTSC_J: | |
133 | args.ucTVStandard = ATOM_TV_NTSCJ; | |
134 | break; | |
135 | case TV_STD_SCART_PAL: | |
136 | args.ucTVStandard = ATOM_TV_PAL; /* ??? */ | |
137 | break; | |
138 | case TV_STD_SECAM: | |
139 | args.ucTVStandard = ATOM_TV_SECAM; | |
140 | break; | |
141 | case TV_STD_PAL_CN: | |
142 | args.ucTVStandard = ATOM_TV_PALCN; | |
143 | break; | |
144 | } | |
145 | args.ucEnable = SCALER_ENABLE_MULTITAP_MODE; | |
4ce001ab | 146 | } else if (is_cv) { |
c93bb85b JG |
147 | args.ucTVStandard = ATOM_TV_CV; |
148 | args.ucEnable = SCALER_ENABLE_MULTITAP_MODE; | |
149 | } else { | |
150 | switch (radeon_crtc->rmx_type) { | |
151 | case RMX_FULL: | |
152 | args.ucEnable = ATOM_SCALER_EXPANSION; | |
153 | break; | |
154 | case RMX_CENTER: | |
155 | args.ucEnable = ATOM_SCALER_CENTER; | |
156 | break; | |
157 | case RMX_ASPECT: | |
158 | args.ucEnable = ATOM_SCALER_EXPANSION; | |
159 | break; | |
160 | default: | |
161 | if (ASIC_IS_AVIVO(rdev)) | |
162 | args.ucEnable = ATOM_SCALER_DISABLE; | |
163 | else | |
164 | args.ucEnable = ATOM_SCALER_CENTER; | |
165 | break; | |
166 | } | |
167 | } | |
168 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
4ce001ab DA |
169 | if ((is_tv || is_cv) |
170 | && rdev->family >= CHIP_RV515 && rdev->family <= CHIP_R580) { | |
171 | atom_rv515_force_tv_scaler(rdev, radeon_crtc); | |
c93bb85b JG |
172 | } |
173 | } | |
174 | ||
771fe6b9 JG |
175 | static void atombios_lock_crtc(struct drm_crtc *crtc, int lock) |
176 | { | |
177 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
178 | struct drm_device *dev = crtc->dev; | |
179 | struct radeon_device *rdev = dev->dev_private; | |
180 | int index = | |
181 | GetIndexIntoMasterTable(COMMAND, UpdateCRTC_DoubleBufferRegisters); | |
182 | ENABLE_CRTC_PS_ALLOCATION args; | |
183 | ||
184 | memset(&args, 0, sizeof(args)); | |
185 | ||
186 | args.ucCRTC = radeon_crtc->crtc_id; | |
187 | args.ucEnable = lock; | |
188 | ||
189 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
190 | } | |
191 | ||
192 | static void atombios_enable_crtc(struct drm_crtc *crtc, int state) | |
193 | { | |
194 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
195 | struct drm_device *dev = crtc->dev; | |
196 | struct radeon_device *rdev = dev->dev_private; | |
197 | int index = GetIndexIntoMasterTable(COMMAND, EnableCRTC); | |
198 | ENABLE_CRTC_PS_ALLOCATION args; | |
199 | ||
200 | memset(&args, 0, sizeof(args)); | |
201 | ||
202 | args.ucCRTC = radeon_crtc->crtc_id; | |
203 | args.ucEnable = state; | |
204 | ||
205 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
206 | } | |
207 | ||
208 | static void atombios_enable_crtc_memreq(struct drm_crtc *crtc, int state) | |
209 | { | |
210 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
211 | struct drm_device *dev = crtc->dev; | |
212 | struct radeon_device *rdev = dev->dev_private; | |
213 | int index = GetIndexIntoMasterTable(COMMAND, EnableCRTCMemReq); | |
214 | ENABLE_CRTC_PS_ALLOCATION args; | |
215 | ||
216 | memset(&args, 0, sizeof(args)); | |
217 | ||
218 | args.ucCRTC = radeon_crtc->crtc_id; | |
219 | args.ucEnable = state; | |
220 | ||
221 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
222 | } | |
223 | ||
224 | static void atombios_blank_crtc(struct drm_crtc *crtc, int state) | |
225 | { | |
226 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
227 | struct drm_device *dev = crtc->dev; | |
228 | struct radeon_device *rdev = dev->dev_private; | |
229 | int index = GetIndexIntoMasterTable(COMMAND, BlankCRTC); | |
230 | BLANK_CRTC_PS_ALLOCATION args; | |
231 | ||
232 | memset(&args, 0, sizeof(args)); | |
233 | ||
234 | args.ucCRTC = radeon_crtc->crtc_id; | |
235 | args.ucBlanking = state; | |
236 | ||
237 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
238 | } | |
239 | ||
240 | void atombios_crtc_dpms(struct drm_crtc *crtc, int mode) | |
241 | { | |
242 | struct drm_device *dev = crtc->dev; | |
243 | struct radeon_device *rdev = dev->dev_private; | |
500b7587 | 244 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
771fe6b9 JG |
245 | |
246 | switch (mode) { | |
247 | case DRM_MODE_DPMS_ON: | |
37b4390e | 248 | atombios_enable_crtc(crtc, ATOM_ENABLE); |
771fe6b9 | 249 | if (ASIC_IS_DCE3(rdev)) |
37b4390e AD |
250 | atombios_enable_crtc_memreq(crtc, ATOM_ENABLE); |
251 | atombios_blank_crtc(crtc, ATOM_DISABLE); | |
45f9a39b | 252 | drm_vblank_post_modeset(dev, radeon_crtc->crtc_id); |
500b7587 | 253 | radeon_crtc_load_lut(crtc); |
771fe6b9 JG |
254 | break; |
255 | case DRM_MODE_DPMS_STANDBY: | |
256 | case DRM_MODE_DPMS_SUSPEND: | |
257 | case DRM_MODE_DPMS_OFF: | |
45f9a39b | 258 | drm_vblank_pre_modeset(dev, radeon_crtc->crtc_id); |
37b4390e | 259 | atombios_blank_crtc(crtc, ATOM_ENABLE); |
771fe6b9 | 260 | if (ASIC_IS_DCE3(rdev)) |
37b4390e AD |
261 | atombios_enable_crtc_memreq(crtc, ATOM_DISABLE); |
262 | atombios_enable_crtc(crtc, ATOM_DISABLE); | |
771fe6b9 JG |
263 | break; |
264 | } | |
771fe6b9 JG |
265 | } |
266 | ||
267 | static void | |
268 | atombios_set_crtc_dtd_timing(struct drm_crtc *crtc, | |
5a9bcacc | 269 | struct drm_display_mode *mode) |
771fe6b9 | 270 | { |
5a9bcacc | 271 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
771fe6b9 JG |
272 | struct drm_device *dev = crtc->dev; |
273 | struct radeon_device *rdev = dev->dev_private; | |
5a9bcacc | 274 | SET_CRTC_USING_DTD_TIMING_PARAMETERS args; |
771fe6b9 | 275 | int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_UsingDTDTiming); |
5a9bcacc | 276 | u16 misc = 0; |
771fe6b9 | 277 | |
5a9bcacc AD |
278 | memset(&args, 0, sizeof(args)); |
279 | args.usH_Size = cpu_to_le16(mode->crtc_hdisplay); | |
280 | args.usH_Blanking_Time = | |
281 | cpu_to_le16(mode->crtc_hblank_end - mode->crtc_hdisplay); | |
282 | args.usV_Size = cpu_to_le16(mode->crtc_vdisplay); | |
283 | args.usV_Blanking_Time = | |
284 | cpu_to_le16(mode->crtc_vblank_end - mode->crtc_vdisplay); | |
285 | args.usH_SyncOffset = | |
286 | cpu_to_le16(mode->crtc_hsync_start - mode->crtc_hdisplay); | |
287 | args.usH_SyncWidth = | |
288 | cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start); | |
289 | args.usV_SyncOffset = | |
290 | cpu_to_le16(mode->crtc_vsync_start - mode->crtc_vdisplay); | |
291 | args.usV_SyncWidth = | |
292 | cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start); | |
293 | /*args.ucH_Border = mode->hborder;*/ | |
294 | /*args.ucV_Border = mode->vborder;*/ | |
295 | ||
296 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) | |
297 | misc |= ATOM_VSYNC_POLARITY; | |
298 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) | |
299 | misc |= ATOM_HSYNC_POLARITY; | |
300 | if (mode->flags & DRM_MODE_FLAG_CSYNC) | |
301 | misc |= ATOM_COMPOSITESYNC; | |
302 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) | |
303 | misc |= ATOM_INTERLACE; | |
304 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) | |
305 | misc |= ATOM_DOUBLE_CLOCK_MODE; | |
306 | ||
307 | args.susModeMiscInfo.usAccess = cpu_to_le16(misc); | |
308 | args.ucCRTC = radeon_crtc->crtc_id; | |
771fe6b9 | 309 | |
5a9bcacc | 310 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
771fe6b9 JG |
311 | } |
312 | ||
5a9bcacc AD |
313 | static void atombios_crtc_set_timing(struct drm_crtc *crtc, |
314 | struct drm_display_mode *mode) | |
771fe6b9 | 315 | { |
5a9bcacc | 316 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
771fe6b9 JG |
317 | struct drm_device *dev = crtc->dev; |
318 | struct radeon_device *rdev = dev->dev_private; | |
5a9bcacc | 319 | SET_CRTC_TIMING_PARAMETERS_PS_ALLOCATION args; |
771fe6b9 | 320 | int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_Timing); |
5a9bcacc | 321 | u16 misc = 0; |
771fe6b9 | 322 | |
5a9bcacc AD |
323 | memset(&args, 0, sizeof(args)); |
324 | args.usH_Total = cpu_to_le16(mode->crtc_htotal); | |
325 | args.usH_Disp = cpu_to_le16(mode->crtc_hdisplay); | |
326 | args.usH_SyncStart = cpu_to_le16(mode->crtc_hsync_start); | |
327 | args.usH_SyncWidth = | |
328 | cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start); | |
329 | args.usV_Total = cpu_to_le16(mode->crtc_vtotal); | |
330 | args.usV_Disp = cpu_to_le16(mode->crtc_vdisplay); | |
331 | args.usV_SyncStart = cpu_to_le16(mode->crtc_vsync_start); | |
332 | args.usV_SyncWidth = | |
333 | cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start); | |
334 | ||
335 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) | |
336 | misc |= ATOM_VSYNC_POLARITY; | |
337 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) | |
338 | misc |= ATOM_HSYNC_POLARITY; | |
339 | if (mode->flags & DRM_MODE_FLAG_CSYNC) | |
340 | misc |= ATOM_COMPOSITESYNC; | |
341 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) | |
342 | misc |= ATOM_INTERLACE; | |
343 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) | |
344 | misc |= ATOM_DOUBLE_CLOCK_MODE; | |
345 | ||
346 | args.susModeMiscInfo.usAccess = cpu_to_le16(misc); | |
347 | args.ucCRTC = radeon_crtc->crtc_id; | |
771fe6b9 | 348 | |
5a9bcacc | 349 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
771fe6b9 JG |
350 | } |
351 | ||
b792210e AD |
352 | static void atombios_disable_ss(struct drm_crtc *crtc) |
353 | { | |
354 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
355 | struct drm_device *dev = crtc->dev; | |
356 | struct radeon_device *rdev = dev->dev_private; | |
357 | u32 ss_cntl; | |
358 | ||
359 | if (ASIC_IS_DCE4(rdev)) { | |
360 | switch (radeon_crtc->pll_id) { | |
361 | case ATOM_PPLL1: | |
362 | ss_cntl = RREG32(EVERGREEN_P1PLL_SS_CNTL); | |
363 | ss_cntl &= ~EVERGREEN_PxPLL_SS_EN; | |
364 | WREG32(EVERGREEN_P1PLL_SS_CNTL, ss_cntl); | |
365 | break; | |
366 | case ATOM_PPLL2: | |
367 | ss_cntl = RREG32(EVERGREEN_P2PLL_SS_CNTL); | |
368 | ss_cntl &= ~EVERGREEN_PxPLL_SS_EN; | |
369 | WREG32(EVERGREEN_P2PLL_SS_CNTL, ss_cntl); | |
370 | break; | |
371 | case ATOM_DCPLL: | |
372 | case ATOM_PPLL_INVALID: | |
373 | return; | |
374 | } | |
375 | } else if (ASIC_IS_AVIVO(rdev)) { | |
376 | switch (radeon_crtc->pll_id) { | |
377 | case ATOM_PPLL1: | |
378 | ss_cntl = RREG32(AVIVO_P1PLL_INT_SS_CNTL); | |
379 | ss_cntl &= ~1; | |
380 | WREG32(AVIVO_P1PLL_INT_SS_CNTL, ss_cntl); | |
381 | break; | |
382 | case ATOM_PPLL2: | |
383 | ss_cntl = RREG32(AVIVO_P2PLL_INT_SS_CNTL); | |
384 | ss_cntl &= ~1; | |
385 | WREG32(AVIVO_P2PLL_INT_SS_CNTL, ss_cntl); | |
386 | break; | |
387 | case ATOM_DCPLL: | |
388 | case ATOM_PPLL_INVALID: | |
389 | return; | |
390 | } | |
391 | } | |
392 | } | |
393 | ||
394 | ||
26b9fc3a AD |
395 | union atom_enable_ss { |
396 | ENABLE_LVDS_SS_PARAMETERS legacy; | |
397 | ENABLE_SPREAD_SPECTRUM_ON_PPLL_PS_ALLOCATION v1; | |
398 | }; | |
399 | ||
b792210e | 400 | static void atombios_enable_ss(struct drm_crtc *crtc) |
ebbe1cb9 AD |
401 | { |
402 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
403 | struct drm_device *dev = crtc->dev; | |
404 | struct radeon_device *rdev = dev->dev_private; | |
405 | struct drm_encoder *encoder = NULL; | |
406 | struct radeon_encoder *radeon_encoder = NULL; | |
407 | struct radeon_encoder_atom_dig *dig = NULL; | |
408 | int index = GetIndexIntoMasterTable(COMMAND, EnableSpreadSpectrumOnPPLL); | |
26b9fc3a | 409 | union atom_enable_ss args; |
ebbe1cb9 AD |
410 | uint16_t percentage = 0; |
411 | uint8_t type = 0, step = 0, delay = 0, range = 0; | |
412 | ||
bcc1c2a1 AD |
413 | /* XXX add ss support for DCE4 */ |
414 | if (ASIC_IS_DCE4(rdev)) | |
415 | return; | |
416 | ||
ebbe1cb9 AD |
417 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
418 | if (encoder->crtc == crtc) { | |
419 | radeon_encoder = to_radeon_encoder(encoder); | |
ebbe1cb9 | 420 | /* only enable spread spectrum on LVDS */ |
d11aa88b AD |
421 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { |
422 | dig = radeon_encoder->enc_priv; | |
423 | if (dig && dig->ss) { | |
424 | percentage = dig->ss->percentage; | |
425 | type = dig->ss->type; | |
426 | step = dig->ss->step; | |
427 | delay = dig->ss->delay; | |
428 | range = dig->ss->range; | |
b792210e | 429 | } else |
d11aa88b | 430 | return; |
b792210e | 431 | } else |
ebbe1cb9 AD |
432 | return; |
433 | break; | |
434 | } | |
435 | } | |
436 | ||
437 | if (!radeon_encoder) | |
438 | return; | |
439 | ||
26b9fc3a | 440 | memset(&args, 0, sizeof(args)); |
ebbe1cb9 | 441 | if (ASIC_IS_AVIVO(rdev)) { |
26b9fc3a AD |
442 | args.v1.usSpreadSpectrumPercentage = cpu_to_le16(percentage); |
443 | args.v1.ucSpreadSpectrumType = type; | |
444 | args.v1.ucSpreadSpectrumStep = step; | |
445 | args.v1.ucSpreadSpectrumDelay = delay; | |
446 | args.v1.ucSpreadSpectrumRange = range; | |
447 | args.v1.ucPpll = radeon_crtc->crtc_id ? ATOM_PPLL2 : ATOM_PPLL1; | |
b792210e | 448 | args.v1.ucEnable = ATOM_ENABLE; |
ebbe1cb9 | 449 | } else { |
26b9fc3a AD |
450 | args.legacy.usSpreadSpectrumPercentage = cpu_to_le16(percentage); |
451 | args.legacy.ucSpreadSpectrumType = type; | |
452 | args.legacy.ucSpreadSpectrumStepSize_Delay = (step & 3) << 2; | |
453 | args.legacy.ucSpreadSpectrumStepSize_Delay |= (delay & 7) << 4; | |
b792210e | 454 | args.legacy.ucEnable = ATOM_ENABLE; |
ebbe1cb9 | 455 | } |
26b9fc3a | 456 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
ebbe1cb9 AD |
457 | } |
458 | ||
4eaeca33 AD |
459 | union adjust_pixel_clock { |
460 | ADJUST_DISPLAY_PLL_PS_ALLOCATION v1; | |
bcc1c2a1 | 461 | ADJUST_DISPLAY_PLL_PS_ALLOCATION_V3 v3; |
4eaeca33 AD |
462 | }; |
463 | ||
464 | static u32 atombios_adjust_pll(struct drm_crtc *crtc, | |
465 | struct drm_display_mode *mode, | |
466 | struct radeon_pll *pll) | |
771fe6b9 | 467 | { |
771fe6b9 JG |
468 | struct drm_device *dev = crtc->dev; |
469 | struct radeon_device *rdev = dev->dev_private; | |
470 | struct drm_encoder *encoder = NULL; | |
471 | struct radeon_encoder *radeon_encoder = NULL; | |
4eaeca33 | 472 | u32 adjusted_clock = mode->clock; |
bcc1c2a1 | 473 | int encoder_mode = 0; |
fc10332b | 474 | |
4eaeca33 AD |
475 | /* reset the pll flags */ |
476 | pll->flags = 0; | |
771fe6b9 | 477 | |
7c27f87d AD |
478 | /* select the PLL algo */ |
479 | if (ASIC_IS_AVIVO(rdev)) { | |
383be5d1 AD |
480 | if (radeon_new_pll == 0) |
481 | pll->algo = PLL_ALGO_LEGACY; | |
482 | else | |
483 | pll->algo = PLL_ALGO_NEW; | |
484 | } else { | |
485 | if (radeon_new_pll == 1) | |
486 | pll->algo = PLL_ALGO_NEW; | |
7c27f87d AD |
487 | else |
488 | pll->algo = PLL_ALGO_LEGACY; | |
383be5d1 | 489 | } |
7c27f87d | 490 | |
771fe6b9 | 491 | if (ASIC_IS_AVIVO(rdev)) { |
eb1300bc AD |
492 | if ((rdev->family == CHIP_RS600) || |
493 | (rdev->family == CHIP_RS690) || | |
494 | (rdev->family == CHIP_RS740)) | |
fc10332b AD |
495 | pll->flags |= (RADEON_PLL_USE_FRAC_FB_DIV | |
496 | RADEON_PLL_PREFER_CLOSEST_LOWER); | |
eb1300bc | 497 | |
771fe6b9 | 498 | if (ASIC_IS_DCE32(rdev) && mode->clock > 200000) /* range limits??? */ |
fc10332b | 499 | pll->flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; |
771fe6b9 | 500 | else |
fc10332b | 501 | pll->flags |= RADEON_PLL_PREFER_LOW_REF_DIV; |
771fe6b9 | 502 | } else { |
fc10332b | 503 | pll->flags |= RADEON_PLL_LEGACY; |
771fe6b9 JG |
504 | |
505 | if (mode->clock > 200000) /* range limits??? */ | |
fc10332b | 506 | pll->flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; |
771fe6b9 | 507 | else |
fc10332b | 508 | pll->flags |= RADEON_PLL_PREFER_LOW_REF_DIV; |
771fe6b9 JG |
509 | |
510 | } | |
511 | ||
512 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | |
513 | if (encoder->crtc == crtc) { | |
4eaeca33 | 514 | radeon_encoder = to_radeon_encoder(encoder); |
bcc1c2a1 | 515 | encoder_mode = atombios_get_encoder_mode(encoder); |
4eaeca33 AD |
516 | if (ASIC_IS_AVIVO(rdev)) { |
517 | /* DVO wants 2x pixel clock if the DVO chip is in 12 bit mode */ | |
518 | if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1) | |
519 | adjusted_clock = mode->clock * 2; | |
520 | } else { | |
521 | if (encoder->encoder_type != DRM_MODE_ENCODER_DAC) | |
fc10332b | 522 | pll->flags |= RADEON_PLL_NO_ODD_POST_DIV; |
4eaeca33 | 523 | if (encoder->encoder_type == DRM_MODE_ENCODER_LVDS) |
fc10332b | 524 | pll->flags |= RADEON_PLL_USE_REF_DIV; |
771fe6b9 | 525 | } |
3ce0a23d | 526 | break; |
771fe6b9 JG |
527 | } |
528 | } | |
529 | ||
2606c886 AD |
530 | /* DCE3+ has an AdjustDisplayPll that will adjust the pixel clock |
531 | * accordingly based on the encoder/transmitter to work around | |
532 | * special hw requirements. | |
533 | */ | |
534 | if (ASIC_IS_DCE3(rdev)) { | |
4eaeca33 | 535 | union adjust_pixel_clock args; |
4eaeca33 AD |
536 | u8 frev, crev; |
537 | int index; | |
2606c886 | 538 | |
2606c886 | 539 | index = GetIndexIntoMasterTable(COMMAND, AdjustDisplayPll); |
a084e6ee AD |
540 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
541 | &crev)) | |
542 | return adjusted_clock; | |
4eaeca33 AD |
543 | |
544 | memset(&args, 0, sizeof(args)); | |
545 | ||
546 | switch (frev) { | |
547 | case 1: | |
548 | switch (crev) { | |
549 | case 1: | |
550 | case 2: | |
551 | args.v1.usPixelClock = cpu_to_le16(mode->clock / 10); | |
552 | args.v1.ucTransmitterID = radeon_encoder->encoder_id; | |
bcc1c2a1 | 553 | args.v1.ucEncodeMode = encoder_mode; |
4eaeca33 AD |
554 | |
555 | atom_execute_table(rdev->mode_info.atom_context, | |
556 | index, (uint32_t *)&args); | |
557 | adjusted_clock = le16_to_cpu(args.v1.usPixelClock) * 10; | |
558 | break; | |
bcc1c2a1 AD |
559 | case 3: |
560 | args.v3.sInput.usPixelClock = cpu_to_le16(mode->clock / 10); | |
561 | args.v3.sInput.ucTransmitterID = radeon_encoder->encoder_id; | |
562 | args.v3.sInput.ucEncodeMode = encoder_mode; | |
563 | args.v3.sInput.ucDispPllConfig = 0; | |
564 | if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { | |
565 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; | |
566 | ||
567 | if (encoder_mode == ATOM_ENCODER_MODE_DP) | |
568 | args.v3.sInput.ucDispPllConfig |= | |
569 | DISPPLL_CONFIG_COHERENT_MODE; | |
570 | else { | |
571 | if (dig->coherent_mode) | |
572 | args.v3.sInput.ucDispPllConfig |= | |
573 | DISPPLL_CONFIG_COHERENT_MODE; | |
574 | if (mode->clock > 165000) | |
575 | args.v3.sInput.ucDispPllConfig |= | |
576 | DISPPLL_CONFIG_DUAL_LINK; | |
577 | } | |
578 | } else if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { | |
579 | /* may want to enable SS on DP/eDP eventually */ | |
9f998ad7 AD |
580 | /*args.v3.sInput.ucDispPllConfig |= |
581 | DISPPLL_CONFIG_SS_ENABLE;*/ | |
582 | if (encoder_mode == ATOM_ENCODER_MODE_DP) | |
bcc1c2a1 | 583 | args.v3.sInput.ucDispPllConfig |= |
9f998ad7 AD |
584 | DISPPLL_CONFIG_COHERENT_MODE; |
585 | else { | |
586 | if (mode->clock > 165000) | |
587 | args.v3.sInput.ucDispPllConfig |= | |
588 | DISPPLL_CONFIG_DUAL_LINK; | |
589 | } | |
bcc1c2a1 AD |
590 | } |
591 | atom_execute_table(rdev->mode_info.atom_context, | |
592 | index, (uint32_t *)&args); | |
593 | adjusted_clock = le32_to_cpu(args.v3.sOutput.ulDispPllFreq) * 10; | |
594 | if (args.v3.sOutput.ucRefDiv) { | |
595 | pll->flags |= RADEON_PLL_USE_REF_DIV; | |
596 | pll->reference_div = args.v3.sOutput.ucRefDiv; | |
597 | } | |
598 | if (args.v3.sOutput.ucPostDiv) { | |
599 | pll->flags |= RADEON_PLL_USE_POST_DIV; | |
600 | pll->post_div = args.v3.sOutput.ucPostDiv; | |
601 | } | |
602 | break; | |
4eaeca33 AD |
603 | default: |
604 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
605 | return adjusted_clock; | |
606 | } | |
607 | break; | |
608 | default: | |
609 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
610 | return adjusted_clock; | |
611 | } | |
d56ef9c8 | 612 | } |
4eaeca33 AD |
613 | return adjusted_clock; |
614 | } | |
615 | ||
616 | union set_pixel_clock { | |
617 | SET_PIXEL_CLOCK_PS_ALLOCATION base; | |
618 | PIXEL_CLOCK_PARAMETERS v1; | |
619 | PIXEL_CLOCK_PARAMETERS_V2 v2; | |
620 | PIXEL_CLOCK_PARAMETERS_V3 v3; | |
bcc1c2a1 | 621 | PIXEL_CLOCK_PARAMETERS_V5 v5; |
4eaeca33 AD |
622 | }; |
623 | ||
bcc1c2a1 AD |
624 | static void atombios_crtc_set_dcpll(struct drm_crtc *crtc) |
625 | { | |
626 | struct drm_device *dev = crtc->dev; | |
627 | struct radeon_device *rdev = dev->dev_private; | |
628 | u8 frev, crev; | |
629 | int index; | |
630 | union set_pixel_clock args; | |
631 | ||
632 | memset(&args, 0, sizeof(args)); | |
633 | ||
634 | index = GetIndexIntoMasterTable(COMMAND, SetPixelClock); | |
a084e6ee AD |
635 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
636 | &crev)) | |
637 | return; | |
bcc1c2a1 AD |
638 | |
639 | switch (frev) { | |
640 | case 1: | |
641 | switch (crev) { | |
642 | case 5: | |
643 | /* if the default dcpll clock is specified, | |
644 | * SetPixelClock provides the dividers | |
645 | */ | |
646 | args.v5.ucCRTC = ATOM_CRTC_INVALID; | |
647 | args.v5.usPixelClock = rdev->clock.default_dispclk; | |
648 | args.v5.ucPpll = ATOM_DCPLL; | |
649 | break; | |
650 | default: | |
651 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
652 | return; | |
653 | } | |
654 | break; | |
655 | default: | |
656 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
657 | return; | |
658 | } | |
659 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
660 | } | |
661 | ||
662 | static void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) | |
4eaeca33 AD |
663 | { |
664 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
665 | struct drm_device *dev = crtc->dev; | |
666 | struct radeon_device *rdev = dev->dev_private; | |
667 | struct drm_encoder *encoder = NULL; | |
668 | struct radeon_encoder *radeon_encoder = NULL; | |
669 | u8 frev, crev; | |
670 | int index; | |
671 | union set_pixel_clock args; | |
672 | u32 pll_clock = mode->clock; | |
673 | u32 ref_div = 0, fb_div = 0, frac_fb_div = 0, post_div = 0; | |
674 | struct radeon_pll *pll; | |
675 | u32 adjusted_clock; | |
bcc1c2a1 | 676 | int encoder_mode = 0; |
4eaeca33 AD |
677 | |
678 | memset(&args, 0, sizeof(args)); | |
679 | ||
680 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | |
681 | if (encoder->crtc == crtc) { | |
682 | radeon_encoder = to_radeon_encoder(encoder); | |
bcc1c2a1 | 683 | encoder_mode = atombios_get_encoder_mode(encoder); |
4eaeca33 AD |
684 | break; |
685 | } | |
686 | } | |
687 | ||
688 | if (!radeon_encoder) | |
689 | return; | |
690 | ||
bcc1c2a1 AD |
691 | switch (radeon_crtc->pll_id) { |
692 | case ATOM_PPLL1: | |
4eaeca33 | 693 | pll = &rdev->clock.p1pll; |
bcc1c2a1 AD |
694 | break; |
695 | case ATOM_PPLL2: | |
4eaeca33 | 696 | pll = &rdev->clock.p2pll; |
bcc1c2a1 AD |
697 | break; |
698 | case ATOM_DCPLL: | |
699 | case ATOM_PPLL_INVALID: | |
700 | pll = &rdev->clock.dcpll; | |
701 | break; | |
702 | } | |
4eaeca33 AD |
703 | |
704 | /* adjust pixel clock as needed */ | |
705 | adjusted_clock = atombios_adjust_pll(crtc, mode, pll); | |
2606c886 | 706 | |
7c27f87d AD |
707 | radeon_compute_pll(pll, adjusted_clock, &pll_clock, &fb_div, &frac_fb_div, |
708 | &ref_div, &post_div); | |
771fe6b9 | 709 | |
39deb2d6 | 710 | index = GetIndexIntoMasterTable(COMMAND, SetPixelClock); |
a084e6ee AD |
711 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
712 | &crev)) | |
713 | return; | |
771fe6b9 JG |
714 | |
715 | switch (frev) { | |
716 | case 1: | |
717 | switch (crev) { | |
718 | case 1: | |
4eaeca33 AD |
719 | args.v1.usPixelClock = cpu_to_le16(mode->clock / 10); |
720 | args.v1.usRefDiv = cpu_to_le16(ref_div); | |
721 | args.v1.usFbDiv = cpu_to_le16(fb_div); | |
722 | args.v1.ucFracFbDiv = frac_fb_div; | |
723 | args.v1.ucPostDiv = post_div; | |
bcc1c2a1 | 724 | args.v1.ucPpll = radeon_crtc->pll_id; |
4eaeca33 AD |
725 | args.v1.ucCRTC = radeon_crtc->crtc_id; |
726 | args.v1.ucRefDivSrc = 1; | |
771fe6b9 JG |
727 | break; |
728 | case 2: | |
4eaeca33 AD |
729 | args.v2.usPixelClock = cpu_to_le16(mode->clock / 10); |
730 | args.v2.usRefDiv = cpu_to_le16(ref_div); | |
731 | args.v2.usFbDiv = cpu_to_le16(fb_div); | |
732 | args.v2.ucFracFbDiv = frac_fb_div; | |
733 | args.v2.ucPostDiv = post_div; | |
bcc1c2a1 | 734 | args.v2.ucPpll = radeon_crtc->pll_id; |
4eaeca33 AD |
735 | args.v2.ucCRTC = radeon_crtc->crtc_id; |
736 | args.v2.ucRefDivSrc = 1; | |
771fe6b9 JG |
737 | break; |
738 | case 3: | |
4eaeca33 AD |
739 | args.v3.usPixelClock = cpu_to_le16(mode->clock / 10); |
740 | args.v3.usRefDiv = cpu_to_le16(ref_div); | |
741 | args.v3.usFbDiv = cpu_to_le16(fb_div); | |
742 | args.v3.ucFracFbDiv = frac_fb_div; | |
743 | args.v3.ucPostDiv = post_div; | |
bcc1c2a1 AD |
744 | args.v3.ucPpll = radeon_crtc->pll_id; |
745 | args.v3.ucMiscInfo = (radeon_crtc->pll_id << 2); | |
4eaeca33 | 746 | args.v3.ucTransmitterId = radeon_encoder->encoder_id; |
bcc1c2a1 AD |
747 | args.v3.ucEncoderMode = encoder_mode; |
748 | break; | |
749 | case 5: | |
750 | args.v5.ucCRTC = radeon_crtc->crtc_id; | |
751 | args.v5.usPixelClock = cpu_to_le16(mode->clock / 10); | |
752 | args.v5.ucRefDiv = ref_div; | |
753 | args.v5.usFbDiv = cpu_to_le16(fb_div); | |
754 | args.v5.ulFbDivDecFrac = cpu_to_le32(frac_fb_div * 100000); | |
755 | args.v5.ucPostDiv = post_div; | |
756 | args.v5.ucMiscInfo = 0; /* HDMI depth, etc. */ | |
757 | args.v5.ucTransmitterID = radeon_encoder->encoder_id; | |
758 | args.v5.ucEncoderMode = encoder_mode; | |
759 | args.v5.ucPpll = radeon_crtc->pll_id; | |
771fe6b9 JG |
760 | break; |
761 | default: | |
762 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
763 | return; | |
764 | } | |
765 | break; | |
766 | default: | |
767 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
768 | return; | |
769 | } | |
770 | ||
771fe6b9 JG |
771 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
772 | } | |
773 | ||
bcc1c2a1 AD |
774 | static int evergreen_crtc_set_base(struct drm_crtc *crtc, int x, int y, |
775 | struct drm_framebuffer *old_fb) | |
776 | { | |
777 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
778 | struct drm_device *dev = crtc->dev; | |
779 | struct radeon_device *rdev = dev->dev_private; | |
780 | struct radeon_framebuffer *radeon_fb; | |
781 | struct drm_gem_object *obj; | |
782 | struct radeon_bo *rbo; | |
783 | uint64_t fb_location; | |
784 | uint32_t fb_format, fb_pitch_pixels, tiling_flags; | |
785 | int r; | |
786 | ||
787 | /* no fb bound */ | |
788 | if (!crtc->fb) { | |
789 | DRM_DEBUG("No FB bound\n"); | |
790 | return 0; | |
791 | } | |
792 | ||
793 | radeon_fb = to_radeon_framebuffer(crtc->fb); | |
794 | ||
795 | /* Pin framebuffer & get tilling informations */ | |
796 | obj = radeon_fb->obj; | |
797 | rbo = obj->driver_private; | |
798 | r = radeon_bo_reserve(rbo, false); | |
799 | if (unlikely(r != 0)) | |
800 | return r; | |
801 | r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_location); | |
802 | if (unlikely(r != 0)) { | |
803 | radeon_bo_unreserve(rbo); | |
804 | return -EINVAL; | |
805 | } | |
806 | radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); | |
807 | radeon_bo_unreserve(rbo); | |
808 | ||
809 | switch (crtc->fb->bits_per_pixel) { | |
810 | case 8: | |
811 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_8BPP) | | |
812 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_INDEXED)); | |
813 | break; | |
814 | case 15: | |
815 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | | |
816 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB1555)); | |
817 | break; | |
818 | case 16: | |
819 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | | |
820 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB565)); | |
821 | break; | |
822 | case 24: | |
823 | case 32: | |
824 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_32BPP) | | |
825 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB8888)); | |
826 | break; | |
827 | default: | |
828 | DRM_ERROR("Unsupported screen depth %d\n", | |
829 | crtc->fb->bits_per_pixel); | |
830 | return -EINVAL; | |
831 | } | |
832 | ||
833 | switch (radeon_crtc->crtc_id) { | |
834 | case 0: | |
835 | WREG32(AVIVO_D1VGA_CONTROL, 0); | |
836 | break; | |
837 | case 1: | |
838 | WREG32(AVIVO_D2VGA_CONTROL, 0); | |
839 | break; | |
840 | case 2: | |
841 | WREG32(EVERGREEN_D3VGA_CONTROL, 0); | |
842 | break; | |
843 | case 3: | |
844 | WREG32(EVERGREEN_D4VGA_CONTROL, 0); | |
845 | break; | |
846 | case 4: | |
847 | WREG32(EVERGREEN_D5VGA_CONTROL, 0); | |
848 | break; | |
849 | case 5: | |
850 | WREG32(EVERGREEN_D6VGA_CONTROL, 0); | |
851 | break; | |
852 | default: | |
853 | break; | |
854 | } | |
855 | ||
856 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, | |
857 | upper_32_bits(fb_location)); | |
858 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, | |
859 | upper_32_bits(fb_location)); | |
860 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, | |
861 | (u32)fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); | |
862 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, | |
863 | (u32) fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); | |
864 | WREG32(EVERGREEN_GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format); | |
865 | ||
866 | WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0); | |
867 | WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0); | |
868 | WREG32(EVERGREEN_GRPH_X_START + radeon_crtc->crtc_offset, 0); | |
869 | WREG32(EVERGREEN_GRPH_Y_START + radeon_crtc->crtc_offset, 0); | |
870 | WREG32(EVERGREEN_GRPH_X_END + radeon_crtc->crtc_offset, crtc->fb->width); | |
871 | WREG32(EVERGREEN_GRPH_Y_END + radeon_crtc->crtc_offset, crtc->fb->height); | |
872 | ||
873 | fb_pitch_pixels = crtc->fb->pitch / (crtc->fb->bits_per_pixel / 8); | |
874 | WREG32(EVERGREEN_GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels); | |
875 | WREG32(EVERGREEN_GRPH_ENABLE + radeon_crtc->crtc_offset, 1); | |
876 | ||
877 | WREG32(EVERGREEN_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, | |
878 | crtc->mode.vdisplay); | |
879 | x &= ~3; | |
880 | y &= ~1; | |
881 | WREG32(EVERGREEN_VIEWPORT_START + radeon_crtc->crtc_offset, | |
882 | (x << 16) | y); | |
883 | WREG32(EVERGREEN_VIEWPORT_SIZE + radeon_crtc->crtc_offset, | |
884 | (crtc->mode.hdisplay << 16) | crtc->mode.vdisplay); | |
885 | ||
886 | if (crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) | |
887 | WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, | |
888 | EVERGREEN_INTERLEAVE_EN); | |
889 | else | |
890 | WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, 0); | |
891 | ||
892 | if (old_fb && old_fb != crtc->fb) { | |
893 | radeon_fb = to_radeon_framebuffer(old_fb); | |
894 | rbo = radeon_fb->obj->driver_private; | |
895 | r = radeon_bo_reserve(rbo, false); | |
896 | if (unlikely(r != 0)) | |
897 | return r; | |
898 | radeon_bo_unpin(rbo); | |
899 | radeon_bo_unreserve(rbo); | |
900 | } | |
901 | ||
902 | /* Bytes per pixel may have changed */ | |
903 | radeon_bandwidth_update(rdev); | |
904 | ||
905 | return 0; | |
906 | } | |
907 | ||
54f088a9 AD |
908 | static int avivo_crtc_set_base(struct drm_crtc *crtc, int x, int y, |
909 | struct drm_framebuffer *old_fb) | |
771fe6b9 JG |
910 | { |
911 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
912 | struct drm_device *dev = crtc->dev; | |
913 | struct radeon_device *rdev = dev->dev_private; | |
914 | struct radeon_framebuffer *radeon_fb; | |
915 | struct drm_gem_object *obj; | |
4c788679 | 916 | struct radeon_bo *rbo; |
771fe6b9 | 917 | uint64_t fb_location; |
e024e110 | 918 | uint32_t fb_format, fb_pitch_pixels, tiling_flags; |
4c788679 | 919 | int r; |
771fe6b9 | 920 | |
2de3b484 JG |
921 | /* no fb bound */ |
922 | if (!crtc->fb) { | |
923 | DRM_DEBUG("No FB bound\n"); | |
924 | return 0; | |
925 | } | |
771fe6b9 JG |
926 | |
927 | radeon_fb = to_radeon_framebuffer(crtc->fb); | |
928 | ||
4c788679 | 929 | /* Pin framebuffer & get tilling informations */ |
771fe6b9 | 930 | obj = radeon_fb->obj; |
4c788679 JG |
931 | rbo = obj->driver_private; |
932 | r = radeon_bo_reserve(rbo, false); | |
933 | if (unlikely(r != 0)) | |
934 | return r; | |
935 | r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_location); | |
936 | if (unlikely(r != 0)) { | |
937 | radeon_bo_unreserve(rbo); | |
771fe6b9 JG |
938 | return -EINVAL; |
939 | } | |
4c788679 JG |
940 | radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); |
941 | radeon_bo_unreserve(rbo); | |
771fe6b9 JG |
942 | |
943 | switch (crtc->fb->bits_per_pixel) { | |
41456df2 DA |
944 | case 8: |
945 | fb_format = | |
946 | AVIVO_D1GRPH_CONTROL_DEPTH_8BPP | | |
947 | AVIVO_D1GRPH_CONTROL_8BPP_INDEXED; | |
948 | break; | |
771fe6b9 JG |
949 | case 15: |
950 | fb_format = | |
951 | AVIVO_D1GRPH_CONTROL_DEPTH_16BPP | | |
952 | AVIVO_D1GRPH_CONTROL_16BPP_ARGB1555; | |
953 | break; | |
954 | case 16: | |
955 | fb_format = | |
956 | AVIVO_D1GRPH_CONTROL_DEPTH_16BPP | | |
957 | AVIVO_D1GRPH_CONTROL_16BPP_RGB565; | |
958 | break; | |
959 | case 24: | |
960 | case 32: | |
961 | fb_format = | |
962 | AVIVO_D1GRPH_CONTROL_DEPTH_32BPP | | |
963 | AVIVO_D1GRPH_CONTROL_32BPP_ARGB8888; | |
964 | break; | |
965 | default: | |
966 | DRM_ERROR("Unsupported screen depth %d\n", | |
967 | crtc->fb->bits_per_pixel); | |
968 | return -EINVAL; | |
969 | } | |
970 | ||
cf2f05d3 DA |
971 | if (tiling_flags & RADEON_TILING_MACRO) |
972 | fb_format |= AVIVO_D1GRPH_MACRO_ADDRESS_MODE; | |
973 | ||
e024e110 DA |
974 | if (tiling_flags & RADEON_TILING_MICRO) |
975 | fb_format |= AVIVO_D1GRPH_TILED; | |
976 | ||
771fe6b9 JG |
977 | if (radeon_crtc->crtc_id == 0) |
978 | WREG32(AVIVO_D1VGA_CONTROL, 0); | |
979 | else | |
980 | WREG32(AVIVO_D2VGA_CONTROL, 0); | |
c290dadf AD |
981 | |
982 | if (rdev->family >= CHIP_RV770) { | |
983 | if (radeon_crtc->crtc_id) { | |
984 | WREG32(R700_D2GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, 0); | |
985 | WREG32(R700_D2GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, 0); | |
986 | } else { | |
987 | WREG32(R700_D1GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, 0); | |
988 | WREG32(R700_D1GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, 0); | |
989 | } | |
990 | } | |
771fe6b9 JG |
991 | WREG32(AVIVO_D1GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
992 | (u32) fb_location); | |
993 | WREG32(AVIVO_D1GRPH_SECONDARY_SURFACE_ADDRESS + | |
994 | radeon_crtc->crtc_offset, (u32) fb_location); | |
995 | WREG32(AVIVO_D1GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format); | |
996 | ||
997 | WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0); | |
998 | WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0); | |
999 | WREG32(AVIVO_D1GRPH_X_START + radeon_crtc->crtc_offset, 0); | |
1000 | WREG32(AVIVO_D1GRPH_Y_START + radeon_crtc->crtc_offset, 0); | |
1001 | WREG32(AVIVO_D1GRPH_X_END + radeon_crtc->crtc_offset, crtc->fb->width); | |
1002 | WREG32(AVIVO_D1GRPH_Y_END + radeon_crtc->crtc_offset, crtc->fb->height); | |
1003 | ||
1004 | fb_pitch_pixels = crtc->fb->pitch / (crtc->fb->bits_per_pixel / 8); | |
1005 | WREG32(AVIVO_D1GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels); | |
1006 | WREG32(AVIVO_D1GRPH_ENABLE + radeon_crtc->crtc_offset, 1); | |
1007 | ||
1008 | WREG32(AVIVO_D1MODE_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, | |
1009 | crtc->mode.vdisplay); | |
1010 | x &= ~3; | |
1011 | y &= ~1; | |
1012 | WREG32(AVIVO_D1MODE_VIEWPORT_START + radeon_crtc->crtc_offset, | |
1013 | (x << 16) | y); | |
1014 | WREG32(AVIVO_D1MODE_VIEWPORT_SIZE + radeon_crtc->crtc_offset, | |
1015 | (crtc->mode.hdisplay << 16) | crtc->mode.vdisplay); | |
1016 | ||
1017 | if (crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) | |
1018 | WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, | |
1019 | AVIVO_D1MODE_INTERLEAVE_EN); | |
1020 | else | |
1021 | WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, 0); | |
1022 | ||
1023 | if (old_fb && old_fb != crtc->fb) { | |
1024 | radeon_fb = to_radeon_framebuffer(old_fb); | |
4c788679 JG |
1025 | rbo = radeon_fb->obj->driver_private; |
1026 | r = radeon_bo_reserve(rbo, false); | |
1027 | if (unlikely(r != 0)) | |
1028 | return r; | |
1029 | radeon_bo_unpin(rbo); | |
1030 | radeon_bo_unreserve(rbo); | |
771fe6b9 | 1031 | } |
f30f37de MD |
1032 | |
1033 | /* Bytes per pixel may have changed */ | |
1034 | radeon_bandwidth_update(rdev); | |
1035 | ||
771fe6b9 JG |
1036 | return 0; |
1037 | } | |
1038 | ||
54f088a9 AD |
1039 | int atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y, |
1040 | struct drm_framebuffer *old_fb) | |
1041 | { | |
1042 | struct drm_device *dev = crtc->dev; | |
1043 | struct radeon_device *rdev = dev->dev_private; | |
1044 | ||
bcc1c2a1 AD |
1045 | if (ASIC_IS_DCE4(rdev)) |
1046 | return evergreen_crtc_set_base(crtc, x, y, old_fb); | |
1047 | else if (ASIC_IS_AVIVO(rdev)) | |
54f088a9 AD |
1048 | return avivo_crtc_set_base(crtc, x, y, old_fb); |
1049 | else | |
1050 | return radeon_crtc_set_base(crtc, x, y, old_fb); | |
1051 | } | |
1052 | ||
615e0cb6 AD |
1053 | /* properly set additional regs when using atombios */ |
1054 | static void radeon_legacy_atom_fixup(struct drm_crtc *crtc) | |
1055 | { | |
1056 | struct drm_device *dev = crtc->dev; | |
1057 | struct radeon_device *rdev = dev->dev_private; | |
1058 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
1059 | u32 disp_merge_cntl; | |
1060 | ||
1061 | switch (radeon_crtc->crtc_id) { | |
1062 | case 0: | |
1063 | disp_merge_cntl = RREG32(RADEON_DISP_MERGE_CNTL); | |
1064 | disp_merge_cntl &= ~RADEON_DISP_RGB_OFFSET_EN; | |
1065 | WREG32(RADEON_DISP_MERGE_CNTL, disp_merge_cntl); | |
1066 | break; | |
1067 | case 1: | |
1068 | disp_merge_cntl = RREG32(RADEON_DISP2_MERGE_CNTL); | |
1069 | disp_merge_cntl &= ~RADEON_DISP2_RGB_OFFSET_EN; | |
1070 | WREG32(RADEON_DISP2_MERGE_CNTL, disp_merge_cntl); | |
1071 | WREG32(RADEON_FP_H2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_H_SYNC_STRT_WID)); | |
1072 | WREG32(RADEON_FP_V2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_V_SYNC_STRT_WID)); | |
1073 | break; | |
1074 | } | |
1075 | } | |
1076 | ||
bcc1c2a1 AD |
1077 | static int radeon_atom_pick_pll(struct drm_crtc *crtc) |
1078 | { | |
1079 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
1080 | struct drm_device *dev = crtc->dev; | |
1081 | struct radeon_device *rdev = dev->dev_private; | |
1082 | struct drm_encoder *test_encoder; | |
1083 | struct drm_crtc *test_crtc; | |
1084 | uint32_t pll_in_use = 0; | |
1085 | ||
1086 | if (ASIC_IS_DCE4(rdev)) { | |
1087 | /* if crtc is driving DP and we have an ext clock, use that */ | |
1088 | list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) { | |
1089 | if (test_encoder->crtc && (test_encoder->crtc == crtc)) { | |
1090 | if (atombios_get_encoder_mode(test_encoder) == ATOM_ENCODER_MODE_DP) { | |
1091 | if (rdev->clock.dp_extclk) | |
1092 | return ATOM_PPLL_INVALID; | |
1093 | } | |
1094 | } | |
1095 | } | |
1096 | ||
1097 | /* otherwise, pick one of the plls */ | |
1098 | list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) { | |
1099 | struct radeon_crtc *radeon_test_crtc; | |
1100 | ||
1101 | if (crtc == test_crtc) | |
1102 | continue; | |
1103 | ||
1104 | radeon_test_crtc = to_radeon_crtc(test_crtc); | |
1105 | if ((radeon_test_crtc->pll_id >= ATOM_PPLL1) && | |
1106 | (radeon_test_crtc->pll_id <= ATOM_PPLL2)) | |
1107 | pll_in_use |= (1 << radeon_test_crtc->pll_id); | |
1108 | } | |
1109 | if (!(pll_in_use & 1)) | |
1110 | return ATOM_PPLL1; | |
1111 | return ATOM_PPLL2; | |
1112 | } else | |
1113 | return radeon_crtc->crtc_id; | |
1114 | ||
1115 | } | |
1116 | ||
771fe6b9 JG |
1117 | int atombios_crtc_mode_set(struct drm_crtc *crtc, |
1118 | struct drm_display_mode *mode, | |
1119 | struct drm_display_mode *adjusted_mode, | |
1120 | int x, int y, struct drm_framebuffer *old_fb) | |
1121 | { | |
1122 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
1123 | struct drm_device *dev = crtc->dev; | |
1124 | struct radeon_device *rdev = dev->dev_private; | |
771fe6b9 JG |
1125 | |
1126 | /* TODO color tiling */ | |
771fe6b9 | 1127 | |
b792210e | 1128 | atombios_disable_ss(crtc); |
bcc1c2a1 AD |
1129 | /* always set DCPLL */ |
1130 | if (ASIC_IS_DCE4(rdev)) | |
1131 | atombios_crtc_set_dcpll(crtc); | |
771fe6b9 | 1132 | atombios_crtc_set_pll(crtc, adjusted_mode); |
b792210e | 1133 | atombios_enable_ss(crtc); |
771fe6b9 | 1134 | |
bcc1c2a1 AD |
1135 | if (ASIC_IS_DCE4(rdev)) |
1136 | atombios_set_crtc_dtd_timing(crtc, adjusted_mode); | |
1137 | else if (ASIC_IS_AVIVO(rdev)) | |
1138 | atombios_crtc_set_timing(crtc, adjusted_mode); | |
771fe6b9 | 1139 | else { |
bcc1c2a1 | 1140 | atombios_crtc_set_timing(crtc, adjusted_mode); |
5a9bcacc AD |
1141 | if (radeon_crtc->crtc_id == 0) |
1142 | atombios_set_crtc_dtd_timing(crtc, adjusted_mode); | |
615e0cb6 | 1143 | radeon_legacy_atom_fixup(crtc); |
771fe6b9 | 1144 | } |
bcc1c2a1 | 1145 | atombios_crtc_set_base(crtc, x, y, old_fb); |
c93bb85b JG |
1146 | atombios_overscan_setup(crtc, mode, adjusted_mode); |
1147 | atombios_scaler_setup(crtc); | |
771fe6b9 JG |
1148 | return 0; |
1149 | } | |
1150 | ||
1151 | static bool atombios_crtc_mode_fixup(struct drm_crtc *crtc, | |
1152 | struct drm_display_mode *mode, | |
1153 | struct drm_display_mode *adjusted_mode) | |
1154 | { | |
c93bb85b JG |
1155 | if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode)) |
1156 | return false; | |
771fe6b9 JG |
1157 | return true; |
1158 | } | |
1159 | ||
1160 | static void atombios_crtc_prepare(struct drm_crtc *crtc) | |
1161 | { | |
267364ac AD |
1162 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
1163 | ||
1164 | /* pick pll */ | |
1165 | radeon_crtc->pll_id = radeon_atom_pick_pll(crtc); | |
1166 | ||
37b4390e | 1167 | atombios_lock_crtc(crtc, ATOM_ENABLE); |
a348c84d | 1168 | atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
771fe6b9 JG |
1169 | } |
1170 | ||
1171 | static void atombios_crtc_commit(struct drm_crtc *crtc) | |
1172 | { | |
1173 | atombios_crtc_dpms(crtc, DRM_MODE_DPMS_ON); | |
37b4390e | 1174 | atombios_lock_crtc(crtc, ATOM_DISABLE); |
771fe6b9 JG |
1175 | } |
1176 | ||
1177 | static const struct drm_crtc_helper_funcs atombios_helper_funcs = { | |
1178 | .dpms = atombios_crtc_dpms, | |
1179 | .mode_fixup = atombios_crtc_mode_fixup, | |
1180 | .mode_set = atombios_crtc_mode_set, | |
1181 | .mode_set_base = atombios_crtc_set_base, | |
1182 | .prepare = atombios_crtc_prepare, | |
1183 | .commit = atombios_crtc_commit, | |
068143d3 | 1184 | .load_lut = radeon_crtc_load_lut, |
771fe6b9 JG |
1185 | }; |
1186 | ||
1187 | void radeon_atombios_init_crtc(struct drm_device *dev, | |
1188 | struct radeon_crtc *radeon_crtc) | |
1189 | { | |
bcc1c2a1 AD |
1190 | struct radeon_device *rdev = dev->dev_private; |
1191 | ||
1192 | if (ASIC_IS_DCE4(rdev)) { | |
1193 | switch (radeon_crtc->crtc_id) { | |
1194 | case 0: | |
1195 | default: | |
12d7798f | 1196 | radeon_crtc->crtc_offset = EVERGREEN_CRTC0_REGISTER_OFFSET; |
bcc1c2a1 AD |
1197 | break; |
1198 | case 1: | |
12d7798f | 1199 | radeon_crtc->crtc_offset = EVERGREEN_CRTC1_REGISTER_OFFSET; |
bcc1c2a1 AD |
1200 | break; |
1201 | case 2: | |
12d7798f | 1202 | radeon_crtc->crtc_offset = EVERGREEN_CRTC2_REGISTER_OFFSET; |
bcc1c2a1 AD |
1203 | break; |
1204 | case 3: | |
12d7798f | 1205 | radeon_crtc->crtc_offset = EVERGREEN_CRTC3_REGISTER_OFFSET; |
bcc1c2a1 AD |
1206 | break; |
1207 | case 4: | |
12d7798f | 1208 | radeon_crtc->crtc_offset = EVERGREEN_CRTC4_REGISTER_OFFSET; |
bcc1c2a1 AD |
1209 | break; |
1210 | case 5: | |
12d7798f | 1211 | radeon_crtc->crtc_offset = EVERGREEN_CRTC5_REGISTER_OFFSET; |
bcc1c2a1 AD |
1212 | break; |
1213 | } | |
1214 | } else { | |
1215 | if (radeon_crtc->crtc_id == 1) | |
1216 | radeon_crtc->crtc_offset = | |
1217 | AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL; | |
1218 | else | |
1219 | radeon_crtc->crtc_offset = 0; | |
1220 | } | |
1221 | radeon_crtc->pll_id = -1; | |
771fe6b9 JG |
1222 | drm_crtc_helper_add(&radeon_crtc->base, &atombios_helper_funcs); |
1223 | } |