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/dmi.h>
28 #include <linux/module.h>
29 #include <linux/input.h>
30 #include <linux/i2c.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/vgaarb.h>
34 #include <drm/drm_edid.h>
36 #include "intel_drv.h"
37 #include <drm/i915_drm.h>
39 #include "i915_trace.h"
40 #include <drm/drm_dp_helper.h>
41 #include <drm/drm_crtc_helper.h>
42 #include <linux/dma_remapping.h>
44 bool intel_pipe_has_type(struct drm_crtc
*crtc
, int type
);
45 static void intel_increase_pllclock(struct drm_crtc
*crtc
);
46 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
, bool on
);
57 #define INTEL_P2_NUM 2
58 typedef struct intel_limit intel_limit_t
;
60 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
63 * find_pll() - Find the best values for the PLL
64 * @limit: limits for the PLL
66 * @target: target frequency in kHz
67 * @refclk: reference clock frequency in kHz
68 * @match_clock: if provided, @best_clock P divider must
69 * match the P divider from @match_clock
70 * used for LVDS downclocking
71 * @best_clock: best PLL values found
73 * Returns true on success, false on failure.
75 bool (*find_pll
)(const intel_limit_t
*limit
,
76 struct drm_crtc
*crtc
,
77 int target
, int refclk
,
78 intel_clock_t
*match_clock
,
79 intel_clock_t
*best_clock
);
83 #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
86 intel_pch_rawclk(struct drm_device
*dev
)
88 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
90 WARN_ON(!HAS_PCH_SPLIT(dev
));
92 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
96 intel_find_best_PLL(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
97 int target
, int refclk
, intel_clock_t
*match_clock
,
98 intel_clock_t
*best_clock
);
100 intel_g4x_find_best_PLL(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
101 int target
, int refclk
, intel_clock_t
*match_clock
,
102 intel_clock_t
*best_clock
);
105 intel_vlv_find_best_pll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
106 int target
, int refclk
, intel_clock_t
*match_clock
,
107 intel_clock_t
*best_clock
);
109 static inline u32
/* units of 100MHz */
110 intel_fdi_link_freq(struct drm_device
*dev
)
113 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
114 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
119 static const intel_limit_t intel_limits_i8xx_dvo
= {
120 .dot
= { .min
= 25000, .max
= 350000 },
121 .vco
= { .min
= 930000, .max
= 1400000 },
122 .n
= { .min
= 3, .max
= 16 },
123 .m
= { .min
= 96, .max
= 140 },
124 .m1
= { .min
= 18, .max
= 26 },
125 .m2
= { .min
= 6, .max
= 16 },
126 .p
= { .min
= 4, .max
= 128 },
127 .p1
= { .min
= 2, .max
= 33 },
128 .p2
= { .dot_limit
= 165000,
129 .p2_slow
= 4, .p2_fast
= 2 },
130 .find_pll
= intel_find_best_PLL
,
133 static const intel_limit_t intel_limits_i8xx_lvds
= {
134 .dot
= { .min
= 25000, .max
= 350000 },
135 .vco
= { .min
= 930000, .max
= 1400000 },
136 .n
= { .min
= 3, .max
= 16 },
137 .m
= { .min
= 96, .max
= 140 },
138 .m1
= { .min
= 18, .max
= 26 },
139 .m2
= { .min
= 6, .max
= 16 },
140 .p
= { .min
= 4, .max
= 128 },
141 .p1
= { .min
= 1, .max
= 6 },
142 .p2
= { .dot_limit
= 165000,
143 .p2_slow
= 14, .p2_fast
= 7 },
144 .find_pll
= intel_find_best_PLL
,
147 static const intel_limit_t intel_limits_i9xx_sdvo
= {
148 .dot
= { .min
= 20000, .max
= 400000 },
149 .vco
= { .min
= 1400000, .max
= 2800000 },
150 .n
= { .min
= 1, .max
= 6 },
151 .m
= { .min
= 70, .max
= 120 },
152 .m1
= { .min
= 8, .max
= 18 },
153 .m2
= { .min
= 3, .max
= 7 },
154 .p
= { .min
= 5, .max
= 80 },
155 .p1
= { .min
= 1, .max
= 8 },
156 .p2
= { .dot_limit
= 200000,
157 .p2_slow
= 10, .p2_fast
= 5 },
158 .find_pll
= intel_find_best_PLL
,
161 static const intel_limit_t intel_limits_i9xx_lvds
= {
162 .dot
= { .min
= 20000, .max
= 400000 },
163 .vco
= { .min
= 1400000, .max
= 2800000 },
164 .n
= { .min
= 1, .max
= 6 },
165 .m
= { .min
= 70, .max
= 120 },
166 .m1
= { .min
= 8, .max
= 18 },
167 .m2
= { .min
= 3, .max
= 7 },
168 .p
= { .min
= 7, .max
= 98 },
169 .p1
= { .min
= 1, .max
= 8 },
170 .p2
= { .dot_limit
= 112000,
171 .p2_slow
= 14, .p2_fast
= 7 },
172 .find_pll
= intel_find_best_PLL
,
176 static const intel_limit_t intel_limits_g4x_sdvo
= {
177 .dot
= { .min
= 25000, .max
= 270000 },
178 .vco
= { .min
= 1750000, .max
= 3500000},
179 .n
= { .min
= 1, .max
= 4 },
180 .m
= { .min
= 104, .max
= 138 },
181 .m1
= { .min
= 17, .max
= 23 },
182 .m2
= { .min
= 5, .max
= 11 },
183 .p
= { .min
= 10, .max
= 30 },
184 .p1
= { .min
= 1, .max
= 3},
185 .p2
= { .dot_limit
= 270000,
189 .find_pll
= intel_g4x_find_best_PLL
,
192 static const intel_limit_t intel_limits_g4x_hdmi
= {
193 .dot
= { .min
= 22000, .max
= 400000 },
194 .vco
= { .min
= 1750000, .max
= 3500000},
195 .n
= { .min
= 1, .max
= 4 },
196 .m
= { .min
= 104, .max
= 138 },
197 .m1
= { .min
= 16, .max
= 23 },
198 .m2
= { .min
= 5, .max
= 11 },
199 .p
= { .min
= 5, .max
= 80 },
200 .p1
= { .min
= 1, .max
= 8},
201 .p2
= { .dot_limit
= 165000,
202 .p2_slow
= 10, .p2_fast
= 5 },
203 .find_pll
= intel_g4x_find_best_PLL
,
206 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
207 .dot
= { .min
= 20000, .max
= 115000 },
208 .vco
= { .min
= 1750000, .max
= 3500000 },
209 .n
= { .min
= 1, .max
= 3 },
210 .m
= { .min
= 104, .max
= 138 },
211 .m1
= { .min
= 17, .max
= 23 },
212 .m2
= { .min
= 5, .max
= 11 },
213 .p
= { .min
= 28, .max
= 112 },
214 .p1
= { .min
= 2, .max
= 8 },
215 .p2
= { .dot_limit
= 0,
216 .p2_slow
= 14, .p2_fast
= 14
218 .find_pll
= intel_g4x_find_best_PLL
,
221 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
222 .dot
= { .min
= 80000, .max
= 224000 },
223 .vco
= { .min
= 1750000, .max
= 3500000 },
224 .n
= { .min
= 1, .max
= 3 },
225 .m
= { .min
= 104, .max
= 138 },
226 .m1
= { .min
= 17, .max
= 23 },
227 .m2
= { .min
= 5, .max
= 11 },
228 .p
= { .min
= 14, .max
= 42 },
229 .p1
= { .min
= 2, .max
= 6 },
230 .p2
= { .dot_limit
= 0,
231 .p2_slow
= 7, .p2_fast
= 7
233 .find_pll
= intel_g4x_find_best_PLL
,
236 static const intel_limit_t intel_limits_pineview_sdvo
= {
237 .dot
= { .min
= 20000, .max
= 400000},
238 .vco
= { .min
= 1700000, .max
= 3500000 },
239 /* Pineview's Ncounter is a ring counter */
240 .n
= { .min
= 3, .max
= 6 },
241 .m
= { .min
= 2, .max
= 256 },
242 /* Pineview only has one combined m divider, which we treat as m2. */
243 .m1
= { .min
= 0, .max
= 0 },
244 .m2
= { .min
= 0, .max
= 254 },
245 .p
= { .min
= 5, .max
= 80 },
246 .p1
= { .min
= 1, .max
= 8 },
247 .p2
= { .dot_limit
= 200000,
248 .p2_slow
= 10, .p2_fast
= 5 },
249 .find_pll
= intel_find_best_PLL
,
252 static const intel_limit_t intel_limits_pineview_lvds
= {
253 .dot
= { .min
= 20000, .max
= 400000 },
254 .vco
= { .min
= 1700000, .max
= 3500000 },
255 .n
= { .min
= 3, .max
= 6 },
256 .m
= { .min
= 2, .max
= 256 },
257 .m1
= { .min
= 0, .max
= 0 },
258 .m2
= { .min
= 0, .max
= 254 },
259 .p
= { .min
= 7, .max
= 112 },
260 .p1
= { .min
= 1, .max
= 8 },
261 .p2
= { .dot_limit
= 112000,
262 .p2_slow
= 14, .p2_fast
= 14 },
263 .find_pll
= intel_find_best_PLL
,
266 /* Ironlake / Sandybridge
268 * We calculate clock using (register_value + 2) for N/M1/M2, so here
269 * the range value for them is (actual_value - 2).
271 static const intel_limit_t intel_limits_ironlake_dac
= {
272 .dot
= { .min
= 25000, .max
= 350000 },
273 .vco
= { .min
= 1760000, .max
= 3510000 },
274 .n
= { .min
= 1, .max
= 5 },
275 .m
= { .min
= 79, .max
= 127 },
276 .m1
= { .min
= 12, .max
= 22 },
277 .m2
= { .min
= 5, .max
= 9 },
278 .p
= { .min
= 5, .max
= 80 },
279 .p1
= { .min
= 1, .max
= 8 },
280 .p2
= { .dot_limit
= 225000,
281 .p2_slow
= 10, .p2_fast
= 5 },
282 .find_pll
= intel_g4x_find_best_PLL
,
285 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
286 .dot
= { .min
= 25000, .max
= 350000 },
287 .vco
= { .min
= 1760000, .max
= 3510000 },
288 .n
= { .min
= 1, .max
= 3 },
289 .m
= { .min
= 79, .max
= 118 },
290 .m1
= { .min
= 12, .max
= 22 },
291 .m2
= { .min
= 5, .max
= 9 },
292 .p
= { .min
= 28, .max
= 112 },
293 .p1
= { .min
= 2, .max
= 8 },
294 .p2
= { .dot_limit
= 225000,
295 .p2_slow
= 14, .p2_fast
= 14 },
296 .find_pll
= intel_g4x_find_best_PLL
,
299 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
300 .dot
= { .min
= 25000, .max
= 350000 },
301 .vco
= { .min
= 1760000, .max
= 3510000 },
302 .n
= { .min
= 1, .max
= 3 },
303 .m
= { .min
= 79, .max
= 127 },
304 .m1
= { .min
= 12, .max
= 22 },
305 .m2
= { .min
= 5, .max
= 9 },
306 .p
= { .min
= 14, .max
= 56 },
307 .p1
= { .min
= 2, .max
= 8 },
308 .p2
= { .dot_limit
= 225000,
309 .p2_slow
= 7, .p2_fast
= 7 },
310 .find_pll
= intel_g4x_find_best_PLL
,
313 /* LVDS 100mhz refclk limits. */
314 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
315 .dot
= { .min
= 25000, .max
= 350000 },
316 .vco
= { .min
= 1760000, .max
= 3510000 },
317 .n
= { .min
= 1, .max
= 2 },
318 .m
= { .min
= 79, .max
= 126 },
319 .m1
= { .min
= 12, .max
= 22 },
320 .m2
= { .min
= 5, .max
= 9 },
321 .p
= { .min
= 28, .max
= 112 },
322 .p1
= { .min
= 2, .max
= 8 },
323 .p2
= { .dot_limit
= 225000,
324 .p2_slow
= 14, .p2_fast
= 14 },
325 .find_pll
= intel_g4x_find_best_PLL
,
328 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
329 .dot
= { .min
= 25000, .max
= 350000 },
330 .vco
= { .min
= 1760000, .max
= 3510000 },
331 .n
= { .min
= 1, .max
= 3 },
332 .m
= { .min
= 79, .max
= 126 },
333 .m1
= { .min
= 12, .max
= 22 },
334 .m2
= { .min
= 5, .max
= 9 },
335 .p
= { .min
= 14, .max
= 42 },
336 .p1
= { .min
= 2, .max
= 6 },
337 .p2
= { .dot_limit
= 225000,
338 .p2_slow
= 7, .p2_fast
= 7 },
339 .find_pll
= intel_g4x_find_best_PLL
,
342 static const intel_limit_t intel_limits_vlv_dac
= {
343 .dot
= { .min
= 25000, .max
= 270000 },
344 .vco
= { .min
= 4000000, .max
= 6000000 },
345 .n
= { .min
= 1, .max
= 7 },
346 .m
= { .min
= 22, .max
= 450 }, /* guess */
347 .m1
= { .min
= 2, .max
= 3 },
348 .m2
= { .min
= 11, .max
= 156 },
349 .p
= { .min
= 10, .max
= 30 },
350 .p1
= { .min
= 1, .max
= 3 },
351 .p2
= { .dot_limit
= 270000,
352 .p2_slow
= 2, .p2_fast
= 20 },
353 .find_pll
= intel_vlv_find_best_pll
,
356 static const intel_limit_t intel_limits_vlv_hdmi
= {
357 .dot
= { .min
= 25000, .max
= 270000 },
358 .vco
= { .min
= 4000000, .max
= 6000000 },
359 .n
= { .min
= 1, .max
= 7 },
360 .m
= { .min
= 60, .max
= 300 }, /* guess */
361 .m1
= { .min
= 2, .max
= 3 },
362 .m2
= { .min
= 11, .max
= 156 },
363 .p
= { .min
= 10, .max
= 30 },
364 .p1
= { .min
= 2, .max
= 3 },
365 .p2
= { .dot_limit
= 270000,
366 .p2_slow
= 2, .p2_fast
= 20 },
367 .find_pll
= intel_vlv_find_best_pll
,
370 static const intel_limit_t intel_limits_vlv_dp
= {
371 .dot
= { .min
= 25000, .max
= 270000 },
372 .vco
= { .min
= 4000000, .max
= 6000000 },
373 .n
= { .min
= 1, .max
= 7 },
374 .m
= { .min
= 22, .max
= 450 },
375 .m1
= { .min
= 2, .max
= 3 },
376 .m2
= { .min
= 11, .max
= 156 },
377 .p
= { .min
= 10, .max
= 30 },
378 .p1
= { .min
= 1, .max
= 3 },
379 .p2
= { .dot_limit
= 270000,
380 .p2_slow
= 2, .p2_fast
= 20 },
381 .find_pll
= intel_vlv_find_best_pll
,
384 u32
intel_dpio_read(struct drm_i915_private
*dev_priv
, int reg
)
386 WARN_ON(!mutex_is_locked(&dev_priv
->dpio_lock
));
388 if (wait_for_atomic_us((I915_READ(DPIO_PKT
) & DPIO_BUSY
) == 0, 100)) {
389 DRM_ERROR("DPIO idle wait timed out\n");
393 I915_WRITE(DPIO_REG
, reg
);
394 I915_WRITE(DPIO_PKT
, DPIO_RID
| DPIO_OP_READ
| DPIO_PORTID
|
396 if (wait_for_atomic_us((I915_READ(DPIO_PKT
) & DPIO_BUSY
) == 0, 100)) {
397 DRM_ERROR("DPIO read wait timed out\n");
401 return I915_READ(DPIO_DATA
);
404 void intel_dpio_write(struct drm_i915_private
*dev_priv
, int reg
, u32 val
)
406 WARN_ON(!mutex_is_locked(&dev_priv
->dpio_lock
));
408 if (wait_for_atomic_us((I915_READ(DPIO_PKT
) & DPIO_BUSY
) == 0, 100)) {
409 DRM_ERROR("DPIO idle wait timed out\n");
413 I915_WRITE(DPIO_DATA
, val
);
414 I915_WRITE(DPIO_REG
, reg
);
415 I915_WRITE(DPIO_PKT
, DPIO_RID
| DPIO_OP_WRITE
| DPIO_PORTID
|
417 if (wait_for_atomic_us((I915_READ(DPIO_PKT
) & DPIO_BUSY
) == 0, 100))
418 DRM_ERROR("DPIO write wait timed out\n");
421 static const intel_limit_t
*intel_ironlake_limit(struct drm_crtc
*crtc
,
424 struct drm_device
*dev
= crtc
->dev
;
425 const intel_limit_t
*limit
;
427 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
428 if (intel_is_dual_link_lvds(dev
)) {
429 if (refclk
== 100000)
430 limit
= &intel_limits_ironlake_dual_lvds_100m
;
432 limit
= &intel_limits_ironlake_dual_lvds
;
434 if (refclk
== 100000)
435 limit
= &intel_limits_ironlake_single_lvds_100m
;
437 limit
= &intel_limits_ironlake_single_lvds
;
440 limit
= &intel_limits_ironlake_dac
;
445 static const intel_limit_t
*intel_g4x_limit(struct drm_crtc
*crtc
)
447 struct drm_device
*dev
= crtc
->dev
;
448 const intel_limit_t
*limit
;
450 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
451 if (intel_is_dual_link_lvds(dev
))
452 limit
= &intel_limits_g4x_dual_channel_lvds
;
454 limit
= &intel_limits_g4x_single_channel_lvds
;
455 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
) ||
456 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
457 limit
= &intel_limits_g4x_hdmi
;
458 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
)) {
459 limit
= &intel_limits_g4x_sdvo
;
460 } else /* The option is for other outputs */
461 limit
= &intel_limits_i9xx_sdvo
;
466 static const intel_limit_t
*intel_limit(struct drm_crtc
*crtc
, int refclk
)
468 struct drm_device
*dev
= crtc
->dev
;
469 const intel_limit_t
*limit
;
471 if (HAS_PCH_SPLIT(dev
))
472 limit
= intel_ironlake_limit(crtc
, refclk
);
473 else if (IS_G4X(dev
)) {
474 limit
= intel_g4x_limit(crtc
);
475 } else if (IS_PINEVIEW(dev
)) {
476 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
477 limit
= &intel_limits_pineview_lvds
;
479 limit
= &intel_limits_pineview_sdvo
;
480 } else if (IS_VALLEYVIEW(dev
)) {
481 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
))
482 limit
= &intel_limits_vlv_dac
;
483 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
))
484 limit
= &intel_limits_vlv_hdmi
;
486 limit
= &intel_limits_vlv_dp
;
487 } else if (!IS_GEN2(dev
)) {
488 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
489 limit
= &intel_limits_i9xx_lvds
;
491 limit
= &intel_limits_i9xx_sdvo
;
493 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
494 limit
= &intel_limits_i8xx_lvds
;
496 limit
= &intel_limits_i8xx_dvo
;
501 /* m1 is reserved as 0 in Pineview, n is a ring counter */
502 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
504 clock
->m
= clock
->m2
+ 2;
505 clock
->p
= clock
->p1
* clock
->p2
;
506 clock
->vco
= refclk
* clock
->m
/ clock
->n
;
507 clock
->dot
= clock
->vco
/ clock
->p
;
510 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
512 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
515 static void intel_clock(struct drm_device
*dev
, int refclk
, intel_clock_t
*clock
)
517 if (IS_PINEVIEW(dev
)) {
518 pineview_clock(refclk
, clock
);
521 clock
->m
= i9xx_dpll_compute_m(clock
);
522 clock
->p
= clock
->p1
* clock
->p2
;
523 clock
->vco
= refclk
* clock
->m
/ (clock
->n
+ 2);
524 clock
->dot
= clock
->vco
/ clock
->p
;
528 * Returns whether any output on the specified pipe is of the specified type
530 bool intel_pipe_has_type(struct drm_crtc
*crtc
, int type
)
532 struct drm_device
*dev
= crtc
->dev
;
533 struct intel_encoder
*encoder
;
535 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
536 if (encoder
->type
== type
)
542 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
544 * Returns whether the given set of divisors are valid for a given refclk with
545 * the given connectors.
548 static bool intel_PLL_is_valid(struct drm_device
*dev
,
549 const intel_limit_t
*limit
,
550 const intel_clock_t
*clock
)
552 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
553 INTELPllInvalid("p1 out of range\n");
554 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
555 INTELPllInvalid("p out of range\n");
556 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
557 INTELPllInvalid("m2 out of range\n");
558 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
559 INTELPllInvalid("m1 out of range\n");
560 if (clock
->m1
<= clock
->m2
&& !IS_PINEVIEW(dev
))
561 INTELPllInvalid("m1 <= m2\n");
562 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
563 INTELPllInvalid("m out of range\n");
564 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
565 INTELPllInvalid("n out of range\n");
566 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
567 INTELPllInvalid("vco out of range\n");
568 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
569 * connector, etc., rather than just a single range.
571 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
572 INTELPllInvalid("dot out of range\n");
578 intel_find_best_PLL(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
579 int target
, int refclk
, intel_clock_t
*match_clock
,
580 intel_clock_t
*best_clock
)
583 struct drm_device
*dev
= crtc
->dev
;
587 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
589 * For LVDS just rely on its current settings for dual-channel.
590 * We haven't figured out how to reliably set up different
591 * single/dual channel state, if we even can.
593 if (intel_is_dual_link_lvds(dev
))
594 clock
.p2
= limit
->p2
.p2_fast
;
596 clock
.p2
= limit
->p2
.p2_slow
;
598 if (target
< limit
->p2
.dot_limit
)
599 clock
.p2
= limit
->p2
.p2_slow
;
601 clock
.p2
= limit
->p2
.p2_fast
;
604 memset(best_clock
, 0, sizeof(*best_clock
));
606 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
608 for (clock
.m2
= limit
->m2
.min
;
609 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
610 /* m1 is always 0 in Pineview */
611 if (clock
.m2
>= clock
.m1
&& !IS_PINEVIEW(dev
))
613 for (clock
.n
= limit
->n
.min
;
614 clock
.n
<= limit
->n
.max
; clock
.n
++) {
615 for (clock
.p1
= limit
->p1
.min
;
616 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
619 intel_clock(dev
, refclk
, &clock
);
620 if (!intel_PLL_is_valid(dev
, limit
,
624 clock
.p
!= match_clock
->p
)
627 this_err
= abs(clock
.dot
- target
);
628 if (this_err
< err
) {
637 return (err
!= target
);
641 intel_g4x_find_best_PLL(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
642 int target
, int refclk
, intel_clock_t
*match_clock
,
643 intel_clock_t
*best_clock
)
645 struct drm_device
*dev
= crtc
->dev
;
649 /* approximately equals target * 0.00585 */
650 int err_most
= (target
>> 8) + (target
>> 9);
653 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
656 if (HAS_PCH_SPLIT(dev
))
660 if (intel_is_dual_link_lvds(dev
))
661 clock
.p2
= limit
->p2
.p2_fast
;
663 clock
.p2
= limit
->p2
.p2_slow
;
665 if (target
< limit
->p2
.dot_limit
)
666 clock
.p2
= limit
->p2
.p2_slow
;
668 clock
.p2
= limit
->p2
.p2_fast
;
671 memset(best_clock
, 0, sizeof(*best_clock
));
672 max_n
= limit
->n
.max
;
673 /* based on hardware requirement, prefer smaller n to precision */
674 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
675 /* based on hardware requirement, prefere larger m1,m2 */
676 for (clock
.m1
= limit
->m1
.max
;
677 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
678 for (clock
.m2
= limit
->m2
.max
;
679 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
680 for (clock
.p1
= limit
->p1
.max
;
681 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
684 intel_clock(dev
, refclk
, &clock
);
685 if (!intel_PLL_is_valid(dev
, limit
,
689 clock
.p
!= match_clock
->p
)
692 this_err
= abs(clock
.dot
- target
);
693 if (this_err
< err_most
) {
707 intel_vlv_find_best_pll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
708 int target
, int refclk
, intel_clock_t
*match_clock
,
709 intel_clock_t
*best_clock
)
711 u32 p1
, p2
, m1
, m2
, vco
, bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
713 u32 updrate
, minupdate
, fracbits
, p
;
714 unsigned long bestppm
, ppm
, absppm
;
718 dotclk
= target
* 1000;
721 fastclk
= dotclk
/ (2*100);
725 n
= p
= p1
= p2
= m
= m1
= m2
= vco
= bestn
= 0;
726 bestm1
= bestm2
= bestp1
= bestp2
= 0;
728 /* based on hardware requirement, prefer smaller n to precision */
729 for (n
= limit
->n
.min
; n
<= ((refclk
) / minupdate
); n
++) {
730 updrate
= refclk
/ n
;
731 for (p1
= limit
->p1
.max
; p1
> limit
->p1
.min
; p1
--) {
732 for (p2
= limit
->p2
.p2_fast
+1; p2
> 0; p2
--) {
736 /* based on hardware requirement, prefer bigger m1,m2 values */
737 for (m1
= limit
->m1
.min
; m1
<= limit
->m1
.max
; m1
++) {
738 m2
= (((2*(fastclk
* p
* n
/ m1
)) +
739 refclk
) / (2*refclk
));
742 if (vco
>= limit
->vco
.min
&& vco
< limit
->vco
.max
) {
743 ppm
= 1000000 * ((vco
/ p
) - fastclk
) / fastclk
;
744 absppm
= (ppm
> 0) ? ppm
: (-ppm
);
745 if (absppm
< 100 && ((p1
* p2
) > (bestp1
* bestp2
))) {
749 if (absppm
< bestppm
- 10) {
766 best_clock
->n
= bestn
;
767 best_clock
->m1
= bestm1
;
768 best_clock
->m2
= bestm2
;
769 best_clock
->p1
= bestp1
;
770 best_clock
->p2
= bestp2
;
775 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
778 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
779 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
781 return intel_crtc
->config
.cpu_transcoder
;
784 static void ironlake_wait_for_vblank(struct drm_device
*dev
, int pipe
)
786 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
787 u32 frame
, frame_reg
= PIPEFRAME(pipe
);
789 frame
= I915_READ(frame_reg
);
791 if (wait_for(I915_READ_NOTRACE(frame_reg
) != frame
, 50))
792 DRM_DEBUG_KMS("vblank wait timed out\n");
796 * intel_wait_for_vblank - wait for vblank on a given pipe
798 * @pipe: pipe to wait for
800 * Wait for vblank to occur on a given pipe. Needed for various bits of
803 void intel_wait_for_vblank(struct drm_device
*dev
, int pipe
)
805 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
806 int pipestat_reg
= PIPESTAT(pipe
);
808 if (INTEL_INFO(dev
)->gen
>= 5) {
809 ironlake_wait_for_vblank(dev
, pipe
);
813 /* Clear existing vblank status. Note this will clear any other
814 * sticky status fields as well.
816 * This races with i915_driver_irq_handler() with the result
817 * that either function could miss a vblank event. Here it is not
818 * fatal, as we will either wait upon the next vblank interrupt or
819 * timeout. Generally speaking intel_wait_for_vblank() is only
820 * called during modeset at which time the GPU should be idle and
821 * should *not* be performing page flips and thus not waiting on
823 * Currently, the result of us stealing a vblank from the irq
824 * handler is that a single frame will be skipped during swapbuffers.
826 I915_WRITE(pipestat_reg
,
827 I915_READ(pipestat_reg
) | PIPE_VBLANK_INTERRUPT_STATUS
);
829 /* Wait for vblank interrupt bit to set */
830 if (wait_for(I915_READ(pipestat_reg
) &
831 PIPE_VBLANK_INTERRUPT_STATUS
,
833 DRM_DEBUG_KMS("vblank wait timed out\n");
837 * intel_wait_for_pipe_off - wait for pipe to turn off
839 * @pipe: pipe to wait for
841 * After disabling a pipe, we can't wait for vblank in the usual way,
842 * spinning on the vblank interrupt status bit, since we won't actually
843 * see an interrupt when the pipe is disabled.
846 * wait for the pipe register state bit to turn off
849 * wait for the display line value to settle (it usually
850 * ends up stopping at the start of the next frame).
853 void intel_wait_for_pipe_off(struct drm_device
*dev
, int pipe
)
855 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
856 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
859 if (INTEL_INFO(dev
)->gen
>= 4) {
860 int reg
= PIPECONF(cpu_transcoder
);
862 /* Wait for the Pipe State to go off */
863 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
865 WARN(1, "pipe_off wait timed out\n");
867 u32 last_line
, line_mask
;
868 int reg
= PIPEDSL(pipe
);
869 unsigned long timeout
= jiffies
+ msecs_to_jiffies(100);
872 line_mask
= DSL_LINEMASK_GEN2
;
874 line_mask
= DSL_LINEMASK_GEN3
;
876 /* Wait for the display line to settle */
878 last_line
= I915_READ(reg
) & line_mask
;
880 } while (((I915_READ(reg
) & line_mask
) != last_line
) &&
881 time_after(timeout
, jiffies
));
882 if (time_after(jiffies
, timeout
))
883 WARN(1, "pipe_off wait timed out\n");
888 * ibx_digital_port_connected - is the specified port connected?
889 * @dev_priv: i915 private structure
890 * @port: the port to test
892 * Returns true if @port is connected, false otherwise.
894 bool ibx_digital_port_connected(struct drm_i915_private
*dev_priv
,
895 struct intel_digital_port
*port
)
899 if (HAS_PCH_IBX(dev_priv
->dev
)) {
902 bit
= SDE_PORTB_HOTPLUG
;
905 bit
= SDE_PORTC_HOTPLUG
;
908 bit
= SDE_PORTD_HOTPLUG
;
916 bit
= SDE_PORTB_HOTPLUG_CPT
;
919 bit
= SDE_PORTC_HOTPLUG_CPT
;
922 bit
= SDE_PORTD_HOTPLUG_CPT
;
929 return I915_READ(SDEISR
) & bit
;
932 static const char *state_string(bool enabled
)
934 return enabled
? "on" : "off";
937 /* Only for pre-ILK configs */
938 static void assert_pll(struct drm_i915_private
*dev_priv
,
939 enum pipe pipe
, bool state
)
946 val
= I915_READ(reg
);
947 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
948 WARN(cur_state
!= state
,
949 "PLL state assertion failure (expected %s, current %s)\n",
950 state_string(state
), state_string(cur_state
));
952 #define assert_pll_enabled(d, p) assert_pll(d, p, true)
953 #define assert_pll_disabled(d, p) assert_pll(d, p, false)
956 static void assert_pch_pll(struct drm_i915_private
*dev_priv
,
957 struct intel_pch_pll
*pll
,
958 struct intel_crtc
*crtc
,
964 if (HAS_PCH_LPT(dev_priv
->dev
)) {
965 DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
970 "asserting PCH PLL %s with no PLL\n", state_string(state
)))
973 val
= I915_READ(pll
->pll_reg
);
974 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
975 WARN(cur_state
!= state
,
976 "PCH PLL state for reg %x assertion failure (expected %s, current %s), val=%08x\n",
977 pll
->pll_reg
, state_string(state
), state_string(cur_state
), val
);
979 /* Make sure the selected PLL is correctly attached to the transcoder */
980 if (crtc
&& HAS_PCH_CPT(dev_priv
->dev
)) {
983 pch_dpll
= I915_READ(PCH_DPLL_SEL
);
984 cur_state
= pll
->pll_reg
== _PCH_DPLL_B
;
985 if (!WARN(((pch_dpll
>> (4 * crtc
->pipe
)) & 1) != cur_state
,
986 "PLL[%d] not attached to this transcoder %c: %08x\n",
987 cur_state
, pipe_name(crtc
->pipe
), pch_dpll
)) {
988 cur_state
= !!(val
>> (4*crtc
->pipe
+ 3));
989 WARN(cur_state
!= state
,
990 "PLL[%d] not %s on this transcoder %c: %08x\n",
991 pll
->pll_reg
== _PCH_DPLL_B
,
993 pipe_name(crtc
->pipe
),
998 #define assert_pch_pll_enabled(d, p, c) assert_pch_pll(d, p, c, true)
999 #define assert_pch_pll_disabled(d, p, c) assert_pch_pll(d, p, c, false)
1001 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1002 enum pipe pipe
, bool state
)
1007 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1010 if (HAS_DDI(dev_priv
->dev
)) {
1011 /* DDI does not have a specific FDI_TX register */
1012 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1013 val
= I915_READ(reg
);
1014 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1016 reg
= FDI_TX_CTL(pipe
);
1017 val
= I915_READ(reg
);
1018 cur_state
= !!(val
& FDI_TX_ENABLE
);
1020 WARN(cur_state
!= state
,
1021 "FDI TX state assertion failure (expected %s, current %s)\n",
1022 state_string(state
), state_string(cur_state
));
1024 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1025 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1027 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1028 enum pipe pipe
, bool state
)
1034 reg
= FDI_RX_CTL(pipe
);
1035 val
= I915_READ(reg
);
1036 cur_state
= !!(val
& FDI_RX_ENABLE
);
1037 WARN(cur_state
!= state
,
1038 "FDI RX state assertion failure (expected %s, current %s)\n",
1039 state_string(state
), state_string(cur_state
));
1041 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1042 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1044 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1050 /* ILK FDI PLL is always enabled */
1051 if (dev_priv
->info
->gen
== 5)
1054 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1055 if (HAS_DDI(dev_priv
->dev
))
1058 reg
= FDI_TX_CTL(pipe
);
1059 val
= I915_READ(reg
);
1060 WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1063 static void assert_fdi_rx_pll_enabled(struct drm_i915_private
*dev_priv
,
1069 reg
= FDI_RX_CTL(pipe
);
1070 val
= I915_READ(reg
);
1071 WARN(!(val
& FDI_RX_PLL_ENABLE
), "FDI RX PLL assertion failure, should be active but is disabled\n");
1074 static void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1077 int pp_reg
, lvds_reg
;
1079 enum pipe panel_pipe
= PIPE_A
;
1082 if (HAS_PCH_SPLIT(dev_priv
->dev
)) {
1083 pp_reg
= PCH_PP_CONTROL
;
1084 lvds_reg
= PCH_LVDS
;
1086 pp_reg
= PP_CONTROL
;
1090 val
= I915_READ(pp_reg
);
1091 if (!(val
& PANEL_POWER_ON
) ||
1092 ((val
& PANEL_UNLOCK_REGS
) == PANEL_UNLOCK_REGS
))
1095 if (I915_READ(lvds_reg
) & LVDS_PIPEB_SELECT
)
1096 panel_pipe
= PIPE_B
;
1098 WARN(panel_pipe
== pipe
&& locked
,
1099 "panel assertion failure, pipe %c regs locked\n",
1103 void assert_pipe(struct drm_i915_private
*dev_priv
,
1104 enum pipe pipe
, bool state
)
1109 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1112 /* if we need the pipe A quirk it must be always on */
1113 if (pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
)
1116 if (!intel_using_power_well(dev_priv
->dev
) &&
1117 cpu_transcoder
!= TRANSCODER_EDP
) {
1120 reg
= PIPECONF(cpu_transcoder
);
1121 val
= I915_READ(reg
);
1122 cur_state
= !!(val
& PIPECONF_ENABLE
);
1125 WARN(cur_state
!= state
,
1126 "pipe %c assertion failure (expected %s, current %s)\n",
1127 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1130 static void assert_plane(struct drm_i915_private
*dev_priv
,
1131 enum plane plane
, bool state
)
1137 reg
= DSPCNTR(plane
);
1138 val
= I915_READ(reg
);
1139 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1140 WARN(cur_state
!= state
,
1141 "plane %c assertion failure (expected %s, current %s)\n",
1142 plane_name(plane
), state_string(state
), state_string(cur_state
));
1145 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1146 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1148 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1155 /* Planes are fixed to pipes on ILK+ */
1156 if (HAS_PCH_SPLIT(dev_priv
->dev
) || IS_VALLEYVIEW(dev_priv
->dev
)) {
1157 reg
= DSPCNTR(pipe
);
1158 val
= I915_READ(reg
);
1159 WARN((val
& DISPLAY_PLANE_ENABLE
),
1160 "plane %c assertion failure, should be disabled but not\n",
1165 /* Need to check both planes against the pipe */
1166 for (i
= 0; i
< 2; i
++) {
1168 val
= I915_READ(reg
);
1169 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1170 DISPPLANE_SEL_PIPE_SHIFT
;
1171 WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1172 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1173 plane_name(i
), pipe_name(pipe
));
1177 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1183 if (!IS_VALLEYVIEW(dev_priv
->dev
))
1186 /* Need to check both planes against the pipe */
1187 for (i
= 0; i
< dev_priv
->num_plane
; i
++) {
1188 reg
= SPCNTR(pipe
, i
);
1189 val
= I915_READ(reg
);
1190 WARN((val
& SP_ENABLE
),
1191 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1192 sprite_name(pipe
, i
), pipe_name(pipe
));
1196 static void assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1201 if (HAS_PCH_LPT(dev_priv
->dev
)) {
1202 DRM_DEBUG_DRIVER("LPT does not has PCH refclk, skipping check\n");
1206 val
= I915_READ(PCH_DREF_CONTROL
);
1207 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1208 DREF_SUPERSPREAD_SOURCE_MASK
));
1209 WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1212 static void assert_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1219 reg
= TRANSCONF(pipe
);
1220 val
= I915_READ(reg
);
1221 enabled
= !!(val
& TRANS_ENABLE
);
1223 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1227 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1228 enum pipe pipe
, u32 port_sel
, u32 val
)
1230 if ((val
& DP_PORT_EN
) == 0)
1233 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1234 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1235 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1236 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1239 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1245 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1246 enum pipe pipe
, u32 val
)
1248 if ((val
& SDVO_ENABLE
) == 0)
1251 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1252 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1255 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1261 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1262 enum pipe pipe
, u32 val
)
1264 if ((val
& LVDS_PORT_EN
) == 0)
1267 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1268 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1271 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1277 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1278 enum pipe pipe
, u32 val
)
1280 if ((val
& ADPA_DAC_ENABLE
) == 0)
1282 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1283 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1286 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1292 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1293 enum pipe pipe
, int reg
, u32 port_sel
)
1295 u32 val
= I915_READ(reg
);
1296 WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1297 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1298 reg
, pipe_name(pipe
));
1300 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1301 && (val
& DP_PIPEB_SELECT
),
1302 "IBX PCH dp port still using transcoder B\n");
1305 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1306 enum pipe pipe
, int reg
)
1308 u32 val
= I915_READ(reg
);
1309 WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1310 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1311 reg
, pipe_name(pipe
));
1313 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& SDVO_ENABLE
) == 0
1314 && (val
& SDVO_PIPE_B_SELECT
),
1315 "IBX PCH hdmi port still using transcoder B\n");
1318 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1324 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1325 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1326 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1329 val
= I915_READ(reg
);
1330 WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1331 "PCH VGA enabled on transcoder %c, should be disabled\n",
1335 val
= I915_READ(reg
);
1336 WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1337 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1340 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1341 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1342 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1346 * intel_enable_pll - enable a PLL
1347 * @dev_priv: i915 private structure
1348 * @pipe: pipe PLL to enable
1350 * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to
1351 * make sure the PLL reg is writable first though, since the panel write
1352 * protect mechanism may be enabled.
1354 * Note! This is for pre-ILK only.
1356 * Unfortunately needed by dvo_ns2501 since the dvo depends on it running.
1358 static void intel_enable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1363 assert_pipe_disabled(dev_priv
, pipe
);
1365 /* No really, not for ILK+ */
1366 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
) && dev_priv
->info
->gen
>= 5);
1368 /* PLL is protected by panel, make sure we can write it */
1369 if (IS_MOBILE(dev_priv
->dev
) && !IS_I830(dev_priv
->dev
))
1370 assert_panel_unlocked(dev_priv
, pipe
);
1373 val
= I915_READ(reg
);
1374 val
|= DPLL_VCO_ENABLE
;
1376 /* We do this three times for luck */
1377 I915_WRITE(reg
, val
);
1379 udelay(150); /* wait for warmup */
1380 I915_WRITE(reg
, val
);
1382 udelay(150); /* wait for warmup */
1383 I915_WRITE(reg
, val
);
1385 udelay(150); /* wait for warmup */
1389 * intel_disable_pll - disable a PLL
1390 * @dev_priv: i915 private structure
1391 * @pipe: pipe PLL to disable
1393 * Disable the PLL for @pipe, making sure the pipe is off first.
1395 * Note! This is for pre-ILK only.
1397 static void intel_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1402 /* Don't disable pipe A or pipe A PLLs if needed */
1403 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
1406 /* Make sure the pipe isn't still relying on us */
1407 assert_pipe_disabled(dev_priv
, pipe
);
1410 val
= I915_READ(reg
);
1411 val
&= ~DPLL_VCO_ENABLE
;
1412 I915_WRITE(reg
, val
);
1418 intel_sbi_write(struct drm_i915_private
*dev_priv
, u16 reg
, u32 value
,
1419 enum intel_sbi_destination destination
)
1423 WARN_ON(!mutex_is_locked(&dev_priv
->dpio_lock
));
1425 if (wait_for((I915_READ(SBI_CTL_STAT
) & SBI_BUSY
) == 0,
1427 DRM_ERROR("timeout waiting for SBI to become ready\n");
1431 I915_WRITE(SBI_ADDR
, (reg
<< 16));
1432 I915_WRITE(SBI_DATA
, value
);
1434 if (destination
== SBI_ICLK
)
1435 tmp
= SBI_CTL_DEST_ICLK
| SBI_CTL_OP_CRWR
;
1437 tmp
= SBI_CTL_DEST_MPHY
| SBI_CTL_OP_IOWR
;
1438 I915_WRITE(SBI_CTL_STAT
, SBI_BUSY
| tmp
);
1440 if (wait_for((I915_READ(SBI_CTL_STAT
) & (SBI_BUSY
| SBI_RESPONSE_FAIL
)) == 0,
1442 DRM_ERROR("timeout waiting for SBI to complete write transaction\n");
1448 intel_sbi_read(struct drm_i915_private
*dev_priv
, u16 reg
,
1449 enum intel_sbi_destination destination
)
1452 WARN_ON(!mutex_is_locked(&dev_priv
->dpio_lock
));
1454 if (wait_for((I915_READ(SBI_CTL_STAT
) & SBI_BUSY
) == 0,
1456 DRM_ERROR("timeout waiting for SBI to become ready\n");
1460 I915_WRITE(SBI_ADDR
, (reg
<< 16));
1462 if (destination
== SBI_ICLK
)
1463 value
= SBI_CTL_DEST_ICLK
| SBI_CTL_OP_CRRD
;
1465 value
= SBI_CTL_DEST_MPHY
| SBI_CTL_OP_IORD
;
1466 I915_WRITE(SBI_CTL_STAT
, value
| SBI_BUSY
);
1468 if (wait_for((I915_READ(SBI_CTL_STAT
) & (SBI_BUSY
| SBI_RESPONSE_FAIL
)) == 0,
1470 DRM_ERROR("timeout waiting for SBI to complete read transaction\n");
1474 return I915_READ(SBI_DATA
);
1477 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
, int port
)
1482 port_mask
= DPLL_PORTB_READY_MASK
;
1484 port_mask
= DPLL_PORTC_READY_MASK
;
1486 if (wait_for((I915_READ(DPLL(0)) & port_mask
) == 0, 1000))
1487 WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
1488 'B' + port
, I915_READ(DPLL(0)));
1492 * ironlake_enable_pch_pll - enable PCH PLL
1493 * @dev_priv: i915 private structure
1494 * @pipe: pipe PLL to enable
1496 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1497 * drives the transcoder clock.
1499 static void ironlake_enable_pch_pll(struct intel_crtc
*intel_crtc
)
1501 struct drm_i915_private
*dev_priv
= intel_crtc
->base
.dev
->dev_private
;
1502 struct intel_pch_pll
*pll
;
1506 /* PCH PLLs only available on ILK, SNB and IVB */
1507 BUG_ON(dev_priv
->info
->gen
< 5);
1508 pll
= intel_crtc
->pch_pll
;
1512 if (WARN_ON(pll
->refcount
== 0))
1515 DRM_DEBUG_KMS("enable PCH PLL %x (active %d, on? %d)for crtc %d\n",
1516 pll
->pll_reg
, pll
->active
, pll
->on
,
1517 intel_crtc
->base
.base
.id
);
1519 /* PCH refclock must be enabled first */
1520 assert_pch_refclk_enabled(dev_priv
);
1522 if (pll
->active
++ && pll
->on
) {
1523 assert_pch_pll_enabled(dev_priv
, pll
, NULL
);
1527 DRM_DEBUG_KMS("enabling PCH PLL %x\n", pll
->pll_reg
);
1530 val
= I915_READ(reg
);
1531 val
|= DPLL_VCO_ENABLE
;
1532 I915_WRITE(reg
, val
);
1539 static void intel_disable_pch_pll(struct intel_crtc
*intel_crtc
)
1541 struct drm_i915_private
*dev_priv
= intel_crtc
->base
.dev
->dev_private
;
1542 struct intel_pch_pll
*pll
= intel_crtc
->pch_pll
;
1546 /* PCH only available on ILK+ */
1547 BUG_ON(dev_priv
->info
->gen
< 5);
1551 if (WARN_ON(pll
->refcount
== 0))
1554 DRM_DEBUG_KMS("disable PCH PLL %x (active %d, on? %d) for crtc %d\n",
1555 pll
->pll_reg
, pll
->active
, pll
->on
,
1556 intel_crtc
->base
.base
.id
);
1558 if (WARN_ON(pll
->active
== 0)) {
1559 assert_pch_pll_disabled(dev_priv
, pll
, NULL
);
1563 if (--pll
->active
) {
1564 assert_pch_pll_enabled(dev_priv
, pll
, NULL
);
1568 DRM_DEBUG_KMS("disabling PCH PLL %x\n", pll
->pll_reg
);
1570 /* Make sure transcoder isn't still depending on us */
1571 assert_transcoder_disabled(dev_priv
, intel_crtc
->pipe
);
1574 val
= I915_READ(reg
);
1575 val
&= ~DPLL_VCO_ENABLE
;
1576 I915_WRITE(reg
, val
);
1583 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1586 struct drm_device
*dev
= dev_priv
->dev
;
1587 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1588 uint32_t reg
, val
, pipeconf_val
;
1590 /* PCH only available on ILK+ */
1591 BUG_ON(dev_priv
->info
->gen
< 5);
1593 /* Make sure PCH DPLL is enabled */
1594 assert_pch_pll_enabled(dev_priv
,
1595 to_intel_crtc(crtc
)->pch_pll
,
1596 to_intel_crtc(crtc
));
1598 /* FDI must be feeding us bits for PCH ports */
1599 assert_fdi_tx_enabled(dev_priv
, pipe
);
1600 assert_fdi_rx_enabled(dev_priv
, pipe
);
1602 if (HAS_PCH_CPT(dev
)) {
1603 /* Workaround: Set the timing override bit before enabling the
1604 * pch transcoder. */
1605 reg
= TRANS_CHICKEN2(pipe
);
1606 val
= I915_READ(reg
);
1607 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1608 I915_WRITE(reg
, val
);
1611 reg
= TRANSCONF(pipe
);
1612 val
= I915_READ(reg
);
1613 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1615 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1617 * make the BPC in transcoder be consistent with
1618 * that in pipeconf reg.
1620 val
&= ~PIPECONF_BPC_MASK
;
1621 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1624 val
&= ~TRANS_INTERLACE_MASK
;
1625 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1626 if (HAS_PCH_IBX(dev_priv
->dev
) &&
1627 intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
))
1628 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1630 val
|= TRANS_INTERLACED
;
1632 val
|= TRANS_PROGRESSIVE
;
1634 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1635 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
1636 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1639 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1640 enum transcoder cpu_transcoder
)
1642 u32 val
, pipeconf_val
;
1644 /* PCH only available on ILK+ */
1645 BUG_ON(dev_priv
->info
->gen
< 5);
1647 /* FDI must be feeding us bits for PCH ports */
1648 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1649 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1651 /* Workaround: set timing override bit. */
1652 val
= I915_READ(_TRANSA_CHICKEN2
);
1653 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1654 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1657 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1659 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1660 PIPECONF_INTERLACED_ILK
)
1661 val
|= TRANS_INTERLACED
;
1663 val
|= TRANS_PROGRESSIVE
;
1665 I915_WRITE(TRANSCONF(TRANSCODER_A
), val
);
1666 if (wait_for(I915_READ(_TRANSACONF
) & TRANS_STATE_ENABLE
, 100))
1667 DRM_ERROR("Failed to enable PCH transcoder\n");
1670 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1673 struct drm_device
*dev
= dev_priv
->dev
;
1676 /* FDI relies on the transcoder */
1677 assert_fdi_tx_disabled(dev_priv
, pipe
);
1678 assert_fdi_rx_disabled(dev_priv
, pipe
);
1680 /* Ports must be off as well */
1681 assert_pch_ports_disabled(dev_priv
, pipe
);
1683 reg
= TRANSCONF(pipe
);
1684 val
= I915_READ(reg
);
1685 val
&= ~TRANS_ENABLE
;
1686 I915_WRITE(reg
, val
);
1687 /* wait for PCH transcoder off, transcoder state */
1688 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
1689 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1691 if (!HAS_PCH_IBX(dev
)) {
1692 /* Workaround: Clear the timing override chicken bit again. */
1693 reg
= TRANS_CHICKEN2(pipe
);
1694 val
= I915_READ(reg
);
1695 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1696 I915_WRITE(reg
, val
);
1700 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1704 val
= I915_READ(_TRANSACONF
);
1705 val
&= ~TRANS_ENABLE
;
1706 I915_WRITE(_TRANSACONF
, val
);
1707 /* wait for PCH transcoder off, transcoder state */
1708 if (wait_for((I915_READ(_TRANSACONF
) & TRANS_STATE_ENABLE
) == 0, 50))
1709 DRM_ERROR("Failed to disable PCH transcoder\n");
1711 /* Workaround: clear timing override bit. */
1712 val
= I915_READ(_TRANSA_CHICKEN2
);
1713 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1714 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1718 * intel_enable_pipe - enable a pipe, asserting requirements
1719 * @dev_priv: i915 private structure
1720 * @pipe: pipe to enable
1721 * @pch_port: on ILK+, is this pipe driving a PCH port or not
1723 * Enable @pipe, making sure that various hardware specific requirements
1724 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1726 * @pipe should be %PIPE_A or %PIPE_B.
1728 * Will wait until the pipe is actually running (i.e. first vblank) before
1731 static void intel_enable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
,
1734 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1736 enum pipe pch_transcoder
;
1740 assert_planes_disabled(dev_priv
, pipe
);
1741 assert_sprites_disabled(dev_priv
, pipe
);
1743 if (HAS_PCH_LPT(dev_priv
->dev
))
1744 pch_transcoder
= TRANSCODER_A
;
1746 pch_transcoder
= pipe
;
1749 * A pipe without a PLL won't actually be able to drive bits from
1750 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1753 if (!HAS_PCH_SPLIT(dev_priv
->dev
))
1754 assert_pll_enabled(dev_priv
, pipe
);
1757 /* if driving the PCH, we need FDI enabled */
1758 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
1759 assert_fdi_tx_pll_enabled(dev_priv
,
1760 (enum pipe
) cpu_transcoder
);
1762 /* FIXME: assert CPU port conditions for SNB+ */
1765 reg
= PIPECONF(cpu_transcoder
);
1766 val
= I915_READ(reg
);
1767 if (val
& PIPECONF_ENABLE
)
1770 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
1771 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
1775 * intel_disable_pipe - disable a pipe, asserting requirements
1776 * @dev_priv: i915 private structure
1777 * @pipe: pipe to disable
1779 * Disable @pipe, making sure that various hardware specific requirements
1780 * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
1782 * @pipe should be %PIPE_A or %PIPE_B.
1784 * Will wait until the pipe has shut down before returning.
1786 static void intel_disable_pipe(struct drm_i915_private
*dev_priv
,
1789 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1795 * Make sure planes won't keep trying to pump pixels to us,
1796 * or we might hang the display.
1798 assert_planes_disabled(dev_priv
, pipe
);
1799 assert_sprites_disabled(dev_priv
, pipe
);
1801 /* Don't disable pipe A or pipe A PLLs if needed */
1802 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
1805 reg
= PIPECONF(cpu_transcoder
);
1806 val
= I915_READ(reg
);
1807 if ((val
& PIPECONF_ENABLE
) == 0)
1810 I915_WRITE(reg
, val
& ~PIPECONF_ENABLE
);
1811 intel_wait_for_pipe_off(dev_priv
->dev
, pipe
);
1815 * Plane regs are double buffered, going from enabled->disabled needs a
1816 * trigger in order to latch. The display address reg provides this.
1818 void intel_flush_display_plane(struct drm_i915_private
*dev_priv
,
1821 if (dev_priv
->info
->gen
>= 4)
1822 I915_WRITE(DSPSURF(plane
), I915_READ(DSPSURF(plane
)));
1824 I915_WRITE(DSPADDR(plane
), I915_READ(DSPADDR(plane
)));
1828 * intel_enable_plane - enable a display plane on a given pipe
1829 * @dev_priv: i915 private structure
1830 * @plane: plane to enable
1831 * @pipe: pipe being fed
1833 * Enable @plane on @pipe, making sure that @pipe is running first.
1835 static void intel_enable_plane(struct drm_i915_private
*dev_priv
,
1836 enum plane plane
, enum pipe pipe
)
1841 /* If the pipe isn't enabled, we can't pump pixels and may hang */
1842 assert_pipe_enabled(dev_priv
, pipe
);
1844 reg
= DSPCNTR(plane
);
1845 val
= I915_READ(reg
);
1846 if (val
& DISPLAY_PLANE_ENABLE
)
1849 I915_WRITE(reg
, val
| DISPLAY_PLANE_ENABLE
);
1850 intel_flush_display_plane(dev_priv
, plane
);
1851 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
1855 * intel_disable_plane - disable a display plane
1856 * @dev_priv: i915 private structure
1857 * @plane: plane to disable
1858 * @pipe: pipe consuming the data
1860 * Disable @plane; should be an independent operation.
1862 static void intel_disable_plane(struct drm_i915_private
*dev_priv
,
1863 enum plane plane
, enum pipe pipe
)
1868 reg
= DSPCNTR(plane
);
1869 val
= I915_READ(reg
);
1870 if ((val
& DISPLAY_PLANE_ENABLE
) == 0)
1873 I915_WRITE(reg
, val
& ~DISPLAY_PLANE_ENABLE
);
1874 intel_flush_display_plane(dev_priv
, plane
);
1875 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
1878 static bool need_vtd_wa(struct drm_device
*dev
)
1880 #ifdef CONFIG_INTEL_IOMMU
1881 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
1888 intel_pin_and_fence_fb_obj(struct drm_device
*dev
,
1889 struct drm_i915_gem_object
*obj
,
1890 struct intel_ring_buffer
*pipelined
)
1892 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1896 switch (obj
->tiling_mode
) {
1897 case I915_TILING_NONE
:
1898 if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
1899 alignment
= 128 * 1024;
1900 else if (INTEL_INFO(dev
)->gen
>= 4)
1901 alignment
= 4 * 1024;
1903 alignment
= 64 * 1024;
1906 /* pin() will align the object as required by fence */
1910 /* Despite that we check this in framebuffer_init userspace can
1911 * screw us over and change the tiling after the fact. Only
1912 * pinned buffers can't change their tiling. */
1913 DRM_DEBUG_DRIVER("Y tiled not allowed for scan out buffers\n");
1919 /* Note that the w/a also requires 64 PTE of padding following the
1920 * bo. We currently fill all unused PTE with the shadow page and so
1921 * we should always have valid PTE following the scanout preventing
1924 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
1925 alignment
= 256 * 1024;
1927 dev_priv
->mm
.interruptible
= false;
1928 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
);
1930 goto err_interruptible
;
1932 /* Install a fence for tiled scan-out. Pre-i965 always needs a
1933 * fence, whereas 965+ only requires a fence if using
1934 * framebuffer compression. For simplicity, we always install
1935 * a fence as the cost is not that onerous.
1937 ret
= i915_gem_object_get_fence(obj
);
1941 i915_gem_object_pin_fence(obj
);
1943 dev_priv
->mm
.interruptible
= true;
1947 i915_gem_object_unpin(obj
);
1949 dev_priv
->mm
.interruptible
= true;
1953 void intel_unpin_fb_obj(struct drm_i915_gem_object
*obj
)
1955 i915_gem_object_unpin_fence(obj
);
1956 i915_gem_object_unpin(obj
);
1959 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
1960 * is assumed to be a power-of-two. */
1961 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
1962 unsigned int tiling_mode
,
1966 if (tiling_mode
!= I915_TILING_NONE
) {
1967 unsigned int tile_rows
, tiles
;
1972 tiles
= *x
/ (512/cpp
);
1975 return tile_rows
* pitch
* 8 + tiles
* 4096;
1977 unsigned int offset
;
1979 offset
= *y
* pitch
+ *x
* cpp
;
1981 *x
= (offset
& 4095) / cpp
;
1982 return offset
& -4096;
1986 static int i9xx_update_plane(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
1989 struct drm_device
*dev
= crtc
->dev
;
1990 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1991 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1992 struct intel_framebuffer
*intel_fb
;
1993 struct drm_i915_gem_object
*obj
;
1994 int plane
= intel_crtc
->plane
;
1995 unsigned long linear_offset
;
2004 DRM_ERROR("Can't update plane %c in SAREA\n", plane_name(plane
));
2008 intel_fb
= to_intel_framebuffer(fb
);
2009 obj
= intel_fb
->obj
;
2011 reg
= DSPCNTR(plane
);
2012 dspcntr
= I915_READ(reg
);
2013 /* Mask out pixel format bits in case we change it */
2014 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
2015 switch (fb
->pixel_format
) {
2017 dspcntr
|= DISPPLANE_8BPP
;
2019 case DRM_FORMAT_XRGB1555
:
2020 case DRM_FORMAT_ARGB1555
:
2021 dspcntr
|= DISPPLANE_BGRX555
;
2023 case DRM_FORMAT_RGB565
:
2024 dspcntr
|= DISPPLANE_BGRX565
;
2026 case DRM_FORMAT_XRGB8888
:
2027 case DRM_FORMAT_ARGB8888
:
2028 dspcntr
|= DISPPLANE_BGRX888
;
2030 case DRM_FORMAT_XBGR8888
:
2031 case DRM_FORMAT_ABGR8888
:
2032 dspcntr
|= DISPPLANE_RGBX888
;
2034 case DRM_FORMAT_XRGB2101010
:
2035 case DRM_FORMAT_ARGB2101010
:
2036 dspcntr
|= DISPPLANE_BGRX101010
;
2038 case DRM_FORMAT_XBGR2101010
:
2039 case DRM_FORMAT_ABGR2101010
:
2040 dspcntr
|= DISPPLANE_RGBX101010
;
2046 if (INTEL_INFO(dev
)->gen
>= 4) {
2047 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2048 dspcntr
|= DISPPLANE_TILED
;
2050 dspcntr
&= ~DISPPLANE_TILED
;
2053 I915_WRITE(reg
, dspcntr
);
2055 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2057 if (INTEL_INFO(dev
)->gen
>= 4) {
2058 intel_crtc
->dspaddr_offset
=
2059 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2060 fb
->bits_per_pixel
/ 8,
2062 linear_offset
-= intel_crtc
->dspaddr_offset
;
2064 intel_crtc
->dspaddr_offset
= linear_offset
;
2067 DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
2068 obj
->gtt_offset
, linear_offset
, x
, y
, fb
->pitches
[0]);
2069 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2070 if (INTEL_INFO(dev
)->gen
>= 4) {
2071 I915_MODIFY_DISPBASE(DSPSURF(plane
),
2072 obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
2073 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2074 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2076 I915_WRITE(DSPADDR(plane
), obj
->gtt_offset
+ linear_offset
);
2082 static int ironlake_update_plane(struct drm_crtc
*crtc
,
2083 struct drm_framebuffer
*fb
, int x
, int y
)
2085 struct drm_device
*dev
= crtc
->dev
;
2086 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2087 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2088 struct intel_framebuffer
*intel_fb
;
2089 struct drm_i915_gem_object
*obj
;
2090 int plane
= intel_crtc
->plane
;
2091 unsigned long linear_offset
;
2101 DRM_ERROR("Can't update plane %c in SAREA\n", plane_name(plane
));
2105 intel_fb
= to_intel_framebuffer(fb
);
2106 obj
= intel_fb
->obj
;
2108 reg
= DSPCNTR(plane
);
2109 dspcntr
= I915_READ(reg
);
2110 /* Mask out pixel format bits in case we change it */
2111 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
2112 switch (fb
->pixel_format
) {
2114 dspcntr
|= DISPPLANE_8BPP
;
2116 case DRM_FORMAT_RGB565
:
2117 dspcntr
|= DISPPLANE_BGRX565
;
2119 case DRM_FORMAT_XRGB8888
:
2120 case DRM_FORMAT_ARGB8888
:
2121 dspcntr
|= DISPPLANE_BGRX888
;
2123 case DRM_FORMAT_XBGR8888
:
2124 case DRM_FORMAT_ABGR8888
:
2125 dspcntr
|= DISPPLANE_RGBX888
;
2127 case DRM_FORMAT_XRGB2101010
:
2128 case DRM_FORMAT_ARGB2101010
:
2129 dspcntr
|= DISPPLANE_BGRX101010
;
2131 case DRM_FORMAT_XBGR2101010
:
2132 case DRM_FORMAT_ABGR2101010
:
2133 dspcntr
|= DISPPLANE_RGBX101010
;
2139 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2140 dspcntr
|= DISPPLANE_TILED
;
2142 dspcntr
&= ~DISPPLANE_TILED
;
2145 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2147 I915_WRITE(reg
, dspcntr
);
2149 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2150 intel_crtc
->dspaddr_offset
=
2151 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2152 fb
->bits_per_pixel
/ 8,
2154 linear_offset
-= intel_crtc
->dspaddr_offset
;
2156 DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
2157 obj
->gtt_offset
, linear_offset
, x
, y
, fb
->pitches
[0]);
2158 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2159 I915_MODIFY_DISPBASE(DSPSURF(plane
),
2160 obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
2161 if (IS_HASWELL(dev
)) {
2162 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2164 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2165 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2172 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2174 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
2175 int x
, int y
, enum mode_set_atomic state
)
2177 struct drm_device
*dev
= crtc
->dev
;
2178 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2180 if (dev_priv
->display
.disable_fbc
)
2181 dev_priv
->display
.disable_fbc(dev
);
2182 intel_increase_pllclock(crtc
);
2184 return dev_priv
->display
.update_plane(crtc
, fb
, x
, y
);
2187 void intel_display_handle_reset(struct drm_device
*dev
)
2189 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2190 struct drm_crtc
*crtc
;
2193 * Flips in the rings have been nuked by the reset,
2194 * so complete all pending flips so that user space
2195 * will get its events and not get stuck.
2197 * Also update the base address of all primary
2198 * planes to the the last fb to make sure we're
2199 * showing the correct fb after a reset.
2201 * Need to make two loops over the crtcs so that we
2202 * don't try to grab a crtc mutex before the
2203 * pending_flip_queue really got woken up.
2206 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
2207 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2208 enum plane plane
= intel_crtc
->plane
;
2210 intel_prepare_page_flip(dev
, plane
);
2211 intel_finish_page_flip_plane(dev
, plane
);
2214 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
2215 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2217 mutex_lock(&crtc
->mutex
);
2218 if (intel_crtc
->active
)
2219 dev_priv
->display
.update_plane(crtc
, crtc
->fb
,
2221 mutex_unlock(&crtc
->mutex
);
2226 intel_finish_fb(struct drm_framebuffer
*old_fb
)
2228 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(old_fb
)->obj
;
2229 struct drm_i915_private
*dev_priv
= obj
->base
.dev
->dev_private
;
2230 bool was_interruptible
= dev_priv
->mm
.interruptible
;
2233 /* Big Hammer, we also need to ensure that any pending
2234 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2235 * current scanout is retired before unpinning the old
2238 * This should only fail upon a hung GPU, in which case we
2239 * can safely continue.
2241 dev_priv
->mm
.interruptible
= false;
2242 ret
= i915_gem_object_finish_gpu(obj
);
2243 dev_priv
->mm
.interruptible
= was_interruptible
;
2248 static void intel_crtc_update_sarea_pos(struct drm_crtc
*crtc
, int x
, int y
)
2250 struct drm_device
*dev
= crtc
->dev
;
2251 struct drm_i915_master_private
*master_priv
;
2252 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2254 if (!dev
->primary
->master
)
2257 master_priv
= dev
->primary
->master
->driver_priv
;
2258 if (!master_priv
->sarea_priv
)
2261 switch (intel_crtc
->pipe
) {
2263 master_priv
->sarea_priv
->pipeA_x
= x
;
2264 master_priv
->sarea_priv
->pipeA_y
= y
;
2267 master_priv
->sarea_priv
->pipeB_x
= x
;
2268 master_priv
->sarea_priv
->pipeB_y
= y
;
2276 intel_pipe_set_base(struct drm_crtc
*crtc
, int x
, int y
,
2277 struct drm_framebuffer
*fb
)
2279 struct drm_device
*dev
= crtc
->dev
;
2280 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2281 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2282 struct drm_framebuffer
*old_fb
;
2287 DRM_ERROR("No FB bound\n");
2291 if (intel_crtc
->plane
> INTEL_INFO(dev
)->num_pipes
) {
2292 DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
2293 plane_name(intel_crtc
->plane
),
2294 INTEL_INFO(dev
)->num_pipes
);
2298 mutex_lock(&dev
->struct_mutex
);
2299 ret
= intel_pin_and_fence_fb_obj(dev
,
2300 to_intel_framebuffer(fb
)->obj
,
2303 mutex_unlock(&dev
->struct_mutex
);
2304 DRM_ERROR("pin & fence failed\n");
2308 ret
= dev_priv
->display
.update_plane(crtc
, fb
, x
, y
);
2310 intel_unpin_fb_obj(to_intel_framebuffer(fb
)->obj
);
2311 mutex_unlock(&dev
->struct_mutex
);
2312 DRM_ERROR("failed to update base address\n");
2322 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2323 intel_unpin_fb_obj(to_intel_framebuffer(old_fb
)->obj
);
2326 intel_update_fbc(dev
);
2327 mutex_unlock(&dev
->struct_mutex
);
2329 intel_crtc_update_sarea_pos(crtc
, x
, y
);
2334 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
2336 struct drm_device
*dev
= crtc
->dev
;
2337 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2338 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2339 int pipe
= intel_crtc
->pipe
;
2342 /* enable normal train */
2343 reg
= FDI_TX_CTL(pipe
);
2344 temp
= I915_READ(reg
);
2345 if (IS_IVYBRIDGE(dev
)) {
2346 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2347 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2349 temp
&= ~FDI_LINK_TRAIN_NONE
;
2350 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2352 I915_WRITE(reg
, temp
);
2354 reg
= FDI_RX_CTL(pipe
);
2355 temp
= I915_READ(reg
);
2356 if (HAS_PCH_CPT(dev
)) {
2357 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2358 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
2360 temp
&= ~FDI_LINK_TRAIN_NONE
;
2361 temp
|= FDI_LINK_TRAIN_NONE
;
2363 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
2365 /* wait one idle pattern time */
2369 /* IVB wants error correction enabled */
2370 if (IS_IVYBRIDGE(dev
))
2371 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
2372 FDI_FE_ERRC_ENABLE
);
2375 static void ivb_modeset_global_resources(struct drm_device
*dev
)
2377 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2378 struct intel_crtc
*pipe_B_crtc
=
2379 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
2380 struct intel_crtc
*pipe_C_crtc
=
2381 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]);
2384 /* When everything is off disable fdi C so that we could enable fdi B
2385 * with all lanes. XXX: This misses the case where a pipe is not using
2386 * any pch resources and so doesn't need any fdi lanes. */
2387 if (!pipe_B_crtc
->base
.enabled
&& !pipe_C_crtc
->base
.enabled
) {
2388 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
2389 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
2391 temp
= I915_READ(SOUTH_CHICKEN1
);
2392 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
2393 DRM_DEBUG_KMS("disabling fdi C rx\n");
2394 I915_WRITE(SOUTH_CHICKEN1
, temp
);
2398 /* The FDI link training functions for ILK/Ibexpeak. */
2399 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
2401 struct drm_device
*dev
= crtc
->dev
;
2402 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2403 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2404 int pipe
= intel_crtc
->pipe
;
2405 int plane
= intel_crtc
->plane
;
2406 u32 reg
, temp
, tries
;
2408 /* FDI needs bits from pipe & plane first */
2409 assert_pipe_enabled(dev_priv
, pipe
);
2410 assert_plane_enabled(dev_priv
, plane
);
2412 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2414 reg
= FDI_RX_IMR(pipe
);
2415 temp
= I915_READ(reg
);
2416 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2417 temp
&= ~FDI_RX_BIT_LOCK
;
2418 I915_WRITE(reg
, temp
);
2422 /* enable CPU FDI TX and PCH FDI RX */
2423 reg
= FDI_TX_CTL(pipe
);
2424 temp
= I915_READ(reg
);
2426 temp
|= (intel_crtc
->fdi_lanes
- 1) << 19;
2427 temp
&= ~FDI_LINK_TRAIN_NONE
;
2428 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2429 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2431 reg
= FDI_RX_CTL(pipe
);
2432 temp
= I915_READ(reg
);
2433 temp
&= ~FDI_LINK_TRAIN_NONE
;
2434 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2435 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2440 /* Ironlake workaround, enable clock pointer after FDI enable*/
2441 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
2442 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
2443 FDI_RX_PHASE_SYNC_POINTER_EN
);
2445 reg
= FDI_RX_IIR(pipe
);
2446 for (tries
= 0; tries
< 5; tries
++) {
2447 temp
= I915_READ(reg
);
2448 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2450 if ((temp
& FDI_RX_BIT_LOCK
)) {
2451 DRM_DEBUG_KMS("FDI train 1 done.\n");
2452 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2457 DRM_ERROR("FDI train 1 fail!\n");
2460 reg
= FDI_TX_CTL(pipe
);
2461 temp
= I915_READ(reg
);
2462 temp
&= ~FDI_LINK_TRAIN_NONE
;
2463 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2464 I915_WRITE(reg
, temp
);
2466 reg
= FDI_RX_CTL(pipe
);
2467 temp
= I915_READ(reg
);
2468 temp
&= ~FDI_LINK_TRAIN_NONE
;
2469 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2470 I915_WRITE(reg
, temp
);
2475 reg
= FDI_RX_IIR(pipe
);
2476 for (tries
= 0; tries
< 5; tries
++) {
2477 temp
= I915_READ(reg
);
2478 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2480 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2481 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2482 DRM_DEBUG_KMS("FDI train 2 done.\n");
2487 DRM_ERROR("FDI train 2 fail!\n");
2489 DRM_DEBUG_KMS("FDI train done\n");
2493 static const int snb_b_fdi_train_param
[] = {
2494 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
2495 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
2496 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
2497 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
2500 /* The FDI link training functions for SNB/Cougarpoint. */
2501 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
2503 struct drm_device
*dev
= crtc
->dev
;
2504 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2505 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2506 int pipe
= intel_crtc
->pipe
;
2507 u32 reg
, temp
, i
, retry
;
2509 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2511 reg
= FDI_RX_IMR(pipe
);
2512 temp
= I915_READ(reg
);
2513 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2514 temp
&= ~FDI_RX_BIT_LOCK
;
2515 I915_WRITE(reg
, temp
);
2520 /* enable CPU FDI TX and PCH FDI RX */
2521 reg
= FDI_TX_CTL(pipe
);
2522 temp
= I915_READ(reg
);
2524 temp
|= (intel_crtc
->fdi_lanes
- 1) << 19;
2525 temp
&= ~FDI_LINK_TRAIN_NONE
;
2526 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2527 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2529 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2530 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2532 I915_WRITE(FDI_RX_MISC(pipe
),
2533 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
2535 reg
= FDI_RX_CTL(pipe
);
2536 temp
= I915_READ(reg
);
2537 if (HAS_PCH_CPT(dev
)) {
2538 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2539 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2541 temp
&= ~FDI_LINK_TRAIN_NONE
;
2542 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2544 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2549 for (i
= 0; i
< 4; i
++) {
2550 reg
= FDI_TX_CTL(pipe
);
2551 temp
= I915_READ(reg
);
2552 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2553 temp
|= snb_b_fdi_train_param
[i
];
2554 I915_WRITE(reg
, temp
);
2559 for (retry
= 0; retry
< 5; retry
++) {
2560 reg
= FDI_RX_IIR(pipe
);
2561 temp
= I915_READ(reg
);
2562 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2563 if (temp
& FDI_RX_BIT_LOCK
) {
2564 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2565 DRM_DEBUG_KMS("FDI train 1 done.\n");
2574 DRM_ERROR("FDI train 1 fail!\n");
2577 reg
= FDI_TX_CTL(pipe
);
2578 temp
= I915_READ(reg
);
2579 temp
&= ~FDI_LINK_TRAIN_NONE
;
2580 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2582 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2584 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2586 I915_WRITE(reg
, temp
);
2588 reg
= FDI_RX_CTL(pipe
);
2589 temp
= I915_READ(reg
);
2590 if (HAS_PCH_CPT(dev
)) {
2591 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2592 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
2594 temp
&= ~FDI_LINK_TRAIN_NONE
;
2595 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2597 I915_WRITE(reg
, temp
);
2602 for (i
= 0; i
< 4; i
++) {
2603 reg
= FDI_TX_CTL(pipe
);
2604 temp
= I915_READ(reg
);
2605 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2606 temp
|= snb_b_fdi_train_param
[i
];
2607 I915_WRITE(reg
, temp
);
2612 for (retry
= 0; retry
< 5; retry
++) {
2613 reg
= FDI_RX_IIR(pipe
);
2614 temp
= I915_READ(reg
);
2615 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2616 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2617 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2618 DRM_DEBUG_KMS("FDI train 2 done.\n");
2627 DRM_ERROR("FDI train 2 fail!\n");
2629 DRM_DEBUG_KMS("FDI train done.\n");
2632 /* Manual link training for Ivy Bridge A0 parts */
2633 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
2635 struct drm_device
*dev
= crtc
->dev
;
2636 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2637 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2638 int pipe
= intel_crtc
->pipe
;
2641 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2643 reg
= FDI_RX_IMR(pipe
);
2644 temp
= I915_READ(reg
);
2645 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2646 temp
&= ~FDI_RX_BIT_LOCK
;
2647 I915_WRITE(reg
, temp
);
2652 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
2653 I915_READ(FDI_RX_IIR(pipe
)));
2655 /* enable CPU FDI TX and PCH FDI RX */
2656 reg
= FDI_TX_CTL(pipe
);
2657 temp
= I915_READ(reg
);
2659 temp
|= (intel_crtc
->fdi_lanes
- 1) << 19;
2660 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
2661 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
2662 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2663 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2664 temp
|= FDI_COMPOSITE_SYNC
;
2665 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2667 I915_WRITE(FDI_RX_MISC(pipe
),
2668 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
2670 reg
= FDI_RX_CTL(pipe
);
2671 temp
= I915_READ(reg
);
2672 temp
&= ~FDI_LINK_TRAIN_AUTO
;
2673 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2674 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2675 temp
|= FDI_COMPOSITE_SYNC
;
2676 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2681 for (i
= 0; i
< 4; i
++) {
2682 reg
= FDI_TX_CTL(pipe
);
2683 temp
= I915_READ(reg
);
2684 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2685 temp
|= snb_b_fdi_train_param
[i
];
2686 I915_WRITE(reg
, temp
);
2691 reg
= FDI_RX_IIR(pipe
);
2692 temp
= I915_READ(reg
);
2693 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2695 if (temp
& FDI_RX_BIT_LOCK
||
2696 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
2697 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2698 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i
);
2703 DRM_ERROR("FDI train 1 fail!\n");
2706 reg
= FDI_TX_CTL(pipe
);
2707 temp
= I915_READ(reg
);
2708 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2709 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
2710 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2711 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2712 I915_WRITE(reg
, temp
);
2714 reg
= FDI_RX_CTL(pipe
);
2715 temp
= I915_READ(reg
);
2716 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2717 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
2718 I915_WRITE(reg
, temp
);
2723 for (i
= 0; i
< 4; i
++) {
2724 reg
= FDI_TX_CTL(pipe
);
2725 temp
= I915_READ(reg
);
2726 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2727 temp
|= snb_b_fdi_train_param
[i
];
2728 I915_WRITE(reg
, temp
);
2733 reg
= FDI_RX_IIR(pipe
);
2734 temp
= I915_READ(reg
);
2735 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2737 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2738 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2739 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i
);
2744 DRM_ERROR("FDI train 2 fail!\n");
2746 DRM_DEBUG_KMS("FDI train done.\n");
2749 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
2751 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2752 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2753 int pipe
= intel_crtc
->pipe
;
2757 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
2758 reg
= FDI_RX_CTL(pipe
);
2759 temp
= I915_READ(reg
);
2760 temp
&= ~((0x7 << 19) | (0x7 << 16));
2761 temp
|= (intel_crtc
->fdi_lanes
- 1) << 19;
2762 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
2763 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
2768 /* Switch from Rawclk to PCDclk */
2769 temp
= I915_READ(reg
);
2770 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
2775 /* Enable CPU FDI TX PLL, always on for Ironlake */
2776 reg
= FDI_TX_CTL(pipe
);
2777 temp
= I915_READ(reg
);
2778 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
2779 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
2786 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
2788 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2789 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2790 int pipe
= intel_crtc
->pipe
;
2793 /* Switch from PCDclk to Rawclk */
2794 reg
= FDI_RX_CTL(pipe
);
2795 temp
= I915_READ(reg
);
2796 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
2798 /* Disable CPU FDI TX PLL */
2799 reg
= FDI_TX_CTL(pipe
);
2800 temp
= I915_READ(reg
);
2801 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
2806 reg
= FDI_RX_CTL(pipe
);
2807 temp
= I915_READ(reg
);
2808 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
2810 /* Wait for the clocks to turn off. */
2815 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
2817 struct drm_device
*dev
= crtc
->dev
;
2818 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2819 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2820 int pipe
= intel_crtc
->pipe
;
2823 /* disable CPU FDI tx and PCH FDI rx */
2824 reg
= FDI_TX_CTL(pipe
);
2825 temp
= I915_READ(reg
);
2826 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
2829 reg
= FDI_RX_CTL(pipe
);
2830 temp
= I915_READ(reg
);
2831 temp
&= ~(0x7 << 16);
2832 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
2833 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
2838 /* Ironlake workaround, disable clock pointer after downing FDI */
2839 if (HAS_PCH_IBX(dev
)) {
2840 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
2843 /* still set train pattern 1 */
2844 reg
= FDI_TX_CTL(pipe
);
2845 temp
= I915_READ(reg
);
2846 temp
&= ~FDI_LINK_TRAIN_NONE
;
2847 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2848 I915_WRITE(reg
, temp
);
2850 reg
= FDI_RX_CTL(pipe
);
2851 temp
= I915_READ(reg
);
2852 if (HAS_PCH_CPT(dev
)) {
2853 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2854 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2856 temp
&= ~FDI_LINK_TRAIN_NONE
;
2857 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2859 /* BPC in FDI rx is consistent with that in PIPECONF */
2860 temp
&= ~(0x07 << 16);
2861 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
2862 I915_WRITE(reg
, temp
);
2868 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
2870 struct drm_device
*dev
= crtc
->dev
;
2871 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2872 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2873 unsigned long flags
;
2876 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
2877 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
2880 spin_lock_irqsave(&dev
->event_lock
, flags
);
2881 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
2882 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2887 static void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
2889 struct drm_device
*dev
= crtc
->dev
;
2890 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2892 if (crtc
->fb
== NULL
)
2895 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
2897 wait_event(dev_priv
->pending_flip_queue
,
2898 !intel_crtc_has_pending_flip(crtc
));
2900 mutex_lock(&dev
->struct_mutex
);
2901 intel_finish_fb(crtc
->fb
);
2902 mutex_unlock(&dev
->struct_mutex
);
2905 /* Program iCLKIP clock to the desired frequency */
2906 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
2908 struct drm_device
*dev
= crtc
->dev
;
2909 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2910 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
2913 mutex_lock(&dev_priv
->dpio_lock
);
2915 /* It is necessary to ungate the pixclk gate prior to programming
2916 * the divisors, and gate it back when it is done.
2918 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
2920 /* Disable SSCCTL */
2921 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
2922 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
2926 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
2927 if (crtc
->mode
.clock
== 20000) {
2932 /* The iCLK virtual clock root frequency is in MHz,
2933 * but the crtc->mode.clock in in KHz. To get the divisors,
2934 * it is necessary to divide one by another, so we
2935 * convert the virtual clock precision to KHz here for higher
2938 u32 iclk_virtual_root_freq
= 172800 * 1000;
2939 u32 iclk_pi_range
= 64;
2940 u32 desired_divisor
, msb_divisor_value
, pi_value
;
2942 desired_divisor
= (iclk_virtual_root_freq
/ crtc
->mode
.clock
);
2943 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
2944 pi_value
= desired_divisor
% iclk_pi_range
;
2947 divsel
= msb_divisor_value
- 2;
2948 phaseinc
= pi_value
;
2951 /* This should not happen with any sane values */
2952 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
2953 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
2954 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
2955 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
2957 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
2964 /* Program SSCDIVINTPHASE6 */
2965 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
2966 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
2967 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
2968 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
2969 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
2970 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
2971 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
2972 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
2974 /* Program SSCAUXDIV */
2975 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
2976 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
2977 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
2978 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
2980 /* Enable modulator and associated divider */
2981 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
2982 temp
&= ~SBI_SSCCTL_DISABLE
;
2983 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
2985 /* Wait for initialization time */
2988 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
2990 mutex_unlock(&dev_priv
->dpio_lock
);
2994 * Enable PCH resources required for PCH ports:
2996 * - FDI training & RX/TX
2997 * - update transcoder timings
2998 * - DP transcoding bits
3001 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
3003 struct drm_device
*dev
= crtc
->dev
;
3004 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3005 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3006 int pipe
= intel_crtc
->pipe
;
3009 assert_transcoder_disabled(dev_priv
, pipe
);
3011 /* Write the TU size bits before fdi link training, so that error
3012 * detection works. */
3013 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
3014 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
3016 /* For PCH output, training FDI link */
3017 dev_priv
->display
.fdi_link_train(crtc
);
3019 /* XXX: pch pll's can be enabled any time before we enable the PCH
3020 * transcoder, and we actually should do this to not upset any PCH
3021 * transcoder that already use the clock when we share it.
3023 * Note that enable_pch_pll tries to do the right thing, but get_pch_pll
3024 * unconditionally resets the pll - we need that to have the right LVDS
3025 * enable sequence. */
3026 ironlake_enable_pch_pll(intel_crtc
);
3028 if (HAS_PCH_CPT(dev
)) {
3031 temp
= I915_READ(PCH_DPLL_SEL
);
3035 temp
|= TRANSA_DPLL_ENABLE
;
3036 sel
= TRANSA_DPLLB_SEL
;
3039 temp
|= TRANSB_DPLL_ENABLE
;
3040 sel
= TRANSB_DPLLB_SEL
;
3043 temp
|= TRANSC_DPLL_ENABLE
;
3044 sel
= TRANSC_DPLLB_SEL
;
3047 if (intel_crtc
->pch_pll
->pll_reg
== _PCH_DPLL_B
)
3051 I915_WRITE(PCH_DPLL_SEL
, temp
);
3054 /* set transcoder timing, panel must allow it */
3055 assert_panel_unlocked(dev_priv
, pipe
);
3056 I915_WRITE(TRANS_HTOTAL(pipe
), I915_READ(HTOTAL(pipe
)));
3057 I915_WRITE(TRANS_HBLANK(pipe
), I915_READ(HBLANK(pipe
)));
3058 I915_WRITE(TRANS_HSYNC(pipe
), I915_READ(HSYNC(pipe
)));
3060 I915_WRITE(TRANS_VTOTAL(pipe
), I915_READ(VTOTAL(pipe
)));
3061 I915_WRITE(TRANS_VBLANK(pipe
), I915_READ(VBLANK(pipe
)));
3062 I915_WRITE(TRANS_VSYNC(pipe
), I915_READ(VSYNC(pipe
)));
3063 I915_WRITE(TRANS_VSYNCSHIFT(pipe
), I915_READ(VSYNCSHIFT(pipe
)));
3065 intel_fdi_normal_train(crtc
);
3067 /* For PCH DP, enable TRANS_DP_CTL */
3068 if (HAS_PCH_CPT(dev
) &&
3069 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
3070 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3071 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
3072 reg
= TRANS_DP_CTL(pipe
);
3073 temp
= I915_READ(reg
);
3074 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
3075 TRANS_DP_SYNC_MASK
|
3077 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
3078 TRANS_DP_ENH_FRAMING
);
3079 temp
|= bpc
<< 9; /* same format but at 11:9 */
3081 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
3082 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
3083 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
3084 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
3086 switch (intel_trans_dp_port_sel(crtc
)) {
3088 temp
|= TRANS_DP_PORT_SEL_B
;
3091 temp
|= TRANS_DP_PORT_SEL_C
;
3094 temp
|= TRANS_DP_PORT_SEL_D
;
3100 I915_WRITE(reg
, temp
);
3103 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
3106 static void lpt_pch_enable(struct drm_crtc
*crtc
)
3108 struct drm_device
*dev
= crtc
->dev
;
3109 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3110 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3111 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
3113 assert_transcoder_disabled(dev_priv
, TRANSCODER_A
);
3115 lpt_program_iclkip(crtc
);
3117 /* Set transcoder timing. */
3118 I915_WRITE(_TRANS_HTOTAL_A
, I915_READ(HTOTAL(cpu_transcoder
)));
3119 I915_WRITE(_TRANS_HBLANK_A
, I915_READ(HBLANK(cpu_transcoder
)));
3120 I915_WRITE(_TRANS_HSYNC_A
, I915_READ(HSYNC(cpu_transcoder
)));
3122 I915_WRITE(_TRANS_VTOTAL_A
, I915_READ(VTOTAL(cpu_transcoder
)));
3123 I915_WRITE(_TRANS_VBLANK_A
, I915_READ(VBLANK(cpu_transcoder
)));
3124 I915_WRITE(_TRANS_VSYNC_A
, I915_READ(VSYNC(cpu_transcoder
)));
3125 I915_WRITE(_TRANS_VSYNCSHIFT_A
, I915_READ(VSYNCSHIFT(cpu_transcoder
)));
3127 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
3130 static void intel_put_pch_pll(struct intel_crtc
*intel_crtc
)
3132 struct intel_pch_pll
*pll
= intel_crtc
->pch_pll
;
3137 if (pll
->refcount
== 0) {
3138 WARN(1, "bad PCH PLL refcount\n");
3143 intel_crtc
->pch_pll
= NULL
;
3146 static struct intel_pch_pll
*intel_get_pch_pll(struct intel_crtc
*intel_crtc
, u32 dpll
, u32 fp
)
3148 struct drm_i915_private
*dev_priv
= intel_crtc
->base
.dev
->dev_private
;
3149 struct intel_pch_pll
*pll
;
3152 pll
= intel_crtc
->pch_pll
;
3154 DRM_DEBUG_KMS("CRTC:%d reusing existing PCH PLL %x\n",
3155 intel_crtc
->base
.base
.id
, pll
->pll_reg
);
3159 if (HAS_PCH_IBX(dev_priv
->dev
)) {
3160 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3161 i
= intel_crtc
->pipe
;
3162 pll
= &dev_priv
->pch_plls
[i
];
3164 DRM_DEBUG_KMS("CRTC:%d using pre-allocated PCH PLL %x\n",
3165 intel_crtc
->base
.base
.id
, pll
->pll_reg
);
3170 for (i
= 0; i
< dev_priv
->num_pch_pll
; i
++) {
3171 pll
= &dev_priv
->pch_plls
[i
];
3173 /* Only want to check enabled timings first */
3174 if (pll
->refcount
== 0)
3177 if (dpll
== (I915_READ(pll
->pll_reg
) & 0x7fffffff) &&
3178 fp
== I915_READ(pll
->fp0_reg
)) {
3179 DRM_DEBUG_KMS("CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n",
3180 intel_crtc
->base
.base
.id
,
3181 pll
->pll_reg
, pll
->refcount
, pll
->active
);
3187 /* Ok no matching timings, maybe there's a free one? */
3188 for (i
= 0; i
< dev_priv
->num_pch_pll
; i
++) {
3189 pll
= &dev_priv
->pch_plls
[i
];
3190 if (pll
->refcount
== 0) {
3191 DRM_DEBUG_KMS("CRTC:%d allocated PCH PLL %x\n",
3192 intel_crtc
->base
.base
.id
, pll
->pll_reg
);
3200 intel_crtc
->pch_pll
= pll
;
3202 DRM_DEBUG_DRIVER("using pll %d for pipe %c\n", i
, pipe_name(intel_crtc
->pipe
));
3203 prepare
: /* separate function? */
3204 DRM_DEBUG_DRIVER("switching PLL %x off\n", pll
->pll_reg
);
3206 /* Wait for the clocks to stabilize before rewriting the regs */
3207 I915_WRITE(pll
->pll_reg
, dpll
& ~DPLL_VCO_ENABLE
);
3208 POSTING_READ(pll
->pll_reg
);
3211 I915_WRITE(pll
->fp0_reg
, fp
);
3212 I915_WRITE(pll
->pll_reg
, dpll
& ~DPLL_VCO_ENABLE
);
3217 void intel_cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
3219 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3220 int dslreg
= PIPEDSL(pipe
);
3223 temp
= I915_READ(dslreg
);
3225 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
3226 if (wait_for(I915_READ(dslreg
) != temp
, 5))
3227 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
3231 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
3233 struct drm_device
*dev
= crtc
->dev
;
3234 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3235 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3236 struct intel_encoder
*encoder
;
3237 int pipe
= intel_crtc
->pipe
;
3238 int plane
= intel_crtc
->plane
;
3241 WARN_ON(!crtc
->enabled
);
3243 if (intel_crtc
->active
)
3246 intel_crtc
->active
= true;
3248 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
3249 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
3251 intel_update_watermarks(dev
);
3253 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
3254 temp
= I915_READ(PCH_LVDS
);
3255 if ((temp
& LVDS_PORT_EN
) == 0)
3256 I915_WRITE(PCH_LVDS
, temp
| LVDS_PORT_EN
);
3260 if (intel_crtc
->config
.has_pch_encoder
) {
3261 /* Note: FDI PLL enabling _must_ be done before we enable the
3262 * cpu pipes, hence this is separate from all the other fdi/pch
3264 ironlake_fdi_pll_enable(intel_crtc
);
3266 assert_fdi_tx_disabled(dev_priv
, pipe
);
3267 assert_fdi_rx_disabled(dev_priv
, pipe
);
3270 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3271 if (encoder
->pre_enable
)
3272 encoder
->pre_enable(encoder
);
3274 /* Enable panel fitting for LVDS */
3275 if (dev_priv
->pch_pf_size
&&
3276 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
3277 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3278 /* Force use of hard-coded filter coefficients
3279 * as some pre-programmed values are broken,
3282 if (IS_IVYBRIDGE(dev
))
3283 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
3284 PF_PIPE_SEL_IVB(pipe
));
3286 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
3287 I915_WRITE(PF_WIN_POS(pipe
), dev_priv
->pch_pf_pos
);
3288 I915_WRITE(PF_WIN_SZ(pipe
), dev_priv
->pch_pf_size
);
3292 * On ILK+ LUT must be loaded before the pipe is running but with
3295 intel_crtc_load_lut(crtc
);
3297 intel_enable_pipe(dev_priv
, pipe
,
3298 intel_crtc
->config
.has_pch_encoder
);
3299 intel_enable_plane(dev_priv
, plane
, pipe
);
3301 if (intel_crtc
->config
.has_pch_encoder
)
3302 ironlake_pch_enable(crtc
);
3304 mutex_lock(&dev
->struct_mutex
);
3305 intel_update_fbc(dev
);
3306 mutex_unlock(&dev
->struct_mutex
);
3308 intel_crtc_update_cursor(crtc
, true);
3310 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3311 encoder
->enable(encoder
);
3313 if (HAS_PCH_CPT(dev
))
3314 intel_cpt_verify_modeset(dev
, intel_crtc
->pipe
);
3317 * There seems to be a race in PCH platform hw (at least on some
3318 * outputs) where an enabled pipe still completes any pageflip right
3319 * away (as if the pipe is off) instead of waiting for vblank. As soon
3320 * as the first vblank happend, everything works as expected. Hence just
3321 * wait for one vblank before returning to avoid strange things
3324 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
3327 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
3329 struct drm_device
*dev
= crtc
->dev
;
3330 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3331 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3332 struct intel_encoder
*encoder
;
3333 int pipe
= intel_crtc
->pipe
;
3334 int plane
= intel_crtc
->plane
;
3336 WARN_ON(!crtc
->enabled
);
3338 if (intel_crtc
->active
)
3341 intel_crtc
->active
= true;
3343 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
3344 if (intel_crtc
->config
.has_pch_encoder
)
3345 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
3347 intel_update_watermarks(dev
);
3349 if (intel_crtc
->config
.has_pch_encoder
)
3350 dev_priv
->display
.fdi_link_train(crtc
);
3352 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3353 if (encoder
->pre_enable
)
3354 encoder
->pre_enable(encoder
);
3356 intel_ddi_enable_pipe_clock(intel_crtc
);
3358 /* Enable panel fitting for eDP */
3359 if (dev_priv
->pch_pf_size
&&
3360 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
)) {
3361 /* Force use of hard-coded filter coefficients
3362 * as some pre-programmed values are broken,
3365 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
3366 PF_PIPE_SEL_IVB(pipe
));
3367 I915_WRITE(PF_WIN_POS(pipe
), dev_priv
->pch_pf_pos
);
3368 I915_WRITE(PF_WIN_SZ(pipe
), dev_priv
->pch_pf_size
);
3372 * On ILK+ LUT must be loaded before the pipe is running but with
3375 intel_crtc_load_lut(crtc
);
3377 intel_ddi_set_pipe_settings(crtc
);
3378 intel_ddi_enable_transcoder_func(crtc
);
3380 intel_enable_pipe(dev_priv
, pipe
,
3381 intel_crtc
->config
.has_pch_encoder
);
3382 intel_enable_plane(dev_priv
, plane
, pipe
);
3384 if (intel_crtc
->config
.has_pch_encoder
)
3385 lpt_pch_enable(crtc
);
3387 mutex_lock(&dev
->struct_mutex
);
3388 intel_update_fbc(dev
);
3389 mutex_unlock(&dev
->struct_mutex
);
3391 intel_crtc_update_cursor(crtc
, true);
3393 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3394 encoder
->enable(encoder
);
3397 * There seems to be a race in PCH platform hw (at least on some
3398 * outputs) where an enabled pipe still completes any pageflip right
3399 * away (as if the pipe is off) instead of waiting for vblank. As soon
3400 * as the first vblank happend, everything works as expected. Hence just
3401 * wait for one vblank before returning to avoid strange things
3404 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
3407 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
3409 struct drm_device
*dev
= crtc
->dev
;
3410 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3411 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3412 struct intel_encoder
*encoder
;
3413 int pipe
= intel_crtc
->pipe
;
3414 int plane
= intel_crtc
->plane
;
3418 if (!intel_crtc
->active
)
3421 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3422 encoder
->disable(encoder
);
3424 intel_crtc_wait_for_pending_flips(crtc
);
3425 drm_vblank_off(dev
, pipe
);
3426 intel_crtc_update_cursor(crtc
, false);
3428 intel_disable_plane(dev_priv
, plane
, pipe
);
3430 if (dev_priv
->cfb_plane
== plane
)
3431 intel_disable_fbc(dev
);
3433 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, false);
3434 intel_disable_pipe(dev_priv
, pipe
);
3437 I915_WRITE(PF_CTL(pipe
), 0);
3438 I915_WRITE(PF_WIN_SZ(pipe
), 0);
3440 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3441 if (encoder
->post_disable
)
3442 encoder
->post_disable(encoder
);
3444 ironlake_fdi_disable(crtc
);
3446 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
3447 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
3449 if (HAS_PCH_CPT(dev
)) {
3450 /* disable TRANS_DP_CTL */
3451 reg
= TRANS_DP_CTL(pipe
);
3452 temp
= I915_READ(reg
);
3453 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
| TRANS_DP_PORT_SEL_MASK
);
3454 temp
|= TRANS_DP_PORT_SEL_NONE
;
3455 I915_WRITE(reg
, temp
);
3457 /* disable DPLL_SEL */
3458 temp
= I915_READ(PCH_DPLL_SEL
);
3461 temp
&= ~(TRANSA_DPLL_ENABLE
| TRANSA_DPLLB_SEL
);
3464 temp
&= ~(TRANSB_DPLL_ENABLE
| TRANSB_DPLLB_SEL
);
3467 /* C shares PLL A or B */
3468 temp
&= ~(TRANSC_DPLL_ENABLE
| TRANSC_DPLLB_SEL
);
3473 I915_WRITE(PCH_DPLL_SEL
, temp
);
3476 /* disable PCH DPLL */
3477 intel_disable_pch_pll(intel_crtc
);
3479 ironlake_fdi_pll_disable(intel_crtc
);
3481 intel_crtc
->active
= false;
3482 intel_update_watermarks(dev
);
3484 mutex_lock(&dev
->struct_mutex
);
3485 intel_update_fbc(dev
);
3486 mutex_unlock(&dev
->struct_mutex
);
3489 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
3491 struct drm_device
*dev
= crtc
->dev
;
3492 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3493 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3494 struct intel_encoder
*encoder
;
3495 int pipe
= intel_crtc
->pipe
;
3496 int plane
= intel_crtc
->plane
;
3497 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
3499 if (!intel_crtc
->active
)
3502 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3503 encoder
->disable(encoder
);
3505 intel_crtc_wait_for_pending_flips(crtc
);
3506 drm_vblank_off(dev
, pipe
);
3507 intel_crtc_update_cursor(crtc
, false);
3509 intel_disable_plane(dev_priv
, plane
, pipe
);
3511 if (dev_priv
->cfb_plane
== plane
)
3512 intel_disable_fbc(dev
);
3514 if (intel_crtc
->config
.has_pch_encoder
)
3515 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, false);
3516 intel_disable_pipe(dev_priv
, pipe
);
3518 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
3520 /* XXX: Once we have proper panel fitter state tracking implemented with
3521 * hardware state read/check support we should switch to only disable
3522 * the panel fitter when we know it's used. */
3523 if (intel_using_power_well(dev
)) {
3524 I915_WRITE(PF_CTL(pipe
), 0);
3525 I915_WRITE(PF_WIN_SZ(pipe
), 0);
3528 intel_ddi_disable_pipe_clock(intel_crtc
);
3530 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3531 if (encoder
->post_disable
)
3532 encoder
->post_disable(encoder
);
3534 if (intel_crtc
->config
.has_pch_encoder
) {
3535 lpt_disable_pch_transcoder(dev_priv
);
3536 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
3537 intel_ddi_fdi_disable(crtc
);
3540 intel_crtc
->active
= false;
3541 intel_update_watermarks(dev
);
3543 mutex_lock(&dev
->struct_mutex
);
3544 intel_update_fbc(dev
);
3545 mutex_unlock(&dev
->struct_mutex
);
3548 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
3550 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3551 intel_put_pch_pll(intel_crtc
);
3554 static void haswell_crtc_off(struct drm_crtc
*crtc
)
3556 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3558 /* Stop saying we're using TRANSCODER_EDP because some other CRTC might
3559 * start using it. */
3560 intel_crtc
->config
.cpu_transcoder
= (enum transcoder
) intel_crtc
->pipe
;
3562 intel_ddi_put_crtc_pll(crtc
);
3565 static void intel_crtc_dpms_overlay(struct intel_crtc
*intel_crtc
, bool enable
)
3567 if (!enable
&& intel_crtc
->overlay
) {
3568 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3569 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3571 mutex_lock(&dev
->struct_mutex
);
3572 dev_priv
->mm
.interruptible
= false;
3573 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
3574 dev_priv
->mm
.interruptible
= true;
3575 mutex_unlock(&dev
->struct_mutex
);
3578 /* Let userspace switch the overlay on again. In most cases userspace
3579 * has to recompute where to put it anyway.
3584 * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
3585 * cursor plane briefly if not already running after enabling the display
3587 * This workaround avoids occasional blank screens when self refresh is
3591 g4x_fixup_plane(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
3593 u32 cntl
= I915_READ(CURCNTR(pipe
));
3595 if ((cntl
& CURSOR_MODE
) == 0) {
3596 u32 fw_bcl_self
= I915_READ(FW_BLC_SELF
);
3598 I915_WRITE(FW_BLC_SELF
, fw_bcl_self
& ~FW_BLC_SELF_EN
);
3599 I915_WRITE(CURCNTR(pipe
), CURSOR_MODE_64_ARGB_AX
);
3600 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
3601 I915_WRITE(CURCNTR(pipe
), cntl
);
3602 I915_WRITE(CURBASE(pipe
), I915_READ(CURBASE(pipe
)));
3603 I915_WRITE(FW_BLC_SELF
, fw_bcl_self
);
3607 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
3609 struct drm_device
*dev
= crtc
->dev
;
3610 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3611 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3612 struct intel_encoder
*encoder
;
3613 int pipe
= intel_crtc
->pipe
;
3614 int plane
= intel_crtc
->plane
;
3616 WARN_ON(!crtc
->enabled
);
3618 if (intel_crtc
->active
)
3621 intel_crtc
->active
= true;
3622 intel_update_watermarks(dev
);
3624 mutex_lock(&dev_priv
->dpio_lock
);
3626 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3627 if (encoder
->pre_pll_enable
)
3628 encoder
->pre_pll_enable(encoder
);
3630 intel_enable_pll(dev_priv
, pipe
);
3632 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3633 if (encoder
->pre_enable
)
3634 encoder
->pre_enable(encoder
);
3636 /* VLV wants encoder enabling _before_ the pipe is up. */
3637 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3638 encoder
->enable(encoder
);
3640 intel_enable_pipe(dev_priv
, pipe
, false);
3641 intel_enable_plane(dev_priv
, plane
, pipe
);
3643 intel_crtc_load_lut(crtc
);
3644 intel_update_fbc(dev
);
3646 /* Give the overlay scaler a chance to enable if it's on this pipe */
3647 intel_crtc_dpms_overlay(intel_crtc
, true);
3648 intel_crtc_update_cursor(crtc
, true);
3650 mutex_unlock(&dev_priv
->dpio_lock
);
3653 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
3655 struct drm_device
*dev
= crtc
->dev
;
3656 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3657 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3658 struct intel_encoder
*encoder
;
3659 int pipe
= intel_crtc
->pipe
;
3660 int plane
= intel_crtc
->plane
;
3662 WARN_ON(!crtc
->enabled
);
3664 if (intel_crtc
->active
)
3667 intel_crtc
->active
= true;
3668 intel_update_watermarks(dev
);
3670 intel_enable_pll(dev_priv
, pipe
);
3672 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3673 if (encoder
->pre_enable
)
3674 encoder
->pre_enable(encoder
);
3676 intel_enable_pipe(dev_priv
, pipe
, false);
3677 intel_enable_plane(dev_priv
, plane
, pipe
);
3679 g4x_fixup_plane(dev_priv
, pipe
);
3681 intel_crtc_load_lut(crtc
);
3682 intel_update_fbc(dev
);
3684 /* Give the overlay scaler a chance to enable if it's on this pipe */
3685 intel_crtc_dpms_overlay(intel_crtc
, true);
3686 intel_crtc_update_cursor(crtc
, true);
3688 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3689 encoder
->enable(encoder
);
3692 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
3694 struct drm_device
*dev
= crtc
->base
.dev
;
3695 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3697 uint32_t pctl
= I915_READ(PFIT_CONTROL
);
3699 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
3701 if (INTEL_INFO(dev
)->gen
>= 4)
3702 pipe
= (pctl
& PFIT_PIPE_MASK
) >> PFIT_PIPE_SHIFT
;
3706 if (pipe
== crtc
->pipe
) {
3707 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", pctl
);
3708 I915_WRITE(PFIT_CONTROL
, 0);
3712 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
3714 struct drm_device
*dev
= crtc
->dev
;
3715 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3716 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3717 struct intel_encoder
*encoder
;
3718 int pipe
= intel_crtc
->pipe
;
3719 int plane
= intel_crtc
->plane
;
3721 if (!intel_crtc
->active
)
3724 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3725 encoder
->disable(encoder
);
3727 /* Give the overlay scaler a chance to disable if it's on this pipe */
3728 intel_crtc_wait_for_pending_flips(crtc
);
3729 drm_vblank_off(dev
, pipe
);
3730 intel_crtc_dpms_overlay(intel_crtc
, false);
3731 intel_crtc_update_cursor(crtc
, false);
3733 if (dev_priv
->cfb_plane
== plane
)
3734 intel_disable_fbc(dev
);
3736 intel_disable_plane(dev_priv
, plane
, pipe
);
3737 intel_disable_pipe(dev_priv
, pipe
);
3739 i9xx_pfit_disable(intel_crtc
);
3741 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3742 if (encoder
->post_disable
)
3743 encoder
->post_disable(encoder
);
3745 intel_disable_pll(dev_priv
, pipe
);
3747 intel_crtc
->active
= false;
3748 intel_update_fbc(dev
);
3749 intel_update_watermarks(dev
);
3752 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
3756 static void intel_crtc_update_sarea(struct drm_crtc
*crtc
,
3759 struct drm_device
*dev
= crtc
->dev
;
3760 struct drm_i915_master_private
*master_priv
;
3761 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3762 int pipe
= intel_crtc
->pipe
;
3764 if (!dev
->primary
->master
)
3767 master_priv
= dev
->primary
->master
->driver_priv
;
3768 if (!master_priv
->sarea_priv
)
3773 master_priv
->sarea_priv
->pipeA_w
= enabled
? crtc
->mode
.hdisplay
: 0;
3774 master_priv
->sarea_priv
->pipeA_h
= enabled
? crtc
->mode
.vdisplay
: 0;
3777 master_priv
->sarea_priv
->pipeB_w
= enabled
? crtc
->mode
.hdisplay
: 0;
3778 master_priv
->sarea_priv
->pipeB_h
= enabled
? crtc
->mode
.vdisplay
: 0;
3781 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe
));
3787 * Sets the power management mode of the pipe and plane.
3789 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
3791 struct drm_device
*dev
= crtc
->dev
;
3792 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3793 struct intel_encoder
*intel_encoder
;
3794 bool enable
= false;
3796 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
3797 enable
|= intel_encoder
->connectors_active
;
3800 dev_priv
->display
.crtc_enable(crtc
);
3802 dev_priv
->display
.crtc_disable(crtc
);
3804 intel_crtc_update_sarea(crtc
, enable
);
3807 static void intel_crtc_disable(struct drm_crtc
*crtc
)
3809 struct drm_device
*dev
= crtc
->dev
;
3810 struct drm_connector
*connector
;
3811 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3812 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3814 /* crtc should still be enabled when we disable it. */
3815 WARN_ON(!crtc
->enabled
);
3817 intel_crtc
->eld_vld
= false;
3818 dev_priv
->display
.crtc_disable(crtc
);
3819 intel_crtc_update_sarea(crtc
, false);
3820 dev_priv
->display
.off(crtc
);
3822 assert_plane_disabled(dev
->dev_private
, to_intel_crtc(crtc
)->plane
);
3823 assert_pipe_disabled(dev
->dev_private
, to_intel_crtc(crtc
)->pipe
);
3826 mutex_lock(&dev
->struct_mutex
);
3827 intel_unpin_fb_obj(to_intel_framebuffer(crtc
->fb
)->obj
);
3828 mutex_unlock(&dev
->struct_mutex
);
3832 /* Update computed state. */
3833 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
3834 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
3837 if (connector
->encoder
->crtc
!= crtc
)
3840 connector
->dpms
= DRM_MODE_DPMS_OFF
;
3841 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
3845 void intel_modeset_disable(struct drm_device
*dev
)
3847 struct drm_crtc
*crtc
;
3849 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
3851 intel_crtc_disable(crtc
);
3855 void intel_encoder_destroy(struct drm_encoder
*encoder
)
3857 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
3859 drm_encoder_cleanup(encoder
);
3860 kfree(intel_encoder
);
3863 /* Simple dpms helper for encodres with just one connector, no cloning and only
3864 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
3865 * state of the entire output pipe. */
3866 void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
3868 if (mode
== DRM_MODE_DPMS_ON
) {
3869 encoder
->connectors_active
= true;
3871 intel_crtc_update_dpms(encoder
->base
.crtc
);
3873 encoder
->connectors_active
= false;
3875 intel_crtc_update_dpms(encoder
->base
.crtc
);
3879 /* Cross check the actual hw state with our own modeset state tracking (and it's
3880 * internal consistency). */
3881 static void intel_connector_check_state(struct intel_connector
*connector
)
3883 if (connector
->get_hw_state(connector
)) {
3884 struct intel_encoder
*encoder
= connector
->encoder
;
3885 struct drm_crtc
*crtc
;
3886 bool encoder_enabled
;
3889 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
3890 connector
->base
.base
.id
,
3891 drm_get_connector_name(&connector
->base
));
3893 WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
3894 "wrong connector dpms state\n");
3895 WARN(connector
->base
.encoder
!= &encoder
->base
,
3896 "active connector not linked to encoder\n");
3897 WARN(!encoder
->connectors_active
,
3898 "encoder->connectors_active not set\n");
3900 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
3901 WARN(!encoder_enabled
, "encoder not enabled\n");
3902 if (WARN_ON(!encoder
->base
.crtc
))
3905 crtc
= encoder
->base
.crtc
;
3907 WARN(!crtc
->enabled
, "crtc not enabled\n");
3908 WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
3909 WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
3910 "encoder active on the wrong pipe\n");
3914 /* Even simpler default implementation, if there's really no special case to
3916 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
3918 struct intel_encoder
*encoder
= intel_attached_encoder(connector
);
3920 /* All the simple cases only support two dpms states. */
3921 if (mode
!= DRM_MODE_DPMS_ON
)
3922 mode
= DRM_MODE_DPMS_OFF
;
3924 if (mode
== connector
->dpms
)
3927 connector
->dpms
= mode
;
3929 /* Only need to change hw state when actually enabled */
3930 if (encoder
->base
.crtc
)
3931 intel_encoder_dpms(encoder
, mode
);
3933 WARN_ON(encoder
->connectors_active
!= false);
3935 intel_modeset_check_state(connector
->dev
);
3938 /* Simple connector->get_hw_state implementation for encoders that support only
3939 * one connector and no cloning and hence the encoder state determines the state
3940 * of the connector. */
3941 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
3944 struct intel_encoder
*encoder
= connector
->encoder
;
3946 return encoder
->get_hw_state(encoder
, &pipe
);
3949 static bool intel_crtc_compute_config(struct drm_crtc
*crtc
,
3950 struct intel_crtc_config
*pipe_config
)
3952 struct drm_device
*dev
= crtc
->dev
;
3953 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
3955 if (HAS_PCH_SPLIT(dev
)) {
3956 /* FDI link clock is fixed at 2.7G */
3957 if (pipe_config
->requested_mode
.clock
* 3
3958 > IRONLAKE_FDI_FREQ
* 4)
3962 /* All interlaced capable intel hw wants timings in frames. Note though
3963 * that intel_lvds_mode_fixup does some funny tricks with the crtc
3964 * timings, so we need to be careful not to clobber these.*/
3965 if (!pipe_config
->timings_set
)
3966 drm_mode_set_crtcinfo(adjusted_mode
, 0);
3968 /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
3969 * with a hsync front porch of 0.
3971 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
3972 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
3975 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) && pipe_config
->pipe_bpp
> 10*3) {
3976 pipe_config
->pipe_bpp
= 10*3; /* 12bpc is gen5+ */
3977 } else if (INTEL_INFO(dev
)->gen
<= 4 && pipe_config
->pipe_bpp
> 8*3) {
3978 /* only a 8bpc pipe, with 6bpc dither through the panel fitter
3980 pipe_config
->pipe_bpp
= 8*3;
3986 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
3988 return 400000; /* FIXME */
3991 static int i945_get_display_clock_speed(struct drm_device
*dev
)
3996 static int i915_get_display_clock_speed(struct drm_device
*dev
)
4001 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
4006 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
4010 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
4012 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
4015 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
4016 case GC_DISPLAY_CLOCK_333_MHZ
:
4019 case GC_DISPLAY_CLOCK_190_200_MHZ
:
4025 static int i865_get_display_clock_speed(struct drm_device
*dev
)
4030 static int i855_get_display_clock_speed(struct drm_device
*dev
)
4033 /* Assume that the hardware is in the high speed state. This
4034 * should be the default.
4036 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
4037 case GC_CLOCK_133_200
:
4038 case GC_CLOCK_100_200
:
4040 case GC_CLOCK_166_250
:
4042 case GC_CLOCK_100_133
:
4046 /* Shouldn't happen */
4050 static int i830_get_display_clock_speed(struct drm_device
*dev
)
4056 intel_reduce_ratio(uint32_t *num
, uint32_t *den
)
4058 while (*num
> 0xffffff || *den
> 0xffffff) {
4065 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
4066 int pixel_clock
, int link_clock
,
4067 struct intel_link_m_n
*m_n
)
4070 m_n
->gmch_m
= bits_per_pixel
* pixel_clock
;
4071 m_n
->gmch_n
= link_clock
* nlanes
* 8;
4072 intel_reduce_ratio(&m_n
->gmch_m
, &m_n
->gmch_n
);
4073 m_n
->link_m
= pixel_clock
;
4074 m_n
->link_n
= link_clock
;
4075 intel_reduce_ratio(&m_n
->link_m
, &m_n
->link_n
);
4078 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
4080 if (i915_panel_use_ssc
>= 0)
4081 return i915_panel_use_ssc
!= 0;
4082 return dev_priv
->lvds_use_ssc
4083 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
4086 static int vlv_get_refclk(struct drm_crtc
*crtc
)
4088 struct drm_device
*dev
= crtc
->dev
;
4089 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4090 int refclk
= 27000; /* for DP & HDMI */
4092 return 100000; /* only one validated so far */
4094 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
4096 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
4097 if (intel_panel_use_ssc(dev_priv
))
4101 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
)) {
4108 static int i9xx_get_refclk(struct drm_crtc
*crtc
, int num_connectors
)
4110 struct drm_device
*dev
= crtc
->dev
;
4111 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4114 if (IS_VALLEYVIEW(dev
)) {
4115 refclk
= vlv_get_refclk(crtc
);
4116 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
4117 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
4118 refclk
= dev_priv
->lvds_ssc_freq
* 1000;
4119 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
4121 } else if (!IS_GEN2(dev
)) {
4130 static void i9xx_adjust_sdvo_tv_clock(struct intel_crtc
*crtc
)
4132 unsigned dotclock
= crtc
->config
.adjusted_mode
.clock
;
4133 struct dpll
*clock
= &crtc
->config
.dpll
;
4135 /* SDVO TV has fixed PLL values depend on its clock range,
4136 this mirrors vbios setting. */
4137 if (dotclock
>= 100000 && dotclock
< 140500) {
4143 } else if (dotclock
>= 140500 && dotclock
<= 200000) {
4151 crtc
->config
.clock_set
= true;
4154 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
4156 return (1 << dpll
->n
) << 16 | dpll
->m1
<< 8 | dpll
->m2
;
4159 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
4161 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
4164 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
4165 intel_clock_t
*reduced_clock
)
4167 struct drm_device
*dev
= crtc
->base
.dev
;
4168 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4169 int pipe
= crtc
->pipe
;
4172 if (IS_PINEVIEW(dev
)) {
4173 fp
= pnv_dpll_compute_fp(&crtc
->config
.dpll
);
4175 fp2
= pnv_dpll_compute_fp(reduced_clock
);
4177 fp
= i9xx_dpll_compute_fp(&crtc
->config
.dpll
);
4179 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
4182 I915_WRITE(FP0(pipe
), fp
);
4184 crtc
->lowfreq_avail
= false;
4185 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
4186 reduced_clock
&& i915_powersave
) {
4187 I915_WRITE(FP1(pipe
), fp2
);
4188 crtc
->lowfreq_avail
= true;
4190 I915_WRITE(FP1(pipe
), fp
);
4194 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
)
4199 * PLLB opamp always calibrates to max value of 0x3f, force enable it
4200 * and set it to a reasonable value instead.
4202 reg_val
= intel_dpio_read(dev_priv
, DPIO_IREF(1));
4203 reg_val
&= 0xffffff00;
4204 reg_val
|= 0x00000030;
4205 intel_dpio_write(dev_priv
, DPIO_IREF(1), reg_val
);
4207 reg_val
= intel_dpio_read(dev_priv
, DPIO_CALIBRATION
);
4208 reg_val
&= 0x8cffffff;
4209 reg_val
= 0x8c000000;
4210 intel_dpio_write(dev_priv
, DPIO_CALIBRATION
, reg_val
);
4212 reg_val
= intel_dpio_read(dev_priv
, DPIO_IREF(1));
4213 reg_val
&= 0xffffff00;
4214 intel_dpio_write(dev_priv
, DPIO_IREF(1), reg_val
);
4216 reg_val
= intel_dpio_read(dev_priv
, DPIO_CALIBRATION
);
4217 reg_val
&= 0x00ffffff;
4218 reg_val
|= 0xb0000000;
4219 intel_dpio_write(dev_priv
, DPIO_CALIBRATION
, reg_val
);
4222 static void intel_dp_set_m_n(struct intel_crtc
*crtc
)
4224 if (crtc
->config
.has_pch_encoder
)
4225 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
4227 intel_cpu_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
4230 static void vlv_update_pll(struct intel_crtc
*crtc
)
4232 struct drm_device
*dev
= crtc
->base
.dev
;
4233 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4234 struct drm_display_mode
*adjusted_mode
=
4235 &crtc
->config
.adjusted_mode
;
4236 struct intel_encoder
*encoder
;
4237 int pipe
= crtc
->pipe
;
4239 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
4241 u32 coreclk
, reg_val
, temp
;
4243 mutex_lock(&dev_priv
->dpio_lock
);
4245 is_hdmi
= intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
);
4247 bestn
= crtc
->config
.dpll
.n
;
4248 bestm1
= crtc
->config
.dpll
.m1
;
4249 bestm2
= crtc
->config
.dpll
.m2
;
4250 bestp1
= crtc
->config
.dpll
.p1
;
4251 bestp2
= crtc
->config
.dpll
.p2
;
4253 /* See eDP HDMI DPIO driver vbios notes doc */
4255 /* PLL B needs special handling */
4257 vlv_pllb_recal_opamp(dev_priv
);
4259 /* Set up Tx target for periodic Rcomp update */
4260 intel_dpio_write(dev_priv
, DPIO_IREF_BCAST
, 0x0100000f);
4262 /* Disable target IRef on PLL */
4263 reg_val
= intel_dpio_read(dev_priv
, DPIO_IREF_CTL(pipe
));
4264 reg_val
&= 0x00ffffff;
4265 intel_dpio_write(dev_priv
, DPIO_IREF_CTL(pipe
), reg_val
);
4267 /* Disable fast lock */
4268 intel_dpio_write(dev_priv
, DPIO_FASTCLK_DISABLE
, 0x610);
4270 /* Set idtafcrecal before PLL is enabled */
4271 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
4272 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
4273 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
4274 mdiv
|= (1 << DPIO_K_SHIFT
);
4275 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
) ||
4276 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
) ||
4277 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
))
4278 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
4279 intel_dpio_write(dev_priv
, DPIO_DIV(pipe
), mdiv
);
4281 mdiv
|= DPIO_ENABLE_CALIBRATION
;
4282 intel_dpio_write(dev_priv
, DPIO_DIV(pipe
), mdiv
);
4284 /* Set HBR and RBR LPF coefficients */
4285 if (adjusted_mode
->clock
== 162000 ||
4286 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
))
4287 intel_dpio_write(dev_priv
, DPIO_LFP_COEFF(pipe
),
4290 intel_dpio_write(dev_priv
, DPIO_LFP_COEFF(pipe
),
4293 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
) ||
4294 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
)) {
4295 /* Use SSC source */
4297 intel_dpio_write(dev_priv
, DPIO_REFSFR(pipe
),
4300 intel_dpio_write(dev_priv
, DPIO_REFSFR(pipe
),
4302 } else { /* HDMI or VGA */
4303 /* Use bend source */
4305 intel_dpio_write(dev_priv
, DPIO_REFSFR(pipe
),
4308 intel_dpio_write(dev_priv
, DPIO_REFSFR(pipe
),
4312 coreclk
= intel_dpio_read(dev_priv
, DPIO_CORE_CLK(pipe
));
4313 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
4314 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
) ||
4315 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
))
4316 coreclk
|= 0x01000000;
4317 intel_dpio_write(dev_priv
, DPIO_CORE_CLK(pipe
), coreclk
);
4319 intel_dpio_write(dev_priv
, DPIO_PLL_CML(pipe
), 0x87871000);
4321 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
4322 if (encoder
->pre_pll_enable
)
4323 encoder
->pre_pll_enable(encoder
);
4325 /* Enable DPIO clock input */
4326 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
4327 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
4329 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
4331 dpll
|= DPLL_VCO_ENABLE
;
4332 I915_WRITE(DPLL(pipe
), dpll
);
4333 POSTING_READ(DPLL(pipe
));
4336 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
4337 DRM_ERROR("DPLL %d failed to lock\n", pipe
);
4341 if (crtc
->config
.pixel_multiplier
> 1) {
4342 temp
= (crtc
->config
.pixel_multiplier
- 1)
4343 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
4346 I915_WRITE(DPLL_MD(pipe
), temp
);
4347 POSTING_READ(DPLL_MD(pipe
));
4350 if (crtc
->config
.has_dp_encoder
)
4351 intel_dp_set_m_n(crtc
);
4353 mutex_unlock(&dev_priv
->dpio_lock
);
4356 static void i9xx_update_pll(struct intel_crtc
*crtc
,
4357 intel_clock_t
*reduced_clock
,
4360 struct drm_device
*dev
= crtc
->base
.dev
;
4361 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4362 struct intel_encoder
*encoder
;
4363 int pipe
= crtc
->pipe
;
4366 struct dpll
*clock
= &crtc
->config
.dpll
;
4368 i9xx_update_pll_dividers(crtc
, reduced_clock
);
4370 is_sdvo
= intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_SDVO
) ||
4371 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
);
4373 dpll
= DPLL_VGA_MODE_DIS
;
4375 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
))
4376 dpll
|= DPLLB_MODE_LVDS
;
4378 dpll
|= DPLLB_MODE_DAC_SERIAL
;
4381 if ((crtc
->config
.pixel_multiplier
> 1) &&
4382 (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
))) {
4383 dpll
|= (crtc
->config
.pixel_multiplier
- 1)
4384 << SDVO_MULTIPLIER_SHIFT_HIRES
;
4386 dpll
|= DPLL_DVO_HIGH_SPEED
;
4388 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
))
4389 dpll
|= DPLL_DVO_HIGH_SPEED
;
4391 /* compute bitmask from p1 value */
4392 if (IS_PINEVIEW(dev
))
4393 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
4395 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
4396 if (IS_G4X(dev
) && reduced_clock
)
4397 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
4399 switch (clock
->p2
) {
4401 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
4404 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
4407 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
4410 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
4413 if (INTEL_INFO(dev
)->gen
>= 4)
4414 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
4416 if (is_sdvo
&& intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_TVOUT
))
4417 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
4418 else if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_TVOUT
))
4419 /* XXX: just matching BIOS for now */
4420 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
4422 else if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
4423 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
4424 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
4426 dpll
|= PLL_REF_INPUT_DREFCLK
;
4428 dpll
|= DPLL_VCO_ENABLE
;
4429 I915_WRITE(DPLL(pipe
), dpll
& ~DPLL_VCO_ENABLE
);
4430 POSTING_READ(DPLL(pipe
));
4433 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
4434 if (encoder
->pre_pll_enable
)
4435 encoder
->pre_pll_enable(encoder
);
4437 if (crtc
->config
.has_dp_encoder
)
4438 intel_dp_set_m_n(crtc
);
4440 I915_WRITE(DPLL(pipe
), dpll
);
4442 /* Wait for the clocks to stabilize. */
4443 POSTING_READ(DPLL(pipe
));
4446 if (INTEL_INFO(dev
)->gen
>= 4) {
4450 if (crtc
->config
.pixel_multiplier
> 1) {
4451 temp
= (crtc
->config
.pixel_multiplier
- 1)
4452 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
4455 I915_WRITE(DPLL_MD(pipe
), temp
);
4457 /* The pixel multiplier can only be updated once the
4458 * DPLL is enabled and the clocks are stable.
4460 * So write it again.
4462 I915_WRITE(DPLL(pipe
), dpll
);
4466 static void i8xx_update_pll(struct intel_crtc
*crtc
,
4467 struct drm_display_mode
*adjusted_mode
,
4468 intel_clock_t
*reduced_clock
,
4471 struct drm_device
*dev
= crtc
->base
.dev
;
4472 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4473 struct intel_encoder
*encoder
;
4474 int pipe
= crtc
->pipe
;
4476 struct dpll
*clock
= &crtc
->config
.dpll
;
4478 i9xx_update_pll_dividers(crtc
, reduced_clock
);
4480 dpll
= DPLL_VGA_MODE_DIS
;
4482 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
)) {
4483 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
4486 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
4488 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
4490 dpll
|= PLL_P2_DIVIDE_BY_4
;
4493 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
4494 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
4495 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
4497 dpll
|= PLL_REF_INPUT_DREFCLK
;
4499 dpll
|= DPLL_VCO_ENABLE
;
4500 I915_WRITE(DPLL(pipe
), dpll
& ~DPLL_VCO_ENABLE
);
4501 POSTING_READ(DPLL(pipe
));
4504 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
4505 if (encoder
->pre_pll_enable
)
4506 encoder
->pre_pll_enable(encoder
);
4508 I915_WRITE(DPLL(pipe
), dpll
);
4510 /* Wait for the clocks to stabilize. */
4511 POSTING_READ(DPLL(pipe
));
4514 /* The pixel multiplier can only be updated once the
4515 * DPLL is enabled and the clocks are stable.
4517 * So write it again.
4519 I915_WRITE(DPLL(pipe
), dpll
);
4522 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
,
4523 struct drm_display_mode
*mode
,
4524 struct drm_display_mode
*adjusted_mode
)
4526 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4527 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4528 enum pipe pipe
= intel_crtc
->pipe
;
4529 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
4530 uint32_t vsyncshift
;
4532 if (!IS_GEN2(dev
) && adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
4533 /* the chip adds 2 halflines automatically */
4534 adjusted_mode
->crtc_vtotal
-= 1;
4535 adjusted_mode
->crtc_vblank_end
-= 1;
4536 vsyncshift
= adjusted_mode
->crtc_hsync_start
4537 - adjusted_mode
->crtc_htotal
/ 2;
4542 if (INTEL_INFO(dev
)->gen
> 3)
4543 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
4545 I915_WRITE(HTOTAL(cpu_transcoder
),
4546 (adjusted_mode
->crtc_hdisplay
- 1) |
4547 ((adjusted_mode
->crtc_htotal
- 1) << 16));
4548 I915_WRITE(HBLANK(cpu_transcoder
),
4549 (adjusted_mode
->crtc_hblank_start
- 1) |
4550 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
4551 I915_WRITE(HSYNC(cpu_transcoder
),
4552 (adjusted_mode
->crtc_hsync_start
- 1) |
4553 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
4555 I915_WRITE(VTOTAL(cpu_transcoder
),
4556 (adjusted_mode
->crtc_vdisplay
- 1) |
4557 ((adjusted_mode
->crtc_vtotal
- 1) << 16));
4558 I915_WRITE(VBLANK(cpu_transcoder
),
4559 (adjusted_mode
->crtc_vblank_start
- 1) |
4560 ((adjusted_mode
->crtc_vblank_end
- 1) << 16));
4561 I915_WRITE(VSYNC(cpu_transcoder
),
4562 (adjusted_mode
->crtc_vsync_start
- 1) |
4563 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
4565 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
4566 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
4567 * documented on the DDI_FUNC_CTL register description, EDP Input Select
4569 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
4570 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
4571 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
4573 /* pipesrc controls the size that is scaled from, which should
4574 * always be the user's requested size.
4576 I915_WRITE(PIPESRC(pipe
),
4577 ((mode
->hdisplay
- 1) << 16) | (mode
->vdisplay
- 1));
4580 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
4582 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4583 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4586 pipeconf
= I915_READ(PIPECONF(intel_crtc
->pipe
));
4588 if (intel_crtc
->pipe
== 0 && INTEL_INFO(dev
)->gen
< 4) {
4589 /* Enable pixel doubling when the dot clock is > 90% of the (display)
4592 * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
4595 if (intel_crtc
->config
.requested_mode
.clock
>
4596 dev_priv
->display
.get_display_clock_speed(dev
) * 9 / 10)
4597 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
4599 pipeconf
&= ~PIPECONF_DOUBLE_WIDE
;
4602 /* default to 8bpc */
4603 pipeconf
&= ~(PIPECONF_BPC_MASK
| PIPECONF_DITHER_EN
);
4604 if (intel_crtc
->config
.has_dp_encoder
) {
4605 if (intel_crtc
->config
.dither
) {
4606 pipeconf
|= PIPECONF_6BPC
|
4607 PIPECONF_DITHER_EN
|
4608 PIPECONF_DITHER_TYPE_SP
;
4612 if (IS_VALLEYVIEW(dev
) && intel_pipe_has_type(&intel_crtc
->base
,
4613 INTEL_OUTPUT_EDP
)) {
4614 if (intel_crtc
->config
.dither
) {
4615 pipeconf
|= PIPECONF_6BPC
|
4617 I965_PIPECONF_ACTIVE
;
4621 if (HAS_PIPE_CXSR(dev
)) {
4622 if (intel_crtc
->lowfreq_avail
) {
4623 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
4624 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
4626 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
4627 pipeconf
&= ~PIPECONF_CXSR_DOWNCLOCK
;
4631 pipeconf
&= ~PIPECONF_INTERLACE_MASK
;
4632 if (!IS_GEN2(dev
) &&
4633 intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
4634 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
4636 pipeconf
|= PIPECONF_PROGRESSIVE
;
4638 if (IS_VALLEYVIEW(dev
)) {
4639 if (intel_crtc
->config
.limited_color_range
)
4640 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
4642 pipeconf
&= ~PIPECONF_COLOR_RANGE_SELECT
;
4645 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
4646 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
4649 static int i9xx_crtc_mode_set(struct drm_crtc
*crtc
,
4651 struct drm_framebuffer
*fb
)
4653 struct drm_device
*dev
= crtc
->dev
;
4654 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4655 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4656 struct drm_display_mode
*adjusted_mode
=
4657 &intel_crtc
->config
.adjusted_mode
;
4658 struct drm_display_mode
*mode
= &intel_crtc
->config
.requested_mode
;
4659 int pipe
= intel_crtc
->pipe
;
4660 int plane
= intel_crtc
->plane
;
4661 int refclk
, num_connectors
= 0;
4662 intel_clock_t clock
, reduced_clock
;
4664 bool ok
, has_reduced_clock
= false, is_sdvo
= false;
4665 bool is_lvds
= false, is_tv
= false;
4666 struct intel_encoder
*encoder
;
4667 const intel_limit_t
*limit
;
4670 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4671 switch (encoder
->type
) {
4672 case INTEL_OUTPUT_LVDS
:
4675 case INTEL_OUTPUT_SDVO
:
4676 case INTEL_OUTPUT_HDMI
:
4678 if (encoder
->needs_tv_clock
)
4681 case INTEL_OUTPUT_TVOUT
:
4689 refclk
= i9xx_get_refclk(crtc
, num_connectors
);
4692 * Returns a set of divisors for the desired target clock with the given
4693 * refclk, or FALSE. The returned values represent the clock equation:
4694 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
4696 limit
= intel_limit(crtc
, refclk
);
4697 ok
= limit
->find_pll(limit
, crtc
, adjusted_mode
->clock
, refclk
, NULL
,
4700 DRM_ERROR("Couldn't find PLL settings for mode!\n");
4704 /* Ensure that the cursor is valid for the new mode before changing... */
4705 intel_crtc_update_cursor(crtc
, true);
4707 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
4709 * Ensure we match the reduced clock's P to the target clock.
4710 * If the clocks don't match, we can't switch the display clock
4711 * by using the FP0/FP1. In such case we will disable the LVDS
4712 * downclock feature.
4714 has_reduced_clock
= limit
->find_pll(limit
, crtc
,
4715 dev_priv
->lvds_downclock
,
4720 /* Compat-code for transition, will disappear. */
4721 if (!intel_crtc
->config
.clock_set
) {
4722 intel_crtc
->config
.dpll
.n
= clock
.n
;
4723 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
4724 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
4725 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
4726 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
4729 if (is_sdvo
&& is_tv
)
4730 i9xx_adjust_sdvo_tv_clock(intel_crtc
);
4733 i8xx_update_pll(intel_crtc
, adjusted_mode
,
4734 has_reduced_clock
? &reduced_clock
: NULL
,
4736 else if (IS_VALLEYVIEW(dev
))
4737 vlv_update_pll(intel_crtc
);
4739 i9xx_update_pll(intel_crtc
,
4740 has_reduced_clock
? &reduced_clock
: NULL
,
4743 /* Set up the display plane register */
4744 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
4746 if (!IS_VALLEYVIEW(dev
)) {
4748 dspcntr
&= ~DISPPLANE_SEL_PIPE_MASK
;
4750 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
4753 DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe_name(pipe
));
4754 drm_mode_debug_printmodeline(mode
);
4756 intel_set_pipe_timings(intel_crtc
, mode
, adjusted_mode
);
4758 /* pipesrc and dspsize control the size that is scaled from,
4759 * which should always be the user's requested size.
4761 I915_WRITE(DSPSIZE(plane
),
4762 ((mode
->vdisplay
- 1) << 16) |
4763 (mode
->hdisplay
- 1));
4764 I915_WRITE(DSPPOS(plane
), 0);
4766 i9xx_set_pipeconf(intel_crtc
);
4768 I915_WRITE(DSPCNTR(plane
), dspcntr
);
4769 POSTING_READ(DSPCNTR(plane
));
4771 ret
= intel_pipe_set_base(crtc
, x
, y
, fb
);
4773 intel_update_watermarks(dev
);
4778 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
4779 struct intel_crtc_config
*pipe_config
)
4781 struct drm_device
*dev
= crtc
->base
.dev
;
4782 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4785 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
4786 if (!(tmp
& PIPECONF_ENABLE
))
4792 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
4794 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4795 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
4796 struct intel_encoder
*encoder
;
4798 bool has_lvds
= false;
4799 bool has_cpu_edp
= false;
4800 bool has_pch_edp
= false;
4801 bool has_panel
= false;
4802 bool has_ck505
= false;
4803 bool can_ssc
= false;
4805 /* We need to take the global config into account */
4806 list_for_each_entry(encoder
, &mode_config
->encoder_list
,
4808 switch (encoder
->type
) {
4809 case INTEL_OUTPUT_LVDS
:
4813 case INTEL_OUTPUT_EDP
:
4815 if (intel_encoder_is_pch_edp(&encoder
->base
))
4823 if (HAS_PCH_IBX(dev
)) {
4824 has_ck505
= dev_priv
->display_clock_mode
;
4825 can_ssc
= has_ck505
;
4831 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n",
4832 has_panel
, has_lvds
, has_pch_edp
, has_cpu_edp
,
4835 /* Ironlake: try to setup display ref clock before DPLL
4836 * enabling. This is only under driver's control after
4837 * PCH B stepping, previous chipset stepping should be
4838 * ignoring this setting.
4840 val
= I915_READ(PCH_DREF_CONTROL
);
4842 /* As we must carefully and slowly disable/enable each source in turn,
4843 * compute the final state we want first and check if we need to
4844 * make any changes at all.
4847 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
4849 final
|= DREF_NONSPREAD_CK505_ENABLE
;
4851 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
4853 final
&= ~DREF_SSC_SOURCE_MASK
;
4854 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
4855 final
&= ~DREF_SSC1_ENABLE
;
4858 final
|= DREF_SSC_SOURCE_ENABLE
;
4860 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
4861 final
|= DREF_SSC1_ENABLE
;
4864 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
4865 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
4867 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
4869 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
4871 final
|= DREF_SSC_SOURCE_DISABLE
;
4872 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
4878 /* Always enable nonspread source */
4879 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
4882 val
|= DREF_NONSPREAD_CK505_ENABLE
;
4884 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
4887 val
&= ~DREF_SSC_SOURCE_MASK
;
4888 val
|= DREF_SSC_SOURCE_ENABLE
;
4890 /* SSC must be turned on before enabling the CPU output */
4891 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
4892 DRM_DEBUG_KMS("Using SSC on panel\n");
4893 val
|= DREF_SSC1_ENABLE
;
4895 val
&= ~DREF_SSC1_ENABLE
;
4897 /* Get SSC going before enabling the outputs */
4898 I915_WRITE(PCH_DREF_CONTROL
, val
);
4899 POSTING_READ(PCH_DREF_CONTROL
);
4902 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
4904 /* Enable CPU source on CPU attached eDP */
4906 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
4907 DRM_DEBUG_KMS("Using SSC on eDP\n");
4908 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
4911 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
4913 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
4915 I915_WRITE(PCH_DREF_CONTROL
, val
);
4916 POSTING_READ(PCH_DREF_CONTROL
);
4919 DRM_DEBUG_KMS("Disabling SSC entirely\n");
4921 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
4923 /* Turn off CPU output */
4924 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
4926 I915_WRITE(PCH_DREF_CONTROL
, val
);
4927 POSTING_READ(PCH_DREF_CONTROL
);
4930 /* Turn off the SSC source */
4931 val
&= ~DREF_SSC_SOURCE_MASK
;
4932 val
|= DREF_SSC_SOURCE_DISABLE
;
4935 val
&= ~DREF_SSC1_ENABLE
;
4937 I915_WRITE(PCH_DREF_CONTROL
, val
);
4938 POSTING_READ(PCH_DREF_CONTROL
);
4942 BUG_ON(val
!= final
);
4945 /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
4946 static void lpt_init_pch_refclk(struct drm_device
*dev
)
4948 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4949 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
4950 struct intel_encoder
*encoder
;
4951 bool has_vga
= false;
4952 bool is_sdv
= false;
4955 list_for_each_entry(encoder
, &mode_config
->encoder_list
, base
.head
) {
4956 switch (encoder
->type
) {
4957 case INTEL_OUTPUT_ANALOG
:
4966 mutex_lock(&dev_priv
->dpio_lock
);
4968 /* XXX: Rip out SDV support once Haswell ships for real. */
4969 if (IS_HASWELL(dev
) && (dev
->pci_device
& 0xFF00) == 0x0C00)
4972 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
4973 tmp
&= ~SBI_SSCCTL_DISABLE
;
4974 tmp
|= SBI_SSCCTL_PATHALT
;
4975 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
4979 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
4980 tmp
&= ~SBI_SSCCTL_PATHALT
;
4981 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
4984 tmp
= I915_READ(SOUTH_CHICKEN2
);
4985 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
4986 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
4988 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
4989 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
4990 DRM_ERROR("FDI mPHY reset assert timeout\n");
4992 tmp
= I915_READ(SOUTH_CHICKEN2
);
4993 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
4994 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
4996 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
4997 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0,
4999 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
5002 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
5003 tmp
&= ~(0xFF << 24);
5004 tmp
|= (0x12 << 24);
5005 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
5008 tmp
= intel_sbi_read(dev_priv
, 0x800C, SBI_MPHY
);
5010 intel_sbi_write(dev_priv
, 0x800C, tmp
, SBI_MPHY
);
5013 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
5015 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
5017 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
5019 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
5022 tmp
= intel_sbi_read(dev_priv
, 0x2038, SBI_MPHY
);
5023 tmp
|= (0x3F << 24) | (0xF << 20) | (0xF << 16);
5024 intel_sbi_write(dev_priv
, 0x2038, tmp
, SBI_MPHY
);
5026 tmp
= intel_sbi_read(dev_priv
, 0x2138, SBI_MPHY
);
5027 tmp
|= (0x3F << 24) | (0xF << 20) | (0xF << 16);
5028 intel_sbi_write(dev_priv
, 0x2138, tmp
, SBI_MPHY
);
5030 tmp
= intel_sbi_read(dev_priv
, 0x203C, SBI_MPHY
);
5032 intel_sbi_write(dev_priv
, 0x203C, tmp
, SBI_MPHY
);
5034 tmp
= intel_sbi_read(dev_priv
, 0x213C, SBI_MPHY
);
5036 intel_sbi_write(dev_priv
, 0x213C, tmp
, SBI_MPHY
);
5039 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
5040 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
5041 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
5043 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
5044 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
5045 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
5048 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
5051 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
5053 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
5056 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
5059 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
5062 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
5064 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
5067 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
5069 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
5070 tmp
&= ~(0xFF << 16);
5071 tmp
|= (0x1C << 16);
5072 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
5074 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
5075 tmp
&= ~(0xFF << 16);
5076 tmp
|= (0x1C << 16);
5077 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
5080 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
5082 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
5084 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
5086 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
5088 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
5089 tmp
&= ~(0xF << 28);
5091 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
5093 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
5094 tmp
&= ~(0xF << 28);
5096 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
5099 /* ULT uses SBI_GEN0, but ULT doesn't have VGA, so we don't care. */
5100 tmp
= intel_sbi_read(dev_priv
, SBI_DBUFF0
, SBI_ICLK
);
5101 tmp
|= SBI_DBUFF0_ENABLE
;
5102 intel_sbi_write(dev_priv
, SBI_DBUFF0
, tmp
, SBI_ICLK
);
5104 mutex_unlock(&dev_priv
->dpio_lock
);
5108 * Initialize reference clocks when the driver loads
5110 void intel_init_pch_refclk(struct drm_device
*dev
)
5112 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
5113 ironlake_init_pch_refclk(dev
);
5114 else if (HAS_PCH_LPT(dev
))
5115 lpt_init_pch_refclk(dev
);
5118 static int ironlake_get_refclk(struct drm_crtc
*crtc
)
5120 struct drm_device
*dev
= crtc
->dev
;
5121 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5122 struct intel_encoder
*encoder
;
5123 struct intel_encoder
*edp_encoder
= NULL
;
5124 int num_connectors
= 0;
5125 bool is_lvds
= false;
5127 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5128 switch (encoder
->type
) {
5129 case INTEL_OUTPUT_LVDS
:
5132 case INTEL_OUTPUT_EDP
:
5133 edp_encoder
= encoder
;
5139 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
5140 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
5141 dev_priv
->lvds_ssc_freq
);
5142 return dev_priv
->lvds_ssc_freq
* 1000;
5148 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
,
5149 struct drm_display_mode
*adjusted_mode
)
5151 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
5152 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5153 int pipe
= intel_crtc
->pipe
;
5156 val
= I915_READ(PIPECONF(pipe
));
5158 val
&= ~PIPECONF_BPC_MASK
;
5159 switch (intel_crtc
->config
.pipe_bpp
) {
5161 val
|= PIPECONF_6BPC
;
5164 val
|= PIPECONF_8BPC
;
5167 val
|= PIPECONF_10BPC
;
5170 val
|= PIPECONF_12BPC
;
5173 /* Case prevented by intel_choose_pipe_bpp_dither. */
5177 val
&= ~(PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_MASK
);
5178 if (intel_crtc
->config
.dither
)
5179 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
5181 val
&= ~PIPECONF_INTERLACE_MASK
;
5182 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
5183 val
|= PIPECONF_INTERLACED_ILK
;
5185 val
|= PIPECONF_PROGRESSIVE
;
5187 if (intel_crtc
->config
.limited_color_range
)
5188 val
|= PIPECONF_COLOR_RANGE_SELECT
;
5190 val
&= ~PIPECONF_COLOR_RANGE_SELECT
;
5192 I915_WRITE(PIPECONF(pipe
), val
);
5193 POSTING_READ(PIPECONF(pipe
));
5197 * Set up the pipe CSC unit.
5199 * Currently only full range RGB to limited range RGB conversion
5200 * is supported, but eventually this should handle various
5201 * RGB<->YCbCr scenarios as well.
5203 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
5205 struct drm_device
*dev
= crtc
->dev
;
5206 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5207 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5208 int pipe
= intel_crtc
->pipe
;
5209 uint16_t coeff
= 0x7800; /* 1.0 */
5212 * TODO: Check what kind of values actually come out of the pipe
5213 * with these coeff/postoff values and adjust to get the best
5214 * accuracy. Perhaps we even need to take the bpc value into
5218 if (intel_crtc
->config
.limited_color_range
)
5219 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
5222 * GY/GU and RY/RU should be the other way around according
5223 * to BSpec, but reality doesn't agree. Just set them up in
5224 * a way that results in the correct picture.
5226 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
5227 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
5229 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
5230 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
5232 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
5233 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
5235 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
5236 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
5237 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
5239 if (INTEL_INFO(dev
)->gen
> 6) {
5240 uint16_t postoff
= 0;
5242 if (intel_crtc
->config
.limited_color_range
)
5243 postoff
= (16 * (1 << 13) / 255) & 0x1fff;
5245 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
5246 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
5247 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
5249 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
5251 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
5253 if (intel_crtc
->config
.limited_color_range
)
5254 mode
|= CSC_BLACK_SCREEN_OFFSET
;
5256 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
5260 static void haswell_set_pipeconf(struct drm_crtc
*crtc
,
5261 struct drm_display_mode
*adjusted_mode
)
5263 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
5264 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5265 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
5268 val
= I915_READ(PIPECONF(cpu_transcoder
));
5270 val
&= ~(PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_MASK
);
5271 if (intel_crtc
->config
.dither
)
5272 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
5274 val
&= ~PIPECONF_INTERLACE_MASK_HSW
;
5275 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
5276 val
|= PIPECONF_INTERLACED_ILK
;
5278 val
|= PIPECONF_PROGRESSIVE
;
5280 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
5281 POSTING_READ(PIPECONF(cpu_transcoder
));
5284 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
5285 struct drm_display_mode
*adjusted_mode
,
5286 intel_clock_t
*clock
,
5287 bool *has_reduced_clock
,
5288 intel_clock_t
*reduced_clock
)
5290 struct drm_device
*dev
= crtc
->dev
;
5291 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5292 struct intel_encoder
*intel_encoder
;
5294 const intel_limit_t
*limit
;
5295 bool ret
, is_sdvo
= false, is_tv
= false, is_lvds
= false;
5297 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
5298 switch (intel_encoder
->type
) {
5299 case INTEL_OUTPUT_LVDS
:
5302 case INTEL_OUTPUT_SDVO
:
5303 case INTEL_OUTPUT_HDMI
:
5305 if (intel_encoder
->needs_tv_clock
)
5308 case INTEL_OUTPUT_TVOUT
:
5314 refclk
= ironlake_get_refclk(crtc
);
5317 * Returns a set of divisors for the desired target clock with the given
5318 * refclk, or FALSE. The returned values represent the clock equation:
5319 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
5321 limit
= intel_limit(crtc
, refclk
);
5322 ret
= limit
->find_pll(limit
, crtc
, adjusted_mode
->clock
, refclk
, NULL
,
5327 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
5329 * Ensure we match the reduced clock's P to the target clock.
5330 * If the clocks don't match, we can't switch the display clock
5331 * by using the FP0/FP1. In such case we will disable the LVDS
5332 * downclock feature.
5334 *has_reduced_clock
= limit
->find_pll(limit
, crtc
,
5335 dev_priv
->lvds_downclock
,
5341 if (is_sdvo
&& is_tv
)
5342 i9xx_adjust_sdvo_tv_clock(to_intel_crtc(crtc
));
5347 static void cpt_enable_fdi_bc_bifurcation(struct drm_device
*dev
)
5349 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5352 temp
= I915_READ(SOUTH_CHICKEN1
);
5353 if (temp
& FDI_BC_BIFURCATION_SELECT
)
5356 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
5357 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
5359 temp
|= FDI_BC_BIFURCATION_SELECT
;
5360 DRM_DEBUG_KMS("enabling fdi C rx\n");
5361 I915_WRITE(SOUTH_CHICKEN1
, temp
);
5362 POSTING_READ(SOUTH_CHICKEN1
);
5365 static bool ironlake_check_fdi_lanes(struct intel_crtc
*intel_crtc
)
5367 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5368 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5369 struct intel_crtc
*pipe_B_crtc
=
5370 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
5372 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
5373 pipe_name(intel_crtc
->pipe
), intel_crtc
->fdi_lanes
);
5374 if (intel_crtc
->fdi_lanes
> 4) {
5375 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
5376 pipe_name(intel_crtc
->pipe
), intel_crtc
->fdi_lanes
);
5377 /* Clamp lanes to avoid programming the hw with bogus values. */
5378 intel_crtc
->fdi_lanes
= 4;
5383 if (INTEL_INFO(dev
)->num_pipes
== 2)
5386 switch (intel_crtc
->pipe
) {
5390 if (dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]->enabled
&&
5391 intel_crtc
->fdi_lanes
> 2) {
5392 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5393 pipe_name(intel_crtc
->pipe
), intel_crtc
->fdi_lanes
);
5394 /* Clamp lanes to avoid programming the hw with bogus values. */
5395 intel_crtc
->fdi_lanes
= 2;
5400 if (intel_crtc
->fdi_lanes
> 2)
5401 WARN_ON(I915_READ(SOUTH_CHICKEN1
) & FDI_BC_BIFURCATION_SELECT
);
5403 cpt_enable_fdi_bc_bifurcation(dev
);
5407 if (!pipe_B_crtc
->base
.enabled
|| pipe_B_crtc
->fdi_lanes
<= 2) {
5408 if (intel_crtc
->fdi_lanes
> 2) {
5409 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5410 pipe_name(intel_crtc
->pipe
), intel_crtc
->fdi_lanes
);
5411 /* Clamp lanes to avoid programming the hw with bogus values. */
5412 intel_crtc
->fdi_lanes
= 2;
5417 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5421 cpt_enable_fdi_bc_bifurcation(dev
);
5429 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
5432 * Account for spread spectrum to avoid
5433 * oversubscribing the link. Max center spread
5434 * is 2.5%; use 5% for safety's sake.
5436 u32 bps
= target_clock
* bpp
* 21 / 20;
5437 return bps
/ (link_bw
* 8) + 1;
5440 void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
5441 struct intel_link_m_n
*m_n
)
5443 struct drm_device
*dev
= crtc
->base
.dev
;
5444 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5445 int pipe
= crtc
->pipe
;
5447 I915_WRITE(TRANSDATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5448 I915_WRITE(TRANSDATA_N1(pipe
), m_n
->gmch_n
);
5449 I915_WRITE(TRANSDPLINK_M1(pipe
), m_n
->link_m
);
5450 I915_WRITE(TRANSDPLINK_N1(pipe
), m_n
->link_n
);
5453 void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
5454 struct intel_link_m_n
*m_n
)
5456 struct drm_device
*dev
= crtc
->base
.dev
;
5457 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5458 int pipe
= crtc
->pipe
;
5459 enum transcoder transcoder
= crtc
->config
.cpu_transcoder
;
5461 if (INTEL_INFO(dev
)->gen
>= 5) {
5462 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5463 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
5464 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
5465 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
5467 I915_WRITE(PIPE_GMCH_DATA_M(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5468 I915_WRITE(PIPE_GMCH_DATA_N(pipe
), m_n
->gmch_n
);
5469 I915_WRITE(PIPE_DP_LINK_M(pipe
), m_n
->link_m
);
5470 I915_WRITE(PIPE_DP_LINK_N(pipe
), m_n
->link_n
);
5474 static void ironlake_fdi_set_m_n(struct drm_crtc
*crtc
)
5476 struct drm_device
*dev
= crtc
->dev
;
5477 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5478 struct drm_display_mode
*adjusted_mode
=
5479 &intel_crtc
->config
.adjusted_mode
;
5480 struct intel_link_m_n m_n
= {0};
5481 int target_clock
, lane
, link_bw
;
5483 /* FDI is a binary signal running at ~2.7GHz, encoding
5484 * each output octet as 10 bits. The actual frequency
5485 * is stored as a divider into a 100MHz clock, and the
5486 * mode pixel clock is stored in units of 1KHz.
5487 * Hence the bw of each lane in terms of the mode signal
5490 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
5492 if (intel_crtc
->config
.pixel_target_clock
)
5493 target_clock
= intel_crtc
->config
.pixel_target_clock
;
5495 target_clock
= adjusted_mode
->clock
;
5497 lane
= ironlake_get_lanes_required(target_clock
, link_bw
,
5498 intel_crtc
->config
.pipe_bpp
);
5500 intel_crtc
->fdi_lanes
= lane
;
5502 if (intel_crtc
->config
.pixel_multiplier
> 1)
5503 link_bw
*= intel_crtc
->config
.pixel_multiplier
;
5504 intel_link_compute_m_n(intel_crtc
->config
.pipe_bpp
, lane
, target_clock
,
5507 intel_cpu_transcoder_set_m_n(intel_crtc
, &m_n
);
5510 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
5512 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
5515 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
5517 intel_clock_t
*reduced_clock
, u32
*fp2
)
5519 struct drm_crtc
*crtc
= &intel_crtc
->base
;
5520 struct drm_device
*dev
= crtc
->dev
;
5521 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5522 struct intel_encoder
*intel_encoder
;
5524 int factor
, num_connectors
= 0;
5525 bool is_lvds
= false, is_sdvo
= false, is_tv
= false;
5527 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
5528 switch (intel_encoder
->type
) {
5529 case INTEL_OUTPUT_LVDS
:
5532 case INTEL_OUTPUT_SDVO
:
5533 case INTEL_OUTPUT_HDMI
:
5535 if (intel_encoder
->needs_tv_clock
)
5538 case INTEL_OUTPUT_TVOUT
:
5546 /* Enable autotuning of the PLL clock (if permissible) */
5549 if ((intel_panel_use_ssc(dev_priv
) &&
5550 dev_priv
->lvds_ssc_freq
== 100) ||
5551 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
5553 } else if (is_sdvo
&& is_tv
)
5556 if (ironlake_needs_fb_cb_tune(&intel_crtc
->config
.dpll
, factor
))
5559 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
5565 dpll
|= DPLLB_MODE_LVDS
;
5567 dpll
|= DPLLB_MODE_DAC_SERIAL
;
5569 if (intel_crtc
->config
.pixel_multiplier
> 1) {
5570 dpll
|= (intel_crtc
->config
.pixel_multiplier
- 1)
5571 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
5573 dpll
|= DPLL_DVO_HIGH_SPEED
;
5575 if (intel_crtc
->config
.has_dp_encoder
&&
5576 intel_crtc
->config
.has_pch_encoder
)
5577 dpll
|= DPLL_DVO_HIGH_SPEED
;
5579 /* compute bitmask from p1 value */
5580 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5582 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
5584 switch (intel_crtc
->config
.dpll
.p2
) {
5586 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
5589 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
5592 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
5595 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
5599 if (is_sdvo
&& is_tv
)
5600 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
5602 /* XXX: just matching BIOS for now */
5603 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
5605 else if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5606 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5608 dpll
|= PLL_REF_INPUT_DREFCLK
;
5613 static int ironlake_crtc_mode_set(struct drm_crtc
*crtc
,
5615 struct drm_framebuffer
*fb
)
5617 struct drm_device
*dev
= crtc
->dev
;
5618 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5619 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5620 struct drm_display_mode
*adjusted_mode
=
5621 &intel_crtc
->config
.adjusted_mode
;
5622 struct drm_display_mode
*mode
= &intel_crtc
->config
.requested_mode
;
5623 int pipe
= intel_crtc
->pipe
;
5624 int plane
= intel_crtc
->plane
;
5625 int num_connectors
= 0;
5626 intel_clock_t clock
, reduced_clock
;
5627 u32 dpll
= 0, fp
= 0, fp2
= 0;
5628 bool ok
, has_reduced_clock
= false;
5629 bool is_lvds
= false;
5630 struct intel_encoder
*encoder
;
5634 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5635 switch (encoder
->type
) {
5636 case INTEL_OUTPUT_LVDS
:
5644 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
5645 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
5647 intel_crtc
->config
.cpu_transcoder
= pipe
;
5649 ok
= ironlake_compute_clocks(crtc
, adjusted_mode
, &clock
,
5650 &has_reduced_clock
, &reduced_clock
);
5652 DRM_ERROR("Couldn't find PLL settings for mode!\n");
5655 /* Compat-code for transition, will disappear. */
5656 if (!intel_crtc
->config
.clock_set
) {
5657 intel_crtc
->config
.dpll
.n
= clock
.n
;
5658 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
5659 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
5660 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
5661 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
5664 /* Ensure that the cursor is valid for the new mode before changing... */
5665 intel_crtc_update_cursor(crtc
, true);
5667 DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe_name(pipe
));
5668 drm_mode_debug_printmodeline(mode
);
5670 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
5671 if (intel_crtc
->config
.has_pch_encoder
) {
5672 struct intel_pch_pll
*pll
;
5674 fp
= i9xx_dpll_compute_fp(&intel_crtc
->config
.dpll
);
5675 if (has_reduced_clock
)
5676 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
5678 dpll
= ironlake_compute_dpll(intel_crtc
,
5679 &fp
, &reduced_clock
,
5680 has_reduced_clock
? &fp2
: NULL
);
5682 pll
= intel_get_pch_pll(intel_crtc
, dpll
, fp
);
5684 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
5689 intel_put_pch_pll(intel_crtc
);
5691 if (intel_crtc
->config
.has_dp_encoder
)
5692 intel_dp_set_m_n(intel_crtc
);
5694 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
5695 if (encoder
->pre_pll_enable
)
5696 encoder
->pre_pll_enable(encoder
);
5698 if (intel_crtc
->pch_pll
) {
5699 I915_WRITE(intel_crtc
->pch_pll
->pll_reg
, dpll
);
5701 /* Wait for the clocks to stabilize. */
5702 POSTING_READ(intel_crtc
->pch_pll
->pll_reg
);
5705 /* The pixel multiplier can only be updated once the
5706 * DPLL is enabled and the clocks are stable.
5708 * So write it again.
5710 I915_WRITE(intel_crtc
->pch_pll
->pll_reg
, dpll
);
5713 intel_crtc
->lowfreq_avail
= false;
5714 if (intel_crtc
->pch_pll
) {
5715 if (is_lvds
&& has_reduced_clock
&& i915_powersave
) {
5716 I915_WRITE(intel_crtc
->pch_pll
->fp1_reg
, fp2
);
5717 intel_crtc
->lowfreq_avail
= true;
5719 I915_WRITE(intel_crtc
->pch_pll
->fp1_reg
, fp
);
5723 intel_set_pipe_timings(intel_crtc
, mode
, adjusted_mode
);
5725 /* Note, this also computes intel_crtc->fdi_lanes which is used below in
5726 * ironlake_check_fdi_lanes. */
5727 intel_crtc
->fdi_lanes
= 0;
5728 if (intel_crtc
->config
.has_pch_encoder
)
5729 ironlake_fdi_set_m_n(crtc
);
5731 fdi_config_ok
= ironlake_check_fdi_lanes(intel_crtc
);
5733 ironlake_set_pipeconf(crtc
, adjusted_mode
);
5735 /* Set up the display plane register */
5736 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
);
5737 POSTING_READ(DSPCNTR(plane
));
5739 ret
= intel_pipe_set_base(crtc
, x
, y
, fb
);
5741 intel_update_watermarks(dev
);
5743 intel_update_linetime_watermarks(dev
, pipe
, adjusted_mode
);
5745 return fdi_config_ok
? ret
: -EINVAL
;
5748 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
5749 struct intel_crtc_config
*pipe_config
)
5751 struct drm_device
*dev
= crtc
->base
.dev
;
5752 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5755 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
5756 if (!(tmp
& PIPECONF_ENABLE
))
5759 if (I915_READ(TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
)
5760 pipe_config
->has_pch_encoder
= true;
5765 static void haswell_modeset_global_resources(struct drm_device
*dev
)
5767 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5768 bool enable
= false;
5769 struct intel_crtc
*crtc
;
5770 struct intel_encoder
*encoder
;
5772 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, base
.head
) {
5773 if (crtc
->pipe
!= PIPE_A
&& crtc
->base
.enabled
)
5775 /* XXX: Should check for edp transcoder here, but thanks to init
5776 * sequence that's not yet available. Just in case desktop eDP
5777 * on PORT D is possible on haswell, too. */
5780 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
5782 if (encoder
->type
!= INTEL_OUTPUT_EDP
&&
5783 encoder
->connectors_active
)
5787 /* Even the eDP panel fitter is outside the always-on well. */
5788 if (dev_priv
->pch_pf_size
)
5791 intel_set_power_well(dev
, enable
);
5794 static int haswell_crtc_mode_set(struct drm_crtc
*crtc
,
5796 struct drm_framebuffer
*fb
)
5798 struct drm_device
*dev
= crtc
->dev
;
5799 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5800 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5801 struct drm_display_mode
*adjusted_mode
=
5802 &intel_crtc
->config
.adjusted_mode
;
5803 struct drm_display_mode
*mode
= &intel_crtc
->config
.requested_mode
;
5804 int pipe
= intel_crtc
->pipe
;
5805 int plane
= intel_crtc
->plane
;
5806 int num_connectors
= 0;
5807 bool is_cpu_edp
= false;
5808 struct intel_encoder
*encoder
;
5811 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5812 switch (encoder
->type
) {
5813 case INTEL_OUTPUT_EDP
:
5814 if (!intel_encoder_is_pch_edp(&encoder
->base
))
5823 intel_crtc
->config
.cpu_transcoder
= TRANSCODER_EDP
;
5825 intel_crtc
->config
.cpu_transcoder
= pipe
;
5827 /* We are not sure yet this won't happen. */
5828 WARN(!HAS_PCH_LPT(dev
), "Unexpected PCH type %d\n",
5829 INTEL_PCH_TYPE(dev
));
5831 WARN(num_connectors
!= 1, "%d connectors attached to pipe %c\n",
5832 num_connectors
, pipe_name(pipe
));
5834 WARN_ON(I915_READ(PIPECONF(intel_crtc
->config
.cpu_transcoder
)) &
5835 (PIPECONF_ENABLE
| I965_PIPECONF_ACTIVE
));
5837 WARN_ON(I915_READ(DSPCNTR(plane
)) & DISPLAY_PLANE_ENABLE
);
5839 if (!intel_ddi_pll_mode_set(crtc
, adjusted_mode
->clock
))
5842 /* Ensure that the cursor is valid for the new mode before changing... */
5843 intel_crtc_update_cursor(crtc
, true);
5845 DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe_name(pipe
));
5846 drm_mode_debug_printmodeline(mode
);
5848 if (intel_crtc
->config
.has_dp_encoder
)
5849 intel_dp_set_m_n(intel_crtc
);
5851 intel_crtc
->lowfreq_avail
= false;
5853 intel_set_pipe_timings(intel_crtc
, mode
, adjusted_mode
);
5855 if (intel_crtc
->config
.has_pch_encoder
)
5856 ironlake_fdi_set_m_n(crtc
);
5858 haswell_set_pipeconf(crtc
, adjusted_mode
);
5860 intel_set_pipe_csc(crtc
);
5862 /* Set up the display plane register */
5863 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
| DISPPLANE_PIPE_CSC_ENABLE
);
5864 POSTING_READ(DSPCNTR(plane
));
5866 ret
= intel_pipe_set_base(crtc
, x
, y
, fb
);
5868 intel_update_watermarks(dev
);
5870 intel_update_linetime_watermarks(dev
, pipe
, adjusted_mode
);
5875 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
5876 struct intel_crtc_config
*pipe_config
)
5878 struct drm_device
*dev
= crtc
->base
.dev
;
5879 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5880 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
5883 if (!intel_using_power_well(dev_priv
->dev
) &&
5884 cpu_transcoder
!= TRANSCODER_EDP
)
5887 tmp
= I915_READ(PIPECONF(cpu_transcoder
));
5888 if (!(tmp
& PIPECONF_ENABLE
))
5892 * Haswell has only FDI/PCH transcoder A. It is which is connected to
5893 * DDI E. So just check whether this pipe is wired to DDI E and whether
5894 * the PCH transcoder is on.
5896 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
5897 if ((tmp
& TRANS_DDI_PORT_MASK
) == TRANS_DDI_SELECT_PORT(PORT_E
) &&
5898 I915_READ(TRANSCONF(PIPE_A
)) & TRANS_ENABLE
)
5899 pipe_config
->has_pch_encoder
= true;
5904 static int intel_crtc_mode_set(struct drm_crtc
*crtc
,
5906 struct drm_framebuffer
*fb
)
5908 struct drm_device
*dev
= crtc
->dev
;
5909 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5910 struct drm_encoder_helper_funcs
*encoder_funcs
;
5911 struct intel_encoder
*encoder
;
5912 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5913 struct drm_display_mode
*adjusted_mode
=
5914 &intel_crtc
->config
.adjusted_mode
;
5915 struct drm_display_mode
*mode
= &intel_crtc
->config
.requested_mode
;
5916 int pipe
= intel_crtc
->pipe
;
5919 drm_vblank_pre_modeset(dev
, pipe
);
5921 ret
= dev_priv
->display
.crtc_mode_set(crtc
, x
, y
, fb
);
5923 drm_vblank_post_modeset(dev
, pipe
);
5928 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5929 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
5930 encoder
->base
.base
.id
,
5931 drm_get_encoder_name(&encoder
->base
),
5932 mode
->base
.id
, mode
->name
);
5933 if (encoder
->mode_set
) {
5934 encoder
->mode_set(encoder
);
5936 encoder_funcs
= encoder
->base
.helper_private
;
5937 encoder_funcs
->mode_set(&encoder
->base
, mode
, adjusted_mode
);
5944 static bool intel_eld_uptodate(struct drm_connector
*connector
,
5945 int reg_eldv
, uint32_t bits_eldv
,
5946 int reg_elda
, uint32_t bits_elda
,
5949 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
5950 uint8_t *eld
= connector
->eld
;
5953 i
= I915_READ(reg_eldv
);
5962 i
= I915_READ(reg_elda
);
5964 I915_WRITE(reg_elda
, i
);
5966 for (i
= 0; i
< eld
[2]; i
++)
5967 if (I915_READ(reg_edid
) != *((uint32_t *)eld
+ i
))
5973 static void g4x_write_eld(struct drm_connector
*connector
,
5974 struct drm_crtc
*crtc
)
5976 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
5977 uint8_t *eld
= connector
->eld
;
5982 i
= I915_READ(G4X_AUD_VID_DID
);
5984 if (i
== INTEL_AUDIO_DEVBLC
|| i
== INTEL_AUDIO_DEVCL
)
5985 eldv
= G4X_ELDV_DEVCL_DEVBLC
;
5987 eldv
= G4X_ELDV_DEVCTG
;
5989 if (intel_eld_uptodate(connector
,
5990 G4X_AUD_CNTL_ST
, eldv
,
5991 G4X_AUD_CNTL_ST
, G4X_ELD_ADDR
,
5992 G4X_HDMIW_HDMIEDID
))
5995 i
= I915_READ(G4X_AUD_CNTL_ST
);
5996 i
&= ~(eldv
| G4X_ELD_ADDR
);
5997 len
= (i
>> 9) & 0x1f; /* ELD buffer size */
5998 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
6003 len
= min_t(uint8_t, eld
[2], len
);
6004 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
6005 for (i
= 0; i
< len
; i
++)
6006 I915_WRITE(G4X_HDMIW_HDMIEDID
, *((uint32_t *)eld
+ i
));
6008 i
= I915_READ(G4X_AUD_CNTL_ST
);
6010 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
6013 static void haswell_write_eld(struct drm_connector
*connector
,
6014 struct drm_crtc
*crtc
)
6016 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
6017 uint8_t *eld
= connector
->eld
;
6018 struct drm_device
*dev
= crtc
->dev
;
6019 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6023 int pipe
= to_intel_crtc(crtc
)->pipe
;
6026 int hdmiw_hdmiedid
= HSW_AUD_EDID_DATA(pipe
);
6027 int aud_cntl_st
= HSW_AUD_DIP_ELD_CTRL(pipe
);
6028 int aud_config
= HSW_AUD_CFG(pipe
);
6029 int aud_cntrl_st2
= HSW_AUD_PIN_ELD_CP_VLD
;
6032 DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n");
6034 /* Audio output enable */
6035 DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
6036 tmp
= I915_READ(aud_cntrl_st2
);
6037 tmp
|= (AUDIO_OUTPUT_ENABLE_A
<< (pipe
* 4));
6038 I915_WRITE(aud_cntrl_st2
, tmp
);
6040 /* Wait for 1 vertical blank */
6041 intel_wait_for_vblank(dev
, pipe
);
6043 /* Set ELD valid state */
6044 tmp
= I915_READ(aud_cntrl_st2
);
6045 DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp
);
6046 tmp
|= (AUDIO_ELD_VALID_A
<< (pipe
* 4));
6047 I915_WRITE(aud_cntrl_st2
, tmp
);
6048 tmp
= I915_READ(aud_cntrl_st2
);
6049 DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp
);
6051 /* Enable HDMI mode */
6052 tmp
= I915_READ(aud_config
);
6053 DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp
);
6054 /* clear N_programing_enable and N_value_index */
6055 tmp
&= ~(AUD_CONFIG_N_VALUE_INDEX
| AUD_CONFIG_N_PROG_ENABLE
);
6056 I915_WRITE(aud_config
, tmp
);
6058 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
6060 eldv
= AUDIO_ELD_VALID_A
<< (pipe
* 4);
6061 intel_crtc
->eld_vld
= true;
6063 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
6064 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
6065 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
6066 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
6068 I915_WRITE(aud_config
, 0);
6070 if (intel_eld_uptodate(connector
,
6071 aud_cntrl_st2
, eldv
,
6072 aud_cntl_st
, IBX_ELD_ADDRESS
,
6076 i
= I915_READ(aud_cntrl_st2
);
6078 I915_WRITE(aud_cntrl_st2
, i
);
6083 i
= I915_READ(aud_cntl_st
);
6084 i
&= ~IBX_ELD_ADDRESS
;
6085 I915_WRITE(aud_cntl_st
, i
);
6086 i
= (i
>> 29) & DIP_PORT_SEL_MASK
; /* DIP_Port_Select, 0x1 = PortB */
6087 DRM_DEBUG_DRIVER("port num:%d\n", i
);
6089 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
6090 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
6091 for (i
= 0; i
< len
; i
++)
6092 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
6094 i
= I915_READ(aud_cntrl_st2
);
6096 I915_WRITE(aud_cntrl_st2
, i
);
6100 static void ironlake_write_eld(struct drm_connector
*connector
,
6101 struct drm_crtc
*crtc
)
6103 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
6104 uint8_t *eld
= connector
->eld
;
6112 int pipe
= to_intel_crtc(crtc
)->pipe
;
6114 if (HAS_PCH_IBX(connector
->dev
)) {
6115 hdmiw_hdmiedid
= IBX_HDMIW_HDMIEDID(pipe
);
6116 aud_config
= IBX_AUD_CFG(pipe
);
6117 aud_cntl_st
= IBX_AUD_CNTL_ST(pipe
);
6118 aud_cntrl_st2
= IBX_AUD_CNTL_ST2
;
6120 hdmiw_hdmiedid
= CPT_HDMIW_HDMIEDID(pipe
);
6121 aud_config
= CPT_AUD_CFG(pipe
);
6122 aud_cntl_st
= CPT_AUD_CNTL_ST(pipe
);
6123 aud_cntrl_st2
= CPT_AUD_CNTRL_ST2
;
6126 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
6128 i
= I915_READ(aud_cntl_st
);
6129 i
= (i
>> 29) & DIP_PORT_SEL_MASK
; /* DIP_Port_Select, 0x1 = PortB */
6131 DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
6132 /* operate blindly on all ports */
6133 eldv
= IBX_ELD_VALIDB
;
6134 eldv
|= IBX_ELD_VALIDB
<< 4;
6135 eldv
|= IBX_ELD_VALIDB
<< 8;
6137 DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i
));
6138 eldv
= IBX_ELD_VALIDB
<< ((i
- 1) * 4);
6141 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
6142 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
6143 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
6144 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
6146 I915_WRITE(aud_config
, 0);
6148 if (intel_eld_uptodate(connector
,
6149 aud_cntrl_st2
, eldv
,
6150 aud_cntl_st
, IBX_ELD_ADDRESS
,
6154 i
= I915_READ(aud_cntrl_st2
);
6156 I915_WRITE(aud_cntrl_st2
, i
);
6161 i
= I915_READ(aud_cntl_st
);
6162 i
&= ~IBX_ELD_ADDRESS
;
6163 I915_WRITE(aud_cntl_st
, i
);
6165 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
6166 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
6167 for (i
= 0; i
< len
; i
++)
6168 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
6170 i
= I915_READ(aud_cntrl_st2
);
6172 I915_WRITE(aud_cntrl_st2
, i
);
6175 void intel_write_eld(struct drm_encoder
*encoder
,
6176 struct drm_display_mode
*mode
)
6178 struct drm_crtc
*crtc
= encoder
->crtc
;
6179 struct drm_connector
*connector
;
6180 struct drm_device
*dev
= encoder
->dev
;
6181 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6183 connector
= drm_select_eld(encoder
, mode
);
6187 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6189 drm_get_connector_name(connector
),
6190 connector
->encoder
->base
.id
,
6191 drm_get_encoder_name(connector
->encoder
));
6193 connector
->eld
[6] = drm_av_sync_delay(connector
, mode
) / 2;
6195 if (dev_priv
->display
.write_eld
)
6196 dev_priv
->display
.write_eld(connector
, crtc
);
6199 /** Loads the palette/gamma unit for the CRTC with the prepared values */
6200 void intel_crtc_load_lut(struct drm_crtc
*crtc
)
6202 struct drm_device
*dev
= crtc
->dev
;
6203 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6204 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6205 int palreg
= PALETTE(intel_crtc
->pipe
);
6208 /* The clocks have to be on to load the palette. */
6209 if (!crtc
->enabled
|| !intel_crtc
->active
)
6212 /* use legacy palette for Ironlake */
6213 if (HAS_PCH_SPLIT(dev
))
6214 palreg
= LGC_PALETTE(intel_crtc
->pipe
);
6216 for (i
= 0; i
< 256; i
++) {
6217 I915_WRITE(palreg
+ 4 * i
,
6218 (intel_crtc
->lut_r
[i
] << 16) |
6219 (intel_crtc
->lut_g
[i
] << 8) |
6220 intel_crtc
->lut_b
[i
]);
6224 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
6226 struct drm_device
*dev
= crtc
->dev
;
6227 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6228 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6229 bool visible
= base
!= 0;
6232 if (intel_crtc
->cursor_visible
== visible
)
6235 cntl
= I915_READ(_CURACNTR
);
6237 /* On these chipsets we can only modify the base whilst
6238 * the cursor is disabled.
6240 I915_WRITE(_CURABASE
, base
);
6242 cntl
&= ~(CURSOR_FORMAT_MASK
);
6243 /* XXX width must be 64, stride 256 => 0x00 << 28 */
6244 cntl
|= CURSOR_ENABLE
|
6245 CURSOR_GAMMA_ENABLE
|
6248 cntl
&= ~(CURSOR_ENABLE
| CURSOR_GAMMA_ENABLE
);
6249 I915_WRITE(_CURACNTR
, cntl
);
6251 intel_crtc
->cursor_visible
= visible
;
6254 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
6256 struct drm_device
*dev
= crtc
->dev
;
6257 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6258 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6259 int pipe
= intel_crtc
->pipe
;
6260 bool visible
= base
!= 0;
6262 if (intel_crtc
->cursor_visible
!= visible
) {
6263 uint32_t cntl
= I915_READ(CURCNTR(pipe
));
6265 cntl
&= ~(CURSOR_MODE
| MCURSOR_PIPE_SELECT
);
6266 cntl
|= CURSOR_MODE_64_ARGB_AX
| MCURSOR_GAMMA_ENABLE
;
6267 cntl
|= pipe
<< 28; /* Connect to correct pipe */
6269 cntl
&= ~(CURSOR_MODE
| MCURSOR_GAMMA_ENABLE
);
6270 cntl
|= CURSOR_MODE_DISABLE
;
6272 I915_WRITE(CURCNTR(pipe
), cntl
);
6274 intel_crtc
->cursor_visible
= visible
;
6276 /* and commit changes on next vblank */
6277 I915_WRITE(CURBASE(pipe
), base
);
6280 static void ivb_update_cursor(struct drm_crtc
*crtc
, u32 base
)
6282 struct drm_device
*dev
= crtc
->dev
;
6283 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6284 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6285 int pipe
= intel_crtc
->pipe
;
6286 bool visible
= base
!= 0;
6288 if (intel_crtc
->cursor_visible
!= visible
) {
6289 uint32_t cntl
= I915_READ(CURCNTR_IVB(pipe
));
6291 cntl
&= ~CURSOR_MODE
;
6292 cntl
|= CURSOR_MODE_64_ARGB_AX
| MCURSOR_GAMMA_ENABLE
;
6294 cntl
&= ~(CURSOR_MODE
| MCURSOR_GAMMA_ENABLE
);
6295 cntl
|= CURSOR_MODE_DISABLE
;
6297 if (IS_HASWELL(dev
))
6298 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
6299 I915_WRITE(CURCNTR_IVB(pipe
), cntl
);
6301 intel_crtc
->cursor_visible
= visible
;
6303 /* and commit changes on next vblank */
6304 I915_WRITE(CURBASE_IVB(pipe
), base
);
6307 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
6308 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
6311 struct drm_device
*dev
= crtc
->dev
;
6312 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6313 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6314 int pipe
= intel_crtc
->pipe
;
6315 int x
= intel_crtc
->cursor_x
;
6316 int y
= intel_crtc
->cursor_y
;
6322 if (on
&& crtc
->enabled
&& crtc
->fb
) {
6323 base
= intel_crtc
->cursor_addr
;
6324 if (x
> (int) crtc
->fb
->width
)
6327 if (y
> (int) crtc
->fb
->height
)
6333 if (x
+ intel_crtc
->cursor_width
< 0)
6336 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
6339 pos
|= x
<< CURSOR_X_SHIFT
;
6342 if (y
+ intel_crtc
->cursor_height
< 0)
6345 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
6348 pos
|= y
<< CURSOR_Y_SHIFT
;
6350 visible
= base
!= 0;
6351 if (!visible
&& !intel_crtc
->cursor_visible
)
6354 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
)) {
6355 I915_WRITE(CURPOS_IVB(pipe
), pos
);
6356 ivb_update_cursor(crtc
, base
);
6358 I915_WRITE(CURPOS(pipe
), pos
);
6359 if (IS_845G(dev
) || IS_I865G(dev
))
6360 i845_update_cursor(crtc
, base
);
6362 i9xx_update_cursor(crtc
, base
);
6366 static int intel_crtc_cursor_set(struct drm_crtc
*crtc
,
6367 struct drm_file
*file
,
6369 uint32_t width
, uint32_t height
)
6371 struct drm_device
*dev
= crtc
->dev
;
6372 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6373 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6374 struct drm_i915_gem_object
*obj
;
6378 /* if we want to turn off the cursor ignore width and height */
6380 DRM_DEBUG_KMS("cursor off\n");
6383 mutex_lock(&dev
->struct_mutex
);
6387 /* Currently we only support 64x64 cursors */
6388 if (width
!= 64 || height
!= 64) {
6389 DRM_ERROR("we currently only support 64x64 cursors\n");
6393 obj
= to_intel_bo(drm_gem_object_lookup(dev
, file
, handle
));
6394 if (&obj
->base
== NULL
)
6397 if (obj
->base
.size
< width
* height
* 4) {
6398 DRM_ERROR("buffer is to small\n");
6403 /* we only need to pin inside GTT if cursor is non-phy */
6404 mutex_lock(&dev
->struct_mutex
);
6405 if (!dev_priv
->info
->cursor_needs_physical
) {
6408 if (obj
->tiling_mode
) {
6409 DRM_ERROR("cursor cannot be tiled\n");
6414 /* Note that the w/a also requires 2 PTE of padding following
6415 * the bo. We currently fill all unused PTE with the shadow
6416 * page and so we should always have valid PTE following the
6417 * cursor preventing the VT-d warning.
6420 if (need_vtd_wa(dev
))
6421 alignment
= 64*1024;
6423 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, NULL
);
6425 DRM_ERROR("failed to move cursor bo into the GTT\n");
6429 ret
= i915_gem_object_put_fence(obj
);
6431 DRM_ERROR("failed to release fence for cursor");
6435 addr
= obj
->gtt_offset
;
6437 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
6438 ret
= i915_gem_attach_phys_object(dev
, obj
,
6439 (intel_crtc
->pipe
== 0) ? I915_GEM_PHYS_CURSOR_0
: I915_GEM_PHYS_CURSOR_1
,
6442 DRM_ERROR("failed to attach phys object\n");
6445 addr
= obj
->phys_obj
->handle
->busaddr
;
6449 I915_WRITE(CURSIZE
, (height
<< 12) | width
);
6452 if (intel_crtc
->cursor_bo
) {
6453 if (dev_priv
->info
->cursor_needs_physical
) {
6454 if (intel_crtc
->cursor_bo
!= obj
)
6455 i915_gem_detach_phys_object(dev
, intel_crtc
->cursor_bo
);
6457 i915_gem_object_unpin(intel_crtc
->cursor_bo
);
6458 drm_gem_object_unreference(&intel_crtc
->cursor_bo
->base
);
6461 mutex_unlock(&dev
->struct_mutex
);
6463 intel_crtc
->cursor_addr
= addr
;
6464 intel_crtc
->cursor_bo
= obj
;
6465 intel_crtc
->cursor_width
= width
;
6466 intel_crtc
->cursor_height
= height
;
6468 intel_crtc_update_cursor(crtc
, true);
6472 i915_gem_object_unpin(obj
);
6474 mutex_unlock(&dev
->struct_mutex
);
6476 drm_gem_object_unreference_unlocked(&obj
->base
);
6480 static int intel_crtc_cursor_move(struct drm_crtc
*crtc
, int x
, int y
)
6482 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6484 intel_crtc
->cursor_x
= x
;
6485 intel_crtc
->cursor_y
= y
;
6487 intel_crtc_update_cursor(crtc
, true);
6492 /** Sets the color ramps on behalf of RandR */
6493 void intel_crtc_fb_gamma_set(struct drm_crtc
*crtc
, u16 red
, u16 green
,
6494 u16 blue
, int regno
)
6496 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6498 intel_crtc
->lut_r
[regno
] = red
>> 8;
6499 intel_crtc
->lut_g
[regno
] = green
>> 8;
6500 intel_crtc
->lut_b
[regno
] = blue
>> 8;
6503 void intel_crtc_fb_gamma_get(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
6504 u16
*blue
, int regno
)
6506 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6508 *red
= intel_crtc
->lut_r
[regno
] << 8;
6509 *green
= intel_crtc
->lut_g
[regno
] << 8;
6510 *blue
= intel_crtc
->lut_b
[regno
] << 8;
6513 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
6514 u16
*blue
, uint32_t start
, uint32_t size
)
6516 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
6517 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6519 for (i
= start
; i
< end
; i
++) {
6520 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
6521 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
6522 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
6525 intel_crtc_load_lut(crtc
);
6528 /* VESA 640x480x72Hz mode to set on the pipe */
6529 static struct drm_display_mode load_detect_mode
= {
6530 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
6531 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
6534 static struct drm_framebuffer
*
6535 intel_framebuffer_create(struct drm_device
*dev
,
6536 struct drm_mode_fb_cmd2
*mode_cmd
,
6537 struct drm_i915_gem_object
*obj
)
6539 struct intel_framebuffer
*intel_fb
;
6542 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
6544 drm_gem_object_unreference_unlocked(&obj
->base
);
6545 return ERR_PTR(-ENOMEM
);
6548 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
6550 drm_gem_object_unreference_unlocked(&obj
->base
);
6552 return ERR_PTR(ret
);
6555 return &intel_fb
->base
;
6559 intel_framebuffer_pitch_for_width(int width
, int bpp
)
6561 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
6562 return ALIGN(pitch
, 64);
6566 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
6568 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
6569 return ALIGN(pitch
* mode
->vdisplay
, PAGE_SIZE
);
6572 static struct drm_framebuffer
*
6573 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
6574 struct drm_display_mode
*mode
,
6577 struct drm_i915_gem_object
*obj
;
6578 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
6580 obj
= i915_gem_alloc_object(dev
,
6581 intel_framebuffer_size_for_mode(mode
, bpp
));
6583 return ERR_PTR(-ENOMEM
);
6585 mode_cmd
.width
= mode
->hdisplay
;
6586 mode_cmd
.height
= mode
->vdisplay
;
6587 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
6589 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
6591 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
6594 static struct drm_framebuffer
*
6595 mode_fits_in_fbdev(struct drm_device
*dev
,
6596 struct drm_display_mode
*mode
)
6598 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6599 struct drm_i915_gem_object
*obj
;
6600 struct drm_framebuffer
*fb
;
6602 if (dev_priv
->fbdev
== NULL
)
6605 obj
= dev_priv
->fbdev
->ifb
.obj
;
6609 fb
= &dev_priv
->fbdev
->ifb
.base
;
6610 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
6611 fb
->bits_per_pixel
))
6614 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
6620 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
6621 struct drm_display_mode
*mode
,
6622 struct intel_load_detect_pipe
*old
)
6624 struct intel_crtc
*intel_crtc
;
6625 struct intel_encoder
*intel_encoder
=
6626 intel_attached_encoder(connector
);
6627 struct drm_crtc
*possible_crtc
;
6628 struct drm_encoder
*encoder
= &intel_encoder
->base
;
6629 struct drm_crtc
*crtc
= NULL
;
6630 struct drm_device
*dev
= encoder
->dev
;
6631 struct drm_framebuffer
*fb
;
6634 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6635 connector
->base
.id
, drm_get_connector_name(connector
),
6636 encoder
->base
.id
, drm_get_encoder_name(encoder
));
6639 * Algorithm gets a little messy:
6641 * - if the connector already has an assigned crtc, use it (but make
6642 * sure it's on first)
6644 * - try to find the first unused crtc that can drive this connector,
6645 * and use that if we find one
6648 /* See if we already have a CRTC for this connector */
6649 if (encoder
->crtc
) {
6650 crtc
= encoder
->crtc
;
6652 mutex_lock(&crtc
->mutex
);
6654 old
->dpms_mode
= connector
->dpms
;
6655 old
->load_detect_temp
= false;
6657 /* Make sure the crtc and connector are running */
6658 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
6659 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
6664 /* Find an unused one (if possible) */
6665 list_for_each_entry(possible_crtc
, &dev
->mode_config
.crtc_list
, head
) {
6667 if (!(encoder
->possible_crtcs
& (1 << i
)))
6669 if (!possible_crtc
->enabled
) {
6670 crtc
= possible_crtc
;
6676 * If we didn't find an unused CRTC, don't use any.
6679 DRM_DEBUG_KMS("no pipe available for load-detect\n");
6683 mutex_lock(&crtc
->mutex
);
6684 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
6685 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
6687 intel_crtc
= to_intel_crtc(crtc
);
6688 old
->dpms_mode
= connector
->dpms
;
6689 old
->load_detect_temp
= true;
6690 old
->release_fb
= NULL
;
6693 mode
= &load_detect_mode
;
6695 /* We need a framebuffer large enough to accommodate all accesses
6696 * that the plane may generate whilst we perform load detection.
6697 * We can not rely on the fbcon either being present (we get called
6698 * during its initialisation to detect all boot displays, or it may
6699 * not even exist) or that it is large enough to satisfy the
6702 fb
= mode_fits_in_fbdev(dev
, mode
);
6704 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
6705 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
6706 old
->release_fb
= fb
;
6708 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
6710 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
6711 mutex_unlock(&crtc
->mutex
);
6715 if (intel_set_mode(crtc
, mode
, 0, 0, fb
)) {
6716 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
6717 if (old
->release_fb
)
6718 old
->release_fb
->funcs
->destroy(old
->release_fb
);
6719 mutex_unlock(&crtc
->mutex
);
6723 /* let the connector get through one full cycle before testing */
6724 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
6728 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
6729 struct intel_load_detect_pipe
*old
)
6731 struct intel_encoder
*intel_encoder
=
6732 intel_attached_encoder(connector
);
6733 struct drm_encoder
*encoder
= &intel_encoder
->base
;
6734 struct drm_crtc
*crtc
= encoder
->crtc
;
6736 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6737 connector
->base
.id
, drm_get_connector_name(connector
),
6738 encoder
->base
.id
, drm_get_encoder_name(encoder
));
6740 if (old
->load_detect_temp
) {
6741 to_intel_connector(connector
)->new_encoder
= NULL
;
6742 intel_encoder
->new_crtc
= NULL
;
6743 intel_set_mode(crtc
, NULL
, 0, 0, NULL
);
6745 if (old
->release_fb
) {
6746 drm_framebuffer_unregister_private(old
->release_fb
);
6747 drm_framebuffer_unreference(old
->release_fb
);
6750 mutex_unlock(&crtc
->mutex
);
6754 /* Switch crtc and encoder back off if necessary */
6755 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
6756 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
6758 mutex_unlock(&crtc
->mutex
);
6761 /* Returns the clock of the currently programmed mode of the given pipe. */
6762 static int intel_crtc_clock_get(struct drm_device
*dev
, struct drm_crtc
*crtc
)
6764 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6765 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6766 int pipe
= intel_crtc
->pipe
;
6767 u32 dpll
= I915_READ(DPLL(pipe
));
6769 intel_clock_t clock
;
6771 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
6772 fp
= I915_READ(FP0(pipe
));
6774 fp
= I915_READ(FP1(pipe
));
6776 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
6777 if (IS_PINEVIEW(dev
)) {
6778 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
6779 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
6781 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
6782 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
6785 if (!IS_GEN2(dev
)) {
6786 if (IS_PINEVIEW(dev
))
6787 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
6788 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
6790 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
6791 DPLL_FPA01_P1_POST_DIV_SHIFT
);
6793 switch (dpll
& DPLL_MODE_MASK
) {
6794 case DPLLB_MODE_DAC_SERIAL
:
6795 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
6798 case DPLLB_MODE_LVDS
:
6799 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
6803 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
6804 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
6808 /* XXX: Handle the 100Mhz refclk */
6809 intel_clock(dev
, 96000, &clock
);
6811 bool is_lvds
= (pipe
== 1) && (I915_READ(LVDS
) & LVDS_PORT_EN
);
6814 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
6815 DPLL_FPA01_P1_POST_DIV_SHIFT
);
6818 if ((dpll
& PLL_REF_INPUT_MASK
) ==
6819 PLLB_REF_INPUT_SPREADSPECTRUMIN
) {
6820 /* XXX: might not be 66MHz */
6821 intel_clock(dev
, 66000, &clock
);
6823 intel_clock(dev
, 48000, &clock
);
6825 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
6828 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
6829 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
6831 if (dpll
& PLL_P2_DIVIDE_BY_4
)
6836 intel_clock(dev
, 48000, &clock
);
6840 /* XXX: It would be nice to validate the clocks, but we can't reuse
6841 * i830PllIsValid() because it relies on the xf86_config connector
6842 * configuration being accurate, which it isn't necessarily.
6848 /** Returns the currently programmed mode of the given pipe. */
6849 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
6850 struct drm_crtc
*crtc
)
6852 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6853 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6854 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
6855 struct drm_display_mode
*mode
;
6856 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
6857 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
6858 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
6859 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
6861 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
6865 mode
->clock
= intel_crtc_clock_get(dev
, crtc
);
6866 mode
->hdisplay
= (htot
& 0xffff) + 1;
6867 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
6868 mode
->hsync_start
= (hsync
& 0xffff) + 1;
6869 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
6870 mode
->vdisplay
= (vtot
& 0xffff) + 1;
6871 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
6872 mode
->vsync_start
= (vsync
& 0xffff) + 1;
6873 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
6875 drm_mode_set_name(mode
);
6880 static void intel_increase_pllclock(struct drm_crtc
*crtc
)
6882 struct drm_device
*dev
= crtc
->dev
;
6883 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
6884 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6885 int pipe
= intel_crtc
->pipe
;
6886 int dpll_reg
= DPLL(pipe
);
6889 if (HAS_PCH_SPLIT(dev
))
6892 if (!dev_priv
->lvds_downclock_avail
)
6895 dpll
= I915_READ(dpll_reg
);
6896 if (!HAS_PIPE_CXSR(dev
) && (dpll
& DISPLAY_RATE_SELECT_FPA1
)) {
6897 DRM_DEBUG_DRIVER("upclocking LVDS\n");
6899 assert_panel_unlocked(dev_priv
, pipe
);
6901 dpll
&= ~DISPLAY_RATE_SELECT_FPA1
;
6902 I915_WRITE(dpll_reg
, dpll
);
6903 intel_wait_for_vblank(dev
, pipe
);
6905 dpll
= I915_READ(dpll_reg
);
6906 if (dpll
& DISPLAY_RATE_SELECT_FPA1
)
6907 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
6911 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
6913 struct drm_device
*dev
= crtc
->dev
;
6914 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
6915 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6917 if (HAS_PCH_SPLIT(dev
))
6920 if (!dev_priv
->lvds_downclock_avail
)
6924 * Since this is called by a timer, we should never get here in
6927 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
6928 int pipe
= intel_crtc
->pipe
;
6929 int dpll_reg
= DPLL(pipe
);
6932 DRM_DEBUG_DRIVER("downclocking LVDS\n");
6934 assert_panel_unlocked(dev_priv
, pipe
);
6936 dpll
= I915_READ(dpll_reg
);
6937 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
6938 I915_WRITE(dpll_reg
, dpll
);
6939 intel_wait_for_vblank(dev
, pipe
);
6940 dpll
= I915_READ(dpll_reg
);
6941 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
6942 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
6947 void intel_mark_busy(struct drm_device
*dev
)
6949 i915_update_gfx_val(dev
->dev_private
);
6952 void intel_mark_idle(struct drm_device
*dev
)
6954 struct drm_crtc
*crtc
;
6956 if (!i915_powersave
)
6959 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
6963 intel_decrease_pllclock(crtc
);
6967 void intel_mark_fb_busy(struct drm_i915_gem_object
*obj
)
6969 struct drm_device
*dev
= obj
->base
.dev
;
6970 struct drm_crtc
*crtc
;
6972 if (!i915_powersave
)
6975 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
6979 if (to_intel_framebuffer(crtc
->fb
)->obj
== obj
)
6980 intel_increase_pllclock(crtc
);
6984 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
6986 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6987 struct drm_device
*dev
= crtc
->dev
;
6988 struct intel_unpin_work
*work
;
6989 unsigned long flags
;
6991 spin_lock_irqsave(&dev
->event_lock
, flags
);
6992 work
= intel_crtc
->unpin_work
;
6993 intel_crtc
->unpin_work
= NULL
;
6994 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
6997 cancel_work_sync(&work
->work
);
7001 drm_crtc_cleanup(crtc
);
7006 static void intel_unpin_work_fn(struct work_struct
*__work
)
7008 struct intel_unpin_work
*work
=
7009 container_of(__work
, struct intel_unpin_work
, work
);
7010 struct drm_device
*dev
= work
->crtc
->dev
;
7012 mutex_lock(&dev
->struct_mutex
);
7013 intel_unpin_fb_obj(work
->old_fb_obj
);
7014 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
7015 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
7017 intel_update_fbc(dev
);
7018 mutex_unlock(&dev
->struct_mutex
);
7020 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
7021 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
7026 static void do_intel_finish_page_flip(struct drm_device
*dev
,
7027 struct drm_crtc
*crtc
)
7029 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7030 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7031 struct intel_unpin_work
*work
;
7032 unsigned long flags
;
7034 /* Ignore early vblank irqs */
7035 if (intel_crtc
== NULL
)
7038 spin_lock_irqsave(&dev
->event_lock
, flags
);
7039 work
= intel_crtc
->unpin_work
;
7041 /* Ensure we don't miss a work->pending update ... */
7044 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
7045 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7049 /* and that the unpin work is consistent wrt ->pending. */
7052 intel_crtc
->unpin_work
= NULL
;
7055 drm_send_vblank_event(dev
, intel_crtc
->pipe
, work
->event
);
7057 drm_vblank_put(dev
, intel_crtc
->pipe
);
7059 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7061 wake_up_all(&dev_priv
->pending_flip_queue
);
7063 queue_work(dev_priv
->wq
, &work
->work
);
7065 trace_i915_flip_complete(intel_crtc
->plane
, work
->pending_flip_obj
);
7068 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
7070 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7071 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
7073 do_intel_finish_page_flip(dev
, crtc
);
7076 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
7078 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7079 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
7081 do_intel_finish_page_flip(dev
, crtc
);
7084 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
7086 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7087 struct intel_crtc
*intel_crtc
=
7088 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
7089 unsigned long flags
;
7091 /* NB: An MMIO update of the plane base pointer will also
7092 * generate a page-flip completion irq, i.e. every modeset
7093 * is also accompanied by a spurious intel_prepare_page_flip().
7095 spin_lock_irqsave(&dev
->event_lock
, flags
);
7096 if (intel_crtc
->unpin_work
)
7097 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
7098 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7101 inline static void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
7103 /* Ensure that the work item is consistent when activating it ... */
7105 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
7106 /* and that it is marked active as soon as the irq could fire. */
7110 static int intel_gen2_queue_flip(struct drm_device
*dev
,
7111 struct drm_crtc
*crtc
,
7112 struct drm_framebuffer
*fb
,
7113 struct drm_i915_gem_object
*obj
)
7115 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7116 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7118 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7121 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7125 ret
= intel_ring_begin(ring
, 6);
7129 /* Can't queue multiple flips, so wait for the previous
7130 * one to finish before executing the next.
7132 if (intel_crtc
->plane
)
7133 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
7135 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
7136 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
7137 intel_ring_emit(ring
, MI_NOOP
);
7138 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
7139 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7140 intel_ring_emit(ring
, fb
->pitches
[0]);
7141 intel_ring_emit(ring
, obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
7142 intel_ring_emit(ring
, 0); /* aux display base address, unused */
7144 intel_mark_page_flip_active(intel_crtc
);
7145 intel_ring_advance(ring
);
7149 intel_unpin_fb_obj(obj
);
7154 static int intel_gen3_queue_flip(struct drm_device
*dev
,
7155 struct drm_crtc
*crtc
,
7156 struct drm_framebuffer
*fb
,
7157 struct drm_i915_gem_object
*obj
)
7159 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7160 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7162 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7165 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7169 ret
= intel_ring_begin(ring
, 6);
7173 if (intel_crtc
->plane
)
7174 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
7176 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
7177 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
7178 intel_ring_emit(ring
, MI_NOOP
);
7179 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
7180 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7181 intel_ring_emit(ring
, fb
->pitches
[0]);
7182 intel_ring_emit(ring
, obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
7183 intel_ring_emit(ring
, MI_NOOP
);
7185 intel_mark_page_flip_active(intel_crtc
);
7186 intel_ring_advance(ring
);
7190 intel_unpin_fb_obj(obj
);
7195 static int intel_gen4_queue_flip(struct drm_device
*dev
,
7196 struct drm_crtc
*crtc
,
7197 struct drm_framebuffer
*fb
,
7198 struct drm_i915_gem_object
*obj
)
7200 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7201 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7202 uint32_t pf
, pipesrc
;
7203 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7206 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7210 ret
= intel_ring_begin(ring
, 4);
7214 /* i965+ uses the linear or tiled offsets from the
7215 * Display Registers (which do not change across a page-flip)
7216 * so we need only reprogram the base address.
7218 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
7219 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7220 intel_ring_emit(ring
, fb
->pitches
[0]);
7221 intel_ring_emit(ring
,
7222 (obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
) |
7225 /* XXX Enabling the panel-fitter across page-flip is so far
7226 * untested on non-native modes, so ignore it for now.
7227 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
7230 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
7231 intel_ring_emit(ring
, pf
| pipesrc
);
7233 intel_mark_page_flip_active(intel_crtc
);
7234 intel_ring_advance(ring
);
7238 intel_unpin_fb_obj(obj
);
7243 static int intel_gen6_queue_flip(struct drm_device
*dev
,
7244 struct drm_crtc
*crtc
,
7245 struct drm_framebuffer
*fb
,
7246 struct drm_i915_gem_object
*obj
)
7248 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7249 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7250 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7251 uint32_t pf
, pipesrc
;
7254 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7258 ret
= intel_ring_begin(ring
, 4);
7262 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
7263 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7264 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
7265 intel_ring_emit(ring
, obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
7267 /* Contrary to the suggestions in the documentation,
7268 * "Enable Panel Fitter" does not seem to be required when page
7269 * flipping with a non-native mode, and worse causes a normal
7271 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
7274 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
7275 intel_ring_emit(ring
, pf
| pipesrc
);
7277 intel_mark_page_flip_active(intel_crtc
);
7278 intel_ring_advance(ring
);
7282 intel_unpin_fb_obj(obj
);
7288 * On gen7 we currently use the blit ring because (in early silicon at least)
7289 * the render ring doesn't give us interrpts for page flip completion, which
7290 * means clients will hang after the first flip is queued. Fortunately the
7291 * blit ring generates interrupts properly, so use it instead.
7293 static int intel_gen7_queue_flip(struct drm_device
*dev
,
7294 struct drm_crtc
*crtc
,
7295 struct drm_framebuffer
*fb
,
7296 struct drm_i915_gem_object
*obj
)
7298 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7299 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7300 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[BCS
];
7301 uint32_t plane_bit
= 0;
7304 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7308 switch(intel_crtc
->plane
) {
7310 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
7313 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
7316 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
7319 WARN_ONCE(1, "unknown plane in flip command\n");
7324 ret
= intel_ring_begin(ring
, 4);
7328 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
7329 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
7330 intel_ring_emit(ring
, obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
7331 intel_ring_emit(ring
, (MI_NOOP
));
7333 intel_mark_page_flip_active(intel_crtc
);
7334 intel_ring_advance(ring
);
7338 intel_unpin_fb_obj(obj
);
7343 static int intel_default_queue_flip(struct drm_device
*dev
,
7344 struct drm_crtc
*crtc
,
7345 struct drm_framebuffer
*fb
,
7346 struct drm_i915_gem_object
*obj
)
7351 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
7352 struct drm_framebuffer
*fb
,
7353 struct drm_pending_vblank_event
*event
)
7355 struct drm_device
*dev
= crtc
->dev
;
7356 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7357 struct drm_framebuffer
*old_fb
= crtc
->fb
;
7358 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(fb
)->obj
;
7359 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7360 struct intel_unpin_work
*work
;
7361 unsigned long flags
;
7364 /* Can't change pixel format via MI display flips. */
7365 if (fb
->pixel_format
!= crtc
->fb
->pixel_format
)
7369 * TILEOFF/LINOFF registers can't be changed via MI display flips.
7370 * Note that pitch changes could also affect these register.
7372 if (INTEL_INFO(dev
)->gen
> 3 &&
7373 (fb
->offsets
[0] != crtc
->fb
->offsets
[0] ||
7374 fb
->pitches
[0] != crtc
->fb
->pitches
[0]))
7377 work
= kzalloc(sizeof *work
, GFP_KERNEL
);
7381 work
->event
= event
;
7383 work
->old_fb_obj
= to_intel_framebuffer(old_fb
)->obj
;
7384 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
7386 ret
= drm_vblank_get(dev
, intel_crtc
->pipe
);
7390 /* We borrow the event spin lock for protecting unpin_work */
7391 spin_lock_irqsave(&dev
->event_lock
, flags
);
7392 if (intel_crtc
->unpin_work
) {
7393 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7395 drm_vblank_put(dev
, intel_crtc
->pipe
);
7397 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
7400 intel_crtc
->unpin_work
= work
;
7401 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7403 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
7404 flush_workqueue(dev_priv
->wq
);
7406 ret
= i915_mutex_lock_interruptible(dev
);
7410 /* Reference the objects for the scheduled work. */
7411 drm_gem_object_reference(&work
->old_fb_obj
->base
);
7412 drm_gem_object_reference(&obj
->base
);
7416 work
->pending_flip_obj
= obj
;
7418 work
->enable_stall_check
= true;
7420 atomic_inc(&intel_crtc
->unpin_work_count
);
7421 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
7423 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
);
7425 goto cleanup_pending
;
7427 intel_disable_fbc(dev
);
7428 intel_mark_fb_busy(obj
);
7429 mutex_unlock(&dev
->struct_mutex
);
7431 trace_i915_flip_request(intel_crtc
->plane
, obj
);
7436 atomic_dec(&intel_crtc
->unpin_work_count
);
7438 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
7439 drm_gem_object_unreference(&obj
->base
);
7440 mutex_unlock(&dev
->struct_mutex
);
7443 spin_lock_irqsave(&dev
->event_lock
, flags
);
7444 intel_crtc
->unpin_work
= NULL
;
7445 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7447 drm_vblank_put(dev
, intel_crtc
->pipe
);
7454 static struct drm_crtc_helper_funcs intel_helper_funcs
= {
7455 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
7456 .load_lut
= intel_crtc_load_lut
,
7459 bool intel_encoder_check_is_cloned(struct intel_encoder
*encoder
)
7461 struct intel_encoder
*other_encoder
;
7462 struct drm_crtc
*crtc
= &encoder
->new_crtc
->base
;
7467 list_for_each_entry(other_encoder
,
7468 &crtc
->dev
->mode_config
.encoder_list
,
7471 if (&other_encoder
->new_crtc
->base
!= crtc
||
7472 encoder
== other_encoder
)
7481 static bool intel_encoder_crtc_ok(struct drm_encoder
*encoder
,
7482 struct drm_crtc
*crtc
)
7484 struct drm_device
*dev
;
7485 struct drm_crtc
*tmp
;
7488 WARN(!crtc
, "checking null crtc?\n");
7492 list_for_each_entry(tmp
, &dev
->mode_config
.crtc_list
, head
) {
7498 if (encoder
->possible_crtcs
& crtc_mask
)
7504 * intel_modeset_update_staged_output_state
7506 * Updates the staged output configuration state, e.g. after we've read out the
7509 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
7511 struct intel_encoder
*encoder
;
7512 struct intel_connector
*connector
;
7514 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7516 connector
->new_encoder
=
7517 to_intel_encoder(connector
->base
.encoder
);
7520 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7523 to_intel_crtc(encoder
->base
.crtc
);
7528 * intel_modeset_commit_output_state
7530 * This function copies the stage display pipe configuration to the real one.
7532 static void intel_modeset_commit_output_state(struct drm_device
*dev
)
7534 struct intel_encoder
*encoder
;
7535 struct intel_connector
*connector
;
7537 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7539 connector
->base
.encoder
= &connector
->new_encoder
->base
;
7542 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7544 encoder
->base
.crtc
= &encoder
->new_crtc
->base
;
7549 pipe_config_set_bpp(struct drm_crtc
*crtc
,
7550 struct drm_framebuffer
*fb
,
7551 struct intel_crtc_config
*pipe_config
)
7553 struct drm_device
*dev
= crtc
->dev
;
7554 struct drm_connector
*connector
;
7557 switch (fb
->pixel_format
) {
7559 bpp
= 8*3; /* since we go through a colormap */
7561 case DRM_FORMAT_XRGB1555
:
7562 case DRM_FORMAT_ARGB1555
:
7563 /* checked in intel_framebuffer_init already */
7564 if (WARN_ON(INTEL_INFO(dev
)->gen
> 3))
7566 case DRM_FORMAT_RGB565
:
7567 bpp
= 6*3; /* min is 18bpp */
7569 case DRM_FORMAT_XBGR8888
:
7570 case DRM_FORMAT_ABGR8888
:
7571 /* checked in intel_framebuffer_init already */
7572 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
7574 case DRM_FORMAT_XRGB8888
:
7575 case DRM_FORMAT_ARGB8888
:
7578 case DRM_FORMAT_XRGB2101010
:
7579 case DRM_FORMAT_ARGB2101010
:
7580 case DRM_FORMAT_XBGR2101010
:
7581 case DRM_FORMAT_ABGR2101010
:
7582 /* checked in intel_framebuffer_init already */
7583 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
7587 /* TODO: gen4+ supports 16 bpc floating point, too. */
7589 DRM_DEBUG_KMS("unsupported depth\n");
7593 pipe_config
->pipe_bpp
= bpp
;
7595 /* Clamp display bpp to EDID value */
7596 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7598 if (connector
->encoder
&& connector
->encoder
->crtc
!= crtc
)
7601 /* Don't use an invalid EDID bpc value */
7602 if (connector
->display_info
.bpc
&&
7603 connector
->display_info
.bpc
* 3 < bpp
) {
7604 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
7605 bpp
, connector
->display_info
.bpc
*3);
7606 pipe_config
->pipe_bpp
= connector
->display_info
.bpc
*3;
7609 /* Clamp bpp to 8 on screens without EDID 1.4 */
7610 if (connector
->display_info
.bpc
== 0 && bpp
> 24) {
7611 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
7613 pipe_config
->pipe_bpp
= 24;
7620 static struct intel_crtc_config
*
7621 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
7622 struct drm_framebuffer
*fb
,
7623 struct drm_display_mode
*mode
)
7625 struct drm_device
*dev
= crtc
->dev
;
7626 struct drm_encoder_helper_funcs
*encoder_funcs
;
7627 struct intel_encoder
*encoder
;
7628 struct intel_crtc_config
*pipe_config
;
7631 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
7633 return ERR_PTR(-ENOMEM
);
7635 drm_mode_copy(&pipe_config
->adjusted_mode
, mode
);
7636 drm_mode_copy(&pipe_config
->requested_mode
, mode
);
7638 plane_bpp
= pipe_config_set_bpp(crtc
, fb
, pipe_config
);
7642 /* Pass our mode to the connectors and the CRTC to give them a chance to
7643 * adjust it according to limitations or connector properties, and also
7644 * a chance to reject the mode entirely.
7646 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7649 if (&encoder
->new_crtc
->base
!= crtc
)
7652 if (encoder
->compute_config
) {
7653 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
7654 DRM_DEBUG_KMS("Encoder config failure\n");
7661 encoder_funcs
= encoder
->base
.helper_private
;
7662 if (!(encoder_funcs
->mode_fixup(&encoder
->base
,
7663 &pipe_config
->requested_mode
,
7664 &pipe_config
->adjusted_mode
))) {
7665 DRM_DEBUG_KMS("Encoder fixup failed\n");
7670 if (!(intel_crtc_compute_config(crtc
, pipe_config
))) {
7671 DRM_DEBUG_KMS("CRTC fixup failed\n");
7674 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
7676 pipe_config
->dither
= pipe_config
->pipe_bpp
!= plane_bpp
;
7677 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
7678 plane_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
7683 return ERR_PTR(-EINVAL
);
7686 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
7687 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
7689 intel_modeset_affected_pipes(struct drm_crtc
*crtc
, unsigned *modeset_pipes
,
7690 unsigned *prepare_pipes
, unsigned *disable_pipes
)
7692 struct intel_crtc
*intel_crtc
;
7693 struct drm_device
*dev
= crtc
->dev
;
7694 struct intel_encoder
*encoder
;
7695 struct intel_connector
*connector
;
7696 struct drm_crtc
*tmp_crtc
;
7698 *disable_pipes
= *modeset_pipes
= *prepare_pipes
= 0;
7700 /* Check which crtcs have changed outputs connected to them, these need
7701 * to be part of the prepare_pipes mask. We don't (yet) support global
7702 * modeset across multiple crtcs, so modeset_pipes will only have one
7703 * bit set at most. */
7704 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7706 if (connector
->base
.encoder
== &connector
->new_encoder
->base
)
7709 if (connector
->base
.encoder
) {
7710 tmp_crtc
= connector
->base
.encoder
->crtc
;
7712 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
7715 if (connector
->new_encoder
)
7717 1 << connector
->new_encoder
->new_crtc
->pipe
;
7720 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7722 if (encoder
->base
.crtc
== &encoder
->new_crtc
->base
)
7725 if (encoder
->base
.crtc
) {
7726 tmp_crtc
= encoder
->base
.crtc
;
7728 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
7731 if (encoder
->new_crtc
)
7732 *prepare_pipes
|= 1 << encoder
->new_crtc
->pipe
;
7735 /* Check for any pipes that will be fully disabled ... */
7736 list_for_each_entry(intel_crtc
, &dev
->mode_config
.crtc_list
,
7740 /* Don't try to disable disabled crtcs. */
7741 if (!intel_crtc
->base
.enabled
)
7744 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7746 if (encoder
->new_crtc
== intel_crtc
)
7751 *disable_pipes
|= 1 << intel_crtc
->pipe
;
7755 /* set_mode is also used to update properties on life display pipes. */
7756 intel_crtc
= to_intel_crtc(crtc
);
7758 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
7761 * For simplicity do a full modeset on any pipe where the output routing
7762 * changed. We could be more clever, but that would require us to be
7763 * more careful with calling the relevant encoder->mode_set functions.
7766 *modeset_pipes
= *prepare_pipes
;
7768 /* ... and mask these out. */
7769 *modeset_pipes
&= ~(*disable_pipes
);
7770 *prepare_pipes
&= ~(*disable_pipes
);
7773 * HACK: We don't (yet) fully support global modesets. intel_set_config
7774 * obies this rule, but the modeset restore mode of
7775 * intel_modeset_setup_hw_state does not.
7777 *modeset_pipes
&= 1 << intel_crtc
->pipe
;
7778 *prepare_pipes
&= 1 << intel_crtc
->pipe
;
7780 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
7781 *modeset_pipes
, *prepare_pipes
, *disable_pipes
);
7784 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
7786 struct drm_encoder
*encoder
;
7787 struct drm_device
*dev
= crtc
->dev
;
7789 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
7790 if (encoder
->crtc
== crtc
)
7797 intel_modeset_update_state(struct drm_device
*dev
, unsigned prepare_pipes
)
7799 struct intel_encoder
*intel_encoder
;
7800 struct intel_crtc
*intel_crtc
;
7801 struct drm_connector
*connector
;
7803 list_for_each_entry(intel_encoder
, &dev
->mode_config
.encoder_list
,
7805 if (!intel_encoder
->base
.crtc
)
7808 intel_crtc
= to_intel_crtc(intel_encoder
->base
.crtc
);
7810 if (prepare_pipes
& (1 << intel_crtc
->pipe
))
7811 intel_encoder
->connectors_active
= false;
7814 intel_modeset_commit_output_state(dev
);
7816 /* Update computed state. */
7817 list_for_each_entry(intel_crtc
, &dev
->mode_config
.crtc_list
,
7819 intel_crtc
->base
.enabled
= intel_crtc_in_use(&intel_crtc
->base
);
7822 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
7823 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
7826 intel_crtc
= to_intel_crtc(connector
->encoder
->crtc
);
7828 if (prepare_pipes
& (1 << intel_crtc
->pipe
)) {
7829 struct drm_property
*dpms_property
=
7830 dev
->mode_config
.dpms_property
;
7832 connector
->dpms
= DRM_MODE_DPMS_ON
;
7833 drm_object_property_set_value(&connector
->base
,
7837 intel_encoder
= to_intel_encoder(connector
->encoder
);
7838 intel_encoder
->connectors_active
= true;
7844 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
7845 list_for_each_entry((intel_crtc), \
7846 &(dev)->mode_config.crtc_list, \
7848 if (mask & (1 <<(intel_crtc)->pipe)) \
7851 intel_pipe_config_compare(struct intel_crtc_config
*current_config
,
7852 struct intel_crtc_config
*pipe_config
)
7854 if (current_config
->has_pch_encoder
!= pipe_config
->has_pch_encoder
) {
7855 DRM_ERROR("mismatch in has_pch_encoder "
7856 "(expected %i, found %i)\n",
7857 current_config
->has_pch_encoder
,
7858 pipe_config
->has_pch_encoder
);
7866 intel_modeset_check_state(struct drm_device
*dev
)
7868 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7869 struct intel_crtc
*crtc
;
7870 struct intel_encoder
*encoder
;
7871 struct intel_connector
*connector
;
7872 struct intel_crtc_config pipe_config
;
7874 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7876 /* This also checks the encoder/connector hw state with the
7877 * ->get_hw_state callbacks. */
7878 intel_connector_check_state(connector
);
7880 WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
7881 "connector's staged encoder doesn't match current encoder\n");
7884 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7886 bool enabled
= false;
7887 bool active
= false;
7888 enum pipe pipe
, tracked_pipe
;
7890 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
7891 encoder
->base
.base
.id
,
7892 drm_get_encoder_name(&encoder
->base
));
7894 WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
7895 "encoder's stage crtc doesn't match current crtc\n");
7896 WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
7897 "encoder's active_connectors set, but no crtc\n");
7899 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7901 if (connector
->base
.encoder
!= &encoder
->base
)
7904 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
7907 WARN(!!encoder
->base
.crtc
!= enabled
,
7908 "encoder's enabled state mismatch "
7909 "(expected %i, found %i)\n",
7910 !!encoder
->base
.crtc
, enabled
);
7911 WARN(active
&& !encoder
->base
.crtc
,
7912 "active encoder with no crtc\n");
7914 WARN(encoder
->connectors_active
!= active
,
7915 "encoder's computed active state doesn't match tracked active state "
7916 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
7918 active
= encoder
->get_hw_state(encoder
, &pipe
);
7919 WARN(active
!= encoder
->connectors_active
,
7920 "encoder's hw state doesn't match sw tracking "
7921 "(expected %i, found %i)\n",
7922 encoder
->connectors_active
, active
);
7924 if (!encoder
->base
.crtc
)
7927 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
7928 WARN(active
&& pipe
!= tracked_pipe
,
7929 "active encoder's pipe doesn't match"
7930 "(expected %i, found %i)\n",
7931 tracked_pipe
, pipe
);
7935 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
7937 bool enabled
= false;
7938 bool active
= false;
7940 DRM_DEBUG_KMS("[CRTC:%d]\n",
7941 crtc
->base
.base
.id
);
7943 WARN(crtc
->active
&& !crtc
->base
.enabled
,
7944 "active crtc, but not enabled in sw tracking\n");
7946 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7948 if (encoder
->base
.crtc
!= &crtc
->base
)
7951 if (encoder
->connectors_active
)
7954 WARN(active
!= crtc
->active
,
7955 "crtc's computed active state doesn't match tracked active state "
7956 "(expected %i, found %i)\n", active
, crtc
->active
);
7957 WARN(enabled
!= crtc
->base
.enabled
,
7958 "crtc's computed enabled state doesn't match tracked enabled state "
7959 "(expected %i, found %i)\n", enabled
, crtc
->base
.enabled
);
7961 memset(&pipe_config
, 0, sizeof(pipe_config
));
7962 active
= dev_priv
->display
.get_pipe_config(crtc
,
7964 WARN(crtc
->active
!= active
,
7965 "crtc active state doesn't match with hw state "
7966 "(expected %i, found %i)\n", crtc
->active
, active
);
7969 !intel_pipe_config_compare(&crtc
->config
, &pipe_config
),
7970 "pipe state doesn't match!\n");
7974 static int __intel_set_mode(struct drm_crtc
*crtc
,
7975 struct drm_display_mode
*mode
,
7976 int x
, int y
, struct drm_framebuffer
*fb
)
7978 struct drm_device
*dev
= crtc
->dev
;
7979 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7980 struct drm_display_mode
*saved_mode
, *saved_hwmode
;
7981 struct intel_crtc_config
*pipe_config
= NULL
;
7982 struct intel_crtc
*intel_crtc
;
7983 unsigned disable_pipes
, prepare_pipes
, modeset_pipes
;
7986 saved_mode
= kmalloc(2 * sizeof(*saved_mode
), GFP_KERNEL
);
7989 saved_hwmode
= saved_mode
+ 1;
7991 intel_modeset_affected_pipes(crtc
, &modeset_pipes
,
7992 &prepare_pipes
, &disable_pipes
);
7994 *saved_hwmode
= crtc
->hwmode
;
7995 *saved_mode
= crtc
->mode
;
7997 /* Hack: Because we don't (yet) support global modeset on multiple
7998 * crtcs, we don't keep track of the new mode for more than one crtc.
7999 * Hence simply check whether any bit is set in modeset_pipes in all the
8000 * pieces of code that are not yet converted to deal with mutliple crtcs
8001 * changing their mode at the same time. */
8002 if (modeset_pipes
) {
8003 pipe_config
= intel_modeset_pipe_config(crtc
, fb
, mode
);
8004 if (IS_ERR(pipe_config
)) {
8005 ret
= PTR_ERR(pipe_config
);
8012 for_each_intel_crtc_masked(dev
, disable_pipes
, intel_crtc
)
8013 intel_crtc_disable(&intel_crtc
->base
);
8015 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
8016 if (intel_crtc
->base
.enabled
)
8017 dev_priv
->display
.crtc_disable(&intel_crtc
->base
);
8020 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
8021 * to set it here already despite that we pass it down the callchain.
8023 if (modeset_pipes
) {
8024 enum transcoder tmp
= to_intel_crtc(crtc
)->config
.cpu_transcoder
;
8026 /* mode_set/enable/disable functions rely on a correct pipe
8028 to_intel_crtc(crtc
)->config
= *pipe_config
;
8029 to_intel_crtc(crtc
)->config
.cpu_transcoder
= tmp
;
8032 /* Only after disabling all output pipelines that will be changed can we
8033 * update the the output configuration. */
8034 intel_modeset_update_state(dev
, prepare_pipes
);
8036 if (dev_priv
->display
.modeset_global_resources
)
8037 dev_priv
->display
.modeset_global_resources(dev
);
8039 /* Set up the DPLL and any encoders state that needs to adjust or depend
8042 for_each_intel_crtc_masked(dev
, modeset_pipes
, intel_crtc
) {
8043 ret
= intel_crtc_mode_set(&intel_crtc
->base
,
8049 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
8050 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
)
8051 dev_priv
->display
.crtc_enable(&intel_crtc
->base
);
8053 if (modeset_pipes
) {
8054 /* Store real post-adjustment hardware mode. */
8055 crtc
->hwmode
= pipe_config
->adjusted_mode
;
8057 /* Calculate and store various constants which
8058 * are later needed by vblank and swap-completion
8059 * timestamping. They are derived from true hwmode.
8061 drm_calc_timestamping_constants(crtc
);
8064 /* FIXME: add subpixel order */
8066 if (ret
&& crtc
->enabled
) {
8067 crtc
->hwmode
= *saved_hwmode
;
8068 crtc
->mode
= *saved_mode
;
8077 int intel_set_mode(struct drm_crtc
*crtc
,
8078 struct drm_display_mode
*mode
,
8079 int x
, int y
, struct drm_framebuffer
*fb
)
8083 ret
= __intel_set_mode(crtc
, mode
, x
, y
, fb
);
8086 intel_modeset_check_state(crtc
->dev
);
8091 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
8093 intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
, crtc
->fb
);
8096 #undef for_each_intel_crtc_masked
8098 static void intel_set_config_free(struct intel_set_config
*config
)
8103 kfree(config
->save_connector_encoders
);
8104 kfree(config
->save_encoder_crtcs
);
8108 static int intel_set_config_save_state(struct drm_device
*dev
,
8109 struct intel_set_config
*config
)
8111 struct drm_encoder
*encoder
;
8112 struct drm_connector
*connector
;
8115 config
->save_encoder_crtcs
=
8116 kcalloc(dev
->mode_config
.num_encoder
,
8117 sizeof(struct drm_crtc
*), GFP_KERNEL
);
8118 if (!config
->save_encoder_crtcs
)
8121 config
->save_connector_encoders
=
8122 kcalloc(dev
->mode_config
.num_connector
,
8123 sizeof(struct drm_encoder
*), GFP_KERNEL
);
8124 if (!config
->save_connector_encoders
)
8127 /* Copy data. Note that driver private data is not affected.
8128 * Should anything bad happen only the expected state is
8129 * restored, not the drivers personal bookkeeping.
8132 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
8133 config
->save_encoder_crtcs
[count
++] = encoder
->crtc
;
8137 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
8138 config
->save_connector_encoders
[count
++] = connector
->encoder
;
8144 static void intel_set_config_restore_state(struct drm_device
*dev
,
8145 struct intel_set_config
*config
)
8147 struct intel_encoder
*encoder
;
8148 struct intel_connector
*connector
;
8152 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
8154 to_intel_crtc(config
->save_encoder_crtcs
[count
++]);
8158 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
8159 connector
->new_encoder
=
8160 to_intel_encoder(config
->save_connector_encoders
[count
++]);
8165 intel_set_config_compute_mode_changes(struct drm_mode_set
*set
,
8166 struct intel_set_config
*config
)
8169 /* We should be able to check here if the fb has the same properties
8170 * and then just flip_or_move it */
8171 if (set
->crtc
->fb
!= set
->fb
) {
8172 /* If we have no fb then treat it as a full mode set */
8173 if (set
->crtc
->fb
== NULL
) {
8174 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
8175 config
->mode_changed
= true;
8176 } else if (set
->fb
== NULL
) {
8177 config
->mode_changed
= true;
8178 } else if (set
->fb
->pixel_format
!=
8179 set
->crtc
->fb
->pixel_format
) {
8180 config
->mode_changed
= true;
8182 config
->fb_changed
= true;
8185 if (set
->fb
&& (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
))
8186 config
->fb_changed
= true;
8188 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
8189 DRM_DEBUG_KMS("modes are different, full mode set\n");
8190 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
8191 drm_mode_debug_printmodeline(set
->mode
);
8192 config
->mode_changed
= true;
8197 intel_modeset_stage_output_state(struct drm_device
*dev
,
8198 struct drm_mode_set
*set
,
8199 struct intel_set_config
*config
)
8201 struct drm_crtc
*new_crtc
;
8202 struct intel_connector
*connector
;
8203 struct intel_encoder
*encoder
;
8206 /* The upper layers ensure that we either disable a crtc or have a list
8207 * of connectors. For paranoia, double-check this. */
8208 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
8209 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
8212 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
8214 /* Otherwise traverse passed in connector list and get encoders
8216 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
8217 if (set
->connectors
[ro
] == &connector
->base
) {
8218 connector
->new_encoder
= connector
->encoder
;
8223 /* If we disable the crtc, disable all its connectors. Also, if
8224 * the connector is on the changing crtc but not on the new
8225 * connector list, disable it. */
8226 if ((!set
->fb
|| ro
== set
->num_connectors
) &&
8227 connector
->base
.encoder
&&
8228 connector
->base
.encoder
->crtc
== set
->crtc
) {
8229 connector
->new_encoder
= NULL
;
8231 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
8232 connector
->base
.base
.id
,
8233 drm_get_connector_name(&connector
->base
));
8237 if (&connector
->new_encoder
->base
!= connector
->base
.encoder
) {
8238 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
8239 config
->mode_changed
= true;
8242 /* connector->new_encoder is now updated for all connectors. */
8244 /* Update crtc of enabled connectors. */
8246 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
8248 if (!connector
->new_encoder
)
8251 new_crtc
= connector
->new_encoder
->base
.crtc
;
8253 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
8254 if (set
->connectors
[ro
] == &connector
->base
)
8255 new_crtc
= set
->crtc
;
8258 /* Make sure the new CRTC will work with the encoder */
8259 if (!intel_encoder_crtc_ok(&connector
->new_encoder
->base
,
8263 connector
->encoder
->new_crtc
= to_intel_crtc(new_crtc
);
8265 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
8266 connector
->base
.base
.id
,
8267 drm_get_connector_name(&connector
->base
),
8271 /* Check for any encoders that needs to be disabled. */
8272 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
8274 list_for_each_entry(connector
,
8275 &dev
->mode_config
.connector_list
,
8277 if (connector
->new_encoder
== encoder
) {
8278 WARN_ON(!connector
->new_encoder
->new_crtc
);
8283 encoder
->new_crtc
= NULL
;
8285 /* Only now check for crtc changes so we don't miss encoders
8286 * that will be disabled. */
8287 if (&encoder
->new_crtc
->base
!= encoder
->base
.crtc
) {
8288 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
8289 config
->mode_changed
= true;
8292 /* Now we've also updated encoder->new_crtc for all encoders. */
8297 static int intel_crtc_set_config(struct drm_mode_set
*set
)
8299 struct drm_device
*dev
;
8300 struct drm_mode_set save_set
;
8301 struct intel_set_config
*config
;
8306 BUG_ON(!set
->crtc
->helper_private
);
8308 /* Enforce sane interface api - has been abused by the fb helper. */
8309 BUG_ON(!set
->mode
&& set
->fb
);
8310 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
8313 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
8314 set
->crtc
->base
.id
, set
->fb
->base
.id
,
8315 (int)set
->num_connectors
, set
->x
, set
->y
);
8317 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
8320 dev
= set
->crtc
->dev
;
8323 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
8327 ret
= intel_set_config_save_state(dev
, config
);
8331 save_set
.crtc
= set
->crtc
;
8332 save_set
.mode
= &set
->crtc
->mode
;
8333 save_set
.x
= set
->crtc
->x
;
8334 save_set
.y
= set
->crtc
->y
;
8335 save_set
.fb
= set
->crtc
->fb
;
8337 /* Compute whether we need a full modeset, only an fb base update or no
8338 * change at all. In the future we might also check whether only the
8339 * mode changed, e.g. for LVDS where we only change the panel fitter in
8341 intel_set_config_compute_mode_changes(set
, config
);
8343 ret
= intel_modeset_stage_output_state(dev
, set
, config
);
8347 if (config
->mode_changed
) {
8349 DRM_DEBUG_KMS("attempting to set mode from"
8351 drm_mode_debug_printmodeline(set
->mode
);
8354 ret
= intel_set_mode(set
->crtc
, set
->mode
,
8355 set
->x
, set
->y
, set
->fb
);
8357 DRM_ERROR("failed to set mode on [CRTC:%d], err = %d\n",
8358 set
->crtc
->base
.id
, ret
);
8361 } else if (config
->fb_changed
) {
8362 intel_crtc_wait_for_pending_flips(set
->crtc
);
8364 ret
= intel_pipe_set_base(set
->crtc
,
8365 set
->x
, set
->y
, set
->fb
);
8368 intel_set_config_free(config
);
8373 intel_set_config_restore_state(dev
, config
);
8375 /* Try to restore the config */
8376 if (config
->mode_changed
&&
8377 intel_set_mode(save_set
.crtc
, save_set
.mode
,
8378 save_set
.x
, save_set
.y
, save_set
.fb
))
8379 DRM_ERROR("failed to restore config after modeset failure\n");
8382 intel_set_config_free(config
);
8386 static const struct drm_crtc_funcs intel_crtc_funcs
= {
8387 .cursor_set
= intel_crtc_cursor_set
,
8388 .cursor_move
= intel_crtc_cursor_move
,
8389 .gamma_set
= intel_crtc_gamma_set
,
8390 .set_config
= intel_crtc_set_config
,
8391 .destroy
= intel_crtc_destroy
,
8392 .page_flip
= intel_crtc_page_flip
,
8395 static void intel_cpu_pll_init(struct drm_device
*dev
)
8398 intel_ddi_pll_init(dev
);
8401 static void intel_pch_pll_init(struct drm_device
*dev
)
8403 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
8406 if (dev_priv
->num_pch_pll
== 0) {
8407 DRM_DEBUG_KMS("No PCH PLLs on this hardware, skipping initialisation\n");
8411 for (i
= 0; i
< dev_priv
->num_pch_pll
; i
++) {
8412 dev_priv
->pch_plls
[i
].pll_reg
= _PCH_DPLL(i
);
8413 dev_priv
->pch_plls
[i
].fp0_reg
= _PCH_FP0(i
);
8414 dev_priv
->pch_plls
[i
].fp1_reg
= _PCH_FP1(i
);
8418 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
8420 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
8421 struct intel_crtc
*intel_crtc
;
8424 intel_crtc
= kzalloc(sizeof(struct intel_crtc
) + (INTELFB_CONN_LIMIT
* sizeof(struct drm_connector
*)), GFP_KERNEL
);
8425 if (intel_crtc
== NULL
)
8428 drm_crtc_init(dev
, &intel_crtc
->base
, &intel_crtc_funcs
);
8430 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
8431 for (i
= 0; i
< 256; i
++) {
8432 intel_crtc
->lut_r
[i
] = i
;
8433 intel_crtc
->lut_g
[i
] = i
;
8434 intel_crtc
->lut_b
[i
] = i
;
8437 /* Swap pipes & planes for FBC on pre-965 */
8438 intel_crtc
->pipe
= pipe
;
8439 intel_crtc
->plane
= pipe
;
8440 intel_crtc
->config
.cpu_transcoder
= pipe
;
8441 if (IS_MOBILE(dev
) && IS_GEN3(dev
)) {
8442 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
8443 intel_crtc
->plane
= !pipe
;
8446 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
8447 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
8448 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
8449 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
8451 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
8454 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
8455 struct drm_file
*file
)
8457 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
8458 struct drm_mode_object
*drmmode_obj
;
8459 struct intel_crtc
*crtc
;
8461 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
8464 drmmode_obj
= drm_mode_object_find(dev
, pipe_from_crtc_id
->crtc_id
,
8465 DRM_MODE_OBJECT_CRTC
);
8468 DRM_ERROR("no such CRTC id\n");
8472 crtc
= to_intel_crtc(obj_to_crtc(drmmode_obj
));
8473 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
8478 static int intel_encoder_clones(struct intel_encoder
*encoder
)
8480 struct drm_device
*dev
= encoder
->base
.dev
;
8481 struct intel_encoder
*source_encoder
;
8485 list_for_each_entry(source_encoder
,
8486 &dev
->mode_config
.encoder_list
, base
.head
) {
8488 if (encoder
== source_encoder
)
8489 index_mask
|= (1 << entry
);
8491 /* Intel hw has only one MUX where enocoders could be cloned. */
8492 if (encoder
->cloneable
&& source_encoder
->cloneable
)
8493 index_mask
|= (1 << entry
);
8501 static bool has_edp_a(struct drm_device
*dev
)
8503 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8505 if (!IS_MOBILE(dev
))
8508 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
8512 (I915_READ(ILK_DISPLAY_CHICKEN_FUSES
) & ILK_eDP_A_DISABLE
))
8518 static void intel_setup_outputs(struct drm_device
*dev
)
8520 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8521 struct intel_encoder
*encoder
;
8522 bool dpd_is_edp
= false;
8525 has_lvds
= intel_lvds_init(dev
);
8526 if (!has_lvds
&& !HAS_PCH_SPLIT(dev
)) {
8527 /* disable the panel fitter on everything but LVDS */
8528 I915_WRITE(PFIT_CONTROL
, 0);
8532 intel_crt_init(dev
);
8537 /* Haswell uses DDI functions to detect digital outputs */
8538 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
8539 /* DDI A only supports eDP */
8541 intel_ddi_init(dev
, PORT_A
);
8543 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
8545 found
= I915_READ(SFUSE_STRAP
);
8547 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
8548 intel_ddi_init(dev
, PORT_B
);
8549 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
8550 intel_ddi_init(dev
, PORT_C
);
8551 if (found
& SFUSE_STRAP_DDID_DETECTED
)
8552 intel_ddi_init(dev
, PORT_D
);
8553 } else if (HAS_PCH_SPLIT(dev
)) {
8555 dpd_is_edp
= intel_dpd_is_edp(dev
);
8558 intel_dp_init(dev
, DP_A
, PORT_A
);
8560 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
8561 /* PCH SDVOB multiplex with HDMIB */
8562 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
8564 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
8565 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
8566 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
8569 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
8570 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
8572 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
8573 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
8575 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
8576 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
8578 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
8579 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
8580 } else if (IS_VALLEYVIEW(dev
)) {
8581 /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
8582 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
)
8583 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
8585 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
) {
8586 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
8588 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
)
8589 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
8591 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
8594 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
8595 DRM_DEBUG_KMS("probing SDVOB\n");
8596 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
8597 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
8598 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
8599 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
8602 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
)) {
8603 DRM_DEBUG_KMS("probing DP_B\n");
8604 intel_dp_init(dev
, DP_B
, PORT_B
);
8608 /* Before G4X SDVOC doesn't have its own detect register */
8610 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
8611 DRM_DEBUG_KMS("probing SDVOC\n");
8612 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
8615 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
8617 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
8618 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
8619 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
8621 if (SUPPORTS_INTEGRATED_DP(dev
)) {
8622 DRM_DEBUG_KMS("probing DP_C\n");
8623 intel_dp_init(dev
, DP_C
, PORT_C
);
8627 if (SUPPORTS_INTEGRATED_DP(dev
) &&
8628 (I915_READ(DP_D
) & DP_DETECTED
)) {
8629 DRM_DEBUG_KMS("probing DP_D\n");
8630 intel_dp_init(dev
, DP_D
, PORT_D
);
8632 } else if (IS_GEN2(dev
))
8633 intel_dvo_init(dev
);
8635 if (SUPPORTS_TV(dev
))
8638 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
8639 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
8640 encoder
->base
.possible_clones
=
8641 intel_encoder_clones(encoder
);
8644 intel_init_pch_refclk(dev
);
8646 drm_helper_move_panel_connectors_to_head(dev
);
8649 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
8651 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
8653 drm_framebuffer_cleanup(fb
);
8654 drm_gem_object_unreference_unlocked(&intel_fb
->obj
->base
);
8659 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
8660 struct drm_file
*file
,
8661 unsigned int *handle
)
8663 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
8664 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
8666 return drm_gem_handle_create(file
, &obj
->base
, handle
);
8669 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
8670 .destroy
= intel_user_framebuffer_destroy
,
8671 .create_handle
= intel_user_framebuffer_create_handle
,
8674 int intel_framebuffer_init(struct drm_device
*dev
,
8675 struct intel_framebuffer
*intel_fb
,
8676 struct drm_mode_fb_cmd2
*mode_cmd
,
8677 struct drm_i915_gem_object
*obj
)
8681 if (obj
->tiling_mode
== I915_TILING_Y
) {
8682 DRM_DEBUG("hardware does not support tiling Y\n");
8686 if (mode_cmd
->pitches
[0] & 63) {
8687 DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
8688 mode_cmd
->pitches
[0]);
8692 /* FIXME <= Gen4 stride limits are bit unclear */
8693 if (mode_cmd
->pitches
[0] > 32768) {
8694 DRM_DEBUG("pitch (%d) must be at less than 32768\n",
8695 mode_cmd
->pitches
[0]);
8699 if (obj
->tiling_mode
!= I915_TILING_NONE
&&
8700 mode_cmd
->pitches
[0] != obj
->stride
) {
8701 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
8702 mode_cmd
->pitches
[0], obj
->stride
);
8706 /* Reject formats not supported by any plane early. */
8707 switch (mode_cmd
->pixel_format
) {
8709 case DRM_FORMAT_RGB565
:
8710 case DRM_FORMAT_XRGB8888
:
8711 case DRM_FORMAT_ARGB8888
:
8713 case DRM_FORMAT_XRGB1555
:
8714 case DRM_FORMAT_ARGB1555
:
8715 if (INTEL_INFO(dev
)->gen
> 3) {
8716 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd
->pixel_format
);
8720 case DRM_FORMAT_XBGR8888
:
8721 case DRM_FORMAT_ABGR8888
:
8722 case DRM_FORMAT_XRGB2101010
:
8723 case DRM_FORMAT_ARGB2101010
:
8724 case DRM_FORMAT_XBGR2101010
:
8725 case DRM_FORMAT_ABGR2101010
:
8726 if (INTEL_INFO(dev
)->gen
< 4) {
8727 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd
->pixel_format
);
8731 case DRM_FORMAT_YUYV
:
8732 case DRM_FORMAT_UYVY
:
8733 case DRM_FORMAT_YVYU
:
8734 case DRM_FORMAT_VYUY
:
8735 if (INTEL_INFO(dev
)->gen
< 5) {
8736 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd
->pixel_format
);
8741 DRM_DEBUG("unsupported pixel format 0x%08x\n", mode_cmd
->pixel_format
);
8745 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
8746 if (mode_cmd
->offsets
[0] != 0)
8749 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
8750 intel_fb
->obj
= obj
;
8752 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
8754 DRM_ERROR("framebuffer init failed %d\n", ret
);
8761 static struct drm_framebuffer
*
8762 intel_user_framebuffer_create(struct drm_device
*dev
,
8763 struct drm_file
*filp
,
8764 struct drm_mode_fb_cmd2
*mode_cmd
)
8766 struct drm_i915_gem_object
*obj
;
8768 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
8769 mode_cmd
->handles
[0]));
8770 if (&obj
->base
== NULL
)
8771 return ERR_PTR(-ENOENT
);
8773 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
8776 static const struct drm_mode_config_funcs intel_mode_funcs
= {
8777 .fb_create
= intel_user_framebuffer_create
,
8778 .output_poll_changed
= intel_fb_output_poll_changed
,
8781 /* Set up chip specific display functions */
8782 static void intel_init_display(struct drm_device
*dev
)
8784 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8787 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
8788 dev_priv
->display
.crtc_mode_set
= haswell_crtc_mode_set
;
8789 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
8790 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
8791 dev_priv
->display
.off
= haswell_crtc_off
;
8792 dev_priv
->display
.update_plane
= ironlake_update_plane
;
8793 } else if (HAS_PCH_SPLIT(dev
)) {
8794 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
8795 dev_priv
->display
.crtc_mode_set
= ironlake_crtc_mode_set
;
8796 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
8797 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
8798 dev_priv
->display
.off
= ironlake_crtc_off
;
8799 dev_priv
->display
.update_plane
= ironlake_update_plane
;
8800 } else if (IS_VALLEYVIEW(dev
)) {
8801 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
8802 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
8803 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
8804 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
8805 dev_priv
->display
.off
= i9xx_crtc_off
;
8806 dev_priv
->display
.update_plane
= i9xx_update_plane
;
8808 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
8809 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
8810 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
8811 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
8812 dev_priv
->display
.off
= i9xx_crtc_off
;
8813 dev_priv
->display
.update_plane
= i9xx_update_plane
;
8816 /* Returns the core display clock speed */
8817 if (IS_VALLEYVIEW(dev
))
8818 dev_priv
->display
.get_display_clock_speed
=
8819 valleyview_get_display_clock_speed
;
8820 else if (IS_I945G(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
8821 dev_priv
->display
.get_display_clock_speed
=
8822 i945_get_display_clock_speed
;
8823 else if (IS_I915G(dev
))
8824 dev_priv
->display
.get_display_clock_speed
=
8825 i915_get_display_clock_speed
;
8826 else if (IS_I945GM(dev
) || IS_845G(dev
) || IS_PINEVIEW_M(dev
))
8827 dev_priv
->display
.get_display_clock_speed
=
8828 i9xx_misc_get_display_clock_speed
;
8829 else if (IS_I915GM(dev
))
8830 dev_priv
->display
.get_display_clock_speed
=
8831 i915gm_get_display_clock_speed
;
8832 else if (IS_I865G(dev
))
8833 dev_priv
->display
.get_display_clock_speed
=
8834 i865_get_display_clock_speed
;
8835 else if (IS_I85X(dev
))
8836 dev_priv
->display
.get_display_clock_speed
=
8837 i855_get_display_clock_speed
;
8839 dev_priv
->display
.get_display_clock_speed
=
8840 i830_get_display_clock_speed
;
8842 if (HAS_PCH_SPLIT(dev
)) {
8844 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
8845 dev_priv
->display
.write_eld
= ironlake_write_eld
;
8846 } else if (IS_GEN6(dev
)) {
8847 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
8848 dev_priv
->display
.write_eld
= ironlake_write_eld
;
8849 } else if (IS_IVYBRIDGE(dev
)) {
8850 /* FIXME: detect B0+ stepping and use auto training */
8851 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
8852 dev_priv
->display
.write_eld
= ironlake_write_eld
;
8853 dev_priv
->display
.modeset_global_resources
=
8854 ivb_modeset_global_resources
;
8855 } else if (IS_HASWELL(dev
)) {
8856 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
8857 dev_priv
->display
.write_eld
= haswell_write_eld
;
8858 dev_priv
->display
.modeset_global_resources
=
8859 haswell_modeset_global_resources
;
8861 } else if (IS_G4X(dev
)) {
8862 dev_priv
->display
.write_eld
= g4x_write_eld
;
8865 /* Default just returns -ENODEV to indicate unsupported */
8866 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
8868 switch (INTEL_INFO(dev
)->gen
) {
8870 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
8874 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
8879 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
8883 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
8886 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
8892 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
8893 * resume, or other times. This quirk makes sure that's the case for
8896 static void quirk_pipea_force(struct drm_device
*dev
)
8898 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8900 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
8901 DRM_INFO("applying pipe a force quirk\n");
8905 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
8907 static void quirk_ssc_force_disable(struct drm_device
*dev
)
8909 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8910 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
8911 DRM_INFO("applying lvds SSC disable quirk\n");
8915 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
8918 static void quirk_invert_brightness(struct drm_device
*dev
)
8920 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8921 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
8922 DRM_INFO("applying inverted panel brightness quirk\n");
8925 struct intel_quirk
{
8927 int subsystem_vendor
;
8928 int subsystem_device
;
8929 void (*hook
)(struct drm_device
*dev
);
8932 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
8933 struct intel_dmi_quirk
{
8934 void (*hook
)(struct drm_device
*dev
);
8935 const struct dmi_system_id (*dmi_id_list
)[];
8938 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
8940 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
8944 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
8946 .dmi_id_list
= &(const struct dmi_system_id
[]) {
8948 .callback
= intel_dmi_reverse_brightness
,
8949 .ident
= "NCR Corporation",
8950 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
8951 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
8954 { } /* terminating entry */
8956 .hook
= quirk_invert_brightness
,
8960 static struct intel_quirk intel_quirks
[] = {
8961 /* HP Mini needs pipe A force quirk (LP: #322104) */
8962 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force
},
8964 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
8965 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
8967 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
8968 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
8970 /* 830/845 need to leave pipe A & dpll A up */
8971 { 0x2562, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
8972 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
8974 /* Lenovo U160 cannot use SSC on LVDS */
8975 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
8977 /* Sony Vaio Y cannot use SSC on LVDS */
8978 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
8980 /* Acer Aspire 5734Z must invert backlight brightness */
8981 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
8983 /* Acer/eMachines G725 */
8984 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
8986 /* Acer/eMachines e725 */
8987 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
8989 /* Acer/Packard Bell NCL20 */
8990 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
8992 /* Acer Aspire 4736Z */
8993 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
8996 static void intel_init_quirks(struct drm_device
*dev
)
8998 struct pci_dev
*d
= dev
->pdev
;
9001 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
9002 struct intel_quirk
*q
= &intel_quirks
[i
];
9004 if (d
->device
== q
->device
&&
9005 (d
->subsystem_vendor
== q
->subsystem_vendor
||
9006 q
->subsystem_vendor
== PCI_ANY_ID
) &&
9007 (d
->subsystem_device
== q
->subsystem_device
||
9008 q
->subsystem_device
== PCI_ANY_ID
))
9011 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
9012 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
9013 intel_dmi_quirks
[i
].hook(dev
);
9017 /* Disable the VGA plane that we never use */
9018 static void i915_disable_vga(struct drm_device
*dev
)
9020 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9022 u32 vga_reg
= i915_vgacntrl_reg(dev
);
9024 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
9025 outb(SR01
, VGA_SR_INDEX
);
9026 sr1
= inb(VGA_SR_DATA
);
9027 outb(sr1
| 1<<5, VGA_SR_DATA
);
9028 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
9031 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
9032 POSTING_READ(vga_reg
);
9035 void intel_modeset_init_hw(struct drm_device
*dev
)
9037 intel_init_power_well(dev
);
9039 intel_prepare_ddi(dev
);
9041 intel_init_clock_gating(dev
);
9043 mutex_lock(&dev
->struct_mutex
);
9044 intel_enable_gt_powersave(dev
);
9045 mutex_unlock(&dev
->struct_mutex
);
9048 void intel_modeset_init(struct drm_device
*dev
)
9050 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9053 drm_mode_config_init(dev
);
9055 dev
->mode_config
.min_width
= 0;
9056 dev
->mode_config
.min_height
= 0;
9058 dev
->mode_config
.preferred_depth
= 24;
9059 dev
->mode_config
.prefer_shadow
= 1;
9061 dev
->mode_config
.funcs
= &intel_mode_funcs
;
9063 intel_init_quirks(dev
);
9067 if (INTEL_INFO(dev
)->num_pipes
== 0)
9070 intel_init_display(dev
);
9073 dev
->mode_config
.max_width
= 2048;
9074 dev
->mode_config
.max_height
= 2048;
9075 } else if (IS_GEN3(dev
)) {
9076 dev
->mode_config
.max_width
= 4096;
9077 dev
->mode_config
.max_height
= 4096;
9079 dev
->mode_config
.max_width
= 8192;
9080 dev
->mode_config
.max_height
= 8192;
9082 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
9084 DRM_DEBUG_KMS("%d display pipe%s available.\n",
9085 INTEL_INFO(dev
)->num_pipes
,
9086 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
9088 for (i
= 0; i
< INTEL_INFO(dev
)->num_pipes
; i
++) {
9089 intel_crtc_init(dev
, i
);
9090 for (j
= 0; j
< dev_priv
->num_plane
; j
++) {
9091 ret
= intel_plane_init(dev
, i
, j
);
9093 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
9094 pipe_name(i
), sprite_name(i
, j
), ret
);
9098 intel_cpu_pll_init(dev
);
9099 intel_pch_pll_init(dev
);
9101 /* Just disable it once at startup */
9102 i915_disable_vga(dev
);
9103 intel_setup_outputs(dev
);
9105 /* Just in case the BIOS is doing something questionable. */
9106 intel_disable_fbc(dev
);
9110 intel_connector_break_all_links(struct intel_connector
*connector
)
9112 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
9113 connector
->base
.encoder
= NULL
;
9114 connector
->encoder
->connectors_active
= false;
9115 connector
->encoder
->base
.crtc
= NULL
;
9118 static void intel_enable_pipe_a(struct drm_device
*dev
)
9120 struct intel_connector
*connector
;
9121 struct drm_connector
*crt
= NULL
;
9122 struct intel_load_detect_pipe load_detect_temp
;
9124 /* We can't just switch on the pipe A, we need to set things up with a
9125 * proper mode and output configuration. As a gross hack, enable pipe A
9126 * by enabling the load detect pipe once. */
9127 list_for_each_entry(connector
,
9128 &dev
->mode_config
.connector_list
,
9130 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
9131 crt
= &connector
->base
;
9139 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
))
9140 intel_release_load_detect_pipe(crt
, &load_detect_temp
);
9146 intel_check_plane_mapping(struct intel_crtc
*crtc
)
9148 struct drm_device
*dev
= crtc
->base
.dev
;
9149 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9152 if (INTEL_INFO(dev
)->num_pipes
== 1)
9155 reg
= DSPCNTR(!crtc
->plane
);
9156 val
= I915_READ(reg
);
9158 if ((val
& DISPLAY_PLANE_ENABLE
) &&
9159 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
9165 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
9167 struct drm_device
*dev
= crtc
->base
.dev
;
9168 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9171 /* Clear any frame start delays used for debugging left by the BIOS */
9172 reg
= PIPECONF(crtc
->config
.cpu_transcoder
);
9173 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
9175 /* We need to sanitize the plane -> pipe mapping first because this will
9176 * disable the crtc (and hence change the state) if it is wrong. Note
9177 * that gen4+ has a fixed plane -> pipe mapping. */
9178 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
9179 struct intel_connector
*connector
;
9182 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
9183 crtc
->base
.base
.id
);
9185 /* Pipe has the wrong plane attached and the plane is active.
9186 * Temporarily change the plane mapping and disable everything
9188 plane
= crtc
->plane
;
9189 crtc
->plane
= !plane
;
9190 dev_priv
->display
.crtc_disable(&crtc
->base
);
9191 crtc
->plane
= plane
;
9193 /* ... and break all links. */
9194 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9196 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
9199 intel_connector_break_all_links(connector
);
9202 WARN_ON(crtc
->active
);
9203 crtc
->base
.enabled
= false;
9206 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
9207 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
9208 /* BIOS forgot to enable pipe A, this mostly happens after
9209 * resume. Force-enable the pipe to fix this, the update_dpms
9210 * call below we restore the pipe to the right state, but leave
9211 * the required bits on. */
9212 intel_enable_pipe_a(dev
);
9215 /* Adjust the state of the output pipe according to whether we
9216 * have active connectors/encoders. */
9217 intel_crtc_update_dpms(&crtc
->base
);
9219 if (crtc
->active
!= crtc
->base
.enabled
) {
9220 struct intel_encoder
*encoder
;
9222 /* This can happen either due to bugs in the get_hw_state
9223 * functions or because the pipe is force-enabled due to the
9225 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
9227 crtc
->base
.enabled
? "enabled" : "disabled",
9228 crtc
->active
? "enabled" : "disabled");
9230 crtc
->base
.enabled
= crtc
->active
;
9232 /* Because we only establish the connector -> encoder ->
9233 * crtc links if something is active, this means the
9234 * crtc is now deactivated. Break the links. connector
9235 * -> encoder links are only establish when things are
9236 * actually up, hence no need to break them. */
9237 WARN_ON(crtc
->active
);
9239 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
9240 WARN_ON(encoder
->connectors_active
);
9241 encoder
->base
.crtc
= NULL
;
9246 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
9248 struct intel_connector
*connector
;
9249 struct drm_device
*dev
= encoder
->base
.dev
;
9251 /* We need to check both for a crtc link (meaning that the
9252 * encoder is active and trying to read from a pipe) and the
9253 * pipe itself being active. */
9254 bool has_active_crtc
= encoder
->base
.crtc
&&
9255 to_intel_crtc(encoder
->base
.crtc
)->active
;
9257 if (encoder
->connectors_active
&& !has_active_crtc
) {
9258 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
9259 encoder
->base
.base
.id
,
9260 drm_get_encoder_name(&encoder
->base
));
9262 /* Connector is active, but has no active pipe. This is
9263 * fallout from our resume register restoring. Disable
9264 * the encoder manually again. */
9265 if (encoder
->base
.crtc
) {
9266 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
9267 encoder
->base
.base
.id
,
9268 drm_get_encoder_name(&encoder
->base
));
9269 encoder
->disable(encoder
);
9272 /* Inconsistent output/port/pipe state happens presumably due to
9273 * a bug in one of the get_hw_state functions. Or someplace else
9274 * in our code, like the register restore mess on resume. Clamp
9275 * things to off as a safer default. */
9276 list_for_each_entry(connector
,
9277 &dev
->mode_config
.connector_list
,
9279 if (connector
->encoder
!= encoder
)
9282 intel_connector_break_all_links(connector
);
9285 /* Enabled encoders without active connectors will be fixed in
9286 * the crtc fixup. */
9289 void i915_redisable_vga(struct drm_device
*dev
)
9291 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9292 u32 vga_reg
= i915_vgacntrl_reg(dev
);
9294 if (I915_READ(vga_reg
) != VGA_DISP_DISABLE
) {
9295 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
9296 i915_disable_vga(dev
);
9300 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
9301 * and i915 state tracking structures. */
9302 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
9305 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9308 struct drm_plane
*plane
;
9309 struct intel_crtc
*crtc
;
9310 struct intel_encoder
*encoder
;
9311 struct intel_connector
*connector
;
9314 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
9316 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
9317 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
9318 case TRANS_DDI_EDP_INPUT_A_ON
:
9319 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
9322 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
9325 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
9329 /* A bogus value has been programmed, disable
9331 WARN(1, "Bogus eDP source %08x\n", tmp
);
9332 intel_ddi_disable_transcoder_func(dev_priv
,
9337 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
9338 crtc
->config
.cpu_transcoder
= TRANSCODER_EDP
;
9340 DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
9346 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
9348 enum transcoder tmp
= crtc
->config
.cpu_transcoder
;
9349 memset(&crtc
->config
, 0, sizeof(crtc
->config
));
9350 crtc
->config
.cpu_transcoder
= tmp
;
9352 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
9355 crtc
->base
.enabled
= crtc
->active
;
9357 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
9359 crtc
->active
? "enabled" : "disabled");
9363 intel_ddi_setup_hw_pll_state(dev
);
9365 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9369 if (encoder
->get_hw_state(encoder
, &pipe
)) {
9370 encoder
->base
.crtc
=
9371 dev_priv
->pipe_to_crtc_mapping
[pipe
];
9373 encoder
->base
.crtc
= NULL
;
9376 encoder
->connectors_active
= false;
9377 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
9378 encoder
->base
.base
.id
,
9379 drm_get_encoder_name(&encoder
->base
),
9380 encoder
->base
.crtc
? "enabled" : "disabled",
9384 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9386 if (connector
->get_hw_state(connector
)) {
9387 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
9388 connector
->encoder
->connectors_active
= true;
9389 connector
->base
.encoder
= &connector
->encoder
->base
;
9391 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
9392 connector
->base
.encoder
= NULL
;
9394 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
9395 connector
->base
.base
.id
,
9396 drm_get_connector_name(&connector
->base
),
9397 connector
->base
.encoder
? "enabled" : "disabled");
9400 /* HW state is read out, now we need to sanitize this mess. */
9401 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9403 intel_sanitize_encoder(encoder
);
9406 for_each_pipe(pipe
) {
9407 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
9408 intel_sanitize_crtc(crtc
);
9411 if (force_restore
) {
9413 * We need to use raw interfaces for restoring state to avoid
9414 * checking (bogus) intermediate states.
9416 for_each_pipe(pipe
) {
9417 struct drm_crtc
*crtc
=
9418 dev_priv
->pipe_to_crtc_mapping
[pipe
];
9420 __intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
,
9423 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
)
9424 intel_plane_restore(plane
);
9426 i915_redisable_vga(dev
);
9428 intel_modeset_update_staged_output_state(dev
);
9431 intel_modeset_check_state(dev
);
9433 drm_mode_config_reset(dev
);
9436 void intel_modeset_gem_init(struct drm_device
*dev
)
9438 intel_modeset_init_hw(dev
);
9440 intel_setup_overlay(dev
);
9442 intel_modeset_setup_hw_state(dev
, false);
9445 void intel_modeset_cleanup(struct drm_device
*dev
)
9447 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9448 struct drm_crtc
*crtc
;
9449 struct intel_crtc
*intel_crtc
;
9452 * Interrupts and polling as the first thing to avoid creating havoc.
9453 * Too much stuff here (turning of rps, connectors, ...) would
9454 * experience fancy races otherwise.
9456 drm_irq_uninstall(dev
);
9457 cancel_work_sync(&dev_priv
->hotplug_work
);
9459 * Due to the hpd irq storm handling the hotplug work can re-arm the
9460 * poll handlers. Hence disable polling after hpd handling is shut down.
9462 drm_kms_helper_poll_fini(dev
);
9464 mutex_lock(&dev
->struct_mutex
);
9466 intel_unregister_dsm_handler();
9468 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
9469 /* Skip inactive CRTCs */
9473 intel_crtc
= to_intel_crtc(crtc
);
9474 intel_increase_pllclock(crtc
);
9477 intel_disable_fbc(dev
);
9479 intel_disable_gt_powersave(dev
);
9481 ironlake_teardown_rc6(dev
);
9483 mutex_unlock(&dev
->struct_mutex
);
9485 /* flush any delayed tasks or pending work */
9486 flush_scheduled_work();
9488 /* destroy backlight, if any, before the connectors */
9489 intel_panel_destroy_backlight(dev
);
9491 drm_mode_config_cleanup(dev
);
9493 intel_cleanup_overlay(dev
);
9497 * Return which encoder is currently attached for connector.
9499 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
9501 return &intel_attached_encoder(connector
)->base
;
9504 void intel_connector_attach_encoder(struct intel_connector
*connector
,
9505 struct intel_encoder
*encoder
)
9507 connector
->encoder
= encoder
;
9508 drm_mode_connector_attach_encoder(&connector
->base
,
9513 * set vga decode state - true == enable VGA decode
9515 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
9517 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9520 pci_read_config_word(dev_priv
->bridge_dev
, INTEL_GMCH_CTRL
, &gmch_ctrl
);
9522 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
9524 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
9525 pci_write_config_word(dev_priv
->bridge_dev
, INTEL_GMCH_CTRL
, gmch_ctrl
);
9529 #ifdef CONFIG_DEBUG_FS
9530 #include <linux/seq_file.h>
9532 struct intel_display_error_state
{
9533 struct intel_cursor_error_state
{
9538 } cursor
[I915_MAX_PIPES
];
9540 struct intel_pipe_error_state
{
9550 } pipe
[I915_MAX_PIPES
];
9552 struct intel_plane_error_state
{
9560 } plane
[I915_MAX_PIPES
];
9563 struct intel_display_error_state
*
9564 intel_display_capture_error_state(struct drm_device
*dev
)
9566 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
9567 struct intel_display_error_state
*error
;
9568 enum transcoder cpu_transcoder
;
9571 error
= kmalloc(sizeof(*error
), GFP_ATOMIC
);
9576 cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
, i
);
9578 if (INTEL_INFO(dev
)->gen
<= 6 || IS_VALLEYVIEW(dev
)) {
9579 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
9580 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
9581 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
9583 error
->cursor
[i
].control
= I915_READ(CURCNTR_IVB(i
));
9584 error
->cursor
[i
].position
= I915_READ(CURPOS_IVB(i
));
9585 error
->cursor
[i
].base
= I915_READ(CURBASE_IVB(i
));
9588 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
9589 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
9590 if (INTEL_INFO(dev
)->gen
<= 3) {
9591 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
9592 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
9594 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
9595 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
9596 if (INTEL_INFO(dev
)->gen
>= 4) {
9597 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
9598 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
9601 error
->pipe
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
9602 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
9603 error
->pipe
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
9604 error
->pipe
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
9605 error
->pipe
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
9606 error
->pipe
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
9607 error
->pipe
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
9608 error
->pipe
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
9615 intel_display_print_error_state(struct seq_file
*m
,
9616 struct drm_device
*dev
,
9617 struct intel_display_error_state
*error
)
9621 seq_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
9623 seq_printf(m
, "Pipe [%d]:\n", i
);
9624 seq_printf(m
, " CONF: %08x\n", error
->pipe
[i
].conf
);
9625 seq_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
9626 seq_printf(m
, " HTOTAL: %08x\n", error
->pipe
[i
].htotal
);
9627 seq_printf(m
, " HBLANK: %08x\n", error
->pipe
[i
].hblank
);
9628 seq_printf(m
, " HSYNC: %08x\n", error
->pipe
[i
].hsync
);
9629 seq_printf(m
, " VTOTAL: %08x\n", error
->pipe
[i
].vtotal
);
9630 seq_printf(m
, " VBLANK: %08x\n", error
->pipe
[i
].vblank
);
9631 seq_printf(m
, " VSYNC: %08x\n", error
->pipe
[i
].vsync
);
9633 seq_printf(m
, "Plane [%d]:\n", i
);
9634 seq_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
9635 seq_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
9636 if (INTEL_INFO(dev
)->gen
<= 3) {
9637 seq_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
9638 seq_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
9640 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
9641 seq_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
9642 if (INTEL_INFO(dev
)->gen
>= 4) {
9643 seq_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
9644 seq_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
9647 seq_printf(m
, "Cursor [%d]:\n", i
);
9648 seq_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
9649 seq_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
9650 seq_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);