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
);
48 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
49 struct intel_crtc_config
*pipe_config
);
50 static void ironlake_crtc_clock_get(struct intel_crtc
*crtc
,
51 struct intel_crtc_config
*pipe_config
);
62 #define INTEL_P2_NUM 2
63 typedef struct intel_limit intel_limit_t
;
65 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
70 #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
73 intel_pch_rawclk(struct drm_device
*dev
)
75 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
77 WARN_ON(!HAS_PCH_SPLIT(dev
));
79 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
82 static inline u32
/* units of 100MHz */
83 intel_fdi_link_freq(struct drm_device
*dev
)
86 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
87 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
92 static const intel_limit_t intel_limits_i8xx_dvo
= {
93 .dot
= { .min
= 25000, .max
= 350000 },
94 .vco
= { .min
= 930000, .max
= 1400000 },
95 .n
= { .min
= 3, .max
= 16 },
96 .m
= { .min
= 96, .max
= 140 },
97 .m1
= { .min
= 18, .max
= 26 },
98 .m2
= { .min
= 6, .max
= 16 },
99 .p
= { .min
= 4, .max
= 128 },
100 .p1
= { .min
= 2, .max
= 33 },
101 .p2
= { .dot_limit
= 165000,
102 .p2_slow
= 4, .p2_fast
= 2 },
105 static const intel_limit_t intel_limits_i8xx_lvds
= {
106 .dot
= { .min
= 25000, .max
= 350000 },
107 .vco
= { .min
= 930000, .max
= 1400000 },
108 .n
= { .min
= 3, .max
= 16 },
109 .m
= { .min
= 96, .max
= 140 },
110 .m1
= { .min
= 18, .max
= 26 },
111 .m2
= { .min
= 6, .max
= 16 },
112 .p
= { .min
= 4, .max
= 128 },
113 .p1
= { .min
= 1, .max
= 6 },
114 .p2
= { .dot_limit
= 165000,
115 .p2_slow
= 14, .p2_fast
= 7 },
118 static const intel_limit_t intel_limits_i9xx_sdvo
= {
119 .dot
= { .min
= 20000, .max
= 400000 },
120 .vco
= { .min
= 1400000, .max
= 2800000 },
121 .n
= { .min
= 1, .max
= 6 },
122 .m
= { .min
= 70, .max
= 120 },
123 .m1
= { .min
= 8, .max
= 18 },
124 .m2
= { .min
= 3, .max
= 7 },
125 .p
= { .min
= 5, .max
= 80 },
126 .p1
= { .min
= 1, .max
= 8 },
127 .p2
= { .dot_limit
= 200000,
128 .p2_slow
= 10, .p2_fast
= 5 },
131 static const intel_limit_t intel_limits_i9xx_lvds
= {
132 .dot
= { .min
= 20000, .max
= 400000 },
133 .vco
= { .min
= 1400000, .max
= 2800000 },
134 .n
= { .min
= 1, .max
= 6 },
135 .m
= { .min
= 70, .max
= 120 },
136 .m1
= { .min
= 8, .max
= 18 },
137 .m2
= { .min
= 3, .max
= 7 },
138 .p
= { .min
= 7, .max
= 98 },
139 .p1
= { .min
= 1, .max
= 8 },
140 .p2
= { .dot_limit
= 112000,
141 .p2_slow
= 14, .p2_fast
= 7 },
145 static const intel_limit_t intel_limits_g4x_sdvo
= {
146 .dot
= { .min
= 25000, .max
= 270000 },
147 .vco
= { .min
= 1750000, .max
= 3500000},
148 .n
= { .min
= 1, .max
= 4 },
149 .m
= { .min
= 104, .max
= 138 },
150 .m1
= { .min
= 17, .max
= 23 },
151 .m2
= { .min
= 5, .max
= 11 },
152 .p
= { .min
= 10, .max
= 30 },
153 .p1
= { .min
= 1, .max
= 3},
154 .p2
= { .dot_limit
= 270000,
160 static const intel_limit_t intel_limits_g4x_hdmi
= {
161 .dot
= { .min
= 22000, .max
= 400000 },
162 .vco
= { .min
= 1750000, .max
= 3500000},
163 .n
= { .min
= 1, .max
= 4 },
164 .m
= { .min
= 104, .max
= 138 },
165 .m1
= { .min
= 16, .max
= 23 },
166 .m2
= { .min
= 5, .max
= 11 },
167 .p
= { .min
= 5, .max
= 80 },
168 .p1
= { .min
= 1, .max
= 8},
169 .p2
= { .dot_limit
= 165000,
170 .p2_slow
= 10, .p2_fast
= 5 },
173 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
174 .dot
= { .min
= 20000, .max
= 115000 },
175 .vco
= { .min
= 1750000, .max
= 3500000 },
176 .n
= { .min
= 1, .max
= 3 },
177 .m
= { .min
= 104, .max
= 138 },
178 .m1
= { .min
= 17, .max
= 23 },
179 .m2
= { .min
= 5, .max
= 11 },
180 .p
= { .min
= 28, .max
= 112 },
181 .p1
= { .min
= 2, .max
= 8 },
182 .p2
= { .dot_limit
= 0,
183 .p2_slow
= 14, .p2_fast
= 14
187 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
188 .dot
= { .min
= 80000, .max
= 224000 },
189 .vco
= { .min
= 1750000, .max
= 3500000 },
190 .n
= { .min
= 1, .max
= 3 },
191 .m
= { .min
= 104, .max
= 138 },
192 .m1
= { .min
= 17, .max
= 23 },
193 .m2
= { .min
= 5, .max
= 11 },
194 .p
= { .min
= 14, .max
= 42 },
195 .p1
= { .min
= 2, .max
= 6 },
196 .p2
= { .dot_limit
= 0,
197 .p2_slow
= 7, .p2_fast
= 7
201 static const intel_limit_t intel_limits_pineview_sdvo
= {
202 .dot
= { .min
= 20000, .max
= 400000},
203 .vco
= { .min
= 1700000, .max
= 3500000 },
204 /* Pineview's Ncounter is a ring counter */
205 .n
= { .min
= 3, .max
= 6 },
206 .m
= { .min
= 2, .max
= 256 },
207 /* Pineview only has one combined m divider, which we treat as m2. */
208 .m1
= { .min
= 0, .max
= 0 },
209 .m2
= { .min
= 0, .max
= 254 },
210 .p
= { .min
= 5, .max
= 80 },
211 .p1
= { .min
= 1, .max
= 8 },
212 .p2
= { .dot_limit
= 200000,
213 .p2_slow
= 10, .p2_fast
= 5 },
216 static const intel_limit_t intel_limits_pineview_lvds
= {
217 .dot
= { .min
= 20000, .max
= 400000 },
218 .vco
= { .min
= 1700000, .max
= 3500000 },
219 .n
= { .min
= 3, .max
= 6 },
220 .m
= { .min
= 2, .max
= 256 },
221 .m1
= { .min
= 0, .max
= 0 },
222 .m2
= { .min
= 0, .max
= 254 },
223 .p
= { .min
= 7, .max
= 112 },
224 .p1
= { .min
= 1, .max
= 8 },
225 .p2
= { .dot_limit
= 112000,
226 .p2_slow
= 14, .p2_fast
= 14 },
229 /* Ironlake / Sandybridge
231 * We calculate clock using (register_value + 2) for N/M1/M2, so here
232 * the range value for them is (actual_value - 2).
234 static const intel_limit_t intel_limits_ironlake_dac
= {
235 .dot
= { .min
= 25000, .max
= 350000 },
236 .vco
= { .min
= 1760000, .max
= 3510000 },
237 .n
= { .min
= 1, .max
= 5 },
238 .m
= { .min
= 79, .max
= 127 },
239 .m1
= { .min
= 12, .max
= 22 },
240 .m2
= { .min
= 5, .max
= 9 },
241 .p
= { .min
= 5, .max
= 80 },
242 .p1
= { .min
= 1, .max
= 8 },
243 .p2
= { .dot_limit
= 225000,
244 .p2_slow
= 10, .p2_fast
= 5 },
247 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
248 .dot
= { .min
= 25000, .max
= 350000 },
249 .vco
= { .min
= 1760000, .max
= 3510000 },
250 .n
= { .min
= 1, .max
= 3 },
251 .m
= { .min
= 79, .max
= 118 },
252 .m1
= { .min
= 12, .max
= 22 },
253 .m2
= { .min
= 5, .max
= 9 },
254 .p
= { .min
= 28, .max
= 112 },
255 .p1
= { .min
= 2, .max
= 8 },
256 .p2
= { .dot_limit
= 225000,
257 .p2_slow
= 14, .p2_fast
= 14 },
260 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
261 .dot
= { .min
= 25000, .max
= 350000 },
262 .vco
= { .min
= 1760000, .max
= 3510000 },
263 .n
= { .min
= 1, .max
= 3 },
264 .m
= { .min
= 79, .max
= 127 },
265 .m1
= { .min
= 12, .max
= 22 },
266 .m2
= { .min
= 5, .max
= 9 },
267 .p
= { .min
= 14, .max
= 56 },
268 .p1
= { .min
= 2, .max
= 8 },
269 .p2
= { .dot_limit
= 225000,
270 .p2_slow
= 7, .p2_fast
= 7 },
273 /* LVDS 100mhz refclk limits. */
274 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
275 .dot
= { .min
= 25000, .max
= 350000 },
276 .vco
= { .min
= 1760000, .max
= 3510000 },
277 .n
= { .min
= 1, .max
= 2 },
278 .m
= { .min
= 79, .max
= 126 },
279 .m1
= { .min
= 12, .max
= 22 },
280 .m2
= { .min
= 5, .max
= 9 },
281 .p
= { .min
= 28, .max
= 112 },
282 .p1
= { .min
= 2, .max
= 8 },
283 .p2
= { .dot_limit
= 225000,
284 .p2_slow
= 14, .p2_fast
= 14 },
287 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
288 .dot
= { .min
= 25000, .max
= 350000 },
289 .vco
= { .min
= 1760000, .max
= 3510000 },
290 .n
= { .min
= 1, .max
= 3 },
291 .m
= { .min
= 79, .max
= 126 },
292 .m1
= { .min
= 12, .max
= 22 },
293 .m2
= { .min
= 5, .max
= 9 },
294 .p
= { .min
= 14, .max
= 42 },
295 .p1
= { .min
= 2, .max
= 6 },
296 .p2
= { .dot_limit
= 225000,
297 .p2_slow
= 7, .p2_fast
= 7 },
300 static const intel_limit_t intel_limits_vlv_dac
= {
301 .dot
= { .min
= 25000, .max
= 270000 },
302 .vco
= { .min
= 4000000, .max
= 6000000 },
303 .n
= { .min
= 1, .max
= 7 },
304 .m
= { .min
= 22, .max
= 450 }, /* guess */
305 .m1
= { .min
= 2, .max
= 3 },
306 .m2
= { .min
= 11, .max
= 156 },
307 .p
= { .min
= 10, .max
= 30 },
308 .p1
= { .min
= 1, .max
= 3 },
309 .p2
= { .dot_limit
= 270000,
310 .p2_slow
= 2, .p2_fast
= 20 },
313 static const intel_limit_t intel_limits_vlv_hdmi
= {
314 .dot
= { .min
= 25000, .max
= 270000 },
315 .vco
= { .min
= 4000000, .max
= 6000000 },
316 .n
= { .min
= 1, .max
= 7 },
317 .m
= { .min
= 60, .max
= 300 }, /* guess */
318 .m1
= { .min
= 2, .max
= 3 },
319 .m2
= { .min
= 11, .max
= 156 },
320 .p
= { .min
= 10, .max
= 30 },
321 .p1
= { .min
= 2, .max
= 3 },
322 .p2
= { .dot_limit
= 270000,
323 .p2_slow
= 2, .p2_fast
= 20 },
326 static const intel_limit_t intel_limits_vlv_dp
= {
327 .dot
= { .min
= 25000, .max
= 270000 },
328 .vco
= { .min
= 4000000, .max
= 6000000 },
329 .n
= { .min
= 1, .max
= 7 },
330 .m
= { .min
= 22, .max
= 450 },
331 .m1
= { .min
= 2, .max
= 3 },
332 .m2
= { .min
= 11, .max
= 156 },
333 .p
= { .min
= 10, .max
= 30 },
334 .p1
= { .min
= 1, .max
= 3 },
335 .p2
= { .dot_limit
= 270000,
336 .p2_slow
= 2, .p2_fast
= 20 },
339 static const intel_limit_t
*intel_ironlake_limit(struct drm_crtc
*crtc
,
342 struct drm_device
*dev
= crtc
->dev
;
343 const intel_limit_t
*limit
;
345 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
346 if (intel_is_dual_link_lvds(dev
)) {
347 if (refclk
== 100000)
348 limit
= &intel_limits_ironlake_dual_lvds_100m
;
350 limit
= &intel_limits_ironlake_dual_lvds
;
352 if (refclk
== 100000)
353 limit
= &intel_limits_ironlake_single_lvds_100m
;
355 limit
= &intel_limits_ironlake_single_lvds
;
358 limit
= &intel_limits_ironlake_dac
;
363 static const intel_limit_t
*intel_g4x_limit(struct drm_crtc
*crtc
)
365 struct drm_device
*dev
= crtc
->dev
;
366 const intel_limit_t
*limit
;
368 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
369 if (intel_is_dual_link_lvds(dev
))
370 limit
= &intel_limits_g4x_dual_channel_lvds
;
372 limit
= &intel_limits_g4x_single_channel_lvds
;
373 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
) ||
374 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
375 limit
= &intel_limits_g4x_hdmi
;
376 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
)) {
377 limit
= &intel_limits_g4x_sdvo
;
378 } else /* The option is for other outputs */
379 limit
= &intel_limits_i9xx_sdvo
;
384 static const intel_limit_t
*intel_limit(struct drm_crtc
*crtc
, int refclk
)
386 struct drm_device
*dev
= crtc
->dev
;
387 const intel_limit_t
*limit
;
389 if (HAS_PCH_SPLIT(dev
))
390 limit
= intel_ironlake_limit(crtc
, refclk
);
391 else if (IS_G4X(dev
)) {
392 limit
= intel_g4x_limit(crtc
);
393 } else if (IS_PINEVIEW(dev
)) {
394 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
395 limit
= &intel_limits_pineview_lvds
;
397 limit
= &intel_limits_pineview_sdvo
;
398 } else if (IS_VALLEYVIEW(dev
)) {
399 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
))
400 limit
= &intel_limits_vlv_dac
;
401 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
))
402 limit
= &intel_limits_vlv_hdmi
;
404 limit
= &intel_limits_vlv_dp
;
405 } else if (!IS_GEN2(dev
)) {
406 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
407 limit
= &intel_limits_i9xx_lvds
;
409 limit
= &intel_limits_i9xx_sdvo
;
411 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
412 limit
= &intel_limits_i8xx_lvds
;
414 limit
= &intel_limits_i8xx_dvo
;
419 /* m1 is reserved as 0 in Pineview, n is a ring counter */
420 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
422 clock
->m
= clock
->m2
+ 2;
423 clock
->p
= clock
->p1
* clock
->p2
;
424 clock
->vco
= refclk
* clock
->m
/ clock
->n
;
425 clock
->dot
= clock
->vco
/ clock
->p
;
428 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
430 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
433 static void i9xx_clock(int refclk
, intel_clock_t
*clock
)
435 clock
->m
= i9xx_dpll_compute_m(clock
);
436 clock
->p
= clock
->p1
* clock
->p2
;
437 clock
->vco
= refclk
* clock
->m
/ (clock
->n
+ 2);
438 clock
->dot
= clock
->vco
/ clock
->p
;
442 * Returns whether any output on the specified pipe is of the specified type
444 bool intel_pipe_has_type(struct drm_crtc
*crtc
, int type
)
446 struct drm_device
*dev
= crtc
->dev
;
447 struct intel_encoder
*encoder
;
449 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
450 if (encoder
->type
== type
)
456 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
458 * Returns whether the given set of divisors are valid for a given refclk with
459 * the given connectors.
462 static bool intel_PLL_is_valid(struct drm_device
*dev
,
463 const intel_limit_t
*limit
,
464 const intel_clock_t
*clock
)
466 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
467 INTELPllInvalid("p1 out of range\n");
468 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
469 INTELPllInvalid("p out of range\n");
470 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
471 INTELPllInvalid("m2 out of range\n");
472 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
473 INTELPllInvalid("m1 out of range\n");
474 if (clock
->m1
<= clock
->m2
&& !IS_PINEVIEW(dev
))
475 INTELPllInvalid("m1 <= m2\n");
476 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
477 INTELPllInvalid("m out of range\n");
478 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
479 INTELPllInvalid("n out of range\n");
480 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
481 INTELPllInvalid("vco out of range\n");
482 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
483 * connector, etc., rather than just a single range.
485 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
486 INTELPllInvalid("dot out of range\n");
492 i9xx_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
493 int target
, int refclk
, intel_clock_t
*match_clock
,
494 intel_clock_t
*best_clock
)
496 struct drm_device
*dev
= crtc
->dev
;
500 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
502 * For LVDS just rely on its current settings for dual-channel.
503 * We haven't figured out how to reliably set up different
504 * single/dual channel state, if we even can.
506 if (intel_is_dual_link_lvds(dev
))
507 clock
.p2
= limit
->p2
.p2_fast
;
509 clock
.p2
= limit
->p2
.p2_slow
;
511 if (target
< limit
->p2
.dot_limit
)
512 clock
.p2
= limit
->p2
.p2_slow
;
514 clock
.p2
= limit
->p2
.p2_fast
;
517 memset(best_clock
, 0, sizeof(*best_clock
));
519 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
521 for (clock
.m2
= limit
->m2
.min
;
522 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
523 if (clock
.m2
>= clock
.m1
)
525 for (clock
.n
= limit
->n
.min
;
526 clock
.n
<= limit
->n
.max
; clock
.n
++) {
527 for (clock
.p1
= limit
->p1
.min
;
528 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
531 i9xx_clock(refclk
, &clock
);
532 if (!intel_PLL_is_valid(dev
, limit
,
536 clock
.p
!= match_clock
->p
)
539 this_err
= abs(clock
.dot
- target
);
540 if (this_err
< err
) {
549 return (err
!= target
);
553 pnv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
554 int target
, int refclk
, intel_clock_t
*match_clock
,
555 intel_clock_t
*best_clock
)
557 struct drm_device
*dev
= crtc
->dev
;
561 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
563 * For LVDS just rely on its current settings for dual-channel.
564 * We haven't figured out how to reliably set up different
565 * single/dual channel state, if we even can.
567 if (intel_is_dual_link_lvds(dev
))
568 clock
.p2
= limit
->p2
.p2_fast
;
570 clock
.p2
= limit
->p2
.p2_slow
;
572 if (target
< limit
->p2
.dot_limit
)
573 clock
.p2
= limit
->p2
.p2_slow
;
575 clock
.p2
= limit
->p2
.p2_fast
;
578 memset(best_clock
, 0, sizeof(*best_clock
));
580 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
582 for (clock
.m2
= limit
->m2
.min
;
583 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
584 for (clock
.n
= limit
->n
.min
;
585 clock
.n
<= limit
->n
.max
; clock
.n
++) {
586 for (clock
.p1
= limit
->p1
.min
;
587 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
590 pineview_clock(refclk
, &clock
);
591 if (!intel_PLL_is_valid(dev
, limit
,
595 clock
.p
!= match_clock
->p
)
598 this_err
= abs(clock
.dot
- target
);
599 if (this_err
< err
) {
608 return (err
!= target
);
612 g4x_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
613 int target
, int refclk
, intel_clock_t
*match_clock
,
614 intel_clock_t
*best_clock
)
616 struct drm_device
*dev
= crtc
->dev
;
620 /* approximately equals target * 0.00585 */
621 int err_most
= (target
>> 8) + (target
>> 9);
624 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
625 if (intel_is_dual_link_lvds(dev
))
626 clock
.p2
= limit
->p2
.p2_fast
;
628 clock
.p2
= limit
->p2
.p2_slow
;
630 if (target
< limit
->p2
.dot_limit
)
631 clock
.p2
= limit
->p2
.p2_slow
;
633 clock
.p2
= limit
->p2
.p2_fast
;
636 memset(best_clock
, 0, sizeof(*best_clock
));
637 max_n
= limit
->n
.max
;
638 /* based on hardware requirement, prefer smaller n to precision */
639 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
640 /* based on hardware requirement, prefere larger m1,m2 */
641 for (clock
.m1
= limit
->m1
.max
;
642 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
643 for (clock
.m2
= limit
->m2
.max
;
644 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
645 for (clock
.p1
= limit
->p1
.max
;
646 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
649 i9xx_clock(refclk
, &clock
);
650 if (!intel_PLL_is_valid(dev
, limit
,
654 this_err
= abs(clock
.dot
- target
);
655 if (this_err
< err_most
) {
669 vlv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
670 int target
, int refclk
, intel_clock_t
*match_clock
,
671 intel_clock_t
*best_clock
)
673 u32 p1
, p2
, m1
, m2
, vco
, bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
675 u32 updrate
, minupdate
, fracbits
, p
;
676 unsigned long bestppm
, ppm
, absppm
;
680 dotclk
= target
* 1000;
683 fastclk
= dotclk
/ (2*100);
687 n
= p
= p1
= p2
= m
= m1
= m2
= vco
= bestn
= 0;
688 bestm1
= bestm2
= bestp1
= bestp2
= 0;
690 /* based on hardware requirement, prefer smaller n to precision */
691 for (n
= limit
->n
.min
; n
<= ((refclk
) / minupdate
); n
++) {
692 updrate
= refclk
/ n
;
693 for (p1
= limit
->p1
.max
; p1
> limit
->p1
.min
; p1
--) {
694 for (p2
= limit
->p2
.p2_fast
+1; p2
> 0; p2
--) {
698 /* based on hardware requirement, prefer bigger m1,m2 values */
699 for (m1
= limit
->m1
.min
; m1
<= limit
->m1
.max
; m1
++) {
700 m2
= (((2*(fastclk
* p
* n
/ m1
)) +
701 refclk
) / (2*refclk
));
704 if (vco
>= limit
->vco
.min
&& vco
< limit
->vco
.max
) {
705 ppm
= 1000000 * ((vco
/ p
) - fastclk
) / fastclk
;
706 absppm
= (ppm
> 0) ? ppm
: (-ppm
);
707 if (absppm
< 100 && ((p1
* p2
) > (bestp1
* bestp2
))) {
711 if (absppm
< bestppm
- 10) {
728 best_clock
->n
= bestn
;
729 best_clock
->m1
= bestm1
;
730 best_clock
->m2
= bestm2
;
731 best_clock
->p1
= bestp1
;
732 best_clock
->p2
= bestp2
;
737 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
740 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
741 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
743 return intel_crtc
->config
.cpu_transcoder
;
746 static void ironlake_wait_for_vblank(struct drm_device
*dev
, int pipe
)
748 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
749 u32 frame
, frame_reg
= PIPEFRAME(pipe
);
751 frame
= I915_READ(frame_reg
);
753 if (wait_for(I915_READ_NOTRACE(frame_reg
) != frame
, 50))
754 DRM_DEBUG_KMS("vblank wait timed out\n");
758 * intel_wait_for_vblank - wait for vblank on a given pipe
760 * @pipe: pipe to wait for
762 * Wait for vblank to occur on a given pipe. Needed for various bits of
765 void intel_wait_for_vblank(struct drm_device
*dev
, int pipe
)
767 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
768 int pipestat_reg
= PIPESTAT(pipe
);
770 if (INTEL_INFO(dev
)->gen
>= 5) {
771 ironlake_wait_for_vblank(dev
, pipe
);
775 /* Clear existing vblank status. Note this will clear any other
776 * sticky status fields as well.
778 * This races with i915_driver_irq_handler() with the result
779 * that either function could miss a vblank event. Here it is not
780 * fatal, as we will either wait upon the next vblank interrupt or
781 * timeout. Generally speaking intel_wait_for_vblank() is only
782 * called during modeset at which time the GPU should be idle and
783 * should *not* be performing page flips and thus not waiting on
785 * Currently, the result of us stealing a vblank from the irq
786 * handler is that a single frame will be skipped during swapbuffers.
788 I915_WRITE(pipestat_reg
,
789 I915_READ(pipestat_reg
) | PIPE_VBLANK_INTERRUPT_STATUS
);
791 /* Wait for vblank interrupt bit to set */
792 if (wait_for(I915_READ(pipestat_reg
) &
793 PIPE_VBLANK_INTERRUPT_STATUS
,
795 DRM_DEBUG_KMS("vblank wait timed out\n");
799 * intel_wait_for_pipe_off - wait for pipe to turn off
801 * @pipe: pipe to wait for
803 * After disabling a pipe, we can't wait for vblank in the usual way,
804 * spinning on the vblank interrupt status bit, since we won't actually
805 * see an interrupt when the pipe is disabled.
808 * wait for the pipe register state bit to turn off
811 * wait for the display line value to settle (it usually
812 * ends up stopping at the start of the next frame).
815 void intel_wait_for_pipe_off(struct drm_device
*dev
, int pipe
)
817 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
818 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
821 if (INTEL_INFO(dev
)->gen
>= 4) {
822 int reg
= PIPECONF(cpu_transcoder
);
824 /* Wait for the Pipe State to go off */
825 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
827 WARN(1, "pipe_off wait timed out\n");
829 u32 last_line
, line_mask
;
830 int reg
= PIPEDSL(pipe
);
831 unsigned long timeout
= jiffies
+ msecs_to_jiffies(100);
834 line_mask
= DSL_LINEMASK_GEN2
;
836 line_mask
= DSL_LINEMASK_GEN3
;
838 /* Wait for the display line to settle */
840 last_line
= I915_READ(reg
) & line_mask
;
842 } while (((I915_READ(reg
) & line_mask
) != last_line
) &&
843 time_after(timeout
, jiffies
));
844 if (time_after(jiffies
, timeout
))
845 WARN(1, "pipe_off wait timed out\n");
850 * ibx_digital_port_connected - is the specified port connected?
851 * @dev_priv: i915 private structure
852 * @port: the port to test
854 * Returns true if @port is connected, false otherwise.
856 bool ibx_digital_port_connected(struct drm_i915_private
*dev_priv
,
857 struct intel_digital_port
*port
)
861 if (HAS_PCH_IBX(dev_priv
->dev
)) {
864 bit
= SDE_PORTB_HOTPLUG
;
867 bit
= SDE_PORTC_HOTPLUG
;
870 bit
= SDE_PORTD_HOTPLUG
;
878 bit
= SDE_PORTB_HOTPLUG_CPT
;
881 bit
= SDE_PORTC_HOTPLUG_CPT
;
884 bit
= SDE_PORTD_HOTPLUG_CPT
;
891 return I915_READ(SDEISR
) & bit
;
894 static const char *state_string(bool enabled
)
896 return enabled
? "on" : "off";
899 /* Only for pre-ILK configs */
900 void assert_pll(struct drm_i915_private
*dev_priv
,
901 enum pipe pipe
, bool state
)
908 val
= I915_READ(reg
);
909 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
910 WARN(cur_state
!= state
,
911 "PLL state assertion failure (expected %s, current %s)\n",
912 state_string(state
), state_string(cur_state
));
915 struct intel_shared_dpll
*
916 intel_crtc_to_shared_dpll(struct intel_crtc
*crtc
)
918 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
920 if (crtc
->config
.shared_dpll
< 0)
923 return &dev_priv
->shared_dplls
[crtc
->config
.shared_dpll
];
927 void assert_shared_dpll(struct drm_i915_private
*dev_priv
,
928 struct intel_shared_dpll
*pll
,
932 struct intel_dpll_hw_state hw_state
;
934 if (HAS_PCH_LPT(dev_priv
->dev
)) {
935 DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
940 "asserting DPLL %s with no DPLL\n", state_string(state
)))
943 cur_state
= pll
->get_hw_state(dev_priv
, pll
, &hw_state
);
944 WARN(cur_state
!= state
,
945 "%s assertion failure (expected %s, current %s)\n",
946 pll
->name
, state_string(state
), state_string(cur_state
));
949 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
950 enum pipe pipe
, bool state
)
955 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
958 if (HAS_DDI(dev_priv
->dev
)) {
959 /* DDI does not have a specific FDI_TX register */
960 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
961 val
= I915_READ(reg
);
962 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
964 reg
= FDI_TX_CTL(pipe
);
965 val
= I915_READ(reg
);
966 cur_state
= !!(val
& FDI_TX_ENABLE
);
968 WARN(cur_state
!= state
,
969 "FDI TX state assertion failure (expected %s, current %s)\n",
970 state_string(state
), state_string(cur_state
));
972 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
973 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
975 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
976 enum pipe pipe
, bool state
)
982 reg
= FDI_RX_CTL(pipe
);
983 val
= I915_READ(reg
);
984 cur_state
= !!(val
& FDI_RX_ENABLE
);
985 WARN(cur_state
!= state
,
986 "FDI RX state assertion failure (expected %s, current %s)\n",
987 state_string(state
), state_string(cur_state
));
989 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
990 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
992 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
998 /* ILK FDI PLL is always enabled */
999 if (dev_priv
->info
->gen
== 5)
1002 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1003 if (HAS_DDI(dev_priv
->dev
))
1006 reg
= FDI_TX_CTL(pipe
);
1007 val
= I915_READ(reg
);
1008 WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1011 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1012 enum pipe pipe
, bool state
)
1018 reg
= FDI_RX_CTL(pipe
);
1019 val
= I915_READ(reg
);
1020 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1021 WARN(cur_state
!= state
,
1022 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1023 state_string(state
), state_string(cur_state
));
1026 static void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1029 int pp_reg
, lvds_reg
;
1031 enum pipe panel_pipe
= PIPE_A
;
1034 if (HAS_PCH_SPLIT(dev_priv
->dev
)) {
1035 pp_reg
= PCH_PP_CONTROL
;
1036 lvds_reg
= PCH_LVDS
;
1038 pp_reg
= PP_CONTROL
;
1042 val
= I915_READ(pp_reg
);
1043 if (!(val
& PANEL_POWER_ON
) ||
1044 ((val
& PANEL_UNLOCK_REGS
) == PANEL_UNLOCK_REGS
))
1047 if (I915_READ(lvds_reg
) & LVDS_PIPEB_SELECT
)
1048 panel_pipe
= PIPE_B
;
1050 WARN(panel_pipe
== pipe
&& locked
,
1051 "panel assertion failure, pipe %c regs locked\n",
1055 void assert_pipe(struct drm_i915_private
*dev_priv
,
1056 enum pipe pipe
, bool state
)
1061 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1064 /* if we need the pipe A quirk it must be always on */
1065 if (pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
)
1068 if (!intel_display_power_enabled(dev_priv
->dev
,
1069 POWER_DOMAIN_TRANSCODER(cpu_transcoder
))) {
1072 reg
= PIPECONF(cpu_transcoder
);
1073 val
= I915_READ(reg
);
1074 cur_state
= !!(val
& PIPECONF_ENABLE
);
1077 WARN(cur_state
!= state
,
1078 "pipe %c assertion failure (expected %s, current %s)\n",
1079 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1082 static void assert_plane(struct drm_i915_private
*dev_priv
,
1083 enum plane plane
, bool state
)
1089 reg
= DSPCNTR(plane
);
1090 val
= I915_READ(reg
);
1091 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1092 WARN(cur_state
!= state
,
1093 "plane %c assertion failure (expected %s, current %s)\n",
1094 plane_name(plane
), state_string(state
), state_string(cur_state
));
1097 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1098 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1100 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1103 struct drm_device
*dev
= dev_priv
->dev
;
1108 /* Primary planes are fixed to pipes on gen4+ */
1109 if (INTEL_INFO(dev
)->gen
>= 4) {
1110 reg
= DSPCNTR(pipe
);
1111 val
= I915_READ(reg
);
1112 WARN((val
& DISPLAY_PLANE_ENABLE
),
1113 "plane %c assertion failure, should be disabled but not\n",
1118 /* Need to check both planes against the pipe */
1119 for (i
= 0; i
< INTEL_INFO(dev
)->num_pipes
; i
++) {
1121 val
= I915_READ(reg
);
1122 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1123 DISPPLANE_SEL_PIPE_SHIFT
;
1124 WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1125 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1126 plane_name(i
), pipe_name(pipe
));
1130 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1133 struct drm_device
*dev
= dev_priv
->dev
;
1137 if (IS_VALLEYVIEW(dev
)) {
1138 for (i
= 0; i
< dev_priv
->num_plane
; i
++) {
1139 reg
= SPCNTR(pipe
, i
);
1140 val
= I915_READ(reg
);
1141 WARN((val
& SP_ENABLE
),
1142 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1143 sprite_name(pipe
, i
), pipe_name(pipe
));
1145 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1147 val
= I915_READ(reg
);
1148 WARN((val
& SPRITE_ENABLE
),
1149 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1150 plane_name(pipe
), pipe_name(pipe
));
1151 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1152 reg
= DVSCNTR(pipe
);
1153 val
= I915_READ(reg
);
1154 WARN((val
& DVS_ENABLE
),
1155 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1156 plane_name(pipe
), pipe_name(pipe
));
1160 static void assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1165 if (HAS_PCH_LPT(dev_priv
->dev
)) {
1166 DRM_DEBUG_DRIVER("LPT does not has PCH refclk, skipping check\n");
1170 val
= I915_READ(PCH_DREF_CONTROL
);
1171 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1172 DREF_SUPERSPREAD_SOURCE_MASK
));
1173 WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1176 static void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1183 reg
= PCH_TRANSCONF(pipe
);
1184 val
= I915_READ(reg
);
1185 enabled
= !!(val
& TRANS_ENABLE
);
1187 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1191 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1192 enum pipe pipe
, u32 port_sel
, u32 val
)
1194 if ((val
& DP_PORT_EN
) == 0)
1197 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1198 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1199 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1200 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1203 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1209 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1210 enum pipe pipe
, u32 val
)
1212 if ((val
& SDVO_ENABLE
) == 0)
1215 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1216 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1219 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1225 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1226 enum pipe pipe
, u32 val
)
1228 if ((val
& LVDS_PORT_EN
) == 0)
1231 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1232 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1235 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1241 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1242 enum pipe pipe
, u32 val
)
1244 if ((val
& ADPA_DAC_ENABLE
) == 0)
1246 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1247 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1250 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1256 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1257 enum pipe pipe
, int reg
, u32 port_sel
)
1259 u32 val
= I915_READ(reg
);
1260 WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1261 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1262 reg
, pipe_name(pipe
));
1264 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1265 && (val
& DP_PIPEB_SELECT
),
1266 "IBX PCH dp port still using transcoder B\n");
1269 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1270 enum pipe pipe
, int reg
)
1272 u32 val
= I915_READ(reg
);
1273 WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1274 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1275 reg
, pipe_name(pipe
));
1277 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& SDVO_ENABLE
) == 0
1278 && (val
& SDVO_PIPE_B_SELECT
),
1279 "IBX PCH hdmi port still using transcoder B\n");
1282 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1288 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1289 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1290 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1293 val
= I915_READ(reg
);
1294 WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1295 "PCH VGA enabled on transcoder %c, should be disabled\n",
1299 val
= I915_READ(reg
);
1300 WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1301 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1304 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1305 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1306 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1309 static void vlv_enable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1314 assert_pipe_disabled(dev_priv
, pipe
);
1316 /* No really, not for ILK+ */
1317 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
));
1319 /* PLL is protected by panel, make sure we can write it */
1320 if (IS_MOBILE(dev_priv
->dev
) && !IS_I830(dev_priv
->dev
))
1321 assert_panel_unlocked(dev_priv
, pipe
);
1324 val
= I915_READ(reg
);
1325 val
|= DPLL_VCO_ENABLE
;
1327 /* We do this three times for luck */
1328 I915_WRITE(reg
, val
);
1330 udelay(150); /* wait for warmup */
1331 I915_WRITE(reg
, val
);
1333 udelay(150); /* wait for warmup */
1334 I915_WRITE(reg
, val
);
1336 udelay(150); /* wait for warmup */
1339 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1341 struct drm_device
*dev
= crtc
->base
.dev
;
1342 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1343 int reg
= DPLL(crtc
->pipe
);
1344 u32 dpll
= crtc
->config
.dpll_hw_state
.dpll
;
1346 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1348 /* No really, not for ILK+ */
1349 BUG_ON(dev_priv
->info
->gen
>= 5);
1351 /* PLL is protected by panel, make sure we can write it */
1352 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1353 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1355 I915_WRITE(reg
, dpll
);
1357 /* Wait for the clocks to stabilize. */
1361 if (INTEL_INFO(dev
)->gen
>= 4) {
1362 I915_WRITE(DPLL_MD(crtc
->pipe
),
1363 crtc
->config
.dpll_hw_state
.dpll_md
);
1365 /* The pixel multiplier can only be updated once the
1366 * DPLL is enabled and the clocks are stable.
1368 * So write it again.
1370 I915_WRITE(reg
, dpll
);
1373 /* We do this three times for luck */
1374 I915_WRITE(reg
, dpll
);
1376 udelay(150); /* wait for warmup */
1377 I915_WRITE(reg
, dpll
);
1379 udelay(150); /* wait for warmup */
1380 I915_WRITE(reg
, dpll
);
1382 udelay(150); /* wait for warmup */
1386 * intel_disable_pll - disable a PLL
1387 * @dev_priv: i915 private structure
1388 * @pipe: pipe PLL to disable
1390 * Disable the PLL for @pipe, making sure the pipe is off first.
1392 * Note! This is for pre-ILK only.
1394 static void intel_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1399 /* Don't disable pipe A or pipe A PLLs if needed */
1400 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
1403 /* Make sure the pipe isn't still relying on us */
1404 assert_pipe_disabled(dev_priv
, pipe
);
1407 val
= I915_READ(reg
);
1408 val
&= ~DPLL_VCO_ENABLE
;
1409 I915_WRITE(reg
, val
);
1413 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
, int port
)
1418 port_mask
= DPLL_PORTB_READY_MASK
;
1420 port_mask
= DPLL_PORTC_READY_MASK
;
1422 if (wait_for((I915_READ(DPLL(0)) & port_mask
) == 0, 1000))
1423 WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
1424 'B' + port
, I915_READ(DPLL(0)));
1428 * ironlake_enable_shared_dpll - enable PCH PLL
1429 * @dev_priv: i915 private structure
1430 * @pipe: pipe PLL to enable
1432 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1433 * drives the transcoder clock.
1435 static void ironlake_enable_shared_dpll(struct intel_crtc
*crtc
)
1437 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
1438 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1440 /* PCH PLLs only available on ILK, SNB and IVB */
1441 BUG_ON(dev_priv
->info
->gen
< 5);
1442 if (WARN_ON(pll
== NULL
))
1445 if (WARN_ON(pll
->refcount
== 0))
1448 DRM_DEBUG_KMS("enable %s (active %d, on? %d)for crtc %d\n",
1449 pll
->name
, pll
->active
, pll
->on
,
1450 crtc
->base
.base
.id
);
1452 if (pll
->active
++) {
1454 assert_shared_dpll_enabled(dev_priv
, pll
);
1459 DRM_DEBUG_KMS("enabling %s\n", pll
->name
);
1460 pll
->enable(dev_priv
, pll
);
1464 static void intel_disable_shared_dpll(struct intel_crtc
*crtc
)
1466 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
1467 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1469 /* PCH only available on ILK+ */
1470 BUG_ON(dev_priv
->info
->gen
< 5);
1471 if (WARN_ON(pll
== NULL
))
1474 if (WARN_ON(pll
->refcount
== 0))
1477 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1478 pll
->name
, pll
->active
, pll
->on
,
1479 crtc
->base
.base
.id
);
1481 if (WARN_ON(pll
->active
== 0)) {
1482 assert_shared_dpll_disabled(dev_priv
, pll
);
1486 assert_shared_dpll_enabled(dev_priv
, pll
);
1491 DRM_DEBUG_KMS("disabling %s\n", pll
->name
);
1492 pll
->disable(dev_priv
, pll
);
1496 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1499 struct drm_device
*dev
= dev_priv
->dev
;
1500 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1501 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1502 uint32_t reg
, val
, pipeconf_val
;
1504 /* PCH only available on ILK+ */
1505 BUG_ON(dev_priv
->info
->gen
< 5);
1507 /* Make sure PCH DPLL is enabled */
1508 assert_shared_dpll_enabled(dev_priv
,
1509 intel_crtc_to_shared_dpll(intel_crtc
));
1511 /* FDI must be feeding us bits for PCH ports */
1512 assert_fdi_tx_enabled(dev_priv
, pipe
);
1513 assert_fdi_rx_enabled(dev_priv
, pipe
);
1515 if (HAS_PCH_CPT(dev
)) {
1516 /* Workaround: Set the timing override bit before enabling the
1517 * pch transcoder. */
1518 reg
= TRANS_CHICKEN2(pipe
);
1519 val
= I915_READ(reg
);
1520 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1521 I915_WRITE(reg
, val
);
1524 reg
= PCH_TRANSCONF(pipe
);
1525 val
= I915_READ(reg
);
1526 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1528 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1530 * make the BPC in transcoder be consistent with
1531 * that in pipeconf reg.
1533 val
&= ~PIPECONF_BPC_MASK
;
1534 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1537 val
&= ~TRANS_INTERLACE_MASK
;
1538 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1539 if (HAS_PCH_IBX(dev_priv
->dev
) &&
1540 intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
))
1541 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1543 val
|= TRANS_INTERLACED
;
1545 val
|= TRANS_PROGRESSIVE
;
1547 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1548 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
1549 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1552 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1553 enum transcoder cpu_transcoder
)
1555 u32 val
, pipeconf_val
;
1557 /* PCH only available on ILK+ */
1558 BUG_ON(dev_priv
->info
->gen
< 5);
1560 /* FDI must be feeding us bits for PCH ports */
1561 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1562 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1564 /* Workaround: set timing override bit. */
1565 val
= I915_READ(_TRANSA_CHICKEN2
);
1566 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1567 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1570 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1572 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1573 PIPECONF_INTERLACED_ILK
)
1574 val
|= TRANS_INTERLACED
;
1576 val
|= TRANS_PROGRESSIVE
;
1578 I915_WRITE(LPT_TRANSCONF
, val
);
1579 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
1580 DRM_ERROR("Failed to enable PCH transcoder\n");
1583 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1586 struct drm_device
*dev
= dev_priv
->dev
;
1589 /* FDI relies on the transcoder */
1590 assert_fdi_tx_disabled(dev_priv
, pipe
);
1591 assert_fdi_rx_disabled(dev_priv
, pipe
);
1593 /* Ports must be off as well */
1594 assert_pch_ports_disabled(dev_priv
, pipe
);
1596 reg
= PCH_TRANSCONF(pipe
);
1597 val
= I915_READ(reg
);
1598 val
&= ~TRANS_ENABLE
;
1599 I915_WRITE(reg
, val
);
1600 /* wait for PCH transcoder off, transcoder state */
1601 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
1602 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1604 if (!HAS_PCH_IBX(dev
)) {
1605 /* Workaround: Clear the timing override chicken bit again. */
1606 reg
= TRANS_CHICKEN2(pipe
);
1607 val
= I915_READ(reg
);
1608 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1609 I915_WRITE(reg
, val
);
1613 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1617 val
= I915_READ(LPT_TRANSCONF
);
1618 val
&= ~TRANS_ENABLE
;
1619 I915_WRITE(LPT_TRANSCONF
, val
);
1620 /* wait for PCH transcoder off, transcoder state */
1621 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
1622 DRM_ERROR("Failed to disable PCH transcoder\n");
1624 /* Workaround: clear timing override bit. */
1625 val
= I915_READ(_TRANSA_CHICKEN2
);
1626 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1627 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1631 * intel_enable_pipe - enable a pipe, asserting requirements
1632 * @dev_priv: i915 private structure
1633 * @pipe: pipe to enable
1634 * @pch_port: on ILK+, is this pipe driving a PCH port or not
1636 * Enable @pipe, making sure that various hardware specific requirements
1637 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1639 * @pipe should be %PIPE_A or %PIPE_B.
1641 * Will wait until the pipe is actually running (i.e. first vblank) before
1644 static void intel_enable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
,
1647 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1649 enum pipe pch_transcoder
;
1653 assert_planes_disabled(dev_priv
, pipe
);
1654 assert_sprites_disabled(dev_priv
, pipe
);
1656 if (HAS_PCH_LPT(dev_priv
->dev
))
1657 pch_transcoder
= TRANSCODER_A
;
1659 pch_transcoder
= pipe
;
1662 * A pipe without a PLL won't actually be able to drive bits from
1663 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1666 if (!HAS_PCH_SPLIT(dev_priv
->dev
))
1667 assert_pll_enabled(dev_priv
, pipe
);
1670 /* if driving the PCH, we need FDI enabled */
1671 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
1672 assert_fdi_tx_pll_enabled(dev_priv
,
1673 (enum pipe
) cpu_transcoder
);
1675 /* FIXME: assert CPU port conditions for SNB+ */
1678 reg
= PIPECONF(cpu_transcoder
);
1679 val
= I915_READ(reg
);
1680 if (val
& PIPECONF_ENABLE
)
1683 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
1684 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
1688 * intel_disable_pipe - disable a pipe, asserting requirements
1689 * @dev_priv: i915 private structure
1690 * @pipe: pipe to disable
1692 * Disable @pipe, making sure that various hardware specific requirements
1693 * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
1695 * @pipe should be %PIPE_A or %PIPE_B.
1697 * Will wait until the pipe has shut down before returning.
1699 static void intel_disable_pipe(struct drm_i915_private
*dev_priv
,
1702 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1708 * Make sure planes won't keep trying to pump pixels to us,
1709 * or we might hang the display.
1711 assert_planes_disabled(dev_priv
, pipe
);
1712 assert_sprites_disabled(dev_priv
, pipe
);
1714 /* Don't disable pipe A or pipe A PLLs if needed */
1715 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
1718 reg
= PIPECONF(cpu_transcoder
);
1719 val
= I915_READ(reg
);
1720 if ((val
& PIPECONF_ENABLE
) == 0)
1723 I915_WRITE(reg
, val
& ~PIPECONF_ENABLE
);
1724 intel_wait_for_pipe_off(dev_priv
->dev
, pipe
);
1728 * Plane regs are double buffered, going from enabled->disabled needs a
1729 * trigger in order to latch. The display address reg provides this.
1731 void intel_flush_display_plane(struct drm_i915_private
*dev_priv
,
1734 if (dev_priv
->info
->gen
>= 4)
1735 I915_WRITE(DSPSURF(plane
), I915_READ(DSPSURF(plane
)));
1737 I915_WRITE(DSPADDR(plane
), I915_READ(DSPADDR(plane
)));
1741 * intel_enable_plane - enable a display plane on a given pipe
1742 * @dev_priv: i915 private structure
1743 * @plane: plane to enable
1744 * @pipe: pipe being fed
1746 * Enable @plane on @pipe, making sure that @pipe is running first.
1748 static void intel_enable_plane(struct drm_i915_private
*dev_priv
,
1749 enum plane plane
, enum pipe pipe
)
1754 /* If the pipe isn't enabled, we can't pump pixels and may hang */
1755 assert_pipe_enabled(dev_priv
, pipe
);
1757 reg
= DSPCNTR(plane
);
1758 val
= I915_READ(reg
);
1759 if (val
& DISPLAY_PLANE_ENABLE
)
1762 I915_WRITE(reg
, val
| DISPLAY_PLANE_ENABLE
);
1763 intel_flush_display_plane(dev_priv
, plane
);
1764 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
1768 * intel_disable_plane - disable a display plane
1769 * @dev_priv: i915 private structure
1770 * @plane: plane to disable
1771 * @pipe: pipe consuming the data
1773 * Disable @plane; should be an independent operation.
1775 static void intel_disable_plane(struct drm_i915_private
*dev_priv
,
1776 enum plane plane
, enum pipe pipe
)
1781 reg
= DSPCNTR(plane
);
1782 val
= I915_READ(reg
);
1783 if ((val
& DISPLAY_PLANE_ENABLE
) == 0)
1786 I915_WRITE(reg
, val
& ~DISPLAY_PLANE_ENABLE
);
1787 intel_flush_display_plane(dev_priv
, plane
);
1788 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
1791 static bool need_vtd_wa(struct drm_device
*dev
)
1793 #ifdef CONFIG_INTEL_IOMMU
1794 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
1801 intel_pin_and_fence_fb_obj(struct drm_device
*dev
,
1802 struct drm_i915_gem_object
*obj
,
1803 struct intel_ring_buffer
*pipelined
)
1805 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1809 switch (obj
->tiling_mode
) {
1810 case I915_TILING_NONE
:
1811 if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
1812 alignment
= 128 * 1024;
1813 else if (INTEL_INFO(dev
)->gen
>= 4)
1814 alignment
= 4 * 1024;
1816 alignment
= 64 * 1024;
1819 /* pin() will align the object as required by fence */
1823 /* Despite that we check this in framebuffer_init userspace can
1824 * screw us over and change the tiling after the fact. Only
1825 * pinned buffers can't change their tiling. */
1826 DRM_DEBUG_DRIVER("Y tiled not allowed for scan out buffers\n");
1832 /* Note that the w/a also requires 64 PTE of padding following the
1833 * bo. We currently fill all unused PTE with the shadow page and so
1834 * we should always have valid PTE following the scanout preventing
1837 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
1838 alignment
= 256 * 1024;
1840 dev_priv
->mm
.interruptible
= false;
1841 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
);
1843 goto err_interruptible
;
1845 /* Install a fence for tiled scan-out. Pre-i965 always needs a
1846 * fence, whereas 965+ only requires a fence if using
1847 * framebuffer compression. For simplicity, we always install
1848 * a fence as the cost is not that onerous.
1850 ret
= i915_gem_object_get_fence(obj
);
1854 i915_gem_object_pin_fence(obj
);
1856 dev_priv
->mm
.interruptible
= true;
1860 i915_gem_object_unpin(obj
);
1862 dev_priv
->mm
.interruptible
= true;
1866 void intel_unpin_fb_obj(struct drm_i915_gem_object
*obj
)
1868 i915_gem_object_unpin_fence(obj
);
1869 i915_gem_object_unpin(obj
);
1872 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
1873 * is assumed to be a power-of-two. */
1874 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
1875 unsigned int tiling_mode
,
1879 if (tiling_mode
!= I915_TILING_NONE
) {
1880 unsigned int tile_rows
, tiles
;
1885 tiles
= *x
/ (512/cpp
);
1888 return tile_rows
* pitch
* 8 + tiles
* 4096;
1890 unsigned int offset
;
1892 offset
= *y
* pitch
+ *x
* cpp
;
1894 *x
= (offset
& 4095) / cpp
;
1895 return offset
& -4096;
1899 static int i9xx_update_plane(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
1902 struct drm_device
*dev
= crtc
->dev
;
1903 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1904 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1905 struct intel_framebuffer
*intel_fb
;
1906 struct drm_i915_gem_object
*obj
;
1907 int plane
= intel_crtc
->plane
;
1908 unsigned long linear_offset
;
1917 DRM_ERROR("Can't update plane %c in SAREA\n", plane_name(plane
));
1921 intel_fb
= to_intel_framebuffer(fb
);
1922 obj
= intel_fb
->obj
;
1924 reg
= DSPCNTR(plane
);
1925 dspcntr
= I915_READ(reg
);
1926 /* Mask out pixel format bits in case we change it */
1927 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
1928 switch (fb
->pixel_format
) {
1930 dspcntr
|= DISPPLANE_8BPP
;
1932 case DRM_FORMAT_XRGB1555
:
1933 case DRM_FORMAT_ARGB1555
:
1934 dspcntr
|= DISPPLANE_BGRX555
;
1936 case DRM_FORMAT_RGB565
:
1937 dspcntr
|= DISPPLANE_BGRX565
;
1939 case DRM_FORMAT_XRGB8888
:
1940 case DRM_FORMAT_ARGB8888
:
1941 dspcntr
|= DISPPLANE_BGRX888
;
1943 case DRM_FORMAT_XBGR8888
:
1944 case DRM_FORMAT_ABGR8888
:
1945 dspcntr
|= DISPPLANE_RGBX888
;
1947 case DRM_FORMAT_XRGB2101010
:
1948 case DRM_FORMAT_ARGB2101010
:
1949 dspcntr
|= DISPPLANE_BGRX101010
;
1951 case DRM_FORMAT_XBGR2101010
:
1952 case DRM_FORMAT_ABGR2101010
:
1953 dspcntr
|= DISPPLANE_RGBX101010
;
1959 if (INTEL_INFO(dev
)->gen
>= 4) {
1960 if (obj
->tiling_mode
!= I915_TILING_NONE
)
1961 dspcntr
|= DISPPLANE_TILED
;
1963 dspcntr
&= ~DISPPLANE_TILED
;
1967 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
1969 I915_WRITE(reg
, dspcntr
);
1971 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
1973 if (INTEL_INFO(dev
)->gen
>= 4) {
1974 intel_crtc
->dspaddr_offset
=
1975 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
1976 fb
->bits_per_pixel
/ 8,
1978 linear_offset
-= intel_crtc
->dspaddr_offset
;
1980 intel_crtc
->dspaddr_offset
= linear_offset
;
1983 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
1984 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
1986 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
1987 if (INTEL_INFO(dev
)->gen
>= 4) {
1988 I915_MODIFY_DISPBASE(DSPSURF(plane
),
1989 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
1990 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
1991 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
1993 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
1999 static int ironlake_update_plane(struct drm_crtc
*crtc
,
2000 struct drm_framebuffer
*fb
, int x
, int y
)
2002 struct drm_device
*dev
= crtc
->dev
;
2003 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2004 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2005 struct intel_framebuffer
*intel_fb
;
2006 struct drm_i915_gem_object
*obj
;
2007 int plane
= intel_crtc
->plane
;
2008 unsigned long linear_offset
;
2018 DRM_ERROR("Can't update plane %c in SAREA\n", plane_name(plane
));
2022 intel_fb
= to_intel_framebuffer(fb
);
2023 obj
= intel_fb
->obj
;
2025 reg
= DSPCNTR(plane
);
2026 dspcntr
= I915_READ(reg
);
2027 /* Mask out pixel format bits in case we change it */
2028 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
2029 switch (fb
->pixel_format
) {
2031 dspcntr
|= DISPPLANE_8BPP
;
2033 case DRM_FORMAT_RGB565
:
2034 dspcntr
|= DISPPLANE_BGRX565
;
2036 case DRM_FORMAT_XRGB8888
:
2037 case DRM_FORMAT_ARGB8888
:
2038 dspcntr
|= DISPPLANE_BGRX888
;
2040 case DRM_FORMAT_XBGR8888
:
2041 case DRM_FORMAT_ABGR8888
:
2042 dspcntr
|= DISPPLANE_RGBX888
;
2044 case DRM_FORMAT_XRGB2101010
:
2045 case DRM_FORMAT_ARGB2101010
:
2046 dspcntr
|= DISPPLANE_BGRX101010
;
2048 case DRM_FORMAT_XBGR2101010
:
2049 case DRM_FORMAT_ABGR2101010
:
2050 dspcntr
|= DISPPLANE_RGBX101010
;
2056 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2057 dspcntr
|= DISPPLANE_TILED
;
2059 dspcntr
&= ~DISPPLANE_TILED
;
2062 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2064 I915_WRITE(reg
, dspcntr
);
2066 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2067 intel_crtc
->dspaddr_offset
=
2068 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2069 fb
->bits_per_pixel
/ 8,
2071 linear_offset
-= intel_crtc
->dspaddr_offset
;
2073 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2074 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2076 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2077 I915_MODIFY_DISPBASE(DSPSURF(plane
),
2078 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2079 if (IS_HASWELL(dev
)) {
2080 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2082 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2083 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2090 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2092 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
2093 int x
, int y
, enum mode_set_atomic state
)
2095 struct drm_device
*dev
= crtc
->dev
;
2096 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2098 if (dev_priv
->display
.disable_fbc
)
2099 dev_priv
->display
.disable_fbc(dev
);
2100 intel_increase_pllclock(crtc
);
2102 return dev_priv
->display
.update_plane(crtc
, fb
, x
, y
);
2105 void intel_display_handle_reset(struct drm_device
*dev
)
2107 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2108 struct drm_crtc
*crtc
;
2111 * Flips in the rings have been nuked by the reset,
2112 * so complete all pending flips so that user space
2113 * will get its events and not get stuck.
2115 * Also update the base address of all primary
2116 * planes to the the last fb to make sure we're
2117 * showing the correct fb after a reset.
2119 * Need to make two loops over the crtcs so that we
2120 * don't try to grab a crtc mutex before the
2121 * pending_flip_queue really got woken up.
2124 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
2125 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2126 enum plane plane
= intel_crtc
->plane
;
2128 intel_prepare_page_flip(dev
, plane
);
2129 intel_finish_page_flip_plane(dev
, plane
);
2132 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
2133 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2135 mutex_lock(&crtc
->mutex
);
2136 if (intel_crtc
->active
)
2137 dev_priv
->display
.update_plane(crtc
, crtc
->fb
,
2139 mutex_unlock(&crtc
->mutex
);
2144 intel_finish_fb(struct drm_framebuffer
*old_fb
)
2146 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(old_fb
)->obj
;
2147 struct drm_i915_private
*dev_priv
= obj
->base
.dev
->dev_private
;
2148 bool was_interruptible
= dev_priv
->mm
.interruptible
;
2151 /* Big Hammer, we also need to ensure that any pending
2152 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2153 * current scanout is retired before unpinning the old
2156 * This should only fail upon a hung GPU, in which case we
2157 * can safely continue.
2159 dev_priv
->mm
.interruptible
= false;
2160 ret
= i915_gem_object_finish_gpu(obj
);
2161 dev_priv
->mm
.interruptible
= was_interruptible
;
2166 static void intel_crtc_update_sarea_pos(struct drm_crtc
*crtc
, int x
, int y
)
2168 struct drm_device
*dev
= crtc
->dev
;
2169 struct drm_i915_master_private
*master_priv
;
2170 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2172 if (!dev
->primary
->master
)
2175 master_priv
= dev
->primary
->master
->driver_priv
;
2176 if (!master_priv
->sarea_priv
)
2179 switch (intel_crtc
->pipe
) {
2181 master_priv
->sarea_priv
->pipeA_x
= x
;
2182 master_priv
->sarea_priv
->pipeA_y
= y
;
2185 master_priv
->sarea_priv
->pipeB_x
= x
;
2186 master_priv
->sarea_priv
->pipeB_y
= y
;
2194 intel_pipe_set_base(struct drm_crtc
*crtc
, int x
, int y
,
2195 struct drm_framebuffer
*fb
)
2197 struct drm_device
*dev
= crtc
->dev
;
2198 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2199 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2200 struct drm_framebuffer
*old_fb
;
2205 DRM_ERROR("No FB bound\n");
2209 if (intel_crtc
->plane
> INTEL_INFO(dev
)->num_pipes
) {
2210 DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
2211 plane_name(intel_crtc
->plane
),
2212 INTEL_INFO(dev
)->num_pipes
);
2216 mutex_lock(&dev
->struct_mutex
);
2217 ret
= intel_pin_and_fence_fb_obj(dev
,
2218 to_intel_framebuffer(fb
)->obj
,
2221 mutex_unlock(&dev
->struct_mutex
);
2222 DRM_ERROR("pin & fence failed\n");
2226 /* Update pipe size and adjust fitter if needed */
2227 if (i915_fastboot
) {
2228 I915_WRITE(PIPESRC(intel_crtc
->pipe
),
2229 ((crtc
->mode
.hdisplay
- 1) << 16) |
2230 (crtc
->mode
.vdisplay
- 1));
2231 if (!intel_crtc
->config
.pch_pfit
.size
&&
2232 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
2233 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
2234 I915_WRITE(PF_CTL(intel_crtc
->pipe
), 0);
2235 I915_WRITE(PF_WIN_POS(intel_crtc
->pipe
), 0);
2236 I915_WRITE(PF_WIN_SZ(intel_crtc
->pipe
), 0);
2240 ret
= dev_priv
->display
.update_plane(crtc
, fb
, x
, y
);
2242 intel_unpin_fb_obj(to_intel_framebuffer(fb
)->obj
);
2243 mutex_unlock(&dev
->struct_mutex
);
2244 DRM_ERROR("failed to update base address\n");
2254 if (intel_crtc
->active
&& old_fb
!= fb
)
2255 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2256 intel_unpin_fb_obj(to_intel_framebuffer(old_fb
)->obj
);
2259 intel_update_fbc(dev
);
2260 mutex_unlock(&dev
->struct_mutex
);
2262 intel_crtc_update_sarea_pos(crtc
, x
, y
);
2267 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
2269 struct drm_device
*dev
= crtc
->dev
;
2270 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2271 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2272 int pipe
= intel_crtc
->pipe
;
2275 /* enable normal train */
2276 reg
= FDI_TX_CTL(pipe
);
2277 temp
= I915_READ(reg
);
2278 if (IS_IVYBRIDGE(dev
)) {
2279 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2280 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2282 temp
&= ~FDI_LINK_TRAIN_NONE
;
2283 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2285 I915_WRITE(reg
, temp
);
2287 reg
= FDI_RX_CTL(pipe
);
2288 temp
= I915_READ(reg
);
2289 if (HAS_PCH_CPT(dev
)) {
2290 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2291 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
2293 temp
&= ~FDI_LINK_TRAIN_NONE
;
2294 temp
|= FDI_LINK_TRAIN_NONE
;
2296 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
2298 /* wait one idle pattern time */
2302 /* IVB wants error correction enabled */
2303 if (IS_IVYBRIDGE(dev
))
2304 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
2305 FDI_FE_ERRC_ENABLE
);
2308 static bool pipe_has_enabled_pch(struct intel_crtc
*intel_crtc
)
2310 return intel_crtc
->base
.enabled
&& intel_crtc
->config
.has_pch_encoder
;
2313 static void ivb_modeset_global_resources(struct drm_device
*dev
)
2315 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2316 struct intel_crtc
*pipe_B_crtc
=
2317 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
2318 struct intel_crtc
*pipe_C_crtc
=
2319 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]);
2323 * When everything is off disable fdi C so that we could enable fdi B
2324 * with all lanes. Note that we don't care about enabled pipes without
2325 * an enabled pch encoder.
2327 if (!pipe_has_enabled_pch(pipe_B_crtc
) &&
2328 !pipe_has_enabled_pch(pipe_C_crtc
)) {
2329 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
2330 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
2332 temp
= I915_READ(SOUTH_CHICKEN1
);
2333 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
2334 DRM_DEBUG_KMS("disabling fdi C rx\n");
2335 I915_WRITE(SOUTH_CHICKEN1
, temp
);
2339 /* The FDI link training functions for ILK/Ibexpeak. */
2340 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
2342 struct drm_device
*dev
= crtc
->dev
;
2343 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2344 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2345 int pipe
= intel_crtc
->pipe
;
2346 int plane
= intel_crtc
->plane
;
2347 u32 reg
, temp
, tries
;
2349 /* FDI needs bits from pipe & plane first */
2350 assert_pipe_enabled(dev_priv
, pipe
);
2351 assert_plane_enabled(dev_priv
, plane
);
2353 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2355 reg
= FDI_RX_IMR(pipe
);
2356 temp
= I915_READ(reg
);
2357 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2358 temp
&= ~FDI_RX_BIT_LOCK
;
2359 I915_WRITE(reg
, temp
);
2363 /* enable CPU FDI TX and PCH FDI RX */
2364 reg
= FDI_TX_CTL(pipe
);
2365 temp
= I915_READ(reg
);
2366 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2367 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2368 temp
&= ~FDI_LINK_TRAIN_NONE
;
2369 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2370 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2372 reg
= FDI_RX_CTL(pipe
);
2373 temp
= I915_READ(reg
);
2374 temp
&= ~FDI_LINK_TRAIN_NONE
;
2375 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2376 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2381 /* Ironlake workaround, enable clock pointer after FDI enable*/
2382 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
2383 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
2384 FDI_RX_PHASE_SYNC_POINTER_EN
);
2386 reg
= FDI_RX_IIR(pipe
);
2387 for (tries
= 0; tries
< 5; tries
++) {
2388 temp
= I915_READ(reg
);
2389 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2391 if ((temp
& FDI_RX_BIT_LOCK
)) {
2392 DRM_DEBUG_KMS("FDI train 1 done.\n");
2393 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2398 DRM_ERROR("FDI train 1 fail!\n");
2401 reg
= FDI_TX_CTL(pipe
);
2402 temp
= I915_READ(reg
);
2403 temp
&= ~FDI_LINK_TRAIN_NONE
;
2404 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2405 I915_WRITE(reg
, temp
);
2407 reg
= FDI_RX_CTL(pipe
);
2408 temp
= I915_READ(reg
);
2409 temp
&= ~FDI_LINK_TRAIN_NONE
;
2410 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2411 I915_WRITE(reg
, temp
);
2416 reg
= FDI_RX_IIR(pipe
);
2417 for (tries
= 0; tries
< 5; tries
++) {
2418 temp
= I915_READ(reg
);
2419 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2421 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2422 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2423 DRM_DEBUG_KMS("FDI train 2 done.\n");
2428 DRM_ERROR("FDI train 2 fail!\n");
2430 DRM_DEBUG_KMS("FDI train done\n");
2434 static const int snb_b_fdi_train_param
[] = {
2435 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
2436 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
2437 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
2438 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
2441 /* The FDI link training functions for SNB/Cougarpoint. */
2442 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
2444 struct drm_device
*dev
= crtc
->dev
;
2445 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2446 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2447 int pipe
= intel_crtc
->pipe
;
2448 u32 reg
, temp
, i
, retry
;
2450 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2452 reg
= FDI_RX_IMR(pipe
);
2453 temp
= I915_READ(reg
);
2454 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2455 temp
&= ~FDI_RX_BIT_LOCK
;
2456 I915_WRITE(reg
, temp
);
2461 /* enable CPU FDI TX and PCH FDI RX */
2462 reg
= FDI_TX_CTL(pipe
);
2463 temp
= I915_READ(reg
);
2464 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2465 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2466 temp
&= ~FDI_LINK_TRAIN_NONE
;
2467 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2468 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2470 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2471 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2473 I915_WRITE(FDI_RX_MISC(pipe
),
2474 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
2476 reg
= FDI_RX_CTL(pipe
);
2477 temp
= I915_READ(reg
);
2478 if (HAS_PCH_CPT(dev
)) {
2479 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2480 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2482 temp
&= ~FDI_LINK_TRAIN_NONE
;
2483 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2485 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2490 for (i
= 0; i
< 4; i
++) {
2491 reg
= FDI_TX_CTL(pipe
);
2492 temp
= I915_READ(reg
);
2493 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2494 temp
|= snb_b_fdi_train_param
[i
];
2495 I915_WRITE(reg
, temp
);
2500 for (retry
= 0; retry
< 5; retry
++) {
2501 reg
= FDI_RX_IIR(pipe
);
2502 temp
= I915_READ(reg
);
2503 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2504 if (temp
& FDI_RX_BIT_LOCK
) {
2505 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2506 DRM_DEBUG_KMS("FDI train 1 done.\n");
2515 DRM_ERROR("FDI train 1 fail!\n");
2518 reg
= FDI_TX_CTL(pipe
);
2519 temp
= I915_READ(reg
);
2520 temp
&= ~FDI_LINK_TRAIN_NONE
;
2521 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2523 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2525 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2527 I915_WRITE(reg
, temp
);
2529 reg
= FDI_RX_CTL(pipe
);
2530 temp
= I915_READ(reg
);
2531 if (HAS_PCH_CPT(dev
)) {
2532 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2533 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
2535 temp
&= ~FDI_LINK_TRAIN_NONE
;
2536 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2538 I915_WRITE(reg
, temp
);
2543 for (i
= 0; i
< 4; i
++) {
2544 reg
= FDI_TX_CTL(pipe
);
2545 temp
= I915_READ(reg
);
2546 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2547 temp
|= snb_b_fdi_train_param
[i
];
2548 I915_WRITE(reg
, temp
);
2553 for (retry
= 0; retry
< 5; retry
++) {
2554 reg
= FDI_RX_IIR(pipe
);
2555 temp
= I915_READ(reg
);
2556 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2557 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2558 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2559 DRM_DEBUG_KMS("FDI train 2 done.\n");
2568 DRM_ERROR("FDI train 2 fail!\n");
2570 DRM_DEBUG_KMS("FDI train done.\n");
2573 /* Manual link training for Ivy Bridge A0 parts */
2574 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
2576 struct drm_device
*dev
= crtc
->dev
;
2577 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2578 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2579 int pipe
= intel_crtc
->pipe
;
2582 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2584 reg
= FDI_RX_IMR(pipe
);
2585 temp
= I915_READ(reg
);
2586 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2587 temp
&= ~FDI_RX_BIT_LOCK
;
2588 I915_WRITE(reg
, temp
);
2593 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
2594 I915_READ(FDI_RX_IIR(pipe
)));
2596 /* enable CPU FDI TX and PCH FDI RX */
2597 reg
= FDI_TX_CTL(pipe
);
2598 temp
= I915_READ(reg
);
2599 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2600 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2601 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
2602 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
2603 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2604 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2605 temp
|= FDI_COMPOSITE_SYNC
;
2606 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2608 I915_WRITE(FDI_RX_MISC(pipe
),
2609 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
2611 reg
= FDI_RX_CTL(pipe
);
2612 temp
= I915_READ(reg
);
2613 temp
&= ~FDI_LINK_TRAIN_AUTO
;
2614 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2615 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2616 temp
|= FDI_COMPOSITE_SYNC
;
2617 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2622 for (i
= 0; i
< 4; i
++) {
2623 reg
= FDI_TX_CTL(pipe
);
2624 temp
= I915_READ(reg
);
2625 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2626 temp
|= snb_b_fdi_train_param
[i
];
2627 I915_WRITE(reg
, temp
);
2632 reg
= FDI_RX_IIR(pipe
);
2633 temp
= I915_READ(reg
);
2634 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2636 if (temp
& FDI_RX_BIT_LOCK
||
2637 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
2638 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2639 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i
);
2644 DRM_ERROR("FDI train 1 fail!\n");
2647 reg
= FDI_TX_CTL(pipe
);
2648 temp
= I915_READ(reg
);
2649 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2650 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
2651 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2652 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2653 I915_WRITE(reg
, temp
);
2655 reg
= FDI_RX_CTL(pipe
);
2656 temp
= I915_READ(reg
);
2657 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2658 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
2659 I915_WRITE(reg
, temp
);
2664 for (i
= 0; i
< 4; i
++) {
2665 reg
= FDI_TX_CTL(pipe
);
2666 temp
= I915_READ(reg
);
2667 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2668 temp
|= snb_b_fdi_train_param
[i
];
2669 I915_WRITE(reg
, temp
);
2674 reg
= FDI_RX_IIR(pipe
);
2675 temp
= I915_READ(reg
);
2676 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2678 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2679 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2680 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i
);
2685 DRM_ERROR("FDI train 2 fail!\n");
2687 DRM_DEBUG_KMS("FDI train done.\n");
2690 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
2692 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2693 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2694 int pipe
= intel_crtc
->pipe
;
2698 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
2699 reg
= FDI_RX_CTL(pipe
);
2700 temp
= I915_READ(reg
);
2701 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
2702 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2703 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
2704 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
2709 /* Switch from Rawclk to PCDclk */
2710 temp
= I915_READ(reg
);
2711 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
2716 /* Enable CPU FDI TX PLL, always on for Ironlake */
2717 reg
= FDI_TX_CTL(pipe
);
2718 temp
= I915_READ(reg
);
2719 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
2720 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
2727 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
2729 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2730 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2731 int pipe
= intel_crtc
->pipe
;
2734 /* Switch from PCDclk to Rawclk */
2735 reg
= FDI_RX_CTL(pipe
);
2736 temp
= I915_READ(reg
);
2737 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
2739 /* Disable CPU FDI TX PLL */
2740 reg
= FDI_TX_CTL(pipe
);
2741 temp
= I915_READ(reg
);
2742 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
2747 reg
= FDI_RX_CTL(pipe
);
2748 temp
= I915_READ(reg
);
2749 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
2751 /* Wait for the clocks to turn off. */
2756 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
2758 struct drm_device
*dev
= crtc
->dev
;
2759 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2760 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2761 int pipe
= intel_crtc
->pipe
;
2764 /* disable CPU FDI tx and PCH FDI rx */
2765 reg
= FDI_TX_CTL(pipe
);
2766 temp
= I915_READ(reg
);
2767 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
2770 reg
= FDI_RX_CTL(pipe
);
2771 temp
= I915_READ(reg
);
2772 temp
&= ~(0x7 << 16);
2773 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
2774 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
2779 /* Ironlake workaround, disable clock pointer after downing FDI */
2780 if (HAS_PCH_IBX(dev
)) {
2781 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
2784 /* still set train pattern 1 */
2785 reg
= FDI_TX_CTL(pipe
);
2786 temp
= I915_READ(reg
);
2787 temp
&= ~FDI_LINK_TRAIN_NONE
;
2788 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2789 I915_WRITE(reg
, temp
);
2791 reg
= FDI_RX_CTL(pipe
);
2792 temp
= I915_READ(reg
);
2793 if (HAS_PCH_CPT(dev
)) {
2794 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2795 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2797 temp
&= ~FDI_LINK_TRAIN_NONE
;
2798 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2800 /* BPC in FDI rx is consistent with that in PIPECONF */
2801 temp
&= ~(0x07 << 16);
2802 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
2803 I915_WRITE(reg
, temp
);
2809 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
2811 struct drm_device
*dev
= crtc
->dev
;
2812 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2813 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2814 unsigned long flags
;
2817 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
2818 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
2821 spin_lock_irqsave(&dev
->event_lock
, flags
);
2822 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
2823 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2828 static void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
2830 struct drm_device
*dev
= crtc
->dev
;
2831 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2833 if (crtc
->fb
== NULL
)
2836 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
2838 wait_event(dev_priv
->pending_flip_queue
,
2839 !intel_crtc_has_pending_flip(crtc
));
2841 mutex_lock(&dev
->struct_mutex
);
2842 intel_finish_fb(crtc
->fb
);
2843 mutex_unlock(&dev
->struct_mutex
);
2846 /* Program iCLKIP clock to the desired frequency */
2847 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
2849 struct drm_device
*dev
= crtc
->dev
;
2850 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2851 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
2854 mutex_lock(&dev_priv
->dpio_lock
);
2856 /* It is necessary to ungate the pixclk gate prior to programming
2857 * the divisors, and gate it back when it is done.
2859 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
2861 /* Disable SSCCTL */
2862 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
2863 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
2867 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
2868 if (crtc
->mode
.clock
== 20000) {
2873 /* The iCLK virtual clock root frequency is in MHz,
2874 * but the crtc->mode.clock in in KHz. To get the divisors,
2875 * it is necessary to divide one by another, so we
2876 * convert the virtual clock precision to KHz here for higher
2879 u32 iclk_virtual_root_freq
= 172800 * 1000;
2880 u32 iclk_pi_range
= 64;
2881 u32 desired_divisor
, msb_divisor_value
, pi_value
;
2883 desired_divisor
= (iclk_virtual_root_freq
/ crtc
->mode
.clock
);
2884 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
2885 pi_value
= desired_divisor
% iclk_pi_range
;
2888 divsel
= msb_divisor_value
- 2;
2889 phaseinc
= pi_value
;
2892 /* This should not happen with any sane values */
2893 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
2894 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
2895 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
2896 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
2898 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
2905 /* Program SSCDIVINTPHASE6 */
2906 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
2907 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
2908 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
2909 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
2910 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
2911 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
2912 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
2913 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
2915 /* Program SSCAUXDIV */
2916 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
2917 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
2918 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
2919 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
2921 /* Enable modulator and associated divider */
2922 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
2923 temp
&= ~SBI_SSCCTL_DISABLE
;
2924 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
2926 /* Wait for initialization time */
2929 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
2931 mutex_unlock(&dev_priv
->dpio_lock
);
2934 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
2935 enum pipe pch_transcoder
)
2937 struct drm_device
*dev
= crtc
->base
.dev
;
2938 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2939 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
2941 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
2942 I915_READ(HTOTAL(cpu_transcoder
)));
2943 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
2944 I915_READ(HBLANK(cpu_transcoder
)));
2945 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
2946 I915_READ(HSYNC(cpu_transcoder
)));
2948 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
2949 I915_READ(VTOTAL(cpu_transcoder
)));
2950 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
2951 I915_READ(VBLANK(cpu_transcoder
)));
2952 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
2953 I915_READ(VSYNC(cpu_transcoder
)));
2954 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
2955 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
2959 * Enable PCH resources required for PCH ports:
2961 * - FDI training & RX/TX
2962 * - update transcoder timings
2963 * - DP transcoding bits
2966 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
2968 struct drm_device
*dev
= crtc
->dev
;
2969 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2970 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2971 int pipe
= intel_crtc
->pipe
;
2974 assert_pch_transcoder_disabled(dev_priv
, pipe
);
2976 /* Write the TU size bits before fdi link training, so that error
2977 * detection works. */
2978 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
2979 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
2981 /* For PCH output, training FDI link */
2982 dev_priv
->display
.fdi_link_train(crtc
);
2984 /* XXX: pch pll's can be enabled any time before we enable the PCH
2985 * transcoder, and we actually should do this to not upset any PCH
2986 * transcoder that already use the clock when we share it.
2988 * Note that enable_shared_dpll tries to do the right thing, but
2989 * get_shared_dpll unconditionally resets the pll - we need that to have
2990 * the right LVDS enable sequence. */
2991 ironlake_enable_shared_dpll(intel_crtc
);
2993 if (HAS_PCH_CPT(dev
)) {
2996 temp
= I915_READ(PCH_DPLL_SEL
);
2997 temp
|= TRANS_DPLL_ENABLE(pipe
);
2998 sel
= TRANS_DPLLB_SEL(pipe
);
2999 if (intel_crtc
->config
.shared_dpll
== DPLL_ID_PCH_PLL_B
)
3003 I915_WRITE(PCH_DPLL_SEL
, temp
);
3006 /* set transcoder timing, panel must allow it */
3007 assert_panel_unlocked(dev_priv
, pipe
);
3008 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
3010 intel_fdi_normal_train(crtc
);
3012 /* For PCH DP, enable TRANS_DP_CTL */
3013 if (HAS_PCH_CPT(dev
) &&
3014 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
3015 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3016 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
3017 reg
= TRANS_DP_CTL(pipe
);
3018 temp
= I915_READ(reg
);
3019 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
3020 TRANS_DP_SYNC_MASK
|
3022 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
3023 TRANS_DP_ENH_FRAMING
);
3024 temp
|= bpc
<< 9; /* same format but at 11:9 */
3026 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
3027 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
3028 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
3029 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
3031 switch (intel_trans_dp_port_sel(crtc
)) {
3033 temp
|= TRANS_DP_PORT_SEL_B
;
3036 temp
|= TRANS_DP_PORT_SEL_C
;
3039 temp
|= TRANS_DP_PORT_SEL_D
;
3045 I915_WRITE(reg
, temp
);
3048 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
3051 static void lpt_pch_enable(struct drm_crtc
*crtc
)
3053 struct drm_device
*dev
= crtc
->dev
;
3054 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3055 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3056 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
3058 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
3060 lpt_program_iclkip(crtc
);
3062 /* Set transcoder timing. */
3063 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
3065 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
3068 static void intel_put_shared_dpll(struct intel_crtc
*crtc
)
3070 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3075 if (pll
->refcount
== 0) {
3076 WARN(1, "bad %s refcount\n", pll
->name
);
3080 if (--pll
->refcount
== 0) {
3082 WARN_ON(pll
->active
);
3085 crtc
->config
.shared_dpll
= DPLL_ID_PRIVATE
;
3088 static struct intel_shared_dpll
*intel_get_shared_dpll(struct intel_crtc
*crtc
)
3090 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
3091 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3092 enum intel_dpll_id i
;
3095 DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
3096 crtc
->base
.base
.id
, pll
->name
);
3097 intel_put_shared_dpll(crtc
);
3100 if (HAS_PCH_IBX(dev_priv
->dev
)) {
3101 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3102 i
= (enum intel_dpll_id
) crtc
->pipe
;
3103 pll
= &dev_priv
->shared_dplls
[i
];
3105 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
3106 crtc
->base
.base
.id
, pll
->name
);
3111 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3112 pll
= &dev_priv
->shared_dplls
[i
];
3114 /* Only want to check enabled timings first */
3115 if (pll
->refcount
== 0)
3118 if (memcmp(&crtc
->config
.dpll_hw_state
, &pll
->hw_state
,
3119 sizeof(pll
->hw_state
)) == 0) {
3120 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
3122 pll
->name
, pll
->refcount
, pll
->active
);
3128 /* Ok no matching timings, maybe there's a free one? */
3129 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3130 pll
= &dev_priv
->shared_dplls
[i
];
3131 if (pll
->refcount
== 0) {
3132 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
3133 crtc
->base
.base
.id
, pll
->name
);
3141 crtc
->config
.shared_dpll
= i
;
3142 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll
->name
,
3143 pipe_name(crtc
->pipe
));
3145 if (pll
->active
== 0) {
3146 memcpy(&pll
->hw_state
, &crtc
->config
.dpll_hw_state
,
3147 sizeof(pll
->hw_state
));
3149 DRM_DEBUG_DRIVER("setting up %s\n", pll
->name
);
3151 assert_shared_dpll_disabled(dev_priv
, pll
);
3153 pll
->mode_set(dev_priv
, pll
);
3160 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
3162 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3163 int dslreg
= PIPEDSL(pipe
);
3166 temp
= I915_READ(dslreg
);
3168 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
3169 if (wait_for(I915_READ(dslreg
) != temp
, 5))
3170 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
3174 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
3176 struct drm_device
*dev
= crtc
->base
.dev
;
3177 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3178 int pipe
= crtc
->pipe
;
3180 if (crtc
->config
.pch_pfit
.size
) {
3181 /* Force use of hard-coded filter coefficients
3182 * as some pre-programmed values are broken,
3185 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
3186 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
3187 PF_PIPE_SEL_IVB(pipe
));
3189 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
3190 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
.pch_pfit
.pos
);
3191 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
.pch_pfit
.size
);
3195 static void intel_enable_planes(struct drm_crtc
*crtc
)
3197 struct drm_device
*dev
= crtc
->dev
;
3198 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3199 struct intel_plane
*intel_plane
;
3201 list_for_each_entry(intel_plane
, &dev
->mode_config
.plane_list
, base
.head
)
3202 if (intel_plane
->pipe
== pipe
)
3203 intel_plane_restore(&intel_plane
->base
);
3206 static void intel_disable_planes(struct drm_crtc
*crtc
)
3208 struct drm_device
*dev
= crtc
->dev
;
3209 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3210 struct intel_plane
*intel_plane
;
3212 list_for_each_entry(intel_plane
, &dev
->mode_config
.plane_list
, base
.head
)
3213 if (intel_plane
->pipe
== pipe
)
3214 intel_plane_disable(&intel_plane
->base
);
3217 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
3219 struct drm_device
*dev
= crtc
->dev
;
3220 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3221 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3222 struct intel_encoder
*encoder
;
3223 int pipe
= intel_crtc
->pipe
;
3224 int plane
= intel_crtc
->plane
;
3226 WARN_ON(!crtc
->enabled
);
3228 if (intel_crtc
->active
)
3231 intel_crtc
->active
= true;
3233 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
3234 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
3236 intel_update_watermarks(dev
);
3238 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3239 if (encoder
->pre_enable
)
3240 encoder
->pre_enable(encoder
);
3242 if (intel_crtc
->config
.has_pch_encoder
) {
3243 /* Note: FDI PLL enabling _must_ be done before we enable the
3244 * cpu pipes, hence this is separate from all the other fdi/pch
3246 ironlake_fdi_pll_enable(intel_crtc
);
3248 assert_fdi_tx_disabled(dev_priv
, pipe
);
3249 assert_fdi_rx_disabled(dev_priv
, pipe
);
3252 ironlake_pfit_enable(intel_crtc
);
3255 * On ILK+ LUT must be loaded before the pipe is running but with
3258 intel_crtc_load_lut(crtc
);
3260 intel_enable_pipe(dev_priv
, pipe
,
3261 intel_crtc
->config
.has_pch_encoder
);
3262 intel_enable_plane(dev_priv
, plane
, pipe
);
3263 intel_enable_planes(crtc
);
3264 intel_crtc_update_cursor(crtc
, true);
3266 if (intel_crtc
->config
.has_pch_encoder
)
3267 ironlake_pch_enable(crtc
);
3269 mutex_lock(&dev
->struct_mutex
);
3270 intel_update_fbc(dev
);
3271 mutex_unlock(&dev
->struct_mutex
);
3273 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3274 encoder
->enable(encoder
);
3276 if (HAS_PCH_CPT(dev
))
3277 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
3280 * There seems to be a race in PCH platform hw (at least on some
3281 * outputs) where an enabled pipe still completes any pageflip right
3282 * away (as if the pipe is off) instead of waiting for vblank. As soon
3283 * as the first vblank happend, everything works as expected. Hence just
3284 * wait for one vblank before returning to avoid strange things
3287 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
3290 /* IPS only exists on ULT machines and is tied to pipe A. */
3291 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
3293 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
3296 static void hsw_enable_ips(struct intel_crtc
*crtc
)
3298 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
3300 if (!crtc
->config
.ips_enabled
)
3303 /* We can only enable IPS after we enable a plane and wait for a vblank.
3304 * We guarantee that the plane is enabled by calling intel_enable_ips
3305 * only after intel_enable_plane. And intel_enable_plane already waits
3306 * for a vblank, so all we need to do here is to enable the IPS bit. */
3307 assert_plane_enabled(dev_priv
, crtc
->plane
);
3308 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
3311 static void hsw_disable_ips(struct intel_crtc
*crtc
)
3313 struct drm_device
*dev
= crtc
->base
.dev
;
3314 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3316 if (!crtc
->config
.ips_enabled
)
3319 assert_plane_enabled(dev_priv
, crtc
->plane
);
3320 I915_WRITE(IPS_CTL
, 0);
3322 /* We need to wait for a vblank before we can disable the plane. */
3323 intel_wait_for_vblank(dev
, crtc
->pipe
);
3326 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
3328 struct drm_device
*dev
= crtc
->dev
;
3329 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3330 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3331 struct intel_encoder
*encoder
;
3332 int pipe
= intel_crtc
->pipe
;
3333 int plane
= intel_crtc
->plane
;
3335 WARN_ON(!crtc
->enabled
);
3337 if (intel_crtc
->active
)
3340 intel_crtc
->active
= true;
3342 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
3343 if (intel_crtc
->config
.has_pch_encoder
)
3344 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
3346 intel_update_watermarks(dev
);
3348 if (intel_crtc
->config
.has_pch_encoder
)
3349 dev_priv
->display
.fdi_link_train(crtc
);
3351 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3352 if (encoder
->pre_enable
)
3353 encoder
->pre_enable(encoder
);
3355 intel_ddi_enable_pipe_clock(intel_crtc
);
3357 ironlake_pfit_enable(intel_crtc
);
3360 * On ILK+ LUT must be loaded before the pipe is running but with
3363 intel_crtc_load_lut(crtc
);
3365 intel_ddi_set_pipe_settings(crtc
);
3366 intel_ddi_enable_transcoder_func(crtc
);
3368 intel_enable_pipe(dev_priv
, pipe
,
3369 intel_crtc
->config
.has_pch_encoder
);
3370 intel_enable_plane(dev_priv
, plane
, pipe
);
3371 intel_enable_planes(crtc
);
3372 intel_crtc_update_cursor(crtc
, true);
3374 hsw_enable_ips(intel_crtc
);
3376 if (intel_crtc
->config
.has_pch_encoder
)
3377 lpt_pch_enable(crtc
);
3379 mutex_lock(&dev
->struct_mutex
);
3380 intel_update_fbc(dev
);
3381 mutex_unlock(&dev
->struct_mutex
);
3383 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3384 encoder
->enable(encoder
);
3387 * There seems to be a race in PCH platform hw (at least on some
3388 * outputs) where an enabled pipe still completes any pageflip right
3389 * away (as if the pipe is off) instead of waiting for vblank. As soon
3390 * as the first vblank happend, everything works as expected. Hence just
3391 * wait for one vblank before returning to avoid strange things
3394 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
3397 static void ironlake_pfit_disable(struct intel_crtc
*crtc
)
3399 struct drm_device
*dev
= crtc
->base
.dev
;
3400 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3401 int pipe
= crtc
->pipe
;
3403 /* To avoid upsetting the power well on haswell only disable the pfit if
3404 * it's in use. The hw state code will make sure we get this right. */
3405 if (crtc
->config
.pch_pfit
.size
) {
3406 I915_WRITE(PF_CTL(pipe
), 0);
3407 I915_WRITE(PF_WIN_POS(pipe
), 0);
3408 I915_WRITE(PF_WIN_SZ(pipe
), 0);
3412 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
3414 struct drm_device
*dev
= crtc
->dev
;
3415 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3416 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3417 struct intel_encoder
*encoder
;
3418 int pipe
= intel_crtc
->pipe
;
3419 int plane
= intel_crtc
->plane
;
3423 if (!intel_crtc
->active
)
3426 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3427 encoder
->disable(encoder
);
3429 intel_crtc_wait_for_pending_flips(crtc
);
3430 drm_vblank_off(dev
, pipe
);
3432 if (dev_priv
->fbc
.plane
== plane
)
3433 intel_disable_fbc(dev
);
3435 intel_crtc_update_cursor(crtc
, false);
3436 intel_disable_planes(crtc
);
3437 intel_disable_plane(dev_priv
, plane
, pipe
);
3439 if (intel_crtc
->config
.has_pch_encoder
)
3440 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, false);
3442 intel_disable_pipe(dev_priv
, pipe
);
3444 ironlake_pfit_disable(intel_crtc
);
3446 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3447 if (encoder
->post_disable
)
3448 encoder
->post_disable(encoder
);
3450 if (intel_crtc
->config
.has_pch_encoder
) {
3451 ironlake_fdi_disable(crtc
);
3453 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
3454 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
3456 if (HAS_PCH_CPT(dev
)) {
3457 /* disable TRANS_DP_CTL */
3458 reg
= TRANS_DP_CTL(pipe
);
3459 temp
= I915_READ(reg
);
3460 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
3461 TRANS_DP_PORT_SEL_MASK
);
3462 temp
|= TRANS_DP_PORT_SEL_NONE
;
3463 I915_WRITE(reg
, temp
);
3465 /* disable DPLL_SEL */
3466 temp
= I915_READ(PCH_DPLL_SEL
);
3467 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
3468 I915_WRITE(PCH_DPLL_SEL
, temp
);
3471 /* disable PCH DPLL */
3472 intel_disable_shared_dpll(intel_crtc
);
3474 ironlake_fdi_pll_disable(intel_crtc
);
3477 intel_crtc
->active
= false;
3478 intel_update_watermarks(dev
);
3480 mutex_lock(&dev
->struct_mutex
);
3481 intel_update_fbc(dev
);
3482 mutex_unlock(&dev
->struct_mutex
);
3485 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
3487 struct drm_device
*dev
= crtc
->dev
;
3488 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3489 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3490 struct intel_encoder
*encoder
;
3491 int pipe
= intel_crtc
->pipe
;
3492 int plane
= intel_crtc
->plane
;
3493 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
3495 if (!intel_crtc
->active
)
3498 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3499 encoder
->disable(encoder
);
3501 intel_crtc_wait_for_pending_flips(crtc
);
3502 drm_vblank_off(dev
, pipe
);
3504 /* FBC must be disabled before disabling the plane on HSW. */
3505 if (dev_priv
->fbc
.plane
== plane
)
3506 intel_disable_fbc(dev
);
3508 hsw_disable_ips(intel_crtc
);
3510 intel_crtc_update_cursor(crtc
, false);
3511 intel_disable_planes(crtc
);
3512 intel_disable_plane(dev_priv
, plane
, pipe
);
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 ironlake_pfit_disable(intel_crtc
);
3522 intel_ddi_disable_pipe_clock(intel_crtc
);
3524 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3525 if (encoder
->post_disable
)
3526 encoder
->post_disable(encoder
);
3528 if (intel_crtc
->config
.has_pch_encoder
) {
3529 lpt_disable_pch_transcoder(dev_priv
);
3530 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
3531 intel_ddi_fdi_disable(crtc
);
3534 intel_crtc
->active
= false;
3535 intel_update_watermarks(dev
);
3537 mutex_lock(&dev
->struct_mutex
);
3538 intel_update_fbc(dev
);
3539 mutex_unlock(&dev
->struct_mutex
);
3542 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
3544 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3545 intel_put_shared_dpll(intel_crtc
);
3548 static void haswell_crtc_off(struct drm_crtc
*crtc
)
3550 intel_ddi_put_crtc_pll(crtc
);
3553 static void intel_crtc_dpms_overlay(struct intel_crtc
*intel_crtc
, bool enable
)
3555 if (!enable
&& intel_crtc
->overlay
) {
3556 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3557 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3559 mutex_lock(&dev
->struct_mutex
);
3560 dev_priv
->mm
.interruptible
= false;
3561 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
3562 dev_priv
->mm
.interruptible
= true;
3563 mutex_unlock(&dev
->struct_mutex
);
3566 /* Let userspace switch the overlay on again. In most cases userspace
3567 * has to recompute where to put it anyway.
3572 * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
3573 * cursor plane briefly if not already running after enabling the display
3575 * This workaround avoids occasional blank screens when self refresh is
3579 g4x_fixup_plane(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
3581 u32 cntl
= I915_READ(CURCNTR(pipe
));
3583 if ((cntl
& CURSOR_MODE
) == 0) {
3584 u32 fw_bcl_self
= I915_READ(FW_BLC_SELF
);
3586 I915_WRITE(FW_BLC_SELF
, fw_bcl_self
& ~FW_BLC_SELF_EN
);
3587 I915_WRITE(CURCNTR(pipe
), CURSOR_MODE_64_ARGB_AX
);
3588 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
3589 I915_WRITE(CURCNTR(pipe
), cntl
);
3590 I915_WRITE(CURBASE(pipe
), I915_READ(CURBASE(pipe
)));
3591 I915_WRITE(FW_BLC_SELF
, fw_bcl_self
);
3595 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
3597 struct drm_device
*dev
= crtc
->base
.dev
;
3598 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3599 struct intel_crtc_config
*pipe_config
= &crtc
->config
;
3601 if (!crtc
->config
.gmch_pfit
.control
)
3605 * The panel fitter should only be adjusted whilst the pipe is disabled,
3606 * according to register description and PRM.
3608 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
3609 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
3611 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
3612 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
3614 /* Border color in case we don't scale up to the full screen. Black by
3615 * default, change to something else for debugging. */
3616 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
3619 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
3621 struct drm_device
*dev
= crtc
->dev
;
3622 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3623 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3624 struct intel_encoder
*encoder
;
3625 int pipe
= intel_crtc
->pipe
;
3626 int plane
= intel_crtc
->plane
;
3628 WARN_ON(!crtc
->enabled
);
3630 if (intel_crtc
->active
)
3633 intel_crtc
->active
= true;
3634 intel_update_watermarks(dev
);
3636 mutex_lock(&dev_priv
->dpio_lock
);
3638 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3639 if (encoder
->pre_pll_enable
)
3640 encoder
->pre_pll_enable(encoder
);
3642 vlv_enable_pll(dev_priv
, pipe
);
3644 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3645 if (encoder
->pre_enable
)
3646 encoder
->pre_enable(encoder
);
3648 /* VLV wants encoder enabling _before_ the pipe is up. */
3649 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3650 encoder
->enable(encoder
);
3652 i9xx_pfit_enable(intel_crtc
);
3654 intel_crtc_load_lut(crtc
);
3656 intel_enable_pipe(dev_priv
, pipe
, false);
3657 intel_enable_plane(dev_priv
, plane
, pipe
);
3658 intel_enable_planes(crtc
);
3659 intel_crtc_update_cursor(crtc
, true);
3661 intel_update_fbc(dev
);
3663 mutex_unlock(&dev_priv
->dpio_lock
);
3666 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
3668 struct drm_device
*dev
= crtc
->dev
;
3669 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3670 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3671 struct intel_encoder
*encoder
;
3672 int pipe
= intel_crtc
->pipe
;
3673 int plane
= intel_crtc
->plane
;
3675 WARN_ON(!crtc
->enabled
);
3677 if (intel_crtc
->active
)
3680 intel_crtc
->active
= true;
3681 intel_update_watermarks(dev
);
3683 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3684 if (encoder
->pre_enable
)
3685 encoder
->pre_enable(encoder
);
3687 i9xx_enable_pll(intel_crtc
);
3689 i9xx_pfit_enable(intel_crtc
);
3691 intel_crtc_load_lut(crtc
);
3693 intel_enable_pipe(dev_priv
, pipe
, false);
3694 intel_enable_plane(dev_priv
, plane
, pipe
);
3695 intel_enable_planes(crtc
);
3696 /* The fixup needs to happen before cursor is enabled */
3698 g4x_fixup_plane(dev_priv
, pipe
);
3699 intel_crtc_update_cursor(crtc
, true);
3701 /* Give the overlay scaler a chance to enable if it's on this pipe */
3702 intel_crtc_dpms_overlay(intel_crtc
, true);
3704 intel_update_fbc(dev
);
3706 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3707 encoder
->enable(encoder
);
3710 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
3712 struct drm_device
*dev
= crtc
->base
.dev
;
3713 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3715 if (!crtc
->config
.gmch_pfit
.control
)
3718 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
3720 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
3721 I915_READ(PFIT_CONTROL
));
3722 I915_WRITE(PFIT_CONTROL
, 0);
3725 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
3727 struct drm_device
*dev
= crtc
->dev
;
3728 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3729 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3730 struct intel_encoder
*encoder
;
3731 int pipe
= intel_crtc
->pipe
;
3732 int plane
= intel_crtc
->plane
;
3734 if (!intel_crtc
->active
)
3737 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3738 encoder
->disable(encoder
);
3740 /* Give the overlay scaler a chance to disable if it's on this pipe */
3741 intel_crtc_wait_for_pending_flips(crtc
);
3742 drm_vblank_off(dev
, pipe
);
3744 if (dev_priv
->fbc
.plane
== plane
)
3745 intel_disable_fbc(dev
);
3747 intel_crtc_dpms_overlay(intel_crtc
, false);
3748 intel_crtc_update_cursor(crtc
, false);
3749 intel_disable_planes(crtc
);
3750 intel_disable_plane(dev_priv
, plane
, pipe
);
3752 intel_disable_pipe(dev_priv
, pipe
);
3754 i9xx_pfit_disable(intel_crtc
);
3756 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3757 if (encoder
->post_disable
)
3758 encoder
->post_disable(encoder
);
3760 intel_disable_pll(dev_priv
, pipe
);
3762 intel_crtc
->active
= false;
3763 intel_update_fbc(dev
);
3764 intel_update_watermarks(dev
);
3767 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
3771 static void intel_crtc_update_sarea(struct drm_crtc
*crtc
,
3774 struct drm_device
*dev
= crtc
->dev
;
3775 struct drm_i915_master_private
*master_priv
;
3776 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3777 int pipe
= intel_crtc
->pipe
;
3779 if (!dev
->primary
->master
)
3782 master_priv
= dev
->primary
->master
->driver_priv
;
3783 if (!master_priv
->sarea_priv
)
3788 master_priv
->sarea_priv
->pipeA_w
= enabled
? crtc
->mode
.hdisplay
: 0;
3789 master_priv
->sarea_priv
->pipeA_h
= enabled
? crtc
->mode
.vdisplay
: 0;
3792 master_priv
->sarea_priv
->pipeB_w
= enabled
? crtc
->mode
.hdisplay
: 0;
3793 master_priv
->sarea_priv
->pipeB_h
= enabled
? crtc
->mode
.vdisplay
: 0;
3796 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe
));
3802 * Sets the power management mode of the pipe and plane.
3804 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
3806 struct drm_device
*dev
= crtc
->dev
;
3807 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3808 struct intel_encoder
*intel_encoder
;
3809 bool enable
= false;
3811 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
3812 enable
|= intel_encoder
->connectors_active
;
3815 dev_priv
->display
.crtc_enable(crtc
);
3817 dev_priv
->display
.crtc_disable(crtc
);
3819 intel_crtc_update_sarea(crtc
, enable
);
3822 static void intel_crtc_disable(struct drm_crtc
*crtc
)
3824 struct drm_device
*dev
= crtc
->dev
;
3825 struct drm_connector
*connector
;
3826 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3827 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3829 /* crtc should still be enabled when we disable it. */
3830 WARN_ON(!crtc
->enabled
);
3832 dev_priv
->display
.crtc_disable(crtc
);
3833 intel_crtc
->eld_vld
= false;
3834 intel_crtc_update_sarea(crtc
, false);
3835 dev_priv
->display
.off(crtc
);
3837 assert_plane_disabled(dev
->dev_private
, to_intel_crtc(crtc
)->plane
);
3838 assert_pipe_disabled(dev
->dev_private
, to_intel_crtc(crtc
)->pipe
);
3841 mutex_lock(&dev
->struct_mutex
);
3842 intel_unpin_fb_obj(to_intel_framebuffer(crtc
->fb
)->obj
);
3843 mutex_unlock(&dev
->struct_mutex
);
3847 /* Update computed state. */
3848 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
3849 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
3852 if (connector
->encoder
->crtc
!= crtc
)
3855 connector
->dpms
= DRM_MODE_DPMS_OFF
;
3856 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
3860 void intel_modeset_disable(struct drm_device
*dev
)
3862 struct drm_crtc
*crtc
;
3864 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
3866 intel_crtc_disable(crtc
);
3870 void intel_encoder_destroy(struct drm_encoder
*encoder
)
3872 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
3874 drm_encoder_cleanup(encoder
);
3875 kfree(intel_encoder
);
3878 /* Simple dpms helper for encodres with just one connector, no cloning and only
3879 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
3880 * state of the entire output pipe. */
3881 void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
3883 if (mode
== DRM_MODE_DPMS_ON
) {
3884 encoder
->connectors_active
= true;
3886 intel_crtc_update_dpms(encoder
->base
.crtc
);
3888 encoder
->connectors_active
= false;
3890 intel_crtc_update_dpms(encoder
->base
.crtc
);
3894 /* Cross check the actual hw state with our own modeset state tracking (and it's
3895 * internal consistency). */
3896 static void intel_connector_check_state(struct intel_connector
*connector
)
3898 if (connector
->get_hw_state(connector
)) {
3899 struct intel_encoder
*encoder
= connector
->encoder
;
3900 struct drm_crtc
*crtc
;
3901 bool encoder_enabled
;
3904 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
3905 connector
->base
.base
.id
,
3906 drm_get_connector_name(&connector
->base
));
3908 WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
3909 "wrong connector dpms state\n");
3910 WARN(connector
->base
.encoder
!= &encoder
->base
,
3911 "active connector not linked to encoder\n");
3912 WARN(!encoder
->connectors_active
,
3913 "encoder->connectors_active not set\n");
3915 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
3916 WARN(!encoder_enabled
, "encoder not enabled\n");
3917 if (WARN_ON(!encoder
->base
.crtc
))
3920 crtc
= encoder
->base
.crtc
;
3922 WARN(!crtc
->enabled
, "crtc not enabled\n");
3923 WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
3924 WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
3925 "encoder active on the wrong pipe\n");
3929 /* Even simpler default implementation, if there's really no special case to
3931 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
3933 struct intel_encoder
*encoder
= intel_attached_encoder(connector
);
3935 /* All the simple cases only support two dpms states. */
3936 if (mode
!= DRM_MODE_DPMS_ON
)
3937 mode
= DRM_MODE_DPMS_OFF
;
3939 if (mode
== connector
->dpms
)
3942 connector
->dpms
= mode
;
3944 /* Only need to change hw state when actually enabled */
3945 if (encoder
->base
.crtc
)
3946 intel_encoder_dpms(encoder
, mode
);
3948 WARN_ON(encoder
->connectors_active
!= false);
3950 intel_modeset_check_state(connector
->dev
);
3953 /* Simple connector->get_hw_state implementation for encoders that support only
3954 * one connector and no cloning and hence the encoder state determines the state
3955 * of the connector. */
3956 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
3959 struct intel_encoder
*encoder
= connector
->encoder
;
3961 return encoder
->get_hw_state(encoder
, &pipe
);
3964 static bool ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
3965 struct intel_crtc_config
*pipe_config
)
3967 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3968 struct intel_crtc
*pipe_B_crtc
=
3969 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
3971 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
3972 pipe_name(pipe
), pipe_config
->fdi_lanes
);
3973 if (pipe_config
->fdi_lanes
> 4) {
3974 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
3975 pipe_name(pipe
), pipe_config
->fdi_lanes
);
3979 if (IS_HASWELL(dev
)) {
3980 if (pipe_config
->fdi_lanes
> 2) {
3981 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
3982 pipe_config
->fdi_lanes
);
3989 if (INTEL_INFO(dev
)->num_pipes
== 2)
3992 /* Ivybridge 3 pipe is really complicated */
3997 if (dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]->enabled
&&
3998 pipe_config
->fdi_lanes
> 2) {
3999 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
4000 pipe_name(pipe
), pipe_config
->fdi_lanes
);
4005 if (!pipe_has_enabled_pch(pipe_B_crtc
) ||
4006 pipe_B_crtc
->config
.fdi_lanes
<= 2) {
4007 if (pipe_config
->fdi_lanes
> 2) {
4008 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
4009 pipe_name(pipe
), pipe_config
->fdi_lanes
);
4013 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
4023 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
4024 struct intel_crtc_config
*pipe_config
)
4026 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4027 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
4028 int lane
, link_bw
, fdi_dotclock
;
4029 bool setup_ok
, needs_recompute
= false;
4032 /* FDI is a binary signal running at ~2.7GHz, encoding
4033 * each output octet as 10 bits. The actual frequency
4034 * is stored as a divider into a 100MHz clock, and the
4035 * mode pixel clock is stored in units of 1KHz.
4036 * Hence the bw of each lane in terms of the mode signal
4039 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
4041 fdi_dotclock
= adjusted_mode
->clock
;
4042 fdi_dotclock
/= pipe_config
->pixel_multiplier
;
4044 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
4045 pipe_config
->pipe_bpp
);
4047 pipe_config
->fdi_lanes
= lane
;
4049 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
4050 link_bw
, &pipe_config
->fdi_m_n
);
4052 setup_ok
= ironlake_check_fdi_lanes(intel_crtc
->base
.dev
,
4053 intel_crtc
->pipe
, pipe_config
);
4054 if (!setup_ok
&& pipe_config
->pipe_bpp
> 6*3) {
4055 pipe_config
->pipe_bpp
-= 2*3;
4056 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
4057 pipe_config
->pipe_bpp
);
4058 needs_recompute
= true;
4059 pipe_config
->bw_constrained
= true;
4064 if (needs_recompute
)
4067 return setup_ok
? 0 : -EINVAL
;
4070 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
4071 struct intel_crtc_config
*pipe_config
)
4073 pipe_config
->ips_enabled
= i915_enable_ips
&&
4074 hsw_crtc_supports_ips(crtc
) &&
4075 pipe_config
->pipe_bpp
== 24;
4078 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
4079 struct intel_crtc_config
*pipe_config
)
4081 struct drm_device
*dev
= crtc
->base
.dev
;
4082 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
4084 if (HAS_PCH_SPLIT(dev
)) {
4085 /* FDI link clock is fixed at 2.7G */
4086 if (pipe_config
->requested_mode
.clock
* 3
4087 > IRONLAKE_FDI_FREQ
* 4)
4091 /* All interlaced capable intel hw wants timings in frames. Note though
4092 * that intel_lvds_mode_fixup does some funny tricks with the crtc
4093 * timings, so we need to be careful not to clobber these.*/
4094 if (!pipe_config
->timings_set
)
4095 drm_mode_set_crtcinfo(adjusted_mode
, 0);
4097 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
4098 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
4100 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
4101 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
4104 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) && pipe_config
->pipe_bpp
> 10*3) {
4105 pipe_config
->pipe_bpp
= 10*3; /* 12bpc is gen5+ */
4106 } else if (INTEL_INFO(dev
)->gen
<= 4 && pipe_config
->pipe_bpp
> 8*3) {
4107 /* only a 8bpc pipe, with 6bpc dither through the panel fitter
4109 pipe_config
->pipe_bpp
= 8*3;
4113 hsw_compute_ips_config(crtc
, pipe_config
);
4115 /* XXX: PCH clock sharing is done in ->mode_set, so make sure the old
4116 * clock survives for now. */
4117 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
4118 pipe_config
->shared_dpll
= crtc
->config
.shared_dpll
;
4120 if (pipe_config
->has_pch_encoder
)
4121 return ironlake_fdi_compute_config(crtc
, pipe_config
);
4126 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
4128 return 400000; /* FIXME */
4131 static int i945_get_display_clock_speed(struct drm_device
*dev
)
4136 static int i915_get_display_clock_speed(struct drm_device
*dev
)
4141 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
4146 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
4150 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
4152 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
4155 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
4156 case GC_DISPLAY_CLOCK_333_MHZ
:
4159 case GC_DISPLAY_CLOCK_190_200_MHZ
:
4165 static int i865_get_display_clock_speed(struct drm_device
*dev
)
4170 static int i855_get_display_clock_speed(struct drm_device
*dev
)
4173 /* Assume that the hardware is in the high speed state. This
4174 * should be the default.
4176 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
4177 case GC_CLOCK_133_200
:
4178 case GC_CLOCK_100_200
:
4180 case GC_CLOCK_166_250
:
4182 case GC_CLOCK_100_133
:
4186 /* Shouldn't happen */
4190 static int i830_get_display_clock_speed(struct drm_device
*dev
)
4196 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
4198 while (*num
> DATA_LINK_M_N_MASK
||
4199 *den
> DATA_LINK_M_N_MASK
) {
4205 static void compute_m_n(unsigned int m
, unsigned int n
,
4206 uint32_t *ret_m
, uint32_t *ret_n
)
4208 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
4209 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
4210 intel_reduce_m_n_ratio(ret_m
, ret_n
);
4214 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
4215 int pixel_clock
, int link_clock
,
4216 struct intel_link_m_n
*m_n
)
4220 compute_m_n(bits_per_pixel
* pixel_clock
,
4221 link_clock
* nlanes
* 8,
4222 &m_n
->gmch_m
, &m_n
->gmch_n
);
4224 compute_m_n(pixel_clock
, link_clock
,
4225 &m_n
->link_m
, &m_n
->link_n
);
4228 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
4230 if (i915_panel_use_ssc
>= 0)
4231 return i915_panel_use_ssc
!= 0;
4232 return dev_priv
->vbt
.lvds_use_ssc
4233 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
4236 static int vlv_get_refclk(struct drm_crtc
*crtc
)
4238 struct drm_device
*dev
= crtc
->dev
;
4239 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4240 int refclk
= 27000; /* for DP & HDMI */
4242 return 100000; /* only one validated so far */
4244 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
4246 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
4247 if (intel_panel_use_ssc(dev_priv
))
4251 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
)) {
4258 static int i9xx_get_refclk(struct drm_crtc
*crtc
, int num_connectors
)
4260 struct drm_device
*dev
= crtc
->dev
;
4261 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4264 if (IS_VALLEYVIEW(dev
)) {
4265 refclk
= vlv_get_refclk(crtc
);
4266 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
4267 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
4268 refclk
= dev_priv
->vbt
.lvds_ssc_freq
* 1000;
4269 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
4271 } else if (!IS_GEN2(dev
)) {
4280 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
4282 return (1 << dpll
->n
) << 16 | dpll
->m2
;
4285 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
4287 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
4290 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
4291 intel_clock_t
*reduced_clock
)
4293 struct drm_device
*dev
= crtc
->base
.dev
;
4294 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4295 int pipe
= crtc
->pipe
;
4298 if (IS_PINEVIEW(dev
)) {
4299 fp
= pnv_dpll_compute_fp(&crtc
->config
.dpll
);
4301 fp2
= pnv_dpll_compute_fp(reduced_clock
);
4303 fp
= i9xx_dpll_compute_fp(&crtc
->config
.dpll
);
4305 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
4308 I915_WRITE(FP0(pipe
), fp
);
4309 crtc
->config
.dpll_hw_state
.fp0
= fp
;
4311 crtc
->lowfreq_avail
= false;
4312 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
4313 reduced_clock
&& i915_powersave
) {
4314 I915_WRITE(FP1(pipe
), fp2
);
4315 crtc
->config
.dpll_hw_state
.fp1
= fp2
;
4316 crtc
->lowfreq_avail
= true;
4318 I915_WRITE(FP1(pipe
), fp
);
4319 crtc
->config
.dpll_hw_state
.fp1
= fp
;
4323 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
)
4328 * PLLB opamp always calibrates to max value of 0x3f, force enable it
4329 * and set it to a reasonable value instead.
4331 reg_val
= vlv_dpio_read(dev_priv
, DPIO_IREF(1));
4332 reg_val
&= 0xffffff00;
4333 reg_val
|= 0x00000030;
4334 vlv_dpio_write(dev_priv
, DPIO_IREF(1), reg_val
);
4336 reg_val
= vlv_dpio_read(dev_priv
, DPIO_CALIBRATION
);
4337 reg_val
&= 0x8cffffff;
4338 reg_val
= 0x8c000000;
4339 vlv_dpio_write(dev_priv
, DPIO_CALIBRATION
, reg_val
);
4341 reg_val
= vlv_dpio_read(dev_priv
, DPIO_IREF(1));
4342 reg_val
&= 0xffffff00;
4343 vlv_dpio_write(dev_priv
, DPIO_IREF(1), reg_val
);
4345 reg_val
= vlv_dpio_read(dev_priv
, DPIO_CALIBRATION
);
4346 reg_val
&= 0x00ffffff;
4347 reg_val
|= 0xb0000000;
4348 vlv_dpio_write(dev_priv
, DPIO_CALIBRATION
, reg_val
);
4351 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
4352 struct intel_link_m_n
*m_n
)
4354 struct drm_device
*dev
= crtc
->base
.dev
;
4355 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4356 int pipe
= crtc
->pipe
;
4358 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
4359 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
4360 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
4361 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
4364 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
4365 struct intel_link_m_n
*m_n
)
4367 struct drm_device
*dev
= crtc
->base
.dev
;
4368 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4369 int pipe
= crtc
->pipe
;
4370 enum transcoder transcoder
= crtc
->config
.cpu_transcoder
;
4372 if (INTEL_INFO(dev
)->gen
>= 5) {
4373 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
4374 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
4375 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
4376 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
4378 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
4379 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
4380 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
4381 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
4385 static void intel_dp_set_m_n(struct intel_crtc
*crtc
)
4387 if (crtc
->config
.has_pch_encoder
)
4388 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
4390 intel_cpu_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
4393 static void vlv_update_pll(struct intel_crtc
*crtc
)
4395 struct drm_device
*dev
= crtc
->base
.dev
;
4396 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4397 struct intel_encoder
*encoder
;
4398 int pipe
= crtc
->pipe
;
4400 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
4402 u32 coreclk
, reg_val
, dpll_md
;
4404 mutex_lock(&dev_priv
->dpio_lock
);
4406 is_hdmi
= intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
);
4408 bestn
= crtc
->config
.dpll
.n
;
4409 bestm1
= crtc
->config
.dpll
.m1
;
4410 bestm2
= crtc
->config
.dpll
.m2
;
4411 bestp1
= crtc
->config
.dpll
.p1
;
4412 bestp2
= crtc
->config
.dpll
.p2
;
4414 /* See eDP HDMI DPIO driver vbios notes doc */
4416 /* PLL B needs special handling */
4418 vlv_pllb_recal_opamp(dev_priv
);
4420 /* Set up Tx target for periodic Rcomp update */
4421 vlv_dpio_write(dev_priv
, DPIO_IREF_BCAST
, 0x0100000f);
4423 /* Disable target IRef on PLL */
4424 reg_val
= vlv_dpio_read(dev_priv
, DPIO_IREF_CTL(pipe
));
4425 reg_val
&= 0x00ffffff;
4426 vlv_dpio_write(dev_priv
, DPIO_IREF_CTL(pipe
), reg_val
);
4428 /* Disable fast lock */
4429 vlv_dpio_write(dev_priv
, DPIO_FASTCLK_DISABLE
, 0x610);
4431 /* Set idtafcrecal before PLL is enabled */
4432 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
4433 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
4434 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
4435 mdiv
|= (1 << DPIO_K_SHIFT
);
4438 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
4439 * but we don't support that).
4440 * Note: don't use the DAC post divider as it seems unstable.
4442 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
4443 vlv_dpio_write(dev_priv
, DPIO_DIV(pipe
), mdiv
);
4445 mdiv
|= DPIO_ENABLE_CALIBRATION
;
4446 vlv_dpio_write(dev_priv
, DPIO_DIV(pipe
), mdiv
);
4448 /* Set HBR and RBR LPF coefficients */
4449 if (crtc
->config
.port_clock
== 162000 ||
4450 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_ANALOG
) ||
4451 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
))
4452 vlv_dpio_write(dev_priv
, DPIO_LPF_COEFF(pipe
),
4455 vlv_dpio_write(dev_priv
, DPIO_LPF_COEFF(pipe
),
4458 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
) ||
4459 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
)) {
4460 /* Use SSC source */
4462 vlv_dpio_write(dev_priv
, DPIO_REFSFR(pipe
),
4465 vlv_dpio_write(dev_priv
, DPIO_REFSFR(pipe
),
4467 } else { /* HDMI or VGA */
4468 /* Use bend source */
4470 vlv_dpio_write(dev_priv
, DPIO_REFSFR(pipe
),
4473 vlv_dpio_write(dev_priv
, DPIO_REFSFR(pipe
),
4477 coreclk
= vlv_dpio_read(dev_priv
, DPIO_CORE_CLK(pipe
));
4478 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
4479 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
) ||
4480 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
))
4481 coreclk
|= 0x01000000;
4482 vlv_dpio_write(dev_priv
, DPIO_CORE_CLK(pipe
), coreclk
);
4484 vlv_dpio_write(dev_priv
, DPIO_PLL_CML(pipe
), 0x87871000);
4486 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
)
4487 if (encoder
->pre_pll_enable
)
4488 encoder
->pre_pll_enable(encoder
);
4490 /* Enable DPIO clock input */
4491 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
4492 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
4494 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
4496 dpll
|= DPLL_VCO_ENABLE
;
4497 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
4499 I915_WRITE(DPLL(pipe
), dpll
);
4500 POSTING_READ(DPLL(pipe
));
4503 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
4504 DRM_ERROR("DPLL %d failed to lock\n", pipe
);
4506 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
4507 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
4508 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
4510 I915_WRITE(DPLL_MD(pipe
), dpll_md
);
4511 POSTING_READ(DPLL_MD(pipe
));
4513 if (crtc
->config
.has_dp_encoder
)
4514 intel_dp_set_m_n(crtc
);
4516 mutex_unlock(&dev_priv
->dpio_lock
);
4519 static void i9xx_update_pll(struct intel_crtc
*crtc
,
4520 intel_clock_t
*reduced_clock
,
4523 struct drm_device
*dev
= crtc
->base
.dev
;
4524 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4527 struct dpll
*clock
= &crtc
->config
.dpll
;
4529 i9xx_update_pll_dividers(crtc
, reduced_clock
);
4531 is_sdvo
= intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_SDVO
) ||
4532 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
);
4534 dpll
= DPLL_VGA_MODE_DIS
;
4536 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
))
4537 dpll
|= DPLLB_MODE_LVDS
;
4539 dpll
|= DPLLB_MODE_DAC_SERIAL
;
4541 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
4542 dpll
|= (crtc
->config
.pixel_multiplier
- 1)
4543 << SDVO_MULTIPLIER_SHIFT_HIRES
;
4547 dpll
|= DPLL_DVO_HIGH_SPEED
;
4549 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
))
4550 dpll
|= DPLL_DVO_HIGH_SPEED
;
4552 /* compute bitmask from p1 value */
4553 if (IS_PINEVIEW(dev
))
4554 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
4556 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
4557 if (IS_G4X(dev
) && reduced_clock
)
4558 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
4560 switch (clock
->p2
) {
4562 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
4565 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
4568 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
4571 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
4574 if (INTEL_INFO(dev
)->gen
>= 4)
4575 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
4577 if (crtc
->config
.sdvo_tv_clock
)
4578 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
4579 else if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
4580 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
4581 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
4583 dpll
|= PLL_REF_INPUT_DREFCLK
;
4585 dpll
|= DPLL_VCO_ENABLE
;
4586 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
4588 if (INTEL_INFO(dev
)->gen
>= 4) {
4589 u32 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
4590 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
4591 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
4594 if (crtc
->config
.has_dp_encoder
)
4595 intel_dp_set_m_n(crtc
);
4598 static void i8xx_update_pll(struct intel_crtc
*crtc
,
4599 intel_clock_t
*reduced_clock
,
4602 struct drm_device
*dev
= crtc
->base
.dev
;
4603 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4605 struct dpll
*clock
= &crtc
->config
.dpll
;
4607 i9xx_update_pll_dividers(crtc
, reduced_clock
);
4609 dpll
= DPLL_VGA_MODE_DIS
;
4611 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
)) {
4612 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
4615 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
4617 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
4619 dpll
|= PLL_P2_DIVIDE_BY_4
;
4622 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
4623 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
4624 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
4626 dpll
|= PLL_REF_INPUT_DREFCLK
;
4628 dpll
|= DPLL_VCO_ENABLE
;
4629 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
4632 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
4634 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4635 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4636 enum pipe pipe
= intel_crtc
->pipe
;
4637 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
4638 struct drm_display_mode
*adjusted_mode
=
4639 &intel_crtc
->config
.adjusted_mode
;
4640 struct drm_display_mode
*mode
= &intel_crtc
->config
.requested_mode
;
4641 uint32_t vsyncshift
, crtc_vtotal
, crtc_vblank_end
;
4643 /* We need to be careful not to changed the adjusted mode, for otherwise
4644 * the hw state checker will get angry at the mismatch. */
4645 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
4646 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
4648 if (!IS_GEN2(dev
) && adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
4649 /* the chip adds 2 halflines automatically */
4651 crtc_vblank_end
-= 1;
4652 vsyncshift
= adjusted_mode
->crtc_hsync_start
4653 - adjusted_mode
->crtc_htotal
/ 2;
4658 if (INTEL_INFO(dev
)->gen
> 3)
4659 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
4661 I915_WRITE(HTOTAL(cpu_transcoder
),
4662 (adjusted_mode
->crtc_hdisplay
- 1) |
4663 ((adjusted_mode
->crtc_htotal
- 1) << 16));
4664 I915_WRITE(HBLANK(cpu_transcoder
),
4665 (adjusted_mode
->crtc_hblank_start
- 1) |
4666 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
4667 I915_WRITE(HSYNC(cpu_transcoder
),
4668 (adjusted_mode
->crtc_hsync_start
- 1) |
4669 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
4671 I915_WRITE(VTOTAL(cpu_transcoder
),
4672 (adjusted_mode
->crtc_vdisplay
- 1) |
4673 ((crtc_vtotal
- 1) << 16));
4674 I915_WRITE(VBLANK(cpu_transcoder
),
4675 (adjusted_mode
->crtc_vblank_start
- 1) |
4676 ((crtc_vblank_end
- 1) << 16));
4677 I915_WRITE(VSYNC(cpu_transcoder
),
4678 (adjusted_mode
->crtc_vsync_start
- 1) |
4679 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
4681 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
4682 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
4683 * documented on the DDI_FUNC_CTL register description, EDP Input Select
4685 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
4686 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
4687 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
4689 /* pipesrc controls the size that is scaled from, which should
4690 * always be the user's requested size.
4692 I915_WRITE(PIPESRC(pipe
),
4693 ((mode
->hdisplay
- 1) << 16) | (mode
->vdisplay
- 1));
4696 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
4697 struct intel_crtc_config
*pipe_config
)
4699 struct drm_device
*dev
= crtc
->base
.dev
;
4700 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4701 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
4704 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
4705 pipe_config
->adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
4706 pipe_config
->adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
4707 tmp
= I915_READ(HBLANK(cpu_transcoder
));
4708 pipe_config
->adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
4709 pipe_config
->adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
4710 tmp
= I915_READ(HSYNC(cpu_transcoder
));
4711 pipe_config
->adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
4712 pipe_config
->adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
4714 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
4715 pipe_config
->adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
4716 pipe_config
->adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
4717 tmp
= I915_READ(VBLANK(cpu_transcoder
));
4718 pipe_config
->adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
4719 pipe_config
->adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
4720 tmp
= I915_READ(VSYNC(cpu_transcoder
));
4721 pipe_config
->adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
4722 pipe_config
->adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
4724 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
4725 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
4726 pipe_config
->adjusted_mode
.crtc_vtotal
+= 1;
4727 pipe_config
->adjusted_mode
.crtc_vblank_end
+= 1;
4730 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
4731 pipe_config
->requested_mode
.vdisplay
= (tmp
& 0xffff) + 1;
4732 pipe_config
->requested_mode
.hdisplay
= ((tmp
>> 16) & 0xffff) + 1;
4735 static void intel_crtc_mode_from_pipe_config(struct intel_crtc
*intel_crtc
,
4736 struct intel_crtc_config
*pipe_config
)
4738 struct drm_crtc
*crtc
= &intel_crtc
->base
;
4740 crtc
->mode
.hdisplay
= pipe_config
->adjusted_mode
.crtc_hdisplay
;
4741 crtc
->mode
.htotal
= pipe_config
->adjusted_mode
.crtc_htotal
;
4742 crtc
->mode
.hsync_start
= pipe_config
->adjusted_mode
.crtc_hsync_start
;
4743 crtc
->mode
.hsync_end
= pipe_config
->adjusted_mode
.crtc_hsync_end
;
4745 crtc
->mode
.vdisplay
= pipe_config
->adjusted_mode
.crtc_vdisplay
;
4746 crtc
->mode
.vtotal
= pipe_config
->adjusted_mode
.crtc_vtotal
;
4747 crtc
->mode
.vsync_start
= pipe_config
->adjusted_mode
.crtc_vsync_start
;
4748 crtc
->mode
.vsync_end
= pipe_config
->adjusted_mode
.crtc_vsync_end
;
4750 crtc
->mode
.flags
= pipe_config
->adjusted_mode
.flags
;
4752 crtc
->mode
.clock
= pipe_config
->adjusted_mode
.clock
;
4753 crtc
->mode
.flags
|= pipe_config
->adjusted_mode
.flags
;
4756 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
4758 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4759 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4764 if (intel_crtc
->pipe
== 0 && INTEL_INFO(dev
)->gen
< 4) {
4765 /* Enable pixel doubling when the dot clock is > 90% of the (display)
4768 * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
4771 if (intel_crtc
->config
.requested_mode
.clock
>
4772 dev_priv
->display
.get_display_clock_speed(dev
) * 9 / 10)
4773 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
4776 /* only g4x and later have fancy bpc/dither controls */
4777 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
4778 /* Bspec claims that we can't use dithering for 30bpp pipes. */
4779 if (intel_crtc
->config
.dither
&& intel_crtc
->config
.pipe_bpp
!= 30)
4780 pipeconf
|= PIPECONF_DITHER_EN
|
4781 PIPECONF_DITHER_TYPE_SP
;
4783 switch (intel_crtc
->config
.pipe_bpp
) {
4785 pipeconf
|= PIPECONF_6BPC
;
4788 pipeconf
|= PIPECONF_8BPC
;
4791 pipeconf
|= PIPECONF_10BPC
;
4794 /* Case prevented by intel_choose_pipe_bpp_dither. */
4799 if (HAS_PIPE_CXSR(dev
)) {
4800 if (intel_crtc
->lowfreq_avail
) {
4801 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
4802 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
4804 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
4808 if (!IS_GEN2(dev
) &&
4809 intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
4810 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
4812 pipeconf
|= PIPECONF_PROGRESSIVE
;
4814 if (IS_VALLEYVIEW(dev
) && intel_crtc
->config
.limited_color_range
)
4815 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
4817 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
4818 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
4821 static int i9xx_crtc_mode_set(struct drm_crtc
*crtc
,
4823 struct drm_framebuffer
*fb
)
4825 struct drm_device
*dev
= crtc
->dev
;
4826 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4827 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4828 struct drm_display_mode
*mode
= &intel_crtc
->config
.requested_mode
;
4829 int pipe
= intel_crtc
->pipe
;
4830 int plane
= intel_crtc
->plane
;
4831 int refclk
, num_connectors
= 0;
4832 intel_clock_t clock
, reduced_clock
;
4834 bool ok
, has_reduced_clock
= false;
4835 bool is_lvds
= false;
4836 struct intel_encoder
*encoder
;
4837 const intel_limit_t
*limit
;
4840 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4841 switch (encoder
->type
) {
4842 case INTEL_OUTPUT_LVDS
:
4850 refclk
= i9xx_get_refclk(crtc
, num_connectors
);
4853 * Returns a set of divisors for the desired target clock with the given
4854 * refclk, or FALSE. The returned values represent the clock equation:
4855 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
4857 limit
= intel_limit(crtc
, refclk
);
4858 ok
= dev_priv
->display
.find_dpll(limit
, crtc
,
4859 intel_crtc
->config
.port_clock
,
4860 refclk
, NULL
, &clock
);
4861 if (!ok
&& !intel_crtc
->config
.clock_set
) {
4862 DRM_ERROR("Couldn't find PLL settings for mode!\n");
4866 /* Ensure that the cursor is valid for the new mode before changing... */
4867 intel_crtc_update_cursor(crtc
, true);
4869 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
4871 * Ensure we match the reduced clock's P to the target clock.
4872 * If the clocks don't match, we can't switch the display clock
4873 * by using the FP0/FP1. In such case we will disable the LVDS
4874 * downclock feature.
4877 dev_priv
->display
.find_dpll(limit
, crtc
,
4878 dev_priv
->lvds_downclock
,
4882 /* Compat-code for transition, will disappear. */
4883 if (!intel_crtc
->config
.clock_set
) {
4884 intel_crtc
->config
.dpll
.n
= clock
.n
;
4885 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
4886 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
4887 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
4888 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
4892 i8xx_update_pll(intel_crtc
,
4893 has_reduced_clock
? &reduced_clock
: NULL
,
4895 else if (IS_VALLEYVIEW(dev
))
4896 vlv_update_pll(intel_crtc
);
4898 i9xx_update_pll(intel_crtc
,
4899 has_reduced_clock
? &reduced_clock
: NULL
,
4902 /* Set up the display plane register */
4903 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
4905 if (!IS_VALLEYVIEW(dev
)) {
4907 dspcntr
&= ~DISPPLANE_SEL_PIPE_MASK
;
4909 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
4912 intel_set_pipe_timings(intel_crtc
);
4914 /* pipesrc and dspsize control the size that is scaled from,
4915 * which should always be the user's requested size.
4917 I915_WRITE(DSPSIZE(plane
),
4918 ((mode
->vdisplay
- 1) << 16) |
4919 (mode
->hdisplay
- 1));
4920 I915_WRITE(DSPPOS(plane
), 0);
4922 i9xx_set_pipeconf(intel_crtc
);
4924 I915_WRITE(DSPCNTR(plane
), dspcntr
);
4925 POSTING_READ(DSPCNTR(plane
));
4927 ret
= intel_pipe_set_base(crtc
, x
, y
, fb
);
4929 intel_update_watermarks(dev
);
4934 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
4935 struct intel_crtc_config
*pipe_config
)
4937 struct drm_device
*dev
= crtc
->base
.dev
;
4938 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4941 tmp
= I915_READ(PFIT_CONTROL
);
4943 if (INTEL_INFO(dev
)->gen
< 4) {
4944 if (crtc
->pipe
!= PIPE_B
)
4947 /* gen2/3 store dither state in pfit control, needs to match */
4948 pipe_config
->gmch_pfit
.control
= tmp
& PANEL_8TO6_DITHER_ENABLE
;
4950 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
4954 if (!(tmp
& PFIT_ENABLE
))
4957 pipe_config
->gmch_pfit
.control
= I915_READ(PFIT_CONTROL
);
4958 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
4959 if (INTEL_INFO(dev
)->gen
< 5)
4960 pipe_config
->gmch_pfit
.lvds_border_bits
=
4961 I915_READ(LVDS
) & LVDS_BORDER_ENABLE
;
4964 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
4965 struct intel_crtc_config
*pipe_config
)
4967 struct drm_device
*dev
= crtc
->base
.dev
;
4968 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4971 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
4972 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
4974 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
4975 if (!(tmp
& PIPECONF_ENABLE
))
4978 intel_get_pipe_timings(crtc
, pipe_config
);
4980 i9xx_get_pfit_config(crtc
, pipe_config
);
4982 if (INTEL_INFO(dev
)->gen
>= 4) {
4983 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
4984 pipe_config
->pixel_multiplier
=
4985 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
4986 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
4987 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
4988 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
4989 tmp
= I915_READ(DPLL(crtc
->pipe
));
4990 pipe_config
->pixel_multiplier
=
4991 ((tmp
& SDVO_MULTIPLIER_MASK
)
4992 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
4994 /* Note that on i915G/GM the pixel multiplier is in the sdvo
4995 * port and will be fixed up in the encoder->get_config
4997 pipe_config
->pixel_multiplier
= 1;
4999 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
5000 if (!IS_VALLEYVIEW(dev
)) {
5001 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
5002 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
5004 /* Mask out read-only status bits. */
5005 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
5006 DPLL_PORTC_READY_MASK
|
5007 DPLL_PORTB_READY_MASK
);
5013 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
5015 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5016 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
5017 struct intel_encoder
*encoder
;
5019 bool has_lvds
= false;
5020 bool has_cpu_edp
= false;
5021 bool has_panel
= false;
5022 bool has_ck505
= false;
5023 bool can_ssc
= false;
5025 /* We need to take the global config into account */
5026 list_for_each_entry(encoder
, &mode_config
->encoder_list
,
5028 switch (encoder
->type
) {
5029 case INTEL_OUTPUT_LVDS
:
5033 case INTEL_OUTPUT_EDP
:
5035 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
5041 if (HAS_PCH_IBX(dev
)) {
5042 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
5043 can_ssc
= has_ck505
;
5049 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
5050 has_panel
, has_lvds
, has_ck505
);
5052 /* Ironlake: try to setup display ref clock before DPLL
5053 * enabling. This is only under driver's control after
5054 * PCH B stepping, previous chipset stepping should be
5055 * ignoring this setting.
5057 val
= I915_READ(PCH_DREF_CONTROL
);
5059 /* As we must carefully and slowly disable/enable each source in turn,
5060 * compute the final state we want first and check if we need to
5061 * make any changes at all.
5064 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
5066 final
|= DREF_NONSPREAD_CK505_ENABLE
;
5068 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
5070 final
&= ~DREF_SSC_SOURCE_MASK
;
5071 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
5072 final
&= ~DREF_SSC1_ENABLE
;
5075 final
|= DREF_SSC_SOURCE_ENABLE
;
5077 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
5078 final
|= DREF_SSC1_ENABLE
;
5081 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
5082 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
5084 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
5086 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
5088 final
|= DREF_SSC_SOURCE_DISABLE
;
5089 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
5095 /* Always enable nonspread source */
5096 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
5099 val
|= DREF_NONSPREAD_CK505_ENABLE
;
5101 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
5104 val
&= ~DREF_SSC_SOURCE_MASK
;
5105 val
|= DREF_SSC_SOURCE_ENABLE
;
5107 /* SSC must be turned on before enabling the CPU output */
5108 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
5109 DRM_DEBUG_KMS("Using SSC on panel\n");
5110 val
|= DREF_SSC1_ENABLE
;
5112 val
&= ~DREF_SSC1_ENABLE
;
5114 /* Get SSC going before enabling the outputs */
5115 I915_WRITE(PCH_DREF_CONTROL
, val
);
5116 POSTING_READ(PCH_DREF_CONTROL
);
5119 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
5121 /* Enable CPU source on CPU attached eDP */
5123 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
5124 DRM_DEBUG_KMS("Using SSC on eDP\n");
5125 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
5128 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
5130 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
5132 I915_WRITE(PCH_DREF_CONTROL
, val
);
5133 POSTING_READ(PCH_DREF_CONTROL
);
5136 DRM_DEBUG_KMS("Disabling SSC entirely\n");
5138 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
5140 /* Turn off CPU output */
5141 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
5143 I915_WRITE(PCH_DREF_CONTROL
, val
);
5144 POSTING_READ(PCH_DREF_CONTROL
);
5147 /* Turn off the SSC source */
5148 val
&= ~DREF_SSC_SOURCE_MASK
;
5149 val
|= DREF_SSC_SOURCE_DISABLE
;
5152 val
&= ~DREF_SSC1_ENABLE
;
5154 I915_WRITE(PCH_DREF_CONTROL
, val
);
5155 POSTING_READ(PCH_DREF_CONTROL
);
5159 BUG_ON(val
!= final
);
5162 /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
5163 static void lpt_init_pch_refclk(struct drm_device
*dev
)
5165 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5166 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
5167 struct intel_encoder
*encoder
;
5168 bool has_vga
= false;
5169 bool is_sdv
= false;
5172 list_for_each_entry(encoder
, &mode_config
->encoder_list
, base
.head
) {
5173 switch (encoder
->type
) {
5174 case INTEL_OUTPUT_ANALOG
:
5183 mutex_lock(&dev_priv
->dpio_lock
);
5185 /* XXX: Rip out SDV support once Haswell ships for real. */
5186 if (IS_HASWELL(dev
) && (dev
->pci_device
& 0xFF00) == 0x0C00)
5189 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
5190 tmp
&= ~SBI_SSCCTL_DISABLE
;
5191 tmp
|= SBI_SSCCTL_PATHALT
;
5192 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
5196 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
5197 tmp
&= ~SBI_SSCCTL_PATHALT
;
5198 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
5201 tmp
= I915_READ(SOUTH_CHICKEN2
);
5202 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
5203 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
5205 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
5206 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
5207 DRM_ERROR("FDI mPHY reset assert timeout\n");
5209 tmp
= I915_READ(SOUTH_CHICKEN2
);
5210 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
5211 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
5213 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
5214 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0,
5216 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
5219 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
5220 tmp
&= ~(0xFF << 24);
5221 tmp
|= (0x12 << 24);
5222 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
5225 tmp
= intel_sbi_read(dev_priv
, 0x800C, SBI_MPHY
);
5227 intel_sbi_write(dev_priv
, 0x800C, tmp
, SBI_MPHY
);
5230 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
5232 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
5234 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
5236 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
5239 tmp
= intel_sbi_read(dev_priv
, 0x2038, SBI_MPHY
);
5240 tmp
|= (0x3F << 24) | (0xF << 20) | (0xF << 16);
5241 intel_sbi_write(dev_priv
, 0x2038, tmp
, SBI_MPHY
);
5243 tmp
= intel_sbi_read(dev_priv
, 0x2138, SBI_MPHY
);
5244 tmp
|= (0x3F << 24) | (0xF << 20) | (0xF << 16);
5245 intel_sbi_write(dev_priv
, 0x2138, tmp
, SBI_MPHY
);
5247 tmp
= intel_sbi_read(dev_priv
, 0x203C, SBI_MPHY
);
5249 intel_sbi_write(dev_priv
, 0x203C, tmp
, SBI_MPHY
);
5251 tmp
= intel_sbi_read(dev_priv
, 0x213C, SBI_MPHY
);
5253 intel_sbi_write(dev_priv
, 0x213C, tmp
, SBI_MPHY
);
5256 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
5257 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
5258 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
5260 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
5261 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
5262 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
5265 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
5268 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
5270 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
5273 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
5276 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
5279 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
5281 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
5284 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
5286 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
5287 tmp
&= ~(0xFF << 16);
5288 tmp
|= (0x1C << 16);
5289 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
5291 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
5292 tmp
&= ~(0xFF << 16);
5293 tmp
|= (0x1C << 16);
5294 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
5297 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
5299 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
5301 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
5303 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
5305 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
5306 tmp
&= ~(0xF << 28);
5308 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
5310 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
5311 tmp
&= ~(0xF << 28);
5313 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
5316 /* ULT uses SBI_GEN0, but ULT doesn't have VGA, so we don't care. */
5317 tmp
= intel_sbi_read(dev_priv
, SBI_DBUFF0
, SBI_ICLK
);
5318 tmp
|= SBI_DBUFF0_ENABLE
;
5319 intel_sbi_write(dev_priv
, SBI_DBUFF0
, tmp
, SBI_ICLK
);
5321 mutex_unlock(&dev_priv
->dpio_lock
);
5325 * Initialize reference clocks when the driver loads
5327 void intel_init_pch_refclk(struct drm_device
*dev
)
5329 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
5330 ironlake_init_pch_refclk(dev
);
5331 else if (HAS_PCH_LPT(dev
))
5332 lpt_init_pch_refclk(dev
);
5335 static int ironlake_get_refclk(struct drm_crtc
*crtc
)
5337 struct drm_device
*dev
= crtc
->dev
;
5338 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5339 struct intel_encoder
*encoder
;
5340 int num_connectors
= 0;
5341 bool is_lvds
= false;
5343 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5344 switch (encoder
->type
) {
5345 case INTEL_OUTPUT_LVDS
:
5352 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
5353 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
5354 dev_priv
->vbt
.lvds_ssc_freq
);
5355 return dev_priv
->vbt
.lvds_ssc_freq
* 1000;
5361 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
5363 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
5364 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5365 int pipe
= intel_crtc
->pipe
;
5370 switch (intel_crtc
->config
.pipe_bpp
) {
5372 val
|= PIPECONF_6BPC
;
5375 val
|= PIPECONF_8BPC
;
5378 val
|= PIPECONF_10BPC
;
5381 val
|= PIPECONF_12BPC
;
5384 /* Case prevented by intel_choose_pipe_bpp_dither. */
5388 if (intel_crtc
->config
.dither
)
5389 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
5391 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
5392 val
|= PIPECONF_INTERLACED_ILK
;
5394 val
|= PIPECONF_PROGRESSIVE
;
5396 if (intel_crtc
->config
.limited_color_range
)
5397 val
|= PIPECONF_COLOR_RANGE_SELECT
;
5399 I915_WRITE(PIPECONF(pipe
), val
);
5400 POSTING_READ(PIPECONF(pipe
));
5404 * Set up the pipe CSC unit.
5406 * Currently only full range RGB to limited range RGB conversion
5407 * is supported, but eventually this should handle various
5408 * RGB<->YCbCr scenarios as well.
5410 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
5412 struct drm_device
*dev
= crtc
->dev
;
5413 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5414 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5415 int pipe
= intel_crtc
->pipe
;
5416 uint16_t coeff
= 0x7800; /* 1.0 */
5419 * TODO: Check what kind of values actually come out of the pipe
5420 * with these coeff/postoff values and adjust to get the best
5421 * accuracy. Perhaps we even need to take the bpc value into
5425 if (intel_crtc
->config
.limited_color_range
)
5426 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
5429 * GY/GU and RY/RU should be the other way around according
5430 * to BSpec, but reality doesn't agree. Just set them up in
5431 * a way that results in the correct picture.
5433 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
5434 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
5436 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
5437 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
5439 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
5440 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
5442 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
5443 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
5444 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
5446 if (INTEL_INFO(dev
)->gen
> 6) {
5447 uint16_t postoff
= 0;
5449 if (intel_crtc
->config
.limited_color_range
)
5450 postoff
= (16 * (1 << 13) / 255) & 0x1fff;
5452 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
5453 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
5454 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
5456 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
5458 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
5460 if (intel_crtc
->config
.limited_color_range
)
5461 mode
|= CSC_BLACK_SCREEN_OFFSET
;
5463 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
5467 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
5469 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
5470 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5471 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
5476 if (intel_crtc
->config
.dither
)
5477 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
5479 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
5480 val
|= PIPECONF_INTERLACED_ILK
;
5482 val
|= PIPECONF_PROGRESSIVE
;
5484 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
5485 POSTING_READ(PIPECONF(cpu_transcoder
));
5487 I915_WRITE(GAMMA_MODE(intel_crtc
->pipe
), GAMMA_MODE_MODE_8BIT
);
5488 POSTING_READ(GAMMA_MODE(intel_crtc
->pipe
));
5491 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
5492 intel_clock_t
*clock
,
5493 bool *has_reduced_clock
,
5494 intel_clock_t
*reduced_clock
)
5496 struct drm_device
*dev
= crtc
->dev
;
5497 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5498 struct intel_encoder
*intel_encoder
;
5500 const intel_limit_t
*limit
;
5501 bool ret
, is_lvds
= false;
5503 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
5504 switch (intel_encoder
->type
) {
5505 case INTEL_OUTPUT_LVDS
:
5511 refclk
= ironlake_get_refclk(crtc
);
5514 * Returns a set of divisors for the desired target clock with the given
5515 * refclk, or FALSE. The returned values represent the clock equation:
5516 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
5518 limit
= intel_limit(crtc
, refclk
);
5519 ret
= dev_priv
->display
.find_dpll(limit
, crtc
,
5520 to_intel_crtc(crtc
)->config
.port_clock
,
5521 refclk
, NULL
, clock
);
5525 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
5527 * Ensure we match the reduced clock's P to the target clock.
5528 * If the clocks don't match, we can't switch the display clock
5529 * by using the FP0/FP1. In such case we will disable the LVDS
5530 * downclock feature.
5532 *has_reduced_clock
=
5533 dev_priv
->display
.find_dpll(limit
, crtc
,
5534 dev_priv
->lvds_downclock
,
5542 static void cpt_enable_fdi_bc_bifurcation(struct drm_device
*dev
)
5544 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5547 temp
= I915_READ(SOUTH_CHICKEN1
);
5548 if (temp
& FDI_BC_BIFURCATION_SELECT
)
5551 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
5552 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
5554 temp
|= FDI_BC_BIFURCATION_SELECT
;
5555 DRM_DEBUG_KMS("enabling fdi C rx\n");
5556 I915_WRITE(SOUTH_CHICKEN1
, temp
);
5557 POSTING_READ(SOUTH_CHICKEN1
);
5560 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
5562 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5563 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5565 switch (intel_crtc
->pipe
) {
5569 if (intel_crtc
->config
.fdi_lanes
> 2)
5570 WARN_ON(I915_READ(SOUTH_CHICKEN1
) & FDI_BC_BIFURCATION_SELECT
);
5572 cpt_enable_fdi_bc_bifurcation(dev
);
5576 cpt_enable_fdi_bc_bifurcation(dev
);
5584 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
5587 * Account for spread spectrum to avoid
5588 * oversubscribing the link. Max center spread
5589 * is 2.5%; use 5% for safety's sake.
5591 u32 bps
= target_clock
* bpp
* 21 / 20;
5592 return bps
/ (link_bw
* 8) + 1;
5595 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
5597 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
5600 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
5602 intel_clock_t
*reduced_clock
, u32
*fp2
)
5604 struct drm_crtc
*crtc
= &intel_crtc
->base
;
5605 struct drm_device
*dev
= crtc
->dev
;
5606 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5607 struct intel_encoder
*intel_encoder
;
5609 int factor
, num_connectors
= 0;
5610 bool is_lvds
= false, is_sdvo
= false;
5612 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
5613 switch (intel_encoder
->type
) {
5614 case INTEL_OUTPUT_LVDS
:
5617 case INTEL_OUTPUT_SDVO
:
5618 case INTEL_OUTPUT_HDMI
:
5626 /* Enable autotuning of the PLL clock (if permissible) */
5629 if ((intel_panel_use_ssc(dev_priv
) &&
5630 dev_priv
->vbt
.lvds_ssc_freq
== 100) ||
5631 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
5633 } else if (intel_crtc
->config
.sdvo_tv_clock
)
5636 if (ironlake_needs_fb_cb_tune(&intel_crtc
->config
.dpll
, factor
))
5639 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
5645 dpll
|= DPLLB_MODE_LVDS
;
5647 dpll
|= DPLLB_MODE_DAC_SERIAL
;
5649 dpll
|= (intel_crtc
->config
.pixel_multiplier
- 1)
5650 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
5653 dpll
|= DPLL_DVO_HIGH_SPEED
;
5654 if (intel_crtc
->config
.has_dp_encoder
)
5655 dpll
|= DPLL_DVO_HIGH_SPEED
;
5657 /* compute bitmask from p1 value */
5658 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5660 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
5662 switch (intel_crtc
->config
.dpll
.p2
) {
5664 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
5667 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
5670 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
5673 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
5677 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5678 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5680 dpll
|= PLL_REF_INPUT_DREFCLK
;
5682 return dpll
| DPLL_VCO_ENABLE
;
5685 static int ironlake_crtc_mode_set(struct drm_crtc
*crtc
,
5687 struct drm_framebuffer
*fb
)
5689 struct drm_device
*dev
= crtc
->dev
;
5690 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5691 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5692 int pipe
= intel_crtc
->pipe
;
5693 int plane
= intel_crtc
->plane
;
5694 int num_connectors
= 0;
5695 intel_clock_t clock
, reduced_clock
;
5696 u32 dpll
= 0, fp
= 0, fp2
= 0;
5697 bool ok
, has_reduced_clock
= false;
5698 bool is_lvds
= false;
5699 struct intel_encoder
*encoder
;
5700 struct intel_shared_dpll
*pll
;
5703 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5704 switch (encoder
->type
) {
5705 case INTEL_OUTPUT_LVDS
:
5713 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
5714 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
5716 ok
= ironlake_compute_clocks(crtc
, &clock
,
5717 &has_reduced_clock
, &reduced_clock
);
5718 if (!ok
&& !intel_crtc
->config
.clock_set
) {
5719 DRM_ERROR("Couldn't find PLL settings for mode!\n");
5722 /* Compat-code for transition, will disappear. */
5723 if (!intel_crtc
->config
.clock_set
) {
5724 intel_crtc
->config
.dpll
.n
= clock
.n
;
5725 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
5726 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
5727 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
5728 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
5731 /* Ensure that the cursor is valid for the new mode before changing... */
5732 intel_crtc_update_cursor(crtc
, true);
5734 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
5735 if (intel_crtc
->config
.has_pch_encoder
) {
5736 fp
= i9xx_dpll_compute_fp(&intel_crtc
->config
.dpll
);
5737 if (has_reduced_clock
)
5738 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
5740 dpll
= ironlake_compute_dpll(intel_crtc
,
5741 &fp
, &reduced_clock
,
5742 has_reduced_clock
? &fp2
: NULL
);
5744 intel_crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5745 intel_crtc
->config
.dpll_hw_state
.fp0
= fp
;
5746 if (has_reduced_clock
)
5747 intel_crtc
->config
.dpll_hw_state
.fp1
= fp2
;
5749 intel_crtc
->config
.dpll_hw_state
.fp1
= fp
;
5751 pll
= intel_get_shared_dpll(intel_crtc
);
5753 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
5758 intel_put_shared_dpll(intel_crtc
);
5760 if (intel_crtc
->config
.has_dp_encoder
)
5761 intel_dp_set_m_n(intel_crtc
);
5763 if (is_lvds
&& has_reduced_clock
&& i915_powersave
)
5764 intel_crtc
->lowfreq_avail
= true;
5766 intel_crtc
->lowfreq_avail
= false;
5768 if (intel_crtc
->config
.has_pch_encoder
) {
5769 pll
= intel_crtc_to_shared_dpll(intel_crtc
);
5773 intel_set_pipe_timings(intel_crtc
);
5775 if (intel_crtc
->config
.has_pch_encoder
) {
5776 intel_cpu_transcoder_set_m_n(intel_crtc
,
5777 &intel_crtc
->config
.fdi_m_n
);
5780 if (IS_IVYBRIDGE(dev
))
5781 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
5783 ironlake_set_pipeconf(crtc
);
5785 /* Set up the display plane register */
5786 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
);
5787 POSTING_READ(DSPCNTR(plane
));
5789 ret
= intel_pipe_set_base(crtc
, x
, y
, fb
);
5791 intel_update_watermarks(dev
);
5796 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
5797 struct intel_crtc_config
*pipe_config
)
5799 struct drm_device
*dev
= crtc
->base
.dev
;
5800 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5801 enum transcoder transcoder
= pipe_config
->cpu_transcoder
;
5803 pipe_config
->fdi_m_n
.link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
5804 pipe_config
->fdi_m_n
.link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
5805 pipe_config
->fdi_m_n
.gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
5807 pipe_config
->fdi_m_n
.gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
5808 pipe_config
->fdi_m_n
.tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
5809 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
5812 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
5813 struct intel_crtc_config
*pipe_config
)
5815 struct drm_device
*dev
= crtc
->base
.dev
;
5816 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5819 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
5821 if (tmp
& PF_ENABLE
) {
5822 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
5823 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
5825 /* We currently do not free assignements of panel fitters on
5826 * ivb/hsw (since we don't use the higher upscaling modes which
5827 * differentiates them) so just WARN about this case for now. */
5829 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
5830 PF_PIPE_SEL_IVB(crtc
->pipe
));
5835 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
5836 struct intel_crtc_config
*pipe_config
)
5838 struct drm_device
*dev
= crtc
->base
.dev
;
5839 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5842 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
5843 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
5845 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
5846 if (!(tmp
& PIPECONF_ENABLE
))
5849 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
5850 struct intel_shared_dpll
*pll
;
5852 pipe_config
->has_pch_encoder
= true;
5854 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
5855 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
5856 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
5858 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
5860 if (HAS_PCH_IBX(dev_priv
->dev
)) {
5861 pipe_config
->shared_dpll
=
5862 (enum intel_dpll_id
) crtc
->pipe
;
5864 tmp
= I915_READ(PCH_DPLL_SEL
);
5865 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
5866 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_B
;
5868 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_A
;
5871 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
5873 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
5874 &pipe_config
->dpll_hw_state
));
5876 tmp
= pipe_config
->dpll_hw_state
.dpll
;
5877 pipe_config
->pixel_multiplier
=
5878 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
5879 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
5881 pipe_config
->pixel_multiplier
= 1;
5884 intel_get_pipe_timings(crtc
, pipe_config
);
5886 ironlake_get_pfit_config(crtc
, pipe_config
);
5891 static void haswell_modeset_global_resources(struct drm_device
*dev
)
5893 bool enable
= false;
5894 struct intel_crtc
*crtc
;
5896 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, base
.head
) {
5897 if (!crtc
->base
.enabled
)
5900 if (crtc
->pipe
!= PIPE_A
|| crtc
->config
.pch_pfit
.size
||
5901 crtc
->config
.cpu_transcoder
!= TRANSCODER_EDP
)
5905 intel_set_power_well(dev
, enable
);
5908 static int haswell_crtc_mode_set(struct drm_crtc
*crtc
,
5910 struct drm_framebuffer
*fb
)
5912 struct drm_device
*dev
= crtc
->dev
;
5913 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5914 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5915 int plane
= intel_crtc
->plane
;
5918 if (!intel_ddi_pll_mode_set(crtc
))
5921 /* Ensure that the cursor is valid for the new mode before changing... */
5922 intel_crtc_update_cursor(crtc
, true);
5924 if (intel_crtc
->config
.has_dp_encoder
)
5925 intel_dp_set_m_n(intel_crtc
);
5927 intel_crtc
->lowfreq_avail
= false;
5929 intel_set_pipe_timings(intel_crtc
);
5931 if (intel_crtc
->config
.has_pch_encoder
) {
5932 intel_cpu_transcoder_set_m_n(intel_crtc
,
5933 &intel_crtc
->config
.fdi_m_n
);
5936 haswell_set_pipeconf(crtc
);
5938 intel_set_pipe_csc(crtc
);
5940 /* Set up the display plane register */
5941 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
| DISPPLANE_PIPE_CSC_ENABLE
);
5942 POSTING_READ(DSPCNTR(plane
));
5944 ret
= intel_pipe_set_base(crtc
, x
, y
, fb
);
5946 intel_update_watermarks(dev
);
5951 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
5952 struct intel_crtc_config
*pipe_config
)
5954 struct drm_device
*dev
= crtc
->base
.dev
;
5955 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5956 enum intel_display_power_domain pfit_domain
;
5959 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
5960 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
5962 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
5963 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
5964 enum pipe trans_edp_pipe
;
5965 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
5967 WARN(1, "unknown pipe linked to edp transcoder\n");
5968 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
5969 case TRANS_DDI_EDP_INPUT_A_ON
:
5970 trans_edp_pipe
= PIPE_A
;
5972 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
5973 trans_edp_pipe
= PIPE_B
;
5975 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
5976 trans_edp_pipe
= PIPE_C
;
5980 if (trans_edp_pipe
== crtc
->pipe
)
5981 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
5984 if (!intel_display_power_enabled(dev
,
5985 POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
)))
5988 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
5989 if (!(tmp
& PIPECONF_ENABLE
))
5993 * Haswell has only FDI/PCH transcoder A. It is which is connected to
5994 * DDI E. So just check whether this pipe is wired to DDI E and whether
5995 * the PCH transcoder is on.
5997 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
5998 if ((tmp
& TRANS_DDI_PORT_MASK
) == TRANS_DDI_SELECT_PORT(PORT_E
) &&
5999 I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
6000 pipe_config
->has_pch_encoder
= true;
6002 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
6003 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
6004 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
6006 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
6009 intel_get_pipe_timings(crtc
, pipe_config
);
6011 pfit_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
6012 if (intel_display_power_enabled(dev
, pfit_domain
))
6013 ironlake_get_pfit_config(crtc
, pipe_config
);
6015 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
6016 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
6018 pipe_config
->pixel_multiplier
= 1;
6023 static int intel_crtc_mode_set(struct drm_crtc
*crtc
,
6025 struct drm_framebuffer
*fb
)
6027 struct drm_device
*dev
= crtc
->dev
;
6028 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6029 struct drm_encoder_helper_funcs
*encoder_funcs
;
6030 struct intel_encoder
*encoder
;
6031 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6032 struct drm_display_mode
*adjusted_mode
=
6033 &intel_crtc
->config
.adjusted_mode
;
6034 struct drm_display_mode
*mode
= &intel_crtc
->config
.requested_mode
;
6035 int pipe
= intel_crtc
->pipe
;
6038 drm_vblank_pre_modeset(dev
, pipe
);
6040 ret
= dev_priv
->display
.crtc_mode_set(crtc
, x
, y
, fb
);
6042 drm_vblank_post_modeset(dev
, pipe
);
6047 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
6048 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
6049 encoder
->base
.base
.id
,
6050 drm_get_encoder_name(&encoder
->base
),
6051 mode
->base
.id
, mode
->name
);
6052 if (encoder
->mode_set
) {
6053 encoder
->mode_set(encoder
);
6055 encoder_funcs
= encoder
->base
.helper_private
;
6056 encoder_funcs
->mode_set(&encoder
->base
, mode
, adjusted_mode
);
6063 static bool intel_eld_uptodate(struct drm_connector
*connector
,
6064 int reg_eldv
, uint32_t bits_eldv
,
6065 int reg_elda
, uint32_t bits_elda
,
6068 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
6069 uint8_t *eld
= connector
->eld
;
6072 i
= I915_READ(reg_eldv
);
6081 i
= I915_READ(reg_elda
);
6083 I915_WRITE(reg_elda
, i
);
6085 for (i
= 0; i
< eld
[2]; i
++)
6086 if (I915_READ(reg_edid
) != *((uint32_t *)eld
+ i
))
6092 static void g4x_write_eld(struct drm_connector
*connector
,
6093 struct drm_crtc
*crtc
)
6095 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
6096 uint8_t *eld
= connector
->eld
;
6101 i
= I915_READ(G4X_AUD_VID_DID
);
6103 if (i
== INTEL_AUDIO_DEVBLC
|| i
== INTEL_AUDIO_DEVCL
)
6104 eldv
= G4X_ELDV_DEVCL_DEVBLC
;
6106 eldv
= G4X_ELDV_DEVCTG
;
6108 if (intel_eld_uptodate(connector
,
6109 G4X_AUD_CNTL_ST
, eldv
,
6110 G4X_AUD_CNTL_ST
, G4X_ELD_ADDR
,
6111 G4X_HDMIW_HDMIEDID
))
6114 i
= I915_READ(G4X_AUD_CNTL_ST
);
6115 i
&= ~(eldv
| G4X_ELD_ADDR
);
6116 len
= (i
>> 9) & 0x1f; /* ELD buffer size */
6117 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
6122 len
= min_t(uint8_t, eld
[2], len
);
6123 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
6124 for (i
= 0; i
< len
; i
++)
6125 I915_WRITE(G4X_HDMIW_HDMIEDID
, *((uint32_t *)eld
+ i
));
6127 i
= I915_READ(G4X_AUD_CNTL_ST
);
6129 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
6132 static void haswell_write_eld(struct drm_connector
*connector
,
6133 struct drm_crtc
*crtc
)
6135 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
6136 uint8_t *eld
= connector
->eld
;
6137 struct drm_device
*dev
= crtc
->dev
;
6138 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6142 int pipe
= to_intel_crtc(crtc
)->pipe
;
6145 int hdmiw_hdmiedid
= HSW_AUD_EDID_DATA(pipe
);
6146 int aud_cntl_st
= HSW_AUD_DIP_ELD_CTRL(pipe
);
6147 int aud_config
= HSW_AUD_CFG(pipe
);
6148 int aud_cntrl_st2
= HSW_AUD_PIN_ELD_CP_VLD
;
6151 DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n");
6153 /* Audio output enable */
6154 DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
6155 tmp
= I915_READ(aud_cntrl_st2
);
6156 tmp
|= (AUDIO_OUTPUT_ENABLE_A
<< (pipe
* 4));
6157 I915_WRITE(aud_cntrl_st2
, tmp
);
6159 /* Wait for 1 vertical blank */
6160 intel_wait_for_vblank(dev
, pipe
);
6162 /* Set ELD valid state */
6163 tmp
= I915_READ(aud_cntrl_st2
);
6164 DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp
);
6165 tmp
|= (AUDIO_ELD_VALID_A
<< (pipe
* 4));
6166 I915_WRITE(aud_cntrl_st2
, tmp
);
6167 tmp
= I915_READ(aud_cntrl_st2
);
6168 DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp
);
6170 /* Enable HDMI mode */
6171 tmp
= I915_READ(aud_config
);
6172 DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp
);
6173 /* clear N_programing_enable and N_value_index */
6174 tmp
&= ~(AUD_CONFIG_N_VALUE_INDEX
| AUD_CONFIG_N_PROG_ENABLE
);
6175 I915_WRITE(aud_config
, tmp
);
6177 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
6179 eldv
= AUDIO_ELD_VALID_A
<< (pipe
* 4);
6180 intel_crtc
->eld_vld
= true;
6182 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
6183 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
6184 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
6185 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
6187 I915_WRITE(aud_config
, 0);
6189 if (intel_eld_uptodate(connector
,
6190 aud_cntrl_st2
, eldv
,
6191 aud_cntl_st
, IBX_ELD_ADDRESS
,
6195 i
= I915_READ(aud_cntrl_st2
);
6197 I915_WRITE(aud_cntrl_st2
, i
);
6202 i
= I915_READ(aud_cntl_st
);
6203 i
&= ~IBX_ELD_ADDRESS
;
6204 I915_WRITE(aud_cntl_st
, i
);
6205 i
= (i
>> 29) & DIP_PORT_SEL_MASK
; /* DIP_Port_Select, 0x1 = PortB */
6206 DRM_DEBUG_DRIVER("port num:%d\n", i
);
6208 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
6209 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
6210 for (i
= 0; i
< len
; i
++)
6211 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
6213 i
= I915_READ(aud_cntrl_st2
);
6215 I915_WRITE(aud_cntrl_st2
, i
);
6219 static void ironlake_write_eld(struct drm_connector
*connector
,
6220 struct drm_crtc
*crtc
)
6222 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
6223 uint8_t *eld
= connector
->eld
;
6231 int pipe
= to_intel_crtc(crtc
)->pipe
;
6233 if (HAS_PCH_IBX(connector
->dev
)) {
6234 hdmiw_hdmiedid
= IBX_HDMIW_HDMIEDID(pipe
);
6235 aud_config
= IBX_AUD_CFG(pipe
);
6236 aud_cntl_st
= IBX_AUD_CNTL_ST(pipe
);
6237 aud_cntrl_st2
= IBX_AUD_CNTL_ST2
;
6239 hdmiw_hdmiedid
= CPT_HDMIW_HDMIEDID(pipe
);
6240 aud_config
= CPT_AUD_CFG(pipe
);
6241 aud_cntl_st
= CPT_AUD_CNTL_ST(pipe
);
6242 aud_cntrl_st2
= CPT_AUD_CNTRL_ST2
;
6245 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
6247 i
= I915_READ(aud_cntl_st
);
6248 i
= (i
>> 29) & DIP_PORT_SEL_MASK
; /* DIP_Port_Select, 0x1 = PortB */
6250 DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
6251 /* operate blindly on all ports */
6252 eldv
= IBX_ELD_VALIDB
;
6253 eldv
|= IBX_ELD_VALIDB
<< 4;
6254 eldv
|= IBX_ELD_VALIDB
<< 8;
6256 DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i
));
6257 eldv
= IBX_ELD_VALIDB
<< ((i
- 1) * 4);
6260 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
6261 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
6262 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
6263 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
6265 I915_WRITE(aud_config
, 0);
6267 if (intel_eld_uptodate(connector
,
6268 aud_cntrl_st2
, eldv
,
6269 aud_cntl_st
, IBX_ELD_ADDRESS
,
6273 i
= I915_READ(aud_cntrl_st2
);
6275 I915_WRITE(aud_cntrl_st2
, i
);
6280 i
= I915_READ(aud_cntl_st
);
6281 i
&= ~IBX_ELD_ADDRESS
;
6282 I915_WRITE(aud_cntl_st
, i
);
6284 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
6285 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
6286 for (i
= 0; i
< len
; i
++)
6287 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
6289 i
= I915_READ(aud_cntrl_st2
);
6291 I915_WRITE(aud_cntrl_st2
, i
);
6294 void intel_write_eld(struct drm_encoder
*encoder
,
6295 struct drm_display_mode
*mode
)
6297 struct drm_crtc
*crtc
= encoder
->crtc
;
6298 struct drm_connector
*connector
;
6299 struct drm_device
*dev
= encoder
->dev
;
6300 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6302 connector
= drm_select_eld(encoder
, mode
);
6306 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6308 drm_get_connector_name(connector
),
6309 connector
->encoder
->base
.id
,
6310 drm_get_encoder_name(connector
->encoder
));
6312 connector
->eld
[6] = drm_av_sync_delay(connector
, mode
) / 2;
6314 if (dev_priv
->display
.write_eld
)
6315 dev_priv
->display
.write_eld(connector
, crtc
);
6318 /** Loads the palette/gamma unit for the CRTC with the prepared values */
6319 void intel_crtc_load_lut(struct drm_crtc
*crtc
)
6321 struct drm_device
*dev
= crtc
->dev
;
6322 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6323 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6324 enum pipe pipe
= intel_crtc
->pipe
;
6325 int palreg
= PALETTE(pipe
);
6327 bool reenable_ips
= false;
6329 /* The clocks have to be on to load the palette. */
6330 if (!crtc
->enabled
|| !intel_crtc
->active
)
6333 if (!HAS_PCH_SPLIT(dev_priv
->dev
))
6334 assert_pll_enabled(dev_priv
, pipe
);
6336 /* use legacy palette for Ironlake */
6337 if (HAS_PCH_SPLIT(dev
))
6338 palreg
= LGC_PALETTE(pipe
);
6340 /* Workaround : Do not read or write the pipe palette/gamma data while
6341 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
6343 if (intel_crtc
->config
.ips_enabled
&&
6344 ((I915_READ(GAMMA_MODE(pipe
)) & GAMMA_MODE_MODE_MASK
) ==
6345 GAMMA_MODE_MODE_SPLIT
)) {
6346 hsw_disable_ips(intel_crtc
);
6347 reenable_ips
= true;
6350 for (i
= 0; i
< 256; i
++) {
6351 I915_WRITE(palreg
+ 4 * i
,
6352 (intel_crtc
->lut_r
[i
] << 16) |
6353 (intel_crtc
->lut_g
[i
] << 8) |
6354 intel_crtc
->lut_b
[i
]);
6358 hsw_enable_ips(intel_crtc
);
6361 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
6363 struct drm_device
*dev
= crtc
->dev
;
6364 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6365 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6366 bool visible
= base
!= 0;
6369 if (intel_crtc
->cursor_visible
== visible
)
6372 cntl
= I915_READ(_CURACNTR
);
6374 /* On these chipsets we can only modify the base whilst
6375 * the cursor is disabled.
6377 I915_WRITE(_CURABASE
, base
);
6379 cntl
&= ~(CURSOR_FORMAT_MASK
);
6380 /* XXX width must be 64, stride 256 => 0x00 << 28 */
6381 cntl
|= CURSOR_ENABLE
|
6382 CURSOR_GAMMA_ENABLE
|
6385 cntl
&= ~(CURSOR_ENABLE
| CURSOR_GAMMA_ENABLE
);
6386 I915_WRITE(_CURACNTR
, cntl
);
6388 intel_crtc
->cursor_visible
= visible
;
6391 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
6393 struct drm_device
*dev
= crtc
->dev
;
6394 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6395 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6396 int pipe
= intel_crtc
->pipe
;
6397 bool visible
= base
!= 0;
6399 if (intel_crtc
->cursor_visible
!= visible
) {
6400 uint32_t cntl
= I915_READ(CURCNTR(pipe
));
6402 cntl
&= ~(CURSOR_MODE
| MCURSOR_PIPE_SELECT
);
6403 cntl
|= CURSOR_MODE_64_ARGB_AX
| MCURSOR_GAMMA_ENABLE
;
6404 cntl
|= pipe
<< 28; /* Connect to correct pipe */
6406 cntl
&= ~(CURSOR_MODE
| MCURSOR_GAMMA_ENABLE
);
6407 cntl
|= CURSOR_MODE_DISABLE
;
6409 I915_WRITE(CURCNTR(pipe
), cntl
);
6411 intel_crtc
->cursor_visible
= visible
;
6413 /* and commit changes on next vblank */
6414 I915_WRITE(CURBASE(pipe
), base
);
6417 static void ivb_update_cursor(struct drm_crtc
*crtc
, u32 base
)
6419 struct drm_device
*dev
= crtc
->dev
;
6420 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6421 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6422 int pipe
= intel_crtc
->pipe
;
6423 bool visible
= base
!= 0;
6425 if (intel_crtc
->cursor_visible
!= visible
) {
6426 uint32_t cntl
= I915_READ(CURCNTR_IVB(pipe
));
6428 cntl
&= ~CURSOR_MODE
;
6429 cntl
|= CURSOR_MODE_64_ARGB_AX
| MCURSOR_GAMMA_ENABLE
;
6431 cntl
&= ~(CURSOR_MODE
| MCURSOR_GAMMA_ENABLE
);
6432 cntl
|= CURSOR_MODE_DISABLE
;
6434 if (IS_HASWELL(dev
))
6435 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
6436 I915_WRITE(CURCNTR_IVB(pipe
), cntl
);
6438 intel_crtc
->cursor_visible
= visible
;
6440 /* and commit changes on next vblank */
6441 I915_WRITE(CURBASE_IVB(pipe
), base
);
6444 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
6445 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
6448 struct drm_device
*dev
= crtc
->dev
;
6449 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6450 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6451 int pipe
= intel_crtc
->pipe
;
6452 int x
= intel_crtc
->cursor_x
;
6453 int y
= intel_crtc
->cursor_y
;
6459 if (on
&& crtc
->enabled
&& crtc
->fb
) {
6460 base
= intel_crtc
->cursor_addr
;
6461 if (x
> (int) crtc
->fb
->width
)
6464 if (y
> (int) crtc
->fb
->height
)
6470 if (x
+ intel_crtc
->cursor_width
< 0)
6473 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
6476 pos
|= x
<< CURSOR_X_SHIFT
;
6479 if (y
+ intel_crtc
->cursor_height
< 0)
6482 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
6485 pos
|= y
<< CURSOR_Y_SHIFT
;
6487 visible
= base
!= 0;
6488 if (!visible
&& !intel_crtc
->cursor_visible
)
6491 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
)) {
6492 I915_WRITE(CURPOS_IVB(pipe
), pos
);
6493 ivb_update_cursor(crtc
, base
);
6495 I915_WRITE(CURPOS(pipe
), pos
);
6496 if (IS_845G(dev
) || IS_I865G(dev
))
6497 i845_update_cursor(crtc
, base
);
6499 i9xx_update_cursor(crtc
, base
);
6503 static int intel_crtc_cursor_set(struct drm_crtc
*crtc
,
6504 struct drm_file
*file
,
6506 uint32_t width
, uint32_t height
)
6508 struct drm_device
*dev
= crtc
->dev
;
6509 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6510 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6511 struct drm_i915_gem_object
*obj
;
6515 /* if we want to turn off the cursor ignore width and height */
6517 DRM_DEBUG_KMS("cursor off\n");
6520 mutex_lock(&dev
->struct_mutex
);
6524 /* Currently we only support 64x64 cursors */
6525 if (width
!= 64 || height
!= 64) {
6526 DRM_ERROR("we currently only support 64x64 cursors\n");
6530 obj
= to_intel_bo(drm_gem_object_lookup(dev
, file
, handle
));
6531 if (&obj
->base
== NULL
)
6534 if (obj
->base
.size
< width
* height
* 4) {
6535 DRM_ERROR("buffer is to small\n");
6540 /* we only need to pin inside GTT if cursor is non-phy */
6541 mutex_lock(&dev
->struct_mutex
);
6542 if (!dev_priv
->info
->cursor_needs_physical
) {
6545 if (obj
->tiling_mode
) {
6546 DRM_ERROR("cursor cannot be tiled\n");
6551 /* Note that the w/a also requires 2 PTE of padding following
6552 * the bo. We currently fill all unused PTE with the shadow
6553 * page and so we should always have valid PTE following the
6554 * cursor preventing the VT-d warning.
6557 if (need_vtd_wa(dev
))
6558 alignment
= 64*1024;
6560 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, NULL
);
6562 DRM_ERROR("failed to move cursor bo into the GTT\n");
6566 ret
= i915_gem_object_put_fence(obj
);
6568 DRM_ERROR("failed to release fence for cursor");
6572 addr
= i915_gem_obj_ggtt_offset(obj
);
6574 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
6575 ret
= i915_gem_attach_phys_object(dev
, obj
,
6576 (intel_crtc
->pipe
== 0) ? I915_GEM_PHYS_CURSOR_0
: I915_GEM_PHYS_CURSOR_1
,
6579 DRM_ERROR("failed to attach phys object\n");
6582 addr
= obj
->phys_obj
->handle
->busaddr
;
6586 I915_WRITE(CURSIZE
, (height
<< 12) | width
);
6589 if (intel_crtc
->cursor_bo
) {
6590 if (dev_priv
->info
->cursor_needs_physical
) {
6591 if (intel_crtc
->cursor_bo
!= obj
)
6592 i915_gem_detach_phys_object(dev
, intel_crtc
->cursor_bo
);
6594 i915_gem_object_unpin(intel_crtc
->cursor_bo
);
6595 drm_gem_object_unreference(&intel_crtc
->cursor_bo
->base
);
6598 mutex_unlock(&dev
->struct_mutex
);
6600 intel_crtc
->cursor_addr
= addr
;
6601 intel_crtc
->cursor_bo
= obj
;
6602 intel_crtc
->cursor_width
= width
;
6603 intel_crtc
->cursor_height
= height
;
6605 intel_crtc_update_cursor(crtc
, intel_crtc
->cursor_bo
!= NULL
);
6609 i915_gem_object_unpin(obj
);
6611 mutex_unlock(&dev
->struct_mutex
);
6613 drm_gem_object_unreference_unlocked(&obj
->base
);
6617 static int intel_crtc_cursor_move(struct drm_crtc
*crtc
, int x
, int y
)
6619 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6621 intel_crtc
->cursor_x
= x
;
6622 intel_crtc
->cursor_y
= y
;
6624 intel_crtc_update_cursor(crtc
, intel_crtc
->cursor_bo
!= NULL
);
6629 /** Sets the color ramps on behalf of RandR */
6630 void intel_crtc_fb_gamma_set(struct drm_crtc
*crtc
, u16 red
, u16 green
,
6631 u16 blue
, int regno
)
6633 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6635 intel_crtc
->lut_r
[regno
] = red
>> 8;
6636 intel_crtc
->lut_g
[regno
] = green
>> 8;
6637 intel_crtc
->lut_b
[regno
] = blue
>> 8;
6640 void intel_crtc_fb_gamma_get(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
6641 u16
*blue
, int regno
)
6643 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6645 *red
= intel_crtc
->lut_r
[regno
] << 8;
6646 *green
= intel_crtc
->lut_g
[regno
] << 8;
6647 *blue
= intel_crtc
->lut_b
[regno
] << 8;
6650 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
6651 u16
*blue
, uint32_t start
, uint32_t size
)
6653 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
6654 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6656 for (i
= start
; i
< end
; i
++) {
6657 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
6658 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
6659 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
6662 intel_crtc_load_lut(crtc
);
6665 /* VESA 640x480x72Hz mode to set on the pipe */
6666 static struct drm_display_mode load_detect_mode
= {
6667 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
6668 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
6671 static struct drm_framebuffer
*
6672 intel_framebuffer_create(struct drm_device
*dev
,
6673 struct drm_mode_fb_cmd2
*mode_cmd
,
6674 struct drm_i915_gem_object
*obj
)
6676 struct intel_framebuffer
*intel_fb
;
6679 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
6681 drm_gem_object_unreference_unlocked(&obj
->base
);
6682 return ERR_PTR(-ENOMEM
);
6685 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
6687 drm_gem_object_unreference_unlocked(&obj
->base
);
6689 return ERR_PTR(ret
);
6692 return &intel_fb
->base
;
6696 intel_framebuffer_pitch_for_width(int width
, int bpp
)
6698 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
6699 return ALIGN(pitch
, 64);
6703 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
6705 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
6706 return ALIGN(pitch
* mode
->vdisplay
, PAGE_SIZE
);
6709 static struct drm_framebuffer
*
6710 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
6711 struct drm_display_mode
*mode
,
6714 struct drm_i915_gem_object
*obj
;
6715 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
6717 obj
= i915_gem_alloc_object(dev
,
6718 intel_framebuffer_size_for_mode(mode
, bpp
));
6720 return ERR_PTR(-ENOMEM
);
6722 mode_cmd
.width
= mode
->hdisplay
;
6723 mode_cmd
.height
= mode
->vdisplay
;
6724 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
6726 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
6728 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
6731 static struct drm_framebuffer
*
6732 mode_fits_in_fbdev(struct drm_device
*dev
,
6733 struct drm_display_mode
*mode
)
6735 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6736 struct drm_i915_gem_object
*obj
;
6737 struct drm_framebuffer
*fb
;
6739 if (dev_priv
->fbdev
== NULL
)
6742 obj
= dev_priv
->fbdev
->ifb
.obj
;
6746 fb
= &dev_priv
->fbdev
->ifb
.base
;
6747 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
6748 fb
->bits_per_pixel
))
6751 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
6757 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
6758 struct drm_display_mode
*mode
,
6759 struct intel_load_detect_pipe
*old
)
6761 struct intel_crtc
*intel_crtc
;
6762 struct intel_encoder
*intel_encoder
=
6763 intel_attached_encoder(connector
);
6764 struct drm_crtc
*possible_crtc
;
6765 struct drm_encoder
*encoder
= &intel_encoder
->base
;
6766 struct drm_crtc
*crtc
= NULL
;
6767 struct drm_device
*dev
= encoder
->dev
;
6768 struct drm_framebuffer
*fb
;
6771 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6772 connector
->base
.id
, drm_get_connector_name(connector
),
6773 encoder
->base
.id
, drm_get_encoder_name(encoder
));
6776 * Algorithm gets a little messy:
6778 * - if the connector already has an assigned crtc, use it (but make
6779 * sure it's on first)
6781 * - try to find the first unused crtc that can drive this connector,
6782 * and use that if we find one
6785 /* See if we already have a CRTC for this connector */
6786 if (encoder
->crtc
) {
6787 crtc
= encoder
->crtc
;
6789 mutex_lock(&crtc
->mutex
);
6791 old
->dpms_mode
= connector
->dpms
;
6792 old
->load_detect_temp
= false;
6794 /* Make sure the crtc and connector are running */
6795 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
6796 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
6801 /* Find an unused one (if possible) */
6802 list_for_each_entry(possible_crtc
, &dev
->mode_config
.crtc_list
, head
) {
6804 if (!(encoder
->possible_crtcs
& (1 << i
)))
6806 if (!possible_crtc
->enabled
) {
6807 crtc
= possible_crtc
;
6813 * If we didn't find an unused CRTC, don't use any.
6816 DRM_DEBUG_KMS("no pipe available for load-detect\n");
6820 mutex_lock(&crtc
->mutex
);
6821 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
6822 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
6824 intel_crtc
= to_intel_crtc(crtc
);
6825 old
->dpms_mode
= connector
->dpms
;
6826 old
->load_detect_temp
= true;
6827 old
->release_fb
= NULL
;
6830 mode
= &load_detect_mode
;
6832 /* We need a framebuffer large enough to accommodate all accesses
6833 * that the plane may generate whilst we perform load detection.
6834 * We can not rely on the fbcon either being present (we get called
6835 * during its initialisation to detect all boot displays, or it may
6836 * not even exist) or that it is large enough to satisfy the
6839 fb
= mode_fits_in_fbdev(dev
, mode
);
6841 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
6842 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
6843 old
->release_fb
= fb
;
6845 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
6847 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
6848 mutex_unlock(&crtc
->mutex
);
6852 if (intel_set_mode(crtc
, mode
, 0, 0, fb
)) {
6853 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
6854 if (old
->release_fb
)
6855 old
->release_fb
->funcs
->destroy(old
->release_fb
);
6856 mutex_unlock(&crtc
->mutex
);
6860 /* let the connector get through one full cycle before testing */
6861 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
6865 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
6866 struct intel_load_detect_pipe
*old
)
6868 struct intel_encoder
*intel_encoder
=
6869 intel_attached_encoder(connector
);
6870 struct drm_encoder
*encoder
= &intel_encoder
->base
;
6871 struct drm_crtc
*crtc
= encoder
->crtc
;
6873 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6874 connector
->base
.id
, drm_get_connector_name(connector
),
6875 encoder
->base
.id
, drm_get_encoder_name(encoder
));
6877 if (old
->load_detect_temp
) {
6878 to_intel_connector(connector
)->new_encoder
= NULL
;
6879 intel_encoder
->new_crtc
= NULL
;
6880 intel_set_mode(crtc
, NULL
, 0, 0, NULL
);
6882 if (old
->release_fb
) {
6883 drm_framebuffer_unregister_private(old
->release_fb
);
6884 drm_framebuffer_unreference(old
->release_fb
);
6887 mutex_unlock(&crtc
->mutex
);
6891 /* Switch crtc and encoder back off if necessary */
6892 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
6893 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
6895 mutex_unlock(&crtc
->mutex
);
6898 /* Returns the clock of the currently programmed mode of the given pipe. */
6899 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
6900 struct intel_crtc_config
*pipe_config
)
6902 struct drm_device
*dev
= crtc
->base
.dev
;
6903 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6904 int pipe
= pipe_config
->cpu_transcoder
;
6905 u32 dpll
= I915_READ(DPLL(pipe
));
6907 intel_clock_t clock
;
6909 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
6910 fp
= I915_READ(FP0(pipe
));
6912 fp
= I915_READ(FP1(pipe
));
6914 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
6915 if (IS_PINEVIEW(dev
)) {
6916 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
6917 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
6919 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
6920 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
6923 if (!IS_GEN2(dev
)) {
6924 if (IS_PINEVIEW(dev
))
6925 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
6926 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
6928 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
6929 DPLL_FPA01_P1_POST_DIV_SHIFT
);
6931 switch (dpll
& DPLL_MODE_MASK
) {
6932 case DPLLB_MODE_DAC_SERIAL
:
6933 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
6936 case DPLLB_MODE_LVDS
:
6937 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
6941 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
6942 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
6943 pipe_config
->adjusted_mode
.clock
= 0;
6947 if (IS_PINEVIEW(dev
))
6948 pineview_clock(96000, &clock
);
6950 i9xx_clock(96000, &clock
);
6952 bool is_lvds
= (pipe
== 1) && (I915_READ(LVDS
) & LVDS_PORT_EN
);
6955 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
6956 DPLL_FPA01_P1_POST_DIV_SHIFT
);
6959 if ((dpll
& PLL_REF_INPUT_MASK
) ==
6960 PLLB_REF_INPUT_SPREADSPECTRUMIN
) {
6961 /* XXX: might not be 66MHz */
6962 i9xx_clock(66000, &clock
);
6964 i9xx_clock(48000, &clock
);
6966 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
6969 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
6970 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
6972 if (dpll
& PLL_P2_DIVIDE_BY_4
)
6977 i9xx_clock(48000, &clock
);
6981 pipe_config
->adjusted_mode
.clock
= clock
.dot
*
6982 pipe_config
->pixel_multiplier
;
6985 static void ironlake_crtc_clock_get(struct intel_crtc
*crtc
,
6986 struct intel_crtc_config
*pipe_config
)
6988 struct drm_device
*dev
= crtc
->base
.dev
;
6989 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6990 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
6991 int link_freq
, repeat
;
6995 repeat
= pipe_config
->pixel_multiplier
;
6998 * The calculation for the data clock is:
6999 * pixel_clock = ((m/n)*(link_clock * nr_lanes * repeat))/bpp
7000 * But we want to avoid losing precison if possible, so:
7001 * pixel_clock = ((m * link_clock * nr_lanes * repeat)/(n*bpp))
7003 * and the link clock is simpler:
7004 * link_clock = (m * link_clock * repeat) / n
7008 * We need to get the FDI or DP link clock here to derive
7011 * For FDI, we read it from the BIOS or use a fixed 2.7GHz.
7012 * For DP, it's either 1.62GHz or 2.7GHz.
7013 * We do our calculations in 10*MHz since we don't need much precison.
7015 if (pipe_config
->has_pch_encoder
)
7016 link_freq
= intel_fdi_link_freq(dev
) * 10000;
7018 link_freq
= pipe_config
->port_clock
;
7020 link_m
= I915_READ(PIPE_LINK_M1(cpu_transcoder
));
7021 link_n
= I915_READ(PIPE_LINK_N1(cpu_transcoder
));
7023 if (!link_m
|| !link_n
)
7026 clock
= ((u64
)link_m
* (u64
)link_freq
* (u64
)repeat
);
7027 do_div(clock
, link_n
);
7029 pipe_config
->adjusted_mode
.clock
= clock
;
7032 /** Returns the currently programmed mode of the given pipe. */
7033 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
7034 struct drm_crtc
*crtc
)
7036 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7037 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7038 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
7039 struct drm_display_mode
*mode
;
7040 struct intel_crtc_config pipe_config
;
7041 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
7042 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
7043 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
7044 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
7046 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
7051 * Construct a pipe_config sufficient for getting the clock info
7052 * back out of crtc_clock_get.
7054 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
7055 * to use a real value here instead.
7057 pipe_config
.cpu_transcoder
= (enum transcoder
) intel_crtc
->pipe
;
7058 pipe_config
.pixel_multiplier
= 1;
7059 i9xx_crtc_clock_get(intel_crtc
, &pipe_config
);
7061 mode
->clock
= pipe_config
.adjusted_mode
.clock
;
7062 mode
->hdisplay
= (htot
& 0xffff) + 1;
7063 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
7064 mode
->hsync_start
= (hsync
& 0xffff) + 1;
7065 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
7066 mode
->vdisplay
= (vtot
& 0xffff) + 1;
7067 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
7068 mode
->vsync_start
= (vsync
& 0xffff) + 1;
7069 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
7071 drm_mode_set_name(mode
);
7076 static void intel_increase_pllclock(struct drm_crtc
*crtc
)
7078 struct drm_device
*dev
= crtc
->dev
;
7079 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7080 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7081 int pipe
= intel_crtc
->pipe
;
7082 int dpll_reg
= DPLL(pipe
);
7085 if (HAS_PCH_SPLIT(dev
))
7088 if (!dev_priv
->lvds_downclock_avail
)
7091 dpll
= I915_READ(dpll_reg
);
7092 if (!HAS_PIPE_CXSR(dev
) && (dpll
& DISPLAY_RATE_SELECT_FPA1
)) {
7093 DRM_DEBUG_DRIVER("upclocking LVDS\n");
7095 assert_panel_unlocked(dev_priv
, pipe
);
7097 dpll
&= ~DISPLAY_RATE_SELECT_FPA1
;
7098 I915_WRITE(dpll_reg
, dpll
);
7099 intel_wait_for_vblank(dev
, pipe
);
7101 dpll
= I915_READ(dpll_reg
);
7102 if (dpll
& DISPLAY_RATE_SELECT_FPA1
)
7103 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
7107 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
7109 struct drm_device
*dev
= crtc
->dev
;
7110 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7111 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7113 if (HAS_PCH_SPLIT(dev
))
7116 if (!dev_priv
->lvds_downclock_avail
)
7120 * Since this is called by a timer, we should never get here in
7123 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
7124 int pipe
= intel_crtc
->pipe
;
7125 int dpll_reg
= DPLL(pipe
);
7128 DRM_DEBUG_DRIVER("downclocking LVDS\n");
7130 assert_panel_unlocked(dev_priv
, pipe
);
7132 dpll
= I915_READ(dpll_reg
);
7133 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
7134 I915_WRITE(dpll_reg
, dpll
);
7135 intel_wait_for_vblank(dev
, pipe
);
7136 dpll
= I915_READ(dpll_reg
);
7137 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
7138 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
7143 void intel_mark_busy(struct drm_device
*dev
)
7145 i915_update_gfx_val(dev
->dev_private
);
7148 void intel_mark_idle(struct drm_device
*dev
)
7150 struct drm_crtc
*crtc
;
7152 if (!i915_powersave
)
7155 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
7159 intel_decrease_pllclock(crtc
);
7163 void intel_mark_fb_busy(struct drm_i915_gem_object
*obj
,
7164 struct intel_ring_buffer
*ring
)
7166 struct drm_device
*dev
= obj
->base
.dev
;
7167 struct drm_crtc
*crtc
;
7169 if (!i915_powersave
)
7172 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
7176 if (to_intel_framebuffer(crtc
->fb
)->obj
!= obj
)
7179 intel_increase_pllclock(crtc
);
7180 if (ring
&& intel_fbc_enabled(dev
))
7181 ring
->fbc_dirty
= true;
7185 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
7187 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7188 struct drm_device
*dev
= crtc
->dev
;
7189 struct intel_unpin_work
*work
;
7190 unsigned long flags
;
7192 spin_lock_irqsave(&dev
->event_lock
, flags
);
7193 work
= intel_crtc
->unpin_work
;
7194 intel_crtc
->unpin_work
= NULL
;
7195 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7198 cancel_work_sync(&work
->work
);
7202 intel_crtc_cursor_set(crtc
, NULL
, 0, 0, 0);
7204 drm_crtc_cleanup(crtc
);
7209 static void intel_unpin_work_fn(struct work_struct
*__work
)
7211 struct intel_unpin_work
*work
=
7212 container_of(__work
, struct intel_unpin_work
, work
);
7213 struct drm_device
*dev
= work
->crtc
->dev
;
7215 mutex_lock(&dev
->struct_mutex
);
7216 intel_unpin_fb_obj(work
->old_fb_obj
);
7217 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
7218 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
7220 intel_update_fbc(dev
);
7221 mutex_unlock(&dev
->struct_mutex
);
7223 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
7224 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
7229 static void do_intel_finish_page_flip(struct drm_device
*dev
,
7230 struct drm_crtc
*crtc
)
7232 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7233 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7234 struct intel_unpin_work
*work
;
7235 unsigned long flags
;
7237 /* Ignore early vblank irqs */
7238 if (intel_crtc
== NULL
)
7241 spin_lock_irqsave(&dev
->event_lock
, flags
);
7242 work
= intel_crtc
->unpin_work
;
7244 /* Ensure we don't miss a work->pending update ... */
7247 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
7248 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7252 /* and that the unpin work is consistent wrt ->pending. */
7255 intel_crtc
->unpin_work
= NULL
;
7258 drm_send_vblank_event(dev
, intel_crtc
->pipe
, work
->event
);
7260 drm_vblank_put(dev
, intel_crtc
->pipe
);
7262 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7264 wake_up_all(&dev_priv
->pending_flip_queue
);
7266 queue_work(dev_priv
->wq
, &work
->work
);
7268 trace_i915_flip_complete(intel_crtc
->plane
, work
->pending_flip_obj
);
7271 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
7273 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7274 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
7276 do_intel_finish_page_flip(dev
, crtc
);
7279 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
7281 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7282 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
7284 do_intel_finish_page_flip(dev
, crtc
);
7287 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
7289 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7290 struct intel_crtc
*intel_crtc
=
7291 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
7292 unsigned long flags
;
7294 /* NB: An MMIO update of the plane base pointer will also
7295 * generate a page-flip completion irq, i.e. every modeset
7296 * is also accompanied by a spurious intel_prepare_page_flip().
7298 spin_lock_irqsave(&dev
->event_lock
, flags
);
7299 if (intel_crtc
->unpin_work
)
7300 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
7301 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7304 inline static void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
7306 /* Ensure that the work item is consistent when activating it ... */
7308 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
7309 /* and that it is marked active as soon as the irq could fire. */
7313 static int intel_gen2_queue_flip(struct drm_device
*dev
,
7314 struct drm_crtc
*crtc
,
7315 struct drm_framebuffer
*fb
,
7316 struct drm_i915_gem_object
*obj
)
7318 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7319 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7321 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7324 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7328 ret
= intel_ring_begin(ring
, 6);
7332 /* Can't queue multiple flips, so wait for the previous
7333 * one to finish before executing the next.
7335 if (intel_crtc
->plane
)
7336 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
7338 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
7339 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
7340 intel_ring_emit(ring
, MI_NOOP
);
7341 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
7342 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7343 intel_ring_emit(ring
, fb
->pitches
[0]);
7344 intel_ring_emit(ring
, i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
7345 intel_ring_emit(ring
, 0); /* aux display base address, unused */
7347 intel_mark_page_flip_active(intel_crtc
);
7348 intel_ring_advance(ring
);
7352 intel_unpin_fb_obj(obj
);
7357 static int intel_gen3_queue_flip(struct drm_device
*dev
,
7358 struct drm_crtc
*crtc
,
7359 struct drm_framebuffer
*fb
,
7360 struct drm_i915_gem_object
*obj
)
7362 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7363 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7365 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7368 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7372 ret
= intel_ring_begin(ring
, 6);
7376 if (intel_crtc
->plane
)
7377 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
7379 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
7380 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
7381 intel_ring_emit(ring
, MI_NOOP
);
7382 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
7383 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7384 intel_ring_emit(ring
, fb
->pitches
[0]);
7385 intel_ring_emit(ring
, i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
7386 intel_ring_emit(ring
, MI_NOOP
);
7388 intel_mark_page_flip_active(intel_crtc
);
7389 intel_ring_advance(ring
);
7393 intel_unpin_fb_obj(obj
);
7398 static int intel_gen4_queue_flip(struct drm_device
*dev
,
7399 struct drm_crtc
*crtc
,
7400 struct drm_framebuffer
*fb
,
7401 struct drm_i915_gem_object
*obj
)
7403 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7404 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7405 uint32_t pf
, pipesrc
;
7406 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7409 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7413 ret
= intel_ring_begin(ring
, 4);
7417 /* i965+ uses the linear or tiled offsets from the
7418 * Display Registers (which do not change across a page-flip)
7419 * so we need only reprogram the base address.
7421 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
7422 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7423 intel_ring_emit(ring
, fb
->pitches
[0]);
7424 intel_ring_emit(ring
,
7425 (i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
) |
7428 /* XXX Enabling the panel-fitter across page-flip is so far
7429 * untested on non-native modes, so ignore it for now.
7430 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
7433 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
7434 intel_ring_emit(ring
, pf
| pipesrc
);
7436 intel_mark_page_flip_active(intel_crtc
);
7437 intel_ring_advance(ring
);
7441 intel_unpin_fb_obj(obj
);
7446 static int intel_gen6_queue_flip(struct drm_device
*dev
,
7447 struct drm_crtc
*crtc
,
7448 struct drm_framebuffer
*fb
,
7449 struct drm_i915_gem_object
*obj
)
7451 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7452 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7453 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7454 uint32_t pf
, pipesrc
;
7457 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7461 ret
= intel_ring_begin(ring
, 4);
7465 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
7466 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7467 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
7468 intel_ring_emit(ring
, i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
7470 /* Contrary to the suggestions in the documentation,
7471 * "Enable Panel Fitter" does not seem to be required when page
7472 * flipping with a non-native mode, and worse causes a normal
7474 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
7477 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
7478 intel_ring_emit(ring
, pf
| pipesrc
);
7480 intel_mark_page_flip_active(intel_crtc
);
7481 intel_ring_advance(ring
);
7485 intel_unpin_fb_obj(obj
);
7491 * On gen7 we currently use the blit ring because (in early silicon at least)
7492 * the render ring doesn't give us interrpts for page flip completion, which
7493 * means clients will hang after the first flip is queued. Fortunately the
7494 * blit ring generates interrupts properly, so use it instead.
7496 static int intel_gen7_queue_flip(struct drm_device
*dev
,
7497 struct drm_crtc
*crtc
,
7498 struct drm_framebuffer
*fb
,
7499 struct drm_i915_gem_object
*obj
)
7501 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7502 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7503 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[BCS
];
7504 uint32_t plane_bit
= 0;
7507 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7511 switch(intel_crtc
->plane
) {
7513 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
7516 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
7519 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
7522 WARN_ONCE(1, "unknown plane in flip command\n");
7527 ret
= intel_ring_begin(ring
, 4);
7531 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
7532 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
7533 intel_ring_emit(ring
, i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
7534 intel_ring_emit(ring
, (MI_NOOP
));
7536 intel_mark_page_flip_active(intel_crtc
);
7537 intel_ring_advance(ring
);
7541 intel_unpin_fb_obj(obj
);
7546 static int intel_default_queue_flip(struct drm_device
*dev
,
7547 struct drm_crtc
*crtc
,
7548 struct drm_framebuffer
*fb
,
7549 struct drm_i915_gem_object
*obj
)
7554 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
7555 struct drm_framebuffer
*fb
,
7556 struct drm_pending_vblank_event
*event
)
7558 struct drm_device
*dev
= crtc
->dev
;
7559 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7560 struct drm_framebuffer
*old_fb
= crtc
->fb
;
7561 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(fb
)->obj
;
7562 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7563 struct intel_unpin_work
*work
;
7564 unsigned long flags
;
7567 /* Can't change pixel format via MI display flips. */
7568 if (fb
->pixel_format
!= crtc
->fb
->pixel_format
)
7572 * TILEOFF/LINOFF registers can't be changed via MI display flips.
7573 * Note that pitch changes could also affect these register.
7575 if (INTEL_INFO(dev
)->gen
> 3 &&
7576 (fb
->offsets
[0] != crtc
->fb
->offsets
[0] ||
7577 fb
->pitches
[0] != crtc
->fb
->pitches
[0]))
7580 work
= kzalloc(sizeof *work
, GFP_KERNEL
);
7584 work
->event
= event
;
7586 work
->old_fb_obj
= to_intel_framebuffer(old_fb
)->obj
;
7587 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
7589 ret
= drm_vblank_get(dev
, intel_crtc
->pipe
);
7593 /* We borrow the event spin lock for protecting unpin_work */
7594 spin_lock_irqsave(&dev
->event_lock
, flags
);
7595 if (intel_crtc
->unpin_work
) {
7596 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7598 drm_vblank_put(dev
, intel_crtc
->pipe
);
7600 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
7603 intel_crtc
->unpin_work
= work
;
7604 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7606 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
7607 flush_workqueue(dev_priv
->wq
);
7609 ret
= i915_mutex_lock_interruptible(dev
);
7613 /* Reference the objects for the scheduled work. */
7614 drm_gem_object_reference(&work
->old_fb_obj
->base
);
7615 drm_gem_object_reference(&obj
->base
);
7619 work
->pending_flip_obj
= obj
;
7621 work
->enable_stall_check
= true;
7623 atomic_inc(&intel_crtc
->unpin_work_count
);
7624 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
7626 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
);
7628 goto cleanup_pending
;
7630 intel_disable_fbc(dev
);
7631 intel_mark_fb_busy(obj
, NULL
);
7632 mutex_unlock(&dev
->struct_mutex
);
7634 trace_i915_flip_request(intel_crtc
->plane
, obj
);
7639 atomic_dec(&intel_crtc
->unpin_work_count
);
7641 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
7642 drm_gem_object_unreference(&obj
->base
);
7643 mutex_unlock(&dev
->struct_mutex
);
7646 spin_lock_irqsave(&dev
->event_lock
, flags
);
7647 intel_crtc
->unpin_work
= NULL
;
7648 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7650 drm_vblank_put(dev
, intel_crtc
->pipe
);
7657 static struct drm_crtc_helper_funcs intel_helper_funcs
= {
7658 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
7659 .load_lut
= intel_crtc_load_lut
,
7662 static bool intel_encoder_crtc_ok(struct drm_encoder
*encoder
,
7663 struct drm_crtc
*crtc
)
7665 struct drm_device
*dev
;
7666 struct drm_crtc
*tmp
;
7669 WARN(!crtc
, "checking null crtc?\n");
7673 list_for_each_entry(tmp
, &dev
->mode_config
.crtc_list
, head
) {
7679 if (encoder
->possible_crtcs
& crtc_mask
)
7685 * intel_modeset_update_staged_output_state
7687 * Updates the staged output configuration state, e.g. after we've read out the
7690 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
7692 struct intel_encoder
*encoder
;
7693 struct intel_connector
*connector
;
7695 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7697 connector
->new_encoder
=
7698 to_intel_encoder(connector
->base
.encoder
);
7701 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7704 to_intel_crtc(encoder
->base
.crtc
);
7709 * intel_modeset_commit_output_state
7711 * This function copies the stage display pipe configuration to the real one.
7713 static void intel_modeset_commit_output_state(struct drm_device
*dev
)
7715 struct intel_encoder
*encoder
;
7716 struct intel_connector
*connector
;
7718 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7720 connector
->base
.encoder
= &connector
->new_encoder
->base
;
7723 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7725 encoder
->base
.crtc
= &encoder
->new_crtc
->base
;
7730 connected_sink_compute_bpp(struct intel_connector
* connector
,
7731 struct intel_crtc_config
*pipe_config
)
7733 int bpp
= pipe_config
->pipe_bpp
;
7735 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
7736 connector
->base
.base
.id
,
7737 drm_get_connector_name(&connector
->base
));
7739 /* Don't use an invalid EDID bpc value */
7740 if (connector
->base
.display_info
.bpc
&&
7741 connector
->base
.display_info
.bpc
* 3 < bpp
) {
7742 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
7743 bpp
, connector
->base
.display_info
.bpc
*3);
7744 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
7747 /* Clamp bpp to 8 on screens without EDID 1.4 */
7748 if (connector
->base
.display_info
.bpc
== 0 && bpp
> 24) {
7749 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
7751 pipe_config
->pipe_bpp
= 24;
7756 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
7757 struct drm_framebuffer
*fb
,
7758 struct intel_crtc_config
*pipe_config
)
7760 struct drm_device
*dev
= crtc
->base
.dev
;
7761 struct intel_connector
*connector
;
7764 switch (fb
->pixel_format
) {
7766 bpp
= 8*3; /* since we go through a colormap */
7768 case DRM_FORMAT_XRGB1555
:
7769 case DRM_FORMAT_ARGB1555
:
7770 /* checked in intel_framebuffer_init already */
7771 if (WARN_ON(INTEL_INFO(dev
)->gen
> 3))
7773 case DRM_FORMAT_RGB565
:
7774 bpp
= 6*3; /* min is 18bpp */
7776 case DRM_FORMAT_XBGR8888
:
7777 case DRM_FORMAT_ABGR8888
:
7778 /* checked in intel_framebuffer_init already */
7779 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
7781 case DRM_FORMAT_XRGB8888
:
7782 case DRM_FORMAT_ARGB8888
:
7785 case DRM_FORMAT_XRGB2101010
:
7786 case DRM_FORMAT_ARGB2101010
:
7787 case DRM_FORMAT_XBGR2101010
:
7788 case DRM_FORMAT_ABGR2101010
:
7789 /* checked in intel_framebuffer_init already */
7790 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
7794 /* TODO: gen4+ supports 16 bpc floating point, too. */
7796 DRM_DEBUG_KMS("unsupported depth\n");
7800 pipe_config
->pipe_bpp
= bpp
;
7802 /* Clamp display bpp to EDID value */
7803 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7805 if (!connector
->new_encoder
||
7806 connector
->new_encoder
->new_crtc
!= crtc
)
7809 connected_sink_compute_bpp(connector
, pipe_config
);
7815 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
7816 struct intel_crtc_config
*pipe_config
,
7817 const char *context
)
7819 DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc
->base
.base
.id
,
7820 context
, pipe_name(crtc
->pipe
));
7822 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config
->cpu_transcoder
));
7823 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
7824 pipe_config
->pipe_bpp
, pipe_config
->dither
);
7825 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
7826 pipe_config
->has_pch_encoder
,
7827 pipe_config
->fdi_lanes
,
7828 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
7829 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
7830 pipe_config
->fdi_m_n
.tu
);
7831 DRM_DEBUG_KMS("requested mode:\n");
7832 drm_mode_debug_printmodeline(&pipe_config
->requested_mode
);
7833 DRM_DEBUG_KMS("adjusted mode:\n");
7834 drm_mode_debug_printmodeline(&pipe_config
->adjusted_mode
);
7835 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
7836 pipe_config
->gmch_pfit
.control
,
7837 pipe_config
->gmch_pfit
.pgm_ratios
,
7838 pipe_config
->gmch_pfit
.lvds_border_bits
);
7839 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x\n",
7840 pipe_config
->pch_pfit
.pos
,
7841 pipe_config
->pch_pfit
.size
);
7842 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
7845 static bool check_encoder_cloning(struct drm_crtc
*crtc
)
7847 int num_encoders
= 0;
7848 bool uncloneable_encoders
= false;
7849 struct intel_encoder
*encoder
;
7851 list_for_each_entry(encoder
, &crtc
->dev
->mode_config
.encoder_list
,
7853 if (&encoder
->new_crtc
->base
!= crtc
)
7857 if (!encoder
->cloneable
)
7858 uncloneable_encoders
= true;
7861 return !(num_encoders
> 1 && uncloneable_encoders
);
7864 static struct intel_crtc_config
*
7865 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
7866 struct drm_framebuffer
*fb
,
7867 struct drm_display_mode
*mode
)
7869 struct drm_device
*dev
= crtc
->dev
;
7870 struct drm_encoder_helper_funcs
*encoder_funcs
;
7871 struct intel_encoder
*encoder
;
7872 struct intel_crtc_config
*pipe_config
;
7873 int plane_bpp
, ret
= -EINVAL
;
7876 if (!check_encoder_cloning(crtc
)) {
7877 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
7878 return ERR_PTR(-EINVAL
);
7881 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
7883 return ERR_PTR(-ENOMEM
);
7885 drm_mode_copy(&pipe_config
->adjusted_mode
, mode
);
7886 drm_mode_copy(&pipe_config
->requested_mode
, mode
);
7887 pipe_config
->cpu_transcoder
=
7888 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
7889 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7891 /* Compute a starting value for pipe_config->pipe_bpp taking the source
7892 * plane pixel format and any sink constraints into account. Returns the
7893 * source plane bpp so that dithering can be selected on mismatches
7894 * after encoders and crtc also have had their say. */
7895 plane_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
7901 /* Ensure the port clock defaults are reset when retrying. */
7902 pipe_config
->port_clock
= 0;
7903 pipe_config
->pixel_multiplier
= 1;
7905 /* Pass our mode to the connectors and the CRTC to give them a chance to
7906 * adjust it according to limitations or connector properties, and also
7907 * a chance to reject the mode entirely.
7909 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7912 if (&encoder
->new_crtc
->base
!= crtc
)
7915 if (encoder
->compute_config
) {
7916 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
7917 DRM_DEBUG_KMS("Encoder config failure\n");
7924 encoder_funcs
= encoder
->base
.helper_private
;
7925 if (!(encoder_funcs
->mode_fixup(&encoder
->base
,
7926 &pipe_config
->requested_mode
,
7927 &pipe_config
->adjusted_mode
))) {
7928 DRM_DEBUG_KMS("Encoder fixup failed\n");
7933 /* Set default port clock if not overwritten by the encoder. Needs to be
7934 * done afterwards in case the encoder adjusts the mode. */
7935 if (!pipe_config
->port_clock
)
7936 pipe_config
->port_clock
= pipe_config
->adjusted_mode
.clock
;
7938 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
7940 DRM_DEBUG_KMS("CRTC fixup failed\n");
7945 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
7950 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
7955 pipe_config
->dither
= pipe_config
->pipe_bpp
!= plane_bpp
;
7956 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
7957 plane_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
7962 return ERR_PTR(ret
);
7965 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
7966 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
7968 intel_modeset_affected_pipes(struct drm_crtc
*crtc
, unsigned *modeset_pipes
,
7969 unsigned *prepare_pipes
, unsigned *disable_pipes
)
7971 struct intel_crtc
*intel_crtc
;
7972 struct drm_device
*dev
= crtc
->dev
;
7973 struct intel_encoder
*encoder
;
7974 struct intel_connector
*connector
;
7975 struct drm_crtc
*tmp_crtc
;
7977 *disable_pipes
= *modeset_pipes
= *prepare_pipes
= 0;
7979 /* Check which crtcs have changed outputs connected to them, these need
7980 * to be part of the prepare_pipes mask. We don't (yet) support global
7981 * modeset across multiple crtcs, so modeset_pipes will only have one
7982 * bit set at most. */
7983 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7985 if (connector
->base
.encoder
== &connector
->new_encoder
->base
)
7988 if (connector
->base
.encoder
) {
7989 tmp_crtc
= connector
->base
.encoder
->crtc
;
7991 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
7994 if (connector
->new_encoder
)
7996 1 << connector
->new_encoder
->new_crtc
->pipe
;
7999 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
8001 if (encoder
->base
.crtc
== &encoder
->new_crtc
->base
)
8004 if (encoder
->base
.crtc
) {
8005 tmp_crtc
= encoder
->base
.crtc
;
8007 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
8010 if (encoder
->new_crtc
)
8011 *prepare_pipes
|= 1 << encoder
->new_crtc
->pipe
;
8014 /* Check for any pipes that will be fully disabled ... */
8015 list_for_each_entry(intel_crtc
, &dev
->mode_config
.crtc_list
,
8019 /* Don't try to disable disabled crtcs. */
8020 if (!intel_crtc
->base
.enabled
)
8023 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
8025 if (encoder
->new_crtc
== intel_crtc
)
8030 *disable_pipes
|= 1 << intel_crtc
->pipe
;
8034 /* set_mode is also used to update properties on life display pipes. */
8035 intel_crtc
= to_intel_crtc(crtc
);
8037 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
8040 * For simplicity do a full modeset on any pipe where the output routing
8041 * changed. We could be more clever, but that would require us to be
8042 * more careful with calling the relevant encoder->mode_set functions.
8045 *modeset_pipes
= *prepare_pipes
;
8047 /* ... and mask these out. */
8048 *modeset_pipes
&= ~(*disable_pipes
);
8049 *prepare_pipes
&= ~(*disable_pipes
);
8052 * HACK: We don't (yet) fully support global modesets. intel_set_config
8053 * obies this rule, but the modeset restore mode of
8054 * intel_modeset_setup_hw_state does not.
8056 *modeset_pipes
&= 1 << intel_crtc
->pipe
;
8057 *prepare_pipes
&= 1 << intel_crtc
->pipe
;
8059 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
8060 *modeset_pipes
, *prepare_pipes
, *disable_pipes
);
8063 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
8065 struct drm_encoder
*encoder
;
8066 struct drm_device
*dev
= crtc
->dev
;
8068 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
8069 if (encoder
->crtc
== crtc
)
8076 intel_modeset_update_state(struct drm_device
*dev
, unsigned prepare_pipes
)
8078 struct intel_encoder
*intel_encoder
;
8079 struct intel_crtc
*intel_crtc
;
8080 struct drm_connector
*connector
;
8082 list_for_each_entry(intel_encoder
, &dev
->mode_config
.encoder_list
,
8084 if (!intel_encoder
->base
.crtc
)
8087 intel_crtc
= to_intel_crtc(intel_encoder
->base
.crtc
);
8089 if (prepare_pipes
& (1 << intel_crtc
->pipe
))
8090 intel_encoder
->connectors_active
= false;
8093 intel_modeset_commit_output_state(dev
);
8095 /* Update computed state. */
8096 list_for_each_entry(intel_crtc
, &dev
->mode_config
.crtc_list
,
8098 intel_crtc
->base
.enabled
= intel_crtc_in_use(&intel_crtc
->base
);
8101 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
8102 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
8105 intel_crtc
= to_intel_crtc(connector
->encoder
->crtc
);
8107 if (prepare_pipes
& (1 << intel_crtc
->pipe
)) {
8108 struct drm_property
*dpms_property
=
8109 dev
->mode_config
.dpms_property
;
8111 connector
->dpms
= DRM_MODE_DPMS_ON
;
8112 drm_object_property_set_value(&connector
->base
,
8116 intel_encoder
= to_intel_encoder(connector
->encoder
);
8117 intel_encoder
->connectors_active
= true;
8123 static bool intel_fuzzy_clock_check(struct intel_crtc_config
*cur
,
8124 struct intel_crtc_config
*new)
8126 int clock1
, clock2
, diff
;
8128 clock1
= cur
->adjusted_mode
.clock
;
8129 clock2
= new->adjusted_mode
.clock
;
8131 if (clock1
== clock2
)
8134 if (!clock1
|| !clock2
)
8137 diff
= abs(clock1
- clock2
);
8139 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
8145 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
8146 list_for_each_entry((intel_crtc), \
8147 &(dev)->mode_config.crtc_list, \
8149 if (mask & (1 <<(intel_crtc)->pipe))
8152 intel_pipe_config_compare(struct drm_device
*dev
,
8153 struct intel_crtc_config
*current_config
,
8154 struct intel_crtc_config
*pipe_config
)
8156 #define PIPE_CONF_CHECK_X(name) \
8157 if (current_config->name != pipe_config->name) { \
8158 DRM_ERROR("mismatch in " #name " " \
8159 "(expected 0x%08x, found 0x%08x)\n", \
8160 current_config->name, \
8161 pipe_config->name); \
8165 #define PIPE_CONF_CHECK_I(name) \
8166 if (current_config->name != pipe_config->name) { \
8167 DRM_ERROR("mismatch in " #name " " \
8168 "(expected %i, found %i)\n", \
8169 current_config->name, \
8170 pipe_config->name); \
8174 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
8175 if ((current_config->name ^ pipe_config->name) & (mask)) { \
8176 DRM_ERROR("mismatch in " #name "(" #mask ") " \
8177 "(expected %i, found %i)\n", \
8178 current_config->name & (mask), \
8179 pipe_config->name & (mask)); \
8183 #define PIPE_CONF_QUIRK(quirk) \
8184 ((current_config->quirks | pipe_config->quirks) & (quirk))
8186 PIPE_CONF_CHECK_I(cpu_transcoder
);
8188 PIPE_CONF_CHECK_I(has_pch_encoder
);
8189 PIPE_CONF_CHECK_I(fdi_lanes
);
8190 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_m
);
8191 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_n
);
8192 PIPE_CONF_CHECK_I(fdi_m_n
.link_m
);
8193 PIPE_CONF_CHECK_I(fdi_m_n
.link_n
);
8194 PIPE_CONF_CHECK_I(fdi_m_n
.tu
);
8196 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hdisplay
);
8197 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_htotal
);
8198 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_start
);
8199 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_end
);
8200 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_start
);
8201 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_end
);
8203 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vdisplay
);
8204 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vtotal
);
8205 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_start
);
8206 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_end
);
8207 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_start
);
8208 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_end
);
8210 PIPE_CONF_CHECK_I(pixel_multiplier
);
8212 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
8213 DRM_MODE_FLAG_INTERLACE
);
8215 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
8216 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
8217 DRM_MODE_FLAG_PHSYNC
);
8218 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
8219 DRM_MODE_FLAG_NHSYNC
);
8220 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
8221 DRM_MODE_FLAG_PVSYNC
);
8222 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
8223 DRM_MODE_FLAG_NVSYNC
);
8226 PIPE_CONF_CHECK_I(requested_mode
.hdisplay
);
8227 PIPE_CONF_CHECK_I(requested_mode
.vdisplay
);
8229 PIPE_CONF_CHECK_I(gmch_pfit
.control
);
8230 /* pfit ratios are autocomputed by the hw on gen4+ */
8231 if (INTEL_INFO(dev
)->gen
< 4)
8232 PIPE_CONF_CHECK_I(gmch_pfit
.pgm_ratios
);
8233 PIPE_CONF_CHECK_I(gmch_pfit
.lvds_border_bits
);
8234 PIPE_CONF_CHECK_I(pch_pfit
.pos
);
8235 PIPE_CONF_CHECK_I(pch_pfit
.size
);
8237 PIPE_CONF_CHECK_I(ips_enabled
);
8239 PIPE_CONF_CHECK_I(shared_dpll
);
8240 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
8241 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
8242 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
8243 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
8245 #undef PIPE_CONF_CHECK_X
8246 #undef PIPE_CONF_CHECK_I
8247 #undef PIPE_CONF_CHECK_FLAGS
8248 #undef PIPE_CONF_QUIRK
8250 if (!IS_HASWELL(dev
)) {
8251 if (!intel_fuzzy_clock_check(current_config
, pipe_config
)) {
8252 DRM_ERROR("mismatch in clock (expected %d, found %d)\n",
8253 current_config
->adjusted_mode
.clock
,
8254 pipe_config
->adjusted_mode
.clock
);
8263 check_connector_state(struct drm_device
*dev
)
8265 struct intel_connector
*connector
;
8267 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
8269 /* This also checks the encoder/connector hw state with the
8270 * ->get_hw_state callbacks. */
8271 intel_connector_check_state(connector
);
8273 WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
8274 "connector's staged encoder doesn't match current encoder\n");
8279 check_encoder_state(struct drm_device
*dev
)
8281 struct intel_encoder
*encoder
;
8282 struct intel_connector
*connector
;
8284 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
8286 bool enabled
= false;
8287 bool active
= false;
8288 enum pipe pipe
, tracked_pipe
;
8290 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
8291 encoder
->base
.base
.id
,
8292 drm_get_encoder_name(&encoder
->base
));
8294 WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
8295 "encoder's stage crtc doesn't match current crtc\n");
8296 WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
8297 "encoder's active_connectors set, but no crtc\n");
8299 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
8301 if (connector
->base
.encoder
!= &encoder
->base
)
8304 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
8307 WARN(!!encoder
->base
.crtc
!= enabled
,
8308 "encoder's enabled state mismatch "
8309 "(expected %i, found %i)\n",
8310 !!encoder
->base
.crtc
, enabled
);
8311 WARN(active
&& !encoder
->base
.crtc
,
8312 "active encoder with no crtc\n");
8314 WARN(encoder
->connectors_active
!= active
,
8315 "encoder's computed active state doesn't match tracked active state "
8316 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
8318 active
= encoder
->get_hw_state(encoder
, &pipe
);
8319 WARN(active
!= encoder
->connectors_active
,
8320 "encoder's hw state doesn't match sw tracking "
8321 "(expected %i, found %i)\n",
8322 encoder
->connectors_active
, active
);
8324 if (!encoder
->base
.crtc
)
8327 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
8328 WARN(active
&& pipe
!= tracked_pipe
,
8329 "active encoder's pipe doesn't match"
8330 "(expected %i, found %i)\n",
8331 tracked_pipe
, pipe
);
8337 check_crtc_state(struct drm_device
*dev
)
8339 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
8340 struct intel_crtc
*crtc
;
8341 struct intel_encoder
*encoder
;
8342 struct intel_crtc_config pipe_config
;
8344 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
8346 bool enabled
= false;
8347 bool active
= false;
8349 memset(&pipe_config
, 0, sizeof(pipe_config
));
8351 DRM_DEBUG_KMS("[CRTC:%d]\n",
8352 crtc
->base
.base
.id
);
8354 WARN(crtc
->active
&& !crtc
->base
.enabled
,
8355 "active crtc, but not enabled in sw tracking\n");
8357 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
8359 if (encoder
->base
.crtc
!= &crtc
->base
)
8362 if (encoder
->connectors_active
)
8366 WARN(active
!= crtc
->active
,
8367 "crtc's computed active state doesn't match tracked active state "
8368 "(expected %i, found %i)\n", active
, crtc
->active
);
8369 WARN(enabled
!= crtc
->base
.enabled
,
8370 "crtc's computed enabled state doesn't match tracked enabled state "
8371 "(expected %i, found %i)\n", enabled
, crtc
->base
.enabled
);
8373 active
= dev_priv
->display
.get_pipe_config(crtc
,
8376 /* hw state is inconsistent with the pipe A quirk */
8377 if (crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
)
8378 active
= crtc
->active
;
8380 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
8382 if (encoder
->base
.crtc
!= &crtc
->base
)
8384 if (encoder
->get_config
)
8385 encoder
->get_config(encoder
, &pipe_config
);
8388 if (dev_priv
->display
.get_clock
)
8389 dev_priv
->display
.get_clock(crtc
, &pipe_config
);
8391 WARN(crtc
->active
!= active
,
8392 "crtc active state doesn't match with hw state "
8393 "(expected %i, found %i)\n", crtc
->active
, active
);
8396 !intel_pipe_config_compare(dev
, &crtc
->config
, &pipe_config
)) {
8397 WARN(1, "pipe state doesn't match!\n");
8398 intel_dump_pipe_config(crtc
, &pipe_config
,
8400 intel_dump_pipe_config(crtc
, &crtc
->config
,
8407 check_shared_dpll_state(struct drm_device
*dev
)
8409 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
8410 struct intel_crtc
*crtc
;
8411 struct intel_dpll_hw_state dpll_hw_state
;
8414 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
8415 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
8416 int enabled_crtcs
= 0, active_crtcs
= 0;
8419 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
8421 DRM_DEBUG_KMS("%s\n", pll
->name
);
8423 active
= pll
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
8425 WARN(pll
->active
> pll
->refcount
,
8426 "more active pll users than references: %i vs %i\n",
8427 pll
->active
, pll
->refcount
);
8428 WARN(pll
->active
&& !pll
->on
,
8429 "pll in active use but not on in sw tracking\n");
8430 WARN(pll
->on
!= active
,
8431 "pll on state mismatch (expected %i, found %i)\n",
8434 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
8436 if (crtc
->base
.enabled
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
8438 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
8441 WARN(pll
->active
!= active_crtcs
,
8442 "pll active crtcs mismatch (expected %i, found %i)\n",
8443 pll
->active
, active_crtcs
);
8444 WARN(pll
->refcount
!= enabled_crtcs
,
8445 "pll enabled crtcs mismatch (expected %i, found %i)\n",
8446 pll
->refcount
, enabled_crtcs
);
8448 WARN(pll
->on
&& memcmp(&pll
->hw_state
, &dpll_hw_state
,
8449 sizeof(dpll_hw_state
)),
8450 "pll hw state mismatch\n");
8455 intel_modeset_check_state(struct drm_device
*dev
)
8457 check_connector_state(dev
);
8458 check_encoder_state(dev
);
8459 check_crtc_state(dev
);
8460 check_shared_dpll_state(dev
);
8463 static int __intel_set_mode(struct drm_crtc
*crtc
,
8464 struct drm_display_mode
*mode
,
8465 int x
, int y
, struct drm_framebuffer
*fb
)
8467 struct drm_device
*dev
= crtc
->dev
;
8468 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
8469 struct drm_display_mode
*saved_mode
, *saved_hwmode
;
8470 struct intel_crtc_config
*pipe_config
= NULL
;
8471 struct intel_crtc
*intel_crtc
;
8472 unsigned disable_pipes
, prepare_pipes
, modeset_pipes
;
8475 saved_mode
= kmalloc(2 * sizeof(*saved_mode
), GFP_KERNEL
);
8478 saved_hwmode
= saved_mode
+ 1;
8480 intel_modeset_affected_pipes(crtc
, &modeset_pipes
,
8481 &prepare_pipes
, &disable_pipes
);
8483 *saved_hwmode
= crtc
->hwmode
;
8484 *saved_mode
= crtc
->mode
;
8486 /* Hack: Because we don't (yet) support global modeset on multiple
8487 * crtcs, we don't keep track of the new mode for more than one crtc.
8488 * Hence simply check whether any bit is set in modeset_pipes in all the
8489 * pieces of code that are not yet converted to deal with mutliple crtcs
8490 * changing their mode at the same time. */
8491 if (modeset_pipes
) {
8492 pipe_config
= intel_modeset_pipe_config(crtc
, fb
, mode
);
8493 if (IS_ERR(pipe_config
)) {
8494 ret
= PTR_ERR(pipe_config
);
8499 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
8503 for_each_intel_crtc_masked(dev
, disable_pipes
, intel_crtc
)
8504 intel_crtc_disable(&intel_crtc
->base
);
8506 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
8507 if (intel_crtc
->base
.enabled
)
8508 dev_priv
->display
.crtc_disable(&intel_crtc
->base
);
8511 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
8512 * to set it here already despite that we pass it down the callchain.
8514 if (modeset_pipes
) {
8516 /* mode_set/enable/disable functions rely on a correct pipe
8518 to_intel_crtc(crtc
)->config
= *pipe_config
;
8521 /* Only after disabling all output pipelines that will be changed can we
8522 * update the the output configuration. */
8523 intel_modeset_update_state(dev
, prepare_pipes
);
8525 if (dev_priv
->display
.modeset_global_resources
)
8526 dev_priv
->display
.modeset_global_resources(dev
);
8528 /* Set up the DPLL and any encoders state that needs to adjust or depend
8531 for_each_intel_crtc_masked(dev
, modeset_pipes
, intel_crtc
) {
8532 ret
= intel_crtc_mode_set(&intel_crtc
->base
,
8538 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
8539 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
)
8540 dev_priv
->display
.crtc_enable(&intel_crtc
->base
);
8542 if (modeset_pipes
) {
8543 /* Store real post-adjustment hardware mode. */
8544 crtc
->hwmode
= pipe_config
->adjusted_mode
;
8546 /* Calculate and store various constants which
8547 * are later needed by vblank and swap-completion
8548 * timestamping. They are derived from true hwmode.
8550 drm_calc_timestamping_constants(crtc
);
8553 /* FIXME: add subpixel order */
8555 if (ret
&& crtc
->enabled
) {
8556 crtc
->hwmode
= *saved_hwmode
;
8557 crtc
->mode
= *saved_mode
;
8566 int intel_set_mode(struct drm_crtc
*crtc
,
8567 struct drm_display_mode
*mode
,
8568 int x
, int y
, struct drm_framebuffer
*fb
)
8572 ret
= __intel_set_mode(crtc
, mode
, x
, y
, fb
);
8575 intel_modeset_check_state(crtc
->dev
);
8580 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
8582 intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
, crtc
->fb
);
8585 #undef for_each_intel_crtc_masked
8587 static void intel_set_config_free(struct intel_set_config
*config
)
8592 kfree(config
->save_connector_encoders
);
8593 kfree(config
->save_encoder_crtcs
);
8597 static int intel_set_config_save_state(struct drm_device
*dev
,
8598 struct intel_set_config
*config
)
8600 struct drm_encoder
*encoder
;
8601 struct drm_connector
*connector
;
8604 config
->save_encoder_crtcs
=
8605 kcalloc(dev
->mode_config
.num_encoder
,
8606 sizeof(struct drm_crtc
*), GFP_KERNEL
);
8607 if (!config
->save_encoder_crtcs
)
8610 config
->save_connector_encoders
=
8611 kcalloc(dev
->mode_config
.num_connector
,
8612 sizeof(struct drm_encoder
*), GFP_KERNEL
);
8613 if (!config
->save_connector_encoders
)
8616 /* Copy data. Note that driver private data is not affected.
8617 * Should anything bad happen only the expected state is
8618 * restored, not the drivers personal bookkeeping.
8621 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
8622 config
->save_encoder_crtcs
[count
++] = encoder
->crtc
;
8626 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
8627 config
->save_connector_encoders
[count
++] = connector
->encoder
;
8633 static void intel_set_config_restore_state(struct drm_device
*dev
,
8634 struct intel_set_config
*config
)
8636 struct intel_encoder
*encoder
;
8637 struct intel_connector
*connector
;
8641 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
8643 to_intel_crtc(config
->save_encoder_crtcs
[count
++]);
8647 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
8648 connector
->new_encoder
=
8649 to_intel_encoder(config
->save_connector_encoders
[count
++]);
8654 is_crtc_connector_off(struct drm_crtc
*crtc
, struct drm_connector
*connectors
,
8659 for (i
= 0; i
< num_connectors
; i
++)
8660 if (connectors
[i
].encoder
&&
8661 connectors
[i
].encoder
->crtc
== crtc
&&
8662 connectors
[i
].dpms
!= DRM_MODE_DPMS_ON
)
8669 intel_set_config_compute_mode_changes(struct drm_mode_set
*set
,
8670 struct intel_set_config
*config
)
8673 /* We should be able to check here if the fb has the same properties
8674 * and then just flip_or_move it */
8675 if (set
->connectors
!= NULL
&&
8676 is_crtc_connector_off(set
->crtc
, *set
->connectors
,
8677 set
->num_connectors
)) {
8678 config
->mode_changed
= true;
8679 } else if (set
->crtc
->fb
!= set
->fb
) {
8680 /* If we have no fb then treat it as a full mode set */
8681 if (set
->crtc
->fb
== NULL
) {
8682 struct intel_crtc
*intel_crtc
=
8683 to_intel_crtc(set
->crtc
);
8685 if (intel_crtc
->active
&& i915_fastboot
) {
8686 DRM_DEBUG_KMS("crtc has no fb, will flip\n");
8687 config
->fb_changed
= true;
8689 DRM_DEBUG_KMS("inactive crtc, full mode set\n");
8690 config
->mode_changed
= true;
8692 } else if (set
->fb
== NULL
) {
8693 config
->mode_changed
= true;
8694 } else if (set
->fb
->pixel_format
!=
8695 set
->crtc
->fb
->pixel_format
) {
8696 config
->mode_changed
= true;
8698 config
->fb_changed
= true;
8702 if (set
->fb
&& (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
))
8703 config
->fb_changed
= true;
8705 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
8706 DRM_DEBUG_KMS("modes are different, full mode set\n");
8707 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
8708 drm_mode_debug_printmodeline(set
->mode
);
8709 config
->mode_changed
= true;
8714 intel_modeset_stage_output_state(struct drm_device
*dev
,
8715 struct drm_mode_set
*set
,
8716 struct intel_set_config
*config
)
8718 struct drm_crtc
*new_crtc
;
8719 struct intel_connector
*connector
;
8720 struct intel_encoder
*encoder
;
8723 /* The upper layers ensure that we either disable a crtc or have a list
8724 * of connectors. For paranoia, double-check this. */
8725 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
8726 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
8729 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
8731 /* Otherwise traverse passed in connector list and get encoders
8733 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
8734 if (set
->connectors
[ro
] == &connector
->base
) {
8735 connector
->new_encoder
= connector
->encoder
;
8740 /* If we disable the crtc, disable all its connectors. Also, if
8741 * the connector is on the changing crtc but not on the new
8742 * connector list, disable it. */
8743 if ((!set
->fb
|| ro
== set
->num_connectors
) &&
8744 connector
->base
.encoder
&&
8745 connector
->base
.encoder
->crtc
== set
->crtc
) {
8746 connector
->new_encoder
= NULL
;
8748 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
8749 connector
->base
.base
.id
,
8750 drm_get_connector_name(&connector
->base
));
8754 if (&connector
->new_encoder
->base
!= connector
->base
.encoder
) {
8755 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
8756 config
->mode_changed
= true;
8759 /* connector->new_encoder is now updated for all connectors. */
8761 /* Update crtc of enabled connectors. */
8763 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
8765 if (!connector
->new_encoder
)
8768 new_crtc
= connector
->new_encoder
->base
.crtc
;
8770 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
8771 if (set
->connectors
[ro
] == &connector
->base
)
8772 new_crtc
= set
->crtc
;
8775 /* Make sure the new CRTC will work with the encoder */
8776 if (!intel_encoder_crtc_ok(&connector
->new_encoder
->base
,
8780 connector
->encoder
->new_crtc
= to_intel_crtc(new_crtc
);
8782 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
8783 connector
->base
.base
.id
,
8784 drm_get_connector_name(&connector
->base
),
8788 /* Check for any encoders that needs to be disabled. */
8789 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
8791 list_for_each_entry(connector
,
8792 &dev
->mode_config
.connector_list
,
8794 if (connector
->new_encoder
== encoder
) {
8795 WARN_ON(!connector
->new_encoder
->new_crtc
);
8800 encoder
->new_crtc
= NULL
;
8802 /* Only now check for crtc changes so we don't miss encoders
8803 * that will be disabled. */
8804 if (&encoder
->new_crtc
->base
!= encoder
->base
.crtc
) {
8805 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
8806 config
->mode_changed
= true;
8809 /* Now we've also updated encoder->new_crtc for all encoders. */
8814 static int intel_crtc_set_config(struct drm_mode_set
*set
)
8816 struct drm_device
*dev
;
8817 struct drm_mode_set save_set
;
8818 struct intel_set_config
*config
;
8823 BUG_ON(!set
->crtc
->helper_private
);
8825 /* Enforce sane interface api - has been abused by the fb helper. */
8826 BUG_ON(!set
->mode
&& set
->fb
);
8827 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
8830 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
8831 set
->crtc
->base
.id
, set
->fb
->base
.id
,
8832 (int)set
->num_connectors
, set
->x
, set
->y
);
8834 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
8837 dev
= set
->crtc
->dev
;
8840 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
8844 ret
= intel_set_config_save_state(dev
, config
);
8848 save_set
.crtc
= set
->crtc
;
8849 save_set
.mode
= &set
->crtc
->mode
;
8850 save_set
.x
= set
->crtc
->x
;
8851 save_set
.y
= set
->crtc
->y
;
8852 save_set
.fb
= set
->crtc
->fb
;
8854 /* Compute whether we need a full modeset, only an fb base update or no
8855 * change at all. In the future we might also check whether only the
8856 * mode changed, e.g. for LVDS where we only change the panel fitter in
8858 intel_set_config_compute_mode_changes(set
, config
);
8860 ret
= intel_modeset_stage_output_state(dev
, set
, config
);
8864 if (config
->mode_changed
) {
8865 ret
= intel_set_mode(set
->crtc
, set
->mode
,
8866 set
->x
, set
->y
, set
->fb
);
8867 } else if (config
->fb_changed
) {
8868 intel_crtc_wait_for_pending_flips(set
->crtc
);
8870 ret
= intel_pipe_set_base(set
->crtc
,
8871 set
->x
, set
->y
, set
->fb
);
8875 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
8876 set
->crtc
->base
.id
, ret
);
8878 intel_set_config_restore_state(dev
, config
);
8880 /* Try to restore the config */
8881 if (config
->mode_changed
&&
8882 intel_set_mode(save_set
.crtc
, save_set
.mode
,
8883 save_set
.x
, save_set
.y
, save_set
.fb
))
8884 DRM_ERROR("failed to restore config after modeset failure\n");
8888 intel_set_config_free(config
);
8892 static const struct drm_crtc_funcs intel_crtc_funcs
= {
8893 .cursor_set
= intel_crtc_cursor_set
,
8894 .cursor_move
= intel_crtc_cursor_move
,
8895 .gamma_set
= intel_crtc_gamma_set
,
8896 .set_config
= intel_crtc_set_config
,
8897 .destroy
= intel_crtc_destroy
,
8898 .page_flip
= intel_crtc_page_flip
,
8901 static void intel_cpu_pll_init(struct drm_device
*dev
)
8904 intel_ddi_pll_init(dev
);
8907 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private
*dev_priv
,
8908 struct intel_shared_dpll
*pll
,
8909 struct intel_dpll_hw_state
*hw_state
)
8913 val
= I915_READ(PCH_DPLL(pll
->id
));
8914 hw_state
->dpll
= val
;
8915 hw_state
->fp0
= I915_READ(PCH_FP0(pll
->id
));
8916 hw_state
->fp1
= I915_READ(PCH_FP1(pll
->id
));
8918 return val
& DPLL_VCO_ENABLE
;
8921 static void ibx_pch_dpll_mode_set(struct drm_i915_private
*dev_priv
,
8922 struct intel_shared_dpll
*pll
)
8924 I915_WRITE(PCH_FP0(pll
->id
), pll
->hw_state
.fp0
);
8925 I915_WRITE(PCH_FP1(pll
->id
), pll
->hw_state
.fp1
);
8928 static void ibx_pch_dpll_enable(struct drm_i915_private
*dev_priv
,
8929 struct intel_shared_dpll
*pll
)
8931 /* PCH refclock must be enabled first */
8932 assert_pch_refclk_enabled(dev_priv
);
8934 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
8936 /* Wait for the clocks to stabilize. */
8937 POSTING_READ(PCH_DPLL(pll
->id
));
8940 /* The pixel multiplier can only be updated once the
8941 * DPLL is enabled and the clocks are stable.
8943 * So write it again.
8945 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
8946 POSTING_READ(PCH_DPLL(pll
->id
));
8950 static void ibx_pch_dpll_disable(struct drm_i915_private
*dev_priv
,
8951 struct intel_shared_dpll
*pll
)
8953 struct drm_device
*dev
= dev_priv
->dev
;
8954 struct intel_crtc
*crtc
;
8956 /* Make sure no transcoder isn't still depending on us. */
8957 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, base
.head
) {
8958 if (intel_crtc_to_shared_dpll(crtc
) == pll
)
8959 assert_pch_transcoder_disabled(dev_priv
, crtc
->pipe
);
8962 I915_WRITE(PCH_DPLL(pll
->id
), 0);
8963 POSTING_READ(PCH_DPLL(pll
->id
));
8967 static char *ibx_pch_dpll_names
[] = {
8972 static void ibx_pch_dpll_init(struct drm_device
*dev
)
8974 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8977 dev_priv
->num_shared_dpll
= 2;
8979 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
8980 dev_priv
->shared_dplls
[i
].id
= i
;
8981 dev_priv
->shared_dplls
[i
].name
= ibx_pch_dpll_names
[i
];
8982 dev_priv
->shared_dplls
[i
].mode_set
= ibx_pch_dpll_mode_set
;
8983 dev_priv
->shared_dplls
[i
].enable
= ibx_pch_dpll_enable
;
8984 dev_priv
->shared_dplls
[i
].disable
= ibx_pch_dpll_disable
;
8985 dev_priv
->shared_dplls
[i
].get_hw_state
=
8986 ibx_pch_dpll_get_hw_state
;
8990 static void intel_shared_dpll_init(struct drm_device
*dev
)
8992 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8994 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
8995 ibx_pch_dpll_init(dev
);
8997 dev_priv
->num_shared_dpll
= 0;
8999 BUG_ON(dev_priv
->num_shared_dpll
> I915_NUM_PLLS
);
9000 DRM_DEBUG_KMS("%i shared PLLs initialized\n",
9001 dev_priv
->num_shared_dpll
);
9004 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
9006 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
9007 struct intel_crtc
*intel_crtc
;
9010 intel_crtc
= kzalloc(sizeof(struct intel_crtc
) + (INTELFB_CONN_LIMIT
* sizeof(struct drm_connector
*)), GFP_KERNEL
);
9011 if (intel_crtc
== NULL
)
9014 drm_crtc_init(dev
, &intel_crtc
->base
, &intel_crtc_funcs
);
9016 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
9017 for (i
= 0; i
< 256; i
++) {
9018 intel_crtc
->lut_r
[i
] = i
;
9019 intel_crtc
->lut_g
[i
] = i
;
9020 intel_crtc
->lut_b
[i
] = i
;
9023 /* Swap pipes & planes for FBC on pre-965 */
9024 intel_crtc
->pipe
= pipe
;
9025 intel_crtc
->plane
= pipe
;
9026 if (IS_MOBILE(dev
) && IS_GEN3(dev
)) {
9027 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
9028 intel_crtc
->plane
= !pipe
;
9031 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
9032 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
9033 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
9034 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
9036 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
9039 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
9040 struct drm_file
*file
)
9042 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
9043 struct drm_mode_object
*drmmode_obj
;
9044 struct intel_crtc
*crtc
;
9046 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
9049 drmmode_obj
= drm_mode_object_find(dev
, pipe_from_crtc_id
->crtc_id
,
9050 DRM_MODE_OBJECT_CRTC
);
9053 DRM_ERROR("no such CRTC id\n");
9057 crtc
= to_intel_crtc(obj_to_crtc(drmmode_obj
));
9058 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
9063 static int intel_encoder_clones(struct intel_encoder
*encoder
)
9065 struct drm_device
*dev
= encoder
->base
.dev
;
9066 struct intel_encoder
*source_encoder
;
9070 list_for_each_entry(source_encoder
,
9071 &dev
->mode_config
.encoder_list
, base
.head
) {
9073 if (encoder
== source_encoder
)
9074 index_mask
|= (1 << entry
);
9076 /* Intel hw has only one MUX where enocoders could be cloned. */
9077 if (encoder
->cloneable
&& source_encoder
->cloneable
)
9078 index_mask
|= (1 << entry
);
9086 static bool has_edp_a(struct drm_device
*dev
)
9088 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9090 if (!IS_MOBILE(dev
))
9093 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
9097 (I915_READ(ILK_DISPLAY_CHICKEN_FUSES
) & ILK_eDP_A_DISABLE
))
9103 static void intel_setup_outputs(struct drm_device
*dev
)
9105 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9106 struct intel_encoder
*encoder
;
9107 bool dpd_is_edp
= false;
9109 intel_lvds_init(dev
);
9112 intel_crt_init(dev
);
9117 /* Haswell uses DDI functions to detect digital outputs */
9118 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
9119 /* DDI A only supports eDP */
9121 intel_ddi_init(dev
, PORT_A
);
9123 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
9125 found
= I915_READ(SFUSE_STRAP
);
9127 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
9128 intel_ddi_init(dev
, PORT_B
);
9129 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
9130 intel_ddi_init(dev
, PORT_C
);
9131 if (found
& SFUSE_STRAP_DDID_DETECTED
)
9132 intel_ddi_init(dev
, PORT_D
);
9133 } else if (HAS_PCH_SPLIT(dev
)) {
9135 dpd_is_edp
= intel_dpd_is_edp(dev
);
9138 intel_dp_init(dev
, DP_A
, PORT_A
);
9140 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
9141 /* PCH SDVOB multiplex with HDMIB */
9142 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
9144 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
9145 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
9146 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
9149 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
9150 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
9152 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
9153 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
9155 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
9156 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
9158 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
9159 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
9160 } else if (IS_VALLEYVIEW(dev
)) {
9161 /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
9162 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
)
9163 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
9165 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
) {
9166 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
9168 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
)
9169 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
9171 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
9174 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
9175 DRM_DEBUG_KMS("probing SDVOB\n");
9176 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
9177 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
9178 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
9179 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
9182 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
))
9183 intel_dp_init(dev
, DP_B
, PORT_B
);
9186 /* Before G4X SDVOC doesn't have its own detect register */
9188 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
9189 DRM_DEBUG_KMS("probing SDVOC\n");
9190 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
9193 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
9195 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
9196 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
9197 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
9199 if (SUPPORTS_INTEGRATED_DP(dev
))
9200 intel_dp_init(dev
, DP_C
, PORT_C
);
9203 if (SUPPORTS_INTEGRATED_DP(dev
) &&
9204 (I915_READ(DP_D
) & DP_DETECTED
))
9205 intel_dp_init(dev
, DP_D
, PORT_D
);
9206 } else if (IS_GEN2(dev
))
9207 intel_dvo_init(dev
);
9209 if (SUPPORTS_TV(dev
))
9212 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
9213 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
9214 encoder
->base
.possible_clones
=
9215 intel_encoder_clones(encoder
);
9218 intel_init_pch_refclk(dev
);
9220 drm_helper_move_panel_connectors_to_head(dev
);
9223 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
9225 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
9227 drm_framebuffer_cleanup(fb
);
9228 drm_gem_object_unreference_unlocked(&intel_fb
->obj
->base
);
9233 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
9234 struct drm_file
*file
,
9235 unsigned int *handle
)
9237 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
9238 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
9240 return drm_gem_handle_create(file
, &obj
->base
, handle
);
9243 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
9244 .destroy
= intel_user_framebuffer_destroy
,
9245 .create_handle
= intel_user_framebuffer_create_handle
,
9248 int intel_framebuffer_init(struct drm_device
*dev
,
9249 struct intel_framebuffer
*intel_fb
,
9250 struct drm_mode_fb_cmd2
*mode_cmd
,
9251 struct drm_i915_gem_object
*obj
)
9256 if (obj
->tiling_mode
== I915_TILING_Y
) {
9257 DRM_DEBUG("hardware does not support tiling Y\n");
9261 if (mode_cmd
->pitches
[0] & 63) {
9262 DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
9263 mode_cmd
->pitches
[0]);
9267 if (INTEL_INFO(dev
)->gen
>= 5 && !IS_VALLEYVIEW(dev
)) {
9268 pitch_limit
= 32*1024;
9269 } else if (INTEL_INFO(dev
)->gen
>= 4) {
9270 if (obj
->tiling_mode
)
9271 pitch_limit
= 16*1024;
9273 pitch_limit
= 32*1024;
9274 } else if (INTEL_INFO(dev
)->gen
>= 3) {
9275 if (obj
->tiling_mode
)
9276 pitch_limit
= 8*1024;
9278 pitch_limit
= 16*1024;
9280 /* XXX DSPC is limited to 4k tiled */
9281 pitch_limit
= 8*1024;
9283 if (mode_cmd
->pitches
[0] > pitch_limit
) {
9284 DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
9285 obj
->tiling_mode
? "tiled" : "linear",
9286 mode_cmd
->pitches
[0], pitch_limit
);
9290 if (obj
->tiling_mode
!= I915_TILING_NONE
&&
9291 mode_cmd
->pitches
[0] != obj
->stride
) {
9292 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
9293 mode_cmd
->pitches
[0], obj
->stride
);
9297 /* Reject formats not supported by any plane early. */
9298 switch (mode_cmd
->pixel_format
) {
9300 case DRM_FORMAT_RGB565
:
9301 case DRM_FORMAT_XRGB8888
:
9302 case DRM_FORMAT_ARGB8888
:
9304 case DRM_FORMAT_XRGB1555
:
9305 case DRM_FORMAT_ARGB1555
:
9306 if (INTEL_INFO(dev
)->gen
> 3) {
9307 DRM_DEBUG("unsupported pixel format: %s\n",
9308 drm_get_format_name(mode_cmd
->pixel_format
));
9312 case DRM_FORMAT_XBGR8888
:
9313 case DRM_FORMAT_ABGR8888
:
9314 case DRM_FORMAT_XRGB2101010
:
9315 case DRM_FORMAT_ARGB2101010
:
9316 case DRM_FORMAT_XBGR2101010
:
9317 case DRM_FORMAT_ABGR2101010
:
9318 if (INTEL_INFO(dev
)->gen
< 4) {
9319 DRM_DEBUG("unsupported pixel format: %s\n",
9320 drm_get_format_name(mode_cmd
->pixel_format
));
9324 case DRM_FORMAT_YUYV
:
9325 case DRM_FORMAT_UYVY
:
9326 case DRM_FORMAT_YVYU
:
9327 case DRM_FORMAT_VYUY
:
9328 if (INTEL_INFO(dev
)->gen
< 5) {
9329 DRM_DEBUG("unsupported pixel format: %s\n",
9330 drm_get_format_name(mode_cmd
->pixel_format
));
9335 DRM_DEBUG("unsupported pixel format: %s\n",
9336 drm_get_format_name(mode_cmd
->pixel_format
));
9340 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
9341 if (mode_cmd
->offsets
[0] != 0)
9344 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
9345 intel_fb
->obj
= obj
;
9347 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
9349 DRM_ERROR("framebuffer init failed %d\n", ret
);
9356 static struct drm_framebuffer
*
9357 intel_user_framebuffer_create(struct drm_device
*dev
,
9358 struct drm_file
*filp
,
9359 struct drm_mode_fb_cmd2
*mode_cmd
)
9361 struct drm_i915_gem_object
*obj
;
9363 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
9364 mode_cmd
->handles
[0]));
9365 if (&obj
->base
== NULL
)
9366 return ERR_PTR(-ENOENT
);
9368 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
9371 static const struct drm_mode_config_funcs intel_mode_funcs
= {
9372 .fb_create
= intel_user_framebuffer_create
,
9373 .output_poll_changed
= intel_fb_output_poll_changed
,
9376 /* Set up chip specific display functions */
9377 static void intel_init_display(struct drm_device
*dev
)
9379 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9381 if (HAS_PCH_SPLIT(dev
) || IS_G4X(dev
))
9382 dev_priv
->display
.find_dpll
= g4x_find_best_dpll
;
9383 else if (IS_VALLEYVIEW(dev
))
9384 dev_priv
->display
.find_dpll
= vlv_find_best_dpll
;
9385 else if (IS_PINEVIEW(dev
))
9386 dev_priv
->display
.find_dpll
= pnv_find_best_dpll
;
9388 dev_priv
->display
.find_dpll
= i9xx_find_best_dpll
;
9391 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
9392 dev_priv
->display
.crtc_mode_set
= haswell_crtc_mode_set
;
9393 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
9394 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
9395 dev_priv
->display
.off
= haswell_crtc_off
;
9396 dev_priv
->display
.update_plane
= ironlake_update_plane
;
9397 } else if (HAS_PCH_SPLIT(dev
)) {
9398 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
9399 dev_priv
->display
.get_clock
= ironlake_crtc_clock_get
;
9400 dev_priv
->display
.crtc_mode_set
= ironlake_crtc_mode_set
;
9401 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
9402 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
9403 dev_priv
->display
.off
= ironlake_crtc_off
;
9404 dev_priv
->display
.update_plane
= ironlake_update_plane
;
9405 } else if (IS_VALLEYVIEW(dev
)) {
9406 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
9407 dev_priv
->display
.get_clock
= i9xx_crtc_clock_get
;
9408 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
9409 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
9410 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
9411 dev_priv
->display
.off
= i9xx_crtc_off
;
9412 dev_priv
->display
.update_plane
= i9xx_update_plane
;
9414 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
9415 dev_priv
->display
.get_clock
= i9xx_crtc_clock_get
;
9416 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
9417 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
9418 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
9419 dev_priv
->display
.off
= i9xx_crtc_off
;
9420 dev_priv
->display
.update_plane
= i9xx_update_plane
;
9423 /* Returns the core display clock speed */
9424 if (IS_VALLEYVIEW(dev
))
9425 dev_priv
->display
.get_display_clock_speed
=
9426 valleyview_get_display_clock_speed
;
9427 else if (IS_I945G(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
9428 dev_priv
->display
.get_display_clock_speed
=
9429 i945_get_display_clock_speed
;
9430 else if (IS_I915G(dev
))
9431 dev_priv
->display
.get_display_clock_speed
=
9432 i915_get_display_clock_speed
;
9433 else if (IS_I945GM(dev
) || IS_845G(dev
) || IS_PINEVIEW_M(dev
))
9434 dev_priv
->display
.get_display_clock_speed
=
9435 i9xx_misc_get_display_clock_speed
;
9436 else if (IS_I915GM(dev
))
9437 dev_priv
->display
.get_display_clock_speed
=
9438 i915gm_get_display_clock_speed
;
9439 else if (IS_I865G(dev
))
9440 dev_priv
->display
.get_display_clock_speed
=
9441 i865_get_display_clock_speed
;
9442 else if (IS_I85X(dev
))
9443 dev_priv
->display
.get_display_clock_speed
=
9444 i855_get_display_clock_speed
;
9446 dev_priv
->display
.get_display_clock_speed
=
9447 i830_get_display_clock_speed
;
9449 if (HAS_PCH_SPLIT(dev
)) {
9451 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
9452 dev_priv
->display
.write_eld
= ironlake_write_eld
;
9453 } else if (IS_GEN6(dev
)) {
9454 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
9455 dev_priv
->display
.write_eld
= ironlake_write_eld
;
9456 } else if (IS_IVYBRIDGE(dev
)) {
9457 /* FIXME: detect B0+ stepping and use auto training */
9458 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
9459 dev_priv
->display
.write_eld
= ironlake_write_eld
;
9460 dev_priv
->display
.modeset_global_resources
=
9461 ivb_modeset_global_resources
;
9462 } else if (IS_HASWELL(dev
)) {
9463 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
9464 dev_priv
->display
.write_eld
= haswell_write_eld
;
9465 dev_priv
->display
.modeset_global_resources
=
9466 haswell_modeset_global_resources
;
9468 } else if (IS_G4X(dev
)) {
9469 dev_priv
->display
.write_eld
= g4x_write_eld
;
9472 /* Default just returns -ENODEV to indicate unsupported */
9473 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
9475 switch (INTEL_INFO(dev
)->gen
) {
9477 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
9481 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
9486 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
9490 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
9493 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
9499 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
9500 * resume, or other times. This quirk makes sure that's the case for
9503 static void quirk_pipea_force(struct drm_device
*dev
)
9505 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9507 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
9508 DRM_INFO("applying pipe a force quirk\n");
9512 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
9514 static void quirk_ssc_force_disable(struct drm_device
*dev
)
9516 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9517 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
9518 DRM_INFO("applying lvds SSC disable quirk\n");
9522 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
9525 static void quirk_invert_brightness(struct drm_device
*dev
)
9527 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9528 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
9529 DRM_INFO("applying inverted panel brightness quirk\n");
9532 struct intel_quirk
{
9534 int subsystem_vendor
;
9535 int subsystem_device
;
9536 void (*hook
)(struct drm_device
*dev
);
9539 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
9540 struct intel_dmi_quirk
{
9541 void (*hook
)(struct drm_device
*dev
);
9542 const struct dmi_system_id (*dmi_id_list
)[];
9545 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
9547 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
9551 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
9553 .dmi_id_list
= &(const struct dmi_system_id
[]) {
9555 .callback
= intel_dmi_reverse_brightness
,
9556 .ident
= "NCR Corporation",
9557 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
9558 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
9561 { } /* terminating entry */
9563 .hook
= quirk_invert_brightness
,
9567 static struct intel_quirk intel_quirks
[] = {
9568 /* HP Mini needs pipe A force quirk (LP: #322104) */
9569 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force
},
9571 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
9572 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
9574 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
9575 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
9577 /* 830/845 need to leave pipe A & dpll A up */
9578 { 0x2562, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
9579 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
9581 /* Lenovo U160 cannot use SSC on LVDS */
9582 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
9584 /* Sony Vaio Y cannot use SSC on LVDS */
9585 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
9587 /* Acer Aspire 5734Z must invert backlight brightness */
9588 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
9590 /* Acer/eMachines G725 */
9591 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
9593 /* Acer/eMachines e725 */
9594 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
9596 /* Acer/Packard Bell NCL20 */
9597 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
9599 /* Acer Aspire 4736Z */
9600 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
9603 static void intel_init_quirks(struct drm_device
*dev
)
9605 struct pci_dev
*d
= dev
->pdev
;
9608 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
9609 struct intel_quirk
*q
= &intel_quirks
[i
];
9611 if (d
->device
== q
->device
&&
9612 (d
->subsystem_vendor
== q
->subsystem_vendor
||
9613 q
->subsystem_vendor
== PCI_ANY_ID
) &&
9614 (d
->subsystem_device
== q
->subsystem_device
||
9615 q
->subsystem_device
== PCI_ANY_ID
))
9618 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
9619 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
9620 intel_dmi_quirks
[i
].hook(dev
);
9624 /* Disable the VGA plane that we never use */
9625 static void i915_disable_vga(struct drm_device
*dev
)
9627 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9629 u32 vga_reg
= i915_vgacntrl_reg(dev
);
9631 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
9632 outb(SR01
, VGA_SR_INDEX
);
9633 sr1
= inb(VGA_SR_DATA
);
9634 outb(sr1
| 1<<5, VGA_SR_DATA
);
9635 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
9638 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
9639 POSTING_READ(vga_reg
);
9642 void intel_modeset_init_hw(struct drm_device
*dev
)
9644 intel_init_power_well(dev
);
9646 intel_prepare_ddi(dev
);
9648 intel_init_clock_gating(dev
);
9650 mutex_lock(&dev
->struct_mutex
);
9651 intel_enable_gt_powersave(dev
);
9652 mutex_unlock(&dev
->struct_mutex
);
9655 void intel_modeset_suspend_hw(struct drm_device
*dev
)
9657 intel_suspend_hw(dev
);
9660 void intel_modeset_init(struct drm_device
*dev
)
9662 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9665 drm_mode_config_init(dev
);
9667 dev
->mode_config
.min_width
= 0;
9668 dev
->mode_config
.min_height
= 0;
9670 dev
->mode_config
.preferred_depth
= 24;
9671 dev
->mode_config
.prefer_shadow
= 1;
9673 dev
->mode_config
.funcs
= &intel_mode_funcs
;
9675 intel_init_quirks(dev
);
9679 if (INTEL_INFO(dev
)->num_pipes
== 0)
9682 intel_init_display(dev
);
9685 dev
->mode_config
.max_width
= 2048;
9686 dev
->mode_config
.max_height
= 2048;
9687 } else if (IS_GEN3(dev
)) {
9688 dev
->mode_config
.max_width
= 4096;
9689 dev
->mode_config
.max_height
= 4096;
9691 dev
->mode_config
.max_width
= 8192;
9692 dev
->mode_config
.max_height
= 8192;
9694 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
9696 DRM_DEBUG_KMS("%d display pipe%s available.\n",
9697 INTEL_INFO(dev
)->num_pipes
,
9698 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
9700 for (i
= 0; i
< INTEL_INFO(dev
)->num_pipes
; i
++) {
9701 intel_crtc_init(dev
, i
);
9702 for (j
= 0; j
< dev_priv
->num_plane
; j
++) {
9703 ret
= intel_plane_init(dev
, i
, j
);
9705 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
9706 pipe_name(i
), sprite_name(i
, j
), ret
);
9710 intel_cpu_pll_init(dev
);
9711 intel_shared_dpll_init(dev
);
9713 /* Just disable it once at startup */
9714 i915_disable_vga(dev
);
9715 intel_setup_outputs(dev
);
9717 /* Just in case the BIOS is doing something questionable. */
9718 intel_disable_fbc(dev
);
9722 intel_connector_break_all_links(struct intel_connector
*connector
)
9724 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
9725 connector
->base
.encoder
= NULL
;
9726 connector
->encoder
->connectors_active
= false;
9727 connector
->encoder
->base
.crtc
= NULL
;
9730 static void intel_enable_pipe_a(struct drm_device
*dev
)
9732 struct intel_connector
*connector
;
9733 struct drm_connector
*crt
= NULL
;
9734 struct intel_load_detect_pipe load_detect_temp
;
9736 /* We can't just switch on the pipe A, we need to set things up with a
9737 * proper mode and output configuration. As a gross hack, enable pipe A
9738 * by enabling the load detect pipe once. */
9739 list_for_each_entry(connector
,
9740 &dev
->mode_config
.connector_list
,
9742 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
9743 crt
= &connector
->base
;
9751 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
))
9752 intel_release_load_detect_pipe(crt
, &load_detect_temp
);
9758 intel_check_plane_mapping(struct intel_crtc
*crtc
)
9760 struct drm_device
*dev
= crtc
->base
.dev
;
9761 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9764 if (INTEL_INFO(dev
)->num_pipes
== 1)
9767 reg
= DSPCNTR(!crtc
->plane
);
9768 val
= I915_READ(reg
);
9770 if ((val
& DISPLAY_PLANE_ENABLE
) &&
9771 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
9777 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
9779 struct drm_device
*dev
= crtc
->base
.dev
;
9780 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9783 /* Clear any frame start delays used for debugging left by the BIOS */
9784 reg
= PIPECONF(crtc
->config
.cpu_transcoder
);
9785 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
9787 /* We need to sanitize the plane -> pipe mapping first because this will
9788 * disable the crtc (and hence change the state) if it is wrong. Note
9789 * that gen4+ has a fixed plane -> pipe mapping. */
9790 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
9791 struct intel_connector
*connector
;
9794 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
9795 crtc
->base
.base
.id
);
9797 /* Pipe has the wrong plane attached and the plane is active.
9798 * Temporarily change the plane mapping and disable everything
9800 plane
= crtc
->plane
;
9801 crtc
->plane
= !plane
;
9802 dev_priv
->display
.crtc_disable(&crtc
->base
);
9803 crtc
->plane
= plane
;
9805 /* ... and break all links. */
9806 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9808 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
9811 intel_connector_break_all_links(connector
);
9814 WARN_ON(crtc
->active
);
9815 crtc
->base
.enabled
= false;
9818 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
9819 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
9820 /* BIOS forgot to enable pipe A, this mostly happens after
9821 * resume. Force-enable the pipe to fix this, the update_dpms
9822 * call below we restore the pipe to the right state, but leave
9823 * the required bits on. */
9824 intel_enable_pipe_a(dev
);
9827 /* Adjust the state of the output pipe according to whether we
9828 * have active connectors/encoders. */
9829 intel_crtc_update_dpms(&crtc
->base
);
9831 if (crtc
->active
!= crtc
->base
.enabled
) {
9832 struct intel_encoder
*encoder
;
9834 /* This can happen either due to bugs in the get_hw_state
9835 * functions or because the pipe is force-enabled due to the
9837 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
9839 crtc
->base
.enabled
? "enabled" : "disabled",
9840 crtc
->active
? "enabled" : "disabled");
9842 crtc
->base
.enabled
= crtc
->active
;
9844 /* Because we only establish the connector -> encoder ->
9845 * crtc links if something is active, this means the
9846 * crtc is now deactivated. Break the links. connector
9847 * -> encoder links are only establish when things are
9848 * actually up, hence no need to break them. */
9849 WARN_ON(crtc
->active
);
9851 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
9852 WARN_ON(encoder
->connectors_active
);
9853 encoder
->base
.crtc
= NULL
;
9858 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
9860 struct intel_connector
*connector
;
9861 struct drm_device
*dev
= encoder
->base
.dev
;
9863 /* We need to check both for a crtc link (meaning that the
9864 * encoder is active and trying to read from a pipe) and the
9865 * pipe itself being active. */
9866 bool has_active_crtc
= encoder
->base
.crtc
&&
9867 to_intel_crtc(encoder
->base
.crtc
)->active
;
9869 if (encoder
->connectors_active
&& !has_active_crtc
) {
9870 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
9871 encoder
->base
.base
.id
,
9872 drm_get_encoder_name(&encoder
->base
));
9874 /* Connector is active, but has no active pipe. This is
9875 * fallout from our resume register restoring. Disable
9876 * the encoder manually again. */
9877 if (encoder
->base
.crtc
) {
9878 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
9879 encoder
->base
.base
.id
,
9880 drm_get_encoder_name(&encoder
->base
));
9881 encoder
->disable(encoder
);
9884 /* Inconsistent output/port/pipe state happens presumably due to
9885 * a bug in one of the get_hw_state functions. Or someplace else
9886 * in our code, like the register restore mess on resume. Clamp
9887 * things to off as a safer default. */
9888 list_for_each_entry(connector
,
9889 &dev
->mode_config
.connector_list
,
9891 if (connector
->encoder
!= encoder
)
9894 intel_connector_break_all_links(connector
);
9897 /* Enabled encoders without active connectors will be fixed in
9898 * the crtc fixup. */
9901 void i915_redisable_vga(struct drm_device
*dev
)
9903 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9904 u32 vga_reg
= i915_vgacntrl_reg(dev
);
9906 if (I915_READ(vga_reg
) != VGA_DISP_DISABLE
) {
9907 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
9908 i915_disable_vga(dev
);
9912 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
9914 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9916 struct intel_crtc
*crtc
;
9917 struct intel_encoder
*encoder
;
9918 struct intel_connector
*connector
;
9921 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
9923 memset(&crtc
->config
, 0, sizeof(crtc
->config
));
9925 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
9928 crtc
->base
.enabled
= crtc
->active
;
9930 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
9932 crtc
->active
? "enabled" : "disabled");
9935 /* FIXME: Smash this into the new shared dpll infrastructure. */
9937 intel_ddi_setup_hw_pll_state(dev
);
9939 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
9940 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
9942 pll
->on
= pll
->get_hw_state(dev_priv
, pll
, &pll
->hw_state
);
9944 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
9946 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
9949 pll
->refcount
= pll
->active
;
9951 DRM_DEBUG_KMS("%s hw state readout: refcount %i\n",
9952 pll
->name
, pll
->refcount
);
9955 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9959 if (encoder
->get_hw_state(encoder
, &pipe
)) {
9960 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
9961 encoder
->base
.crtc
= &crtc
->base
;
9962 if (encoder
->get_config
)
9963 encoder
->get_config(encoder
, &crtc
->config
);
9965 encoder
->base
.crtc
= NULL
;
9968 encoder
->connectors_active
= false;
9969 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
9970 encoder
->base
.base
.id
,
9971 drm_get_encoder_name(&encoder
->base
),
9972 encoder
->base
.crtc
? "enabled" : "disabled",
9976 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
9980 if (dev_priv
->display
.get_clock
)
9981 dev_priv
->display
.get_clock(crtc
,
9985 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9987 if (connector
->get_hw_state(connector
)) {
9988 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
9989 connector
->encoder
->connectors_active
= true;
9990 connector
->base
.encoder
= &connector
->encoder
->base
;
9992 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
9993 connector
->base
.encoder
= NULL
;
9995 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
9996 connector
->base
.base
.id
,
9997 drm_get_connector_name(&connector
->base
),
9998 connector
->base
.encoder
? "enabled" : "disabled");
10002 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
10003 * and i915 state tracking structures. */
10004 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
10005 bool force_restore
)
10007 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10009 struct drm_plane
*plane
;
10010 struct intel_crtc
*crtc
;
10011 struct intel_encoder
*encoder
;
10013 intel_modeset_readout_hw_state(dev
);
10016 * Now that we have the config, copy it to each CRTC struct
10017 * Note that this could go away if we move to using crtc_config
10018 * checking everywhere.
10020 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
10022 if (crtc
->active
&& i915_fastboot
) {
10023 intel_crtc_mode_from_pipe_config(crtc
, &crtc
->config
);
10025 DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
10026 crtc
->base
.base
.id
);
10027 drm_mode_debug_printmodeline(&crtc
->base
.mode
);
10031 /* HW state is read out, now we need to sanitize this mess. */
10032 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10034 intel_sanitize_encoder(encoder
);
10037 for_each_pipe(pipe
) {
10038 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
10039 intel_sanitize_crtc(crtc
);
10040 intel_dump_pipe_config(crtc
, &crtc
->config
, "[setup_hw_state]");
10043 if (force_restore
) {
10045 * We need to use raw interfaces for restoring state to avoid
10046 * checking (bogus) intermediate states.
10048 for_each_pipe(pipe
) {
10049 struct drm_crtc
*crtc
=
10050 dev_priv
->pipe_to_crtc_mapping
[pipe
];
10052 __intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
,
10055 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
)
10056 intel_plane_restore(plane
);
10058 i915_redisable_vga(dev
);
10060 intel_modeset_update_staged_output_state(dev
);
10063 intel_modeset_check_state(dev
);
10065 drm_mode_config_reset(dev
);
10068 void intel_modeset_gem_init(struct drm_device
*dev
)
10070 intel_modeset_init_hw(dev
);
10072 intel_setup_overlay(dev
);
10074 intel_modeset_setup_hw_state(dev
, false);
10077 void intel_modeset_cleanup(struct drm_device
*dev
)
10079 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10080 struct drm_crtc
*crtc
;
10081 struct intel_crtc
*intel_crtc
;
10084 * Interrupts and polling as the first thing to avoid creating havoc.
10085 * Too much stuff here (turning of rps, connectors, ...) would
10086 * experience fancy races otherwise.
10088 drm_irq_uninstall(dev
);
10089 cancel_work_sync(&dev_priv
->hotplug_work
);
10091 * Due to the hpd irq storm handling the hotplug work can re-arm the
10092 * poll handlers. Hence disable polling after hpd handling is shut down.
10094 drm_kms_helper_poll_fini(dev
);
10096 mutex_lock(&dev
->struct_mutex
);
10098 intel_unregister_dsm_handler();
10100 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
10101 /* Skip inactive CRTCs */
10105 intel_crtc
= to_intel_crtc(crtc
);
10106 intel_increase_pllclock(crtc
);
10109 intel_disable_fbc(dev
);
10111 intel_disable_gt_powersave(dev
);
10113 ironlake_teardown_rc6(dev
);
10115 mutex_unlock(&dev
->struct_mutex
);
10117 /* flush any delayed tasks or pending work */
10118 flush_scheduled_work();
10120 /* destroy backlight, if any, before the connectors */
10121 intel_panel_destroy_backlight(dev
);
10123 drm_mode_config_cleanup(dev
);
10125 intel_cleanup_overlay(dev
);
10129 * Return which encoder is currently attached for connector.
10131 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
10133 return &intel_attached_encoder(connector
)->base
;
10136 void intel_connector_attach_encoder(struct intel_connector
*connector
,
10137 struct intel_encoder
*encoder
)
10139 connector
->encoder
= encoder
;
10140 drm_mode_connector_attach_encoder(&connector
->base
,
10145 * set vga decode state - true == enable VGA decode
10147 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
10149 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10152 pci_read_config_word(dev_priv
->bridge_dev
, INTEL_GMCH_CTRL
, &gmch_ctrl
);
10154 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
10156 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
10157 pci_write_config_word(dev_priv
->bridge_dev
, INTEL_GMCH_CTRL
, gmch_ctrl
);
10161 #ifdef CONFIG_DEBUG_FS
10162 #include <linux/seq_file.h>
10164 struct intel_display_error_state
{
10166 u32 power_well_driver
;
10168 struct intel_cursor_error_state
{
10173 } cursor
[I915_MAX_PIPES
];
10175 struct intel_pipe_error_state
{
10176 enum transcoder cpu_transcoder
;
10186 } pipe
[I915_MAX_PIPES
];
10188 struct intel_plane_error_state
{
10196 } plane
[I915_MAX_PIPES
];
10199 struct intel_display_error_state
*
10200 intel_display_capture_error_state(struct drm_device
*dev
)
10202 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
10203 struct intel_display_error_state
*error
;
10204 enum transcoder cpu_transcoder
;
10207 error
= kmalloc(sizeof(*error
), GFP_ATOMIC
);
10211 if (HAS_POWER_WELL(dev
))
10212 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
10215 cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
, i
);
10216 error
->pipe
[i
].cpu_transcoder
= cpu_transcoder
;
10218 if (INTEL_INFO(dev
)->gen
<= 6 || IS_VALLEYVIEW(dev
)) {
10219 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
10220 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
10221 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
10223 error
->cursor
[i
].control
= I915_READ(CURCNTR_IVB(i
));
10224 error
->cursor
[i
].position
= I915_READ(CURPOS_IVB(i
));
10225 error
->cursor
[i
].base
= I915_READ(CURBASE_IVB(i
));
10228 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
10229 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
10230 if (INTEL_INFO(dev
)->gen
<= 3) {
10231 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
10232 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
10234 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
10235 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
10236 if (INTEL_INFO(dev
)->gen
>= 4) {
10237 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
10238 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
10241 error
->pipe
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
10242 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
10243 error
->pipe
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
10244 error
->pipe
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
10245 error
->pipe
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
10246 error
->pipe
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
10247 error
->pipe
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
10248 error
->pipe
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
10251 /* In the code above we read the registers without checking if the power
10252 * well was on, so here we have to clear the FPGA_DBG_RM_NOCLAIM bit to
10253 * prevent the next I915_WRITE from detecting it and printing an error
10255 if (HAS_POWER_WELL(dev
))
10256 I915_WRITE_NOTRACE(FPGA_DBG
, FPGA_DBG_RM_NOCLAIM
);
10261 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
10264 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
10265 struct drm_device
*dev
,
10266 struct intel_display_error_state
*error
)
10270 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
10271 if (HAS_POWER_WELL(dev
))
10272 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
10273 error
->power_well_driver
);
10275 err_printf(m
, "Pipe [%d]:\n", i
);
10276 err_printf(m
, " CPU transcoder: %c\n",
10277 transcoder_name(error
->pipe
[i
].cpu_transcoder
));
10278 err_printf(m
, " CONF: %08x\n", error
->pipe
[i
].conf
);
10279 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
10280 err_printf(m
, " HTOTAL: %08x\n", error
->pipe
[i
].htotal
);
10281 err_printf(m
, " HBLANK: %08x\n", error
->pipe
[i
].hblank
);
10282 err_printf(m
, " HSYNC: %08x\n", error
->pipe
[i
].hsync
);
10283 err_printf(m
, " VTOTAL: %08x\n", error
->pipe
[i
].vtotal
);
10284 err_printf(m
, " VBLANK: %08x\n", error
->pipe
[i
].vblank
);
10285 err_printf(m
, " VSYNC: %08x\n", error
->pipe
[i
].vsync
);
10287 err_printf(m
, "Plane [%d]:\n", i
);
10288 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
10289 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
10290 if (INTEL_INFO(dev
)->gen
<= 3) {
10291 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
10292 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
10294 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
10295 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
10296 if (INTEL_INFO(dev
)->gen
>= 4) {
10297 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
10298 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
10301 err_printf(m
, "Cursor [%d]:\n", i
);
10302 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
10303 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
10304 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);