2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/module.h>
28 #include <linux/input.h>
29 #include <linux/i2c.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/vgaarb.h>
34 #include "intel_drv.h"
37 #include "i915_trace.h"
38 #include "drm_dp_helper.h"
40 #include "drm_crtc_helper.h"
42 #define HAS_eDP (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
44 bool intel_pipe_has_type (struct drm_crtc *crtc, int type);
45 static void intel_update_watermarks(struct drm_device *dev);
46 static void intel_increase_pllclock(struct drm_crtc *crtc);
47 static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
70 #define INTEL_P2_NUM 2
71 typedef struct intel_limit intel_limit_t;
73 intel_range_t dot, vco, n, m, m1, m2, p, p1;
75 bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
76 int, int, intel_clock_t *);
79 #define I8XX_DOT_MIN 25000
80 #define I8XX_DOT_MAX 350000
81 #define I8XX_VCO_MIN 930000
82 #define I8XX_VCO_MAX 1400000
86 #define I8XX_M_MAX 140
87 #define I8XX_M1_MIN 18
88 #define I8XX_M1_MAX 26
90 #define I8XX_M2_MAX 16
92 #define I8XX_P_MAX 128
94 #define I8XX_P1_MAX 33
95 #define I8XX_P1_LVDS_MIN 1
96 #define I8XX_P1_LVDS_MAX 6
97 #define I8XX_P2_SLOW 4
98 #define I8XX_P2_FAST 2
99 #define I8XX_P2_LVDS_SLOW 14
100 #define I8XX_P2_LVDS_FAST 7
101 #define I8XX_P2_SLOW_LIMIT 165000
103 #define I9XX_DOT_MIN 20000
104 #define I9XX_DOT_MAX 400000
105 #define I9XX_VCO_MIN 1400000
106 #define I9XX_VCO_MAX 2800000
107 #define PINEVIEW_VCO_MIN 1700000
108 #define PINEVIEW_VCO_MAX 3500000
111 /* Pineview's Ncounter is a ring counter */
112 #define PINEVIEW_N_MIN 3
113 #define PINEVIEW_N_MAX 6
114 #define I9XX_M_MIN 70
115 #define I9XX_M_MAX 120
116 #define PINEVIEW_M_MIN 2
117 #define PINEVIEW_M_MAX 256
118 #define I9XX_M1_MIN 10
119 #define I9XX_M1_MAX 22
120 #define I9XX_M2_MIN 5
121 #define I9XX_M2_MAX 9
122 /* Pineview M1 is reserved, and must be 0 */
123 #define PINEVIEW_M1_MIN 0
124 #define PINEVIEW_M1_MAX 0
125 #define PINEVIEW_M2_MIN 0
126 #define PINEVIEW_M2_MAX 254
127 #define I9XX_P_SDVO_DAC_MIN 5
128 #define I9XX_P_SDVO_DAC_MAX 80
129 #define I9XX_P_LVDS_MIN 7
130 #define I9XX_P_LVDS_MAX 98
131 #define PINEVIEW_P_LVDS_MIN 7
132 #define PINEVIEW_P_LVDS_MAX 112
133 #define I9XX_P1_MIN 1
134 #define I9XX_P1_MAX 8
135 #define I9XX_P2_SDVO_DAC_SLOW 10
136 #define I9XX_P2_SDVO_DAC_FAST 5
137 #define I9XX_P2_SDVO_DAC_SLOW_LIMIT 200000
138 #define I9XX_P2_LVDS_SLOW 14
139 #define I9XX_P2_LVDS_FAST 7
140 #define I9XX_P2_LVDS_SLOW_LIMIT 112000
142 /*The parameter is for SDVO on G4x platform*/
143 #define G4X_DOT_SDVO_MIN 25000
144 #define G4X_DOT_SDVO_MAX 270000
145 #define G4X_VCO_MIN 1750000
146 #define G4X_VCO_MAX 3500000
147 #define G4X_N_SDVO_MIN 1
148 #define G4X_N_SDVO_MAX 4
149 #define G4X_M_SDVO_MIN 104
150 #define G4X_M_SDVO_MAX 138
151 #define G4X_M1_SDVO_MIN 17
152 #define G4X_M1_SDVO_MAX 23
153 #define G4X_M2_SDVO_MIN 5
154 #define G4X_M2_SDVO_MAX 11
155 #define G4X_P_SDVO_MIN 10
156 #define G4X_P_SDVO_MAX 30
157 #define G4X_P1_SDVO_MIN 1
158 #define G4X_P1_SDVO_MAX 3
159 #define G4X_P2_SDVO_SLOW 10
160 #define G4X_P2_SDVO_FAST 10
161 #define G4X_P2_SDVO_LIMIT 270000
163 /*The parameter is for HDMI_DAC on G4x platform*/
164 #define G4X_DOT_HDMI_DAC_MIN 22000
165 #define G4X_DOT_HDMI_DAC_MAX 400000
166 #define G4X_N_HDMI_DAC_MIN 1
167 #define G4X_N_HDMI_DAC_MAX 4
168 #define G4X_M_HDMI_DAC_MIN 104
169 #define G4X_M_HDMI_DAC_MAX 138
170 #define G4X_M1_HDMI_DAC_MIN 16
171 #define G4X_M1_HDMI_DAC_MAX 23
172 #define G4X_M2_HDMI_DAC_MIN 5
173 #define G4X_M2_HDMI_DAC_MAX 11
174 #define G4X_P_HDMI_DAC_MIN 5
175 #define G4X_P_HDMI_DAC_MAX 80
176 #define G4X_P1_HDMI_DAC_MIN 1
177 #define G4X_P1_HDMI_DAC_MAX 8
178 #define G4X_P2_HDMI_DAC_SLOW 10
179 #define G4X_P2_HDMI_DAC_FAST 5
180 #define G4X_P2_HDMI_DAC_LIMIT 165000
182 /*The parameter is for SINGLE_CHANNEL_LVDS on G4x platform*/
183 #define G4X_DOT_SINGLE_CHANNEL_LVDS_MIN 20000
184 #define G4X_DOT_SINGLE_CHANNEL_LVDS_MAX 115000
185 #define G4X_N_SINGLE_CHANNEL_LVDS_MIN 1
186 #define G4X_N_SINGLE_CHANNEL_LVDS_MAX 3
187 #define G4X_M_SINGLE_CHANNEL_LVDS_MIN 104
188 #define G4X_M_SINGLE_CHANNEL_LVDS_MAX 138
189 #define G4X_M1_SINGLE_CHANNEL_LVDS_MIN 17
190 #define G4X_M1_SINGLE_CHANNEL_LVDS_MAX 23
191 #define G4X_M2_SINGLE_CHANNEL_LVDS_MIN 5
192 #define G4X_M2_SINGLE_CHANNEL_LVDS_MAX 11
193 #define G4X_P_SINGLE_CHANNEL_LVDS_MIN 28
194 #define G4X_P_SINGLE_CHANNEL_LVDS_MAX 112
195 #define G4X_P1_SINGLE_CHANNEL_LVDS_MIN 2
196 #define G4X_P1_SINGLE_CHANNEL_LVDS_MAX 8
197 #define G4X_P2_SINGLE_CHANNEL_LVDS_SLOW 14
198 #define G4X_P2_SINGLE_CHANNEL_LVDS_FAST 14
199 #define G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT 0
201 /*The parameter is for DUAL_CHANNEL_LVDS on G4x platform*/
202 #define G4X_DOT_DUAL_CHANNEL_LVDS_MIN 80000
203 #define G4X_DOT_DUAL_CHANNEL_LVDS_MAX 224000
204 #define G4X_N_DUAL_CHANNEL_LVDS_MIN 1
205 #define G4X_N_DUAL_CHANNEL_LVDS_MAX 3
206 #define G4X_M_DUAL_CHANNEL_LVDS_MIN 104
207 #define G4X_M_DUAL_CHANNEL_LVDS_MAX 138
208 #define G4X_M1_DUAL_CHANNEL_LVDS_MIN 17
209 #define G4X_M1_DUAL_CHANNEL_LVDS_MAX 23
210 #define G4X_M2_DUAL_CHANNEL_LVDS_MIN 5
211 #define G4X_M2_DUAL_CHANNEL_LVDS_MAX 11
212 #define G4X_P_DUAL_CHANNEL_LVDS_MIN 14
213 #define G4X_P_DUAL_CHANNEL_LVDS_MAX 42
214 #define G4X_P1_DUAL_CHANNEL_LVDS_MIN 2
215 #define G4X_P1_DUAL_CHANNEL_LVDS_MAX 6
216 #define G4X_P2_DUAL_CHANNEL_LVDS_SLOW 7
217 #define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7
218 #define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0
220 /*The parameter is for DISPLAY PORT on G4x platform*/
221 #define G4X_DOT_DISPLAY_PORT_MIN 161670
222 #define G4X_DOT_DISPLAY_PORT_MAX 227000
223 #define G4X_N_DISPLAY_PORT_MIN 1
224 #define G4X_N_DISPLAY_PORT_MAX 2
225 #define G4X_M_DISPLAY_PORT_MIN 97
226 #define G4X_M_DISPLAY_PORT_MAX 108
227 #define G4X_M1_DISPLAY_PORT_MIN 0x10
228 #define G4X_M1_DISPLAY_PORT_MAX 0x12
229 #define G4X_M2_DISPLAY_PORT_MIN 0x05
230 #define G4X_M2_DISPLAY_PORT_MAX 0x06
231 #define G4X_P_DISPLAY_PORT_MIN 10
232 #define G4X_P_DISPLAY_PORT_MAX 20
233 #define G4X_P1_DISPLAY_PORT_MIN 1
234 #define G4X_P1_DISPLAY_PORT_MAX 2
235 #define G4X_P2_DISPLAY_PORT_SLOW 10
236 #define G4X_P2_DISPLAY_PORT_FAST 10
237 #define G4X_P2_DISPLAY_PORT_LIMIT 0
239 /* Ironlake / Sandybridge */
240 /* as we calculate clock using (register_value + 2) for
241 N/M1/M2, so here the range value for them is (actual_value-2).
243 #define IRONLAKE_DOT_MIN 25000
244 #define IRONLAKE_DOT_MAX 350000
245 #define IRONLAKE_VCO_MIN 1760000
246 #define IRONLAKE_VCO_MAX 3510000
247 #define IRONLAKE_M1_MIN 12
248 #define IRONLAKE_M1_MAX 22
249 #define IRONLAKE_M2_MIN 5
250 #define IRONLAKE_M2_MAX 9
251 #define IRONLAKE_P2_DOT_LIMIT 225000 /* 225Mhz */
253 /* We have parameter ranges for different type of outputs. */
255 /* DAC & HDMI Refclk 120Mhz */
256 #define IRONLAKE_DAC_N_MIN 1
257 #define IRONLAKE_DAC_N_MAX 5
258 #define IRONLAKE_DAC_M_MIN 79
259 #define IRONLAKE_DAC_M_MAX 127
260 #define IRONLAKE_DAC_P_MIN 5
261 #define IRONLAKE_DAC_P_MAX 80
262 #define IRONLAKE_DAC_P1_MIN 1
263 #define IRONLAKE_DAC_P1_MAX 8
264 #define IRONLAKE_DAC_P2_SLOW 10
265 #define IRONLAKE_DAC_P2_FAST 5
267 /* LVDS single-channel 120Mhz refclk */
268 #define IRONLAKE_LVDS_S_N_MIN 1
269 #define IRONLAKE_LVDS_S_N_MAX 3
270 #define IRONLAKE_LVDS_S_M_MIN 79
271 #define IRONLAKE_LVDS_S_M_MAX 118
272 #define IRONLAKE_LVDS_S_P_MIN 28
273 #define IRONLAKE_LVDS_S_P_MAX 112
274 #define IRONLAKE_LVDS_S_P1_MIN 2
275 #define IRONLAKE_LVDS_S_P1_MAX 8
276 #define IRONLAKE_LVDS_S_P2_SLOW 14
277 #define IRONLAKE_LVDS_S_P2_FAST 14
279 /* LVDS dual-channel 120Mhz refclk */
280 #define IRONLAKE_LVDS_D_N_MIN 1
281 #define IRONLAKE_LVDS_D_N_MAX 3
282 #define IRONLAKE_LVDS_D_M_MIN 79
283 #define IRONLAKE_LVDS_D_M_MAX 127
284 #define IRONLAKE_LVDS_D_P_MIN 14
285 #define IRONLAKE_LVDS_D_P_MAX 56
286 #define IRONLAKE_LVDS_D_P1_MIN 2
287 #define IRONLAKE_LVDS_D_P1_MAX 8
288 #define IRONLAKE_LVDS_D_P2_SLOW 7
289 #define IRONLAKE_LVDS_D_P2_FAST 7
291 /* LVDS single-channel 100Mhz refclk */
292 #define IRONLAKE_LVDS_S_SSC_N_MIN 1
293 #define IRONLAKE_LVDS_S_SSC_N_MAX 2
294 #define IRONLAKE_LVDS_S_SSC_M_MIN 79
295 #define IRONLAKE_LVDS_S_SSC_M_MAX 126
296 #define IRONLAKE_LVDS_S_SSC_P_MIN 28
297 #define IRONLAKE_LVDS_S_SSC_P_MAX 112
298 #define IRONLAKE_LVDS_S_SSC_P1_MIN 2
299 #define IRONLAKE_LVDS_S_SSC_P1_MAX 8
300 #define IRONLAKE_LVDS_S_SSC_P2_SLOW 14
301 #define IRONLAKE_LVDS_S_SSC_P2_FAST 14
303 /* LVDS dual-channel 100Mhz refclk */
304 #define IRONLAKE_LVDS_D_SSC_N_MIN 1
305 #define IRONLAKE_LVDS_D_SSC_N_MAX 3
306 #define IRONLAKE_LVDS_D_SSC_M_MIN 79
307 #define IRONLAKE_LVDS_D_SSC_M_MAX 126
308 #define IRONLAKE_LVDS_D_SSC_P_MIN 14
309 #define IRONLAKE_LVDS_D_SSC_P_MAX 42
310 #define IRONLAKE_LVDS_D_SSC_P1_MIN 2
311 #define IRONLAKE_LVDS_D_SSC_P1_MAX 6
312 #define IRONLAKE_LVDS_D_SSC_P2_SLOW 7
313 #define IRONLAKE_LVDS_D_SSC_P2_FAST 7
316 #define IRONLAKE_DP_N_MIN 1
317 #define IRONLAKE_DP_N_MAX 2
318 #define IRONLAKE_DP_M_MIN 81
319 #define IRONLAKE_DP_M_MAX 90
320 #define IRONLAKE_DP_P_MIN 10
321 #define IRONLAKE_DP_P_MAX 20
322 #define IRONLAKE_DP_P2_FAST 10
323 #define IRONLAKE_DP_P2_SLOW 10
324 #define IRONLAKE_DP_P2_LIMIT 0
325 #define IRONLAKE_DP_P1_MIN 1
326 #define IRONLAKE_DP_P1_MAX 2
329 #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
332 intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
333 int target, int refclk, intel_clock_t *best_clock);
335 intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
336 int target, int refclk, intel_clock_t *best_clock);
339 intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
340 int target, int refclk, intel_clock_t *best_clock);
342 intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc,
343 int target, int refclk, intel_clock_t *best_clock);
345 static inline u32 /* units of 100MHz */
346 intel_fdi_link_freq(struct drm_device *dev)
349 struct drm_i915_private *dev_priv = dev->dev_private;
350 return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
355 static const intel_limit_t intel_limits_i8xx_dvo = {
356 .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
357 .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
358 .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
359 .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
360 .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
361 .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
362 .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
363 .p1 = { .min = I8XX_P1_MIN, .max = I8XX_P1_MAX },
364 .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
365 .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST },
366 .find_pll = intel_find_best_PLL,
369 static const intel_limit_t intel_limits_i8xx_lvds = {
370 .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
371 .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
372 .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
373 .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
374 .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
375 .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
376 .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
377 .p1 = { .min = I8XX_P1_LVDS_MIN, .max = I8XX_P1_LVDS_MAX },
378 .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
379 .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST },
380 .find_pll = intel_find_best_PLL,
383 static const intel_limit_t intel_limits_i9xx_sdvo = {
384 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
385 .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
386 .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
387 .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
388 .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
389 .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
390 .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
391 .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
392 .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
393 .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
394 .find_pll = intel_find_best_PLL,
397 static const intel_limit_t intel_limits_i9xx_lvds = {
398 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
399 .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
400 .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
401 .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
402 .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
403 .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
404 .p = { .min = I9XX_P_LVDS_MIN, .max = I9XX_P_LVDS_MAX },
405 .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
406 /* The single-channel range is 25-112Mhz, and dual-channel
407 * is 80-224Mhz. Prefer single channel as much as possible.
409 .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
410 .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST },
411 .find_pll = intel_find_best_PLL,
414 /* below parameter and function is for G4X Chipset Family*/
415 static const intel_limit_t intel_limits_g4x_sdvo = {
416 .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX },
417 .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
418 .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX },
419 .m = { .min = G4X_M_SDVO_MIN, .max = G4X_M_SDVO_MAX },
420 .m1 = { .min = G4X_M1_SDVO_MIN, .max = G4X_M1_SDVO_MAX },
421 .m2 = { .min = G4X_M2_SDVO_MIN, .max = G4X_M2_SDVO_MAX },
422 .p = { .min = G4X_P_SDVO_MIN, .max = G4X_P_SDVO_MAX },
423 .p1 = { .min = G4X_P1_SDVO_MIN, .max = G4X_P1_SDVO_MAX},
424 .p2 = { .dot_limit = G4X_P2_SDVO_LIMIT,
425 .p2_slow = G4X_P2_SDVO_SLOW,
426 .p2_fast = G4X_P2_SDVO_FAST
428 .find_pll = intel_g4x_find_best_PLL,
431 static const intel_limit_t intel_limits_g4x_hdmi = {
432 .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX },
433 .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
434 .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX },
435 .m = { .min = G4X_M_HDMI_DAC_MIN, .max = G4X_M_HDMI_DAC_MAX },
436 .m1 = { .min = G4X_M1_HDMI_DAC_MIN, .max = G4X_M1_HDMI_DAC_MAX },
437 .m2 = { .min = G4X_M2_HDMI_DAC_MIN, .max = G4X_M2_HDMI_DAC_MAX },
438 .p = { .min = G4X_P_HDMI_DAC_MIN, .max = G4X_P_HDMI_DAC_MAX },
439 .p1 = { .min = G4X_P1_HDMI_DAC_MIN, .max = G4X_P1_HDMI_DAC_MAX},
440 .p2 = { .dot_limit = G4X_P2_HDMI_DAC_LIMIT,
441 .p2_slow = G4X_P2_HDMI_DAC_SLOW,
442 .p2_fast = G4X_P2_HDMI_DAC_FAST
444 .find_pll = intel_g4x_find_best_PLL,
447 static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
448 .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN,
449 .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX },
450 .vco = { .min = G4X_VCO_MIN,
451 .max = G4X_VCO_MAX },
452 .n = { .min = G4X_N_SINGLE_CHANNEL_LVDS_MIN,
453 .max = G4X_N_SINGLE_CHANNEL_LVDS_MAX },
454 .m = { .min = G4X_M_SINGLE_CHANNEL_LVDS_MIN,
455 .max = G4X_M_SINGLE_CHANNEL_LVDS_MAX },
456 .m1 = { .min = G4X_M1_SINGLE_CHANNEL_LVDS_MIN,
457 .max = G4X_M1_SINGLE_CHANNEL_LVDS_MAX },
458 .m2 = { .min = G4X_M2_SINGLE_CHANNEL_LVDS_MIN,
459 .max = G4X_M2_SINGLE_CHANNEL_LVDS_MAX },
460 .p = { .min = G4X_P_SINGLE_CHANNEL_LVDS_MIN,
461 .max = G4X_P_SINGLE_CHANNEL_LVDS_MAX },
462 .p1 = { .min = G4X_P1_SINGLE_CHANNEL_LVDS_MIN,
463 .max = G4X_P1_SINGLE_CHANNEL_LVDS_MAX },
464 .p2 = { .dot_limit = G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT,
465 .p2_slow = G4X_P2_SINGLE_CHANNEL_LVDS_SLOW,
466 .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST
468 .find_pll = intel_g4x_find_best_PLL,
471 static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
472 .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN,
473 .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX },
474 .vco = { .min = G4X_VCO_MIN,
475 .max = G4X_VCO_MAX },
476 .n = { .min = G4X_N_DUAL_CHANNEL_LVDS_MIN,
477 .max = G4X_N_DUAL_CHANNEL_LVDS_MAX },
478 .m = { .min = G4X_M_DUAL_CHANNEL_LVDS_MIN,
479 .max = G4X_M_DUAL_CHANNEL_LVDS_MAX },
480 .m1 = { .min = G4X_M1_DUAL_CHANNEL_LVDS_MIN,
481 .max = G4X_M1_DUAL_CHANNEL_LVDS_MAX },
482 .m2 = { .min = G4X_M2_DUAL_CHANNEL_LVDS_MIN,
483 .max = G4X_M2_DUAL_CHANNEL_LVDS_MAX },
484 .p = { .min = G4X_P_DUAL_CHANNEL_LVDS_MIN,
485 .max = G4X_P_DUAL_CHANNEL_LVDS_MAX },
486 .p1 = { .min = G4X_P1_DUAL_CHANNEL_LVDS_MIN,
487 .max = G4X_P1_DUAL_CHANNEL_LVDS_MAX },
488 .p2 = { .dot_limit = G4X_P2_DUAL_CHANNEL_LVDS_LIMIT,
489 .p2_slow = G4X_P2_DUAL_CHANNEL_LVDS_SLOW,
490 .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST
492 .find_pll = intel_g4x_find_best_PLL,
495 static const intel_limit_t intel_limits_g4x_display_port = {
496 .dot = { .min = G4X_DOT_DISPLAY_PORT_MIN,
497 .max = G4X_DOT_DISPLAY_PORT_MAX },
498 .vco = { .min = G4X_VCO_MIN,
500 .n = { .min = G4X_N_DISPLAY_PORT_MIN,
501 .max = G4X_N_DISPLAY_PORT_MAX },
502 .m = { .min = G4X_M_DISPLAY_PORT_MIN,
503 .max = G4X_M_DISPLAY_PORT_MAX },
504 .m1 = { .min = G4X_M1_DISPLAY_PORT_MIN,
505 .max = G4X_M1_DISPLAY_PORT_MAX },
506 .m2 = { .min = G4X_M2_DISPLAY_PORT_MIN,
507 .max = G4X_M2_DISPLAY_PORT_MAX },
508 .p = { .min = G4X_P_DISPLAY_PORT_MIN,
509 .max = G4X_P_DISPLAY_PORT_MAX },
510 .p1 = { .min = G4X_P1_DISPLAY_PORT_MIN,
511 .max = G4X_P1_DISPLAY_PORT_MAX},
512 .p2 = { .dot_limit = G4X_P2_DISPLAY_PORT_LIMIT,
513 .p2_slow = G4X_P2_DISPLAY_PORT_SLOW,
514 .p2_fast = G4X_P2_DISPLAY_PORT_FAST },
515 .find_pll = intel_find_pll_g4x_dp,
518 static const intel_limit_t intel_limits_pineview_sdvo = {
519 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX},
520 .vco = { .min = PINEVIEW_VCO_MIN, .max = PINEVIEW_VCO_MAX },
521 .n = { .min = PINEVIEW_N_MIN, .max = PINEVIEW_N_MAX },
522 .m = { .min = PINEVIEW_M_MIN, .max = PINEVIEW_M_MAX },
523 .m1 = { .min = PINEVIEW_M1_MIN, .max = PINEVIEW_M1_MAX },
524 .m2 = { .min = PINEVIEW_M2_MIN, .max = PINEVIEW_M2_MAX },
525 .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
526 .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
527 .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
528 .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
529 .find_pll = intel_find_best_PLL,
532 static const intel_limit_t intel_limits_pineview_lvds = {
533 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
534 .vco = { .min = PINEVIEW_VCO_MIN, .max = PINEVIEW_VCO_MAX },
535 .n = { .min = PINEVIEW_N_MIN, .max = PINEVIEW_N_MAX },
536 .m = { .min = PINEVIEW_M_MIN, .max = PINEVIEW_M_MAX },
537 .m1 = { .min = PINEVIEW_M1_MIN, .max = PINEVIEW_M1_MAX },
538 .m2 = { .min = PINEVIEW_M2_MIN, .max = PINEVIEW_M2_MAX },
539 .p = { .min = PINEVIEW_P_LVDS_MIN, .max = PINEVIEW_P_LVDS_MAX },
540 .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
541 /* Pineview only supports single-channel mode. */
542 .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
543 .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW },
544 .find_pll = intel_find_best_PLL,
547 static const intel_limit_t intel_limits_ironlake_dac = {
548 .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
549 .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
550 .n = { .min = IRONLAKE_DAC_N_MIN, .max = IRONLAKE_DAC_N_MAX },
551 .m = { .min = IRONLAKE_DAC_M_MIN, .max = IRONLAKE_DAC_M_MAX },
552 .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
553 .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
554 .p = { .min = IRONLAKE_DAC_P_MIN, .max = IRONLAKE_DAC_P_MAX },
555 .p1 = { .min = IRONLAKE_DAC_P1_MIN, .max = IRONLAKE_DAC_P1_MAX },
556 .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
557 .p2_slow = IRONLAKE_DAC_P2_SLOW,
558 .p2_fast = IRONLAKE_DAC_P2_FAST },
559 .find_pll = intel_g4x_find_best_PLL,
562 static const intel_limit_t intel_limits_ironlake_single_lvds = {
563 .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
564 .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
565 .n = { .min = IRONLAKE_LVDS_S_N_MIN, .max = IRONLAKE_LVDS_S_N_MAX },
566 .m = { .min = IRONLAKE_LVDS_S_M_MIN, .max = IRONLAKE_LVDS_S_M_MAX },
567 .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
568 .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
569 .p = { .min = IRONLAKE_LVDS_S_P_MIN, .max = IRONLAKE_LVDS_S_P_MAX },
570 .p1 = { .min = IRONLAKE_LVDS_S_P1_MIN, .max = IRONLAKE_LVDS_S_P1_MAX },
571 .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
572 .p2_slow = IRONLAKE_LVDS_S_P2_SLOW,
573 .p2_fast = IRONLAKE_LVDS_S_P2_FAST },
574 .find_pll = intel_g4x_find_best_PLL,
577 static const intel_limit_t intel_limits_ironlake_dual_lvds = {
578 .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
579 .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
580 .n = { .min = IRONLAKE_LVDS_D_N_MIN, .max = IRONLAKE_LVDS_D_N_MAX },
581 .m = { .min = IRONLAKE_LVDS_D_M_MIN, .max = IRONLAKE_LVDS_D_M_MAX },
582 .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
583 .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
584 .p = { .min = IRONLAKE_LVDS_D_P_MIN, .max = IRONLAKE_LVDS_D_P_MAX },
585 .p1 = { .min = IRONLAKE_LVDS_D_P1_MIN, .max = IRONLAKE_LVDS_D_P1_MAX },
586 .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
587 .p2_slow = IRONLAKE_LVDS_D_P2_SLOW,
588 .p2_fast = IRONLAKE_LVDS_D_P2_FAST },
589 .find_pll = intel_g4x_find_best_PLL,
592 static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
593 .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
594 .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
595 .n = { .min = IRONLAKE_LVDS_S_SSC_N_MIN, .max = IRONLAKE_LVDS_S_SSC_N_MAX },
596 .m = { .min = IRONLAKE_LVDS_S_SSC_M_MIN, .max = IRONLAKE_LVDS_S_SSC_M_MAX },
597 .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
598 .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
599 .p = { .min = IRONLAKE_LVDS_S_SSC_P_MIN, .max = IRONLAKE_LVDS_S_SSC_P_MAX },
600 .p1 = { .min = IRONLAKE_LVDS_S_SSC_P1_MIN,.max = IRONLAKE_LVDS_S_SSC_P1_MAX },
601 .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
602 .p2_slow = IRONLAKE_LVDS_S_SSC_P2_SLOW,
603 .p2_fast = IRONLAKE_LVDS_S_SSC_P2_FAST },
604 .find_pll = intel_g4x_find_best_PLL,
607 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
608 .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
609 .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
610 .n = { .min = IRONLAKE_LVDS_D_SSC_N_MIN, .max = IRONLAKE_LVDS_D_SSC_N_MAX },
611 .m = { .min = IRONLAKE_LVDS_D_SSC_M_MIN, .max = IRONLAKE_LVDS_D_SSC_M_MAX },
612 .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
613 .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
614 .p = { .min = IRONLAKE_LVDS_D_SSC_P_MIN, .max = IRONLAKE_LVDS_D_SSC_P_MAX },
615 .p1 = { .min = IRONLAKE_LVDS_D_SSC_P1_MIN,.max = IRONLAKE_LVDS_D_SSC_P1_MAX },
616 .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
617 .p2_slow = IRONLAKE_LVDS_D_SSC_P2_SLOW,
618 .p2_fast = IRONLAKE_LVDS_D_SSC_P2_FAST },
619 .find_pll = intel_g4x_find_best_PLL,
622 static const intel_limit_t intel_limits_ironlake_display_port = {
623 .dot = { .min = IRONLAKE_DOT_MIN,
624 .max = IRONLAKE_DOT_MAX },
625 .vco = { .min = IRONLAKE_VCO_MIN,
626 .max = IRONLAKE_VCO_MAX},
627 .n = { .min = IRONLAKE_DP_N_MIN,
628 .max = IRONLAKE_DP_N_MAX },
629 .m = { .min = IRONLAKE_DP_M_MIN,
630 .max = IRONLAKE_DP_M_MAX },
631 .m1 = { .min = IRONLAKE_M1_MIN,
632 .max = IRONLAKE_M1_MAX },
633 .m2 = { .min = IRONLAKE_M2_MIN,
634 .max = IRONLAKE_M2_MAX },
635 .p = { .min = IRONLAKE_DP_P_MIN,
636 .max = IRONLAKE_DP_P_MAX },
637 .p1 = { .min = IRONLAKE_DP_P1_MIN,
638 .max = IRONLAKE_DP_P1_MAX},
639 .p2 = { .dot_limit = IRONLAKE_DP_P2_LIMIT,
640 .p2_slow = IRONLAKE_DP_P2_SLOW,
641 .p2_fast = IRONLAKE_DP_P2_FAST },
642 .find_pll = intel_find_pll_ironlake_dp,
645 static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
648 struct drm_device *dev = crtc->dev;
649 struct drm_i915_private *dev_priv = dev->dev_private;
650 const intel_limit_t *limit;
652 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
653 if ((I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) ==
654 LVDS_CLKB_POWER_UP) {
655 /* LVDS dual channel */
656 if (refclk == 100000)
657 limit = &intel_limits_ironlake_dual_lvds_100m;
659 limit = &intel_limits_ironlake_dual_lvds;
661 if (refclk == 100000)
662 limit = &intel_limits_ironlake_single_lvds_100m;
664 limit = &intel_limits_ironlake_single_lvds;
666 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
668 limit = &intel_limits_ironlake_display_port;
670 limit = &intel_limits_ironlake_dac;
675 static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
677 struct drm_device *dev = crtc->dev;
678 struct drm_i915_private *dev_priv = dev->dev_private;
679 const intel_limit_t *limit;
681 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
682 if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
684 /* LVDS with dual channel */
685 limit = &intel_limits_g4x_dual_channel_lvds;
687 /* LVDS with dual channel */
688 limit = &intel_limits_g4x_single_channel_lvds;
689 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
690 intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
691 limit = &intel_limits_g4x_hdmi;
692 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
693 limit = &intel_limits_g4x_sdvo;
694 } else if (intel_pipe_has_type (crtc, INTEL_OUTPUT_DISPLAYPORT)) {
695 limit = &intel_limits_g4x_display_port;
696 } else /* The option is for other outputs */
697 limit = &intel_limits_i9xx_sdvo;
702 static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
704 struct drm_device *dev = crtc->dev;
705 const intel_limit_t *limit;
707 if (HAS_PCH_SPLIT(dev))
708 limit = intel_ironlake_limit(crtc, refclk);
709 else if (IS_G4X(dev)) {
710 limit = intel_g4x_limit(crtc);
711 } else if (IS_PINEVIEW(dev)) {
712 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
713 limit = &intel_limits_pineview_lvds;
715 limit = &intel_limits_pineview_sdvo;
716 } else if (!IS_GEN2(dev)) {
717 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
718 limit = &intel_limits_i9xx_lvds;
720 limit = &intel_limits_i9xx_sdvo;
722 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
723 limit = &intel_limits_i8xx_lvds;
725 limit = &intel_limits_i8xx_dvo;
730 /* m1 is reserved as 0 in Pineview, n is a ring counter */
731 static void pineview_clock(int refclk, intel_clock_t *clock)
733 clock->m = clock->m2 + 2;
734 clock->p = clock->p1 * clock->p2;
735 clock->vco = refclk * clock->m / clock->n;
736 clock->dot = clock->vco / clock->p;
739 static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
741 if (IS_PINEVIEW(dev)) {
742 pineview_clock(refclk, clock);
745 clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
746 clock->p = clock->p1 * clock->p2;
747 clock->vco = refclk * clock->m / (clock->n + 2);
748 clock->dot = clock->vco / clock->p;
752 * Returns whether any output on the specified pipe is of the specified type
754 bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
756 struct drm_device *dev = crtc->dev;
757 struct drm_mode_config *mode_config = &dev->mode_config;
758 struct intel_encoder *encoder;
760 list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
761 if (encoder->base.crtc == crtc && encoder->type == type)
767 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
769 * Returns whether the given set of divisors are valid for a given refclk with
770 * the given connectors.
773 static bool intel_PLL_is_valid(struct drm_device *dev,
774 const intel_limit_t *limit,
775 const intel_clock_t *clock)
777 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
778 INTELPllInvalid ("p1 out of range\n");
779 if (clock->p < limit->p.min || limit->p.max < clock->p)
780 INTELPllInvalid ("p out of range\n");
781 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
782 INTELPllInvalid ("m2 out of range\n");
783 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
784 INTELPllInvalid ("m1 out of range\n");
785 if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev))
786 INTELPllInvalid ("m1 <= m2\n");
787 if (clock->m < limit->m.min || limit->m.max < clock->m)
788 INTELPllInvalid ("m out of range\n");
789 if (clock->n < limit->n.min || limit->n.max < clock->n)
790 INTELPllInvalid ("n out of range\n");
791 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
792 INTELPllInvalid ("vco out of range\n");
793 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
794 * connector, etc., rather than just a single range.
796 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
797 INTELPllInvalid ("dot out of range\n");
803 intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
804 int target, int refclk, intel_clock_t *best_clock)
807 struct drm_device *dev = crtc->dev;
808 struct drm_i915_private *dev_priv = dev->dev_private;
812 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
813 (I915_READ(LVDS)) != 0) {
815 * For LVDS, if the panel is on, just rely on its current
816 * settings for dual-channel. We haven't figured out how to
817 * reliably set up different single/dual channel state, if we
820 if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
822 clock.p2 = limit->p2.p2_fast;
824 clock.p2 = limit->p2.p2_slow;
826 if (target < limit->p2.dot_limit)
827 clock.p2 = limit->p2.p2_slow;
829 clock.p2 = limit->p2.p2_fast;
832 memset (best_clock, 0, sizeof (*best_clock));
834 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
836 for (clock.m2 = limit->m2.min;
837 clock.m2 <= limit->m2.max; clock.m2++) {
838 /* m1 is always 0 in Pineview */
839 if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev))
841 for (clock.n = limit->n.min;
842 clock.n <= limit->n.max; clock.n++) {
843 for (clock.p1 = limit->p1.min;
844 clock.p1 <= limit->p1.max; clock.p1++) {
847 intel_clock(dev, refclk, &clock);
848 if (!intel_PLL_is_valid(dev, limit,
852 this_err = abs(clock.dot - target);
853 if (this_err < err) {
862 return (err != target);
866 intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
867 int target, int refclk, intel_clock_t *best_clock)
869 struct drm_device *dev = crtc->dev;
870 struct drm_i915_private *dev_priv = dev->dev_private;
874 /* approximately equals target * 0.00585 */
875 int err_most = (target >> 8) + (target >> 9);
878 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
881 if (HAS_PCH_SPLIT(dev))
885 if ((I915_READ(lvds_reg) & LVDS_CLKB_POWER_MASK) ==
887 clock.p2 = limit->p2.p2_fast;
889 clock.p2 = limit->p2.p2_slow;
891 if (target < limit->p2.dot_limit)
892 clock.p2 = limit->p2.p2_slow;
894 clock.p2 = limit->p2.p2_fast;
897 memset(best_clock, 0, sizeof(*best_clock));
898 max_n = limit->n.max;
899 /* based on hardware requirement, prefer smaller n to precision */
900 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
901 /* based on hardware requirement, prefere larger m1,m2 */
902 for (clock.m1 = limit->m1.max;
903 clock.m1 >= limit->m1.min; clock.m1--) {
904 for (clock.m2 = limit->m2.max;
905 clock.m2 >= limit->m2.min; clock.m2--) {
906 for (clock.p1 = limit->p1.max;
907 clock.p1 >= limit->p1.min; clock.p1--) {
910 intel_clock(dev, refclk, &clock);
911 if (!intel_PLL_is_valid(dev, limit,
915 this_err = abs(clock.dot - target);
916 if (this_err < err_most) {
930 intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
931 int target, int refclk, intel_clock_t *best_clock)
933 struct drm_device *dev = crtc->dev;
936 if (target < 200000) {
949 intel_clock(dev, refclk, &clock);
950 memcpy(best_clock, &clock, sizeof(intel_clock_t));
954 /* DisplayPort has only two frequencies, 162MHz and 270MHz */
956 intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
957 int target, int refclk, intel_clock_t *best_clock)
960 if (target < 200000) {
973 clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
974 clock.p = (clock.p1 * clock.p2);
975 clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
977 memcpy(best_clock, &clock, sizeof(intel_clock_t));
982 * intel_wait_for_vblank - wait for vblank on a given pipe
984 * @pipe: pipe to wait for
986 * Wait for vblank to occur on a given pipe. Needed for various bits of
989 void intel_wait_for_vblank(struct drm_device *dev, int pipe)
991 struct drm_i915_private *dev_priv = dev->dev_private;
992 int pipestat_reg = (pipe == 0 ? PIPEASTAT : PIPEBSTAT);
994 /* Clear existing vblank status. Note this will clear any other
995 * sticky status fields as well.
997 * This races with i915_driver_irq_handler() with the result
998 * that either function could miss a vblank event. Here it is not
999 * fatal, as we will either wait upon the next vblank interrupt or
1000 * timeout. Generally speaking intel_wait_for_vblank() is only
1001 * called during modeset at which time the GPU should be idle and
1002 * should *not* be performing page flips and thus not waiting on
1004 * Currently, the result of us stealing a vblank from the irq
1005 * handler is that a single frame will be skipped during swapbuffers.
1007 I915_WRITE(pipestat_reg,
1008 I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
1010 /* Wait for vblank interrupt bit to set */
1011 if (wait_for(I915_READ(pipestat_reg) &
1012 PIPE_VBLANK_INTERRUPT_STATUS,
1014 DRM_DEBUG_KMS("vblank wait timed out\n");
1018 * intel_wait_for_pipe_off - wait for pipe to turn off
1020 * @pipe: pipe to wait for
1022 * After disabling a pipe, we can't wait for vblank in the usual way,
1023 * spinning on the vblank interrupt status bit, since we won't actually
1024 * see an interrupt when the pipe is disabled.
1026 * On Gen4 and above:
1027 * wait for the pipe register state bit to turn off
1030 * wait for the display line value to settle (it usually
1031 * ends up stopping at the start of the next frame).
1034 void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
1036 struct drm_i915_private *dev_priv = dev->dev_private;
1038 if (INTEL_INFO(dev)->gen >= 4) {
1039 int reg = PIPECONF(pipe);
1041 /* Wait for the Pipe State to go off */
1042 if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
1044 DRM_DEBUG_KMS("pipe_off wait timed out\n");
1047 int reg = PIPEDSL(pipe);
1048 unsigned long timeout = jiffies + msecs_to_jiffies(100);
1050 /* Wait for the display line to settle */
1052 last_line = I915_READ(reg) & DSL_LINEMASK;
1054 } while (((I915_READ(reg) & DSL_LINEMASK) != last_line) &&
1055 time_after(timeout, jiffies));
1056 if (time_after(jiffies, timeout))
1057 DRM_DEBUG_KMS("pipe_off wait timed out\n");
1061 static const char *state_string(bool enabled)
1063 return enabled ? "on" : "off";
1066 /* Only for pre-ILK configs */
1067 static void assert_pll(struct drm_i915_private *dev_priv,
1068 enum pipe pipe, bool state)
1075 val = I915_READ(reg);
1076 cur_state = !!(val & DPLL_VCO_ENABLE);
1077 WARN(cur_state != state,
1078 "PLL state assertion failure (expected %s, current %s)\n",
1079 state_string(state), state_string(cur_state));
1081 #define assert_pll_enabled(d, p) assert_pll(d, p, true)
1082 #define assert_pll_disabled(d, p) assert_pll(d, p, false)
1084 static void assert_pipe_enabled(struct drm_i915_private *dev_priv,
1090 reg = PIPECONF(pipe);
1091 val = I915_READ(reg);
1092 WARN(!(val & PIPECONF_ENABLE),
1093 "pipe %c assertion failure, should be active but is disabled\n",
1097 static void assert_plane_enabled(struct drm_i915_private *dev_priv,
1103 reg = DSPCNTR(plane);
1104 val = I915_READ(reg);
1105 WARN(!(val & DISPLAY_PLANE_ENABLE),
1106 "plane %c assertion failure, should be active but is disabled\n",
1110 static void assert_planes_disabled(struct drm_i915_private *dev_priv,
1117 /* Need to check both planes against the pipe */
1118 for (i = 0; i < 2; i++) {
1120 val = I915_READ(reg);
1121 cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
1122 DISPPLANE_SEL_PIPE_SHIFT;
1123 WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
1124 "plane %d assertion failure, should be off on pipe %c but is still active\n",
1125 i, pipe ? 'B' : 'A');
1130 * intel_enable_pipe - enable a pipe, assertiing requirements
1131 * @dev_priv: i915 private structure
1132 * @pipe: pipe to enable
1134 * Enable @pipe, making sure that various hardware specific requirements
1135 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1137 * @pipe should be %PIPE_A or %PIPE_B.
1139 * Will wait until the pipe is actually running (i.e. first vblank) before
1142 static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
1148 * A pipe without a PLL won't actually be able to drive bits from
1149 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1152 if (!HAS_PCH_SPLIT(dev_priv->dev))
1153 assert_pll_enabled(dev_priv, pipe);
1155 reg = PIPECONF(pipe);
1156 val = I915_READ(reg);
1157 val |= PIPECONF_ENABLE;
1158 I915_WRITE(reg, val);
1160 intel_wait_for_vblank(dev_priv->dev, pipe);
1164 * intel_disable_pipe - disable a pipe, assertiing requirements
1165 * @dev_priv: i915 private structure
1166 * @pipe: pipe to disable
1168 * Disable @pipe, making sure that various hardware specific requirements
1169 * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
1171 * @pipe should be %PIPE_A or %PIPE_B.
1173 * Will wait until the pipe has shut down before returning.
1175 static void intel_disable_pipe(struct drm_i915_private *dev_priv,
1182 * Make sure planes won't keep trying to pump pixels to us,
1183 * or we might hang the display.
1185 assert_planes_disabled(dev_priv, pipe);
1187 /* Don't disable pipe A or pipe A PLLs if needed */
1188 if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
1191 reg = PIPECONF(pipe);
1192 val = I915_READ(reg);
1193 val &= ~PIPECONF_ENABLE;
1194 I915_WRITE(reg, val);
1196 intel_wait_for_pipe_off(dev_priv->dev, pipe);
1200 * intel_enable_plane - enable a display plane on a given pipe
1201 * @dev_priv: i915 private structure
1202 * @plane: plane to enable
1203 * @pipe: pipe being fed
1205 * Enable @plane on @pipe, making sure that @pipe is running first.
1207 static void intel_enable_plane(struct drm_i915_private *dev_priv,
1208 enum plane plane, enum pipe pipe)
1213 /* If the pipe isn't enabled, we can't pump pixels and may hang */
1214 assert_pipe_enabled(dev_priv, pipe);
1216 reg = DSPCNTR(plane);
1217 val = I915_READ(reg);
1218 val |= DISPLAY_PLANE_ENABLE;
1219 I915_WRITE(reg, val);
1221 intel_wait_for_vblank(dev_priv->dev, pipe);
1225 * Plane regs are double buffered, going from enabled->disabled needs a
1226 * trigger in order to latch. The display address reg provides this.
1228 static void intel_flush_display_plane(struct drm_i915_private *dev_priv,
1231 u32 reg = DSPADDR(plane);
1232 I915_WRITE(reg, I915_READ(reg));
1236 * intel_disable_plane - disable a display plane
1237 * @dev_priv: i915 private structure
1238 * @plane: plane to disable
1239 * @pipe: pipe consuming the data
1241 * Disable @plane; should be an independent operation.
1243 static void intel_disable_plane(struct drm_i915_private *dev_priv,
1244 enum plane plane, enum pipe pipe)
1249 reg = DSPCNTR(plane);
1250 val = I915_READ(reg);
1251 val &= ~DISPLAY_PLANE_ENABLE;
1252 I915_WRITE(reg, val);
1254 intel_flush_display_plane(dev_priv, plane);
1255 intel_wait_for_vblank(dev_priv->dev, pipe);
1258 static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
1260 struct drm_device *dev = crtc->dev;
1261 struct drm_i915_private *dev_priv = dev->dev_private;
1262 struct drm_framebuffer *fb = crtc->fb;
1263 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
1264 struct drm_i915_gem_object *obj = intel_fb->obj;
1265 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1267 u32 fbc_ctl, fbc_ctl2;
1269 if (fb->pitch == dev_priv->cfb_pitch &&
1270 obj->fence_reg == dev_priv->cfb_fence &&
1271 intel_crtc->plane == dev_priv->cfb_plane &&
1272 I915_READ(FBC_CONTROL) & FBC_CTL_EN)
1275 i8xx_disable_fbc(dev);
1277 dev_priv->cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE;
1279 if (fb->pitch < dev_priv->cfb_pitch)
1280 dev_priv->cfb_pitch = fb->pitch;
1282 /* FBC_CTL wants 64B units */
1283 dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
1284 dev_priv->cfb_fence = obj->fence_reg;
1285 dev_priv->cfb_plane = intel_crtc->plane;
1286 plane = dev_priv->cfb_plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB;
1288 /* Clear old tags */
1289 for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++)
1290 I915_WRITE(FBC_TAG + (i * 4), 0);
1293 fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | plane;
1294 if (obj->tiling_mode != I915_TILING_NONE)
1295 fbc_ctl2 |= FBC_CTL_CPU_FENCE;
1296 I915_WRITE(FBC_CONTROL2, fbc_ctl2);
1297 I915_WRITE(FBC_FENCE_OFF, crtc->y);
1300 fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC;
1302 fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */
1303 fbc_ctl |= (dev_priv->cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT;
1304 fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT;
1305 if (obj->tiling_mode != I915_TILING_NONE)
1306 fbc_ctl |= dev_priv->cfb_fence;
1307 I915_WRITE(FBC_CONTROL, fbc_ctl);
1309 DRM_DEBUG_KMS("enabled FBC, pitch %ld, yoff %d, plane %d, ",
1310 dev_priv->cfb_pitch, crtc->y, dev_priv->cfb_plane);
1313 void i8xx_disable_fbc(struct drm_device *dev)
1315 struct drm_i915_private *dev_priv = dev->dev_private;
1318 /* Disable compression */
1319 fbc_ctl = I915_READ(FBC_CONTROL);
1320 if ((fbc_ctl & FBC_CTL_EN) == 0)
1323 fbc_ctl &= ~FBC_CTL_EN;
1324 I915_WRITE(FBC_CONTROL, fbc_ctl);
1326 /* Wait for compressing bit to clear */
1327 if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) {
1328 DRM_DEBUG_KMS("FBC idle timed out\n");
1332 DRM_DEBUG_KMS("disabled FBC\n");
1335 static bool i8xx_fbc_enabled(struct drm_device *dev)
1337 struct drm_i915_private *dev_priv = dev->dev_private;
1339 return I915_READ(FBC_CONTROL) & FBC_CTL_EN;
1342 static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
1344 struct drm_device *dev = crtc->dev;
1345 struct drm_i915_private *dev_priv = dev->dev_private;
1346 struct drm_framebuffer *fb = crtc->fb;
1347 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
1348 struct drm_i915_gem_object *obj = intel_fb->obj;
1349 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1350 int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB;
1351 unsigned long stall_watermark = 200;
1354 dpfc_ctl = I915_READ(DPFC_CONTROL);
1355 if (dpfc_ctl & DPFC_CTL_EN) {
1356 if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 &&
1357 dev_priv->cfb_fence == obj->fence_reg &&
1358 dev_priv->cfb_plane == intel_crtc->plane &&
1359 dev_priv->cfb_y == crtc->y)
1362 I915_WRITE(DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN);
1363 POSTING_READ(DPFC_CONTROL);
1364 intel_wait_for_vblank(dev, intel_crtc->pipe);
1367 dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
1368 dev_priv->cfb_fence = obj->fence_reg;
1369 dev_priv->cfb_plane = intel_crtc->plane;
1370 dev_priv->cfb_y = crtc->y;
1372 dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X;
1373 if (obj->tiling_mode != I915_TILING_NONE) {
1374 dpfc_ctl |= DPFC_CTL_FENCE_EN | dev_priv->cfb_fence;
1375 I915_WRITE(DPFC_CHICKEN, DPFC_HT_MODIFY);
1377 I915_WRITE(DPFC_CHICKEN, ~DPFC_HT_MODIFY);
1380 I915_WRITE(DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
1381 (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
1382 (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
1383 I915_WRITE(DPFC_FENCE_YOFF, crtc->y);
1386 I915_WRITE(DPFC_CONTROL, I915_READ(DPFC_CONTROL) | DPFC_CTL_EN);
1388 DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane);
1391 void g4x_disable_fbc(struct drm_device *dev)
1393 struct drm_i915_private *dev_priv = dev->dev_private;
1396 /* Disable compression */
1397 dpfc_ctl = I915_READ(DPFC_CONTROL);
1398 if (dpfc_ctl & DPFC_CTL_EN) {
1399 dpfc_ctl &= ~DPFC_CTL_EN;
1400 I915_WRITE(DPFC_CONTROL, dpfc_ctl);
1402 DRM_DEBUG_KMS("disabled FBC\n");
1406 static bool g4x_fbc_enabled(struct drm_device *dev)
1408 struct drm_i915_private *dev_priv = dev->dev_private;
1410 return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN;
1413 static void ironlake_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
1415 struct drm_device *dev = crtc->dev;
1416 struct drm_i915_private *dev_priv = dev->dev_private;
1417 struct drm_framebuffer *fb = crtc->fb;
1418 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
1419 struct drm_i915_gem_object *obj = intel_fb->obj;
1420 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1421 int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB;
1422 unsigned long stall_watermark = 200;
1425 dpfc_ctl = I915_READ(ILK_DPFC_CONTROL);
1426 if (dpfc_ctl & DPFC_CTL_EN) {
1427 if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 &&
1428 dev_priv->cfb_fence == obj->fence_reg &&
1429 dev_priv->cfb_plane == intel_crtc->plane &&
1430 dev_priv->cfb_offset == obj->gtt_offset &&
1431 dev_priv->cfb_y == crtc->y)
1434 I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN);
1435 POSTING_READ(ILK_DPFC_CONTROL);
1436 intel_wait_for_vblank(dev, intel_crtc->pipe);
1439 dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
1440 dev_priv->cfb_fence = obj->fence_reg;
1441 dev_priv->cfb_plane = intel_crtc->plane;
1442 dev_priv->cfb_offset = obj->gtt_offset;
1443 dev_priv->cfb_y = crtc->y;
1445 dpfc_ctl &= DPFC_RESERVED;
1446 dpfc_ctl |= (plane | DPFC_CTL_LIMIT_1X);
1447 if (obj->tiling_mode != I915_TILING_NONE) {
1448 dpfc_ctl |= (DPFC_CTL_FENCE_EN | dev_priv->cfb_fence);
1449 I915_WRITE(ILK_DPFC_CHICKEN, DPFC_HT_MODIFY);
1451 I915_WRITE(ILK_DPFC_CHICKEN, ~DPFC_HT_MODIFY);
1454 I915_WRITE(ILK_DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
1455 (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
1456 (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
1457 I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y);
1458 I915_WRITE(ILK_FBC_RT_BASE, obj->gtt_offset | ILK_FBC_RT_VALID);
1460 I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN);
1463 I915_WRITE(SNB_DPFC_CTL_SA,
1464 SNB_CPU_FENCE_ENABLE | dev_priv->cfb_fence);
1465 I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y);
1468 DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane);
1471 void ironlake_disable_fbc(struct drm_device *dev)
1473 struct drm_i915_private *dev_priv = dev->dev_private;
1476 /* Disable compression */
1477 dpfc_ctl = I915_READ(ILK_DPFC_CONTROL);
1478 if (dpfc_ctl & DPFC_CTL_EN) {
1479 dpfc_ctl &= ~DPFC_CTL_EN;
1480 I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl);
1482 DRM_DEBUG_KMS("disabled FBC\n");
1486 static bool ironlake_fbc_enabled(struct drm_device *dev)
1488 struct drm_i915_private *dev_priv = dev->dev_private;
1490 return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN;
1493 bool intel_fbc_enabled(struct drm_device *dev)
1495 struct drm_i915_private *dev_priv = dev->dev_private;
1497 if (!dev_priv->display.fbc_enabled)
1500 return dev_priv->display.fbc_enabled(dev);
1503 void intel_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
1505 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1507 if (!dev_priv->display.enable_fbc)
1510 dev_priv->display.enable_fbc(crtc, interval);
1513 void intel_disable_fbc(struct drm_device *dev)
1515 struct drm_i915_private *dev_priv = dev->dev_private;
1517 if (!dev_priv->display.disable_fbc)
1520 dev_priv->display.disable_fbc(dev);
1524 * intel_update_fbc - enable/disable FBC as needed
1525 * @dev: the drm_device
1527 * Set up the framebuffer compression hardware at mode set time. We
1528 * enable it if possible:
1529 * - plane A only (on pre-965)
1530 * - no pixel mulitply/line duplication
1531 * - no alpha buffer discard
1533 * - framebuffer <= 2048 in width, 1536 in height
1535 * We can't assume that any compression will take place (worst case),
1536 * so the compressed buffer has to be the same size as the uncompressed
1537 * one. It also must reside (along with the line length buffer) in
1540 * We need to enable/disable FBC on a global basis.
1542 static void intel_update_fbc(struct drm_device *dev)
1544 struct drm_i915_private *dev_priv = dev->dev_private;
1545 struct drm_crtc *crtc = NULL, *tmp_crtc;
1546 struct intel_crtc *intel_crtc;
1547 struct drm_framebuffer *fb;
1548 struct intel_framebuffer *intel_fb;
1549 struct drm_i915_gem_object *obj;
1551 DRM_DEBUG_KMS("\n");
1553 if (!i915_powersave)
1556 if (!I915_HAS_FBC(dev))
1560 * If FBC is already on, we just have to verify that we can
1561 * keep it that way...
1562 * Need to disable if:
1563 * - more than one pipe is active
1564 * - changing FBC params (stride, fence, mode)
1565 * - new fb is too large to fit in compressed buffer
1566 * - going to an unsupported config (interlace, pixel multiply, etc.)
1568 list_for_each_entry(tmp_crtc, &dev->mode_config.crtc_list, head) {
1569 if (tmp_crtc->enabled) {
1571 DRM_DEBUG_KMS("more than one pipe active, disabling compression\n");
1572 dev_priv->no_fbc_reason = FBC_MULTIPLE_PIPES;
1579 if (!crtc || crtc->fb == NULL) {
1580 DRM_DEBUG_KMS("no output, disabling\n");
1581 dev_priv->no_fbc_reason = FBC_NO_OUTPUT;
1585 intel_crtc = to_intel_crtc(crtc);
1587 intel_fb = to_intel_framebuffer(fb);
1588 obj = intel_fb->obj;
1590 if (intel_fb->obj->base.size > dev_priv->cfb_size) {
1591 DRM_DEBUG_KMS("framebuffer too large, disabling "
1593 dev_priv->no_fbc_reason = FBC_STOLEN_TOO_SMALL;
1596 if ((crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) ||
1597 (crtc->mode.flags & DRM_MODE_FLAG_DBLSCAN)) {
1598 DRM_DEBUG_KMS("mode incompatible with compression, "
1600 dev_priv->no_fbc_reason = FBC_UNSUPPORTED_MODE;
1603 if ((crtc->mode.hdisplay > 2048) ||
1604 (crtc->mode.vdisplay > 1536)) {
1605 DRM_DEBUG_KMS("mode too large for compression, disabling\n");
1606 dev_priv->no_fbc_reason = FBC_MODE_TOO_LARGE;
1609 if ((IS_I915GM(dev) || IS_I945GM(dev)) && intel_crtc->plane != 0) {
1610 DRM_DEBUG_KMS("plane not 0, disabling compression\n");
1611 dev_priv->no_fbc_reason = FBC_BAD_PLANE;
1614 if (obj->tiling_mode != I915_TILING_X) {
1615 DRM_DEBUG_KMS("framebuffer not tiled, disabling compression\n");
1616 dev_priv->no_fbc_reason = FBC_NOT_TILED;
1620 /* If the kernel debugger is active, always disable compression */
1621 if (in_dbg_master())
1624 intel_enable_fbc(crtc, 500);
1628 /* Multiple disables should be harmless */
1629 if (intel_fbc_enabled(dev)) {
1630 DRM_DEBUG_KMS("unsupported config, disabling FBC\n");
1631 intel_disable_fbc(dev);
1636 intel_pin_and_fence_fb_obj(struct drm_device *dev,
1637 struct drm_i915_gem_object *obj,
1638 struct intel_ring_buffer *pipelined)
1643 switch (obj->tiling_mode) {
1644 case I915_TILING_NONE:
1645 if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
1646 alignment = 128 * 1024;
1647 else if (INTEL_INFO(dev)->gen >= 4)
1648 alignment = 4 * 1024;
1650 alignment = 64 * 1024;
1653 /* pin() will align the object as required by fence */
1657 /* FIXME: Is this true? */
1658 DRM_ERROR("Y tiled not allowed for scan out buffers\n");
1664 ret = i915_gem_object_pin(obj, alignment, true);
1668 ret = i915_gem_object_set_to_display_plane(obj, pipelined);
1672 /* Install a fence for tiled scan-out. Pre-i965 always needs a
1673 * fence, whereas 965+ only requires a fence if using
1674 * framebuffer compression. For simplicity, we always install
1675 * a fence as the cost is not that onerous.
1677 if (obj->tiling_mode != I915_TILING_NONE) {
1678 ret = i915_gem_object_get_fence(obj, pipelined, false);
1686 i915_gem_object_unpin(obj);
1690 /* Assume fb object is pinned & idle & fenced and just update base pointers */
1692 intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
1693 int x, int y, enum mode_set_atomic state)
1695 struct drm_device *dev = crtc->dev;
1696 struct drm_i915_private *dev_priv = dev->dev_private;
1697 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1698 struct intel_framebuffer *intel_fb;
1699 struct drm_i915_gem_object *obj;
1700 int plane = intel_crtc->plane;
1701 unsigned long Start, Offset;
1710 DRM_ERROR("Can't update plane %d in SAREA\n", plane);
1714 intel_fb = to_intel_framebuffer(fb);
1715 obj = intel_fb->obj;
1717 reg = DSPCNTR(plane);
1718 dspcntr = I915_READ(reg);
1719 /* Mask out pixel format bits in case we change it */
1720 dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
1721 switch (fb->bits_per_pixel) {
1723 dspcntr |= DISPPLANE_8BPP;
1726 if (fb->depth == 15)
1727 dspcntr |= DISPPLANE_15_16BPP;
1729 dspcntr |= DISPPLANE_16BPP;
1733 dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
1736 DRM_ERROR("Unknown color depth\n");
1739 if (INTEL_INFO(dev)->gen >= 4) {
1740 if (obj->tiling_mode != I915_TILING_NONE)
1741 dspcntr |= DISPPLANE_TILED;
1743 dspcntr &= ~DISPPLANE_TILED;
1746 if (HAS_PCH_SPLIT(dev))
1748 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
1750 I915_WRITE(reg, dspcntr);
1752 Start = obj->gtt_offset;
1753 Offset = y * fb->pitch + x * (fb->bits_per_pixel / 8);
1755 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
1756 Start, Offset, x, y, fb->pitch);
1757 I915_WRITE(DSPSTRIDE(plane), fb->pitch);
1758 if (INTEL_INFO(dev)->gen >= 4) {
1759 I915_WRITE(DSPSURF(plane), Start);
1760 I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
1761 I915_WRITE(DSPADDR(plane), Offset);
1763 I915_WRITE(DSPADDR(plane), Start + Offset);
1766 intel_update_fbc(dev);
1767 intel_increase_pllclock(crtc);
1773 intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
1774 struct drm_framebuffer *old_fb)
1776 struct drm_device *dev = crtc->dev;
1777 struct drm_i915_master_private *master_priv;
1778 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1783 DRM_DEBUG_KMS("No FB bound\n");
1787 switch (intel_crtc->plane) {
1795 mutex_lock(&dev->struct_mutex);
1796 ret = intel_pin_and_fence_fb_obj(dev,
1797 to_intel_framebuffer(crtc->fb)->obj,
1800 mutex_unlock(&dev->struct_mutex);
1805 struct drm_i915_private *dev_priv = dev->dev_private;
1806 struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
1808 wait_event(dev_priv->pending_flip_queue,
1809 atomic_read(&obj->pending_flip) == 0);
1811 /* Big Hammer, we also need to ensure that any pending
1812 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
1813 * current scanout is retired before unpinning the old
1816 ret = i915_gem_object_flush_gpu(obj, false);
1818 i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj);
1819 mutex_unlock(&dev->struct_mutex);
1824 ret = intel_pipe_set_base_atomic(crtc, crtc->fb, x, y,
1825 LEAVE_ATOMIC_MODE_SET);
1827 i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj);
1828 mutex_unlock(&dev->struct_mutex);
1833 intel_wait_for_vblank(dev, intel_crtc->pipe);
1834 i915_gem_object_unpin(to_intel_framebuffer(old_fb)->obj);
1837 mutex_unlock(&dev->struct_mutex);
1839 if (!dev->primary->master)
1842 master_priv = dev->primary->master->driver_priv;
1843 if (!master_priv->sarea_priv)
1846 if (intel_crtc->pipe) {
1847 master_priv->sarea_priv->pipeB_x = x;
1848 master_priv->sarea_priv->pipeB_y = y;
1850 master_priv->sarea_priv->pipeA_x = x;
1851 master_priv->sarea_priv->pipeA_y = y;
1857 static void ironlake_set_pll_edp(struct drm_crtc *crtc, int clock)
1859 struct drm_device *dev = crtc->dev;
1860 struct drm_i915_private *dev_priv = dev->dev_private;
1863 DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", clock);
1864 dpa_ctl = I915_READ(DP_A);
1865 dpa_ctl &= ~DP_PLL_FREQ_MASK;
1867 if (clock < 200000) {
1869 dpa_ctl |= DP_PLL_FREQ_160MHZ;
1870 /* workaround for 160Mhz:
1871 1) program 0x4600c bits 15:0 = 0x8124
1872 2) program 0x46010 bit 0 = 1
1873 3) program 0x46034 bit 24 = 1
1874 4) program 0x64000 bit 14 = 1
1876 temp = I915_READ(0x4600c);
1878 I915_WRITE(0x4600c, temp | 0x8124);
1880 temp = I915_READ(0x46010);
1881 I915_WRITE(0x46010, temp | 1);
1883 temp = I915_READ(0x46034);
1884 I915_WRITE(0x46034, temp | (1 << 24));
1886 dpa_ctl |= DP_PLL_FREQ_270MHZ;
1888 I915_WRITE(DP_A, dpa_ctl);
1894 static void intel_fdi_normal_train(struct drm_crtc *crtc)
1896 struct drm_device *dev = crtc->dev;
1897 struct drm_i915_private *dev_priv = dev->dev_private;
1898 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1899 int pipe = intel_crtc->pipe;
1902 /* enable normal train */
1903 reg = FDI_TX_CTL(pipe);
1904 temp = I915_READ(reg);
1905 temp &= ~FDI_LINK_TRAIN_NONE;
1906 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
1907 I915_WRITE(reg, temp);
1909 reg = FDI_RX_CTL(pipe);
1910 temp = I915_READ(reg);
1911 if (HAS_PCH_CPT(dev)) {
1912 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
1913 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
1915 temp &= ~FDI_LINK_TRAIN_NONE;
1916 temp |= FDI_LINK_TRAIN_NONE;
1918 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
1920 /* wait one idle pattern time */
1925 /* The FDI link training functions for ILK/Ibexpeak. */
1926 static void ironlake_fdi_link_train(struct drm_crtc *crtc)
1928 struct drm_device *dev = crtc->dev;
1929 struct drm_i915_private *dev_priv = dev->dev_private;
1930 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1931 int pipe = intel_crtc->pipe;
1932 u32 reg, temp, tries;
1934 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
1936 reg = FDI_RX_IMR(pipe);
1937 temp = I915_READ(reg);
1938 temp &= ~FDI_RX_SYMBOL_LOCK;
1939 temp &= ~FDI_RX_BIT_LOCK;
1940 I915_WRITE(reg, temp);
1944 /* enable CPU FDI TX and PCH FDI RX */
1945 reg = FDI_TX_CTL(pipe);
1946 temp = I915_READ(reg);
1948 temp |= (intel_crtc->fdi_lanes - 1) << 19;
1949 temp &= ~FDI_LINK_TRAIN_NONE;
1950 temp |= FDI_LINK_TRAIN_PATTERN_1;
1951 I915_WRITE(reg, temp | FDI_TX_ENABLE);
1953 reg = FDI_RX_CTL(pipe);
1954 temp = I915_READ(reg);
1955 temp &= ~FDI_LINK_TRAIN_NONE;
1956 temp |= FDI_LINK_TRAIN_PATTERN_1;
1957 I915_WRITE(reg, temp | FDI_RX_ENABLE);
1962 /* Ironlake workaround, enable clock pointer after FDI enable*/
1963 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_ENABLE);
1965 reg = FDI_RX_IIR(pipe);
1966 for (tries = 0; tries < 5; tries++) {
1967 temp = I915_READ(reg);
1968 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
1970 if ((temp & FDI_RX_BIT_LOCK)) {
1971 DRM_DEBUG_KMS("FDI train 1 done.\n");
1972 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
1977 DRM_ERROR("FDI train 1 fail!\n");
1980 reg = FDI_TX_CTL(pipe);
1981 temp = I915_READ(reg);
1982 temp &= ~FDI_LINK_TRAIN_NONE;
1983 temp |= FDI_LINK_TRAIN_PATTERN_2;
1984 I915_WRITE(reg, temp);
1986 reg = FDI_RX_CTL(pipe);
1987 temp = I915_READ(reg);
1988 temp &= ~FDI_LINK_TRAIN_NONE;
1989 temp |= FDI_LINK_TRAIN_PATTERN_2;
1990 I915_WRITE(reg, temp);
1995 reg = FDI_RX_IIR(pipe);
1996 for (tries = 0; tries < 5; tries++) {
1997 temp = I915_READ(reg);
1998 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2000 if (temp & FDI_RX_SYMBOL_LOCK) {
2001 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2002 DRM_DEBUG_KMS("FDI train 2 done.\n");
2007 DRM_ERROR("FDI train 2 fail!\n");
2009 DRM_DEBUG_KMS("FDI train done\n");
2013 static const int const snb_b_fdi_train_param [] = {
2014 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
2015 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
2016 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
2017 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
2020 /* The FDI link training functions for SNB/Cougarpoint. */
2021 static void gen6_fdi_link_train(struct drm_crtc *crtc)
2023 struct drm_device *dev = crtc->dev;
2024 struct drm_i915_private *dev_priv = dev->dev_private;
2025 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2026 int pipe = intel_crtc->pipe;
2029 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2031 reg = FDI_RX_IMR(pipe);
2032 temp = I915_READ(reg);
2033 temp &= ~FDI_RX_SYMBOL_LOCK;
2034 temp &= ~FDI_RX_BIT_LOCK;
2035 I915_WRITE(reg, temp);
2040 /* enable CPU FDI TX and PCH FDI RX */
2041 reg = FDI_TX_CTL(pipe);
2042 temp = I915_READ(reg);
2044 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2045 temp &= ~FDI_LINK_TRAIN_NONE;
2046 temp |= FDI_LINK_TRAIN_PATTERN_1;
2047 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2049 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2050 I915_WRITE(reg, temp | FDI_TX_ENABLE);
2052 reg = FDI_RX_CTL(pipe);
2053 temp = I915_READ(reg);
2054 if (HAS_PCH_CPT(dev)) {
2055 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2056 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
2058 temp &= ~FDI_LINK_TRAIN_NONE;
2059 temp |= FDI_LINK_TRAIN_PATTERN_1;
2061 I915_WRITE(reg, temp | FDI_RX_ENABLE);
2066 for (i = 0; i < 4; i++ ) {
2067 reg = FDI_TX_CTL(pipe);
2068 temp = I915_READ(reg);
2069 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2070 temp |= snb_b_fdi_train_param[i];
2071 I915_WRITE(reg, temp);
2076 reg = FDI_RX_IIR(pipe);
2077 temp = I915_READ(reg);
2078 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2080 if (temp & FDI_RX_BIT_LOCK) {
2081 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2082 DRM_DEBUG_KMS("FDI train 1 done.\n");
2087 DRM_ERROR("FDI train 1 fail!\n");
2090 reg = FDI_TX_CTL(pipe);
2091 temp = I915_READ(reg);
2092 temp &= ~FDI_LINK_TRAIN_NONE;
2093 temp |= FDI_LINK_TRAIN_PATTERN_2;
2095 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2097 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2099 I915_WRITE(reg, temp);
2101 reg = FDI_RX_CTL(pipe);
2102 temp = I915_READ(reg);
2103 if (HAS_PCH_CPT(dev)) {
2104 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2105 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
2107 temp &= ~FDI_LINK_TRAIN_NONE;
2108 temp |= FDI_LINK_TRAIN_PATTERN_2;
2110 I915_WRITE(reg, temp);
2115 for (i = 0; i < 4; i++ ) {
2116 reg = FDI_TX_CTL(pipe);
2117 temp = I915_READ(reg);
2118 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2119 temp |= snb_b_fdi_train_param[i];
2120 I915_WRITE(reg, temp);
2125 reg = FDI_RX_IIR(pipe);
2126 temp = I915_READ(reg);
2127 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2129 if (temp & FDI_RX_SYMBOL_LOCK) {
2130 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2131 DRM_DEBUG_KMS("FDI train 2 done.\n");
2136 DRM_ERROR("FDI train 2 fail!\n");
2138 DRM_DEBUG_KMS("FDI train done.\n");
2141 static void ironlake_fdi_enable(struct drm_crtc *crtc)
2143 struct drm_device *dev = crtc->dev;
2144 struct drm_i915_private *dev_priv = dev->dev_private;
2145 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2146 int pipe = intel_crtc->pipe;
2149 /* Write the TU size bits so error detection works */
2150 I915_WRITE(FDI_RX_TUSIZE1(pipe),
2151 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
2153 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
2154 reg = FDI_RX_CTL(pipe);
2155 temp = I915_READ(reg);
2156 temp &= ~((0x7 << 19) | (0x7 << 16));
2157 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2158 temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
2159 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
2164 /* Switch from Rawclk to PCDclk */
2165 temp = I915_READ(reg);
2166 I915_WRITE(reg, temp | FDI_PCDCLK);
2171 /* Enable CPU FDI TX PLL, always on for Ironlake */
2172 reg = FDI_TX_CTL(pipe);
2173 temp = I915_READ(reg);
2174 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
2175 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
2183 * When we disable a pipe, we need to clear any pending scanline wait events
2184 * to avoid hanging the ring, which we assume we are waiting on.
2186 static void intel_clear_scanline_wait(struct drm_device *dev)
2188 struct drm_i915_private *dev_priv = dev->dev_private;
2189 struct intel_ring_buffer *ring;
2193 /* Can't break the hang on i8xx */
2196 ring = LP_RING(dev_priv);
2197 tmp = I915_READ_CTL(ring);
2198 if (tmp & RING_WAIT)
2199 I915_WRITE_CTL(ring, tmp);
2202 static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
2204 struct drm_i915_gem_object *obj;
2205 struct drm_i915_private *dev_priv;
2207 if (crtc->fb == NULL)
2210 obj = to_intel_framebuffer(crtc->fb)->obj;
2211 dev_priv = crtc->dev->dev_private;
2212 wait_event(dev_priv->pending_flip_queue,
2213 atomic_read(&obj->pending_flip) == 0);
2216 static void ironlake_crtc_enable(struct drm_crtc *crtc)
2218 struct drm_device *dev = crtc->dev;
2219 struct drm_i915_private *dev_priv = dev->dev_private;
2220 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2221 int pipe = intel_crtc->pipe;
2222 int plane = intel_crtc->plane;
2225 if (intel_crtc->active)
2228 intel_crtc->active = true;
2229 intel_update_watermarks(dev);
2231 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
2232 temp = I915_READ(PCH_LVDS);
2233 if ((temp & LVDS_PORT_EN) == 0)
2234 I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
2237 ironlake_fdi_enable(crtc);
2239 /* Enable panel fitting for LVDS */
2240 if (dev_priv->pch_pf_size &&
2241 (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || HAS_eDP)) {
2242 /* Force use of hard-coded filter coefficients
2243 * as some pre-programmed values are broken,
2246 I915_WRITE(pipe ? PFB_CTL_1 : PFA_CTL_1,
2247 PF_ENABLE | PF_FILTER_MED_3x3);
2248 I915_WRITE(pipe ? PFB_WIN_POS : PFA_WIN_POS,
2249 dev_priv->pch_pf_pos);
2250 I915_WRITE(pipe ? PFB_WIN_SZ : PFA_WIN_SZ,
2251 dev_priv->pch_pf_size);
2254 intel_enable_pipe(dev_priv, pipe);
2255 intel_enable_plane(dev_priv, plane, pipe);
2257 /* For PCH output, training FDI link */
2259 gen6_fdi_link_train(crtc);
2261 ironlake_fdi_link_train(crtc);
2263 /* enable PCH DPLL */
2264 reg = PCH_DPLL(pipe);
2265 temp = I915_READ(reg);
2266 if ((temp & DPLL_VCO_ENABLE) == 0) {
2267 I915_WRITE(reg, temp | DPLL_VCO_ENABLE);
2272 if (HAS_PCH_CPT(dev)) {
2273 /* Be sure PCH DPLL SEL is set */
2274 temp = I915_READ(PCH_DPLL_SEL);
2275 if (pipe == 0 && (temp & TRANSA_DPLL_ENABLE) == 0)
2276 temp |= (TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL);
2277 else if (pipe == 1 && (temp & TRANSB_DPLL_ENABLE) == 0)
2278 temp |= (TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
2279 I915_WRITE(PCH_DPLL_SEL, temp);
2282 /* set transcoder timing */
2283 I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
2284 I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
2285 I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
2287 I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
2288 I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
2289 I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
2291 intel_fdi_normal_train(crtc);
2293 /* For PCH DP, enable TRANS_DP_CTL */
2294 if (HAS_PCH_CPT(dev) &&
2295 intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
2296 reg = TRANS_DP_CTL(pipe);
2297 temp = I915_READ(reg);
2298 temp &= ~(TRANS_DP_PORT_SEL_MASK |
2299 TRANS_DP_SYNC_MASK |
2301 temp |= (TRANS_DP_OUTPUT_ENABLE |
2302 TRANS_DP_ENH_FRAMING);
2303 temp |= TRANS_DP_8BPC;
2305 if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
2306 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
2307 if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
2308 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
2310 switch (intel_trans_dp_port_sel(crtc)) {
2312 temp |= TRANS_DP_PORT_SEL_B;
2315 temp |= TRANS_DP_PORT_SEL_C;
2318 temp |= TRANS_DP_PORT_SEL_D;
2321 DRM_DEBUG_KMS("Wrong PCH DP port return. Guess port B\n");
2322 temp |= TRANS_DP_PORT_SEL_B;
2326 I915_WRITE(reg, temp);
2329 /* enable PCH transcoder */
2330 reg = TRANSCONF(pipe);
2331 temp = I915_READ(reg);
2333 * make the BPC in transcoder be consistent with
2334 * that in pipeconf reg.
2336 temp &= ~PIPE_BPC_MASK;
2337 temp |= I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK;
2338 I915_WRITE(reg, temp | TRANS_ENABLE);
2339 if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
2340 DRM_ERROR("failed to enable transcoder %d\n", pipe);
2342 intel_crtc_load_lut(crtc);
2343 intel_update_fbc(dev);
2344 intel_crtc_update_cursor(crtc, true);
2347 static void ironlake_crtc_disable(struct drm_crtc *crtc)
2349 struct drm_device *dev = crtc->dev;
2350 struct drm_i915_private *dev_priv = dev->dev_private;
2351 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2352 int pipe = intel_crtc->pipe;
2353 int plane = intel_crtc->plane;
2356 if (!intel_crtc->active)
2359 intel_crtc_wait_for_pending_flips(crtc);
2360 drm_vblank_off(dev, pipe);
2361 intel_crtc_update_cursor(crtc, false);
2363 intel_disable_plane(dev_priv, plane, pipe);
2365 if (dev_priv->cfb_plane == plane &&
2366 dev_priv->display.disable_fbc)
2367 dev_priv->display.disable_fbc(dev);
2369 intel_disable_pipe(dev_priv, pipe);
2372 I915_WRITE(pipe ? PFB_CTL_1 : PFA_CTL_1, 0);
2373 I915_WRITE(pipe ? PFB_WIN_SZ : PFA_WIN_SZ, 0);
2375 /* disable CPU FDI tx and PCH FDI rx */
2376 reg = FDI_TX_CTL(pipe);
2377 temp = I915_READ(reg);
2378 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
2381 reg = FDI_RX_CTL(pipe);
2382 temp = I915_READ(reg);
2383 temp &= ~(0x7 << 16);
2384 temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
2385 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
2390 /* Ironlake workaround, disable clock pointer after downing FDI */
2391 if (HAS_PCH_IBX(dev))
2392 I915_WRITE(FDI_RX_CHICKEN(pipe),
2393 I915_READ(FDI_RX_CHICKEN(pipe) &
2394 ~FDI_RX_PHASE_SYNC_POINTER_ENABLE));
2396 /* still set train pattern 1 */
2397 reg = FDI_TX_CTL(pipe);
2398 temp = I915_READ(reg);
2399 temp &= ~FDI_LINK_TRAIN_NONE;
2400 temp |= FDI_LINK_TRAIN_PATTERN_1;
2401 I915_WRITE(reg, temp);
2403 reg = FDI_RX_CTL(pipe);
2404 temp = I915_READ(reg);
2405 if (HAS_PCH_CPT(dev)) {
2406 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2407 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
2409 temp &= ~FDI_LINK_TRAIN_NONE;
2410 temp |= FDI_LINK_TRAIN_PATTERN_1;
2412 /* BPC in FDI rx is consistent with that in PIPECONF */
2413 temp &= ~(0x07 << 16);
2414 temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
2415 I915_WRITE(reg, temp);
2420 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
2421 temp = I915_READ(PCH_LVDS);
2422 if (temp & LVDS_PORT_EN) {
2423 I915_WRITE(PCH_LVDS, temp & ~LVDS_PORT_EN);
2424 POSTING_READ(PCH_LVDS);
2429 /* disable PCH transcoder */
2430 reg = TRANSCONF(plane);
2431 temp = I915_READ(reg);
2432 if (temp & TRANS_ENABLE) {
2433 I915_WRITE(reg, temp & ~TRANS_ENABLE);
2434 /* wait for PCH transcoder off, transcoder state */
2435 if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
2436 DRM_ERROR("failed to disable transcoder\n");
2439 if (HAS_PCH_CPT(dev)) {
2440 /* disable TRANS_DP_CTL */
2441 reg = TRANS_DP_CTL(pipe);
2442 temp = I915_READ(reg);
2443 temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
2444 I915_WRITE(reg, temp);
2446 /* disable DPLL_SEL */
2447 temp = I915_READ(PCH_DPLL_SEL);
2449 temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL);
2451 temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
2452 I915_WRITE(PCH_DPLL_SEL, temp);
2455 /* disable PCH DPLL */
2456 reg = PCH_DPLL(pipe);
2457 temp = I915_READ(reg);
2458 I915_WRITE(reg, temp & ~DPLL_VCO_ENABLE);
2460 /* Switch from PCDclk to Rawclk */
2461 reg = FDI_RX_CTL(pipe);
2462 temp = I915_READ(reg);
2463 I915_WRITE(reg, temp & ~FDI_PCDCLK);
2465 /* Disable CPU FDI TX PLL */
2466 reg = FDI_TX_CTL(pipe);
2467 temp = I915_READ(reg);
2468 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
2473 reg = FDI_RX_CTL(pipe);
2474 temp = I915_READ(reg);
2475 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
2477 /* Wait for the clocks to turn off. */
2481 intel_crtc->active = false;
2482 intel_update_watermarks(dev);
2483 intel_update_fbc(dev);
2484 intel_clear_scanline_wait(dev);
2487 static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode)
2489 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2490 int pipe = intel_crtc->pipe;
2491 int plane = intel_crtc->plane;
2493 /* XXX: When our outputs are all unaware of DPMS modes other than off
2494 * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
2497 case DRM_MODE_DPMS_ON:
2498 case DRM_MODE_DPMS_STANDBY:
2499 case DRM_MODE_DPMS_SUSPEND:
2500 DRM_DEBUG_KMS("crtc %d/%d dpms on\n", pipe, plane);
2501 ironlake_crtc_enable(crtc);
2504 case DRM_MODE_DPMS_OFF:
2505 DRM_DEBUG_KMS("crtc %d/%d dpms off\n", pipe, plane);
2506 ironlake_crtc_disable(crtc);
2511 static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
2513 if (!enable && intel_crtc->overlay) {
2514 struct drm_device *dev = intel_crtc->base.dev;
2516 mutex_lock(&dev->struct_mutex);
2517 (void) intel_overlay_switch_off(intel_crtc->overlay, false);
2518 mutex_unlock(&dev->struct_mutex);
2521 /* Let userspace switch the overlay on again. In most cases userspace
2522 * has to recompute where to put it anyway.
2526 static void i9xx_crtc_enable(struct drm_crtc *crtc)
2528 struct drm_device *dev = crtc->dev;
2529 struct drm_i915_private *dev_priv = dev->dev_private;
2530 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2531 int pipe = intel_crtc->pipe;
2532 int plane = intel_crtc->plane;
2535 if (intel_crtc->active)
2538 intel_crtc->active = true;
2539 intel_update_watermarks(dev);
2541 /* Enable the DPLL */
2543 temp = I915_READ(reg);
2544 if ((temp & DPLL_VCO_ENABLE) == 0) {
2545 I915_WRITE(reg, temp);
2547 /* Wait for the clocks to stabilize. */
2551 I915_WRITE(reg, temp | DPLL_VCO_ENABLE);
2553 /* Wait for the clocks to stabilize. */
2557 I915_WRITE(reg, temp | DPLL_VCO_ENABLE);
2559 /* Wait for the clocks to stabilize. */
2564 intel_enable_pipe(dev_priv, pipe);
2565 intel_enable_plane(dev_priv, plane, pipe);
2567 intel_crtc_load_lut(crtc);
2568 intel_update_fbc(dev);
2570 /* Give the overlay scaler a chance to enable if it's on this pipe */
2571 intel_crtc_dpms_overlay(intel_crtc, true);
2572 intel_crtc_update_cursor(crtc, true);
2575 static void i9xx_crtc_disable(struct drm_crtc *crtc)
2577 struct drm_device *dev = crtc->dev;
2578 struct drm_i915_private *dev_priv = dev->dev_private;
2579 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2580 int pipe = intel_crtc->pipe;
2581 int plane = intel_crtc->plane;
2584 if (!intel_crtc->active)
2587 /* Give the overlay scaler a chance to disable if it's on this pipe */
2588 intel_crtc_wait_for_pending_flips(crtc);
2589 drm_vblank_off(dev, pipe);
2590 intel_crtc_dpms_overlay(intel_crtc, false);
2591 intel_crtc_update_cursor(crtc, false);
2593 if (dev_priv->cfb_plane == plane &&
2594 dev_priv->display.disable_fbc)
2595 dev_priv->display.disable_fbc(dev);
2597 intel_disable_plane(dev_priv, plane, pipe);
2599 /* Don't disable pipe A or pipe A PLLs if needed */
2600 if (pipe == 0 && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
2603 intel_disable_pipe(dev_priv, pipe);
2606 temp = I915_READ(reg);
2607 if (temp & DPLL_VCO_ENABLE) {
2608 I915_WRITE(reg, temp & ~DPLL_VCO_ENABLE);
2610 /* Wait for the clocks to turn off. */
2616 intel_crtc->active = false;
2617 intel_update_fbc(dev);
2618 intel_update_watermarks(dev);
2619 intel_clear_scanline_wait(dev);
2622 static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
2624 /* XXX: When our outputs are all unaware of DPMS modes other than off
2625 * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
2628 case DRM_MODE_DPMS_ON:
2629 case DRM_MODE_DPMS_STANDBY:
2630 case DRM_MODE_DPMS_SUSPEND:
2631 i9xx_crtc_enable(crtc);
2633 case DRM_MODE_DPMS_OFF:
2634 i9xx_crtc_disable(crtc);
2640 * Sets the power management mode of the pipe and plane.
2642 static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
2644 struct drm_device *dev = crtc->dev;
2645 struct drm_i915_private *dev_priv = dev->dev_private;
2646 struct drm_i915_master_private *master_priv;
2647 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2648 int pipe = intel_crtc->pipe;
2651 if (intel_crtc->dpms_mode == mode)
2654 intel_crtc->dpms_mode = mode;
2656 dev_priv->display.dpms(crtc, mode);
2658 if (!dev->primary->master)
2661 master_priv = dev->primary->master->driver_priv;
2662 if (!master_priv->sarea_priv)
2665 enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
2669 master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
2670 master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
2673 master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
2674 master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
2677 DRM_ERROR("Can't update pipe %d in SAREA\n", pipe);
2682 static void intel_crtc_disable(struct drm_crtc *crtc)
2684 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
2685 struct drm_device *dev = crtc->dev;
2687 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
2690 mutex_lock(&dev->struct_mutex);
2691 i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj);
2692 mutex_unlock(&dev->struct_mutex);
2696 /* Prepare for a mode set.
2698 * Note we could be a lot smarter here. We need to figure out which outputs
2699 * will be enabled, which disabled (in short, how the config will changes)
2700 * and perform the minimum necessary steps to accomplish that, e.g. updating
2701 * watermarks, FBC configuration, making sure PLLs are programmed correctly,
2702 * panel fitting is in the proper state, etc.
2704 static void i9xx_crtc_prepare(struct drm_crtc *crtc)
2706 i9xx_crtc_disable(crtc);
2709 static void i9xx_crtc_commit(struct drm_crtc *crtc)
2711 i9xx_crtc_enable(crtc);
2714 static void ironlake_crtc_prepare(struct drm_crtc *crtc)
2716 ironlake_crtc_disable(crtc);
2719 static void ironlake_crtc_commit(struct drm_crtc *crtc)
2721 ironlake_crtc_enable(crtc);
2724 void intel_encoder_prepare (struct drm_encoder *encoder)
2726 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
2727 /* lvds has its own version of prepare see intel_lvds_prepare */
2728 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
2731 void intel_encoder_commit (struct drm_encoder *encoder)
2733 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
2734 /* lvds has its own version of commit see intel_lvds_commit */
2735 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
2738 void intel_encoder_destroy(struct drm_encoder *encoder)
2740 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2742 drm_encoder_cleanup(encoder);
2743 kfree(intel_encoder);
2746 static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
2747 struct drm_display_mode *mode,
2748 struct drm_display_mode *adjusted_mode)
2750 struct drm_device *dev = crtc->dev;
2752 if (HAS_PCH_SPLIT(dev)) {
2753 /* FDI link clock is fixed at 2.7G */
2754 if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
2758 /* XXX some encoders set the crtcinfo, others don't.
2759 * Obviously we need some form of conflict resolution here...
2761 if (adjusted_mode->crtc_htotal == 0)
2762 drm_mode_set_crtcinfo(adjusted_mode, 0);
2767 static int i945_get_display_clock_speed(struct drm_device *dev)
2772 static int i915_get_display_clock_speed(struct drm_device *dev)
2777 static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
2782 static int i915gm_get_display_clock_speed(struct drm_device *dev)
2786 pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
2788 if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
2791 switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
2792 case GC_DISPLAY_CLOCK_333_MHZ:
2795 case GC_DISPLAY_CLOCK_190_200_MHZ:
2801 static int i865_get_display_clock_speed(struct drm_device *dev)
2806 static int i855_get_display_clock_speed(struct drm_device *dev)
2809 /* Assume that the hardware is in the high speed state. This
2810 * should be the default.
2812 switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
2813 case GC_CLOCK_133_200:
2814 case GC_CLOCK_100_200:
2816 case GC_CLOCK_166_250:
2818 case GC_CLOCK_100_133:
2822 /* Shouldn't happen */
2826 static int i830_get_display_clock_speed(struct drm_device *dev)
2840 fdi_reduce_ratio(u32 *num, u32 *den)
2842 while (*num > 0xffffff || *den > 0xffffff) {
2849 ironlake_compute_m_n(int bits_per_pixel, int nlanes, int pixel_clock,
2850 int link_clock, struct fdi_m_n *m_n)
2852 m_n->tu = 64; /* default size */
2854 /* BUG_ON(pixel_clock > INT_MAX / 36); */
2855 m_n->gmch_m = bits_per_pixel * pixel_clock;
2856 m_n->gmch_n = link_clock * nlanes * 8;
2857 fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
2859 m_n->link_m = pixel_clock;
2860 m_n->link_n = link_clock;
2861 fdi_reduce_ratio(&m_n->link_m, &m_n->link_n);
2865 struct intel_watermark_params {
2866 unsigned long fifo_size;
2867 unsigned long max_wm;
2868 unsigned long default_wm;
2869 unsigned long guard_size;
2870 unsigned long cacheline_size;
2873 /* Pineview has different values for various configs */
2874 static struct intel_watermark_params pineview_display_wm = {
2875 PINEVIEW_DISPLAY_FIFO,
2879 PINEVIEW_FIFO_LINE_SIZE
2881 static struct intel_watermark_params pineview_display_hplloff_wm = {
2882 PINEVIEW_DISPLAY_FIFO,
2884 PINEVIEW_DFT_HPLLOFF_WM,
2886 PINEVIEW_FIFO_LINE_SIZE
2888 static struct intel_watermark_params pineview_cursor_wm = {
2889 PINEVIEW_CURSOR_FIFO,
2890 PINEVIEW_CURSOR_MAX_WM,
2891 PINEVIEW_CURSOR_DFT_WM,
2892 PINEVIEW_CURSOR_GUARD_WM,
2893 PINEVIEW_FIFO_LINE_SIZE,
2895 static struct intel_watermark_params pineview_cursor_hplloff_wm = {
2896 PINEVIEW_CURSOR_FIFO,
2897 PINEVIEW_CURSOR_MAX_WM,
2898 PINEVIEW_CURSOR_DFT_WM,
2899 PINEVIEW_CURSOR_GUARD_WM,
2900 PINEVIEW_FIFO_LINE_SIZE
2902 static struct intel_watermark_params g4x_wm_info = {
2909 static struct intel_watermark_params g4x_cursor_wm_info = {
2916 static struct intel_watermark_params i965_cursor_wm_info = {
2921 I915_FIFO_LINE_SIZE,
2923 static struct intel_watermark_params i945_wm_info = {
2930 static struct intel_watermark_params i915_wm_info = {
2937 static struct intel_watermark_params i855_wm_info = {
2944 static struct intel_watermark_params i830_wm_info = {
2952 static struct intel_watermark_params ironlake_display_wm_info = {
2960 static struct intel_watermark_params ironlake_cursor_wm_info = {
2968 static struct intel_watermark_params ironlake_display_srwm_info = {
2969 ILK_DISPLAY_SR_FIFO,
2970 ILK_DISPLAY_MAX_SRWM,
2971 ILK_DISPLAY_DFT_SRWM,
2976 static struct intel_watermark_params ironlake_cursor_srwm_info = {
2978 ILK_CURSOR_MAX_SRWM,
2979 ILK_CURSOR_DFT_SRWM,
2984 static struct intel_watermark_params sandybridge_display_wm_info = {
2992 static struct intel_watermark_params sandybridge_cursor_wm_info = {
3000 static struct intel_watermark_params sandybridge_display_srwm_info = {
3001 SNB_DISPLAY_SR_FIFO,
3002 SNB_DISPLAY_MAX_SRWM,
3003 SNB_DISPLAY_DFT_SRWM,
3008 static struct intel_watermark_params sandybridge_cursor_srwm_info = {
3010 SNB_CURSOR_MAX_SRWM,
3011 SNB_CURSOR_DFT_SRWM,
3018 * intel_calculate_wm - calculate watermark level
3019 * @clock_in_khz: pixel clock
3020 * @wm: chip FIFO params
3021 * @pixel_size: display pixel size
3022 * @latency_ns: memory latency for the platform
3024 * Calculate the watermark level (the level at which the display plane will
3025 * start fetching from memory again). Each chip has a different display
3026 * FIFO size and allocation, so the caller needs to figure that out and pass
3027 * in the correct intel_watermark_params structure.
3029 * As the pixel clock runs, the FIFO will be drained at a rate that depends
3030 * on the pixel size. When it reaches the watermark level, it'll start
3031 * fetching FIFO line sized based chunks from memory until the FIFO fills
3032 * past the watermark point. If the FIFO drains completely, a FIFO underrun
3033 * will occur, and a display engine hang could result.
3035 static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
3036 struct intel_watermark_params *wm,
3038 unsigned long latency_ns)
3040 long entries_required, wm_size;
3043 * Note: we need to make sure we don't overflow for various clock &
3045 * clocks go from a few thousand to several hundred thousand.
3046 * latency is usually a few thousand
3048 entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) /
3050 entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size);
3052 DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries_required);
3054 wm_size = wm->fifo_size - (entries_required + wm->guard_size);
3056 DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size);
3058 /* Don't promote wm_size to unsigned... */
3059 if (wm_size > (long)wm->max_wm)
3060 wm_size = wm->max_wm;
3062 wm_size = wm->default_wm;
3066 struct cxsr_latency {
3069 unsigned long fsb_freq;
3070 unsigned long mem_freq;
3071 unsigned long display_sr;
3072 unsigned long display_hpll_disable;
3073 unsigned long cursor_sr;
3074 unsigned long cursor_hpll_disable;
3077 static const struct cxsr_latency cxsr_latency_table[] = {
3078 {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
3079 {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
3080 {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
3081 {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
3082 {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
3084 {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
3085 {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
3086 {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
3087 {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
3088 {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
3090 {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
3091 {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
3092 {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
3093 {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
3094 {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
3096 {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
3097 {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
3098 {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
3099 {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
3100 {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
3102 {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
3103 {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
3104 {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
3105 {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
3106 {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
3108 {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
3109 {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
3110 {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
3111 {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
3112 {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
3115 static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop,
3120 const struct cxsr_latency *latency;
3123 if (fsb == 0 || mem == 0)
3126 for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
3127 latency = &cxsr_latency_table[i];
3128 if (is_desktop == latency->is_desktop &&
3129 is_ddr3 == latency->is_ddr3 &&
3130 fsb == latency->fsb_freq && mem == latency->mem_freq)
3134 DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
3139 static void pineview_disable_cxsr(struct drm_device *dev)
3141 struct drm_i915_private *dev_priv = dev->dev_private;
3143 /* deactivate cxsr */
3144 I915_WRITE(DSPFW3, I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN);
3148 * Latency for FIFO fetches is dependent on several factors:
3149 * - memory configuration (speed, channels)
3151 * - current MCH state
3152 * It can be fairly high in some situations, so here we assume a fairly
3153 * pessimal value. It's a tradeoff between extra memory fetches (if we
3154 * set this value too high, the FIFO will fetch frequently to stay full)
3155 * and power consumption (set it too low to save power and we might see
3156 * FIFO underruns and display "flicker").
3158 * A value of 5us seems to be a good balance; safe for very low end
3159 * platforms but not overly aggressive on lower latency configs.
3161 static const int latency_ns = 5000;
3163 static int i9xx_get_fifo_size(struct drm_device *dev, int plane)
3165 struct drm_i915_private *dev_priv = dev->dev_private;
3166 uint32_t dsparb = I915_READ(DSPARB);
3169 size = dsparb & 0x7f;
3171 size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size;
3173 DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
3174 plane ? "B" : "A", size);
3179 static int i85x_get_fifo_size(struct drm_device *dev, int plane)
3181 struct drm_i915_private *dev_priv = dev->dev_private;
3182 uint32_t dsparb = I915_READ(DSPARB);
3185 size = dsparb & 0x1ff;
3187 size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size;
3188 size >>= 1; /* Convert to cachelines */
3190 DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
3191 plane ? "B" : "A", size);
3196 static int i845_get_fifo_size(struct drm_device *dev, int plane)
3198 struct drm_i915_private *dev_priv = dev->dev_private;
3199 uint32_t dsparb = I915_READ(DSPARB);
3202 size = dsparb & 0x7f;
3203 size >>= 2; /* Convert to cachelines */
3205 DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
3212 static int i830_get_fifo_size(struct drm_device *dev, int plane)
3214 struct drm_i915_private *dev_priv = dev->dev_private;
3215 uint32_t dsparb = I915_READ(DSPARB);
3218 size = dsparb & 0x7f;
3219 size >>= 1; /* Convert to cachelines */
3221 DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
3222 plane ? "B" : "A", size);
3227 static void pineview_update_wm(struct drm_device *dev, int planea_clock,
3228 int planeb_clock, int sr_hdisplay, int unused,
3231 struct drm_i915_private *dev_priv = dev->dev_private;
3232 const struct cxsr_latency *latency;
3237 latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3,
3238 dev_priv->fsb_freq, dev_priv->mem_freq);
3240 DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
3241 pineview_disable_cxsr(dev);
3245 if (!planea_clock || !planeb_clock) {
3246 sr_clock = planea_clock ? planea_clock : planeb_clock;
3249 wm = intel_calculate_wm(sr_clock, &pineview_display_wm,
3250 pixel_size, latency->display_sr);
3251 reg = I915_READ(DSPFW1);
3252 reg &= ~DSPFW_SR_MASK;
3253 reg |= wm << DSPFW_SR_SHIFT;
3254 I915_WRITE(DSPFW1, reg);
3255 DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg);
3258 wm = intel_calculate_wm(sr_clock, &pineview_cursor_wm,
3259 pixel_size, latency->cursor_sr);
3260 reg = I915_READ(DSPFW3);
3261 reg &= ~DSPFW_CURSOR_SR_MASK;
3262 reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT;
3263 I915_WRITE(DSPFW3, reg);
3265 /* Display HPLL off SR */
3266 wm = intel_calculate_wm(sr_clock, &pineview_display_hplloff_wm,
3267 pixel_size, latency->display_hpll_disable);
3268 reg = I915_READ(DSPFW3);
3269 reg &= ~DSPFW_HPLL_SR_MASK;
3270 reg |= wm & DSPFW_HPLL_SR_MASK;
3271 I915_WRITE(DSPFW3, reg);
3273 /* cursor HPLL off SR */
3274 wm = intel_calculate_wm(sr_clock, &pineview_cursor_hplloff_wm,
3275 pixel_size, latency->cursor_hpll_disable);
3276 reg = I915_READ(DSPFW3);
3277 reg &= ~DSPFW_HPLL_CURSOR_MASK;
3278 reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT;
3279 I915_WRITE(DSPFW3, reg);
3280 DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg);
3284 I915_READ(DSPFW3) | PINEVIEW_SELF_REFRESH_EN);
3285 DRM_DEBUG_KMS("Self-refresh is enabled\n");
3287 pineview_disable_cxsr(dev);
3288 DRM_DEBUG_KMS("Self-refresh is disabled\n");
3292 static void g4x_update_wm(struct drm_device *dev, int planea_clock,
3293 int planeb_clock, int sr_hdisplay, int sr_htotal,
3296 struct drm_i915_private *dev_priv = dev->dev_private;
3297 int total_size, cacheline_size;
3298 int planea_wm, planeb_wm, cursora_wm, cursorb_wm, cursor_sr;
3299 struct intel_watermark_params planea_params, planeb_params;
3300 unsigned long line_time_us;
3301 int sr_clock, sr_entries = 0, entries_required;
3303 /* Create copies of the base settings for each pipe */
3304 planea_params = planeb_params = g4x_wm_info;
3306 /* Grab a couple of global values before we overwrite them */
3307 total_size = planea_params.fifo_size;
3308 cacheline_size = planea_params.cacheline_size;
3311 * Note: we need to make sure we don't overflow for various clock &
3313 * clocks go from a few thousand to several hundred thousand.
3314 * latency is usually a few thousand
3316 entries_required = ((planea_clock / 1000) * pixel_size * latency_ns) /
3318 entries_required = DIV_ROUND_UP(entries_required, G4X_FIFO_LINE_SIZE);
3319 planea_wm = entries_required + planea_params.guard_size;
3321 entries_required = ((planeb_clock / 1000) * pixel_size * latency_ns) /
3323 entries_required = DIV_ROUND_UP(entries_required, G4X_FIFO_LINE_SIZE);
3324 planeb_wm = entries_required + planeb_params.guard_size;
3326 cursora_wm = cursorb_wm = 16;
3329 DRM_DEBUG("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
3331 /* Calc sr entries for one plane configs */
3332 if (sr_hdisplay && (!planea_clock || !planeb_clock)) {
3333 /* self-refresh has much higher latency */
3334 static const int sr_latency_ns = 12000;
3336 sr_clock = planea_clock ? planea_clock : planeb_clock;
3337 line_time_us = ((sr_htotal * 1000) / sr_clock);
3339 /* Use ns/us then divide to preserve precision */
3340 sr_entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
3341 pixel_size * sr_hdisplay;
3342 sr_entries = DIV_ROUND_UP(sr_entries, cacheline_size);
3344 entries_required = (((sr_latency_ns / line_time_us) +
3345 1000) / 1000) * pixel_size * 64;
3346 entries_required = DIV_ROUND_UP(entries_required,
3347 g4x_cursor_wm_info.cacheline_size);
3348 cursor_sr = entries_required + g4x_cursor_wm_info.guard_size;
3350 if (cursor_sr > g4x_cursor_wm_info.max_wm)
3351 cursor_sr = g4x_cursor_wm_info.max_wm;
3352 DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
3353 "cursor %d\n", sr_entries, cursor_sr);
3355 I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
3357 /* Turn off self refresh if both pipes are enabled */
3358 I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF)
3362 DRM_DEBUG("Setting FIFO watermarks - A: %d, B: %d, SR %d\n",
3363 planea_wm, planeb_wm, sr_entries);
3368 I915_WRITE(DSPFW1, (sr_entries << DSPFW_SR_SHIFT) |
3369 (cursorb_wm << DSPFW_CURSORB_SHIFT) |
3370 (planeb_wm << DSPFW_PLANEB_SHIFT) | planea_wm);
3371 I915_WRITE(DSPFW2, (I915_READ(DSPFW2) & DSPFW_CURSORA_MASK) |
3372 (cursora_wm << DSPFW_CURSORA_SHIFT));
3373 /* HPLL off in SR has some issues on G4x... disable it */
3374 I915_WRITE(DSPFW3, (I915_READ(DSPFW3) & ~DSPFW_HPLL_SR_EN) |
3375 (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
3378 static void i965_update_wm(struct drm_device *dev, int planea_clock,
3379 int planeb_clock, int sr_hdisplay, int sr_htotal,
3382 struct drm_i915_private *dev_priv = dev->dev_private;
3383 unsigned long line_time_us;
3384 int sr_clock, sr_entries, srwm = 1;
3387 /* Calc sr entries for one plane configs */
3388 if (sr_hdisplay && (!planea_clock || !planeb_clock)) {
3389 /* self-refresh has much higher latency */
3390 static const int sr_latency_ns = 12000;
3392 sr_clock = planea_clock ? planea_clock : planeb_clock;
3393 line_time_us = ((sr_htotal * 1000) / sr_clock);
3395 /* Use ns/us then divide to preserve precision */
3396 sr_entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
3397 pixel_size * sr_hdisplay;
3398 sr_entries = DIV_ROUND_UP(sr_entries, I915_FIFO_LINE_SIZE);
3399 DRM_DEBUG("self-refresh entries: %d\n", sr_entries);
3400 srwm = I965_FIFO_SIZE - sr_entries;
3405 sr_entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
3407 sr_entries = DIV_ROUND_UP(sr_entries,
3408 i965_cursor_wm_info.cacheline_size);
3409 cursor_sr = i965_cursor_wm_info.fifo_size -
3410 (sr_entries + i965_cursor_wm_info.guard_size);
3412 if (cursor_sr > i965_cursor_wm_info.max_wm)
3413 cursor_sr = i965_cursor_wm_info.max_wm;
3415 DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
3416 "cursor %d\n", srwm, cursor_sr);
3418 if (IS_CRESTLINE(dev))
3419 I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
3421 /* Turn off self refresh if both pipes are enabled */
3422 if (IS_CRESTLINE(dev))
3423 I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF)
3427 DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
3430 /* 965 has limitations... */
3431 I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | (8 << 16) | (8 << 8) |
3433 I915_WRITE(DSPFW2, (8 << 8) | (8 << 0));
3434 /* update cursor SR watermark */
3435 I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
3438 static void i9xx_update_wm(struct drm_device *dev, int planea_clock,
3439 int planeb_clock, int sr_hdisplay, int sr_htotal,
3442 struct drm_i915_private *dev_priv = dev->dev_private;
3445 int total_size, cacheline_size, cwm, srwm = 1;
3446 int planea_wm, planeb_wm;
3447 struct intel_watermark_params planea_params, planeb_params;
3448 unsigned long line_time_us;
3449 int sr_clock, sr_entries = 0;
3451 /* Create copies of the base settings for each pipe */
3452 if (IS_CRESTLINE(dev) || IS_I945GM(dev))
3453 planea_params = planeb_params = i945_wm_info;
3454 else if (!IS_GEN2(dev))
3455 planea_params = planeb_params = i915_wm_info;
3457 planea_params = planeb_params = i855_wm_info;
3459 /* Grab a couple of global values before we overwrite them */
3460 total_size = planea_params.fifo_size;
3461 cacheline_size = planea_params.cacheline_size;
3463 /* Update per-plane FIFO sizes */
3464 planea_params.fifo_size = dev_priv->display.get_fifo_size(dev, 0);
3465 planeb_params.fifo_size = dev_priv->display.get_fifo_size(dev, 1);
3467 planea_wm = intel_calculate_wm(planea_clock, &planea_params,
3468 pixel_size, latency_ns);
3469 planeb_wm = intel_calculate_wm(planeb_clock, &planeb_params,
3470 pixel_size, latency_ns);
3471 DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
3474 * Overlay gets an aggressive default since video jitter is bad.
3478 /* Calc sr entries for one plane configs */
3479 if (HAS_FW_BLC(dev) && sr_hdisplay &&
3480 (!planea_clock || !planeb_clock)) {
3481 /* self-refresh has much higher latency */
3482 static const int sr_latency_ns = 6000;
3484 sr_clock = planea_clock ? planea_clock : planeb_clock;
3485 line_time_us = ((sr_htotal * 1000) / sr_clock);
3487 /* Use ns/us then divide to preserve precision */
3488 sr_entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
3489 pixel_size * sr_hdisplay;
3490 sr_entries = DIV_ROUND_UP(sr_entries, cacheline_size);
3491 DRM_DEBUG_KMS("self-refresh entries: %d\n", sr_entries);
3492 srwm = total_size - sr_entries;
3496 if (IS_I945G(dev) || IS_I945GM(dev))
3497 I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_FIFO_MASK | (srwm & 0xff));
3498 else if (IS_I915GM(dev)) {
3499 /* 915M has a smaller SRWM field */
3500 I915_WRITE(FW_BLC_SELF, srwm & 0x3f);
3501 I915_WRITE(INSTPM, I915_READ(INSTPM) | INSTPM_SELF_EN);
3504 /* Turn off self refresh if both pipes are enabled */
3505 if (IS_I945G(dev) || IS_I945GM(dev)) {
3506 I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF)
3508 } else if (IS_I915GM(dev)) {
3509 I915_WRITE(INSTPM, I915_READ(INSTPM) & ~INSTPM_SELF_EN);
3513 DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
3514 planea_wm, planeb_wm, cwm, srwm);
3516 fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
3517 fwater_hi = (cwm & 0x1f);
3519 /* Set request length to 8 cachelines per fetch */
3520 fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
3521 fwater_hi = fwater_hi | (1 << 8);
3523 I915_WRITE(FW_BLC, fwater_lo);
3524 I915_WRITE(FW_BLC2, fwater_hi);
3527 static void i830_update_wm(struct drm_device *dev, int planea_clock, int unused,
3528 int unused2, int unused3, int pixel_size)
3530 struct drm_i915_private *dev_priv = dev->dev_private;
3531 uint32_t fwater_lo = I915_READ(FW_BLC) & ~0xfff;
3534 i830_wm_info.fifo_size = dev_priv->display.get_fifo_size(dev, 0);
3536 planea_wm = intel_calculate_wm(planea_clock, &i830_wm_info,
3537 pixel_size, latency_ns);
3538 fwater_lo |= (3<<8) | planea_wm;
3540 DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm);
3542 I915_WRITE(FW_BLC, fwater_lo);
3545 #define ILK_LP0_PLANE_LATENCY 700
3546 #define ILK_LP0_CURSOR_LATENCY 1300
3548 static bool ironlake_compute_wm0(struct drm_device *dev,
3550 const struct intel_watermark_params *display,
3551 int display_latency_ns,
3552 const struct intel_watermark_params *cursor,
3553 int cursor_latency_ns,
3557 struct drm_crtc *crtc;
3558 int htotal, hdisplay, clock, pixel_size;
3559 int line_time_us, line_count;
3560 int entries, tlb_miss;
3562 crtc = intel_get_crtc_for_pipe(dev, pipe);
3563 if (crtc->fb == NULL || !crtc->enabled)
3566 htotal = crtc->mode.htotal;
3567 hdisplay = crtc->mode.hdisplay;
3568 clock = crtc->mode.clock;
3569 pixel_size = crtc->fb->bits_per_pixel / 8;
3571 /* Use the small buffer method to calculate plane watermark */
3572 entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;
3573 tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8;
3575 entries += tlb_miss;
3576 entries = DIV_ROUND_UP(entries, display->cacheline_size);
3577 *plane_wm = entries + display->guard_size;
3578 if (*plane_wm > (int)display->max_wm)
3579 *plane_wm = display->max_wm;
3581 /* Use the large buffer method to calculate cursor watermark */
3582 line_time_us = ((htotal * 1000) / clock);
3583 line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;
3584 entries = line_count * 64 * pixel_size;
3585 tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8;
3587 entries += tlb_miss;
3588 entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
3589 *cursor_wm = entries + cursor->guard_size;
3590 if (*cursor_wm > (int)cursor->max_wm)
3591 *cursor_wm = (int)cursor->max_wm;
3597 * Check the wm result.
3599 * If any calculated watermark values is larger than the maximum value that
3600 * can be programmed into the associated watermark register, that watermark
3603 static bool ironlake_check_srwm(struct drm_device *dev, int level,
3604 int fbc_wm, int display_wm, int cursor_wm,
3605 const struct intel_watermark_params *display,
3606 const struct intel_watermark_params *cursor)
3608 struct drm_i915_private *dev_priv = dev->dev_private;
3610 DRM_DEBUG_KMS("watermark %d: display plane %d, fbc lines %d,"
3611 " cursor %d\n", level, display_wm, fbc_wm, cursor_wm);
3613 if (fbc_wm > SNB_FBC_MAX_SRWM) {
3614 DRM_DEBUG_KMS("fbc watermark(%d) is too large(%d), disabling wm%d+\n",
3615 fbc_wm, SNB_FBC_MAX_SRWM, level);
3617 /* fbc has it's own way to disable FBC WM */
3618 I915_WRITE(DISP_ARB_CTL,
3619 I915_READ(DISP_ARB_CTL) | DISP_FBC_WM_DIS);
3623 if (display_wm > display->max_wm) {
3624 DRM_DEBUG_KMS("display watermark(%d) is too large(%d), disabling wm%d+\n",
3625 display_wm, SNB_DISPLAY_MAX_SRWM, level);
3629 if (cursor_wm > cursor->max_wm) {
3630 DRM_DEBUG_KMS("cursor watermark(%d) is too large(%d), disabling wm%d+\n",
3631 cursor_wm, SNB_CURSOR_MAX_SRWM, level);
3635 if (!(fbc_wm || display_wm || cursor_wm)) {
3636 DRM_DEBUG_KMS("latency %d is 0, disabling wm%d+\n", level, level);
3644 * Compute watermark values of WM[1-3],
3646 static bool ironlake_compute_srwm(struct drm_device *dev, int level,
3647 int hdisplay, int htotal,
3648 int pixel_size, int clock, int latency_ns,
3649 const struct intel_watermark_params *display,
3650 const struct intel_watermark_params *cursor,
3651 int *fbc_wm, int *display_wm, int *cursor_wm)
3654 unsigned long line_time_us;
3655 int line_count, line_size;
3660 *fbc_wm = *display_wm = *cursor_wm = 0;
3664 line_time_us = (htotal * 1000) / clock;
3665 line_count = (latency_ns / line_time_us + 1000) / 1000;
3666 line_size = hdisplay * pixel_size;
3668 /* Use the minimum of the small and large buffer method for primary */
3669 small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
3670 large = line_count * line_size;
3672 entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
3673 *display_wm = entries + display->guard_size;
3677 * FBC WM = ((Final Primary WM * 64) / number of bytes per line) + 2
3679 *fbc_wm = DIV_ROUND_UP(*display_wm * 64, line_size) + 2;
3681 /* calculate the self-refresh watermark for display cursor */
3682 entries = line_count * pixel_size * 64;
3683 entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
3684 *cursor_wm = entries + cursor->guard_size;
3686 return ironlake_check_srwm(dev, level,
3687 *fbc_wm, *display_wm, *cursor_wm,
3691 static void ironlake_update_wm(struct drm_device *dev,
3692 int planea_clock, int planeb_clock,
3693 int hdisplay, int htotal,
3696 struct drm_i915_private *dev_priv = dev->dev_private;
3697 int fbc_wm, plane_wm, cursor_wm, enabled;
3701 if (ironlake_compute_wm0(dev, 0,
3702 &ironlake_display_wm_info,
3703 ILK_LP0_PLANE_LATENCY,
3704 &ironlake_cursor_wm_info,
3705 ILK_LP0_CURSOR_LATENCY,
3706 &plane_wm, &cursor_wm)) {
3707 I915_WRITE(WM0_PIPEA_ILK,
3708 (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
3709 DRM_DEBUG_KMS("FIFO watermarks For pipe A -"
3710 " plane %d, " "cursor: %d\n",
3711 plane_wm, cursor_wm);
3715 if (ironlake_compute_wm0(dev, 1,
3716 &ironlake_display_wm_info,
3717 ILK_LP0_PLANE_LATENCY,
3718 &ironlake_cursor_wm_info,
3719 ILK_LP0_CURSOR_LATENCY,
3720 &plane_wm, &cursor_wm)) {
3721 I915_WRITE(WM0_PIPEB_ILK,
3722 (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
3723 DRM_DEBUG_KMS("FIFO watermarks For pipe B -"
3724 " plane %d, cursor: %d\n",
3725 plane_wm, cursor_wm);
3730 * Calculate and update the self-refresh watermark only when one
3731 * display plane is used.
3733 I915_WRITE(WM3_LP_ILK, 0);
3734 I915_WRITE(WM2_LP_ILK, 0);
3735 I915_WRITE(WM1_LP_ILK, 0);
3740 clock = planea_clock ? planea_clock : planeb_clock;
3743 if (!ironlake_compute_srwm(dev, 1, hdisplay, htotal, pixel_size,
3744 clock, ILK_READ_WM1_LATENCY() * 500,
3745 &ironlake_display_srwm_info,
3746 &ironlake_cursor_srwm_info,
3747 &fbc_wm, &plane_wm, &cursor_wm))
3750 I915_WRITE(WM1_LP_ILK,
3752 (ILK_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) |
3753 (fbc_wm << WM1_LP_FBC_SHIFT) |
3754 (plane_wm << WM1_LP_SR_SHIFT) |
3758 if (!ironlake_compute_srwm(dev, 2, hdisplay, htotal, pixel_size,
3759 clock, ILK_READ_WM2_LATENCY() * 500,
3760 &ironlake_display_srwm_info,
3761 &ironlake_cursor_srwm_info,
3762 &fbc_wm, &plane_wm, &cursor_wm))
3765 I915_WRITE(WM2_LP_ILK,
3767 (ILK_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) |
3768 (fbc_wm << WM1_LP_FBC_SHIFT) |
3769 (plane_wm << WM1_LP_SR_SHIFT) |
3773 * WM3 is unsupported on ILK, probably because we don't have latency
3774 * data for that power state
3778 static void sandybridge_update_wm(struct drm_device *dev,
3779 int planea_clock, int planeb_clock,
3780 int hdisplay, int htotal,
3783 struct drm_i915_private *dev_priv = dev->dev_private;
3784 int latency = SNB_READ_WM0_LATENCY() * 100; /* In unit 0.1us */
3785 int fbc_wm, plane_wm, cursor_wm, enabled;
3789 if (ironlake_compute_wm0(dev, 0,
3790 &sandybridge_display_wm_info, latency,
3791 &sandybridge_cursor_wm_info, latency,
3792 &plane_wm, &cursor_wm)) {
3793 I915_WRITE(WM0_PIPEA_ILK,
3794 (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
3795 DRM_DEBUG_KMS("FIFO watermarks For pipe A -"
3796 " plane %d, " "cursor: %d\n",
3797 plane_wm, cursor_wm);
3801 if (ironlake_compute_wm0(dev, 1,
3802 &sandybridge_display_wm_info, latency,
3803 &sandybridge_cursor_wm_info, latency,
3804 &plane_wm, &cursor_wm)) {
3805 I915_WRITE(WM0_PIPEB_ILK,
3806 (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
3807 DRM_DEBUG_KMS("FIFO watermarks For pipe B -"
3808 " plane %d, cursor: %d\n",
3809 plane_wm, cursor_wm);
3814 * Calculate and update the self-refresh watermark only when one
3815 * display plane is used.
3817 * SNB support 3 levels of watermark.
3819 * WM1/WM2/WM2 watermarks have to be enabled in the ascending order,
3820 * and disabled in the descending order
3823 I915_WRITE(WM3_LP_ILK, 0);
3824 I915_WRITE(WM2_LP_ILK, 0);
3825 I915_WRITE(WM1_LP_ILK, 0);
3830 clock = planea_clock ? planea_clock : planeb_clock;
3833 if (!ironlake_compute_srwm(dev, 1, hdisplay, htotal, pixel_size,
3834 clock, SNB_READ_WM1_LATENCY() * 500,
3835 &sandybridge_display_srwm_info,
3836 &sandybridge_cursor_srwm_info,
3837 &fbc_wm, &plane_wm, &cursor_wm))
3840 I915_WRITE(WM1_LP_ILK,
3842 (SNB_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) |
3843 (fbc_wm << WM1_LP_FBC_SHIFT) |
3844 (plane_wm << WM1_LP_SR_SHIFT) |
3848 if (!ironlake_compute_srwm(dev, 2,
3849 hdisplay, htotal, pixel_size,
3850 clock, SNB_READ_WM2_LATENCY() * 500,
3851 &sandybridge_display_srwm_info,
3852 &sandybridge_cursor_srwm_info,
3853 &fbc_wm, &plane_wm, &cursor_wm))
3856 I915_WRITE(WM2_LP_ILK,
3858 (SNB_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) |
3859 (fbc_wm << WM1_LP_FBC_SHIFT) |
3860 (plane_wm << WM1_LP_SR_SHIFT) |
3864 if (!ironlake_compute_srwm(dev, 3,
3865 hdisplay, htotal, pixel_size,
3866 clock, SNB_READ_WM3_LATENCY() * 500,
3867 &sandybridge_display_srwm_info,
3868 &sandybridge_cursor_srwm_info,
3869 &fbc_wm, &plane_wm, &cursor_wm))
3872 I915_WRITE(WM3_LP_ILK,
3874 (SNB_READ_WM3_LATENCY() << WM1_LP_LATENCY_SHIFT) |
3875 (fbc_wm << WM1_LP_FBC_SHIFT) |
3876 (plane_wm << WM1_LP_SR_SHIFT) |
3881 * intel_update_watermarks - update FIFO watermark values based on current modes
3883 * Calculate watermark values for the various WM regs based on current mode
3884 * and plane configuration.
3886 * There are several cases to deal with here:
3887 * - normal (i.e. non-self-refresh)
3888 * - self-refresh (SR) mode
3889 * - lines are large relative to FIFO size (buffer can hold up to 2)
3890 * - lines are small relative to FIFO size (buffer can hold more than 2
3891 * lines), so need to account for TLB latency
3893 * The normal calculation is:
3894 * watermark = dotclock * bytes per pixel * latency
3895 * where latency is platform & configuration dependent (we assume pessimal
3898 * The SR calculation is:
3899 * watermark = (trunc(latency/line time)+1) * surface width *
3902 * line time = htotal / dotclock
3903 * surface width = hdisplay for normal plane and 64 for cursor
3904 * and latency is assumed to be high, as above.
3906 * The final value programmed to the register should always be rounded up,
3907 * and include an extra 2 entries to account for clock crossings.
3909 * We don't use the sprite, so we can ignore that. And on Crestline we have
3910 * to set the non-SR watermarks to 8.
3912 static void intel_update_watermarks(struct drm_device *dev)
3914 struct drm_i915_private *dev_priv = dev->dev_private;
3915 struct drm_crtc *crtc;
3916 int sr_hdisplay = 0;
3917 unsigned long planea_clock = 0, planeb_clock = 0, sr_clock = 0;
3918 int enabled = 0, pixel_size = 0;
3921 if (!dev_priv->display.update_wm)
3924 /* Get the clock config from both planes */
3925 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
3926 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3927 if (intel_crtc->active) {
3929 if (intel_crtc->plane == 0) {
3930 DRM_DEBUG_KMS("plane A (pipe %d) clock: %d\n",
3931 intel_crtc->pipe, crtc->mode.clock);
3932 planea_clock = crtc->mode.clock;
3934 DRM_DEBUG_KMS("plane B (pipe %d) clock: %d\n",
3935 intel_crtc->pipe, crtc->mode.clock);
3936 planeb_clock = crtc->mode.clock;
3938 sr_hdisplay = crtc->mode.hdisplay;
3939 sr_clock = crtc->mode.clock;
3940 sr_htotal = crtc->mode.htotal;
3942 pixel_size = crtc->fb->bits_per_pixel / 8;
3944 pixel_size = 4; /* by default */
3951 dev_priv->display.update_wm(dev, planea_clock, planeb_clock,
3952 sr_hdisplay, sr_htotal, pixel_size);
3955 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
3957 return dev_priv->lvds_use_ssc && i915_panel_use_ssc;
3960 static int intel_crtc_mode_set(struct drm_crtc *crtc,
3961 struct drm_display_mode *mode,
3962 struct drm_display_mode *adjusted_mode,
3964 struct drm_framebuffer *old_fb)
3966 struct drm_device *dev = crtc->dev;
3967 struct drm_i915_private *dev_priv = dev->dev_private;
3968 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3969 int pipe = intel_crtc->pipe;
3970 int plane = intel_crtc->plane;
3971 u32 fp_reg, dpll_reg;
3972 int refclk, num_connectors = 0;
3973 intel_clock_t clock, reduced_clock;
3974 u32 dpll, fp = 0, fp2 = 0, dspcntr, pipeconf;
3975 bool ok, has_reduced_clock = false, is_sdvo = false, is_dvo = false;
3976 bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
3977 struct intel_encoder *has_edp_encoder = NULL;
3978 struct drm_mode_config *mode_config = &dev->mode_config;
3979 struct intel_encoder *encoder;
3980 const intel_limit_t *limit;
3982 struct fdi_m_n m_n = {0};
3986 drm_vblank_pre_modeset(dev, pipe);
3988 list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
3989 if (encoder->base.crtc != crtc)
3992 switch (encoder->type) {
3993 case INTEL_OUTPUT_LVDS:
3996 case INTEL_OUTPUT_SDVO:
3997 case INTEL_OUTPUT_HDMI:
3999 if (encoder->needs_tv_clock)
4002 case INTEL_OUTPUT_DVO:
4005 case INTEL_OUTPUT_TVOUT:
4008 case INTEL_OUTPUT_ANALOG:
4011 case INTEL_OUTPUT_DISPLAYPORT:
4014 case INTEL_OUTPUT_EDP:
4015 has_edp_encoder = encoder;
4022 if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
4023 refclk = dev_priv->lvds_ssc_freq * 1000;
4024 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
4026 } else if (!IS_GEN2(dev)) {
4028 if (HAS_PCH_SPLIT(dev) &&
4029 (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)))
4030 refclk = 120000; /* 120Mhz refclk */
4036 * Returns a set of divisors for the desired target clock with the given
4037 * refclk, or FALSE. The returned values represent the clock equation:
4038 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
4040 limit = intel_limit(crtc, refclk);
4041 ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock);
4043 DRM_ERROR("Couldn't find PLL settings for mode!\n");
4044 drm_vblank_post_modeset(dev, pipe);
4048 /* Ensure that the cursor is valid for the new mode before changing... */
4049 intel_crtc_update_cursor(crtc, true);
4051 if (is_lvds && dev_priv->lvds_downclock_avail) {
4052 has_reduced_clock = limit->find_pll(limit, crtc,
4053 dev_priv->lvds_downclock,
4056 if (has_reduced_clock && (clock.p != reduced_clock.p)) {
4058 * If the different P is found, it means that we can't
4059 * switch the display clock by using the FP0/FP1.
4060 * In such case we will disable the LVDS downclock
4063 DRM_DEBUG_KMS("Different P is found for "
4064 "LVDS clock/downclock\n");
4065 has_reduced_clock = 0;
4068 /* SDVO TV has fixed PLL values depend on its clock range,
4069 this mirrors vbios setting. */
4070 if (is_sdvo && is_tv) {
4071 if (adjusted_mode->clock >= 100000
4072 && adjusted_mode->clock < 140500) {
4078 } else if (adjusted_mode->clock >= 140500
4079 && adjusted_mode->clock <= 200000) {
4089 if (HAS_PCH_SPLIT(dev)) {
4090 int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
4091 int lane = 0, link_bw, bpp;
4092 /* CPU eDP doesn't require FDI link, so just set DP M/N
4093 according to current link config */
4094 if (has_edp_encoder && !intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
4095 target_clock = mode->clock;
4096 intel_edp_link_config(has_edp_encoder,
4099 /* [e]DP over FDI requires target mode clock
4100 instead of link clock */
4101 if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base))
4102 target_clock = mode->clock;
4104 target_clock = adjusted_mode->clock;
4106 /* FDI is a binary signal running at ~2.7GHz, encoding
4107 * each output octet as 10 bits. The actual frequency
4108 * is stored as a divider into a 100MHz clock, and the
4109 * mode pixel clock is stored in units of 1KHz.
4110 * Hence the bw of each lane in terms of the mode signal
4113 link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
4116 /* determine panel color depth */
4117 temp = I915_READ(PIPECONF(pipe));
4118 temp &= ~PIPE_BPC_MASK;
4120 /* the BPC will be 6 if it is 18-bit LVDS panel */
4121 if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) == LVDS_A3_POWER_UP)
4125 } else if (has_edp_encoder) {
4126 switch (dev_priv->edp.bpp/3) {
4142 I915_WRITE(PIPECONF(pipe), temp);
4144 switch (temp & PIPE_BPC_MASK) {
4158 DRM_ERROR("unknown pipe bpc value\n");
4164 * Account for spread spectrum to avoid
4165 * oversubscribing the link. Max center spread
4166 * is 2.5%; use 5% for safety's sake.
4168 u32 bps = target_clock * bpp * 21 / 20;
4169 lane = bps / (link_bw * 8) + 1;
4172 intel_crtc->fdi_lanes = lane;
4174 if (pixel_multiplier > 1)
4175 link_bw *= pixel_multiplier;
4176 ironlake_compute_m_n(bpp, lane, target_clock, link_bw, &m_n);
4179 /* Ironlake: try to setup display ref clock before DPLL
4180 * enabling. This is only under driver's control after
4181 * PCH B stepping, previous chipset stepping should be
4182 * ignoring this setting.
4184 if (HAS_PCH_SPLIT(dev)) {
4185 temp = I915_READ(PCH_DREF_CONTROL);
4186 /* Always enable nonspread source */
4187 temp &= ~DREF_NONSPREAD_SOURCE_MASK;
4188 temp |= DREF_NONSPREAD_SOURCE_ENABLE;
4189 temp &= ~DREF_SSC_SOURCE_MASK;
4190 temp |= DREF_SSC_SOURCE_ENABLE;
4191 I915_WRITE(PCH_DREF_CONTROL, temp);
4193 POSTING_READ(PCH_DREF_CONTROL);
4196 if (has_edp_encoder) {
4197 if (intel_panel_use_ssc(dev_priv)) {
4198 temp |= DREF_SSC1_ENABLE;
4199 I915_WRITE(PCH_DREF_CONTROL, temp);
4201 POSTING_READ(PCH_DREF_CONTROL);
4204 temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4206 /* Enable CPU source on CPU attached eDP */
4207 if (!intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
4208 if (intel_panel_use_ssc(dev_priv))
4209 temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
4211 temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
4213 /* Enable SSC on PCH eDP if needed */
4214 if (intel_panel_use_ssc(dev_priv)) {
4215 DRM_ERROR("enabling SSC on PCH\n");
4216 temp |= DREF_SUPERSPREAD_SOURCE_ENABLE;
4219 I915_WRITE(PCH_DREF_CONTROL, temp);
4220 POSTING_READ(PCH_DREF_CONTROL);
4225 if (IS_PINEVIEW(dev)) {
4226 fp = (1 << clock.n) << 16 | clock.m1 << 8 | clock.m2;
4227 if (has_reduced_clock)
4228 fp2 = (1 << reduced_clock.n) << 16 |
4229 reduced_clock.m1 << 8 | reduced_clock.m2;
4231 fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
4232 if (has_reduced_clock)
4233 fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
4237 /* Enable autotuning of the PLL clock (if permissible) */
4238 if (HAS_PCH_SPLIT(dev)) {
4242 if ((intel_panel_use_ssc(dev_priv) &&
4243 dev_priv->lvds_ssc_freq == 100) ||
4244 (I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP)
4246 } else if (is_sdvo && is_tv)
4249 if (clock.m1 < factor * clock.n)
4254 if (!HAS_PCH_SPLIT(dev))
4255 dpll = DPLL_VGA_MODE_DIS;
4257 if (!IS_GEN2(dev)) {
4259 dpll |= DPLLB_MODE_LVDS;
4261 dpll |= DPLLB_MODE_DAC_SERIAL;
4263 int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
4264 if (pixel_multiplier > 1) {
4265 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
4266 dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
4267 else if (HAS_PCH_SPLIT(dev))
4268 dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
4270 dpll |= DPLL_DVO_HIGH_SPEED;
4272 if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base))
4273 dpll |= DPLL_DVO_HIGH_SPEED;
4275 /* compute bitmask from p1 value */
4276 if (IS_PINEVIEW(dev))
4277 dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
4279 dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4281 if (HAS_PCH_SPLIT(dev))
4282 dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
4283 if (IS_G4X(dev) && has_reduced_clock)
4284 dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
4288 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
4291 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
4294 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
4297 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
4300 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
4301 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
4304 dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4307 dpll |= PLL_P1_DIVIDE_BY_TWO;
4309 dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4311 dpll |= PLL_P2_DIVIDE_BY_4;
4315 if (is_sdvo && is_tv)
4316 dpll |= PLL_REF_INPUT_TVCLKINBC;
4318 /* XXX: just matching BIOS for now */
4319 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
4321 else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4322 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4324 dpll |= PLL_REF_INPUT_DREFCLK;
4326 /* setup pipeconf */
4327 pipeconf = I915_READ(PIPECONF(pipe));
4329 /* Set up the display plane register */
4330 dspcntr = DISPPLANE_GAMMA_ENABLE;
4332 /* Ironlake's plane is forced to pipe, bit 24 is to
4333 enable color space conversion */
4334 if (!HAS_PCH_SPLIT(dev)) {
4336 dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
4338 dspcntr |= DISPPLANE_SEL_PIPE_B;
4341 if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
4342 /* Enable pixel doubling when the dot clock is > 90% of the (display)
4345 * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
4349 dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
4350 pipeconf |= PIPECONF_DOUBLE_WIDE;
4352 pipeconf &= ~PIPECONF_DOUBLE_WIDE;
4355 if (!HAS_PCH_SPLIT(dev))
4356 dpll |= DPLL_VCO_ENABLE;
4358 DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
4359 drm_mode_debug_printmodeline(mode);
4361 /* assign to Ironlake registers */
4362 if (HAS_PCH_SPLIT(dev)) {
4363 fp_reg = PCH_FP0(pipe);
4364 dpll_reg = PCH_DPLL(pipe);
4367 dpll_reg = DPLL(pipe);
4370 /* PCH eDP needs FDI, but CPU eDP does not */
4371 if (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
4372 I915_WRITE(fp_reg, fp);
4373 I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
4375 POSTING_READ(dpll_reg);
4379 /* enable transcoder DPLL */
4380 if (HAS_PCH_CPT(dev)) {
4381 temp = I915_READ(PCH_DPLL_SEL);
4383 temp |= TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL;
4385 temp |= TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL;
4386 I915_WRITE(PCH_DPLL_SEL, temp);
4388 POSTING_READ(PCH_DPLL_SEL);
4392 /* The LVDS pin pair needs to be on before the DPLLs are enabled.
4393 * This is an exception to the general rule that mode_set doesn't turn
4398 if (HAS_PCH_SPLIT(dev))
4401 temp = I915_READ(reg);
4402 temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
4404 if (HAS_PCH_CPT(dev))
4405 temp |= PORT_TRANS_B_SEL_CPT;
4407 temp |= LVDS_PIPEB_SELECT;
4409 if (HAS_PCH_CPT(dev))
4410 temp &= ~PORT_TRANS_SEL_MASK;
4412 temp &= ~LVDS_PIPEB_SELECT;
4414 /* set the corresponsding LVDS_BORDER bit */
4415 temp |= dev_priv->lvds_border_bits;
4416 /* Set the B0-B3 data pairs corresponding to whether we're going to
4417 * set the DPLLs for dual-channel mode or not.
4420 temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
4422 temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
4424 /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
4425 * appropriately here, but we need to look more thoroughly into how
4426 * panels behave in the two modes.
4428 /* set the dithering flag on non-PCH LVDS as needed */
4429 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
4430 if (dev_priv->lvds_dither)
4431 temp |= LVDS_ENABLE_DITHER;
4433 temp &= ~LVDS_ENABLE_DITHER;
4435 I915_WRITE(reg, temp);
4438 /* set the dithering flag and clear for anything other than a panel. */
4439 if (HAS_PCH_SPLIT(dev)) {
4440 pipeconf &= ~PIPECONF_DITHER_EN;
4441 pipeconf &= ~PIPECONF_DITHER_TYPE_MASK;
4442 if (dev_priv->lvds_dither && (is_lvds || has_edp_encoder)) {
4443 pipeconf |= PIPECONF_DITHER_EN;
4444 pipeconf |= PIPECONF_DITHER_TYPE_ST1;
4448 if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
4449 intel_dp_set_m_n(crtc, mode, adjusted_mode);
4450 } else if (HAS_PCH_SPLIT(dev)) {
4451 /* For non-DP output, clear any trans DP clock recovery setting.*/
4453 I915_WRITE(TRANSA_DATA_M1, 0);
4454 I915_WRITE(TRANSA_DATA_N1, 0);
4455 I915_WRITE(TRANSA_DP_LINK_M1, 0);
4456 I915_WRITE(TRANSA_DP_LINK_N1, 0);
4458 I915_WRITE(TRANSB_DATA_M1, 0);
4459 I915_WRITE(TRANSB_DATA_N1, 0);
4460 I915_WRITE(TRANSB_DP_LINK_M1, 0);
4461 I915_WRITE(TRANSB_DP_LINK_N1, 0);
4465 if (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
4466 I915_WRITE(dpll_reg, dpll);
4468 /* Wait for the clocks to stabilize. */
4469 POSTING_READ(dpll_reg);
4472 if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
4475 temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4477 temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
4481 I915_WRITE(DPLL_MD(pipe), temp);
4483 /* The pixel multiplier can only be updated once the
4484 * DPLL is enabled and the clocks are stable.
4486 * So write it again.
4488 I915_WRITE(dpll_reg, dpll);
4492 intel_crtc->lowfreq_avail = false;
4493 if (is_lvds && has_reduced_clock && i915_powersave) {
4494 I915_WRITE(fp_reg + 4, fp2);
4495 intel_crtc->lowfreq_avail = true;
4496 if (HAS_PIPE_CXSR(dev)) {
4497 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
4498 pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
4501 I915_WRITE(fp_reg + 4, fp);
4502 if (HAS_PIPE_CXSR(dev)) {
4503 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
4504 pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
4508 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4509 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
4510 /* the chip adds 2 halflines automatically */
4511 adjusted_mode->crtc_vdisplay -= 1;
4512 adjusted_mode->crtc_vtotal -= 1;
4513 adjusted_mode->crtc_vblank_start -= 1;
4514 adjusted_mode->crtc_vblank_end -= 1;
4515 adjusted_mode->crtc_vsync_end -= 1;
4516 adjusted_mode->crtc_vsync_start -= 1;
4518 pipeconf &= ~PIPECONF_INTERLACE_W_FIELD_INDICATION; /* progressive */
4520 I915_WRITE(HTOTAL(pipe),
4521 (adjusted_mode->crtc_hdisplay - 1) |
4522 ((adjusted_mode->crtc_htotal - 1) << 16));
4523 I915_WRITE(HBLANK(pipe),
4524 (adjusted_mode->crtc_hblank_start - 1) |
4525 ((adjusted_mode->crtc_hblank_end - 1) << 16));
4526 I915_WRITE(HSYNC(pipe),
4527 (adjusted_mode->crtc_hsync_start - 1) |
4528 ((adjusted_mode->crtc_hsync_end - 1) << 16));
4530 I915_WRITE(VTOTAL(pipe),
4531 (adjusted_mode->crtc_vdisplay - 1) |
4532 ((adjusted_mode->crtc_vtotal - 1) << 16));
4533 I915_WRITE(VBLANK(pipe),
4534 (adjusted_mode->crtc_vblank_start - 1) |
4535 ((adjusted_mode->crtc_vblank_end - 1) << 16));
4536 I915_WRITE(VSYNC(pipe),
4537 (adjusted_mode->crtc_vsync_start - 1) |
4538 ((adjusted_mode->crtc_vsync_end - 1) << 16));
4540 /* pipesrc and dspsize control the size that is scaled from,
4541 * which should always be the user's requested size.
4543 if (!HAS_PCH_SPLIT(dev)) {
4544 I915_WRITE(DSPSIZE(plane),
4545 ((mode->vdisplay - 1) << 16) |
4546 (mode->hdisplay - 1));
4547 I915_WRITE(DSPPOS(plane), 0);
4549 I915_WRITE(PIPESRC(pipe),
4550 ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
4552 if (HAS_PCH_SPLIT(dev)) {
4553 I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
4554 I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
4555 I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
4556 I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
4558 if (has_edp_encoder && !intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
4559 ironlake_set_pll_edp(crtc, adjusted_mode->clock);
4563 I915_WRITE(PIPECONF(pipe), pipeconf);
4564 POSTING_READ(PIPECONF(pipe));
4565 if (!HAS_PCH_SPLIT(dev))
4566 intel_enable_pipe(dev_priv, pipe);
4568 intel_wait_for_vblank(dev, pipe);
4571 /* enable address swizzle for tiling buffer */
4572 temp = I915_READ(DISP_ARB_CTL);
4573 I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING);
4576 I915_WRITE(DSPCNTR(plane), dspcntr);
4577 POSTING_READ(DSPCNTR(plane));
4578 if (!HAS_PCH_SPLIT(dev))
4579 intel_enable_plane(dev_priv, plane, pipe);
4581 ret = intel_pipe_set_base(crtc, x, y, old_fb);
4583 intel_update_watermarks(dev);
4585 drm_vblank_post_modeset(dev, pipe);
4590 /** Loads the palette/gamma unit for the CRTC with the prepared values */
4591 void intel_crtc_load_lut(struct drm_crtc *crtc)
4593 struct drm_device *dev = crtc->dev;
4594 struct drm_i915_private *dev_priv = dev->dev_private;
4595 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4596 int palreg = (intel_crtc->pipe == 0) ? PALETTE_A : PALETTE_B;
4599 /* The clocks have to be on to load the palette. */
4603 /* use legacy palette for Ironlake */
4604 if (HAS_PCH_SPLIT(dev))
4605 palreg = (intel_crtc->pipe == 0) ? LGC_PALETTE_A :
4608 for (i = 0; i < 256; i++) {
4609 I915_WRITE(palreg + 4 * i,
4610 (intel_crtc->lut_r[i] << 16) |
4611 (intel_crtc->lut_g[i] << 8) |
4612 intel_crtc->lut_b[i]);
4616 static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
4618 struct drm_device *dev = crtc->dev;
4619 struct drm_i915_private *dev_priv = dev->dev_private;
4620 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4621 bool visible = base != 0;
4624 if (intel_crtc->cursor_visible == visible)
4627 cntl = I915_READ(CURACNTR);
4629 /* On these chipsets we can only modify the base whilst
4630 * the cursor is disabled.
4632 I915_WRITE(CURABASE, base);
4634 cntl &= ~(CURSOR_FORMAT_MASK);
4635 /* XXX width must be 64, stride 256 => 0x00 << 28 */
4636 cntl |= CURSOR_ENABLE |
4637 CURSOR_GAMMA_ENABLE |
4640 cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
4641 I915_WRITE(CURACNTR, cntl);
4643 intel_crtc->cursor_visible = visible;
4646 static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
4648 struct drm_device *dev = crtc->dev;
4649 struct drm_i915_private *dev_priv = dev->dev_private;
4650 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4651 int pipe = intel_crtc->pipe;
4652 bool visible = base != 0;
4654 if (intel_crtc->cursor_visible != visible) {
4655 uint32_t cntl = I915_READ(pipe == 0 ? CURACNTR : CURBCNTR);
4657 cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
4658 cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
4659 cntl |= pipe << 28; /* Connect to correct pipe */
4661 cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
4662 cntl |= CURSOR_MODE_DISABLE;
4664 I915_WRITE(pipe == 0 ? CURACNTR : CURBCNTR, cntl);
4666 intel_crtc->cursor_visible = visible;
4668 /* and commit changes on next vblank */
4669 I915_WRITE(pipe == 0 ? CURABASE : CURBBASE, base);
4672 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
4673 static void intel_crtc_update_cursor(struct drm_crtc *crtc,
4676 struct drm_device *dev = crtc->dev;
4677 struct drm_i915_private *dev_priv = dev->dev_private;
4678 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4679 int pipe = intel_crtc->pipe;
4680 int x = intel_crtc->cursor_x;
4681 int y = intel_crtc->cursor_y;
4687 if (on && crtc->enabled && crtc->fb) {
4688 base = intel_crtc->cursor_addr;
4689 if (x > (int) crtc->fb->width)
4692 if (y > (int) crtc->fb->height)
4698 if (x + intel_crtc->cursor_width < 0)
4701 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
4704 pos |= x << CURSOR_X_SHIFT;
4707 if (y + intel_crtc->cursor_height < 0)
4710 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
4713 pos |= y << CURSOR_Y_SHIFT;
4715 visible = base != 0;
4716 if (!visible && !intel_crtc->cursor_visible)
4719 I915_WRITE(pipe == 0 ? CURAPOS : CURBPOS, pos);
4720 if (IS_845G(dev) || IS_I865G(dev))
4721 i845_update_cursor(crtc, base);
4723 i9xx_update_cursor(crtc, base);
4726 intel_mark_busy(dev, to_intel_framebuffer(crtc->fb)->obj);
4729 static int intel_crtc_cursor_set(struct drm_crtc *crtc,
4730 struct drm_file *file,
4732 uint32_t width, uint32_t height)
4734 struct drm_device *dev = crtc->dev;
4735 struct drm_i915_private *dev_priv = dev->dev_private;
4736 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4737 struct drm_i915_gem_object *obj;
4741 DRM_DEBUG_KMS("\n");
4743 /* if we want to turn off the cursor ignore width and height */
4745 DRM_DEBUG_KMS("cursor off\n");
4748 mutex_lock(&dev->struct_mutex);
4752 /* Currently we only support 64x64 cursors */
4753 if (width != 64 || height != 64) {
4754 DRM_ERROR("we currently only support 64x64 cursors\n");
4758 obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
4762 if (obj->base.size < width * height * 4) {
4763 DRM_ERROR("buffer is to small\n");
4768 /* we only need to pin inside GTT if cursor is non-phy */
4769 mutex_lock(&dev->struct_mutex);
4770 if (!dev_priv->info->cursor_needs_physical) {
4771 if (obj->tiling_mode) {
4772 DRM_ERROR("cursor cannot be tiled\n");
4777 ret = i915_gem_object_pin(obj, PAGE_SIZE, true);
4779 DRM_ERROR("failed to pin cursor bo\n");
4783 ret = i915_gem_object_set_to_gtt_domain(obj, 0);
4785 DRM_ERROR("failed to move cursor bo into the GTT\n");
4789 ret = i915_gem_object_put_fence(obj);
4791 DRM_ERROR("failed to move cursor bo into the GTT\n");
4795 addr = obj->gtt_offset;
4797 int align = IS_I830(dev) ? 16 * 1024 : 256;
4798 ret = i915_gem_attach_phys_object(dev, obj,
4799 (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
4802 DRM_ERROR("failed to attach phys object\n");
4805 addr = obj->phys_obj->handle->busaddr;
4809 I915_WRITE(CURSIZE, (height << 12) | width);
4812 if (intel_crtc->cursor_bo) {
4813 if (dev_priv->info->cursor_needs_physical) {
4814 if (intel_crtc->cursor_bo != obj)
4815 i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
4817 i915_gem_object_unpin(intel_crtc->cursor_bo);
4818 drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
4821 mutex_unlock(&dev->struct_mutex);
4823 intel_crtc->cursor_addr = addr;
4824 intel_crtc->cursor_bo = obj;
4825 intel_crtc->cursor_width = width;
4826 intel_crtc->cursor_height = height;
4828 intel_crtc_update_cursor(crtc, true);
4832 i915_gem_object_unpin(obj);
4834 mutex_unlock(&dev->struct_mutex);
4836 drm_gem_object_unreference_unlocked(&obj->base);
4840 static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
4842 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4844 intel_crtc->cursor_x = x;
4845 intel_crtc->cursor_y = y;
4847 intel_crtc_update_cursor(crtc, true);
4852 /** Sets the color ramps on behalf of RandR */
4853 void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
4854 u16 blue, int regno)
4856 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4858 intel_crtc->lut_r[regno] = red >> 8;
4859 intel_crtc->lut_g[regno] = green >> 8;
4860 intel_crtc->lut_b[regno] = blue >> 8;
4863 void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
4864 u16 *blue, int regno)
4866 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4868 *red = intel_crtc->lut_r[regno] << 8;
4869 *green = intel_crtc->lut_g[regno] << 8;
4870 *blue = intel_crtc->lut_b[regno] << 8;
4873 static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
4874 u16 *blue, uint32_t start, uint32_t size)
4876 int end = (start + size > 256) ? 256 : start + size, i;
4877 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4879 for (i = start; i < end; i++) {
4880 intel_crtc->lut_r[i] = red[i] >> 8;
4881 intel_crtc->lut_g[i] = green[i] >> 8;
4882 intel_crtc->lut_b[i] = blue[i] >> 8;
4885 intel_crtc_load_lut(crtc);
4889 * Get a pipe with a simple mode set on it for doing load-based monitor
4892 * It will be up to the load-detect code to adjust the pipe as appropriate for
4893 * its requirements. The pipe will be connected to no other encoders.
4895 * Currently this code will only succeed if there is a pipe with no encoders
4896 * configured for it. In the future, it could choose to temporarily disable
4897 * some outputs to free up a pipe for its use.
4899 * \return crtc, or NULL if no pipes are available.
4902 /* VESA 640x480x72Hz mode to set on the pipe */
4903 static struct drm_display_mode load_detect_mode = {
4904 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
4905 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
4908 struct drm_crtc *intel_get_load_detect_pipe(struct intel_encoder *intel_encoder,
4909 struct drm_connector *connector,
4910 struct drm_display_mode *mode,
4913 struct intel_crtc *intel_crtc;
4914 struct drm_crtc *possible_crtc;
4915 struct drm_crtc *supported_crtc =NULL;
4916 struct drm_encoder *encoder = &intel_encoder->base;
4917 struct drm_crtc *crtc = NULL;
4918 struct drm_device *dev = encoder->dev;
4919 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
4920 struct drm_crtc_helper_funcs *crtc_funcs;
4924 * Algorithm gets a little messy:
4925 * - if the connector already has an assigned crtc, use it (but make
4926 * sure it's on first)
4927 * - try to find the first unused crtc that can drive this connector,
4928 * and use that if we find one
4929 * - if there are no unused crtcs available, try to use the first
4930 * one we found that supports the connector
4933 /* See if we already have a CRTC for this connector */
4934 if (encoder->crtc) {
4935 crtc = encoder->crtc;
4936 /* Make sure the crtc and connector are running */
4937 intel_crtc = to_intel_crtc(crtc);
4938 *dpms_mode = intel_crtc->dpms_mode;
4939 if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
4940 crtc_funcs = crtc->helper_private;
4941 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
4942 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
4947 /* Find an unused one (if possible) */
4948 list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
4950 if (!(encoder->possible_crtcs & (1 << i)))
4952 if (!possible_crtc->enabled) {
4953 crtc = possible_crtc;
4956 if (!supported_crtc)
4957 supported_crtc = possible_crtc;
4961 * If we didn't find an unused CRTC, don't use any.
4967 encoder->crtc = crtc;
4968 connector->encoder = encoder;
4969 intel_encoder->load_detect_temp = true;
4971 intel_crtc = to_intel_crtc(crtc);
4972 *dpms_mode = intel_crtc->dpms_mode;
4974 if (!crtc->enabled) {
4976 mode = &load_detect_mode;
4977 drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb);
4979 if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
4980 crtc_funcs = crtc->helper_private;
4981 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
4984 /* Add this connector to the crtc */
4985 encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode);
4986 encoder_funcs->commit(encoder);
4988 /* let the connector get through one full cycle before testing */
4989 intel_wait_for_vblank(dev, intel_crtc->pipe);
4994 void intel_release_load_detect_pipe(struct intel_encoder *intel_encoder,
4995 struct drm_connector *connector, int dpms_mode)
4997 struct drm_encoder *encoder = &intel_encoder->base;
4998 struct drm_device *dev = encoder->dev;
4999 struct drm_crtc *crtc = encoder->crtc;
5000 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
5001 struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
5003 if (intel_encoder->load_detect_temp) {
5004 encoder->crtc = NULL;
5005 connector->encoder = NULL;
5006 intel_encoder->load_detect_temp = false;
5007 crtc->enabled = drm_helper_crtc_in_use(crtc);
5008 drm_helper_disable_unused_functions(dev);
5011 /* Switch crtc and encoder back off if necessary */
5012 if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) {
5013 if (encoder->crtc == crtc)
5014 encoder_funcs->dpms(encoder, dpms_mode);
5015 crtc_funcs->dpms(crtc, dpms_mode);
5019 /* Returns the clock of the currently programmed mode of the given pipe. */
5020 static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
5022 struct drm_i915_private *dev_priv = dev->dev_private;
5023 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5024 int pipe = intel_crtc->pipe;
5025 u32 dpll = I915_READ((pipe == 0) ? DPLL_A : DPLL_B);
5027 intel_clock_t clock;
5029 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
5030 fp = I915_READ((pipe == 0) ? FPA0 : FPB0);
5032 fp = I915_READ((pipe == 0) ? FPA1 : FPB1);
5034 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
5035 if (IS_PINEVIEW(dev)) {
5036 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
5037 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
5039 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
5040 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
5043 if (!IS_GEN2(dev)) {
5044 if (IS_PINEVIEW(dev))
5045 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
5046 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
5048 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
5049 DPLL_FPA01_P1_POST_DIV_SHIFT);
5051 switch (dpll & DPLL_MODE_MASK) {
5052 case DPLLB_MODE_DAC_SERIAL:
5053 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
5056 case DPLLB_MODE_LVDS:
5057 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
5061 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
5062 "mode\n", (int)(dpll & DPLL_MODE_MASK));
5066 /* XXX: Handle the 100Mhz refclk */
5067 intel_clock(dev, 96000, &clock);
5069 bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
5072 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
5073 DPLL_FPA01_P1_POST_DIV_SHIFT);
5076 if ((dpll & PLL_REF_INPUT_MASK) ==
5077 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
5078 /* XXX: might not be 66MHz */
5079 intel_clock(dev, 66000, &clock);
5081 intel_clock(dev, 48000, &clock);
5083 if (dpll & PLL_P1_DIVIDE_BY_TWO)
5086 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
5087 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
5089 if (dpll & PLL_P2_DIVIDE_BY_4)
5094 intel_clock(dev, 48000, &clock);
5098 /* XXX: It would be nice to validate the clocks, but we can't reuse
5099 * i830PllIsValid() because it relies on the xf86_config connector
5100 * configuration being accurate, which it isn't necessarily.
5106 /** Returns the currently programmed mode of the given pipe. */
5107 struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
5108 struct drm_crtc *crtc)
5110 struct drm_i915_private *dev_priv = dev->dev_private;
5111 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5112 int pipe = intel_crtc->pipe;
5113 struct drm_display_mode *mode;
5114 int htot = I915_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B);
5115 int hsync = I915_READ((pipe == 0) ? HSYNC_A : HSYNC_B);
5116 int vtot = I915_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B);
5117 int vsync = I915_READ((pipe == 0) ? VSYNC_A : VSYNC_B);
5119 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
5123 mode->clock = intel_crtc_clock_get(dev, crtc);
5124 mode->hdisplay = (htot & 0xffff) + 1;
5125 mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
5126 mode->hsync_start = (hsync & 0xffff) + 1;
5127 mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
5128 mode->vdisplay = (vtot & 0xffff) + 1;
5129 mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
5130 mode->vsync_start = (vsync & 0xffff) + 1;
5131 mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
5133 drm_mode_set_name(mode);
5134 drm_mode_set_crtcinfo(mode, 0);
5139 #define GPU_IDLE_TIMEOUT 500 /* ms */
5141 /* When this timer fires, we've been idle for awhile */
5142 static void intel_gpu_idle_timer(unsigned long arg)
5144 struct drm_device *dev = (struct drm_device *)arg;
5145 drm_i915_private_t *dev_priv = dev->dev_private;
5147 if (!list_empty(&dev_priv->mm.active_list)) {
5148 /* Still processing requests, so just re-arm the timer. */
5149 mod_timer(&dev_priv->idle_timer, jiffies +
5150 msecs_to_jiffies(GPU_IDLE_TIMEOUT));
5154 dev_priv->busy = false;
5155 queue_work(dev_priv->wq, &dev_priv->idle_work);
5158 #define CRTC_IDLE_TIMEOUT 1000 /* ms */
5160 static void intel_crtc_idle_timer(unsigned long arg)
5162 struct intel_crtc *intel_crtc = (struct intel_crtc *)arg;
5163 struct drm_crtc *crtc = &intel_crtc->base;
5164 drm_i915_private_t *dev_priv = crtc->dev->dev_private;
5165 struct intel_framebuffer *intel_fb;
5167 intel_fb = to_intel_framebuffer(crtc->fb);
5168 if (intel_fb && intel_fb->obj->active) {
5169 /* The framebuffer is still being accessed by the GPU. */
5170 mod_timer(&intel_crtc->idle_timer, jiffies +
5171 msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
5175 intel_crtc->busy = false;
5176 queue_work(dev_priv->wq, &dev_priv->idle_work);
5179 static void intel_increase_pllclock(struct drm_crtc *crtc)
5181 struct drm_device *dev = crtc->dev;
5182 drm_i915_private_t *dev_priv = dev->dev_private;
5183 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5184 int pipe = intel_crtc->pipe;
5185 int dpll_reg = DPLL(pipe);
5188 if (HAS_PCH_SPLIT(dev))
5191 if (!dev_priv->lvds_downclock_avail)
5194 dpll = I915_READ(dpll_reg);
5195 if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
5196 DRM_DEBUG_DRIVER("upclocking LVDS\n");
5198 /* Unlock panel regs */
5199 I915_WRITE(PP_CONTROL,
5200 I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
5202 dpll &= ~DISPLAY_RATE_SELECT_FPA1;
5203 I915_WRITE(dpll_reg, dpll);
5204 POSTING_READ(dpll_reg);
5205 intel_wait_for_vblank(dev, pipe);
5207 dpll = I915_READ(dpll_reg);
5208 if (dpll & DISPLAY_RATE_SELECT_FPA1)
5209 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
5211 /* ...and lock them again */
5212 I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
5215 /* Schedule downclock */
5216 mod_timer(&intel_crtc->idle_timer, jiffies +
5217 msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
5220 static void intel_decrease_pllclock(struct drm_crtc *crtc)
5222 struct drm_device *dev = crtc->dev;
5223 drm_i915_private_t *dev_priv = dev->dev_private;
5224 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5225 int pipe = intel_crtc->pipe;
5226 int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
5227 int dpll = I915_READ(dpll_reg);
5229 if (HAS_PCH_SPLIT(dev))
5232 if (!dev_priv->lvds_downclock_avail)
5236 * Since this is called by a timer, we should never get here in
5239 if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
5240 DRM_DEBUG_DRIVER("downclocking LVDS\n");
5242 /* Unlock panel regs */
5243 I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) |
5246 dpll |= DISPLAY_RATE_SELECT_FPA1;
5247 I915_WRITE(dpll_reg, dpll);
5248 dpll = I915_READ(dpll_reg);
5249 intel_wait_for_vblank(dev, pipe);
5250 dpll = I915_READ(dpll_reg);
5251 if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
5252 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
5254 /* ...and lock them again */
5255 I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
5261 * intel_idle_update - adjust clocks for idleness
5262 * @work: work struct
5264 * Either the GPU or display (or both) went idle. Check the busy status
5265 * here and adjust the CRTC and GPU clocks as necessary.
5267 static void intel_idle_update(struct work_struct *work)
5269 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
5271 struct drm_device *dev = dev_priv->dev;
5272 struct drm_crtc *crtc;
5273 struct intel_crtc *intel_crtc;
5276 if (!i915_powersave)
5279 mutex_lock(&dev->struct_mutex);
5281 i915_update_gfx_val(dev_priv);
5283 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
5284 /* Skip inactive CRTCs */
5289 intel_crtc = to_intel_crtc(crtc);
5290 if (!intel_crtc->busy)
5291 intel_decrease_pllclock(crtc);
5294 if ((enabled == 1) && (IS_I945G(dev) || IS_I945GM(dev))) {
5295 DRM_DEBUG_DRIVER("enable memory self refresh on 945\n");
5296 I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN_MASK | FW_BLC_SELF_EN);
5299 mutex_unlock(&dev->struct_mutex);
5303 * intel_mark_busy - mark the GPU and possibly the display busy
5305 * @obj: object we're operating on
5307 * Callers can use this function to indicate that the GPU is busy processing
5308 * commands. If @obj matches one of the CRTC objects (i.e. it's a scanout
5309 * buffer), we'll also mark the display as busy, so we know to increase its
5312 void intel_mark_busy(struct drm_device *dev, struct drm_i915_gem_object *obj)
5314 drm_i915_private_t *dev_priv = dev->dev_private;
5315 struct drm_crtc *crtc = NULL;
5316 struct intel_framebuffer *intel_fb;
5317 struct intel_crtc *intel_crtc;
5319 if (!drm_core_check_feature(dev, DRIVER_MODESET))
5322 if (!dev_priv->busy) {
5323 if (IS_I945G(dev) || IS_I945GM(dev)) {
5326 DRM_DEBUG_DRIVER("disable memory self refresh on 945\n");
5327 fw_blc_self = I915_READ(FW_BLC_SELF);
5328 fw_blc_self &= ~FW_BLC_SELF_EN;
5329 I915_WRITE(FW_BLC_SELF, fw_blc_self | FW_BLC_SELF_EN_MASK);
5331 dev_priv->busy = true;
5333 mod_timer(&dev_priv->idle_timer, jiffies +
5334 msecs_to_jiffies(GPU_IDLE_TIMEOUT));
5336 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
5340 intel_crtc = to_intel_crtc(crtc);
5341 intel_fb = to_intel_framebuffer(crtc->fb);
5342 if (intel_fb->obj == obj) {
5343 if (!intel_crtc->busy) {
5344 if (IS_I945G(dev) || IS_I945GM(dev)) {
5347 DRM_DEBUG_DRIVER("disable memory self refresh on 945\n");
5348 fw_blc_self = I915_READ(FW_BLC_SELF);
5349 fw_blc_self &= ~FW_BLC_SELF_EN;
5350 I915_WRITE(FW_BLC_SELF, fw_blc_self | FW_BLC_SELF_EN_MASK);
5352 /* Non-busy -> busy, upclock */
5353 intel_increase_pllclock(crtc);
5354 intel_crtc->busy = true;
5356 /* Busy -> busy, put off timer */
5357 mod_timer(&intel_crtc->idle_timer, jiffies +
5358 msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
5364 static void intel_crtc_destroy(struct drm_crtc *crtc)
5366 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5367 struct drm_device *dev = crtc->dev;
5368 struct intel_unpin_work *work;
5369 unsigned long flags;
5371 spin_lock_irqsave(&dev->event_lock, flags);
5372 work = intel_crtc->unpin_work;
5373 intel_crtc->unpin_work = NULL;
5374 spin_unlock_irqrestore(&dev->event_lock, flags);
5377 cancel_work_sync(&work->work);
5381 drm_crtc_cleanup(crtc);
5386 static void intel_unpin_work_fn(struct work_struct *__work)
5388 struct intel_unpin_work *work =
5389 container_of(__work, struct intel_unpin_work, work);
5391 mutex_lock(&work->dev->struct_mutex);
5392 i915_gem_object_unpin(work->old_fb_obj);
5393 drm_gem_object_unreference(&work->pending_flip_obj->base);
5394 drm_gem_object_unreference(&work->old_fb_obj->base);
5396 mutex_unlock(&work->dev->struct_mutex);
5400 static void do_intel_finish_page_flip(struct drm_device *dev,
5401 struct drm_crtc *crtc)
5403 drm_i915_private_t *dev_priv = dev->dev_private;
5404 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5405 struct intel_unpin_work *work;
5406 struct drm_i915_gem_object *obj;
5407 struct drm_pending_vblank_event *e;
5408 struct timeval tnow, tvbl;
5409 unsigned long flags;
5411 /* Ignore early vblank irqs */
5412 if (intel_crtc == NULL)
5415 do_gettimeofday(&tnow);
5417 spin_lock_irqsave(&dev->event_lock, flags);
5418 work = intel_crtc->unpin_work;
5419 if (work == NULL || !work->pending) {
5420 spin_unlock_irqrestore(&dev->event_lock, flags);
5424 intel_crtc->unpin_work = NULL;
5428 e->event.sequence = drm_vblank_count_and_time(dev, intel_crtc->pipe, &tvbl);
5430 /* Called before vblank count and timestamps have
5431 * been updated for the vblank interval of flip
5432 * completion? Need to increment vblank count and
5433 * add one videorefresh duration to returned timestamp
5434 * to account for this. We assume this happened if we
5435 * get called over 0.9 frame durations after the last
5436 * timestamped vblank.
5438 * This calculation can not be used with vrefresh rates
5439 * below 5Hz (10Hz to be on the safe side) without
5440 * promoting to 64 integers.
5442 if (10 * (timeval_to_ns(&tnow) - timeval_to_ns(&tvbl)) >
5443 9 * crtc->framedur_ns) {
5444 e->event.sequence++;
5445 tvbl = ns_to_timeval(timeval_to_ns(&tvbl) +
5449 e->event.tv_sec = tvbl.tv_sec;
5450 e->event.tv_usec = tvbl.tv_usec;
5452 list_add_tail(&e->base.link,
5453 &e->base.file_priv->event_list);
5454 wake_up_interruptible(&e->base.file_priv->event_wait);
5457 drm_vblank_put(dev, intel_crtc->pipe);
5459 spin_unlock_irqrestore(&dev->event_lock, flags);
5461 obj = work->old_fb_obj;
5463 atomic_clear_mask(1 << intel_crtc->plane,
5464 &obj->pending_flip.counter);
5465 if (atomic_read(&obj->pending_flip) == 0)
5466 wake_up(&dev_priv->pending_flip_queue);
5468 schedule_work(&work->work);
5470 trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
5473 void intel_finish_page_flip(struct drm_device *dev, int pipe)
5475 drm_i915_private_t *dev_priv = dev->dev_private;
5476 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
5478 do_intel_finish_page_flip(dev, crtc);
5481 void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
5483 drm_i915_private_t *dev_priv = dev->dev_private;
5484 struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
5486 do_intel_finish_page_flip(dev, crtc);
5489 void intel_prepare_page_flip(struct drm_device *dev, int plane)
5491 drm_i915_private_t *dev_priv = dev->dev_private;
5492 struct intel_crtc *intel_crtc =
5493 to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
5494 unsigned long flags;
5496 spin_lock_irqsave(&dev->event_lock, flags);
5497 if (intel_crtc->unpin_work) {
5498 if ((++intel_crtc->unpin_work->pending) > 1)
5499 DRM_ERROR("Prepared flip multiple times\n");
5501 DRM_DEBUG_DRIVER("preparing flip with no unpin work?\n");
5503 spin_unlock_irqrestore(&dev->event_lock, flags);
5506 static int intel_crtc_page_flip(struct drm_crtc *crtc,
5507 struct drm_framebuffer *fb,
5508 struct drm_pending_vblank_event *event)
5510 struct drm_device *dev = crtc->dev;
5511 struct drm_i915_private *dev_priv = dev->dev_private;
5512 struct intel_framebuffer *intel_fb;
5513 struct drm_i915_gem_object *obj;
5514 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5515 struct intel_unpin_work *work;
5516 unsigned long flags, offset;
5517 int pipe = intel_crtc->pipe;
5521 work = kzalloc(sizeof *work, GFP_KERNEL);
5525 work->event = event;
5526 work->dev = crtc->dev;
5527 intel_fb = to_intel_framebuffer(crtc->fb);
5528 work->old_fb_obj = intel_fb->obj;
5529 INIT_WORK(&work->work, intel_unpin_work_fn);
5531 /* We borrow the event spin lock for protecting unpin_work */
5532 spin_lock_irqsave(&dev->event_lock, flags);
5533 if (intel_crtc->unpin_work) {
5534 spin_unlock_irqrestore(&dev->event_lock, flags);
5537 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
5540 intel_crtc->unpin_work = work;
5541 spin_unlock_irqrestore(&dev->event_lock, flags);
5543 intel_fb = to_intel_framebuffer(fb);
5544 obj = intel_fb->obj;
5546 mutex_lock(&dev->struct_mutex);
5547 ret = intel_pin_and_fence_fb_obj(dev, obj, LP_RING(dev_priv));
5551 /* Reference the objects for the scheduled work. */
5552 drm_gem_object_reference(&work->old_fb_obj->base);
5553 drm_gem_object_reference(&obj->base);
5557 ret = drm_vblank_get(dev, intel_crtc->pipe);
5561 if (IS_GEN3(dev) || IS_GEN2(dev)) {
5564 /* Can't queue multiple flips, so wait for the previous
5565 * one to finish before executing the next.
5567 ret = BEGIN_LP_RING(2);
5571 if (intel_crtc->plane)
5572 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
5574 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
5575 OUT_RING(MI_WAIT_FOR_EVENT | flip_mask);
5580 work->pending_flip_obj = obj;
5582 work->enable_stall_check = true;
5584 /* Offset into the new buffer for cases of shared fbs between CRTCs */
5585 offset = crtc->y * fb->pitch + crtc->x * fb->bits_per_pixel/8;
5587 ret = BEGIN_LP_RING(4);
5591 /* Block clients from rendering to the new back buffer until
5592 * the flip occurs and the object is no longer visible.
5594 atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
5596 switch (INTEL_INFO(dev)->gen) {
5598 OUT_RING(MI_DISPLAY_FLIP |
5599 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
5600 OUT_RING(fb->pitch);
5601 OUT_RING(obj->gtt_offset + offset);
5606 OUT_RING(MI_DISPLAY_FLIP_I915 |
5607 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
5608 OUT_RING(fb->pitch);
5609 OUT_RING(obj->gtt_offset + offset);
5615 /* i965+ uses the linear or tiled offsets from the
5616 * Display Registers (which do not change across a page-flip)
5617 * so we need only reprogram the base address.
5619 OUT_RING(MI_DISPLAY_FLIP |
5620 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
5621 OUT_RING(fb->pitch);
5622 OUT_RING(obj->gtt_offset | obj->tiling_mode);
5624 /* XXX Enabling the panel-fitter across page-flip is so far
5625 * untested on non-native modes, so ignore it for now.
5626 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
5629 pipesrc = I915_READ(pipe == 0 ? PIPEASRC : PIPEBSRC) & 0x0fff0fff;
5630 OUT_RING(pf | pipesrc);
5634 OUT_RING(MI_DISPLAY_FLIP |
5635 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
5636 OUT_RING(fb->pitch | obj->tiling_mode);
5637 OUT_RING(obj->gtt_offset);
5639 pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
5640 pipesrc = I915_READ(pipe == 0 ? PIPEASRC : PIPEBSRC) & 0x0fff0fff;
5641 OUT_RING(pf | pipesrc);
5646 mutex_unlock(&dev->struct_mutex);
5648 trace_i915_flip_request(intel_crtc->plane, obj);
5653 drm_gem_object_unreference(&work->old_fb_obj->base);
5654 drm_gem_object_unreference(&obj->base);
5656 mutex_unlock(&dev->struct_mutex);
5658 spin_lock_irqsave(&dev->event_lock, flags);
5659 intel_crtc->unpin_work = NULL;
5660 spin_unlock_irqrestore(&dev->event_lock, flags);
5667 static struct drm_crtc_helper_funcs intel_helper_funcs = {
5668 .dpms = intel_crtc_dpms,
5669 .mode_fixup = intel_crtc_mode_fixup,
5670 .mode_set = intel_crtc_mode_set,
5671 .mode_set_base = intel_pipe_set_base,
5672 .mode_set_base_atomic = intel_pipe_set_base_atomic,
5673 .load_lut = intel_crtc_load_lut,
5674 .disable = intel_crtc_disable,
5677 static const struct drm_crtc_funcs intel_crtc_funcs = {
5678 .cursor_set = intel_crtc_cursor_set,
5679 .cursor_move = intel_crtc_cursor_move,
5680 .gamma_set = intel_crtc_gamma_set,
5681 .set_config = drm_crtc_helper_set_config,
5682 .destroy = intel_crtc_destroy,
5683 .page_flip = intel_crtc_page_flip,
5686 static void intel_sanitize_modesetting(struct drm_device *dev,
5687 int pipe, int plane)
5689 struct drm_i915_private *dev_priv = dev->dev_private;
5692 if (HAS_PCH_SPLIT(dev))
5695 /* Who knows what state these registers were left in by the BIOS or
5698 * If we leave the registers in a conflicting state (e.g. with the
5699 * display plane reading from the other pipe than the one we intend
5700 * to use) then when we attempt to teardown the active mode, we will
5701 * not disable the pipes and planes in the correct order -- leaving
5702 * a plane reading from a disabled pipe and possibly leading to
5703 * undefined behaviour.
5706 reg = DSPCNTR(plane);
5707 val = I915_READ(reg);
5709 if ((val & DISPLAY_PLANE_ENABLE) == 0)
5711 if (!!(val & DISPPLANE_SEL_PIPE_MASK) == pipe)
5714 /* This display plane is active and attached to the other CPU pipe. */
5717 /* Disable the plane and wait for it to stop reading from the pipe. */
5718 intel_disable_plane(dev_priv, plane, pipe);
5719 intel_disable_pipe(dev_priv, pipe);
5722 static void intel_crtc_init(struct drm_device *dev, int pipe)
5724 drm_i915_private_t *dev_priv = dev->dev_private;
5725 struct intel_crtc *intel_crtc;
5728 intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
5729 if (intel_crtc == NULL)
5732 drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
5734 drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
5735 for (i = 0; i < 256; i++) {
5736 intel_crtc->lut_r[i] = i;
5737 intel_crtc->lut_g[i] = i;
5738 intel_crtc->lut_b[i] = i;
5741 /* Swap pipes & planes for FBC on pre-965 */
5742 intel_crtc->pipe = pipe;
5743 intel_crtc->plane = pipe;
5744 if (IS_MOBILE(dev) && IS_GEN3(dev)) {
5745 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
5746 intel_crtc->plane = !pipe;
5749 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
5750 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
5751 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
5752 dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
5754 intel_crtc->cursor_addr = 0;
5755 intel_crtc->dpms_mode = -1;
5756 intel_crtc->active = true; /* force the pipe off on setup_init_config */
5758 if (HAS_PCH_SPLIT(dev)) {
5759 intel_helper_funcs.prepare = ironlake_crtc_prepare;
5760 intel_helper_funcs.commit = ironlake_crtc_commit;
5762 intel_helper_funcs.prepare = i9xx_crtc_prepare;
5763 intel_helper_funcs.commit = i9xx_crtc_commit;
5766 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
5768 intel_crtc->busy = false;
5770 setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer,
5771 (unsigned long)intel_crtc);
5773 intel_sanitize_modesetting(dev, intel_crtc->pipe, intel_crtc->plane);
5776 int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
5777 struct drm_file *file)
5779 drm_i915_private_t *dev_priv = dev->dev_private;
5780 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
5781 struct drm_mode_object *drmmode_obj;
5782 struct intel_crtc *crtc;
5785 DRM_ERROR("called with no initialization\n");
5789 drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
5790 DRM_MODE_OBJECT_CRTC);
5793 DRM_ERROR("no such CRTC id\n");
5797 crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
5798 pipe_from_crtc_id->pipe = crtc->pipe;
5803 static int intel_encoder_clones(struct drm_device *dev, int type_mask)
5805 struct intel_encoder *encoder;
5809 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
5810 if (type_mask & encoder->clone_mask)
5811 index_mask |= (1 << entry);
5818 static bool has_edp_a(struct drm_device *dev)
5820 struct drm_i915_private *dev_priv = dev->dev_private;
5822 if (!IS_MOBILE(dev))
5825 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
5829 (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
5835 static void intel_setup_outputs(struct drm_device *dev)
5837 struct drm_i915_private *dev_priv = dev->dev_private;
5838 struct intel_encoder *encoder;
5839 bool dpd_is_edp = false;
5840 bool has_lvds = false;
5842 if (IS_MOBILE(dev) && !IS_I830(dev))
5843 has_lvds = intel_lvds_init(dev);
5844 if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
5845 /* disable the panel fitter on everything but LVDS */
5846 I915_WRITE(PFIT_CONTROL, 0);
5849 if (HAS_PCH_SPLIT(dev)) {
5850 dpd_is_edp = intel_dpd_is_edp(dev);
5853 intel_dp_init(dev, DP_A);
5855 if (dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
5856 intel_dp_init(dev, PCH_DP_D);
5859 intel_crt_init(dev);
5861 if (HAS_PCH_SPLIT(dev)) {
5864 if (I915_READ(HDMIB) & PORT_DETECTED) {
5865 /* PCH SDVOB multiplex with HDMIB */
5866 found = intel_sdvo_init(dev, PCH_SDVOB);
5868 intel_hdmi_init(dev, HDMIB);
5869 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
5870 intel_dp_init(dev, PCH_DP_B);
5873 if (I915_READ(HDMIC) & PORT_DETECTED)
5874 intel_hdmi_init(dev, HDMIC);
5876 if (I915_READ(HDMID) & PORT_DETECTED)
5877 intel_hdmi_init(dev, HDMID);
5879 if (I915_READ(PCH_DP_C) & DP_DETECTED)
5880 intel_dp_init(dev, PCH_DP_C);
5882 if (!dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
5883 intel_dp_init(dev, PCH_DP_D);
5885 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
5888 if (I915_READ(SDVOB) & SDVO_DETECTED) {
5889 DRM_DEBUG_KMS("probing SDVOB\n");
5890 found = intel_sdvo_init(dev, SDVOB);
5891 if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
5892 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
5893 intel_hdmi_init(dev, SDVOB);
5896 if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
5897 DRM_DEBUG_KMS("probing DP_B\n");
5898 intel_dp_init(dev, DP_B);
5902 /* Before G4X SDVOC doesn't have its own detect register */
5904 if (I915_READ(SDVOB) & SDVO_DETECTED) {
5905 DRM_DEBUG_KMS("probing SDVOC\n");
5906 found = intel_sdvo_init(dev, SDVOC);
5909 if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
5911 if (SUPPORTS_INTEGRATED_HDMI(dev)) {
5912 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
5913 intel_hdmi_init(dev, SDVOC);
5915 if (SUPPORTS_INTEGRATED_DP(dev)) {
5916 DRM_DEBUG_KMS("probing DP_C\n");
5917 intel_dp_init(dev, DP_C);
5921 if (SUPPORTS_INTEGRATED_DP(dev) &&
5922 (I915_READ(DP_D) & DP_DETECTED)) {
5923 DRM_DEBUG_KMS("probing DP_D\n");
5924 intel_dp_init(dev, DP_D);
5926 } else if (IS_GEN2(dev))
5927 intel_dvo_init(dev);
5929 if (SUPPORTS_TV(dev))
5932 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
5933 encoder->base.possible_crtcs = encoder->crtc_mask;
5934 encoder->base.possible_clones =
5935 intel_encoder_clones(dev, encoder->clone_mask);
5938 intel_panel_setup_backlight(dev);
5941 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
5943 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
5945 drm_framebuffer_cleanup(fb);
5946 drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
5951 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
5952 struct drm_file *file,
5953 unsigned int *handle)
5955 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
5956 struct drm_i915_gem_object *obj = intel_fb->obj;
5958 return drm_gem_handle_create(file, &obj->base, handle);
5961 static const struct drm_framebuffer_funcs intel_fb_funcs = {
5962 .destroy = intel_user_framebuffer_destroy,
5963 .create_handle = intel_user_framebuffer_create_handle,
5966 int intel_framebuffer_init(struct drm_device *dev,
5967 struct intel_framebuffer *intel_fb,
5968 struct drm_mode_fb_cmd *mode_cmd,
5969 struct drm_i915_gem_object *obj)
5973 if (obj->tiling_mode == I915_TILING_Y)
5976 if (mode_cmd->pitch & 63)
5979 switch (mode_cmd->bpp) {
5989 ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
5991 DRM_ERROR("framebuffer init failed %d\n", ret);
5995 drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
5996 intel_fb->obj = obj;
6000 static struct drm_framebuffer *
6001 intel_user_framebuffer_create(struct drm_device *dev,
6002 struct drm_file *filp,
6003 struct drm_mode_fb_cmd *mode_cmd)
6005 struct drm_i915_gem_object *obj;
6006 struct intel_framebuffer *intel_fb;
6009 obj = to_intel_bo(drm_gem_object_lookup(dev, filp, mode_cmd->handle));
6011 return ERR_PTR(-ENOENT);
6013 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
6015 return ERR_PTR(-ENOMEM);
6017 ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
6019 drm_gem_object_unreference_unlocked(&obj->base);
6021 return ERR_PTR(ret);
6024 return &intel_fb->base;
6027 static const struct drm_mode_config_funcs intel_mode_funcs = {
6028 .fb_create = intel_user_framebuffer_create,
6029 .output_poll_changed = intel_fb_output_poll_changed,
6032 static struct drm_i915_gem_object *
6033 intel_alloc_context_page(struct drm_device *dev)
6035 struct drm_i915_gem_object *ctx;
6038 ctx = i915_gem_alloc_object(dev, 4096);
6040 DRM_DEBUG("failed to alloc power context, RC6 disabled\n");
6044 mutex_lock(&dev->struct_mutex);
6045 ret = i915_gem_object_pin(ctx, 4096, true);
6047 DRM_ERROR("failed to pin power context: %d\n", ret);
6051 ret = i915_gem_object_set_to_gtt_domain(ctx, 1);
6053 DRM_ERROR("failed to set-domain on power context: %d\n", ret);
6056 mutex_unlock(&dev->struct_mutex);
6061 i915_gem_object_unpin(ctx);
6063 drm_gem_object_unreference(&ctx->base);
6064 mutex_unlock(&dev->struct_mutex);
6068 bool ironlake_set_drps(struct drm_device *dev, u8 val)
6070 struct drm_i915_private *dev_priv = dev->dev_private;
6073 rgvswctl = I915_READ16(MEMSWCTL);
6074 if (rgvswctl & MEMCTL_CMD_STS) {
6075 DRM_DEBUG("gpu busy, RCS change rejected\n");
6076 return false; /* still busy with another command */
6079 rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) |
6080 (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM;
6081 I915_WRITE16(MEMSWCTL, rgvswctl);
6082 POSTING_READ16(MEMSWCTL);
6084 rgvswctl |= MEMCTL_CMD_STS;
6085 I915_WRITE16(MEMSWCTL, rgvswctl);
6090 void ironlake_enable_drps(struct drm_device *dev)
6092 struct drm_i915_private *dev_priv = dev->dev_private;
6093 u32 rgvmodectl = I915_READ(MEMMODECTL);
6094 u8 fmax, fmin, fstart, vstart;
6096 /* Enable temp reporting */
6097 I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN);
6098 I915_WRITE16(TSC1, I915_READ(TSC1) | TSE);
6100 /* 100ms RC evaluation intervals */
6101 I915_WRITE(RCUPEI, 100000);
6102 I915_WRITE(RCDNEI, 100000);
6104 /* Set max/min thresholds to 90ms and 80ms respectively */
6105 I915_WRITE(RCBMAXAVG, 90000);
6106 I915_WRITE(RCBMINAVG, 80000);
6108 I915_WRITE(MEMIHYST, 1);
6110 /* Set up min, max, and cur for interrupt handling */
6111 fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT;
6112 fmin = (rgvmodectl & MEMMODE_FMIN_MASK);
6113 fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >>
6114 MEMMODE_FSTART_SHIFT;
6116 vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >>
6119 dev_priv->fmax = fmax; /* IPS callback will increase this */
6120 dev_priv->fstart = fstart;
6122 dev_priv->max_delay = fstart;
6123 dev_priv->min_delay = fmin;
6124 dev_priv->cur_delay = fstart;
6126 DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n",
6127 fmax, fmin, fstart);
6129 I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN);
6132 * Interrupts will be enabled in ironlake_irq_postinstall
6135 I915_WRITE(VIDSTART, vstart);
6136 POSTING_READ(VIDSTART);
6138 rgvmodectl |= MEMMODE_SWMODE_EN;
6139 I915_WRITE(MEMMODECTL, rgvmodectl);
6141 if (wait_for((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10))
6142 DRM_ERROR("stuck trying to change perf mode\n");
6145 ironlake_set_drps(dev, fstart);
6147 dev_priv->last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) +
6149 dev_priv->last_time1 = jiffies_to_msecs(jiffies);
6150 dev_priv->last_count2 = I915_READ(0x112f4);
6151 getrawmonotonic(&dev_priv->last_time2);
6154 void ironlake_disable_drps(struct drm_device *dev)
6156 struct drm_i915_private *dev_priv = dev->dev_private;
6157 u16 rgvswctl = I915_READ16(MEMSWCTL);
6159 /* Ack interrupts, disable EFC interrupt */
6160 I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN);
6161 I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG);
6162 I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT);
6163 I915_WRITE(DEIIR, DE_PCU_EVENT);
6164 I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT);
6166 /* Go back to the starting frequency */
6167 ironlake_set_drps(dev, dev_priv->fstart);
6169 rgvswctl |= MEMCTL_CMD_STS;
6170 I915_WRITE(MEMSWCTL, rgvswctl);
6175 void gen6_set_rps(struct drm_device *dev, u8 val)
6177 struct drm_i915_private *dev_priv = dev->dev_private;
6180 swreq = (val & 0x3ff) << 25;
6181 I915_WRITE(GEN6_RPNSWREQ, swreq);
6184 void gen6_disable_rps(struct drm_device *dev)
6186 struct drm_i915_private *dev_priv = dev->dev_private;
6188 I915_WRITE(GEN6_RPNSWREQ, 1 << 31);
6189 I915_WRITE(GEN6_PMINTRMSK, 0xffffffff);
6190 I915_WRITE(GEN6_PMIER, 0);
6191 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
6194 static unsigned long intel_pxfreq(u32 vidfreq)
6197 int div = (vidfreq & 0x3f0000) >> 16;
6198 int post = (vidfreq & 0x3000) >> 12;
6199 int pre = (vidfreq & 0x7);
6204 freq = ((div * 133333) / ((1<<post) * pre));
6209 void intel_init_emon(struct drm_device *dev)
6211 struct drm_i915_private *dev_priv = dev->dev_private;
6216 /* Disable to program */
6220 /* Program energy weights for various events */
6221 I915_WRITE(SDEW, 0x15040d00);
6222 I915_WRITE(CSIEW0, 0x007f0000);
6223 I915_WRITE(CSIEW1, 0x1e220004);
6224 I915_WRITE(CSIEW2, 0x04000004);
6226 for (i = 0; i < 5; i++)
6227 I915_WRITE(PEW + (i * 4), 0);
6228 for (i = 0; i < 3; i++)
6229 I915_WRITE(DEW + (i * 4), 0);
6231 /* Program P-state weights to account for frequency power adjustment */
6232 for (i = 0; i < 16; i++) {
6233 u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4));
6234 unsigned long freq = intel_pxfreq(pxvidfreq);
6235 unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >>
6240 val *= (freq / 1000);
6242 val /= (127*127*900);
6244 DRM_ERROR("bad pxval: %ld\n", val);
6247 /* Render standby states get 0 weight */
6251 for (i = 0; i < 4; i++) {
6252 u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) |
6253 (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]);
6254 I915_WRITE(PXW + (i * 4), val);
6257 /* Adjust magic regs to magic values (more experimental results) */
6258 I915_WRITE(OGW0, 0);
6259 I915_WRITE(OGW1, 0);
6260 I915_WRITE(EG0, 0x00007f00);
6261 I915_WRITE(EG1, 0x0000000e);
6262 I915_WRITE(EG2, 0x000e0000);
6263 I915_WRITE(EG3, 0x68000300);
6264 I915_WRITE(EG4, 0x42000000);
6265 I915_WRITE(EG5, 0x00140031);
6269 for (i = 0; i < 8; i++)
6270 I915_WRITE(PXWL + (i * 4), 0);
6272 /* Enable PMON + select events */
6273 I915_WRITE(ECR, 0x80000019);
6275 lcfuse = I915_READ(LCFUSE02);
6277 dev_priv->corr = (lcfuse & LCFUSE_HIV_MASK);
6280 void gen6_enable_rps(struct drm_i915_private *dev_priv)
6282 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
6283 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
6285 int cur_freq, min_freq, max_freq;
6288 /* Here begins a magic sequence of register writes to enable
6289 * auto-downclocking.
6291 * Perhaps there might be some value in exposing these to
6294 I915_WRITE(GEN6_RC_STATE, 0);
6295 __gen6_force_wake_get(dev_priv);
6297 /* disable the counters and set deterministic thresholds */
6298 I915_WRITE(GEN6_RC_CONTROL, 0);
6300 I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16);
6301 I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30);
6302 I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30);
6303 I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000);
6304 I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25);
6306 for (i = 0; i < I915_NUM_RINGS; i++)
6307 I915_WRITE(RING_MAX_IDLE(dev_priv->ring[i].mmio_base), 10);
6309 I915_WRITE(GEN6_RC_SLEEP, 0);
6310 I915_WRITE(GEN6_RC1e_THRESHOLD, 1000);
6311 I915_WRITE(GEN6_RC6_THRESHOLD, 50000);
6312 I915_WRITE(GEN6_RC6p_THRESHOLD, 100000);
6313 I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */
6315 I915_WRITE(GEN6_RC_CONTROL,
6316 GEN6_RC_CTL_RC6p_ENABLE |
6317 GEN6_RC_CTL_RC6_ENABLE |
6318 GEN6_RC_CTL_EI_MODE(1) |
6319 GEN6_RC_CTL_HW_ENABLE);
6321 I915_WRITE(GEN6_RPNSWREQ,
6322 GEN6_FREQUENCY(10) |
6324 GEN6_AGGRESSIVE_TURBO);
6325 I915_WRITE(GEN6_RC_VIDEO_FREQ,
6326 GEN6_FREQUENCY(12));
6328 I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000);
6329 I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
6332 I915_WRITE(GEN6_RP_UP_THRESHOLD, 90000);
6333 I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 100000);
6334 I915_WRITE(GEN6_RP_UP_EI, 100000);
6335 I915_WRITE(GEN6_RP_DOWN_EI, 300000);
6336 I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
6337 I915_WRITE(GEN6_RP_CONTROL,
6338 GEN6_RP_MEDIA_TURBO |
6339 GEN6_RP_USE_NORMAL_FREQ |
6340 GEN6_RP_MEDIA_IS_GFX |
6342 GEN6_RP_UP_BUSY_MAX |
6343 GEN6_RP_DOWN_BUSY_MIN);
6345 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
6347 DRM_ERROR("timeout waiting for pcode mailbox to become idle\n");
6349 I915_WRITE(GEN6_PCODE_DATA, 0);
6350 I915_WRITE(GEN6_PCODE_MAILBOX,
6352 GEN6_PCODE_WRITE_MIN_FREQ_TABLE);
6353 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
6355 DRM_ERROR("timeout waiting for pcode mailbox to finish\n");
6357 min_freq = (rp_state_cap & 0xff0000) >> 16;
6358 max_freq = rp_state_cap & 0xff;
6359 cur_freq = (gt_perf_status & 0xff00) >> 8;
6361 /* Check for overclock support */
6362 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
6364 DRM_ERROR("timeout waiting for pcode mailbox to become idle\n");
6365 I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_READ_OC_PARAMS);
6366 pcu_mbox = I915_READ(GEN6_PCODE_DATA);
6367 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
6369 DRM_ERROR("timeout waiting for pcode mailbox to finish\n");
6370 if (pcu_mbox & (1<<31)) { /* OC supported */
6371 max_freq = pcu_mbox & 0xff;
6372 DRM_DEBUG_DRIVER("overclocking supported, adjusting frequency max to %dMHz\n", pcu_mbox * 100);
6375 /* In units of 100MHz */
6376 dev_priv->max_delay = max_freq;
6377 dev_priv->min_delay = min_freq;
6378 dev_priv->cur_delay = cur_freq;
6380 /* requires MSI enabled */
6381 I915_WRITE(GEN6_PMIER,
6382 GEN6_PM_MBOX_EVENT |
6383 GEN6_PM_THERMAL_EVENT |
6384 GEN6_PM_RP_DOWN_TIMEOUT |
6385 GEN6_PM_RP_UP_THRESHOLD |
6386 GEN6_PM_RP_DOWN_THRESHOLD |
6387 GEN6_PM_RP_UP_EI_EXPIRED |
6388 GEN6_PM_RP_DOWN_EI_EXPIRED);
6389 I915_WRITE(GEN6_PMIMR, 0);
6390 /* enable all PM interrupts */
6391 I915_WRITE(GEN6_PMINTRMSK, 0);
6393 __gen6_force_wake_put(dev_priv);
6396 void intel_enable_clock_gating(struct drm_device *dev)
6398 struct drm_i915_private *dev_priv = dev->dev_private;
6401 * Disable clock gating reported to work incorrectly according to the
6402 * specs, but enable as much else as we can.
6404 if (HAS_PCH_SPLIT(dev)) {
6405 uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE;
6408 /* Required for FBC */
6409 dspclk_gate |= DPFDUNIT_CLOCK_GATE_DISABLE;
6410 /* Required for CxSR */
6411 dspclk_gate |= DPARBUNIT_CLOCK_GATE_DISABLE;
6413 I915_WRITE(PCH_3DCGDIS0,
6414 MARIUNIT_CLOCK_GATE_DISABLE |
6415 SVSMUNIT_CLOCK_GATE_DISABLE);
6416 I915_WRITE(PCH_3DCGDIS1,
6417 VFMUNIT_CLOCK_GATE_DISABLE);
6420 I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate);
6423 * On Ibex Peak and Cougar Point, we need to disable clock
6424 * gating for the panel power sequencer or it will fail to
6425 * start up when no ports are active.
6427 I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
6430 * According to the spec the following bits should be set in
6431 * order to enable memory self-refresh
6432 * The bit 22/21 of 0x42004
6433 * The bit 5 of 0x42020
6434 * The bit 15 of 0x45000
6437 I915_WRITE(ILK_DISPLAY_CHICKEN2,
6438 (I915_READ(ILK_DISPLAY_CHICKEN2) |
6439 ILK_DPARB_GATE | ILK_VSDPFD_FULL));
6440 I915_WRITE(ILK_DSPCLK_GATE,
6441 (I915_READ(ILK_DSPCLK_GATE) |
6442 ILK_DPARB_CLK_GATE));
6443 I915_WRITE(DISP_ARB_CTL,
6444 (I915_READ(DISP_ARB_CTL) |
6446 I915_WRITE(WM3_LP_ILK, 0);
6447 I915_WRITE(WM2_LP_ILK, 0);
6448 I915_WRITE(WM1_LP_ILK, 0);
6451 * Based on the document from hardware guys the following bits
6452 * should be set unconditionally in order to enable FBC.
6453 * The bit 22 of 0x42000
6454 * The bit 22 of 0x42004
6455 * The bit 7,8,9 of 0x42020.
6457 if (IS_IRONLAKE_M(dev)) {
6458 I915_WRITE(ILK_DISPLAY_CHICKEN1,
6459 I915_READ(ILK_DISPLAY_CHICKEN1) |
6461 I915_WRITE(ILK_DISPLAY_CHICKEN2,
6462 I915_READ(ILK_DISPLAY_CHICKEN2) |
6464 I915_WRITE(ILK_DSPCLK_GATE,
6465 I915_READ(ILK_DSPCLK_GATE) |
6471 I915_WRITE(ILK_DISPLAY_CHICKEN2,
6472 I915_READ(ILK_DISPLAY_CHICKEN2) |
6473 ILK_ELPIN_409_SELECT);
6476 I915_WRITE(_3D_CHICKEN2,
6477 _3D_CHICKEN2_WM_READ_PIPELINED << 16 |
6478 _3D_CHICKEN2_WM_READ_PIPELINED);
6482 I915_WRITE(WM3_LP_ILK, 0);
6483 I915_WRITE(WM2_LP_ILK, 0);
6484 I915_WRITE(WM1_LP_ILK, 0);
6487 * According to the spec the following bits should be
6488 * set in order to enable memory self-refresh and fbc:
6489 * The bit21 and bit22 of 0x42000
6490 * The bit21 and bit22 of 0x42004
6491 * The bit5 and bit7 of 0x42020
6492 * The bit14 of 0x70180
6493 * The bit14 of 0x71180
6495 I915_WRITE(ILK_DISPLAY_CHICKEN1,
6496 I915_READ(ILK_DISPLAY_CHICKEN1) |
6497 ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS);
6498 I915_WRITE(ILK_DISPLAY_CHICKEN2,
6499 I915_READ(ILK_DISPLAY_CHICKEN2) |
6500 ILK_DPARB_GATE | ILK_VSDPFD_FULL);
6501 I915_WRITE(ILK_DSPCLK_GATE,
6502 I915_READ(ILK_DSPCLK_GATE) |
6503 ILK_DPARB_CLK_GATE |
6506 I915_WRITE(DSPACNTR,
6507 I915_READ(DSPACNTR) |
6508 DISPPLANE_TRICKLE_FEED_DISABLE);
6509 I915_WRITE(DSPBCNTR,
6510 I915_READ(DSPBCNTR) |
6511 DISPPLANE_TRICKLE_FEED_DISABLE);
6513 } else if (IS_G4X(dev)) {
6514 uint32_t dspclk_gate;
6515 I915_WRITE(RENCLK_GATE_D1, 0);
6516 I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
6517 GS_UNIT_CLOCK_GATE_DISABLE |
6518 CL_UNIT_CLOCK_GATE_DISABLE);
6519 I915_WRITE(RAMCLK_GATE_D, 0);
6520 dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
6521 OVRUNIT_CLOCK_GATE_DISABLE |
6522 OVCUNIT_CLOCK_GATE_DISABLE;
6524 dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
6525 I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
6526 } else if (IS_CRESTLINE(dev)) {
6527 I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
6528 I915_WRITE(RENCLK_GATE_D2, 0);
6529 I915_WRITE(DSPCLK_GATE_D, 0);
6530 I915_WRITE(RAMCLK_GATE_D, 0);
6531 I915_WRITE16(DEUC, 0);
6532 } else if (IS_BROADWATER(dev)) {
6533 I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
6534 I965_RCC_CLOCK_GATE_DISABLE |
6535 I965_RCPB_CLOCK_GATE_DISABLE |
6536 I965_ISC_CLOCK_GATE_DISABLE |
6537 I965_FBC_CLOCK_GATE_DISABLE);
6538 I915_WRITE(RENCLK_GATE_D2, 0);
6539 } else if (IS_GEN3(dev)) {
6540 u32 dstate = I915_READ(D_STATE);
6542 dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
6543 DSTATE_DOT_CLOCK_GATING;
6544 I915_WRITE(D_STATE, dstate);
6545 } else if (IS_I85X(dev) || IS_I865G(dev)) {
6546 I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
6547 } else if (IS_I830(dev)) {
6548 I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE);
6552 void intel_disable_clock_gating(struct drm_device *dev)
6554 struct drm_i915_private *dev_priv = dev->dev_private;
6556 if (dev_priv->renderctx) {
6557 struct drm_i915_gem_object *obj = dev_priv->renderctx;
6559 I915_WRITE(CCID, 0);
6562 i915_gem_object_unpin(obj);
6563 drm_gem_object_unreference(&obj->base);
6564 dev_priv->renderctx = NULL;
6567 if (dev_priv->pwrctx) {
6568 struct drm_i915_gem_object *obj = dev_priv->pwrctx;
6570 I915_WRITE(PWRCTXA, 0);
6571 POSTING_READ(PWRCTXA);
6573 i915_gem_object_unpin(obj);
6574 drm_gem_object_unreference(&obj->base);
6575 dev_priv->pwrctx = NULL;
6579 static void ironlake_disable_rc6(struct drm_device *dev)
6581 struct drm_i915_private *dev_priv = dev->dev_private;
6583 /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */
6584 I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT);
6585 wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON),
6588 I915_WRITE(PWRCTXA, 0);
6589 POSTING_READ(PWRCTXA);
6590 I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
6591 POSTING_READ(RSTDBYCTL);
6592 i915_gem_object_unpin(dev_priv->renderctx);
6593 drm_gem_object_unreference(&dev_priv->renderctx->base);
6594 dev_priv->renderctx = NULL;
6595 i915_gem_object_unpin(dev_priv->pwrctx);
6596 drm_gem_object_unreference(&dev_priv->pwrctx->base);
6597 dev_priv->pwrctx = NULL;
6600 void ironlake_enable_rc6(struct drm_device *dev)
6602 struct drm_i915_private *dev_priv = dev->dev_private;
6606 * GPU can automatically power down the render unit if given a page
6609 ret = BEGIN_LP_RING(6);
6611 ironlake_disable_rc6(dev);
6614 OUT_RING(MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN);
6615 OUT_RING(MI_SET_CONTEXT);
6616 OUT_RING(dev_priv->renderctx->gtt_offset |
6618 MI_SAVE_EXT_STATE_EN |
6619 MI_RESTORE_EXT_STATE_EN |
6620 MI_RESTORE_INHIBIT);
6621 OUT_RING(MI_SUSPEND_FLUSH);
6626 I915_WRITE(PWRCTXA, dev_priv->pwrctx->gtt_offset | PWRCTX_EN);
6627 I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
6630 /* Set up chip specific display functions */
6631 static void intel_init_display(struct drm_device *dev)
6633 struct drm_i915_private *dev_priv = dev->dev_private;
6635 /* We always want a DPMS function */
6636 if (HAS_PCH_SPLIT(dev))
6637 dev_priv->display.dpms = ironlake_crtc_dpms;
6639 dev_priv->display.dpms = i9xx_crtc_dpms;
6641 if (I915_HAS_FBC(dev)) {
6642 if (HAS_PCH_SPLIT(dev)) {
6643 dev_priv->display.fbc_enabled = ironlake_fbc_enabled;
6644 dev_priv->display.enable_fbc = ironlake_enable_fbc;
6645 dev_priv->display.disable_fbc = ironlake_disable_fbc;
6646 } else if (IS_GM45(dev)) {
6647 dev_priv->display.fbc_enabled = g4x_fbc_enabled;
6648 dev_priv->display.enable_fbc = g4x_enable_fbc;
6649 dev_priv->display.disable_fbc = g4x_disable_fbc;
6650 } else if (IS_CRESTLINE(dev)) {
6651 dev_priv->display.fbc_enabled = i8xx_fbc_enabled;
6652 dev_priv->display.enable_fbc = i8xx_enable_fbc;
6653 dev_priv->display.disable_fbc = i8xx_disable_fbc;
6655 /* 855GM needs testing */
6658 /* Returns the core display clock speed */
6659 if (IS_I945G(dev) || (IS_G33(dev) && ! IS_PINEVIEW_M(dev)))
6660 dev_priv->display.get_display_clock_speed =
6661 i945_get_display_clock_speed;
6662 else if (IS_I915G(dev))
6663 dev_priv->display.get_display_clock_speed =
6664 i915_get_display_clock_speed;
6665 else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
6666 dev_priv->display.get_display_clock_speed =
6667 i9xx_misc_get_display_clock_speed;
6668 else if (IS_I915GM(dev))
6669 dev_priv->display.get_display_clock_speed =
6670 i915gm_get_display_clock_speed;
6671 else if (IS_I865G(dev))
6672 dev_priv->display.get_display_clock_speed =
6673 i865_get_display_clock_speed;
6674 else if (IS_I85X(dev))
6675 dev_priv->display.get_display_clock_speed =
6676 i855_get_display_clock_speed;
6678 dev_priv->display.get_display_clock_speed =
6679 i830_get_display_clock_speed;
6681 /* For FIFO watermark updates */
6682 if (HAS_PCH_SPLIT(dev)) {
6684 if (I915_READ(MLTR_ILK) & ILK_SRLT_MASK)
6685 dev_priv->display.update_wm = ironlake_update_wm;
6687 DRM_DEBUG_KMS("Failed to get proper latency. "
6689 dev_priv->display.update_wm = NULL;
6691 } else if (IS_GEN6(dev)) {
6692 if (SNB_READ_WM0_LATENCY()) {
6693 dev_priv->display.update_wm = sandybridge_update_wm;
6695 DRM_DEBUG_KMS("Failed to read display plane latency. "
6697 dev_priv->display.update_wm = NULL;
6700 dev_priv->display.update_wm = NULL;
6701 } else if (IS_PINEVIEW(dev)) {
6702 if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev),
6705 dev_priv->mem_freq)) {
6706 DRM_INFO("failed to find known CxSR latency "
6707 "(found ddr%s fsb freq %d, mem freq %d), "
6709 (dev_priv->is_ddr3 == 1) ? "3": "2",
6710 dev_priv->fsb_freq, dev_priv->mem_freq);
6711 /* Disable CxSR and never update its watermark again */
6712 pineview_disable_cxsr(dev);
6713 dev_priv->display.update_wm = NULL;
6715 dev_priv->display.update_wm = pineview_update_wm;
6716 } else if (IS_G4X(dev))
6717 dev_priv->display.update_wm = g4x_update_wm;
6718 else if (IS_GEN4(dev))
6719 dev_priv->display.update_wm = i965_update_wm;
6720 else if (IS_GEN3(dev)) {
6721 dev_priv->display.update_wm = i9xx_update_wm;
6722 dev_priv->display.get_fifo_size = i9xx_get_fifo_size;
6723 } else if (IS_I85X(dev)) {
6724 dev_priv->display.update_wm = i9xx_update_wm;
6725 dev_priv->display.get_fifo_size = i85x_get_fifo_size;
6727 dev_priv->display.update_wm = i830_update_wm;
6729 dev_priv->display.get_fifo_size = i845_get_fifo_size;
6731 dev_priv->display.get_fifo_size = i830_get_fifo_size;
6736 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
6737 * resume, or other times. This quirk makes sure that's the case for
6740 static void quirk_pipea_force (struct drm_device *dev)
6742 struct drm_i915_private *dev_priv = dev->dev_private;
6744 dev_priv->quirks |= QUIRK_PIPEA_FORCE;
6745 DRM_DEBUG_DRIVER("applying pipe a force quirk\n");
6748 struct intel_quirk {
6750 int subsystem_vendor;
6751 int subsystem_device;
6752 void (*hook)(struct drm_device *dev);
6755 struct intel_quirk intel_quirks[] = {
6756 /* HP Compaq 2730p needs pipe A force quirk (LP: #291555) */
6757 { 0x2a42, 0x103c, 0x30eb, quirk_pipea_force },
6758 /* HP Mini needs pipe A force quirk (LP: #322104) */
6759 { 0x27ae,0x103c, 0x361a, quirk_pipea_force },
6761 /* Thinkpad R31 needs pipe A force quirk */
6762 { 0x3577, 0x1014, 0x0505, quirk_pipea_force },
6763 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
6764 { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
6766 /* ThinkPad X30 needs pipe A force quirk (LP: #304614) */
6767 { 0x3577, 0x1014, 0x0513, quirk_pipea_force },
6768 /* ThinkPad X40 needs pipe A force quirk */
6770 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
6771 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
6773 /* 855 & before need to leave pipe A & dpll A up */
6774 { 0x3582, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
6775 { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
6778 static void intel_init_quirks(struct drm_device *dev)
6780 struct pci_dev *d = dev->pdev;
6783 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
6784 struct intel_quirk *q = &intel_quirks[i];
6786 if (d->device == q->device &&
6787 (d->subsystem_vendor == q->subsystem_vendor ||
6788 q->subsystem_vendor == PCI_ANY_ID) &&
6789 (d->subsystem_device == q->subsystem_device ||
6790 q->subsystem_device == PCI_ANY_ID))
6795 /* Disable the VGA plane that we never use */
6796 static void i915_disable_vga(struct drm_device *dev)
6798 struct drm_i915_private *dev_priv = dev->dev_private;
6802 if (HAS_PCH_SPLIT(dev))
6803 vga_reg = CPU_VGACNTRL;
6807 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
6808 outb(1, VGA_SR_INDEX);
6809 sr1 = inb(VGA_SR_DATA);
6810 outb(sr1 | 1<<5, VGA_SR_DATA);
6811 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
6814 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
6815 POSTING_READ(vga_reg);
6818 void intel_modeset_init(struct drm_device *dev)
6820 struct drm_i915_private *dev_priv = dev->dev_private;
6823 drm_mode_config_init(dev);
6825 dev->mode_config.min_width = 0;
6826 dev->mode_config.min_height = 0;
6828 dev->mode_config.funcs = (void *)&intel_mode_funcs;
6830 intel_init_quirks(dev);
6832 intel_init_display(dev);
6835 dev->mode_config.max_width = 2048;
6836 dev->mode_config.max_height = 2048;
6837 } else if (IS_GEN3(dev)) {
6838 dev->mode_config.max_width = 4096;
6839 dev->mode_config.max_height = 4096;
6841 dev->mode_config.max_width = 8192;
6842 dev->mode_config.max_height = 8192;
6844 dev->mode_config.fb_base = dev->agp->base;
6846 if (IS_MOBILE(dev) || !IS_GEN2(dev))
6847 dev_priv->num_pipe = 2;
6849 dev_priv->num_pipe = 1;
6850 DRM_DEBUG_KMS("%d display pipe%s available.\n",
6851 dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
6853 for (i = 0; i < dev_priv->num_pipe; i++) {
6854 intel_crtc_init(dev, i);
6857 intel_setup_outputs(dev);
6859 intel_enable_clock_gating(dev);
6861 /* Just disable it once at startup */
6862 i915_disable_vga(dev);
6864 if (IS_IRONLAKE_M(dev)) {
6865 ironlake_enable_drps(dev);
6866 intel_init_emon(dev);
6870 gen6_enable_rps(dev_priv);
6872 if (IS_IRONLAKE_M(dev)) {
6873 dev_priv->renderctx = intel_alloc_context_page(dev);
6874 if (!dev_priv->renderctx)
6876 dev_priv->pwrctx = intel_alloc_context_page(dev);
6877 if (!dev_priv->pwrctx) {
6878 i915_gem_object_unpin(dev_priv->renderctx);
6879 drm_gem_object_unreference(&dev_priv->renderctx->base);
6880 dev_priv->renderctx = NULL;
6883 ironlake_enable_rc6(dev);
6887 INIT_WORK(&dev_priv->idle_work, intel_idle_update);
6888 setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer,
6889 (unsigned long)dev);
6891 intel_setup_overlay(dev);
6894 void intel_modeset_cleanup(struct drm_device *dev)
6896 struct drm_i915_private *dev_priv = dev->dev_private;
6897 struct drm_crtc *crtc;
6898 struct intel_crtc *intel_crtc;
6900 drm_kms_helper_poll_fini(dev);
6901 mutex_lock(&dev->struct_mutex);
6903 intel_unregister_dsm_handler();
6906 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
6907 /* Skip inactive CRTCs */
6911 intel_crtc = to_intel_crtc(crtc);
6912 intel_increase_pllclock(crtc);
6915 if (dev_priv->display.disable_fbc)
6916 dev_priv->display.disable_fbc(dev);
6918 if (IS_IRONLAKE_M(dev))
6919 ironlake_disable_drps(dev);
6921 gen6_disable_rps(dev);
6923 if (IS_IRONLAKE_M(dev))
6924 ironlake_disable_rc6(dev);
6926 mutex_unlock(&dev->struct_mutex);
6928 /* Disable the irq before mode object teardown, for the irq might
6929 * enqueue unpin/hotplug work. */
6930 drm_irq_uninstall(dev);
6931 cancel_work_sync(&dev_priv->hotplug_work);
6933 /* Shut off idle work before the crtcs get freed. */
6934 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
6935 intel_crtc = to_intel_crtc(crtc);
6936 del_timer_sync(&intel_crtc->idle_timer);
6938 del_timer_sync(&dev_priv->idle_timer);
6939 cancel_work_sync(&dev_priv->idle_work);
6941 drm_mode_config_cleanup(dev);
6945 * Return which encoder is currently attached for connector.
6947 struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
6949 return &intel_attached_encoder(connector)->base;
6952 void intel_connector_attach_encoder(struct intel_connector *connector,
6953 struct intel_encoder *encoder)
6955 connector->encoder = encoder;
6956 drm_mode_connector_attach_encoder(&connector->base,
6961 * set vga decode state - true == enable VGA decode
6963 int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
6965 struct drm_i915_private *dev_priv = dev->dev_private;
6968 pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
6970 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
6972 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
6973 pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
6977 #ifdef CONFIG_DEBUG_FS
6978 #include <linux/seq_file.h>
6980 struct intel_display_error_state {
6981 struct intel_cursor_error_state {
6988 struct intel_pipe_error_state {
7000 struct intel_plane_error_state {
7011 struct intel_display_error_state *
7012 intel_display_capture_error_state(struct drm_device *dev)
7014 drm_i915_private_t *dev_priv = dev->dev_private;
7015 struct intel_display_error_state *error;
7018 error = kmalloc(sizeof(*error), GFP_ATOMIC);
7022 for (i = 0; i < 2; i++) {
7023 error->cursor[i].control = I915_READ(CURCNTR(i));
7024 error->cursor[i].position = I915_READ(CURPOS(i));
7025 error->cursor[i].base = I915_READ(CURBASE(i));
7027 error->plane[i].control = I915_READ(DSPCNTR(i));
7028 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
7029 error->plane[i].size = I915_READ(DSPSIZE(i));
7030 error->plane[i].pos= I915_READ(DSPPOS(i));
7031 error->plane[i].addr = I915_READ(DSPADDR(i));
7032 if (INTEL_INFO(dev)->gen >= 4) {
7033 error->plane[i].surface = I915_READ(DSPSURF(i));
7034 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
7037 error->pipe[i].conf = I915_READ(PIPECONF(i));
7038 error->pipe[i].source = I915_READ(PIPESRC(i));
7039 error->pipe[i].htotal = I915_READ(HTOTAL(i));
7040 error->pipe[i].hblank = I915_READ(HBLANK(i));
7041 error->pipe[i].hsync = I915_READ(HSYNC(i));
7042 error->pipe[i].vtotal = I915_READ(VTOTAL(i));
7043 error->pipe[i].vblank = I915_READ(VBLANK(i));
7044 error->pipe[i].vsync = I915_READ(VSYNC(i));
7051 intel_display_print_error_state(struct seq_file *m,
7052 struct drm_device *dev,
7053 struct intel_display_error_state *error)
7057 for (i = 0; i < 2; i++) {
7058 seq_printf(m, "Pipe [%d]:\n", i);
7059 seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
7060 seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
7061 seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
7062 seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
7063 seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
7064 seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
7065 seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
7066 seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
7068 seq_printf(m, "Plane [%d]:\n", i);
7069 seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
7070 seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
7071 seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
7072 seq_printf(m, " POS: %08x\n", error->plane[i].pos);
7073 seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
7074 if (INTEL_INFO(dev)->gen >= 4) {
7075 seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
7076 seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
7079 seq_printf(m, "Cursor [%d]:\n", i);
7080 seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
7081 seq_printf(m, " POS: %08x\n", error->cursor[i].position);
7082 seq_printf(m, " BASE: %08x\n", error->cursor[i].base);