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> | |
68adac5e | 29 | #include <drm/drm_fixed.h> |
771fe6b9 JG |
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 | ||
c93bb85b JG |
47 | args.ucCRTC = radeon_crtc->crtc_id; |
48 | ||
49 | switch (radeon_crtc->rmx_type) { | |
50 | case RMX_CENTER: | |
4589433c CC |
51 | args.usOverscanTop = cpu_to_le16((adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2); |
52 | args.usOverscanBottom = cpu_to_le16((adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2); | |
53 | args.usOverscanLeft = cpu_to_le16((adjusted_mode->crtc_hdisplay - mode->crtc_hdisplay) / 2); | |
54 | args.usOverscanRight = cpu_to_le16((adjusted_mode->crtc_hdisplay - mode->crtc_hdisplay) / 2); | |
c93bb85b JG |
55 | break; |
56 | case RMX_ASPECT: | |
57 | a1 = mode->crtc_vdisplay * adjusted_mode->crtc_hdisplay; | |
58 | a2 = adjusted_mode->crtc_vdisplay * mode->crtc_hdisplay; | |
59 | ||
60 | if (a1 > a2) { | |
4589433c CC |
61 | args.usOverscanLeft = cpu_to_le16((adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2); |
62 | args.usOverscanRight = cpu_to_le16((adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2); | |
c93bb85b | 63 | } else if (a2 > a1) { |
942b0e95 AD |
64 | args.usOverscanTop = cpu_to_le16((adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2); |
65 | args.usOverscanBottom = cpu_to_le16((adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2); | |
c93bb85b | 66 | } |
c93bb85b JG |
67 | break; |
68 | case RMX_FULL: | |
69 | default: | |
4589433c CC |
70 | args.usOverscanRight = cpu_to_le16(radeon_crtc->h_border); |
71 | args.usOverscanLeft = cpu_to_le16(radeon_crtc->h_border); | |
72 | args.usOverscanBottom = cpu_to_le16(radeon_crtc->v_border); | |
73 | args.usOverscanTop = cpu_to_le16(radeon_crtc->v_border); | |
c93bb85b JG |
74 | break; |
75 | } | |
5b1714d3 | 76 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
c93bb85b JG |
77 | } |
78 | ||
79 | static void atombios_scaler_setup(struct drm_crtc *crtc) | |
80 | { | |
81 | struct drm_device *dev = crtc->dev; | |
82 | struct radeon_device *rdev = dev->dev_private; | |
83 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
84 | ENABLE_SCALER_PS_ALLOCATION args; | |
85 | int index = GetIndexIntoMasterTable(COMMAND, EnableScaler); | |
4ce001ab | 86 | |
c93bb85b JG |
87 | /* fixme - fill in enc_priv for atom dac */ |
88 | enum radeon_tv_std tv_std = TV_STD_NTSC; | |
4ce001ab DA |
89 | bool is_tv = false, is_cv = false; |
90 | struct drm_encoder *encoder; | |
c93bb85b JG |
91 | |
92 | if (!ASIC_IS_AVIVO(rdev) && radeon_crtc->crtc_id) | |
93 | return; | |
94 | ||
4ce001ab DA |
95 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
96 | /* find tv std */ | |
97 | if (encoder->crtc == crtc) { | |
98 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); | |
99 | if (radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT) { | |
100 | struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv; | |
101 | tv_std = tv_dac->tv_std; | |
102 | is_tv = true; | |
103 | } | |
104 | } | |
105 | } | |
106 | ||
c93bb85b JG |
107 | memset(&args, 0, sizeof(args)); |
108 | ||
109 | args.ucScaler = radeon_crtc->crtc_id; | |
110 | ||
4ce001ab | 111 | if (is_tv) { |
c93bb85b JG |
112 | switch (tv_std) { |
113 | case TV_STD_NTSC: | |
114 | default: | |
115 | args.ucTVStandard = ATOM_TV_NTSC; | |
116 | break; | |
117 | case TV_STD_PAL: | |
118 | args.ucTVStandard = ATOM_TV_PAL; | |
119 | break; | |
120 | case TV_STD_PAL_M: | |
121 | args.ucTVStandard = ATOM_TV_PALM; | |
122 | break; | |
123 | case TV_STD_PAL_60: | |
124 | args.ucTVStandard = ATOM_TV_PAL60; | |
125 | break; | |
126 | case TV_STD_NTSC_J: | |
127 | args.ucTVStandard = ATOM_TV_NTSCJ; | |
128 | break; | |
129 | case TV_STD_SCART_PAL: | |
130 | args.ucTVStandard = ATOM_TV_PAL; /* ??? */ | |
131 | break; | |
132 | case TV_STD_SECAM: | |
133 | args.ucTVStandard = ATOM_TV_SECAM; | |
134 | break; | |
135 | case TV_STD_PAL_CN: | |
136 | args.ucTVStandard = ATOM_TV_PALCN; | |
137 | break; | |
138 | } | |
139 | args.ucEnable = SCALER_ENABLE_MULTITAP_MODE; | |
4ce001ab | 140 | } else if (is_cv) { |
c93bb85b JG |
141 | args.ucTVStandard = ATOM_TV_CV; |
142 | args.ucEnable = SCALER_ENABLE_MULTITAP_MODE; | |
143 | } else { | |
144 | switch (radeon_crtc->rmx_type) { | |
145 | case RMX_FULL: | |
146 | args.ucEnable = ATOM_SCALER_EXPANSION; | |
147 | break; | |
148 | case RMX_CENTER: | |
149 | args.ucEnable = ATOM_SCALER_CENTER; | |
150 | break; | |
151 | case RMX_ASPECT: | |
152 | args.ucEnable = ATOM_SCALER_EXPANSION; | |
153 | break; | |
154 | default: | |
155 | if (ASIC_IS_AVIVO(rdev)) | |
156 | args.ucEnable = ATOM_SCALER_DISABLE; | |
157 | else | |
158 | args.ucEnable = ATOM_SCALER_CENTER; | |
159 | break; | |
160 | } | |
161 | } | |
162 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
4ce001ab DA |
163 | if ((is_tv || is_cv) |
164 | && rdev->family >= CHIP_RV515 && rdev->family <= CHIP_R580) { | |
165 | atom_rv515_force_tv_scaler(rdev, radeon_crtc); | |
c93bb85b JG |
166 | } |
167 | } | |
168 | ||
771fe6b9 JG |
169 | static void atombios_lock_crtc(struct drm_crtc *crtc, int lock) |
170 | { | |
171 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
172 | struct drm_device *dev = crtc->dev; | |
173 | struct radeon_device *rdev = dev->dev_private; | |
174 | int index = | |
175 | GetIndexIntoMasterTable(COMMAND, UpdateCRTC_DoubleBufferRegisters); | |
176 | ENABLE_CRTC_PS_ALLOCATION args; | |
177 | ||
178 | memset(&args, 0, sizeof(args)); | |
179 | ||
180 | args.ucCRTC = radeon_crtc->crtc_id; | |
181 | args.ucEnable = lock; | |
182 | ||
183 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
184 | } | |
185 | ||
186 | static void atombios_enable_crtc(struct drm_crtc *crtc, int state) | |
187 | { | |
188 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
189 | struct drm_device *dev = crtc->dev; | |
190 | struct radeon_device *rdev = dev->dev_private; | |
191 | int index = GetIndexIntoMasterTable(COMMAND, EnableCRTC); | |
192 | ENABLE_CRTC_PS_ALLOCATION args; | |
193 | ||
194 | memset(&args, 0, sizeof(args)); | |
195 | ||
196 | args.ucCRTC = radeon_crtc->crtc_id; | |
197 | args.ucEnable = state; | |
198 | ||
199 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
200 | } | |
201 | ||
202 | static void atombios_enable_crtc_memreq(struct drm_crtc *crtc, int state) | |
203 | { | |
204 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
205 | struct drm_device *dev = crtc->dev; | |
206 | struct radeon_device *rdev = dev->dev_private; | |
207 | int index = GetIndexIntoMasterTable(COMMAND, EnableCRTCMemReq); | |
208 | ENABLE_CRTC_PS_ALLOCATION args; | |
209 | ||
210 | memset(&args, 0, sizeof(args)); | |
211 | ||
212 | args.ucCRTC = radeon_crtc->crtc_id; | |
213 | args.ucEnable = state; | |
214 | ||
215 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
216 | } | |
217 | ||
218 | static void atombios_blank_crtc(struct drm_crtc *crtc, int state) | |
219 | { | |
220 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
221 | struct drm_device *dev = crtc->dev; | |
222 | struct radeon_device *rdev = dev->dev_private; | |
223 | int index = GetIndexIntoMasterTable(COMMAND, BlankCRTC); | |
224 | BLANK_CRTC_PS_ALLOCATION args; | |
225 | ||
226 | memset(&args, 0, sizeof(args)); | |
227 | ||
228 | args.ucCRTC = radeon_crtc->crtc_id; | |
229 | args.ucBlanking = state; | |
230 | ||
231 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
232 | } | |
233 | ||
fef9f91f AD |
234 | static void atombios_powergate_crtc(struct drm_crtc *crtc, int state) |
235 | { | |
236 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
237 | struct drm_device *dev = crtc->dev; | |
238 | struct radeon_device *rdev = dev->dev_private; | |
239 | int index = GetIndexIntoMasterTable(COMMAND, EnableDispPowerGating); | |
240 | ENABLE_DISP_POWER_GATING_PARAMETERS_V2_1 args; | |
241 | ||
242 | memset(&args, 0, sizeof(args)); | |
243 | ||
244 | args.ucDispPipeId = radeon_crtc->crtc_id; | |
245 | args.ucEnable = state; | |
246 | ||
247 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
248 | } | |
249 | ||
771fe6b9 JG |
250 | void atombios_crtc_dpms(struct drm_crtc *crtc, int mode) |
251 | { | |
252 | struct drm_device *dev = crtc->dev; | |
253 | struct radeon_device *rdev = dev->dev_private; | |
500b7587 | 254 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
771fe6b9 JG |
255 | |
256 | switch (mode) { | |
257 | case DRM_MODE_DPMS_ON: | |
d7311171 AD |
258 | radeon_crtc->enabled = true; |
259 | /* adjust pm to dpms changes BEFORE enabling crtcs */ | |
260 | radeon_pm_compute_clocks(rdev); | |
6c0ae2ab | 261 | if (ASIC_IS_DCE6(rdev) && !radeon_crtc->in_mode_set) |
fef9f91f | 262 | atombios_powergate_crtc(crtc, ATOM_DISABLE); |
37b4390e | 263 | atombios_enable_crtc(crtc, ATOM_ENABLE); |
79f17c64 | 264 | if (ASIC_IS_DCE3(rdev) && !ASIC_IS_DCE6(rdev)) |
37b4390e AD |
265 | atombios_enable_crtc_memreq(crtc, ATOM_ENABLE); |
266 | atombios_blank_crtc(crtc, ATOM_DISABLE); | |
45f9a39b | 267 | drm_vblank_post_modeset(dev, radeon_crtc->crtc_id); |
500b7587 | 268 | radeon_crtc_load_lut(crtc); |
771fe6b9 JG |
269 | break; |
270 | case DRM_MODE_DPMS_STANDBY: | |
271 | case DRM_MODE_DPMS_SUSPEND: | |
272 | case DRM_MODE_DPMS_OFF: | |
45f9a39b | 273 | drm_vblank_pre_modeset(dev, radeon_crtc->crtc_id); |
a93f344d AD |
274 | if (radeon_crtc->enabled) |
275 | atombios_blank_crtc(crtc, ATOM_ENABLE); | |
79f17c64 | 276 | if (ASIC_IS_DCE3(rdev) && !ASIC_IS_DCE6(rdev)) |
37b4390e AD |
277 | atombios_enable_crtc_memreq(crtc, ATOM_DISABLE); |
278 | atombios_enable_crtc(crtc, ATOM_DISABLE); | |
a48b9b4e | 279 | radeon_crtc->enabled = false; |
c205b232 AD |
280 | if (ASIC_IS_DCE6(rdev) && !radeon_crtc->in_mode_set) |
281 | atombios_powergate_crtc(crtc, ATOM_ENABLE); | |
d7311171 AD |
282 | /* adjust pm to dpms changes AFTER disabling crtcs */ |
283 | radeon_pm_compute_clocks(rdev); | |
771fe6b9 JG |
284 | break; |
285 | } | |
771fe6b9 JG |
286 | } |
287 | ||
288 | static void | |
289 | atombios_set_crtc_dtd_timing(struct drm_crtc *crtc, | |
5a9bcacc | 290 | struct drm_display_mode *mode) |
771fe6b9 | 291 | { |
5a9bcacc | 292 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
771fe6b9 JG |
293 | struct drm_device *dev = crtc->dev; |
294 | struct radeon_device *rdev = dev->dev_private; | |
5a9bcacc | 295 | SET_CRTC_USING_DTD_TIMING_PARAMETERS args; |
771fe6b9 | 296 | int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_UsingDTDTiming); |
5a9bcacc | 297 | u16 misc = 0; |
771fe6b9 | 298 | |
5a9bcacc | 299 | memset(&args, 0, sizeof(args)); |
5b1714d3 | 300 | args.usH_Size = cpu_to_le16(mode->crtc_hdisplay - (radeon_crtc->h_border * 2)); |
5a9bcacc | 301 | args.usH_Blanking_Time = |
5b1714d3 AD |
302 | cpu_to_le16(mode->crtc_hblank_end - mode->crtc_hdisplay + (radeon_crtc->h_border * 2)); |
303 | args.usV_Size = cpu_to_le16(mode->crtc_vdisplay - (radeon_crtc->v_border * 2)); | |
5a9bcacc | 304 | args.usV_Blanking_Time = |
5b1714d3 | 305 | cpu_to_le16(mode->crtc_vblank_end - mode->crtc_vdisplay + (radeon_crtc->v_border * 2)); |
5a9bcacc | 306 | args.usH_SyncOffset = |
5b1714d3 | 307 | cpu_to_le16(mode->crtc_hsync_start - mode->crtc_hdisplay + radeon_crtc->h_border); |
5a9bcacc AD |
308 | args.usH_SyncWidth = |
309 | cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start); | |
310 | args.usV_SyncOffset = | |
5b1714d3 | 311 | cpu_to_le16(mode->crtc_vsync_start - mode->crtc_vdisplay + radeon_crtc->v_border); |
5a9bcacc AD |
312 | args.usV_SyncWidth = |
313 | cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start); | |
5b1714d3 AD |
314 | args.ucH_Border = radeon_crtc->h_border; |
315 | args.ucV_Border = radeon_crtc->v_border; | |
5a9bcacc AD |
316 | |
317 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) | |
318 | misc |= ATOM_VSYNC_POLARITY; | |
319 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) | |
320 | misc |= ATOM_HSYNC_POLARITY; | |
321 | if (mode->flags & DRM_MODE_FLAG_CSYNC) | |
322 | misc |= ATOM_COMPOSITESYNC; | |
323 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) | |
324 | misc |= ATOM_INTERLACE; | |
325 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) | |
326 | misc |= ATOM_DOUBLE_CLOCK_MODE; | |
327 | ||
328 | args.susModeMiscInfo.usAccess = cpu_to_le16(misc); | |
329 | args.ucCRTC = radeon_crtc->crtc_id; | |
771fe6b9 | 330 | |
5a9bcacc | 331 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
771fe6b9 JG |
332 | } |
333 | ||
5a9bcacc AD |
334 | static void atombios_crtc_set_timing(struct drm_crtc *crtc, |
335 | struct drm_display_mode *mode) | |
771fe6b9 | 336 | { |
5a9bcacc | 337 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
771fe6b9 JG |
338 | struct drm_device *dev = crtc->dev; |
339 | struct radeon_device *rdev = dev->dev_private; | |
5a9bcacc | 340 | SET_CRTC_TIMING_PARAMETERS_PS_ALLOCATION args; |
771fe6b9 | 341 | int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_Timing); |
5a9bcacc | 342 | u16 misc = 0; |
771fe6b9 | 343 | |
5a9bcacc AD |
344 | memset(&args, 0, sizeof(args)); |
345 | args.usH_Total = cpu_to_le16(mode->crtc_htotal); | |
346 | args.usH_Disp = cpu_to_le16(mode->crtc_hdisplay); | |
347 | args.usH_SyncStart = cpu_to_le16(mode->crtc_hsync_start); | |
348 | args.usH_SyncWidth = | |
349 | cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start); | |
350 | args.usV_Total = cpu_to_le16(mode->crtc_vtotal); | |
351 | args.usV_Disp = cpu_to_le16(mode->crtc_vdisplay); | |
352 | args.usV_SyncStart = cpu_to_le16(mode->crtc_vsync_start); | |
353 | args.usV_SyncWidth = | |
354 | cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start); | |
355 | ||
54bfe496 AD |
356 | args.ucOverscanRight = radeon_crtc->h_border; |
357 | args.ucOverscanLeft = radeon_crtc->h_border; | |
358 | args.ucOverscanBottom = radeon_crtc->v_border; | |
359 | args.ucOverscanTop = radeon_crtc->v_border; | |
360 | ||
5a9bcacc AD |
361 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
362 | misc |= ATOM_VSYNC_POLARITY; | |
363 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) | |
364 | misc |= ATOM_HSYNC_POLARITY; | |
365 | if (mode->flags & DRM_MODE_FLAG_CSYNC) | |
366 | misc |= ATOM_COMPOSITESYNC; | |
367 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) | |
368 | misc |= ATOM_INTERLACE; | |
369 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) | |
370 | misc |= ATOM_DOUBLE_CLOCK_MODE; | |
371 | ||
372 | args.susModeMiscInfo.usAccess = cpu_to_le16(misc); | |
373 | args.ucCRTC = radeon_crtc->crtc_id; | |
771fe6b9 | 374 | |
5a9bcacc | 375 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
771fe6b9 JG |
376 | } |
377 | ||
3fa47d9e | 378 | static void atombios_disable_ss(struct radeon_device *rdev, int pll_id) |
b792210e | 379 | { |
b792210e AD |
380 | u32 ss_cntl; |
381 | ||
382 | if (ASIC_IS_DCE4(rdev)) { | |
3fa47d9e | 383 | switch (pll_id) { |
b792210e AD |
384 | case ATOM_PPLL1: |
385 | ss_cntl = RREG32(EVERGREEN_P1PLL_SS_CNTL); | |
386 | ss_cntl &= ~EVERGREEN_PxPLL_SS_EN; | |
387 | WREG32(EVERGREEN_P1PLL_SS_CNTL, ss_cntl); | |
388 | break; | |
389 | case ATOM_PPLL2: | |
390 | ss_cntl = RREG32(EVERGREEN_P2PLL_SS_CNTL); | |
391 | ss_cntl &= ~EVERGREEN_PxPLL_SS_EN; | |
392 | WREG32(EVERGREEN_P2PLL_SS_CNTL, ss_cntl); | |
393 | break; | |
394 | case ATOM_DCPLL: | |
395 | case ATOM_PPLL_INVALID: | |
396 | return; | |
397 | } | |
398 | } else if (ASIC_IS_AVIVO(rdev)) { | |
3fa47d9e | 399 | switch (pll_id) { |
b792210e AD |
400 | case ATOM_PPLL1: |
401 | ss_cntl = RREG32(AVIVO_P1PLL_INT_SS_CNTL); | |
402 | ss_cntl &= ~1; | |
403 | WREG32(AVIVO_P1PLL_INT_SS_CNTL, ss_cntl); | |
404 | break; | |
405 | case ATOM_PPLL2: | |
406 | ss_cntl = RREG32(AVIVO_P2PLL_INT_SS_CNTL); | |
407 | ss_cntl &= ~1; | |
408 | WREG32(AVIVO_P2PLL_INT_SS_CNTL, ss_cntl); | |
409 | break; | |
410 | case ATOM_DCPLL: | |
411 | case ATOM_PPLL_INVALID: | |
412 | return; | |
413 | } | |
414 | } | |
415 | } | |
416 | ||
417 | ||
26b9fc3a | 418 | union atom_enable_ss { |
ba032a58 AD |
419 | ENABLE_LVDS_SS_PARAMETERS lvds_ss; |
420 | ENABLE_LVDS_SS_PARAMETERS_V2 lvds_ss_2; | |
26b9fc3a | 421 | ENABLE_SPREAD_SPECTRUM_ON_PPLL_PS_ALLOCATION v1; |
ba032a58 | 422 | ENABLE_SPREAD_SPECTRUM_ON_PPLL_V2 v2; |
a572eaa3 | 423 | ENABLE_SPREAD_SPECTRUM_ON_PPLL_V3 v3; |
26b9fc3a AD |
424 | }; |
425 | ||
3fa47d9e | 426 | static void atombios_crtc_program_ss(struct radeon_device *rdev, |
ba032a58 AD |
427 | int enable, |
428 | int pll_id, | |
5efcc76c | 429 | int crtc_id, |
ba032a58 | 430 | struct radeon_atom_ss *ss) |
ebbe1cb9 | 431 | { |
5efcc76c | 432 | unsigned i; |
ebbe1cb9 | 433 | int index = GetIndexIntoMasterTable(COMMAND, EnableSpreadSpectrumOnPPLL); |
26b9fc3a | 434 | union atom_enable_ss args; |
ebbe1cb9 | 435 | |
5efcc76c | 436 | if (!enable) { |
53176706 | 437 | for (i = 0; i < rdev->num_crtc; i++) { |
5efcc76c JG |
438 | if (rdev->mode_info.crtcs[i] && |
439 | rdev->mode_info.crtcs[i]->enabled && | |
440 | i != crtc_id && | |
441 | pll_id == rdev->mode_info.crtcs[i]->pll_id) { | |
442 | /* one other crtc is using this pll don't turn | |
443 | * off spread spectrum as it might turn off | |
444 | * display on active crtc | |
445 | */ | |
446 | return; | |
447 | } | |
448 | } | |
449 | } | |
450 | ||
ba032a58 | 451 | memset(&args, 0, sizeof(args)); |
bcc1c2a1 | 452 | |
a572eaa3 | 453 | if (ASIC_IS_DCE5(rdev)) { |
4589433c | 454 | args.v3.usSpreadSpectrumAmountFrac = cpu_to_le16(0); |
8e8e523d | 455 | args.v3.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; |
a572eaa3 AD |
456 | switch (pll_id) { |
457 | case ATOM_PPLL1: | |
458 | args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_P1PLL; | |
a572eaa3 AD |
459 | break; |
460 | case ATOM_PPLL2: | |
461 | args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_P2PLL; | |
a572eaa3 AD |
462 | break; |
463 | case ATOM_DCPLL: | |
464 | args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_DCPLL; | |
a572eaa3 AD |
465 | break; |
466 | case ATOM_PPLL_INVALID: | |
467 | return; | |
468 | } | |
f312f093 AD |
469 | args.v3.usSpreadSpectrumAmount = cpu_to_le16(ss->amount); |
470 | args.v3.usSpreadSpectrumStep = cpu_to_le16(ss->step); | |
d0ae3e89 | 471 | args.v3.ucEnable = enable; |
0671bdd7 | 472 | if ((ss->percentage == 0) || (ss->type & ATOM_EXTERNAL_SS_MASK) || ASIC_IS_DCE61(rdev)) |
8e8e523d | 473 | args.v3.ucEnable = ATOM_DISABLE; |
a572eaa3 | 474 | } else if (ASIC_IS_DCE4(rdev)) { |
ba032a58 | 475 | args.v2.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); |
8e8e523d | 476 | args.v2.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; |
ba032a58 AD |
477 | switch (pll_id) { |
478 | case ATOM_PPLL1: | |
479 | args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_P1PLL; | |
ba032a58 AD |
480 | break; |
481 | case ATOM_PPLL2: | |
482 | args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_P2PLL; | |
ebbe1cb9 | 483 | break; |
ba032a58 AD |
484 | case ATOM_DCPLL: |
485 | args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_DCPLL; | |
ba032a58 AD |
486 | break; |
487 | case ATOM_PPLL_INVALID: | |
488 | return; | |
ebbe1cb9 | 489 | } |
f312f093 AD |
490 | args.v2.usSpreadSpectrumAmount = cpu_to_le16(ss->amount); |
491 | args.v2.usSpreadSpectrumStep = cpu_to_le16(ss->step); | |
ba032a58 | 492 | args.v2.ucEnable = enable; |
09cc6506 | 493 | if ((ss->percentage == 0) || (ss->type & ATOM_EXTERNAL_SS_MASK) || ASIC_IS_DCE41(rdev)) |
8e8e523d | 494 | args.v2.ucEnable = ATOM_DISABLE; |
ba032a58 AD |
495 | } else if (ASIC_IS_DCE3(rdev)) { |
496 | args.v1.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); | |
8e8e523d | 497 | args.v1.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; |
ba032a58 AD |
498 | args.v1.ucSpreadSpectrumStep = ss->step; |
499 | args.v1.ucSpreadSpectrumDelay = ss->delay; | |
500 | args.v1.ucSpreadSpectrumRange = ss->range; | |
501 | args.v1.ucPpll = pll_id; | |
502 | args.v1.ucEnable = enable; | |
503 | } else if (ASIC_IS_AVIVO(rdev)) { | |
8e8e523d AD |
504 | if ((enable == ATOM_DISABLE) || (ss->percentage == 0) || |
505 | (ss->type & ATOM_EXTERNAL_SS_MASK)) { | |
3fa47d9e | 506 | atombios_disable_ss(rdev, pll_id); |
ba032a58 AD |
507 | return; |
508 | } | |
509 | args.lvds_ss_2.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); | |
8e8e523d | 510 | args.lvds_ss_2.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; |
ba032a58 AD |
511 | args.lvds_ss_2.ucSpreadSpectrumStep = ss->step; |
512 | args.lvds_ss_2.ucSpreadSpectrumDelay = ss->delay; | |
513 | args.lvds_ss_2.ucSpreadSpectrumRange = ss->range; | |
514 | args.lvds_ss_2.ucEnable = enable; | |
ebbe1cb9 | 515 | } else { |
8e8e523d AD |
516 | if ((enable == ATOM_DISABLE) || (ss->percentage == 0) || |
517 | (ss->type & ATOM_EXTERNAL_SS_MASK)) { | |
3fa47d9e | 518 | atombios_disable_ss(rdev, pll_id); |
ba032a58 AD |
519 | return; |
520 | } | |
521 | args.lvds_ss.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); | |
8e8e523d | 522 | args.lvds_ss.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; |
ba032a58 AD |
523 | args.lvds_ss.ucSpreadSpectrumStepSize_Delay = (ss->step & 3) << 2; |
524 | args.lvds_ss.ucSpreadSpectrumStepSize_Delay |= (ss->delay & 7) << 4; | |
525 | args.lvds_ss.ucEnable = enable; | |
ebbe1cb9 | 526 | } |
26b9fc3a | 527 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
ebbe1cb9 AD |
528 | } |
529 | ||
4eaeca33 AD |
530 | union adjust_pixel_clock { |
531 | ADJUST_DISPLAY_PLL_PS_ALLOCATION v1; | |
bcc1c2a1 | 532 | ADJUST_DISPLAY_PLL_PS_ALLOCATION_V3 v3; |
4eaeca33 AD |
533 | }; |
534 | ||
535 | static u32 atombios_adjust_pll(struct drm_crtc *crtc, | |
536 | struct drm_display_mode *mode, | |
ba032a58 AD |
537 | struct radeon_pll *pll, |
538 | bool ss_enabled, | |
539 | struct radeon_atom_ss *ss) | |
771fe6b9 | 540 | { |
771fe6b9 JG |
541 | struct drm_device *dev = crtc->dev; |
542 | struct radeon_device *rdev = dev->dev_private; | |
543 | struct drm_encoder *encoder = NULL; | |
544 | struct radeon_encoder *radeon_encoder = NULL; | |
df271bec | 545 | struct drm_connector *connector = NULL; |
4eaeca33 | 546 | u32 adjusted_clock = mode->clock; |
bcc1c2a1 | 547 | int encoder_mode = 0; |
fbee67a6 AD |
548 | u32 dp_clock = mode->clock; |
549 | int bpc = 8; | |
9aa59993 | 550 | bool is_duallink = false; |
fc10332b | 551 | |
4eaeca33 AD |
552 | /* reset the pll flags */ |
553 | pll->flags = 0; | |
771fe6b9 JG |
554 | |
555 | if (ASIC_IS_AVIVO(rdev)) { | |
eb1300bc AD |
556 | if ((rdev->family == CHIP_RS600) || |
557 | (rdev->family == CHIP_RS690) || | |
558 | (rdev->family == CHIP_RS740)) | |
2ff776cf | 559 | pll->flags |= (/*RADEON_PLL_USE_FRAC_FB_DIV |*/ |
fc10332b | 560 | RADEON_PLL_PREFER_CLOSEST_LOWER); |
5480f727 DA |
561 | |
562 | if (ASIC_IS_DCE32(rdev) && mode->clock > 200000) /* range limits??? */ | |
563 | pll->flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; | |
564 | else | |
565 | pll->flags |= RADEON_PLL_PREFER_LOW_REF_DIV; | |
9bb09fa1 | 566 | |
5785e53f | 567 | if (rdev->family < CHIP_RV770) |
9bb09fa1 | 568 | pll->flags |= RADEON_PLL_PREFER_MINM_OVER_MAXP; |
37d4174d AD |
569 | /* use frac fb div on APUs */ |
570 | if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev)) | |
571 | pll->flags |= RADEON_PLL_USE_FRAC_FB_DIV; | |
5480f727 | 572 | } else { |
fc10332b | 573 | pll->flags |= RADEON_PLL_LEGACY; |
771fe6b9 | 574 | |
5480f727 DA |
575 | if (mode->clock > 200000) /* range limits??? */ |
576 | pll->flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; | |
577 | else | |
578 | pll->flags |= RADEON_PLL_PREFER_LOW_REF_DIV; | |
5480f727 DA |
579 | } |
580 | ||
771fe6b9 JG |
581 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
582 | if (encoder->crtc == crtc) { | |
4eaeca33 | 583 | radeon_encoder = to_radeon_encoder(encoder); |
df271bec | 584 | connector = radeon_get_connector_for_encoder(encoder); |
eccea792 | 585 | bpc = radeon_get_monitor_bpc(connector); |
bcc1c2a1 | 586 | encoder_mode = atombios_get_encoder_mode(encoder); |
9aa59993 | 587 | is_duallink = radeon_dig_monitor_is_duallink(encoder, mode->clock); |
eac4dff6 | 588 | if ((radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) || |
1d33e1fc | 589 | (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)) { |
fbee67a6 AD |
590 | if (connector) { |
591 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); | |
592 | struct radeon_connector_atom_dig *dig_connector = | |
593 | radeon_connector->con_priv; | |
594 | ||
595 | dp_clock = dig_connector->dp_clock; | |
596 | } | |
597 | } | |
5b40ddf8 | 598 | |
ba032a58 AD |
599 | /* use recommended ref_div for ss */ |
600 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { | |
601 | if (ss_enabled) { | |
602 | if (ss->refdiv) { | |
603 | pll->flags |= RADEON_PLL_USE_REF_DIV; | |
604 | pll->reference_div = ss->refdiv; | |
5b40ddf8 AD |
605 | if (ASIC_IS_AVIVO(rdev)) |
606 | pll->flags |= RADEON_PLL_USE_FRAC_FB_DIV; | |
ba032a58 AD |
607 | } |
608 | } | |
609 | } | |
5b40ddf8 | 610 | |
4eaeca33 AD |
611 | if (ASIC_IS_AVIVO(rdev)) { |
612 | /* DVO wants 2x pixel clock if the DVO chip is in 12 bit mode */ | |
613 | if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1) | |
614 | adjusted_clock = mode->clock * 2; | |
48dfaaeb | 615 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) |
a1a4b23b | 616 | pll->flags |= RADEON_PLL_PREFER_CLOSEST_LOWER; |
5b40ddf8 AD |
617 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) |
618 | pll->flags |= RADEON_PLL_IS_LCD; | |
4eaeca33 AD |
619 | } else { |
620 | if (encoder->encoder_type != DRM_MODE_ENCODER_DAC) | |
fc10332b | 621 | pll->flags |= RADEON_PLL_NO_ODD_POST_DIV; |
4eaeca33 | 622 | if (encoder->encoder_type == DRM_MODE_ENCODER_LVDS) |
fc10332b | 623 | pll->flags |= RADEON_PLL_USE_REF_DIV; |
771fe6b9 | 624 | } |
3ce0a23d | 625 | break; |
771fe6b9 JG |
626 | } |
627 | } | |
628 | ||
2606c886 AD |
629 | /* DCE3+ has an AdjustDisplayPll that will adjust the pixel clock |
630 | * accordingly based on the encoder/transmitter to work around | |
631 | * special hw requirements. | |
632 | */ | |
633 | if (ASIC_IS_DCE3(rdev)) { | |
4eaeca33 | 634 | union adjust_pixel_clock args; |
4eaeca33 AD |
635 | u8 frev, crev; |
636 | int index; | |
2606c886 | 637 | |
2606c886 | 638 | index = GetIndexIntoMasterTable(COMMAND, AdjustDisplayPll); |
a084e6ee AD |
639 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
640 | &crev)) | |
641 | return adjusted_clock; | |
4eaeca33 AD |
642 | |
643 | memset(&args, 0, sizeof(args)); | |
644 | ||
645 | switch (frev) { | |
646 | case 1: | |
647 | switch (crev) { | |
648 | case 1: | |
649 | case 2: | |
650 | args.v1.usPixelClock = cpu_to_le16(mode->clock / 10); | |
651 | args.v1.ucTransmitterID = radeon_encoder->encoder_id; | |
bcc1c2a1 | 652 | args.v1.ucEncodeMode = encoder_mode; |
8e8e523d | 653 | if (ss_enabled && ss->percentage) |
fbee67a6 AD |
654 | args.v1.ucConfig |= |
655 | ADJUST_DISPLAY_CONFIG_SS_ENABLE; | |
4eaeca33 AD |
656 | |
657 | atom_execute_table(rdev->mode_info.atom_context, | |
658 | index, (uint32_t *)&args); | |
659 | adjusted_clock = le16_to_cpu(args.v1.usPixelClock) * 10; | |
660 | break; | |
bcc1c2a1 AD |
661 | case 3: |
662 | args.v3.sInput.usPixelClock = cpu_to_le16(mode->clock / 10); | |
663 | args.v3.sInput.ucTransmitterID = radeon_encoder->encoder_id; | |
664 | args.v3.sInput.ucEncodeMode = encoder_mode; | |
665 | args.v3.sInput.ucDispPllConfig = 0; | |
8e8e523d | 666 | if (ss_enabled && ss->percentage) |
b526ce22 AD |
667 | args.v3.sInput.ucDispPllConfig |= |
668 | DISPPLL_CONFIG_SS_ENABLE; | |
996d5c59 | 669 | if (ENCODER_MODE_IS_DP(encoder_mode)) { |
b4f15f80 AD |
670 | args.v3.sInput.ucDispPllConfig |= |
671 | DISPPLL_CONFIG_COHERENT_MODE; | |
672 | /* 16200 or 27000 */ | |
673 | args.v3.sInput.usPixelClock = cpu_to_le16(dp_clock / 10); | |
674 | } else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { | |
bcc1c2a1 | 675 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
b4f15f80 AD |
676 | if (encoder_mode == ATOM_ENCODER_MODE_HDMI) |
677 | /* deep color support */ | |
678 | args.v3.sInput.usPixelClock = | |
679 | cpu_to_le16((mode->clock * bpc / 8) / 10); | |
680 | if (dig->coherent_mode) | |
bcc1c2a1 AD |
681 | args.v3.sInput.ucDispPllConfig |= |
682 | DISPPLL_CONFIG_COHERENT_MODE; | |
9aa59993 | 683 | if (is_duallink) |
bcc1c2a1 | 684 | args.v3.sInput.ucDispPllConfig |= |
b4f15f80 | 685 | DISPPLL_CONFIG_DUAL_LINK; |
bcc1c2a1 | 686 | } |
1d33e1fc AD |
687 | if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != |
688 | ENCODER_OBJECT_ID_NONE) | |
689 | args.v3.sInput.ucExtTransmitterID = | |
690 | radeon_encoder_get_dp_bridge_encoder_id(encoder); | |
691 | else | |
cc9f67a0 AD |
692 | args.v3.sInput.ucExtTransmitterID = 0; |
693 | ||
bcc1c2a1 AD |
694 | atom_execute_table(rdev->mode_info.atom_context, |
695 | index, (uint32_t *)&args); | |
696 | adjusted_clock = le32_to_cpu(args.v3.sOutput.ulDispPllFreq) * 10; | |
697 | if (args.v3.sOutput.ucRefDiv) { | |
9f4283f4 | 698 | pll->flags |= RADEON_PLL_USE_FRAC_FB_DIV; |
bcc1c2a1 AD |
699 | pll->flags |= RADEON_PLL_USE_REF_DIV; |
700 | pll->reference_div = args.v3.sOutput.ucRefDiv; | |
701 | } | |
702 | if (args.v3.sOutput.ucPostDiv) { | |
9f4283f4 | 703 | pll->flags |= RADEON_PLL_USE_FRAC_FB_DIV; |
bcc1c2a1 AD |
704 | pll->flags |= RADEON_PLL_USE_POST_DIV; |
705 | pll->post_div = args.v3.sOutput.ucPostDiv; | |
706 | } | |
707 | break; | |
4eaeca33 AD |
708 | default: |
709 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
710 | return adjusted_clock; | |
711 | } | |
712 | break; | |
713 | default: | |
714 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
715 | return adjusted_clock; | |
716 | } | |
d56ef9c8 | 717 | } |
4eaeca33 AD |
718 | return adjusted_clock; |
719 | } | |
720 | ||
721 | union set_pixel_clock { | |
722 | SET_PIXEL_CLOCK_PS_ALLOCATION base; | |
723 | PIXEL_CLOCK_PARAMETERS v1; | |
724 | PIXEL_CLOCK_PARAMETERS_V2 v2; | |
725 | PIXEL_CLOCK_PARAMETERS_V3 v3; | |
bcc1c2a1 | 726 | PIXEL_CLOCK_PARAMETERS_V5 v5; |
f82b3ddc | 727 | PIXEL_CLOCK_PARAMETERS_V6 v6; |
4eaeca33 AD |
728 | }; |
729 | ||
f82b3ddc AD |
730 | /* on DCE5, make sure the voltage is high enough to support the |
731 | * required disp clk. | |
732 | */ | |
f3f1f03e | 733 | static void atombios_crtc_set_disp_eng_pll(struct radeon_device *rdev, |
f82b3ddc | 734 | u32 dispclk) |
bcc1c2a1 | 735 | { |
bcc1c2a1 AD |
736 | u8 frev, crev; |
737 | int index; | |
738 | union set_pixel_clock args; | |
739 | ||
740 | memset(&args, 0, sizeof(args)); | |
741 | ||
742 | index = GetIndexIntoMasterTable(COMMAND, SetPixelClock); | |
a084e6ee AD |
743 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
744 | &crev)) | |
745 | return; | |
bcc1c2a1 AD |
746 | |
747 | switch (frev) { | |
748 | case 1: | |
749 | switch (crev) { | |
750 | case 5: | |
751 | /* if the default dcpll clock is specified, | |
752 | * SetPixelClock provides the dividers | |
753 | */ | |
754 | args.v5.ucCRTC = ATOM_CRTC_INVALID; | |
4589433c | 755 | args.v5.usPixelClock = cpu_to_le16(dispclk); |
bcc1c2a1 AD |
756 | args.v5.ucPpll = ATOM_DCPLL; |
757 | break; | |
f82b3ddc AD |
758 | case 6: |
759 | /* if the default dcpll clock is specified, | |
760 | * SetPixelClock provides the dividers | |
761 | */ | |
265aa6c8 | 762 | args.v6.ulDispEngClkFreq = cpu_to_le32(dispclk); |
729b95ef AD |
763 | if (ASIC_IS_DCE61(rdev)) |
764 | args.v6.ucPpll = ATOM_EXT_PLL1; | |
765 | else if (ASIC_IS_DCE6(rdev)) | |
f3f1f03e AD |
766 | args.v6.ucPpll = ATOM_PPLL0; |
767 | else | |
768 | args.v6.ucPpll = ATOM_DCPLL; | |
f82b3ddc | 769 | break; |
bcc1c2a1 AD |
770 | default: |
771 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
772 | return; | |
773 | } | |
774 | break; | |
775 | default: | |
776 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
777 | return; | |
778 | } | |
779 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); | |
780 | } | |
781 | ||
37f9003b | 782 | static void atombios_crtc_program_pll(struct drm_crtc *crtc, |
f1bece7f | 783 | u32 crtc_id, |
37f9003b AD |
784 | int pll_id, |
785 | u32 encoder_mode, | |
786 | u32 encoder_id, | |
787 | u32 clock, | |
788 | u32 ref_div, | |
789 | u32 fb_div, | |
790 | u32 frac_fb_div, | |
df271bec | 791 | u32 post_div, |
8e8e523d AD |
792 | int bpc, |
793 | bool ss_enabled, | |
794 | struct radeon_atom_ss *ss) | |
4eaeca33 | 795 | { |
4eaeca33 AD |
796 | struct drm_device *dev = crtc->dev; |
797 | struct radeon_device *rdev = dev->dev_private; | |
4eaeca33 | 798 | u8 frev, crev; |
37f9003b | 799 | int index = GetIndexIntoMasterTable(COMMAND, SetPixelClock); |
4eaeca33 | 800 | union set_pixel_clock args; |
4eaeca33 AD |
801 | |
802 | memset(&args, 0, sizeof(args)); | |
803 | ||
a084e6ee AD |
804 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
805 | &crev)) | |
806 | return; | |
771fe6b9 JG |
807 | |
808 | switch (frev) { | |
809 | case 1: | |
810 | switch (crev) { | |
811 | case 1: | |
37f9003b AD |
812 | if (clock == ATOM_DISABLE) |
813 | return; | |
814 | args.v1.usPixelClock = cpu_to_le16(clock / 10); | |
4eaeca33 AD |
815 | args.v1.usRefDiv = cpu_to_le16(ref_div); |
816 | args.v1.usFbDiv = cpu_to_le16(fb_div); | |
817 | args.v1.ucFracFbDiv = frac_fb_div; | |
818 | args.v1.ucPostDiv = post_div; | |
37f9003b AD |
819 | args.v1.ucPpll = pll_id; |
820 | args.v1.ucCRTC = crtc_id; | |
4eaeca33 | 821 | args.v1.ucRefDivSrc = 1; |
771fe6b9 JG |
822 | break; |
823 | case 2: | |
37f9003b | 824 | args.v2.usPixelClock = cpu_to_le16(clock / 10); |
4eaeca33 AD |
825 | args.v2.usRefDiv = cpu_to_le16(ref_div); |
826 | args.v2.usFbDiv = cpu_to_le16(fb_div); | |
827 | args.v2.ucFracFbDiv = frac_fb_div; | |
828 | args.v2.ucPostDiv = post_div; | |
37f9003b AD |
829 | args.v2.ucPpll = pll_id; |
830 | args.v2.ucCRTC = crtc_id; | |
4eaeca33 | 831 | args.v2.ucRefDivSrc = 1; |
771fe6b9 JG |
832 | break; |
833 | case 3: | |
37f9003b | 834 | args.v3.usPixelClock = cpu_to_le16(clock / 10); |
4eaeca33 AD |
835 | args.v3.usRefDiv = cpu_to_le16(ref_div); |
836 | args.v3.usFbDiv = cpu_to_le16(fb_div); | |
837 | args.v3.ucFracFbDiv = frac_fb_div; | |
838 | args.v3.ucPostDiv = post_div; | |
37f9003b | 839 | args.v3.ucPpll = pll_id; |
e729586e AD |
840 | if (crtc_id == ATOM_CRTC2) |
841 | args.v3.ucMiscInfo = PIXEL_CLOCK_MISC_CRTC_SEL_CRTC2; | |
842 | else | |
843 | args.v3.ucMiscInfo = PIXEL_CLOCK_MISC_CRTC_SEL_CRTC1; | |
6f15c506 AD |
844 | if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK)) |
845 | args.v3.ucMiscInfo |= PIXEL_CLOCK_MISC_REF_DIV_SRC; | |
37f9003b | 846 | args.v3.ucTransmitterId = encoder_id; |
bcc1c2a1 AD |
847 | args.v3.ucEncoderMode = encoder_mode; |
848 | break; | |
849 | case 5: | |
37f9003b AD |
850 | args.v5.ucCRTC = crtc_id; |
851 | args.v5.usPixelClock = cpu_to_le16(clock / 10); | |
bcc1c2a1 AD |
852 | args.v5.ucRefDiv = ref_div; |
853 | args.v5.usFbDiv = cpu_to_le16(fb_div); | |
854 | args.v5.ulFbDivDecFrac = cpu_to_le32(frac_fb_div * 100000); | |
855 | args.v5.ucPostDiv = post_div; | |
856 | args.v5.ucMiscInfo = 0; /* HDMI depth, etc. */ | |
8e8e523d AD |
857 | if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK)) |
858 | args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_REF_DIV_SRC; | |
df271bec AD |
859 | switch (bpc) { |
860 | case 8: | |
861 | default: | |
862 | args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_HDMI_24BPP; | |
863 | break; | |
864 | case 10: | |
865 | args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_HDMI_30BPP; | |
866 | break; | |
867 | } | |
37f9003b | 868 | args.v5.ucTransmitterID = encoder_id; |
bcc1c2a1 | 869 | args.v5.ucEncoderMode = encoder_mode; |
37f9003b | 870 | args.v5.ucPpll = pll_id; |
771fe6b9 | 871 | break; |
f82b3ddc | 872 | case 6: |
f1bece7f | 873 | args.v6.ulDispEngClkFreq = cpu_to_le32(crtc_id << 24 | clock / 10); |
f82b3ddc AD |
874 | args.v6.ucRefDiv = ref_div; |
875 | args.v6.usFbDiv = cpu_to_le16(fb_div); | |
876 | args.v6.ulFbDivDecFrac = cpu_to_le32(frac_fb_div * 100000); | |
877 | args.v6.ucPostDiv = post_div; | |
878 | args.v6.ucMiscInfo = 0; /* HDMI depth, etc. */ | |
8e8e523d AD |
879 | if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK)) |
880 | args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_REF_DIV_SRC; | |
df271bec AD |
881 | switch (bpc) { |
882 | case 8: | |
883 | default: | |
884 | args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_24BPP; | |
885 | break; | |
886 | case 10: | |
887 | args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_30BPP; | |
888 | break; | |
889 | case 12: | |
890 | args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_36BPP; | |
891 | break; | |
892 | case 16: | |
893 | args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_48BPP; | |
894 | break; | |
895 | } | |
f82b3ddc AD |
896 | args.v6.ucTransmitterID = encoder_id; |
897 | args.v6.ucEncoderMode = encoder_mode; | |
898 | args.v6.ucPpll = pll_id; | |
899 | break; | |
771fe6b9 JG |
900 | default: |
901 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
902 | return; | |
903 | } | |
904 | break; | |
905 | default: | |
906 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); | |
907 | return; | |
908 | } | |
909 | ||
771fe6b9 JG |
910 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
911 | } | |
912 | ||
37f9003b AD |
913 | static void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) |
914 | { | |
915 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
916 | struct drm_device *dev = crtc->dev; | |
917 | struct radeon_device *rdev = dev->dev_private; | |
918 | struct drm_encoder *encoder = NULL; | |
919 | struct radeon_encoder *radeon_encoder = NULL; | |
920 | u32 pll_clock = mode->clock; | |
921 | u32 ref_div = 0, fb_div = 0, frac_fb_div = 0, post_div = 0; | |
922 | struct radeon_pll *pll; | |
923 | u32 adjusted_clock; | |
924 | int encoder_mode = 0; | |
ba032a58 AD |
925 | struct radeon_atom_ss ss; |
926 | bool ss_enabled = false; | |
df271bec | 927 | int bpc = 8; |
37f9003b AD |
928 | |
929 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | |
930 | if (encoder->crtc == crtc) { | |
931 | radeon_encoder = to_radeon_encoder(encoder); | |
932 | encoder_mode = atombios_get_encoder_mode(encoder); | |
933 | break; | |
934 | } | |
935 | } | |
936 | ||
937 | if (!radeon_encoder) | |
938 | return; | |
939 | ||
940 | switch (radeon_crtc->pll_id) { | |
941 | case ATOM_PPLL1: | |
942 | pll = &rdev->clock.p1pll; | |
943 | break; | |
944 | case ATOM_PPLL2: | |
945 | pll = &rdev->clock.p2pll; | |
946 | break; | |
947 | case ATOM_DCPLL: | |
948 | case ATOM_PPLL_INVALID: | |
949 | default: | |
950 | pll = &rdev->clock.dcpll; | |
951 | break; | |
952 | } | |
953 | ||
700698e7 AD |
954 | if ((radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) || |
955 | (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)) { | |
ba032a58 AD |
956 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
957 | struct drm_connector *connector = | |
958 | radeon_get_connector_for_encoder(encoder); | |
959 | struct radeon_connector *radeon_connector = | |
960 | to_radeon_connector(connector); | |
961 | struct radeon_connector_atom_dig *dig_connector = | |
962 | radeon_connector->con_priv; | |
963 | int dp_clock; | |
eccea792 | 964 | bpc = radeon_get_monitor_bpc(connector); |
ba032a58 AD |
965 | |
966 | switch (encoder_mode) { | |
996d5c59 | 967 | case ATOM_ENCODER_MODE_DP_MST: |
ba032a58 AD |
968 | case ATOM_ENCODER_MODE_DP: |
969 | /* DP/eDP */ | |
970 | dp_clock = dig_connector->dp_clock / 10; | |
2307790f AD |
971 | if (ASIC_IS_DCE4(rdev)) |
972 | ss_enabled = | |
973 | radeon_atombios_get_asic_ss_info(rdev, &ss, | |
974 | ASIC_INTERNAL_SS_ON_DP, | |
975 | dp_clock); | |
976 | else { | |
977 | if (dp_clock == 16200) { | |
ba032a58 | 978 | ss_enabled = |
2307790f AD |
979 | radeon_atombios_get_ppll_ss_info(rdev, &ss, |
980 | ATOM_DP_SS_ID2); | |
8e8e523d AD |
981 | if (!ss_enabled) |
982 | ss_enabled = | |
2307790f AD |
983 | radeon_atombios_get_ppll_ss_info(rdev, &ss, |
984 | ATOM_DP_SS_ID1); | |
8e8e523d | 985 | } else |
ba032a58 AD |
986 | ss_enabled = |
987 | radeon_atombios_get_ppll_ss_info(rdev, &ss, | |
2307790f | 988 | ATOM_DP_SS_ID1); |
ba032a58 AD |
989 | } |
990 | break; | |
991 | case ATOM_ENCODER_MODE_LVDS: | |
992 | if (ASIC_IS_DCE4(rdev)) | |
993 | ss_enabled = radeon_atombios_get_asic_ss_info(rdev, &ss, | |
994 | dig->lcd_ss_id, | |
995 | mode->clock / 10); | |
996 | else | |
997 | ss_enabled = radeon_atombios_get_ppll_ss_info(rdev, &ss, | |
998 | dig->lcd_ss_id); | |
999 | break; | |
1000 | case ATOM_ENCODER_MODE_DVI: | |
1001 | if (ASIC_IS_DCE4(rdev)) | |
1002 | ss_enabled = | |
1003 | radeon_atombios_get_asic_ss_info(rdev, &ss, | |
1004 | ASIC_INTERNAL_SS_ON_TMDS, | |
1005 | mode->clock / 10); | |
1006 | break; | |
1007 | case ATOM_ENCODER_MODE_HDMI: | |
1008 | if (ASIC_IS_DCE4(rdev)) | |
1009 | ss_enabled = | |
1010 | radeon_atombios_get_asic_ss_info(rdev, &ss, | |
1011 | ASIC_INTERNAL_SS_ON_HDMI, | |
1012 | mode->clock / 10); | |
1013 | break; | |
1014 | default: | |
1015 | break; | |
1016 | } | |
1017 | } | |
1018 | ||
37f9003b | 1019 | /* adjust pixel clock as needed */ |
ba032a58 | 1020 | adjusted_clock = atombios_adjust_pll(crtc, mode, pll, ss_enabled, &ss); |
37f9003b | 1021 | |
64146f8b AD |
1022 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) |
1023 | /* TV seems to prefer the legacy algo on some boards */ | |
1024 | radeon_compute_pll_legacy(pll, adjusted_clock, &pll_clock, &fb_div, &frac_fb_div, | |
1025 | &ref_div, &post_div); | |
1026 | else if (ASIC_IS_AVIVO(rdev)) | |
619efb10 AD |
1027 | radeon_compute_pll_avivo(pll, adjusted_clock, &pll_clock, &fb_div, &frac_fb_div, |
1028 | &ref_div, &post_div); | |
1029 | else | |
1030 | radeon_compute_pll_legacy(pll, adjusted_clock, &pll_clock, &fb_div, &frac_fb_div, | |
1031 | &ref_div, &post_div); | |
37f9003b | 1032 | |
5efcc76c | 1033 | atombios_crtc_program_ss(rdev, ATOM_DISABLE, radeon_crtc->pll_id, radeon_crtc->crtc_id, &ss); |
ba032a58 | 1034 | |
37f9003b AD |
1035 | atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id, |
1036 | encoder_mode, radeon_encoder->encoder_id, mode->clock, | |
8e8e523d | 1037 | ref_div, fb_div, frac_fb_div, post_div, bpc, ss_enabled, &ss); |
37f9003b | 1038 | |
ba032a58 AD |
1039 | if (ss_enabled) { |
1040 | /* calculate ss amount and step size */ | |
1041 | if (ASIC_IS_DCE4(rdev)) { | |
1042 | u32 step_size; | |
1043 | u32 amount = (((fb_div * 10) + frac_fb_div) * ss.percentage) / 10000; | |
1044 | ss.amount = (amount / 10) & ATOM_PPLL_SS_AMOUNT_V2_FBDIV_MASK; | |
8e8e523d | 1045 | ss.amount |= ((amount - (amount / 10)) << ATOM_PPLL_SS_AMOUNT_V2_NFRAC_SHIFT) & |
ba032a58 AD |
1046 | ATOM_PPLL_SS_AMOUNT_V2_NFRAC_MASK; |
1047 | if (ss.type & ATOM_PPLL_SS_TYPE_V2_CENTRE_SPREAD) | |
1048 | step_size = (4 * amount * ref_div * (ss.rate * 2048)) / | |
1049 | (125 * 25 * pll->reference_freq / 100); | |
1050 | else | |
1051 | step_size = (2 * amount * ref_div * (ss.rate * 2048)) / | |
1052 | (125 * 25 * pll->reference_freq / 100); | |
1053 | ss.step = step_size; | |
1054 | } | |
1055 | ||
5efcc76c | 1056 | atombios_crtc_program_ss(rdev, ATOM_ENABLE, radeon_crtc->pll_id, radeon_crtc->crtc_id, &ss); |
ba032a58 | 1057 | } |
37f9003b AD |
1058 | } |
1059 | ||
c9417bdd AD |
1060 | static int dce4_crtc_do_set_base(struct drm_crtc *crtc, |
1061 | struct drm_framebuffer *fb, | |
1062 | int x, int y, int atomic) | |
bcc1c2a1 AD |
1063 | { |
1064 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
1065 | struct drm_device *dev = crtc->dev; | |
1066 | struct radeon_device *rdev = dev->dev_private; | |
1067 | struct radeon_framebuffer *radeon_fb; | |
4dd19b0d | 1068 | struct drm_framebuffer *target_fb; |
bcc1c2a1 AD |
1069 | struct drm_gem_object *obj; |
1070 | struct radeon_bo *rbo; | |
1071 | uint64_t fb_location; | |
1072 | uint32_t fb_format, fb_pitch_pixels, tiling_flags; | |
285484e2 | 1073 | unsigned bankw, bankh, mtaspect, tile_split; |
fa6bee46 | 1074 | u32 fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_NONE); |
adcfde51 | 1075 | u32 tmp, viewport_w, viewport_h; |
bcc1c2a1 AD |
1076 | int r; |
1077 | ||
1078 | /* no fb bound */ | |
4dd19b0d | 1079 | if (!atomic && !crtc->fb) { |
d9fdaafb | 1080 | DRM_DEBUG_KMS("No FB bound\n"); |
bcc1c2a1 AD |
1081 | return 0; |
1082 | } | |
1083 | ||
4dd19b0d CB |
1084 | if (atomic) { |
1085 | radeon_fb = to_radeon_framebuffer(fb); | |
1086 | target_fb = fb; | |
1087 | } | |
1088 | else { | |
1089 | radeon_fb = to_radeon_framebuffer(crtc->fb); | |
1090 | target_fb = crtc->fb; | |
1091 | } | |
bcc1c2a1 | 1092 | |
4dd19b0d CB |
1093 | /* If atomic, assume fb object is pinned & idle & fenced and |
1094 | * just update base pointers | |
1095 | */ | |
bcc1c2a1 | 1096 | obj = radeon_fb->obj; |
7e4d15d9 | 1097 | rbo = gem_to_radeon_bo(obj); |
bcc1c2a1 AD |
1098 | r = radeon_bo_reserve(rbo, false); |
1099 | if (unlikely(r != 0)) | |
1100 | return r; | |
4dd19b0d CB |
1101 | |
1102 | if (atomic) | |
1103 | fb_location = radeon_bo_gpu_offset(rbo); | |
1104 | else { | |
1105 | r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_location); | |
1106 | if (unlikely(r != 0)) { | |
1107 | radeon_bo_unreserve(rbo); | |
1108 | return -EINVAL; | |
1109 | } | |
bcc1c2a1 | 1110 | } |
4dd19b0d | 1111 | |
bcc1c2a1 AD |
1112 | radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); |
1113 | radeon_bo_unreserve(rbo); | |
1114 | ||
4dd19b0d | 1115 | switch (target_fb->bits_per_pixel) { |
bcc1c2a1 AD |
1116 | case 8: |
1117 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_8BPP) | | |
1118 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_INDEXED)); | |
1119 | break; | |
1120 | case 15: | |
1121 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | | |
1122 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB1555)); | |
1123 | break; | |
1124 | case 16: | |
1125 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | | |
1126 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB565)); | |
fa6bee46 AD |
1127 | #ifdef __BIG_ENDIAN |
1128 | fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN16); | |
1129 | #endif | |
bcc1c2a1 AD |
1130 | break; |
1131 | case 24: | |
1132 | case 32: | |
1133 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_32BPP) | | |
1134 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB8888)); | |
fa6bee46 AD |
1135 | #ifdef __BIG_ENDIAN |
1136 | fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN32); | |
1137 | #endif | |
bcc1c2a1 AD |
1138 | break; |
1139 | default: | |
1140 | DRM_ERROR("Unsupported screen depth %d\n", | |
4dd19b0d | 1141 | target_fb->bits_per_pixel); |
bcc1c2a1 AD |
1142 | return -EINVAL; |
1143 | } | |
1144 | ||
392e3722 | 1145 | if (tiling_flags & RADEON_TILING_MACRO) { |
b7019b2f AD |
1146 | if (rdev->family >= CHIP_TAHITI) |
1147 | tmp = rdev->config.si.tile_config; | |
1148 | else if (rdev->family >= CHIP_CAYMAN) | |
392e3722 AD |
1149 | tmp = rdev->config.cayman.tile_config; |
1150 | else | |
1151 | tmp = rdev->config.evergreen.tile_config; | |
1152 | ||
1153 | switch ((tmp & 0xf0) >> 4) { | |
1154 | case 0: /* 4 banks */ | |
1155 | fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_4_BANK); | |
1156 | break; | |
1157 | case 1: /* 8 banks */ | |
1158 | default: | |
1159 | fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_8_BANK); | |
1160 | break; | |
1161 | case 2: /* 16 banks */ | |
1162 | fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_16_BANK); | |
1163 | break; | |
1164 | } | |
1165 | ||
97d66328 | 1166 | fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_2D_TILED_THIN1); |
285484e2 JG |
1167 | |
1168 | evergreen_tiling_fields(tiling_flags, &bankw, &bankh, &mtaspect, &tile_split); | |
1169 | fb_format |= EVERGREEN_GRPH_TILE_SPLIT(tile_split); | |
1170 | fb_format |= EVERGREEN_GRPH_BANK_WIDTH(bankw); | |
1171 | fb_format |= EVERGREEN_GRPH_BANK_HEIGHT(bankh); | |
1172 | fb_format |= EVERGREEN_GRPH_MACRO_TILE_ASPECT(mtaspect); | |
392e3722 | 1173 | } else if (tiling_flags & RADEON_TILING_MICRO) |
97d66328 AD |
1174 | fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_1D_TILED_THIN1); |
1175 | ||
b7019b2f AD |
1176 | if ((rdev->family == CHIP_TAHITI) || |
1177 | (rdev->family == CHIP_PITCAIRN)) | |
1178 | fb_format |= SI_GRPH_PIPE_CONFIG(SI_ADDR_SURF_P8_32x32_8x16); | |
1179 | else if (rdev->family == CHIP_VERDE) | |
1180 | fb_format |= SI_GRPH_PIPE_CONFIG(SI_ADDR_SURF_P4_8x16); | |
1181 | ||
bcc1c2a1 AD |
1182 | switch (radeon_crtc->crtc_id) { |
1183 | case 0: | |
1184 | WREG32(AVIVO_D1VGA_CONTROL, 0); | |
1185 | break; | |
1186 | case 1: | |
1187 | WREG32(AVIVO_D2VGA_CONTROL, 0); | |
1188 | break; | |
1189 | case 2: | |
1190 | WREG32(EVERGREEN_D3VGA_CONTROL, 0); | |
1191 | break; | |
1192 | case 3: | |
1193 | WREG32(EVERGREEN_D4VGA_CONTROL, 0); | |
1194 | break; | |
1195 | case 4: | |
1196 | WREG32(EVERGREEN_D5VGA_CONTROL, 0); | |
1197 | break; | |
1198 | case 5: | |
1199 | WREG32(EVERGREEN_D6VGA_CONTROL, 0); | |
1200 | break; | |
1201 | default: | |
1202 | break; | |
1203 | } | |
1204 | ||
1205 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, | |
1206 | upper_32_bits(fb_location)); | |
1207 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, | |
1208 | upper_32_bits(fb_location)); | |
1209 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, | |
1210 | (u32)fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); | |
1211 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, | |
1212 | (u32) fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); | |
1213 | WREG32(EVERGREEN_GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format); | |
fa6bee46 | 1214 | WREG32(EVERGREEN_GRPH_SWAP_CONTROL + radeon_crtc->crtc_offset, fb_swap); |
bcc1c2a1 AD |
1215 | |
1216 | WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0); | |
1217 | WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0); | |
1218 | WREG32(EVERGREEN_GRPH_X_START + radeon_crtc->crtc_offset, 0); | |
1219 | WREG32(EVERGREEN_GRPH_Y_START + radeon_crtc->crtc_offset, 0); | |
4dd19b0d CB |
1220 | WREG32(EVERGREEN_GRPH_X_END + radeon_crtc->crtc_offset, target_fb->width); |
1221 | WREG32(EVERGREEN_GRPH_Y_END + radeon_crtc->crtc_offset, target_fb->height); | |
bcc1c2a1 | 1222 | |
01f2c773 | 1223 | fb_pitch_pixels = target_fb->pitches[0] / (target_fb->bits_per_pixel / 8); |
bcc1c2a1 AD |
1224 | WREG32(EVERGREEN_GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels); |
1225 | WREG32(EVERGREEN_GRPH_ENABLE + radeon_crtc->crtc_offset, 1); | |
1226 | ||
1227 | WREG32(EVERGREEN_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, | |
1b619250 | 1228 | target_fb->height); |
bcc1c2a1 AD |
1229 | x &= ~3; |
1230 | y &= ~1; | |
1231 | WREG32(EVERGREEN_VIEWPORT_START + radeon_crtc->crtc_offset, | |
1232 | (x << 16) | y); | |
adcfde51 AD |
1233 | viewport_w = crtc->mode.hdisplay; |
1234 | viewport_h = (crtc->mode.vdisplay + 1) & ~1; | |
bcc1c2a1 | 1235 | WREG32(EVERGREEN_VIEWPORT_SIZE + radeon_crtc->crtc_offset, |
adcfde51 | 1236 | (viewport_w << 16) | viewport_h); |
bcc1c2a1 | 1237 | |
fb9674bd AD |
1238 | /* pageflip setup */ |
1239 | /* make sure flip is at vb rather than hb */ | |
1240 | tmp = RREG32(EVERGREEN_GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset); | |
1241 | tmp &= ~EVERGREEN_GRPH_SURFACE_UPDATE_H_RETRACE_EN; | |
1242 | WREG32(EVERGREEN_GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset, tmp); | |
1243 | ||
1244 | /* set pageflip to happen anywhere in vblank interval */ | |
1245 | WREG32(EVERGREEN_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 0); | |
1246 | ||
4dd19b0d CB |
1247 | if (!atomic && fb && fb != crtc->fb) { |
1248 | radeon_fb = to_radeon_framebuffer(fb); | |
7e4d15d9 | 1249 | rbo = gem_to_radeon_bo(radeon_fb->obj); |
bcc1c2a1 AD |
1250 | r = radeon_bo_reserve(rbo, false); |
1251 | if (unlikely(r != 0)) | |
1252 | return r; | |
1253 | radeon_bo_unpin(rbo); | |
1254 | radeon_bo_unreserve(rbo); | |
1255 | } | |
1256 | ||
1257 | /* Bytes per pixel may have changed */ | |
1258 | radeon_bandwidth_update(rdev); | |
1259 | ||
1260 | return 0; | |
1261 | } | |
1262 | ||
4dd19b0d CB |
1263 | static int avivo_crtc_do_set_base(struct drm_crtc *crtc, |
1264 | struct drm_framebuffer *fb, | |
1265 | int x, int y, int atomic) | |
771fe6b9 JG |
1266 | { |
1267 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
1268 | struct drm_device *dev = crtc->dev; | |
1269 | struct radeon_device *rdev = dev->dev_private; | |
1270 | struct radeon_framebuffer *radeon_fb; | |
1271 | struct drm_gem_object *obj; | |
4c788679 | 1272 | struct radeon_bo *rbo; |
4dd19b0d | 1273 | struct drm_framebuffer *target_fb; |
771fe6b9 | 1274 | uint64_t fb_location; |
e024e110 | 1275 | uint32_t fb_format, fb_pitch_pixels, tiling_flags; |
fa6bee46 | 1276 | u32 fb_swap = R600_D1GRPH_SWAP_ENDIAN_NONE; |
adcfde51 | 1277 | u32 tmp, viewport_w, viewport_h; |
4c788679 | 1278 | int r; |
771fe6b9 | 1279 | |
2de3b484 | 1280 | /* no fb bound */ |
4dd19b0d | 1281 | if (!atomic && !crtc->fb) { |
d9fdaafb | 1282 | DRM_DEBUG_KMS("No FB bound\n"); |
2de3b484 JG |
1283 | return 0; |
1284 | } | |
771fe6b9 | 1285 | |
4dd19b0d CB |
1286 | if (atomic) { |
1287 | radeon_fb = to_radeon_framebuffer(fb); | |
1288 | target_fb = fb; | |
1289 | } | |
1290 | else { | |
1291 | radeon_fb = to_radeon_framebuffer(crtc->fb); | |
1292 | target_fb = crtc->fb; | |
1293 | } | |
771fe6b9 JG |
1294 | |
1295 | obj = radeon_fb->obj; | |
7e4d15d9 | 1296 | rbo = gem_to_radeon_bo(obj); |
4c788679 JG |
1297 | r = radeon_bo_reserve(rbo, false); |
1298 | if (unlikely(r != 0)) | |
1299 | return r; | |
4dd19b0d CB |
1300 | |
1301 | /* If atomic, assume fb object is pinned & idle & fenced and | |
1302 | * just update base pointers | |
1303 | */ | |
1304 | if (atomic) | |
1305 | fb_location = radeon_bo_gpu_offset(rbo); | |
1306 | else { | |
1307 | r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_location); | |
1308 | if (unlikely(r != 0)) { | |
1309 | radeon_bo_unreserve(rbo); | |
1310 | return -EINVAL; | |
1311 | } | |
771fe6b9 | 1312 | } |
4c788679 JG |
1313 | radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); |
1314 | radeon_bo_unreserve(rbo); | |
771fe6b9 | 1315 | |
4dd19b0d | 1316 | switch (target_fb->bits_per_pixel) { |
41456df2 DA |
1317 | case 8: |
1318 | fb_format = | |
1319 | AVIVO_D1GRPH_CONTROL_DEPTH_8BPP | | |
1320 | AVIVO_D1GRPH_CONTROL_8BPP_INDEXED; | |
1321 | break; | |
771fe6b9 JG |
1322 | case 15: |
1323 | fb_format = | |
1324 | AVIVO_D1GRPH_CONTROL_DEPTH_16BPP | | |
1325 | AVIVO_D1GRPH_CONTROL_16BPP_ARGB1555; | |
1326 | break; | |
1327 | case 16: | |
1328 | fb_format = | |
1329 | AVIVO_D1GRPH_CONTROL_DEPTH_16BPP | | |
1330 | AVIVO_D1GRPH_CONTROL_16BPP_RGB565; | |
fa6bee46 AD |
1331 | #ifdef __BIG_ENDIAN |
1332 | fb_swap = R600_D1GRPH_SWAP_ENDIAN_16BIT; | |
1333 | #endif | |
771fe6b9 JG |
1334 | break; |
1335 | case 24: | |
1336 | case 32: | |
1337 | fb_format = | |
1338 | AVIVO_D1GRPH_CONTROL_DEPTH_32BPP | | |
1339 | AVIVO_D1GRPH_CONTROL_32BPP_ARGB8888; | |
fa6bee46 AD |
1340 | #ifdef __BIG_ENDIAN |
1341 | fb_swap = R600_D1GRPH_SWAP_ENDIAN_32BIT; | |
1342 | #endif | |
771fe6b9 JG |
1343 | break; |
1344 | default: | |
1345 | DRM_ERROR("Unsupported screen depth %d\n", | |
4dd19b0d | 1346 | target_fb->bits_per_pixel); |
771fe6b9 JG |
1347 | return -EINVAL; |
1348 | } | |
1349 | ||
40c4ac1c AD |
1350 | if (rdev->family >= CHIP_R600) { |
1351 | if (tiling_flags & RADEON_TILING_MACRO) | |
1352 | fb_format |= R600_D1GRPH_ARRAY_MODE_2D_TILED_THIN1; | |
1353 | else if (tiling_flags & RADEON_TILING_MICRO) | |
1354 | fb_format |= R600_D1GRPH_ARRAY_MODE_1D_TILED_THIN1; | |
1355 | } else { | |
1356 | if (tiling_flags & RADEON_TILING_MACRO) | |
1357 | fb_format |= AVIVO_D1GRPH_MACRO_ADDRESS_MODE; | |
cf2f05d3 | 1358 | |
40c4ac1c AD |
1359 | if (tiling_flags & RADEON_TILING_MICRO) |
1360 | fb_format |= AVIVO_D1GRPH_TILED; | |
1361 | } | |
e024e110 | 1362 | |
771fe6b9 JG |
1363 | if (radeon_crtc->crtc_id == 0) |
1364 | WREG32(AVIVO_D1VGA_CONTROL, 0); | |
1365 | else | |
1366 | WREG32(AVIVO_D2VGA_CONTROL, 0); | |
c290dadf AD |
1367 | |
1368 | if (rdev->family >= CHIP_RV770) { | |
1369 | if (radeon_crtc->crtc_id) { | |
95347871 AD |
1370 | WREG32(R700_D2GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); |
1371 | WREG32(R700_D2GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); | |
c290dadf | 1372 | } else { |
95347871 AD |
1373 | WREG32(R700_D1GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); |
1374 | WREG32(R700_D1GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); | |
c290dadf AD |
1375 | } |
1376 | } | |
771fe6b9 JG |
1377 | WREG32(AVIVO_D1GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
1378 | (u32) fb_location); | |
1379 | WREG32(AVIVO_D1GRPH_SECONDARY_SURFACE_ADDRESS + | |
1380 | radeon_crtc->crtc_offset, (u32) fb_location); | |
1381 | WREG32(AVIVO_D1GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format); | |
fa6bee46 AD |
1382 | if (rdev->family >= CHIP_R600) |
1383 | WREG32(R600_D1GRPH_SWAP_CONTROL + radeon_crtc->crtc_offset, fb_swap); | |
771fe6b9 JG |
1384 | |
1385 | WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0); | |
1386 | WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0); | |
1387 | WREG32(AVIVO_D1GRPH_X_START + radeon_crtc->crtc_offset, 0); | |
1388 | WREG32(AVIVO_D1GRPH_Y_START + radeon_crtc->crtc_offset, 0); | |
4dd19b0d CB |
1389 | WREG32(AVIVO_D1GRPH_X_END + radeon_crtc->crtc_offset, target_fb->width); |
1390 | WREG32(AVIVO_D1GRPH_Y_END + radeon_crtc->crtc_offset, target_fb->height); | |
771fe6b9 | 1391 | |
01f2c773 | 1392 | fb_pitch_pixels = target_fb->pitches[0] / (target_fb->bits_per_pixel / 8); |
771fe6b9 JG |
1393 | WREG32(AVIVO_D1GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels); |
1394 | WREG32(AVIVO_D1GRPH_ENABLE + radeon_crtc->crtc_offset, 1); | |
1395 | ||
1396 | WREG32(AVIVO_D1MODE_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, | |
1b619250 | 1397 | target_fb->height); |
771fe6b9 JG |
1398 | x &= ~3; |
1399 | y &= ~1; | |
1400 | WREG32(AVIVO_D1MODE_VIEWPORT_START + radeon_crtc->crtc_offset, | |
1401 | (x << 16) | y); | |
adcfde51 AD |
1402 | viewport_w = crtc->mode.hdisplay; |
1403 | viewport_h = (crtc->mode.vdisplay + 1) & ~1; | |
771fe6b9 | 1404 | WREG32(AVIVO_D1MODE_VIEWPORT_SIZE + radeon_crtc->crtc_offset, |
adcfde51 | 1405 | (viewport_w << 16) | viewport_h); |
771fe6b9 | 1406 | |
fb9674bd AD |
1407 | /* pageflip setup */ |
1408 | /* make sure flip is at vb rather than hb */ | |
1409 | tmp = RREG32(AVIVO_D1GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset); | |
1410 | tmp &= ~AVIVO_D1GRPH_SURFACE_UPDATE_H_RETRACE_EN; | |
1411 | WREG32(AVIVO_D1GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset, tmp); | |
1412 | ||
1413 | /* set pageflip to happen anywhere in vblank interval */ | |
1414 | WREG32(AVIVO_D1MODE_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 0); | |
1415 | ||
4dd19b0d CB |
1416 | if (!atomic && fb && fb != crtc->fb) { |
1417 | radeon_fb = to_radeon_framebuffer(fb); | |
7e4d15d9 | 1418 | rbo = gem_to_radeon_bo(radeon_fb->obj); |
4c788679 JG |
1419 | r = radeon_bo_reserve(rbo, false); |
1420 | if (unlikely(r != 0)) | |
1421 | return r; | |
1422 | radeon_bo_unpin(rbo); | |
1423 | radeon_bo_unreserve(rbo); | |
771fe6b9 | 1424 | } |
f30f37de MD |
1425 | |
1426 | /* Bytes per pixel may have changed */ | |
1427 | radeon_bandwidth_update(rdev); | |
1428 | ||
771fe6b9 JG |
1429 | return 0; |
1430 | } | |
1431 | ||
54f088a9 AD |
1432 | int atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y, |
1433 | struct drm_framebuffer *old_fb) | |
1434 | { | |
1435 | struct drm_device *dev = crtc->dev; | |
1436 | struct radeon_device *rdev = dev->dev_private; | |
1437 | ||
bcc1c2a1 | 1438 | if (ASIC_IS_DCE4(rdev)) |
c9417bdd | 1439 | return dce4_crtc_do_set_base(crtc, old_fb, x, y, 0); |
4dd19b0d CB |
1440 | else if (ASIC_IS_AVIVO(rdev)) |
1441 | return avivo_crtc_do_set_base(crtc, old_fb, x, y, 0); | |
1442 | else | |
1443 | return radeon_crtc_do_set_base(crtc, old_fb, x, y, 0); | |
1444 | } | |
1445 | ||
1446 | int atombios_crtc_set_base_atomic(struct drm_crtc *crtc, | |
1447 | struct drm_framebuffer *fb, | |
21c74a8e | 1448 | int x, int y, enum mode_set_atomic state) |
4dd19b0d CB |
1449 | { |
1450 | struct drm_device *dev = crtc->dev; | |
1451 | struct radeon_device *rdev = dev->dev_private; | |
1452 | ||
1453 | if (ASIC_IS_DCE4(rdev)) | |
c9417bdd | 1454 | return dce4_crtc_do_set_base(crtc, fb, x, y, 1); |
bcc1c2a1 | 1455 | else if (ASIC_IS_AVIVO(rdev)) |
4dd19b0d | 1456 | return avivo_crtc_do_set_base(crtc, fb, x, y, 1); |
54f088a9 | 1457 | else |
4dd19b0d | 1458 | return radeon_crtc_do_set_base(crtc, fb, x, y, 1); |
54f088a9 AD |
1459 | } |
1460 | ||
615e0cb6 AD |
1461 | /* properly set additional regs when using atombios */ |
1462 | static void radeon_legacy_atom_fixup(struct drm_crtc *crtc) | |
1463 | { | |
1464 | struct drm_device *dev = crtc->dev; | |
1465 | struct radeon_device *rdev = dev->dev_private; | |
1466 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
1467 | u32 disp_merge_cntl; | |
1468 | ||
1469 | switch (radeon_crtc->crtc_id) { | |
1470 | case 0: | |
1471 | disp_merge_cntl = RREG32(RADEON_DISP_MERGE_CNTL); | |
1472 | disp_merge_cntl &= ~RADEON_DISP_RGB_OFFSET_EN; | |
1473 | WREG32(RADEON_DISP_MERGE_CNTL, disp_merge_cntl); | |
1474 | break; | |
1475 | case 1: | |
1476 | disp_merge_cntl = RREG32(RADEON_DISP2_MERGE_CNTL); | |
1477 | disp_merge_cntl &= ~RADEON_DISP2_RGB_OFFSET_EN; | |
1478 | WREG32(RADEON_DISP2_MERGE_CNTL, disp_merge_cntl); | |
1479 | WREG32(RADEON_FP_H2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_H_SYNC_STRT_WID)); | |
1480 | WREG32(RADEON_FP_V2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_V_SYNC_STRT_WID)); | |
1481 | break; | |
1482 | } | |
1483 | } | |
1484 | ||
bcc1c2a1 AD |
1485 | static int radeon_atom_pick_pll(struct drm_crtc *crtc) |
1486 | { | |
1487 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
1488 | struct drm_device *dev = crtc->dev; | |
1489 | struct radeon_device *rdev = dev->dev_private; | |
1490 | struct drm_encoder *test_encoder; | |
2f1f4d9b AD |
1491 | struct drm_crtc *test_crtc; |
1492 | uint32_t pll_in_use = 0; | |
bcc1c2a1 | 1493 | |
24e1f794 AD |
1494 | if (ASIC_IS_DCE61(rdev)) { |
1495 | list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) { | |
1496 | if (test_encoder->crtc && (test_encoder->crtc == crtc)) { | |
1497 | struct radeon_encoder *test_radeon_encoder = | |
1498 | to_radeon_encoder(test_encoder); | |
1499 | struct radeon_encoder_atom_dig *dig = | |
1500 | test_radeon_encoder->enc_priv; | |
1501 | ||
1502 | if ((test_radeon_encoder->encoder_id == | |
1503 | ENCODER_OBJECT_ID_INTERNAL_UNIPHY) && | |
2f1f4d9b | 1504 | (dig->linkb == false)) /* UNIPHY A uses PPLL2 */ |
24e1f794 AD |
1505 | return ATOM_PPLL2; |
1506 | } | |
1507 | } | |
1508 | /* UNIPHY B/C/D/E/F */ | |
2f1f4d9b AD |
1509 | list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) { |
1510 | struct radeon_crtc *radeon_test_crtc; | |
1511 | ||
1512 | if (crtc == test_crtc) | |
1513 | continue; | |
1514 | ||
1515 | radeon_test_crtc = to_radeon_crtc(test_crtc); | |
1516 | if ((radeon_test_crtc->pll_id == ATOM_PPLL0) || | |
1517 | (radeon_test_crtc->pll_id == ATOM_PPLL1)) | |
1518 | pll_in_use |= (1 << radeon_test_crtc->pll_id); | |
1519 | } | |
1520 | if (!(pll_in_use & 4)) | |
24e1f794 | 1521 | return ATOM_PPLL0; |
2f1f4d9b | 1522 | return ATOM_PPLL1; |
24e1f794 | 1523 | } else if (ASIC_IS_DCE4(rdev)) { |
bcc1c2a1 AD |
1524 | list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) { |
1525 | if (test_encoder->crtc && (test_encoder->crtc == crtc)) { | |
86a94def AD |
1526 | /* in DP mode, the DP ref clock can come from PPLL, DCPLL, or ext clock, |
1527 | * depending on the asic: | |
1528 | * DCE4: PPLL or ext clock | |
2f1f4d9b | 1529 | * DCE5: DCPLL or ext clock |
86a94def AD |
1530 | * |
1531 | * Setting ATOM_PPLL_INVALID will cause SetPixelClock to skip | |
1532 | * PPLL/DCPLL programming and only program the DP DTO for the | |
1533 | * crtc virtual pixel clock. | |
1534 | */ | |
996d5c59 | 1535 | if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(test_encoder))) { |
ecd67955 AD |
1536 | if (rdev->clock.dp_extclk) |
1537 | return ATOM_PPLL_INVALID; | |
26fe45a0 AD |
1538 | else if (ASIC_IS_DCE6(rdev)) |
1539 | return ATOM_PPLL0; | |
ecd67955 AD |
1540 | else if (ASIC_IS_DCE5(rdev)) |
1541 | return ATOM_DCPLL; | |
bcc1c2a1 AD |
1542 | } |
1543 | } | |
1544 | } | |
2f1f4d9b AD |
1545 | |
1546 | /* otherwise, pick one of the plls */ | |
1547 | list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) { | |
1548 | struct radeon_crtc *radeon_test_crtc; | |
1549 | ||
1550 | if (crtc == test_crtc) | |
1551 | continue; | |
1552 | ||
1553 | radeon_test_crtc = to_radeon_crtc(test_crtc); | |
1554 | if ((radeon_test_crtc->pll_id >= ATOM_PPLL1) && | |
1555 | (radeon_test_crtc->pll_id <= ATOM_PPLL2)) | |
1556 | pll_in_use |= (1 << radeon_test_crtc->pll_id); | |
1557 | } | |
1558 | if (!(pll_in_use & 1)) | |
bcc1c2a1 | 1559 | return ATOM_PPLL1; |
2f1f4d9b | 1560 | return ATOM_PPLL2; |
bcc1c2a1 AD |
1561 | } else |
1562 | return radeon_crtc->crtc_id; | |
1563 | ||
1564 | } | |
1565 | ||
f3f1f03e | 1566 | void radeon_atom_disp_eng_pll_init(struct radeon_device *rdev) |
3fa47d9e AD |
1567 | { |
1568 | /* always set DCPLL */ | |
f3f1f03e AD |
1569 | if (ASIC_IS_DCE6(rdev)) |
1570 | atombios_crtc_set_disp_eng_pll(rdev, rdev->clock.default_dispclk); | |
1571 | else if (ASIC_IS_DCE4(rdev)) { | |
3fa47d9e AD |
1572 | struct radeon_atom_ss ss; |
1573 | bool ss_enabled = radeon_atombios_get_asic_ss_info(rdev, &ss, | |
1574 | ASIC_INTERNAL_SS_ON_DCPLL, | |
1575 | rdev->clock.default_dispclk); | |
1576 | if (ss_enabled) | |
5efcc76c | 1577 | atombios_crtc_program_ss(rdev, ATOM_DISABLE, ATOM_DCPLL, -1, &ss); |
3fa47d9e | 1578 | /* XXX: DCE5, make sure voltage, dispclk is high enough */ |
f3f1f03e | 1579 | atombios_crtc_set_disp_eng_pll(rdev, rdev->clock.default_dispclk); |
3fa47d9e | 1580 | if (ss_enabled) |
5efcc76c | 1581 | atombios_crtc_program_ss(rdev, ATOM_ENABLE, ATOM_DCPLL, -1, &ss); |
3fa47d9e AD |
1582 | } |
1583 | ||
1584 | } | |
1585 | ||
771fe6b9 JG |
1586 | int atombios_crtc_mode_set(struct drm_crtc *crtc, |
1587 | struct drm_display_mode *mode, | |
1588 | struct drm_display_mode *adjusted_mode, | |
1589 | int x, int y, struct drm_framebuffer *old_fb) | |
1590 | { | |
1591 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
1592 | struct drm_device *dev = crtc->dev; | |
1593 | struct radeon_device *rdev = dev->dev_private; | |
54bfe496 AD |
1594 | struct drm_encoder *encoder; |
1595 | bool is_tvcv = false; | |
771fe6b9 | 1596 | |
54bfe496 AD |
1597 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
1598 | /* find tv std */ | |
1599 | if (encoder->crtc == crtc) { | |
1600 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); | |
1601 | if (radeon_encoder->active_device & | |
1602 | (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) | |
1603 | is_tvcv = true; | |
1604 | } | |
1605 | } | |
771fe6b9 JG |
1606 | |
1607 | atombios_crtc_set_pll(crtc, adjusted_mode); | |
771fe6b9 | 1608 | |
54bfe496 | 1609 | if (ASIC_IS_DCE4(rdev)) |
bcc1c2a1 | 1610 | atombios_set_crtc_dtd_timing(crtc, adjusted_mode); |
54bfe496 AD |
1611 | else if (ASIC_IS_AVIVO(rdev)) { |
1612 | if (is_tvcv) | |
1613 | atombios_crtc_set_timing(crtc, adjusted_mode); | |
1614 | else | |
1615 | atombios_set_crtc_dtd_timing(crtc, adjusted_mode); | |
1616 | } else { | |
bcc1c2a1 | 1617 | atombios_crtc_set_timing(crtc, adjusted_mode); |
5a9bcacc AD |
1618 | if (radeon_crtc->crtc_id == 0) |
1619 | atombios_set_crtc_dtd_timing(crtc, adjusted_mode); | |
615e0cb6 | 1620 | radeon_legacy_atom_fixup(crtc); |
771fe6b9 | 1621 | } |
bcc1c2a1 | 1622 | atombios_crtc_set_base(crtc, x, y, old_fb); |
c93bb85b JG |
1623 | atombios_overscan_setup(crtc, mode, adjusted_mode); |
1624 | atombios_scaler_setup(crtc); | |
771fe6b9 JG |
1625 | return 0; |
1626 | } | |
1627 | ||
1628 | static bool atombios_crtc_mode_fixup(struct drm_crtc *crtc, | |
e811f5ae | 1629 | const struct drm_display_mode *mode, |
771fe6b9 JG |
1630 | struct drm_display_mode *adjusted_mode) |
1631 | { | |
c93bb85b JG |
1632 | if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode)) |
1633 | return false; | |
771fe6b9 JG |
1634 | return true; |
1635 | } | |
1636 | ||
1637 | static void atombios_crtc_prepare(struct drm_crtc *crtc) | |
1638 | { | |
267364ac | 1639 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
6c0ae2ab AD |
1640 | struct drm_device *dev = crtc->dev; |
1641 | struct radeon_device *rdev = dev->dev_private; | |
267364ac | 1642 | |
6c0ae2ab | 1643 | radeon_crtc->in_mode_set = true; |
267364ac AD |
1644 | /* pick pll */ |
1645 | radeon_crtc->pll_id = radeon_atom_pick_pll(crtc); | |
1646 | ||
6c0ae2ab AD |
1647 | /* disable crtc pair power gating before programming */ |
1648 | if (ASIC_IS_DCE6(rdev)) | |
1649 | atombios_powergate_crtc(crtc, ATOM_DISABLE); | |
1650 | ||
37b4390e | 1651 | atombios_lock_crtc(crtc, ATOM_ENABLE); |
a348c84d | 1652 | atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
771fe6b9 JG |
1653 | } |
1654 | ||
1655 | static void atombios_crtc_commit(struct drm_crtc *crtc) | |
1656 | { | |
6c0ae2ab AD |
1657 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
1658 | ||
771fe6b9 | 1659 | atombios_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
37b4390e | 1660 | atombios_lock_crtc(crtc, ATOM_DISABLE); |
6c0ae2ab | 1661 | radeon_crtc->in_mode_set = false; |
771fe6b9 JG |
1662 | } |
1663 | ||
37f9003b AD |
1664 | static void atombios_crtc_disable(struct drm_crtc *crtc) |
1665 | { | |
1666 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); | |
64199870 AD |
1667 | struct drm_device *dev = crtc->dev; |
1668 | struct radeon_device *rdev = dev->dev_private; | |
8e8e523d | 1669 | struct radeon_atom_ss ss; |
4e58591c | 1670 | int i; |
8e8e523d | 1671 | |
37f9003b AD |
1672 | atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
1673 | ||
4e58591c AD |
1674 | for (i = 0; i < rdev->num_crtc; i++) { |
1675 | if (rdev->mode_info.crtcs[i] && | |
1676 | rdev->mode_info.crtcs[i]->enabled && | |
1677 | i != radeon_crtc->crtc_id && | |
1678 | radeon_crtc->pll_id == rdev->mode_info.crtcs[i]->pll_id) { | |
1679 | /* one other crtc is using this pll don't turn | |
1680 | * off the pll | |
1681 | */ | |
1682 | goto done; | |
1683 | } | |
1684 | } | |
1685 | ||
37f9003b AD |
1686 | switch (radeon_crtc->pll_id) { |
1687 | case ATOM_PPLL1: | |
1688 | case ATOM_PPLL2: | |
1689 | /* disable the ppll */ | |
1690 | atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id, | |
8e8e523d | 1691 | 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss); |
37f9003b | 1692 | break; |
64199870 AD |
1693 | case ATOM_PPLL0: |
1694 | /* disable the ppll */ | |
1695 | if (ASIC_IS_DCE61(rdev)) | |
1696 | atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id, | |
1697 | 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss); | |
1698 | break; | |
37f9003b AD |
1699 | default: |
1700 | break; | |
1701 | } | |
4e58591c | 1702 | done: |
2f1f4d9b | 1703 | radeon_crtc->pll_id = -1; |
37f9003b AD |
1704 | } |
1705 | ||
771fe6b9 JG |
1706 | static const struct drm_crtc_helper_funcs atombios_helper_funcs = { |
1707 | .dpms = atombios_crtc_dpms, | |
1708 | .mode_fixup = atombios_crtc_mode_fixup, | |
1709 | .mode_set = atombios_crtc_mode_set, | |
1710 | .mode_set_base = atombios_crtc_set_base, | |
4dd19b0d | 1711 | .mode_set_base_atomic = atombios_crtc_set_base_atomic, |
771fe6b9 JG |
1712 | .prepare = atombios_crtc_prepare, |
1713 | .commit = atombios_crtc_commit, | |
068143d3 | 1714 | .load_lut = radeon_crtc_load_lut, |
37f9003b | 1715 | .disable = atombios_crtc_disable, |
771fe6b9 JG |
1716 | }; |
1717 | ||
1718 | void radeon_atombios_init_crtc(struct drm_device *dev, | |
1719 | struct radeon_crtc *radeon_crtc) | |
1720 | { | |
bcc1c2a1 AD |
1721 | struct radeon_device *rdev = dev->dev_private; |
1722 | ||
1723 | if (ASIC_IS_DCE4(rdev)) { | |
1724 | switch (radeon_crtc->crtc_id) { | |
1725 | case 0: | |
1726 | default: | |
12d7798f | 1727 | radeon_crtc->crtc_offset = EVERGREEN_CRTC0_REGISTER_OFFSET; |
bcc1c2a1 AD |
1728 | break; |
1729 | case 1: | |
12d7798f | 1730 | radeon_crtc->crtc_offset = EVERGREEN_CRTC1_REGISTER_OFFSET; |
bcc1c2a1 AD |
1731 | break; |
1732 | case 2: | |
12d7798f | 1733 | radeon_crtc->crtc_offset = EVERGREEN_CRTC2_REGISTER_OFFSET; |
bcc1c2a1 AD |
1734 | break; |
1735 | case 3: | |
12d7798f | 1736 | radeon_crtc->crtc_offset = EVERGREEN_CRTC3_REGISTER_OFFSET; |
bcc1c2a1 AD |
1737 | break; |
1738 | case 4: | |
12d7798f | 1739 | radeon_crtc->crtc_offset = EVERGREEN_CRTC4_REGISTER_OFFSET; |
bcc1c2a1 AD |
1740 | break; |
1741 | case 5: | |
12d7798f | 1742 | radeon_crtc->crtc_offset = EVERGREEN_CRTC5_REGISTER_OFFSET; |
bcc1c2a1 AD |
1743 | break; |
1744 | } | |
1745 | } else { | |
1746 | if (radeon_crtc->crtc_id == 1) | |
1747 | radeon_crtc->crtc_offset = | |
1748 | AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL; | |
1749 | else | |
1750 | radeon_crtc->crtc_offset = 0; | |
1751 | } | |
2f1f4d9b | 1752 | radeon_crtc->pll_id = -1; |
771fe6b9 JG |
1753 | drm_crtc_helper_add(&radeon_crtc->base, &atombios_helper_funcs); |
1754 | } |