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 <drm/drm_plane_helper.h>
43 #include <drm/drm_rect.h>
44 #include <linux/dma_remapping.h>
46 /* Primary plane formats supported by all gen */
47 #define COMMON_PRIMARY_FORMATS \
50 DRM_FORMAT_XRGB8888, \
53 /* Primary plane formats for gen <= 3 */
54 static const uint32_t intel_primary_formats_gen2
[] = {
55 COMMON_PRIMARY_FORMATS
,
60 /* Primary plane formats for gen >= 4 */
61 static const uint32_t intel_primary_formats_gen4
[] = {
62 COMMON_PRIMARY_FORMATS
, \
65 DRM_FORMAT_XRGB2101010
,
66 DRM_FORMAT_ARGB2101010
,
67 DRM_FORMAT_XBGR2101010
,
68 DRM_FORMAT_ABGR2101010
,
72 static const uint32_t intel_cursor_formats
[] = {
76 #define DIV_ROUND_CLOSEST_ULL(ll, d) \
77 ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
79 static void intel_increase_pllclock(struct drm_device
*dev
,
81 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
, bool on
);
83 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
84 struct intel_crtc_config
*pipe_config
);
85 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
86 struct intel_crtc_config
*pipe_config
);
88 static int intel_set_mode(struct drm_crtc
*crtc
, struct drm_display_mode
*mode
,
89 int x
, int y
, struct drm_framebuffer
*old_fb
);
90 static int intel_framebuffer_init(struct drm_device
*dev
,
91 struct intel_framebuffer
*ifb
,
92 struct drm_mode_fb_cmd2
*mode_cmd
,
93 struct drm_i915_gem_object
*obj
);
94 static void intel_dp_set_m_n(struct intel_crtc
*crtc
);
95 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
96 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
97 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
98 struct intel_link_m_n
*m_n
);
99 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
100 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
101 static void intel_set_pipe_csc(struct drm_crtc
*crtc
);
102 static void vlv_prepare_pll(struct intel_crtc
*crtc
);
110 int p2_slow
, p2_fast
;
113 typedef struct intel_limit intel_limit_t
;
115 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
120 intel_pch_rawclk(struct drm_device
*dev
)
122 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
124 WARN_ON(!HAS_PCH_SPLIT(dev
));
126 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
129 static inline u32
/* units of 100MHz */
130 intel_fdi_link_freq(struct drm_device
*dev
)
133 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
134 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
139 static const intel_limit_t intel_limits_i8xx_dac
= {
140 .dot
= { .min
= 25000, .max
= 350000 },
141 .vco
= { .min
= 908000, .max
= 1512000 },
142 .n
= { .min
= 2, .max
= 16 },
143 .m
= { .min
= 96, .max
= 140 },
144 .m1
= { .min
= 18, .max
= 26 },
145 .m2
= { .min
= 6, .max
= 16 },
146 .p
= { .min
= 4, .max
= 128 },
147 .p1
= { .min
= 2, .max
= 33 },
148 .p2
= { .dot_limit
= 165000,
149 .p2_slow
= 4, .p2_fast
= 2 },
152 static const intel_limit_t intel_limits_i8xx_dvo
= {
153 .dot
= { .min
= 25000, .max
= 350000 },
154 .vco
= { .min
= 908000, .max
= 1512000 },
155 .n
= { .min
= 2, .max
= 16 },
156 .m
= { .min
= 96, .max
= 140 },
157 .m1
= { .min
= 18, .max
= 26 },
158 .m2
= { .min
= 6, .max
= 16 },
159 .p
= { .min
= 4, .max
= 128 },
160 .p1
= { .min
= 2, .max
= 33 },
161 .p2
= { .dot_limit
= 165000,
162 .p2_slow
= 4, .p2_fast
= 4 },
165 static const intel_limit_t intel_limits_i8xx_lvds
= {
166 .dot
= { .min
= 25000, .max
= 350000 },
167 .vco
= { .min
= 908000, .max
= 1512000 },
168 .n
= { .min
= 2, .max
= 16 },
169 .m
= { .min
= 96, .max
= 140 },
170 .m1
= { .min
= 18, .max
= 26 },
171 .m2
= { .min
= 6, .max
= 16 },
172 .p
= { .min
= 4, .max
= 128 },
173 .p1
= { .min
= 1, .max
= 6 },
174 .p2
= { .dot_limit
= 165000,
175 .p2_slow
= 14, .p2_fast
= 7 },
178 static const intel_limit_t intel_limits_i9xx_sdvo
= {
179 .dot
= { .min
= 20000, .max
= 400000 },
180 .vco
= { .min
= 1400000, .max
= 2800000 },
181 .n
= { .min
= 1, .max
= 6 },
182 .m
= { .min
= 70, .max
= 120 },
183 .m1
= { .min
= 8, .max
= 18 },
184 .m2
= { .min
= 3, .max
= 7 },
185 .p
= { .min
= 5, .max
= 80 },
186 .p1
= { .min
= 1, .max
= 8 },
187 .p2
= { .dot_limit
= 200000,
188 .p2_slow
= 10, .p2_fast
= 5 },
191 static const intel_limit_t intel_limits_i9xx_lvds
= {
192 .dot
= { .min
= 20000, .max
= 400000 },
193 .vco
= { .min
= 1400000, .max
= 2800000 },
194 .n
= { .min
= 1, .max
= 6 },
195 .m
= { .min
= 70, .max
= 120 },
196 .m1
= { .min
= 8, .max
= 18 },
197 .m2
= { .min
= 3, .max
= 7 },
198 .p
= { .min
= 7, .max
= 98 },
199 .p1
= { .min
= 1, .max
= 8 },
200 .p2
= { .dot_limit
= 112000,
201 .p2_slow
= 14, .p2_fast
= 7 },
205 static const intel_limit_t intel_limits_g4x_sdvo
= {
206 .dot
= { .min
= 25000, .max
= 270000 },
207 .vco
= { .min
= 1750000, .max
= 3500000},
208 .n
= { .min
= 1, .max
= 4 },
209 .m
= { .min
= 104, .max
= 138 },
210 .m1
= { .min
= 17, .max
= 23 },
211 .m2
= { .min
= 5, .max
= 11 },
212 .p
= { .min
= 10, .max
= 30 },
213 .p1
= { .min
= 1, .max
= 3},
214 .p2
= { .dot_limit
= 270000,
220 static const intel_limit_t intel_limits_g4x_hdmi
= {
221 .dot
= { .min
= 22000, .max
= 400000 },
222 .vco
= { .min
= 1750000, .max
= 3500000},
223 .n
= { .min
= 1, .max
= 4 },
224 .m
= { .min
= 104, .max
= 138 },
225 .m1
= { .min
= 16, .max
= 23 },
226 .m2
= { .min
= 5, .max
= 11 },
227 .p
= { .min
= 5, .max
= 80 },
228 .p1
= { .min
= 1, .max
= 8},
229 .p2
= { .dot_limit
= 165000,
230 .p2_slow
= 10, .p2_fast
= 5 },
233 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
234 .dot
= { .min
= 20000, .max
= 115000 },
235 .vco
= { .min
= 1750000, .max
= 3500000 },
236 .n
= { .min
= 1, .max
= 3 },
237 .m
= { .min
= 104, .max
= 138 },
238 .m1
= { .min
= 17, .max
= 23 },
239 .m2
= { .min
= 5, .max
= 11 },
240 .p
= { .min
= 28, .max
= 112 },
241 .p1
= { .min
= 2, .max
= 8 },
242 .p2
= { .dot_limit
= 0,
243 .p2_slow
= 14, .p2_fast
= 14
247 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
248 .dot
= { .min
= 80000, .max
= 224000 },
249 .vco
= { .min
= 1750000, .max
= 3500000 },
250 .n
= { .min
= 1, .max
= 3 },
251 .m
= { .min
= 104, .max
= 138 },
252 .m1
= { .min
= 17, .max
= 23 },
253 .m2
= { .min
= 5, .max
= 11 },
254 .p
= { .min
= 14, .max
= 42 },
255 .p1
= { .min
= 2, .max
= 6 },
256 .p2
= { .dot_limit
= 0,
257 .p2_slow
= 7, .p2_fast
= 7
261 static const intel_limit_t intel_limits_pineview_sdvo
= {
262 .dot
= { .min
= 20000, .max
= 400000},
263 .vco
= { .min
= 1700000, .max
= 3500000 },
264 /* Pineview's Ncounter is a ring counter */
265 .n
= { .min
= 3, .max
= 6 },
266 .m
= { .min
= 2, .max
= 256 },
267 /* Pineview only has one combined m divider, which we treat as m2. */
268 .m1
= { .min
= 0, .max
= 0 },
269 .m2
= { .min
= 0, .max
= 254 },
270 .p
= { .min
= 5, .max
= 80 },
271 .p1
= { .min
= 1, .max
= 8 },
272 .p2
= { .dot_limit
= 200000,
273 .p2_slow
= 10, .p2_fast
= 5 },
276 static const intel_limit_t intel_limits_pineview_lvds
= {
277 .dot
= { .min
= 20000, .max
= 400000 },
278 .vco
= { .min
= 1700000, .max
= 3500000 },
279 .n
= { .min
= 3, .max
= 6 },
280 .m
= { .min
= 2, .max
= 256 },
281 .m1
= { .min
= 0, .max
= 0 },
282 .m2
= { .min
= 0, .max
= 254 },
283 .p
= { .min
= 7, .max
= 112 },
284 .p1
= { .min
= 1, .max
= 8 },
285 .p2
= { .dot_limit
= 112000,
286 .p2_slow
= 14, .p2_fast
= 14 },
289 /* Ironlake / Sandybridge
291 * We calculate clock using (register_value + 2) for N/M1/M2, so here
292 * the range value for them is (actual_value - 2).
294 static const intel_limit_t intel_limits_ironlake_dac
= {
295 .dot
= { .min
= 25000, .max
= 350000 },
296 .vco
= { .min
= 1760000, .max
= 3510000 },
297 .n
= { .min
= 1, .max
= 5 },
298 .m
= { .min
= 79, .max
= 127 },
299 .m1
= { .min
= 12, .max
= 22 },
300 .m2
= { .min
= 5, .max
= 9 },
301 .p
= { .min
= 5, .max
= 80 },
302 .p1
= { .min
= 1, .max
= 8 },
303 .p2
= { .dot_limit
= 225000,
304 .p2_slow
= 10, .p2_fast
= 5 },
307 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
308 .dot
= { .min
= 25000, .max
= 350000 },
309 .vco
= { .min
= 1760000, .max
= 3510000 },
310 .n
= { .min
= 1, .max
= 3 },
311 .m
= { .min
= 79, .max
= 118 },
312 .m1
= { .min
= 12, .max
= 22 },
313 .m2
= { .min
= 5, .max
= 9 },
314 .p
= { .min
= 28, .max
= 112 },
315 .p1
= { .min
= 2, .max
= 8 },
316 .p2
= { .dot_limit
= 225000,
317 .p2_slow
= 14, .p2_fast
= 14 },
320 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
321 .dot
= { .min
= 25000, .max
= 350000 },
322 .vco
= { .min
= 1760000, .max
= 3510000 },
323 .n
= { .min
= 1, .max
= 3 },
324 .m
= { .min
= 79, .max
= 127 },
325 .m1
= { .min
= 12, .max
= 22 },
326 .m2
= { .min
= 5, .max
= 9 },
327 .p
= { .min
= 14, .max
= 56 },
328 .p1
= { .min
= 2, .max
= 8 },
329 .p2
= { .dot_limit
= 225000,
330 .p2_slow
= 7, .p2_fast
= 7 },
333 /* LVDS 100mhz refclk limits. */
334 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
335 .dot
= { .min
= 25000, .max
= 350000 },
336 .vco
= { .min
= 1760000, .max
= 3510000 },
337 .n
= { .min
= 1, .max
= 2 },
338 .m
= { .min
= 79, .max
= 126 },
339 .m1
= { .min
= 12, .max
= 22 },
340 .m2
= { .min
= 5, .max
= 9 },
341 .p
= { .min
= 28, .max
= 112 },
342 .p1
= { .min
= 2, .max
= 8 },
343 .p2
= { .dot_limit
= 225000,
344 .p2_slow
= 14, .p2_fast
= 14 },
347 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
348 .dot
= { .min
= 25000, .max
= 350000 },
349 .vco
= { .min
= 1760000, .max
= 3510000 },
350 .n
= { .min
= 1, .max
= 3 },
351 .m
= { .min
= 79, .max
= 126 },
352 .m1
= { .min
= 12, .max
= 22 },
353 .m2
= { .min
= 5, .max
= 9 },
354 .p
= { .min
= 14, .max
= 42 },
355 .p1
= { .min
= 2, .max
= 6 },
356 .p2
= { .dot_limit
= 225000,
357 .p2_slow
= 7, .p2_fast
= 7 },
360 static const intel_limit_t intel_limits_vlv
= {
362 * These are the data rate limits (measured in fast clocks)
363 * since those are the strictest limits we have. The fast
364 * clock and actual rate limits are more relaxed, so checking
365 * them would make no difference.
367 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
368 .vco
= { .min
= 4000000, .max
= 6000000 },
369 .n
= { .min
= 1, .max
= 7 },
370 .m1
= { .min
= 2, .max
= 3 },
371 .m2
= { .min
= 11, .max
= 156 },
372 .p1
= { .min
= 2, .max
= 3 },
373 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
376 static const intel_limit_t intel_limits_chv
= {
378 * These are the data rate limits (measured in fast clocks)
379 * since those are the strictest limits we have. The fast
380 * clock and actual rate limits are more relaxed, so checking
381 * them would make no difference.
383 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
384 .vco
= { .min
= 4860000, .max
= 6700000 },
385 .n
= { .min
= 1, .max
= 1 },
386 .m1
= { .min
= 2, .max
= 2 },
387 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
388 .p1
= { .min
= 2, .max
= 4 },
389 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
392 static void vlv_clock(int refclk
, intel_clock_t
*clock
)
394 clock
->m
= clock
->m1
* clock
->m2
;
395 clock
->p
= clock
->p1
* clock
->p2
;
396 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
398 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
399 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
403 * Returns whether any output on the specified pipe is of the specified type
405 static bool intel_pipe_has_type(struct drm_crtc
*crtc
, int type
)
407 struct drm_device
*dev
= crtc
->dev
;
408 struct intel_encoder
*encoder
;
410 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
411 if (encoder
->type
== type
)
417 static const intel_limit_t
*intel_ironlake_limit(struct drm_crtc
*crtc
,
420 struct drm_device
*dev
= crtc
->dev
;
421 const intel_limit_t
*limit
;
423 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
424 if (intel_is_dual_link_lvds(dev
)) {
425 if (refclk
== 100000)
426 limit
= &intel_limits_ironlake_dual_lvds_100m
;
428 limit
= &intel_limits_ironlake_dual_lvds
;
430 if (refclk
== 100000)
431 limit
= &intel_limits_ironlake_single_lvds_100m
;
433 limit
= &intel_limits_ironlake_single_lvds
;
436 limit
= &intel_limits_ironlake_dac
;
441 static const intel_limit_t
*intel_g4x_limit(struct drm_crtc
*crtc
)
443 struct drm_device
*dev
= crtc
->dev
;
444 const intel_limit_t
*limit
;
446 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
447 if (intel_is_dual_link_lvds(dev
))
448 limit
= &intel_limits_g4x_dual_channel_lvds
;
450 limit
= &intel_limits_g4x_single_channel_lvds
;
451 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
) ||
452 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
453 limit
= &intel_limits_g4x_hdmi
;
454 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
)) {
455 limit
= &intel_limits_g4x_sdvo
;
456 } else /* The option is for other outputs */
457 limit
= &intel_limits_i9xx_sdvo
;
462 static const intel_limit_t
*intel_limit(struct drm_crtc
*crtc
, int refclk
)
464 struct drm_device
*dev
= crtc
->dev
;
465 const intel_limit_t
*limit
;
467 if (HAS_PCH_SPLIT(dev
))
468 limit
= intel_ironlake_limit(crtc
, refclk
);
469 else if (IS_G4X(dev
)) {
470 limit
= intel_g4x_limit(crtc
);
471 } else if (IS_PINEVIEW(dev
)) {
472 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
473 limit
= &intel_limits_pineview_lvds
;
475 limit
= &intel_limits_pineview_sdvo
;
476 } else if (IS_CHERRYVIEW(dev
)) {
477 limit
= &intel_limits_chv
;
478 } else if (IS_VALLEYVIEW(dev
)) {
479 limit
= &intel_limits_vlv
;
480 } else if (!IS_GEN2(dev
)) {
481 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
482 limit
= &intel_limits_i9xx_lvds
;
484 limit
= &intel_limits_i9xx_sdvo
;
486 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
487 limit
= &intel_limits_i8xx_lvds
;
488 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
))
489 limit
= &intel_limits_i8xx_dvo
;
491 limit
= &intel_limits_i8xx_dac
;
496 /* m1 is reserved as 0 in Pineview, n is a ring counter */
497 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
499 clock
->m
= clock
->m2
+ 2;
500 clock
->p
= clock
->p1
* clock
->p2
;
501 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
503 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
504 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
507 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
509 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
512 static void i9xx_clock(int refclk
, intel_clock_t
*clock
)
514 clock
->m
= i9xx_dpll_compute_m(clock
);
515 clock
->p
= clock
->p1
* clock
->p2
;
516 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
518 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
519 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
522 static void chv_clock(int refclk
, intel_clock_t
*clock
)
524 clock
->m
= clock
->m1
* clock
->m2
;
525 clock
->p
= clock
->p1
* clock
->p2
;
526 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
528 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
530 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
533 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
535 * Returns whether the given set of divisors are valid for a given refclk with
536 * the given connectors.
539 static bool intel_PLL_is_valid(struct drm_device
*dev
,
540 const intel_limit_t
*limit
,
541 const intel_clock_t
*clock
)
543 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
544 INTELPllInvalid("n out of range\n");
545 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
546 INTELPllInvalid("p1 out of range\n");
547 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
548 INTELPllInvalid("m2 out of range\n");
549 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
550 INTELPllInvalid("m1 out of range\n");
552 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
))
553 if (clock
->m1
<= clock
->m2
)
554 INTELPllInvalid("m1 <= m2\n");
556 if (!IS_VALLEYVIEW(dev
)) {
557 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
558 INTELPllInvalid("p out of range\n");
559 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
560 INTELPllInvalid("m out of range\n");
563 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
564 INTELPllInvalid("vco out of range\n");
565 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
566 * connector, etc., rather than just a single range.
568 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
569 INTELPllInvalid("dot out of range\n");
575 i9xx_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
576 int target
, int refclk
, intel_clock_t
*match_clock
,
577 intel_clock_t
*best_clock
)
579 struct drm_device
*dev
= crtc
->dev
;
583 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
585 * For LVDS just rely on its current settings for dual-channel.
586 * We haven't figured out how to reliably set up different
587 * single/dual channel state, if we even can.
589 if (intel_is_dual_link_lvds(dev
))
590 clock
.p2
= limit
->p2
.p2_fast
;
592 clock
.p2
= limit
->p2
.p2_slow
;
594 if (target
< limit
->p2
.dot_limit
)
595 clock
.p2
= limit
->p2
.p2_slow
;
597 clock
.p2
= limit
->p2
.p2_fast
;
600 memset(best_clock
, 0, sizeof(*best_clock
));
602 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
604 for (clock
.m2
= limit
->m2
.min
;
605 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
606 if (clock
.m2
>= clock
.m1
)
608 for (clock
.n
= limit
->n
.min
;
609 clock
.n
<= limit
->n
.max
; clock
.n
++) {
610 for (clock
.p1
= limit
->p1
.min
;
611 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
614 i9xx_clock(refclk
, &clock
);
615 if (!intel_PLL_is_valid(dev
, limit
,
619 clock
.p
!= match_clock
->p
)
622 this_err
= abs(clock
.dot
- target
);
623 if (this_err
< err
) {
632 return (err
!= target
);
636 pnv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
637 int target
, int refclk
, intel_clock_t
*match_clock
,
638 intel_clock_t
*best_clock
)
640 struct drm_device
*dev
= crtc
->dev
;
644 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
646 * For LVDS just rely on its current settings for dual-channel.
647 * We haven't figured out how to reliably set up different
648 * single/dual channel state, if we even can.
650 if (intel_is_dual_link_lvds(dev
))
651 clock
.p2
= limit
->p2
.p2_fast
;
653 clock
.p2
= limit
->p2
.p2_slow
;
655 if (target
< limit
->p2
.dot_limit
)
656 clock
.p2
= limit
->p2
.p2_slow
;
658 clock
.p2
= limit
->p2
.p2_fast
;
661 memset(best_clock
, 0, sizeof(*best_clock
));
663 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
665 for (clock
.m2
= limit
->m2
.min
;
666 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
667 for (clock
.n
= limit
->n
.min
;
668 clock
.n
<= limit
->n
.max
; clock
.n
++) {
669 for (clock
.p1
= limit
->p1
.min
;
670 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
673 pineview_clock(refclk
, &clock
);
674 if (!intel_PLL_is_valid(dev
, limit
,
678 clock
.p
!= match_clock
->p
)
681 this_err
= abs(clock
.dot
- target
);
682 if (this_err
< err
) {
691 return (err
!= target
);
695 g4x_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
696 int target
, int refclk
, intel_clock_t
*match_clock
,
697 intel_clock_t
*best_clock
)
699 struct drm_device
*dev
= crtc
->dev
;
703 /* approximately equals target * 0.00585 */
704 int err_most
= (target
>> 8) + (target
>> 9);
707 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
708 if (intel_is_dual_link_lvds(dev
))
709 clock
.p2
= limit
->p2
.p2_fast
;
711 clock
.p2
= limit
->p2
.p2_slow
;
713 if (target
< limit
->p2
.dot_limit
)
714 clock
.p2
= limit
->p2
.p2_slow
;
716 clock
.p2
= limit
->p2
.p2_fast
;
719 memset(best_clock
, 0, sizeof(*best_clock
));
720 max_n
= limit
->n
.max
;
721 /* based on hardware requirement, prefer smaller n to precision */
722 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
723 /* based on hardware requirement, prefere larger m1,m2 */
724 for (clock
.m1
= limit
->m1
.max
;
725 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
726 for (clock
.m2
= limit
->m2
.max
;
727 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
728 for (clock
.p1
= limit
->p1
.max
;
729 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
732 i9xx_clock(refclk
, &clock
);
733 if (!intel_PLL_is_valid(dev
, limit
,
737 this_err
= abs(clock
.dot
- target
);
738 if (this_err
< err_most
) {
752 vlv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
753 int target
, int refclk
, intel_clock_t
*match_clock
,
754 intel_clock_t
*best_clock
)
756 struct drm_device
*dev
= crtc
->dev
;
758 unsigned int bestppm
= 1000000;
759 /* min update 19.2 MHz */
760 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
763 target
*= 5; /* fast clock */
765 memset(best_clock
, 0, sizeof(*best_clock
));
767 /* based on hardware requirement, prefer smaller n to precision */
768 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
769 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
770 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
771 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
772 clock
.p
= clock
.p1
* clock
.p2
;
773 /* based on hardware requirement, prefer bigger m1,m2 values */
774 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
775 unsigned int ppm
, diff
;
777 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
780 vlv_clock(refclk
, &clock
);
782 if (!intel_PLL_is_valid(dev
, limit
,
786 diff
= abs(clock
.dot
- target
);
787 ppm
= div_u64(1000000ULL * diff
, target
);
789 if (ppm
< 100 && clock
.p
> best_clock
->p
) {
795 if (bestppm
>= 10 && ppm
< bestppm
- 10) {
809 chv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
810 int target
, int refclk
, intel_clock_t
*match_clock
,
811 intel_clock_t
*best_clock
)
813 struct drm_device
*dev
= crtc
->dev
;
818 memset(best_clock
, 0, sizeof(*best_clock
));
821 * Based on hardware doc, the n always set to 1, and m1 always
822 * set to 2. If requires to support 200Mhz refclk, we need to
823 * revisit this because n may not 1 anymore.
825 clock
.n
= 1, clock
.m1
= 2;
826 target
*= 5; /* fast clock */
828 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
829 for (clock
.p2
= limit
->p2
.p2_fast
;
830 clock
.p2
>= limit
->p2
.p2_slow
;
831 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
833 clock
.p
= clock
.p1
* clock
.p2
;
835 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
836 clock
.n
) << 22, refclk
* clock
.m1
);
838 if (m2
> INT_MAX
/clock
.m1
)
843 chv_clock(refclk
, &clock
);
845 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
848 /* based on hardware requirement, prefer bigger p
850 if (clock
.p
> best_clock
->p
) {
860 bool intel_crtc_active(struct drm_crtc
*crtc
)
862 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
864 /* Be paranoid as we can arrive here with only partial
865 * state retrieved from the hardware during setup.
867 * We can ditch the adjusted_mode.crtc_clock check as soon
868 * as Haswell has gained clock readout/fastboot support.
870 * We can ditch the crtc->primary->fb check as soon as we can
871 * properly reconstruct framebuffers.
873 return intel_crtc
->active
&& crtc
->primary
->fb
&&
874 intel_crtc
->config
.adjusted_mode
.crtc_clock
;
877 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
880 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
881 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
883 return intel_crtc
->config
.cpu_transcoder
;
886 static void g4x_wait_for_vblank(struct drm_device
*dev
, int pipe
)
888 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
889 u32 frame
, frame_reg
= PIPE_FRMCOUNT_GM45(pipe
);
891 frame
= I915_READ(frame_reg
);
893 if (wait_for(I915_READ_NOTRACE(frame_reg
) != frame
, 50))
894 WARN(1, "vblank wait timed out\n");
898 * intel_wait_for_vblank - wait for vblank on a given pipe
900 * @pipe: pipe to wait for
902 * Wait for vblank to occur on a given pipe. Needed for various bits of
905 void intel_wait_for_vblank(struct drm_device
*dev
, int pipe
)
907 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
908 int pipestat_reg
= PIPESTAT(pipe
);
910 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5) {
911 g4x_wait_for_vblank(dev
, pipe
);
915 /* Clear existing vblank status. Note this will clear any other
916 * sticky status fields as well.
918 * This races with i915_driver_irq_handler() with the result
919 * that either function could miss a vblank event. Here it is not
920 * fatal, as we will either wait upon the next vblank interrupt or
921 * timeout. Generally speaking intel_wait_for_vblank() is only
922 * called during modeset at which time the GPU should be idle and
923 * should *not* be performing page flips and thus not waiting on
925 * Currently, the result of us stealing a vblank from the irq
926 * handler is that a single frame will be skipped during swapbuffers.
928 I915_WRITE(pipestat_reg
,
929 I915_READ(pipestat_reg
) | PIPE_VBLANK_INTERRUPT_STATUS
);
931 /* Wait for vblank interrupt bit to set */
932 if (wait_for(I915_READ(pipestat_reg
) &
933 PIPE_VBLANK_INTERRUPT_STATUS
,
935 DRM_DEBUG_KMS("vblank wait timed out\n");
938 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
940 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
941 u32 reg
= PIPEDSL(pipe
);
946 line_mask
= DSL_LINEMASK_GEN2
;
948 line_mask
= DSL_LINEMASK_GEN3
;
950 line1
= I915_READ(reg
) & line_mask
;
952 line2
= I915_READ(reg
) & line_mask
;
954 return line1
== line2
;
958 * intel_wait_for_pipe_off - wait for pipe to turn off
960 * @pipe: pipe to wait for
962 * After disabling a pipe, we can't wait for vblank in the usual way,
963 * spinning on the vblank interrupt status bit, since we won't actually
964 * see an interrupt when the pipe is disabled.
967 * wait for the pipe register state bit to turn off
970 * wait for the display line value to settle (it usually
971 * ends up stopping at the start of the next frame).
974 void intel_wait_for_pipe_off(struct drm_device
*dev
, int pipe
)
976 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
977 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
980 if (INTEL_INFO(dev
)->gen
>= 4) {
981 int reg
= PIPECONF(cpu_transcoder
);
983 /* Wait for the Pipe State to go off */
984 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
986 WARN(1, "pipe_off wait timed out\n");
988 /* Wait for the display line to settle */
989 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
990 WARN(1, "pipe_off wait timed out\n");
995 * ibx_digital_port_connected - is the specified port connected?
996 * @dev_priv: i915 private structure
997 * @port: the port to test
999 * Returns true if @port is connected, false otherwise.
1001 bool ibx_digital_port_connected(struct drm_i915_private
*dev_priv
,
1002 struct intel_digital_port
*port
)
1006 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1007 switch (port
->port
) {
1009 bit
= SDE_PORTB_HOTPLUG
;
1012 bit
= SDE_PORTC_HOTPLUG
;
1015 bit
= SDE_PORTD_HOTPLUG
;
1021 switch (port
->port
) {
1023 bit
= SDE_PORTB_HOTPLUG_CPT
;
1026 bit
= SDE_PORTC_HOTPLUG_CPT
;
1029 bit
= SDE_PORTD_HOTPLUG_CPT
;
1036 return I915_READ(SDEISR
) & bit
;
1039 static const char *state_string(bool enabled
)
1041 return enabled
? "on" : "off";
1044 /* Only for pre-ILK configs */
1045 void assert_pll(struct drm_i915_private
*dev_priv
,
1046 enum pipe pipe
, bool state
)
1053 val
= I915_READ(reg
);
1054 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1055 WARN(cur_state
!= state
,
1056 "PLL state assertion failure (expected %s, current %s)\n",
1057 state_string(state
), state_string(cur_state
));
1060 /* XXX: the dsi pll is shared between MIPI DSI ports */
1061 static void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1066 mutex_lock(&dev_priv
->dpio_lock
);
1067 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1068 mutex_unlock(&dev_priv
->dpio_lock
);
1070 cur_state
= val
& DSI_PLL_VCO_EN
;
1071 WARN(cur_state
!= state
,
1072 "DSI PLL state assertion failure (expected %s, current %s)\n",
1073 state_string(state
), state_string(cur_state
));
1075 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
1076 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
1078 struct intel_shared_dpll
*
1079 intel_crtc_to_shared_dpll(struct intel_crtc
*crtc
)
1081 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
1083 if (crtc
->config
.shared_dpll
< 0)
1086 return &dev_priv
->shared_dplls
[crtc
->config
.shared_dpll
];
1090 void assert_shared_dpll(struct drm_i915_private
*dev_priv
,
1091 struct intel_shared_dpll
*pll
,
1095 struct intel_dpll_hw_state hw_state
;
1097 if (HAS_PCH_LPT(dev_priv
->dev
)) {
1098 DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
1103 "asserting DPLL %s with no DPLL\n", state_string(state
)))
1106 cur_state
= pll
->get_hw_state(dev_priv
, pll
, &hw_state
);
1107 WARN(cur_state
!= state
,
1108 "%s assertion failure (expected %s, current %s)\n",
1109 pll
->name
, state_string(state
), state_string(cur_state
));
1112 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1113 enum pipe pipe
, bool state
)
1118 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1121 if (HAS_DDI(dev_priv
->dev
)) {
1122 /* DDI does not have a specific FDI_TX register */
1123 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1124 val
= I915_READ(reg
);
1125 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1127 reg
= FDI_TX_CTL(pipe
);
1128 val
= I915_READ(reg
);
1129 cur_state
= !!(val
& FDI_TX_ENABLE
);
1131 WARN(cur_state
!= state
,
1132 "FDI TX state assertion failure (expected %s, current %s)\n",
1133 state_string(state
), state_string(cur_state
));
1135 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1136 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1138 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1139 enum pipe pipe
, bool state
)
1145 reg
= FDI_RX_CTL(pipe
);
1146 val
= I915_READ(reg
);
1147 cur_state
= !!(val
& FDI_RX_ENABLE
);
1148 WARN(cur_state
!= state
,
1149 "FDI RX state assertion failure (expected %s, current %s)\n",
1150 state_string(state
), state_string(cur_state
));
1152 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1153 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1155 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1161 /* ILK FDI PLL is always enabled */
1162 if (INTEL_INFO(dev_priv
->dev
)->gen
== 5)
1165 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1166 if (HAS_DDI(dev_priv
->dev
))
1169 reg
= FDI_TX_CTL(pipe
);
1170 val
= I915_READ(reg
);
1171 WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1174 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1175 enum pipe pipe
, bool state
)
1181 reg
= FDI_RX_CTL(pipe
);
1182 val
= I915_READ(reg
);
1183 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1184 WARN(cur_state
!= state
,
1185 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1186 state_string(state
), state_string(cur_state
));
1189 static void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1192 int pp_reg
, lvds_reg
;
1194 enum pipe panel_pipe
= PIPE_A
;
1197 if (HAS_PCH_SPLIT(dev_priv
->dev
)) {
1198 pp_reg
= PCH_PP_CONTROL
;
1199 lvds_reg
= PCH_LVDS
;
1201 pp_reg
= PP_CONTROL
;
1205 val
= I915_READ(pp_reg
);
1206 if (!(val
& PANEL_POWER_ON
) ||
1207 ((val
& PANEL_UNLOCK_REGS
) == PANEL_UNLOCK_REGS
))
1210 if (I915_READ(lvds_reg
) & LVDS_PIPEB_SELECT
)
1211 panel_pipe
= PIPE_B
;
1213 WARN(panel_pipe
== pipe
&& locked
,
1214 "panel assertion failure, pipe %c regs locked\n",
1218 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1219 enum pipe pipe
, bool state
)
1221 struct drm_device
*dev
= dev_priv
->dev
;
1224 if (IS_845G(dev
) || IS_I865G(dev
))
1225 cur_state
= I915_READ(_CURACNTR
) & CURSOR_ENABLE
;
1227 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1229 WARN(cur_state
!= state
,
1230 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1231 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1233 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1234 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1236 void assert_pipe(struct drm_i915_private
*dev_priv
,
1237 enum pipe pipe
, bool state
)
1242 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1245 /* if we need the pipe A quirk it must be always on */
1246 if (pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
)
1249 if (!intel_display_power_enabled(dev_priv
,
1250 POWER_DOMAIN_TRANSCODER(cpu_transcoder
))) {
1253 reg
= PIPECONF(cpu_transcoder
);
1254 val
= I915_READ(reg
);
1255 cur_state
= !!(val
& PIPECONF_ENABLE
);
1258 WARN(cur_state
!= state
,
1259 "pipe %c assertion failure (expected %s, current %s)\n",
1260 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1263 static void assert_plane(struct drm_i915_private
*dev_priv
,
1264 enum plane plane
, bool state
)
1270 reg
= DSPCNTR(plane
);
1271 val
= I915_READ(reg
);
1272 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1273 WARN(cur_state
!= state
,
1274 "plane %c assertion failure (expected %s, current %s)\n",
1275 plane_name(plane
), state_string(state
), state_string(cur_state
));
1278 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1279 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1281 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1284 struct drm_device
*dev
= dev_priv
->dev
;
1289 /* Primary planes are fixed to pipes on gen4+ */
1290 if (INTEL_INFO(dev
)->gen
>= 4) {
1291 reg
= DSPCNTR(pipe
);
1292 val
= I915_READ(reg
);
1293 WARN(val
& DISPLAY_PLANE_ENABLE
,
1294 "plane %c assertion failure, should be disabled but not\n",
1299 /* Need to check both planes against the pipe */
1302 val
= I915_READ(reg
);
1303 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1304 DISPPLANE_SEL_PIPE_SHIFT
;
1305 WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1306 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1307 plane_name(i
), pipe_name(pipe
));
1311 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1314 struct drm_device
*dev
= dev_priv
->dev
;
1318 if (IS_VALLEYVIEW(dev
)) {
1319 for_each_sprite(pipe
, sprite
) {
1320 reg
= SPCNTR(pipe
, sprite
);
1321 val
= I915_READ(reg
);
1322 WARN(val
& SP_ENABLE
,
1323 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1324 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1326 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1328 val
= I915_READ(reg
);
1329 WARN(val
& SPRITE_ENABLE
,
1330 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1331 plane_name(pipe
), pipe_name(pipe
));
1332 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1333 reg
= DVSCNTR(pipe
);
1334 val
= I915_READ(reg
);
1335 WARN(val
& DVS_ENABLE
,
1336 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1337 plane_name(pipe
), pipe_name(pipe
));
1341 static void ibx_assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1346 WARN_ON(!(HAS_PCH_IBX(dev_priv
->dev
) || HAS_PCH_CPT(dev_priv
->dev
)));
1348 val
= I915_READ(PCH_DREF_CONTROL
);
1349 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1350 DREF_SUPERSPREAD_SOURCE_MASK
));
1351 WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1354 static void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1361 reg
= PCH_TRANSCONF(pipe
);
1362 val
= I915_READ(reg
);
1363 enabled
= !!(val
& TRANS_ENABLE
);
1365 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1369 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1370 enum pipe pipe
, u32 port_sel
, u32 val
)
1372 if ((val
& DP_PORT_EN
) == 0)
1375 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1376 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1377 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1378 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1380 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1381 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1384 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1390 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1391 enum pipe pipe
, u32 val
)
1393 if ((val
& SDVO_ENABLE
) == 0)
1396 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1397 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1399 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1400 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1403 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1409 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1410 enum pipe pipe
, u32 val
)
1412 if ((val
& LVDS_PORT_EN
) == 0)
1415 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1416 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1419 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1425 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1426 enum pipe pipe
, u32 val
)
1428 if ((val
& ADPA_DAC_ENABLE
) == 0)
1430 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1431 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1434 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1440 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1441 enum pipe pipe
, int reg
, u32 port_sel
)
1443 u32 val
= I915_READ(reg
);
1444 WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1445 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1446 reg
, pipe_name(pipe
));
1448 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1449 && (val
& DP_PIPEB_SELECT
),
1450 "IBX PCH dp port still using transcoder B\n");
1453 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1454 enum pipe pipe
, int reg
)
1456 u32 val
= I915_READ(reg
);
1457 WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1458 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1459 reg
, pipe_name(pipe
));
1461 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& SDVO_ENABLE
) == 0
1462 && (val
& SDVO_PIPE_B_SELECT
),
1463 "IBX PCH hdmi port still using transcoder B\n");
1466 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1472 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1473 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1474 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1477 val
= I915_READ(reg
);
1478 WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1479 "PCH VGA enabled on transcoder %c, should be disabled\n",
1483 val
= I915_READ(reg
);
1484 WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1485 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1488 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1489 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1490 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1493 static void intel_init_dpio(struct drm_device
*dev
)
1495 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1497 if (!IS_VALLEYVIEW(dev
))
1501 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
1502 * CHV x1 PHY (DP/HDMI D)
1503 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
1505 if (IS_CHERRYVIEW(dev
)) {
1506 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO_2
;
1507 DPIO_PHY_IOSF_PORT(DPIO_PHY1
) = IOSF_PORT_DPIO
;
1509 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO
;
1513 static void intel_reset_dpio(struct drm_device
*dev
)
1515 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1517 if (!IS_VALLEYVIEW(dev
))
1520 if (IS_CHERRYVIEW(dev
)) {
1524 for (phy
= DPIO_PHY0
; phy
< I915_NUM_PHYS_VLV
; phy
++) {
1525 /* Poll for phypwrgood signal */
1526 if (wait_for(I915_READ(DISPLAY_PHY_STATUS
) &
1527 PHY_POWERGOOD(phy
), 1))
1528 DRM_ERROR("Display PHY %d is not power up\n", phy
);
1531 * Deassert common lane reset for PHY.
1533 * This should only be done on init and resume from S3
1534 * with both PLLs disabled, or we risk losing DPIO and
1535 * PLL synchronization.
1537 val
= I915_READ(DISPLAY_PHY_CONTROL
);
1538 I915_WRITE(DISPLAY_PHY_CONTROL
,
1539 PHY_COM_LANE_RESET_DEASSERT(phy
, val
));
1544 * If DPIO has already been reset, e.g. by BIOS, just skip all
1547 if (I915_READ(DPIO_CTL
) & DPIO_CMNRST
)
1551 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
1552 * Need to assert and de-assert PHY SB reset by gating the
1553 * common lane power, then un-gating it.
1554 * Simply ungating isn't enough to reset the PHY enough to get
1555 * ports and lanes running.
1557 __vlv_set_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
,
1559 __vlv_set_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
,
1564 static void vlv_enable_pll(struct intel_crtc
*crtc
)
1566 struct drm_device
*dev
= crtc
->base
.dev
;
1567 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1568 int reg
= DPLL(crtc
->pipe
);
1569 u32 dpll
= crtc
->config
.dpll_hw_state
.dpll
;
1571 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1573 /* No really, not for ILK+ */
1574 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
));
1576 /* PLL is protected by panel, make sure we can write it */
1577 if (IS_MOBILE(dev_priv
->dev
) && !IS_I830(dev_priv
->dev
))
1578 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1580 I915_WRITE(reg
, dpll
);
1584 if (wait_for(((I915_READ(reg
) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1585 DRM_ERROR("DPLL %d failed to lock\n", crtc
->pipe
);
1587 I915_WRITE(DPLL_MD(crtc
->pipe
), crtc
->config
.dpll_hw_state
.dpll_md
);
1588 POSTING_READ(DPLL_MD(crtc
->pipe
));
1590 /* We do this three times for luck */
1591 I915_WRITE(reg
, dpll
);
1593 udelay(150); /* wait for warmup */
1594 I915_WRITE(reg
, dpll
);
1596 udelay(150); /* wait for warmup */
1597 I915_WRITE(reg
, dpll
);
1599 udelay(150); /* wait for warmup */
1602 static void chv_enable_pll(struct intel_crtc
*crtc
)
1604 struct drm_device
*dev
= crtc
->base
.dev
;
1605 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1606 int pipe
= crtc
->pipe
;
1607 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1610 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1612 BUG_ON(!IS_CHERRYVIEW(dev_priv
->dev
));
1614 mutex_lock(&dev_priv
->dpio_lock
);
1616 /* Enable back the 10bit clock to display controller */
1617 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1618 tmp
|= DPIO_DCLKP_EN
;
1619 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1622 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1627 I915_WRITE(DPLL(pipe
), crtc
->config
.dpll_hw_state
.dpll
);
1629 /* Check PLL is locked */
1630 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1631 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1633 /* not sure when this should be written */
1634 I915_WRITE(DPLL_MD(pipe
), crtc
->config
.dpll_hw_state
.dpll_md
);
1635 POSTING_READ(DPLL_MD(pipe
));
1637 mutex_unlock(&dev_priv
->dpio_lock
);
1640 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1642 struct drm_device
*dev
= crtc
->base
.dev
;
1643 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1644 int reg
= DPLL(crtc
->pipe
);
1645 u32 dpll
= crtc
->config
.dpll_hw_state
.dpll
;
1647 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1649 /* No really, not for ILK+ */
1650 BUG_ON(INTEL_INFO(dev
)->gen
>= 5);
1652 /* PLL is protected by panel, make sure we can write it */
1653 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1654 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1656 I915_WRITE(reg
, dpll
);
1658 /* Wait for the clocks to stabilize. */
1662 if (INTEL_INFO(dev
)->gen
>= 4) {
1663 I915_WRITE(DPLL_MD(crtc
->pipe
),
1664 crtc
->config
.dpll_hw_state
.dpll_md
);
1666 /* The pixel multiplier can only be updated once the
1667 * DPLL is enabled and the clocks are stable.
1669 * So write it again.
1671 I915_WRITE(reg
, dpll
);
1674 /* We do this three times for luck */
1675 I915_WRITE(reg
, dpll
);
1677 udelay(150); /* wait for warmup */
1678 I915_WRITE(reg
, dpll
);
1680 udelay(150); /* wait for warmup */
1681 I915_WRITE(reg
, dpll
);
1683 udelay(150); /* wait for warmup */
1687 * i9xx_disable_pll - disable a PLL
1688 * @dev_priv: i915 private structure
1689 * @pipe: pipe PLL to disable
1691 * Disable the PLL for @pipe, making sure the pipe is off first.
1693 * Note! This is for pre-ILK only.
1695 static void i9xx_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1697 /* Don't disable pipe A or pipe A PLLs if needed */
1698 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
1701 /* Make sure the pipe isn't still relying on us */
1702 assert_pipe_disabled(dev_priv
, pipe
);
1704 I915_WRITE(DPLL(pipe
), 0);
1705 POSTING_READ(DPLL(pipe
));
1708 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1712 /* Make sure the pipe isn't still relying on us */
1713 assert_pipe_disabled(dev_priv
, pipe
);
1716 * Leave integrated clock source and reference clock enabled for pipe B.
1717 * The latter is needed for VGA hotplug / manual detection.
1720 val
= DPLL_INTEGRATED_CRI_CLK_VLV
| DPLL_REFA_CLK_ENABLE_VLV
;
1721 I915_WRITE(DPLL(pipe
), val
);
1722 POSTING_READ(DPLL(pipe
));
1726 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1728 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1731 /* Make sure the pipe isn't still relying on us */
1732 assert_pipe_disabled(dev_priv
, pipe
);
1734 /* Set PLL en = 0 */
1735 val
= DPLL_SSC_REF_CLOCK_CHV
;
1737 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1738 I915_WRITE(DPLL(pipe
), val
);
1739 POSTING_READ(DPLL(pipe
));
1741 mutex_lock(&dev_priv
->dpio_lock
);
1743 /* Disable 10bit clock to display controller */
1744 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1745 val
&= ~DPIO_DCLKP_EN
;
1746 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1748 /* disable left/right clock distribution */
1749 if (pipe
!= PIPE_B
) {
1750 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
);
1751 val
&= ~(CHV_BUFLEFTENA1_MASK
| CHV_BUFRIGHTENA1_MASK
);
1752 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
, val
);
1754 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
);
1755 val
&= ~(CHV_BUFLEFTENA2_MASK
| CHV_BUFRIGHTENA2_MASK
);
1756 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
, val
);
1759 mutex_unlock(&dev_priv
->dpio_lock
);
1762 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1763 struct intel_digital_port
*dport
)
1768 switch (dport
->port
) {
1770 port_mask
= DPLL_PORTB_READY_MASK
;
1774 port_mask
= DPLL_PORTC_READY_MASK
;
1778 port_mask
= DPLL_PORTD_READY_MASK
;
1779 dpll_reg
= DPIO_PHY_STATUS
;
1785 if (wait_for((I915_READ(dpll_reg
) & port_mask
) == 0, 1000))
1786 WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
1787 port_name(dport
->port
), I915_READ(dpll_reg
));
1790 static void intel_prepare_shared_dpll(struct intel_crtc
*crtc
)
1792 struct drm_device
*dev
= crtc
->base
.dev
;
1793 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1794 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1796 if (WARN_ON(pll
== NULL
))
1799 WARN_ON(!pll
->refcount
);
1800 if (pll
->active
== 0) {
1801 DRM_DEBUG_DRIVER("setting up %s\n", pll
->name
);
1803 assert_shared_dpll_disabled(dev_priv
, pll
);
1805 pll
->mode_set(dev_priv
, pll
);
1810 * intel_enable_shared_dpll - enable PCH PLL
1811 * @dev_priv: i915 private structure
1812 * @pipe: pipe PLL to enable
1814 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1815 * drives the transcoder clock.
1817 static void intel_enable_shared_dpll(struct intel_crtc
*crtc
)
1819 struct drm_device
*dev
= crtc
->base
.dev
;
1820 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1821 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1823 if (WARN_ON(pll
== NULL
))
1826 if (WARN_ON(pll
->refcount
== 0))
1829 DRM_DEBUG_KMS("enable %s (active %d, on? %d)for crtc %d\n",
1830 pll
->name
, pll
->active
, pll
->on
,
1831 crtc
->base
.base
.id
);
1833 if (pll
->active
++) {
1835 assert_shared_dpll_enabled(dev_priv
, pll
);
1840 DRM_DEBUG_KMS("enabling %s\n", pll
->name
);
1841 pll
->enable(dev_priv
, pll
);
1845 static void intel_disable_shared_dpll(struct intel_crtc
*crtc
)
1847 struct drm_device
*dev
= crtc
->base
.dev
;
1848 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1849 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1851 /* PCH only available on ILK+ */
1852 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1853 if (WARN_ON(pll
== NULL
))
1856 if (WARN_ON(pll
->refcount
== 0))
1859 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1860 pll
->name
, pll
->active
, pll
->on
,
1861 crtc
->base
.base
.id
);
1863 if (WARN_ON(pll
->active
== 0)) {
1864 assert_shared_dpll_disabled(dev_priv
, pll
);
1868 assert_shared_dpll_enabled(dev_priv
, pll
);
1873 DRM_DEBUG_KMS("disabling %s\n", pll
->name
);
1874 pll
->disable(dev_priv
, pll
);
1878 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1881 struct drm_device
*dev
= dev_priv
->dev
;
1882 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1883 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1884 uint32_t reg
, val
, pipeconf_val
;
1886 /* PCH only available on ILK+ */
1887 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1889 /* Make sure PCH DPLL is enabled */
1890 assert_shared_dpll_enabled(dev_priv
,
1891 intel_crtc_to_shared_dpll(intel_crtc
));
1893 /* FDI must be feeding us bits for PCH ports */
1894 assert_fdi_tx_enabled(dev_priv
, pipe
);
1895 assert_fdi_rx_enabled(dev_priv
, pipe
);
1897 if (HAS_PCH_CPT(dev
)) {
1898 /* Workaround: Set the timing override bit before enabling the
1899 * pch transcoder. */
1900 reg
= TRANS_CHICKEN2(pipe
);
1901 val
= I915_READ(reg
);
1902 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1903 I915_WRITE(reg
, val
);
1906 reg
= PCH_TRANSCONF(pipe
);
1907 val
= I915_READ(reg
);
1908 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1910 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1912 * make the BPC in transcoder be consistent with
1913 * that in pipeconf reg.
1915 val
&= ~PIPECONF_BPC_MASK
;
1916 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1919 val
&= ~TRANS_INTERLACE_MASK
;
1920 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1921 if (HAS_PCH_IBX(dev_priv
->dev
) &&
1922 intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
))
1923 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1925 val
|= TRANS_INTERLACED
;
1927 val
|= TRANS_PROGRESSIVE
;
1929 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1930 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
1931 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1934 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1935 enum transcoder cpu_transcoder
)
1937 u32 val
, pipeconf_val
;
1939 /* PCH only available on ILK+ */
1940 BUG_ON(INTEL_INFO(dev_priv
->dev
)->gen
< 5);
1942 /* FDI must be feeding us bits for PCH ports */
1943 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1944 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1946 /* Workaround: set timing override bit. */
1947 val
= I915_READ(_TRANSA_CHICKEN2
);
1948 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1949 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1952 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1954 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1955 PIPECONF_INTERLACED_ILK
)
1956 val
|= TRANS_INTERLACED
;
1958 val
|= TRANS_PROGRESSIVE
;
1960 I915_WRITE(LPT_TRANSCONF
, val
);
1961 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
1962 DRM_ERROR("Failed to enable PCH transcoder\n");
1965 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1968 struct drm_device
*dev
= dev_priv
->dev
;
1971 /* FDI relies on the transcoder */
1972 assert_fdi_tx_disabled(dev_priv
, pipe
);
1973 assert_fdi_rx_disabled(dev_priv
, pipe
);
1975 /* Ports must be off as well */
1976 assert_pch_ports_disabled(dev_priv
, pipe
);
1978 reg
= PCH_TRANSCONF(pipe
);
1979 val
= I915_READ(reg
);
1980 val
&= ~TRANS_ENABLE
;
1981 I915_WRITE(reg
, val
);
1982 /* wait for PCH transcoder off, transcoder state */
1983 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
1984 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1986 if (!HAS_PCH_IBX(dev
)) {
1987 /* Workaround: Clear the timing override chicken bit again. */
1988 reg
= TRANS_CHICKEN2(pipe
);
1989 val
= I915_READ(reg
);
1990 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1991 I915_WRITE(reg
, val
);
1995 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1999 val
= I915_READ(LPT_TRANSCONF
);
2000 val
&= ~TRANS_ENABLE
;
2001 I915_WRITE(LPT_TRANSCONF
, val
);
2002 /* wait for PCH transcoder off, transcoder state */
2003 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
2004 DRM_ERROR("Failed to disable PCH transcoder\n");
2006 /* Workaround: clear timing override bit. */
2007 val
= I915_READ(_TRANSA_CHICKEN2
);
2008 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
2009 I915_WRITE(_TRANSA_CHICKEN2
, val
);
2013 * intel_enable_pipe - enable a pipe, asserting requirements
2014 * @crtc: crtc responsible for the pipe
2016 * Enable @crtc's pipe, making sure that various hardware specific requirements
2017 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
2019 static void intel_enable_pipe(struct intel_crtc
*crtc
)
2021 struct drm_device
*dev
= crtc
->base
.dev
;
2022 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2023 enum pipe pipe
= crtc
->pipe
;
2024 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
2026 enum pipe pch_transcoder
;
2030 assert_planes_disabled(dev_priv
, pipe
);
2031 assert_cursor_disabled(dev_priv
, pipe
);
2032 assert_sprites_disabled(dev_priv
, pipe
);
2034 if (HAS_PCH_LPT(dev_priv
->dev
))
2035 pch_transcoder
= TRANSCODER_A
;
2037 pch_transcoder
= pipe
;
2040 * A pipe without a PLL won't actually be able to drive bits from
2041 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
2044 if (!HAS_PCH_SPLIT(dev_priv
->dev
))
2045 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DSI
))
2046 assert_dsi_pll_enabled(dev_priv
);
2048 assert_pll_enabled(dev_priv
, pipe
);
2050 if (crtc
->config
.has_pch_encoder
) {
2051 /* if driving the PCH, we need FDI enabled */
2052 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
2053 assert_fdi_tx_pll_enabled(dev_priv
,
2054 (enum pipe
) cpu_transcoder
);
2056 /* FIXME: assert CPU port conditions for SNB+ */
2059 reg
= PIPECONF(cpu_transcoder
);
2060 val
= I915_READ(reg
);
2061 if (val
& PIPECONF_ENABLE
) {
2062 WARN_ON(!(pipe
== PIPE_A
&&
2063 dev_priv
->quirks
& QUIRK_PIPEA_FORCE
));
2067 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
2072 * intel_disable_pipe - disable a pipe, asserting requirements
2073 * @dev_priv: i915 private structure
2074 * @pipe: pipe to disable
2076 * Disable @pipe, making sure that various hardware specific requirements
2077 * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
2079 * @pipe should be %PIPE_A or %PIPE_B.
2081 * Will wait until the pipe has shut down before returning.
2083 static void intel_disable_pipe(struct drm_i915_private
*dev_priv
,
2086 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
2092 * Make sure planes won't keep trying to pump pixels to us,
2093 * or we might hang the display.
2095 assert_planes_disabled(dev_priv
, pipe
);
2096 assert_cursor_disabled(dev_priv
, pipe
);
2097 assert_sprites_disabled(dev_priv
, pipe
);
2099 /* Don't disable pipe A or pipe A PLLs if needed */
2100 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
2103 reg
= PIPECONF(cpu_transcoder
);
2104 val
= I915_READ(reg
);
2105 if ((val
& PIPECONF_ENABLE
) == 0)
2108 I915_WRITE(reg
, val
& ~PIPECONF_ENABLE
);
2109 intel_wait_for_pipe_off(dev_priv
->dev
, pipe
);
2113 * Plane regs are double buffered, going from enabled->disabled needs a
2114 * trigger in order to latch. The display address reg provides this.
2116 void intel_flush_primary_plane(struct drm_i915_private
*dev_priv
,
2119 struct drm_device
*dev
= dev_priv
->dev
;
2120 u32 reg
= INTEL_INFO(dev
)->gen
>= 4 ? DSPSURF(plane
) : DSPADDR(plane
);
2122 I915_WRITE(reg
, I915_READ(reg
));
2127 * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
2128 * @dev_priv: i915 private structure
2129 * @plane: plane to enable
2130 * @pipe: pipe being fed
2132 * Enable @plane on @pipe, making sure that @pipe is running first.
2134 static void intel_enable_primary_hw_plane(struct drm_i915_private
*dev_priv
,
2135 enum plane plane
, enum pipe pipe
)
2137 struct drm_device
*dev
= dev_priv
->dev
;
2138 struct intel_crtc
*intel_crtc
=
2139 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
2143 /* If the pipe isn't enabled, we can't pump pixels and may hang */
2144 assert_pipe_enabled(dev_priv
, pipe
);
2146 if (intel_crtc
->primary_enabled
)
2149 intel_crtc
->primary_enabled
= true;
2151 reg
= DSPCNTR(plane
);
2152 val
= I915_READ(reg
);
2153 WARN_ON(val
& DISPLAY_PLANE_ENABLE
);
2155 I915_WRITE(reg
, val
| DISPLAY_PLANE_ENABLE
);
2156 intel_flush_primary_plane(dev_priv
, plane
);
2159 * BDW signals flip done immediately if the plane
2160 * is disabled, even if the plane enable is already
2161 * armed to occur at the next vblank :(
2163 if (IS_BROADWELL(dev
))
2164 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2168 * intel_disable_primary_hw_plane - disable the primary hardware plane
2169 * @dev_priv: i915 private structure
2170 * @plane: plane to disable
2171 * @pipe: pipe consuming the data
2173 * Disable @plane; should be an independent operation.
2175 static void intel_disable_primary_hw_plane(struct drm_i915_private
*dev_priv
,
2176 enum plane plane
, enum pipe pipe
)
2178 struct intel_crtc
*intel_crtc
=
2179 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
2183 if (!intel_crtc
->primary_enabled
)
2186 intel_crtc
->primary_enabled
= false;
2188 reg
= DSPCNTR(plane
);
2189 val
= I915_READ(reg
);
2190 WARN_ON((val
& DISPLAY_PLANE_ENABLE
) == 0);
2192 I915_WRITE(reg
, val
& ~DISPLAY_PLANE_ENABLE
);
2193 intel_flush_primary_plane(dev_priv
, plane
);
2196 static bool need_vtd_wa(struct drm_device
*dev
)
2198 #ifdef CONFIG_INTEL_IOMMU
2199 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2205 static int intel_align_height(struct drm_device
*dev
, int height
, bool tiled
)
2209 tile_height
= tiled
? (IS_GEN2(dev
) ? 16 : 8) : 1;
2210 return ALIGN(height
, tile_height
);
2214 intel_pin_and_fence_fb_obj(struct drm_device
*dev
,
2215 struct drm_i915_gem_object
*obj
,
2216 struct intel_engine_cs
*pipelined
)
2218 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2222 switch (obj
->tiling_mode
) {
2223 case I915_TILING_NONE
:
2224 if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
2225 alignment
= 128 * 1024;
2226 else if (INTEL_INFO(dev
)->gen
>= 4)
2227 alignment
= 4 * 1024;
2229 alignment
= 64 * 1024;
2232 /* pin() will align the object as required by fence */
2236 WARN(1, "Y tiled bo slipped through, driver bug!\n");
2242 /* Note that the w/a also requires 64 PTE of padding following the
2243 * bo. We currently fill all unused PTE with the shadow page and so
2244 * we should always have valid PTE following the scanout preventing
2247 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2248 alignment
= 256 * 1024;
2250 dev_priv
->mm
.interruptible
= false;
2251 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
);
2253 goto err_interruptible
;
2255 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2256 * fence, whereas 965+ only requires a fence if using
2257 * framebuffer compression. For simplicity, we always install
2258 * a fence as the cost is not that onerous.
2260 ret
= i915_gem_object_get_fence(obj
);
2264 i915_gem_object_pin_fence(obj
);
2266 dev_priv
->mm
.interruptible
= true;
2270 i915_gem_object_unpin_from_display_plane(obj
);
2272 dev_priv
->mm
.interruptible
= true;
2276 void intel_unpin_fb_obj(struct drm_i915_gem_object
*obj
)
2278 i915_gem_object_unpin_fence(obj
);
2279 i915_gem_object_unpin_from_display_plane(obj
);
2282 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2283 * is assumed to be a power-of-two. */
2284 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
2285 unsigned int tiling_mode
,
2289 if (tiling_mode
!= I915_TILING_NONE
) {
2290 unsigned int tile_rows
, tiles
;
2295 tiles
= *x
/ (512/cpp
);
2298 return tile_rows
* pitch
* 8 + tiles
* 4096;
2300 unsigned int offset
;
2302 offset
= *y
* pitch
+ *x
* cpp
;
2304 *x
= (offset
& 4095) / cpp
;
2305 return offset
& -4096;
2309 int intel_format_to_fourcc(int format
)
2312 case DISPPLANE_8BPP
:
2313 return DRM_FORMAT_C8
;
2314 case DISPPLANE_BGRX555
:
2315 return DRM_FORMAT_XRGB1555
;
2316 case DISPPLANE_BGRX565
:
2317 return DRM_FORMAT_RGB565
;
2319 case DISPPLANE_BGRX888
:
2320 return DRM_FORMAT_XRGB8888
;
2321 case DISPPLANE_RGBX888
:
2322 return DRM_FORMAT_XBGR8888
;
2323 case DISPPLANE_BGRX101010
:
2324 return DRM_FORMAT_XRGB2101010
;
2325 case DISPPLANE_RGBX101010
:
2326 return DRM_FORMAT_XBGR2101010
;
2330 static bool intel_alloc_plane_obj(struct intel_crtc
*crtc
,
2331 struct intel_plane_config
*plane_config
)
2333 struct drm_device
*dev
= crtc
->base
.dev
;
2334 struct drm_i915_gem_object
*obj
= NULL
;
2335 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2336 u32 base
= plane_config
->base
;
2338 if (plane_config
->size
== 0)
2341 obj
= i915_gem_object_create_stolen_for_preallocated(dev
, base
, base
,
2342 plane_config
->size
);
2346 if (plane_config
->tiled
) {
2347 obj
->tiling_mode
= I915_TILING_X
;
2348 obj
->stride
= crtc
->base
.primary
->fb
->pitches
[0];
2351 mode_cmd
.pixel_format
= crtc
->base
.primary
->fb
->pixel_format
;
2352 mode_cmd
.width
= crtc
->base
.primary
->fb
->width
;
2353 mode_cmd
.height
= crtc
->base
.primary
->fb
->height
;
2354 mode_cmd
.pitches
[0] = crtc
->base
.primary
->fb
->pitches
[0];
2356 mutex_lock(&dev
->struct_mutex
);
2358 if (intel_framebuffer_init(dev
, to_intel_framebuffer(crtc
->base
.primary
->fb
),
2360 DRM_DEBUG_KMS("intel fb init failed\n");
2364 obj
->frontbuffer_bits
= INTEL_FRONTBUFFER_PRIMARY(crtc
->pipe
);
2365 mutex_unlock(&dev
->struct_mutex
);
2367 DRM_DEBUG_KMS("plane fb obj %p\n", obj
);
2371 drm_gem_object_unreference(&obj
->base
);
2372 mutex_unlock(&dev
->struct_mutex
);
2376 static void intel_find_plane_obj(struct intel_crtc
*intel_crtc
,
2377 struct intel_plane_config
*plane_config
)
2379 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2381 struct intel_crtc
*i
;
2382 struct intel_framebuffer
*fb
;
2384 if (!intel_crtc
->base
.primary
->fb
)
2387 if (intel_alloc_plane_obj(intel_crtc
, plane_config
))
2390 kfree(intel_crtc
->base
.primary
->fb
);
2391 intel_crtc
->base
.primary
->fb
= NULL
;
2394 * Failed to alloc the obj, check to see if we should share
2395 * an fb with another CRTC instead
2397 for_each_crtc(dev
, c
) {
2398 i
= to_intel_crtc(c
);
2400 if (c
== &intel_crtc
->base
)
2403 if (!i
->active
|| !c
->primary
->fb
)
2406 fb
= to_intel_framebuffer(c
->primary
->fb
);
2407 if (i915_gem_obj_ggtt_offset(fb
->obj
) == plane_config
->base
) {
2408 drm_framebuffer_reference(c
->primary
->fb
);
2409 intel_crtc
->base
.primary
->fb
= c
->primary
->fb
;
2410 fb
->obj
->frontbuffer_bits
|= INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
2416 static void i9xx_update_primary_plane(struct drm_crtc
*crtc
,
2417 struct drm_framebuffer
*fb
,
2420 struct drm_device
*dev
= crtc
->dev
;
2421 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2422 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2423 struct intel_framebuffer
*intel_fb
;
2424 struct drm_i915_gem_object
*obj
;
2425 int plane
= intel_crtc
->plane
;
2426 unsigned long linear_offset
;
2430 intel_fb
= to_intel_framebuffer(fb
);
2431 obj
= intel_fb
->obj
;
2433 reg
= DSPCNTR(plane
);
2434 dspcntr
= I915_READ(reg
);
2435 /* Mask out pixel format bits in case we change it */
2436 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
2437 switch (fb
->pixel_format
) {
2439 dspcntr
|= DISPPLANE_8BPP
;
2441 case DRM_FORMAT_XRGB1555
:
2442 case DRM_FORMAT_ARGB1555
:
2443 dspcntr
|= DISPPLANE_BGRX555
;
2445 case DRM_FORMAT_RGB565
:
2446 dspcntr
|= DISPPLANE_BGRX565
;
2448 case DRM_FORMAT_XRGB8888
:
2449 case DRM_FORMAT_ARGB8888
:
2450 dspcntr
|= DISPPLANE_BGRX888
;
2452 case DRM_FORMAT_XBGR8888
:
2453 case DRM_FORMAT_ABGR8888
:
2454 dspcntr
|= DISPPLANE_RGBX888
;
2456 case DRM_FORMAT_XRGB2101010
:
2457 case DRM_FORMAT_ARGB2101010
:
2458 dspcntr
|= DISPPLANE_BGRX101010
;
2460 case DRM_FORMAT_XBGR2101010
:
2461 case DRM_FORMAT_ABGR2101010
:
2462 dspcntr
|= DISPPLANE_RGBX101010
;
2468 if (INTEL_INFO(dev
)->gen
>= 4) {
2469 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2470 dspcntr
|= DISPPLANE_TILED
;
2472 dspcntr
&= ~DISPPLANE_TILED
;
2476 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2478 I915_WRITE(reg
, dspcntr
);
2480 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2482 if (INTEL_INFO(dev
)->gen
>= 4) {
2483 intel_crtc
->dspaddr_offset
=
2484 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2485 fb
->bits_per_pixel
/ 8,
2487 linear_offset
-= intel_crtc
->dspaddr_offset
;
2489 intel_crtc
->dspaddr_offset
= linear_offset
;
2492 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2493 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2495 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2496 if (INTEL_INFO(dev
)->gen
>= 4) {
2497 I915_WRITE(DSPSURF(plane
),
2498 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2499 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2500 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2502 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2506 static void ironlake_update_primary_plane(struct drm_crtc
*crtc
,
2507 struct drm_framebuffer
*fb
,
2510 struct drm_device
*dev
= crtc
->dev
;
2511 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2512 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2513 struct intel_framebuffer
*intel_fb
;
2514 struct drm_i915_gem_object
*obj
;
2515 int plane
= intel_crtc
->plane
;
2516 unsigned long linear_offset
;
2520 intel_fb
= to_intel_framebuffer(fb
);
2521 obj
= intel_fb
->obj
;
2523 reg
= DSPCNTR(plane
);
2524 dspcntr
= I915_READ(reg
);
2525 /* Mask out pixel format bits in case we change it */
2526 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
2527 switch (fb
->pixel_format
) {
2529 dspcntr
|= DISPPLANE_8BPP
;
2531 case DRM_FORMAT_RGB565
:
2532 dspcntr
|= DISPPLANE_BGRX565
;
2534 case DRM_FORMAT_XRGB8888
:
2535 case DRM_FORMAT_ARGB8888
:
2536 dspcntr
|= DISPPLANE_BGRX888
;
2538 case DRM_FORMAT_XBGR8888
:
2539 case DRM_FORMAT_ABGR8888
:
2540 dspcntr
|= DISPPLANE_RGBX888
;
2542 case DRM_FORMAT_XRGB2101010
:
2543 case DRM_FORMAT_ARGB2101010
:
2544 dspcntr
|= DISPPLANE_BGRX101010
;
2546 case DRM_FORMAT_XBGR2101010
:
2547 case DRM_FORMAT_ABGR2101010
:
2548 dspcntr
|= DISPPLANE_RGBX101010
;
2554 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2555 dspcntr
|= DISPPLANE_TILED
;
2557 dspcntr
&= ~DISPPLANE_TILED
;
2559 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2560 dspcntr
&= ~DISPPLANE_TRICKLE_FEED_DISABLE
;
2562 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2564 I915_WRITE(reg
, dspcntr
);
2566 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2567 intel_crtc
->dspaddr_offset
=
2568 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2569 fb
->bits_per_pixel
/ 8,
2571 linear_offset
-= intel_crtc
->dspaddr_offset
;
2573 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2574 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2576 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2577 I915_WRITE(DSPSURF(plane
),
2578 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2579 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2580 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2582 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2583 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2588 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2590 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
2591 int x
, int y
, enum mode_set_atomic state
)
2593 struct drm_device
*dev
= crtc
->dev
;
2594 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2596 if (dev_priv
->display
.disable_fbc
)
2597 dev_priv
->display
.disable_fbc(dev
);
2598 intel_increase_pllclock(dev
, to_intel_crtc(crtc
)->pipe
);
2600 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2605 void intel_display_handle_reset(struct drm_device
*dev
)
2607 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2608 struct drm_crtc
*crtc
;
2611 * Flips in the rings have been nuked by the reset,
2612 * so complete all pending flips so that user space
2613 * will get its events and not get stuck.
2615 * Also update the base address of all primary
2616 * planes to the the last fb to make sure we're
2617 * showing the correct fb after a reset.
2619 * Need to make two loops over the crtcs so that we
2620 * don't try to grab a crtc mutex before the
2621 * pending_flip_queue really got woken up.
2624 for_each_crtc(dev
, crtc
) {
2625 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2626 enum plane plane
= intel_crtc
->plane
;
2628 intel_prepare_page_flip(dev
, plane
);
2629 intel_finish_page_flip_plane(dev
, plane
);
2632 for_each_crtc(dev
, crtc
) {
2633 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2635 drm_modeset_lock(&crtc
->mutex
, NULL
);
2637 * FIXME: Once we have proper support for primary planes (and
2638 * disabling them without disabling the entire crtc) allow again
2639 * a NULL crtc->primary->fb.
2641 if (intel_crtc
->active
&& crtc
->primary
->fb
)
2642 dev_priv
->display
.update_primary_plane(crtc
,
2646 drm_modeset_unlock(&crtc
->mutex
);
2651 intel_finish_fb(struct drm_framebuffer
*old_fb
)
2653 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(old_fb
)->obj
;
2654 struct drm_i915_private
*dev_priv
= obj
->base
.dev
->dev_private
;
2655 bool was_interruptible
= dev_priv
->mm
.interruptible
;
2658 /* Big Hammer, we also need to ensure that any pending
2659 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2660 * current scanout is retired before unpinning the old
2663 * This should only fail upon a hung GPU, in which case we
2664 * can safely continue.
2666 dev_priv
->mm
.interruptible
= false;
2667 ret
= i915_gem_object_finish_gpu(obj
);
2668 dev_priv
->mm
.interruptible
= was_interruptible
;
2673 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
2675 struct drm_device
*dev
= crtc
->dev
;
2676 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2677 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2678 unsigned long flags
;
2681 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
2682 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
2685 spin_lock_irqsave(&dev
->event_lock
, flags
);
2686 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
2687 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2693 intel_pipe_set_base(struct drm_crtc
*crtc
, int x
, int y
,
2694 struct drm_framebuffer
*fb
)
2696 struct drm_device
*dev
= crtc
->dev
;
2697 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2698 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2699 enum pipe pipe
= intel_crtc
->pipe
;
2700 struct drm_framebuffer
*old_fb
;
2701 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(fb
)->obj
;
2704 if (intel_crtc_has_pending_flip(crtc
)) {
2705 DRM_ERROR("pipe is still busy with an old pageflip\n");
2711 DRM_ERROR("No FB bound\n");
2715 if (intel_crtc
->plane
> INTEL_INFO(dev
)->num_pipes
) {
2716 DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
2717 plane_name(intel_crtc
->plane
),
2718 INTEL_INFO(dev
)->num_pipes
);
2722 old_fb
= crtc
->primary
->fb
;
2724 mutex_lock(&dev
->struct_mutex
);
2725 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
2727 i915_gem_track_fb(to_intel_framebuffer(old_fb
)->obj
, obj
,
2728 INTEL_FRONTBUFFER_PRIMARY(pipe
));
2729 mutex_unlock(&dev
->struct_mutex
);
2731 DRM_ERROR("pin & fence failed\n");
2736 * Update pipe size and adjust fitter if needed: the reason for this is
2737 * that in compute_mode_changes we check the native mode (not the pfit
2738 * mode) to see if we can flip rather than do a full mode set. In the
2739 * fastboot case, we'll flip, but if we don't update the pipesrc and
2740 * pfit state, we'll end up with a big fb scanned out into the wrong
2743 * To fix this properly, we need to hoist the checks up into
2744 * compute_mode_changes (or above), check the actual pfit state and
2745 * whether the platform allows pfit disable with pipe active, and only
2746 * then update the pipesrc and pfit state, even on the flip path.
2748 if (i915
.fastboot
) {
2749 const struct drm_display_mode
*adjusted_mode
=
2750 &intel_crtc
->config
.adjusted_mode
;
2752 I915_WRITE(PIPESRC(intel_crtc
->pipe
),
2753 ((adjusted_mode
->crtc_hdisplay
- 1) << 16) |
2754 (adjusted_mode
->crtc_vdisplay
- 1));
2755 if (!intel_crtc
->config
.pch_pfit
.enabled
&&
2756 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
2757 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
2758 I915_WRITE(PF_CTL(intel_crtc
->pipe
), 0);
2759 I915_WRITE(PF_WIN_POS(intel_crtc
->pipe
), 0);
2760 I915_WRITE(PF_WIN_SZ(intel_crtc
->pipe
), 0);
2762 intel_crtc
->config
.pipe_src_w
= adjusted_mode
->crtc_hdisplay
;
2763 intel_crtc
->config
.pipe_src_h
= adjusted_mode
->crtc_vdisplay
;
2766 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2768 if (intel_crtc
->active
)
2769 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
2771 crtc
->primary
->fb
= fb
;
2776 if (intel_crtc
->active
&& old_fb
!= fb
)
2777 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2778 mutex_lock(&dev
->struct_mutex
);
2779 intel_unpin_fb_obj(to_intel_framebuffer(old_fb
)->obj
);
2780 mutex_unlock(&dev
->struct_mutex
);
2783 mutex_lock(&dev
->struct_mutex
);
2784 intel_update_fbc(dev
);
2785 mutex_unlock(&dev
->struct_mutex
);
2790 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
2792 struct drm_device
*dev
= crtc
->dev
;
2793 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2794 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2795 int pipe
= intel_crtc
->pipe
;
2798 /* enable normal train */
2799 reg
= FDI_TX_CTL(pipe
);
2800 temp
= I915_READ(reg
);
2801 if (IS_IVYBRIDGE(dev
)) {
2802 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2803 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2805 temp
&= ~FDI_LINK_TRAIN_NONE
;
2806 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2808 I915_WRITE(reg
, temp
);
2810 reg
= FDI_RX_CTL(pipe
);
2811 temp
= I915_READ(reg
);
2812 if (HAS_PCH_CPT(dev
)) {
2813 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2814 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
2816 temp
&= ~FDI_LINK_TRAIN_NONE
;
2817 temp
|= FDI_LINK_TRAIN_NONE
;
2819 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
2821 /* wait one idle pattern time */
2825 /* IVB wants error correction enabled */
2826 if (IS_IVYBRIDGE(dev
))
2827 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
2828 FDI_FE_ERRC_ENABLE
);
2831 static bool pipe_has_enabled_pch(struct intel_crtc
*crtc
)
2833 return crtc
->base
.enabled
&& crtc
->active
&&
2834 crtc
->config
.has_pch_encoder
;
2837 static void ivb_modeset_global_resources(struct drm_device
*dev
)
2839 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2840 struct intel_crtc
*pipe_B_crtc
=
2841 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
2842 struct intel_crtc
*pipe_C_crtc
=
2843 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]);
2847 * When everything is off disable fdi C so that we could enable fdi B
2848 * with all lanes. Note that we don't care about enabled pipes without
2849 * an enabled pch encoder.
2851 if (!pipe_has_enabled_pch(pipe_B_crtc
) &&
2852 !pipe_has_enabled_pch(pipe_C_crtc
)) {
2853 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
2854 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
2856 temp
= I915_READ(SOUTH_CHICKEN1
);
2857 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
2858 DRM_DEBUG_KMS("disabling fdi C rx\n");
2859 I915_WRITE(SOUTH_CHICKEN1
, temp
);
2863 /* The FDI link training functions for ILK/Ibexpeak. */
2864 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
2866 struct drm_device
*dev
= crtc
->dev
;
2867 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2868 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2869 int pipe
= intel_crtc
->pipe
;
2870 u32 reg
, temp
, tries
;
2872 /* FDI needs bits from pipe first */
2873 assert_pipe_enabled(dev_priv
, pipe
);
2875 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2877 reg
= FDI_RX_IMR(pipe
);
2878 temp
= I915_READ(reg
);
2879 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2880 temp
&= ~FDI_RX_BIT_LOCK
;
2881 I915_WRITE(reg
, temp
);
2885 /* enable CPU FDI TX and PCH FDI RX */
2886 reg
= FDI_TX_CTL(pipe
);
2887 temp
= I915_READ(reg
);
2888 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2889 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2890 temp
&= ~FDI_LINK_TRAIN_NONE
;
2891 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2892 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2894 reg
= FDI_RX_CTL(pipe
);
2895 temp
= I915_READ(reg
);
2896 temp
&= ~FDI_LINK_TRAIN_NONE
;
2897 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2898 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2903 /* Ironlake workaround, enable clock pointer after FDI enable*/
2904 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
2905 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
2906 FDI_RX_PHASE_SYNC_POINTER_EN
);
2908 reg
= FDI_RX_IIR(pipe
);
2909 for (tries
= 0; tries
< 5; tries
++) {
2910 temp
= I915_READ(reg
);
2911 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2913 if ((temp
& FDI_RX_BIT_LOCK
)) {
2914 DRM_DEBUG_KMS("FDI train 1 done.\n");
2915 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2920 DRM_ERROR("FDI train 1 fail!\n");
2923 reg
= FDI_TX_CTL(pipe
);
2924 temp
= I915_READ(reg
);
2925 temp
&= ~FDI_LINK_TRAIN_NONE
;
2926 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2927 I915_WRITE(reg
, temp
);
2929 reg
= FDI_RX_CTL(pipe
);
2930 temp
= I915_READ(reg
);
2931 temp
&= ~FDI_LINK_TRAIN_NONE
;
2932 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2933 I915_WRITE(reg
, temp
);
2938 reg
= FDI_RX_IIR(pipe
);
2939 for (tries
= 0; tries
< 5; tries
++) {
2940 temp
= I915_READ(reg
);
2941 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2943 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2944 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2945 DRM_DEBUG_KMS("FDI train 2 done.\n");
2950 DRM_ERROR("FDI train 2 fail!\n");
2952 DRM_DEBUG_KMS("FDI train done\n");
2956 static const int snb_b_fdi_train_param
[] = {
2957 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
2958 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
2959 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
2960 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
2963 /* The FDI link training functions for SNB/Cougarpoint. */
2964 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
2966 struct drm_device
*dev
= crtc
->dev
;
2967 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2968 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2969 int pipe
= intel_crtc
->pipe
;
2970 u32 reg
, temp
, i
, retry
;
2972 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2974 reg
= FDI_RX_IMR(pipe
);
2975 temp
= I915_READ(reg
);
2976 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2977 temp
&= ~FDI_RX_BIT_LOCK
;
2978 I915_WRITE(reg
, temp
);
2983 /* enable CPU FDI TX and PCH FDI RX */
2984 reg
= FDI_TX_CTL(pipe
);
2985 temp
= I915_READ(reg
);
2986 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2987 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2988 temp
&= ~FDI_LINK_TRAIN_NONE
;
2989 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2990 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2992 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2993 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2995 I915_WRITE(FDI_RX_MISC(pipe
),
2996 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
2998 reg
= FDI_RX_CTL(pipe
);
2999 temp
= I915_READ(reg
);
3000 if (HAS_PCH_CPT(dev
)) {
3001 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3002 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3004 temp
&= ~FDI_LINK_TRAIN_NONE
;
3005 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3007 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3012 for (i
= 0; i
< 4; i
++) {
3013 reg
= FDI_TX_CTL(pipe
);
3014 temp
= I915_READ(reg
);
3015 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3016 temp
|= snb_b_fdi_train_param
[i
];
3017 I915_WRITE(reg
, temp
);
3022 for (retry
= 0; retry
< 5; retry
++) {
3023 reg
= FDI_RX_IIR(pipe
);
3024 temp
= I915_READ(reg
);
3025 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3026 if (temp
& FDI_RX_BIT_LOCK
) {
3027 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3028 DRM_DEBUG_KMS("FDI train 1 done.\n");
3037 DRM_ERROR("FDI train 1 fail!\n");
3040 reg
= FDI_TX_CTL(pipe
);
3041 temp
= I915_READ(reg
);
3042 temp
&= ~FDI_LINK_TRAIN_NONE
;
3043 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3045 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3047 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3049 I915_WRITE(reg
, temp
);
3051 reg
= FDI_RX_CTL(pipe
);
3052 temp
= I915_READ(reg
);
3053 if (HAS_PCH_CPT(dev
)) {
3054 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3055 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3057 temp
&= ~FDI_LINK_TRAIN_NONE
;
3058 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3060 I915_WRITE(reg
, temp
);
3065 for (i
= 0; i
< 4; i
++) {
3066 reg
= FDI_TX_CTL(pipe
);
3067 temp
= I915_READ(reg
);
3068 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3069 temp
|= snb_b_fdi_train_param
[i
];
3070 I915_WRITE(reg
, temp
);
3075 for (retry
= 0; retry
< 5; retry
++) {
3076 reg
= FDI_RX_IIR(pipe
);
3077 temp
= I915_READ(reg
);
3078 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3079 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3080 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3081 DRM_DEBUG_KMS("FDI train 2 done.\n");
3090 DRM_ERROR("FDI train 2 fail!\n");
3092 DRM_DEBUG_KMS("FDI train done.\n");
3095 /* Manual link training for Ivy Bridge A0 parts */
3096 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3098 struct drm_device
*dev
= crtc
->dev
;
3099 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3100 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3101 int pipe
= intel_crtc
->pipe
;
3102 u32 reg
, temp
, i
, j
;
3104 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3106 reg
= FDI_RX_IMR(pipe
);
3107 temp
= I915_READ(reg
);
3108 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3109 temp
&= ~FDI_RX_BIT_LOCK
;
3110 I915_WRITE(reg
, temp
);
3115 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3116 I915_READ(FDI_RX_IIR(pipe
)));
3118 /* Try each vswing and preemphasis setting twice before moving on */
3119 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3120 /* disable first in case we need to retry */
3121 reg
= FDI_TX_CTL(pipe
);
3122 temp
= I915_READ(reg
);
3123 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3124 temp
&= ~FDI_TX_ENABLE
;
3125 I915_WRITE(reg
, temp
);
3127 reg
= FDI_RX_CTL(pipe
);
3128 temp
= I915_READ(reg
);
3129 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3130 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3131 temp
&= ~FDI_RX_ENABLE
;
3132 I915_WRITE(reg
, temp
);
3134 /* enable CPU FDI TX and PCH FDI RX */
3135 reg
= FDI_TX_CTL(pipe
);
3136 temp
= I915_READ(reg
);
3137 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3138 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3139 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3140 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3141 temp
|= snb_b_fdi_train_param
[j
/2];
3142 temp
|= FDI_COMPOSITE_SYNC
;
3143 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3145 I915_WRITE(FDI_RX_MISC(pipe
),
3146 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3148 reg
= FDI_RX_CTL(pipe
);
3149 temp
= I915_READ(reg
);
3150 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3151 temp
|= FDI_COMPOSITE_SYNC
;
3152 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3155 udelay(1); /* should be 0.5us */
3157 for (i
= 0; i
< 4; i
++) {
3158 reg
= FDI_RX_IIR(pipe
);
3159 temp
= I915_READ(reg
);
3160 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3162 if (temp
& FDI_RX_BIT_LOCK
||
3163 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3164 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3165 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3169 udelay(1); /* should be 0.5us */
3172 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3177 reg
= FDI_TX_CTL(pipe
);
3178 temp
= I915_READ(reg
);
3179 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3180 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3181 I915_WRITE(reg
, temp
);
3183 reg
= FDI_RX_CTL(pipe
);
3184 temp
= I915_READ(reg
);
3185 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3186 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3187 I915_WRITE(reg
, temp
);
3190 udelay(2); /* should be 1.5us */
3192 for (i
= 0; i
< 4; i
++) {
3193 reg
= FDI_RX_IIR(pipe
);
3194 temp
= I915_READ(reg
);
3195 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3197 if (temp
& FDI_RX_SYMBOL_LOCK
||
3198 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3199 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3200 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3204 udelay(2); /* should be 1.5us */
3207 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3211 DRM_DEBUG_KMS("FDI train done.\n");
3214 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3216 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3217 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3218 int pipe
= intel_crtc
->pipe
;
3222 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3223 reg
= FDI_RX_CTL(pipe
);
3224 temp
= I915_READ(reg
);
3225 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3226 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3227 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3228 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3233 /* Switch from Rawclk to PCDclk */
3234 temp
= I915_READ(reg
);
3235 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3240 /* Enable CPU FDI TX PLL, always on for Ironlake */
3241 reg
= FDI_TX_CTL(pipe
);
3242 temp
= I915_READ(reg
);
3243 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3244 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3251 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3253 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3254 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3255 int pipe
= intel_crtc
->pipe
;
3258 /* Switch from PCDclk to Rawclk */
3259 reg
= FDI_RX_CTL(pipe
);
3260 temp
= I915_READ(reg
);
3261 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3263 /* Disable CPU FDI TX PLL */
3264 reg
= FDI_TX_CTL(pipe
);
3265 temp
= I915_READ(reg
);
3266 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3271 reg
= FDI_RX_CTL(pipe
);
3272 temp
= I915_READ(reg
);
3273 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3275 /* Wait for the clocks to turn off. */
3280 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3282 struct drm_device
*dev
= crtc
->dev
;
3283 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3284 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3285 int pipe
= intel_crtc
->pipe
;
3288 /* disable CPU FDI tx and PCH FDI rx */
3289 reg
= FDI_TX_CTL(pipe
);
3290 temp
= I915_READ(reg
);
3291 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3294 reg
= FDI_RX_CTL(pipe
);
3295 temp
= I915_READ(reg
);
3296 temp
&= ~(0x7 << 16);
3297 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3298 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3303 /* Ironlake workaround, disable clock pointer after downing FDI */
3304 if (HAS_PCH_IBX(dev
))
3305 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3307 /* still set train pattern 1 */
3308 reg
= FDI_TX_CTL(pipe
);
3309 temp
= I915_READ(reg
);
3310 temp
&= ~FDI_LINK_TRAIN_NONE
;
3311 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3312 I915_WRITE(reg
, temp
);
3314 reg
= FDI_RX_CTL(pipe
);
3315 temp
= I915_READ(reg
);
3316 if (HAS_PCH_CPT(dev
)) {
3317 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3318 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3320 temp
&= ~FDI_LINK_TRAIN_NONE
;
3321 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3323 /* BPC in FDI rx is consistent with that in PIPECONF */
3324 temp
&= ~(0x07 << 16);
3325 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3326 I915_WRITE(reg
, temp
);
3332 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3334 struct intel_crtc
*crtc
;
3336 /* Note that we don't need to be called with mode_config.lock here
3337 * as our list of CRTC objects is static for the lifetime of the
3338 * device and so cannot disappear as we iterate. Similarly, we can
3339 * happily treat the predicates as racy, atomic checks as userspace
3340 * cannot claim and pin a new fb without at least acquring the
3341 * struct_mutex and so serialising with us.
3343 for_each_intel_crtc(dev
, crtc
) {
3344 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3347 if (crtc
->unpin_work
)
3348 intel_wait_for_vblank(dev
, crtc
->pipe
);
3356 void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3358 struct drm_device
*dev
= crtc
->dev
;
3359 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3361 if (crtc
->primary
->fb
== NULL
)
3364 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3366 WARN_ON(wait_event_timeout(dev_priv
->pending_flip_queue
,
3367 !intel_crtc_has_pending_flip(crtc
),
3370 mutex_lock(&dev
->struct_mutex
);
3371 intel_finish_fb(crtc
->primary
->fb
);
3372 mutex_unlock(&dev
->struct_mutex
);
3375 /* Program iCLKIP clock to the desired frequency */
3376 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3378 struct drm_device
*dev
= crtc
->dev
;
3379 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3380 int clock
= to_intel_crtc(crtc
)->config
.adjusted_mode
.crtc_clock
;
3381 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3384 mutex_lock(&dev_priv
->dpio_lock
);
3386 /* It is necessary to ungate the pixclk gate prior to programming
3387 * the divisors, and gate it back when it is done.
3389 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3391 /* Disable SSCCTL */
3392 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
3393 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
3397 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3398 if (clock
== 20000) {
3403 /* The iCLK virtual clock root frequency is in MHz,
3404 * but the adjusted_mode->crtc_clock in in KHz. To get the
3405 * divisors, it is necessary to divide one by another, so we
3406 * convert the virtual clock precision to KHz here for higher
3409 u32 iclk_virtual_root_freq
= 172800 * 1000;
3410 u32 iclk_pi_range
= 64;
3411 u32 desired_divisor
, msb_divisor_value
, pi_value
;
3413 desired_divisor
= (iclk_virtual_root_freq
/ clock
);
3414 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
3415 pi_value
= desired_divisor
% iclk_pi_range
;
3418 divsel
= msb_divisor_value
- 2;
3419 phaseinc
= pi_value
;
3422 /* This should not happen with any sane values */
3423 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3424 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3425 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3426 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3428 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3435 /* Program SSCDIVINTPHASE6 */
3436 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3437 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
3438 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
3439 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
3440 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
3441 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
3442 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
3443 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
3445 /* Program SSCAUXDIV */
3446 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3447 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3448 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
3449 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
3451 /* Enable modulator and associated divider */
3452 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3453 temp
&= ~SBI_SSCCTL_DISABLE
;
3454 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3456 /* Wait for initialization time */
3459 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
3461 mutex_unlock(&dev_priv
->dpio_lock
);
3464 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
3465 enum pipe pch_transcoder
)
3467 struct drm_device
*dev
= crtc
->base
.dev
;
3468 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3469 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
3471 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
3472 I915_READ(HTOTAL(cpu_transcoder
)));
3473 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
3474 I915_READ(HBLANK(cpu_transcoder
)));
3475 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
3476 I915_READ(HSYNC(cpu_transcoder
)));
3478 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
3479 I915_READ(VTOTAL(cpu_transcoder
)));
3480 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
3481 I915_READ(VBLANK(cpu_transcoder
)));
3482 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
3483 I915_READ(VSYNC(cpu_transcoder
)));
3484 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
3485 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
3488 static void cpt_enable_fdi_bc_bifurcation(struct drm_device
*dev
)
3490 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3493 temp
= I915_READ(SOUTH_CHICKEN1
);
3494 if (temp
& FDI_BC_BIFURCATION_SELECT
)
3497 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
3498 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
3500 temp
|= FDI_BC_BIFURCATION_SELECT
;
3501 DRM_DEBUG_KMS("enabling fdi C rx\n");
3502 I915_WRITE(SOUTH_CHICKEN1
, temp
);
3503 POSTING_READ(SOUTH_CHICKEN1
);
3506 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
3508 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3509 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3511 switch (intel_crtc
->pipe
) {
3515 if (intel_crtc
->config
.fdi_lanes
> 2)
3516 WARN_ON(I915_READ(SOUTH_CHICKEN1
) & FDI_BC_BIFURCATION_SELECT
);
3518 cpt_enable_fdi_bc_bifurcation(dev
);
3522 cpt_enable_fdi_bc_bifurcation(dev
);
3531 * Enable PCH resources required for PCH ports:
3533 * - FDI training & RX/TX
3534 * - update transcoder timings
3535 * - DP transcoding bits
3538 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
3540 struct drm_device
*dev
= crtc
->dev
;
3541 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3542 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3543 int pipe
= intel_crtc
->pipe
;
3546 assert_pch_transcoder_disabled(dev_priv
, pipe
);
3548 if (IS_IVYBRIDGE(dev
))
3549 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
3551 /* Write the TU size bits before fdi link training, so that error
3552 * detection works. */
3553 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
3554 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
3556 /* For PCH output, training FDI link */
3557 dev_priv
->display
.fdi_link_train(crtc
);
3559 /* We need to program the right clock selection before writing the pixel
3560 * mutliplier into the DPLL. */
3561 if (HAS_PCH_CPT(dev
)) {
3564 temp
= I915_READ(PCH_DPLL_SEL
);
3565 temp
|= TRANS_DPLL_ENABLE(pipe
);
3566 sel
= TRANS_DPLLB_SEL(pipe
);
3567 if (intel_crtc
->config
.shared_dpll
== DPLL_ID_PCH_PLL_B
)
3571 I915_WRITE(PCH_DPLL_SEL
, temp
);
3574 /* XXX: pch pll's can be enabled any time before we enable the PCH
3575 * transcoder, and we actually should do this to not upset any PCH
3576 * transcoder that already use the clock when we share it.
3578 * Note that enable_shared_dpll tries to do the right thing, but
3579 * get_shared_dpll unconditionally resets the pll - we need that to have
3580 * the right LVDS enable sequence. */
3581 intel_enable_shared_dpll(intel_crtc
);
3583 /* set transcoder timing, panel must allow it */
3584 assert_panel_unlocked(dev_priv
, pipe
);
3585 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
3587 intel_fdi_normal_train(crtc
);
3589 /* For PCH DP, enable TRANS_DP_CTL */
3590 if (HAS_PCH_CPT(dev
) &&
3591 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
3592 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3593 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
3594 reg
= TRANS_DP_CTL(pipe
);
3595 temp
= I915_READ(reg
);
3596 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
3597 TRANS_DP_SYNC_MASK
|
3599 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
3600 TRANS_DP_ENH_FRAMING
);
3601 temp
|= bpc
<< 9; /* same format but at 11:9 */
3603 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
3604 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
3605 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
3606 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
3608 switch (intel_trans_dp_port_sel(crtc
)) {
3610 temp
|= TRANS_DP_PORT_SEL_B
;
3613 temp
|= TRANS_DP_PORT_SEL_C
;
3616 temp
|= TRANS_DP_PORT_SEL_D
;
3622 I915_WRITE(reg
, temp
);
3625 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
3628 static void lpt_pch_enable(struct drm_crtc
*crtc
)
3630 struct drm_device
*dev
= crtc
->dev
;
3631 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3632 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3633 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
3635 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
3637 lpt_program_iclkip(crtc
);
3639 /* Set transcoder timing. */
3640 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
3642 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
3645 static void intel_put_shared_dpll(struct intel_crtc
*crtc
)
3647 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3652 if (pll
->refcount
== 0) {
3653 WARN(1, "bad %s refcount\n", pll
->name
);
3657 if (--pll
->refcount
== 0) {
3659 WARN_ON(pll
->active
);
3662 crtc
->config
.shared_dpll
= DPLL_ID_PRIVATE
;
3665 static struct intel_shared_dpll
*intel_get_shared_dpll(struct intel_crtc
*crtc
)
3667 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
3668 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3669 enum intel_dpll_id i
;
3672 DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
3673 crtc
->base
.base
.id
, pll
->name
);
3674 intel_put_shared_dpll(crtc
);
3677 if (HAS_PCH_IBX(dev_priv
->dev
)) {
3678 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3679 i
= (enum intel_dpll_id
) crtc
->pipe
;
3680 pll
= &dev_priv
->shared_dplls
[i
];
3682 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
3683 crtc
->base
.base
.id
, pll
->name
);
3685 WARN_ON(pll
->refcount
);
3690 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3691 pll
= &dev_priv
->shared_dplls
[i
];
3693 /* Only want to check enabled timings first */
3694 if (pll
->refcount
== 0)
3697 if (memcmp(&crtc
->config
.dpll_hw_state
, &pll
->hw_state
,
3698 sizeof(pll
->hw_state
)) == 0) {
3699 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
3701 pll
->name
, pll
->refcount
, pll
->active
);
3707 /* Ok no matching timings, maybe there's a free one? */
3708 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3709 pll
= &dev_priv
->shared_dplls
[i
];
3710 if (pll
->refcount
== 0) {
3711 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
3712 crtc
->base
.base
.id
, pll
->name
);
3720 if (pll
->refcount
== 0)
3721 pll
->hw_state
= crtc
->config
.dpll_hw_state
;
3723 crtc
->config
.shared_dpll
= i
;
3724 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll
->name
,
3725 pipe_name(crtc
->pipe
));
3732 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
3734 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3735 int dslreg
= PIPEDSL(pipe
);
3738 temp
= I915_READ(dslreg
);
3740 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
3741 if (wait_for(I915_READ(dslreg
) != temp
, 5))
3742 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
3746 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
3748 struct drm_device
*dev
= crtc
->base
.dev
;
3749 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3750 int pipe
= crtc
->pipe
;
3752 if (crtc
->config
.pch_pfit
.enabled
) {
3753 /* Force use of hard-coded filter coefficients
3754 * as some pre-programmed values are broken,
3757 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
3758 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
3759 PF_PIPE_SEL_IVB(pipe
));
3761 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
3762 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
.pch_pfit
.pos
);
3763 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
.pch_pfit
.size
);
3767 static void intel_enable_planes(struct drm_crtc
*crtc
)
3769 struct drm_device
*dev
= crtc
->dev
;
3770 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3771 struct drm_plane
*plane
;
3772 struct intel_plane
*intel_plane
;
3774 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3775 intel_plane
= to_intel_plane(plane
);
3776 if (intel_plane
->pipe
== pipe
)
3777 intel_plane_restore(&intel_plane
->base
);
3781 static void intel_disable_planes(struct drm_crtc
*crtc
)
3783 struct drm_device
*dev
= crtc
->dev
;
3784 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3785 struct drm_plane
*plane
;
3786 struct intel_plane
*intel_plane
;
3788 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3789 intel_plane
= to_intel_plane(plane
);
3790 if (intel_plane
->pipe
== pipe
)
3791 intel_plane_disable(&intel_plane
->base
);
3795 void hsw_enable_ips(struct intel_crtc
*crtc
)
3797 struct drm_device
*dev
= crtc
->base
.dev
;
3798 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3800 if (!crtc
->config
.ips_enabled
)
3803 /* We can only enable IPS after we enable a plane and wait for a vblank */
3804 intel_wait_for_vblank(dev
, crtc
->pipe
);
3806 assert_plane_enabled(dev_priv
, crtc
->plane
);
3807 if (IS_BROADWELL(dev
)) {
3808 mutex_lock(&dev_priv
->rps
.hw_lock
);
3809 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
3810 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3811 /* Quoting Art Runyan: "its not safe to expect any particular
3812 * value in IPS_CTL bit 31 after enabling IPS through the
3813 * mailbox." Moreover, the mailbox may return a bogus state,
3814 * so we need to just enable it and continue on.
3817 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
3818 /* The bit only becomes 1 in the next vblank, so this wait here
3819 * is essentially intel_wait_for_vblank. If we don't have this
3820 * and don't wait for vblanks until the end of crtc_enable, then
3821 * the HW state readout code will complain that the expected
3822 * IPS_CTL value is not the one we read. */
3823 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
3824 DRM_ERROR("Timed out waiting for IPS enable\n");
3828 void hsw_disable_ips(struct intel_crtc
*crtc
)
3830 struct drm_device
*dev
= crtc
->base
.dev
;
3831 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3833 if (!crtc
->config
.ips_enabled
)
3836 assert_plane_enabled(dev_priv
, crtc
->plane
);
3837 if (IS_BROADWELL(dev
)) {
3838 mutex_lock(&dev_priv
->rps
.hw_lock
);
3839 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
3840 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3841 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
3842 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
3843 DRM_ERROR("Timed out waiting for IPS disable\n");
3845 I915_WRITE(IPS_CTL
, 0);
3846 POSTING_READ(IPS_CTL
);
3849 /* We need to wait for a vblank before we can disable the plane. */
3850 intel_wait_for_vblank(dev
, crtc
->pipe
);
3853 /** Loads the palette/gamma unit for the CRTC with the prepared values */
3854 static void intel_crtc_load_lut(struct drm_crtc
*crtc
)
3856 struct drm_device
*dev
= crtc
->dev
;
3857 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3858 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3859 enum pipe pipe
= intel_crtc
->pipe
;
3860 int palreg
= PALETTE(pipe
);
3862 bool reenable_ips
= false;
3864 /* The clocks have to be on to load the palette. */
3865 if (!crtc
->enabled
|| !intel_crtc
->active
)
3868 if (!HAS_PCH_SPLIT(dev_priv
->dev
)) {
3869 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
))
3870 assert_dsi_pll_enabled(dev_priv
);
3872 assert_pll_enabled(dev_priv
, pipe
);
3875 /* use legacy palette for Ironlake */
3876 if (HAS_PCH_SPLIT(dev
))
3877 palreg
= LGC_PALETTE(pipe
);
3879 /* Workaround : Do not read or write the pipe palette/gamma data while
3880 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
3882 if (IS_HASWELL(dev
) && intel_crtc
->config
.ips_enabled
&&
3883 ((I915_READ(GAMMA_MODE(pipe
)) & GAMMA_MODE_MODE_MASK
) ==
3884 GAMMA_MODE_MODE_SPLIT
)) {
3885 hsw_disable_ips(intel_crtc
);
3886 reenable_ips
= true;
3889 for (i
= 0; i
< 256; i
++) {
3890 I915_WRITE(palreg
+ 4 * i
,
3891 (intel_crtc
->lut_r
[i
] << 16) |
3892 (intel_crtc
->lut_g
[i
] << 8) |
3893 intel_crtc
->lut_b
[i
]);
3897 hsw_enable_ips(intel_crtc
);
3900 static void intel_crtc_dpms_overlay(struct intel_crtc
*intel_crtc
, bool enable
)
3902 if (!enable
&& intel_crtc
->overlay
) {
3903 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3904 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3906 mutex_lock(&dev
->struct_mutex
);
3907 dev_priv
->mm
.interruptible
= false;
3908 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
3909 dev_priv
->mm
.interruptible
= true;
3910 mutex_unlock(&dev
->struct_mutex
);
3913 /* Let userspace switch the overlay on again. In most cases userspace
3914 * has to recompute where to put it anyway.
3919 * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
3920 * cursor plane briefly if not already running after enabling the display
3922 * This workaround avoids occasional blank screens when self refresh is
3926 g4x_fixup_plane(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
3928 u32 cntl
= I915_READ(CURCNTR(pipe
));
3930 if ((cntl
& CURSOR_MODE
) == 0) {
3931 u32 fw_bcl_self
= I915_READ(FW_BLC_SELF
);
3933 I915_WRITE(FW_BLC_SELF
, fw_bcl_self
& ~FW_BLC_SELF_EN
);
3934 I915_WRITE(CURCNTR(pipe
), CURSOR_MODE_64_ARGB_AX
);
3935 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
3936 I915_WRITE(CURCNTR(pipe
), cntl
);
3937 I915_WRITE(CURBASE(pipe
), I915_READ(CURBASE(pipe
)));
3938 I915_WRITE(FW_BLC_SELF
, fw_bcl_self
);
3942 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
)
3944 struct drm_device
*dev
= crtc
->dev
;
3945 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3946 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3947 int pipe
= intel_crtc
->pipe
;
3948 int plane
= intel_crtc
->plane
;
3950 drm_vblank_on(dev
, pipe
);
3952 intel_enable_primary_hw_plane(dev_priv
, plane
, pipe
);
3953 intel_enable_planes(crtc
);
3954 /* The fixup needs to happen before cursor is enabled */
3956 g4x_fixup_plane(dev_priv
, pipe
);
3957 intel_crtc_update_cursor(crtc
, true);
3958 intel_crtc_dpms_overlay(intel_crtc
, true);
3960 hsw_enable_ips(intel_crtc
);
3962 mutex_lock(&dev
->struct_mutex
);
3963 intel_update_fbc(dev
);
3964 mutex_unlock(&dev
->struct_mutex
);
3967 * FIXME: Once we grow proper nuclear flip support out of this we need
3968 * to compute the mask of flip planes precisely. For the time being
3969 * consider this a flip from a NULL plane.
3971 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
3974 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
)
3976 struct drm_device
*dev
= crtc
->dev
;
3977 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3978 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3979 int pipe
= intel_crtc
->pipe
;
3980 int plane
= intel_crtc
->plane
;
3982 intel_crtc_wait_for_pending_flips(crtc
);
3984 if (dev_priv
->fbc
.plane
== plane
)
3985 intel_disable_fbc(dev
);
3987 hsw_disable_ips(intel_crtc
);
3989 intel_crtc_dpms_overlay(intel_crtc
, false);
3990 intel_crtc_update_cursor(crtc
, false);
3991 intel_disable_planes(crtc
);
3992 intel_disable_primary_hw_plane(dev_priv
, plane
, pipe
);
3995 * FIXME: Once we grow proper nuclear flip support out of this we need
3996 * to compute the mask of flip planes precisely. For the time being
3997 * consider this a flip to a NULL plane.
3999 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
4001 drm_vblank_off(dev
, pipe
);
4004 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
4006 struct drm_device
*dev
= crtc
->dev
;
4007 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4008 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4009 struct intel_encoder
*encoder
;
4010 int pipe
= intel_crtc
->pipe
;
4011 enum plane plane
= intel_crtc
->plane
;
4013 WARN_ON(!crtc
->enabled
);
4015 if (intel_crtc
->active
)
4018 if (intel_crtc
->config
.has_pch_encoder
)
4019 intel_prepare_shared_dpll(intel_crtc
);
4021 if (intel_crtc
->config
.has_dp_encoder
)
4022 intel_dp_set_m_n(intel_crtc
);
4024 intel_set_pipe_timings(intel_crtc
);
4026 if (intel_crtc
->config
.has_pch_encoder
) {
4027 intel_cpu_transcoder_set_m_n(intel_crtc
,
4028 &intel_crtc
->config
.fdi_m_n
);
4031 ironlake_set_pipeconf(crtc
);
4033 /* Set up the display plane register */
4034 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
);
4035 POSTING_READ(DSPCNTR(plane
));
4037 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4040 intel_crtc
->active
= true;
4042 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4043 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
4045 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4046 if (encoder
->pre_enable
)
4047 encoder
->pre_enable(encoder
);
4049 if (intel_crtc
->config
.has_pch_encoder
) {
4050 /* Note: FDI PLL enabling _must_ be done before we enable the
4051 * cpu pipes, hence this is separate from all the other fdi/pch
4053 ironlake_fdi_pll_enable(intel_crtc
);
4055 assert_fdi_tx_disabled(dev_priv
, pipe
);
4056 assert_fdi_rx_disabled(dev_priv
, pipe
);
4059 ironlake_pfit_enable(intel_crtc
);
4062 * On ILK+ LUT must be loaded before the pipe is running but with
4065 intel_crtc_load_lut(crtc
);
4067 intel_update_watermarks(crtc
);
4068 intel_enable_pipe(intel_crtc
);
4070 if (intel_crtc
->config
.has_pch_encoder
)
4071 ironlake_pch_enable(crtc
);
4073 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4074 encoder
->enable(encoder
);
4076 if (HAS_PCH_CPT(dev
))
4077 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4079 intel_crtc_enable_planes(crtc
);
4082 /* IPS only exists on ULT machines and is tied to pipe A. */
4083 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4085 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4089 * This implements the workaround described in the "notes" section of the mode
4090 * set sequence documentation. When going from no pipes or single pipe to
4091 * multiple pipes, and planes are enabled after the pipe, we need to wait at
4092 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
4094 static void haswell_mode_set_planes_workaround(struct intel_crtc
*crtc
)
4096 struct drm_device
*dev
= crtc
->base
.dev
;
4097 struct intel_crtc
*crtc_it
, *other_active_crtc
= NULL
;
4099 /* We want to get the other_active_crtc only if there's only 1 other
4101 for_each_intel_crtc(dev
, crtc_it
) {
4102 if (!crtc_it
->active
|| crtc_it
== crtc
)
4105 if (other_active_crtc
)
4108 other_active_crtc
= crtc_it
;
4110 if (!other_active_crtc
)
4113 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4114 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4117 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4119 struct drm_device
*dev
= crtc
->dev
;
4120 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4121 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4122 struct intel_encoder
*encoder
;
4123 int pipe
= intel_crtc
->pipe
;
4124 enum plane plane
= intel_crtc
->plane
;
4126 WARN_ON(!crtc
->enabled
);
4128 if (intel_crtc
->active
)
4131 if (intel_crtc
->config
.has_dp_encoder
)
4132 intel_dp_set_m_n(intel_crtc
);
4134 intel_set_pipe_timings(intel_crtc
);
4136 if (intel_crtc
->config
.has_pch_encoder
) {
4137 intel_cpu_transcoder_set_m_n(intel_crtc
,
4138 &intel_crtc
->config
.fdi_m_n
);
4141 haswell_set_pipeconf(crtc
);
4143 intel_set_pipe_csc(crtc
);
4145 /* Set up the display plane register */
4146 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
| DISPPLANE_PIPE_CSC_ENABLE
);
4147 POSTING_READ(DSPCNTR(plane
));
4149 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4152 intel_crtc
->active
= true;
4154 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4155 if (intel_crtc
->config
.has_pch_encoder
)
4156 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
4158 if (intel_crtc
->config
.has_pch_encoder
)
4159 dev_priv
->display
.fdi_link_train(crtc
);
4161 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4162 if (encoder
->pre_enable
)
4163 encoder
->pre_enable(encoder
);
4165 intel_ddi_enable_pipe_clock(intel_crtc
);
4167 ironlake_pfit_enable(intel_crtc
);
4170 * On ILK+ LUT must be loaded before the pipe is running but with
4173 intel_crtc_load_lut(crtc
);
4175 intel_ddi_set_pipe_settings(crtc
);
4176 intel_ddi_enable_transcoder_func(crtc
);
4178 intel_update_watermarks(crtc
);
4179 intel_enable_pipe(intel_crtc
);
4181 if (intel_crtc
->config
.has_pch_encoder
)
4182 lpt_pch_enable(crtc
);
4184 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4185 encoder
->enable(encoder
);
4186 intel_opregion_notify_encoder(encoder
, true);
4189 /* If we change the relative order between pipe/planes enabling, we need
4190 * to change the workaround. */
4191 haswell_mode_set_planes_workaround(intel_crtc
);
4192 intel_crtc_enable_planes(crtc
);
4195 static void ironlake_pfit_disable(struct intel_crtc
*crtc
)
4197 struct drm_device
*dev
= crtc
->base
.dev
;
4198 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4199 int pipe
= crtc
->pipe
;
4201 /* To avoid upsetting the power well on haswell only disable the pfit if
4202 * it's in use. The hw state code will make sure we get this right. */
4203 if (crtc
->config
.pch_pfit
.enabled
) {
4204 I915_WRITE(PF_CTL(pipe
), 0);
4205 I915_WRITE(PF_WIN_POS(pipe
), 0);
4206 I915_WRITE(PF_WIN_SZ(pipe
), 0);
4210 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
4212 struct drm_device
*dev
= crtc
->dev
;
4213 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4214 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4215 struct intel_encoder
*encoder
;
4216 int pipe
= intel_crtc
->pipe
;
4219 if (!intel_crtc
->active
)
4222 intel_crtc_disable_planes(crtc
);
4224 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4225 encoder
->disable(encoder
);
4227 if (intel_crtc
->config
.has_pch_encoder
)
4228 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, false);
4230 intel_disable_pipe(dev_priv
, pipe
);
4232 ironlake_pfit_disable(intel_crtc
);
4234 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4235 if (encoder
->post_disable
)
4236 encoder
->post_disable(encoder
);
4238 if (intel_crtc
->config
.has_pch_encoder
) {
4239 ironlake_fdi_disable(crtc
);
4241 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
4242 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
4244 if (HAS_PCH_CPT(dev
)) {
4245 /* disable TRANS_DP_CTL */
4246 reg
= TRANS_DP_CTL(pipe
);
4247 temp
= I915_READ(reg
);
4248 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
4249 TRANS_DP_PORT_SEL_MASK
);
4250 temp
|= TRANS_DP_PORT_SEL_NONE
;
4251 I915_WRITE(reg
, temp
);
4253 /* disable DPLL_SEL */
4254 temp
= I915_READ(PCH_DPLL_SEL
);
4255 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
4256 I915_WRITE(PCH_DPLL_SEL
, temp
);
4259 /* disable PCH DPLL */
4260 intel_disable_shared_dpll(intel_crtc
);
4262 ironlake_fdi_pll_disable(intel_crtc
);
4265 intel_crtc
->active
= false;
4266 intel_update_watermarks(crtc
);
4268 mutex_lock(&dev
->struct_mutex
);
4269 intel_update_fbc(dev
);
4270 mutex_unlock(&dev
->struct_mutex
);
4273 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
4275 struct drm_device
*dev
= crtc
->dev
;
4276 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4277 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4278 struct intel_encoder
*encoder
;
4279 int pipe
= intel_crtc
->pipe
;
4280 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
4282 if (!intel_crtc
->active
)
4285 intel_crtc_disable_planes(crtc
);
4287 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4288 intel_opregion_notify_encoder(encoder
, false);
4289 encoder
->disable(encoder
);
4292 if (intel_crtc
->config
.has_pch_encoder
)
4293 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, false);
4294 intel_disable_pipe(dev_priv
, pipe
);
4296 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
4298 ironlake_pfit_disable(intel_crtc
);
4300 intel_ddi_disable_pipe_clock(intel_crtc
);
4302 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4303 if (encoder
->post_disable
)
4304 encoder
->post_disable(encoder
);
4306 if (intel_crtc
->config
.has_pch_encoder
) {
4307 lpt_disable_pch_transcoder(dev_priv
);
4308 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
4309 intel_ddi_fdi_disable(crtc
);
4312 intel_crtc
->active
= false;
4313 intel_update_watermarks(crtc
);
4315 mutex_lock(&dev
->struct_mutex
);
4316 intel_update_fbc(dev
);
4317 mutex_unlock(&dev
->struct_mutex
);
4320 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
4322 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4323 intel_put_shared_dpll(intel_crtc
);
4326 static void haswell_crtc_off(struct drm_crtc
*crtc
)
4328 intel_ddi_put_crtc_pll(crtc
);
4331 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
4333 struct drm_device
*dev
= crtc
->base
.dev
;
4334 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4335 struct intel_crtc_config
*pipe_config
= &crtc
->config
;
4337 if (!crtc
->config
.gmch_pfit
.control
)
4341 * The panel fitter should only be adjusted whilst the pipe is disabled,
4342 * according to register description and PRM.
4344 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
4345 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4347 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
4348 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
4350 /* Border color in case we don't scale up to the full screen. Black by
4351 * default, change to something else for debugging. */
4352 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
4355 #define for_each_power_domain(domain, mask) \
4356 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
4357 if ((1 << (domain)) & (mask))
4359 enum intel_display_power_domain
4360 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
4362 struct drm_device
*dev
= intel_encoder
->base
.dev
;
4363 struct intel_digital_port
*intel_dig_port
;
4365 switch (intel_encoder
->type
) {
4366 case INTEL_OUTPUT_UNKNOWN
:
4367 /* Only DDI platforms should ever use this output type */
4368 WARN_ON_ONCE(!HAS_DDI(dev
));
4369 case INTEL_OUTPUT_DISPLAYPORT
:
4370 case INTEL_OUTPUT_HDMI
:
4371 case INTEL_OUTPUT_EDP
:
4372 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
4373 switch (intel_dig_port
->port
) {
4375 return POWER_DOMAIN_PORT_DDI_A_4_LANES
;
4377 return POWER_DOMAIN_PORT_DDI_B_4_LANES
;
4379 return POWER_DOMAIN_PORT_DDI_C_4_LANES
;
4381 return POWER_DOMAIN_PORT_DDI_D_4_LANES
;
4384 return POWER_DOMAIN_PORT_OTHER
;
4386 case INTEL_OUTPUT_ANALOG
:
4387 return POWER_DOMAIN_PORT_CRT
;
4388 case INTEL_OUTPUT_DSI
:
4389 return POWER_DOMAIN_PORT_DSI
;
4391 return POWER_DOMAIN_PORT_OTHER
;
4395 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
)
4397 struct drm_device
*dev
= crtc
->dev
;
4398 struct intel_encoder
*intel_encoder
;
4399 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4400 enum pipe pipe
= intel_crtc
->pipe
;
4401 bool pfit_enabled
= intel_crtc
->config
.pch_pfit
.enabled
;
4403 enum transcoder transcoder
;
4405 transcoder
= intel_pipe_to_cpu_transcoder(dev
->dev_private
, pipe
);
4407 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
4408 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
4410 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
4412 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
4413 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
4418 void intel_display_set_init_power(struct drm_i915_private
*dev_priv
,
4421 if (dev_priv
->power_domains
.init_power_on
== enable
)
4425 intel_display_power_get(dev_priv
, POWER_DOMAIN_INIT
);
4427 intel_display_power_put(dev_priv
, POWER_DOMAIN_INIT
);
4429 dev_priv
->power_domains
.init_power_on
= enable
;
4432 static void modeset_update_crtc_power_domains(struct drm_device
*dev
)
4434 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4435 unsigned long pipe_domains
[I915_MAX_PIPES
] = { 0, };
4436 struct intel_crtc
*crtc
;
4439 * First get all needed power domains, then put all unneeded, to avoid
4440 * any unnecessary toggling of the power wells.
4442 for_each_intel_crtc(dev
, crtc
) {
4443 enum intel_display_power_domain domain
;
4445 if (!crtc
->base
.enabled
)
4448 pipe_domains
[crtc
->pipe
] = get_crtc_power_domains(&crtc
->base
);
4450 for_each_power_domain(domain
, pipe_domains
[crtc
->pipe
])
4451 intel_display_power_get(dev_priv
, domain
);
4454 for_each_intel_crtc(dev
, crtc
) {
4455 enum intel_display_power_domain domain
;
4457 for_each_power_domain(domain
, crtc
->enabled_power_domains
)
4458 intel_display_power_put(dev_priv
, domain
);
4460 crtc
->enabled_power_domains
= pipe_domains
[crtc
->pipe
];
4463 intel_display_set_init_power(dev_priv
, false);
4466 int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
4468 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
4470 /* Obtain SKU information */
4471 mutex_lock(&dev_priv
->dpio_lock
);
4472 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
4473 CCK_FUSE_HPLL_FREQ_MASK
;
4474 mutex_unlock(&dev_priv
->dpio_lock
);
4476 return vco_freq
[hpll_freq
];
4479 /* Adjust CDclk dividers to allow high res or save power if possible */
4480 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
4482 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4485 WARN_ON(valleyview_cur_cdclk(dev_priv
) != dev_priv
->vlv_cdclk_freq
);
4486 dev_priv
->vlv_cdclk_freq
= cdclk
;
4488 if (cdclk
>= 320) /* jump to highest voltage for 400MHz too */
4490 else if (cdclk
== 266)
4495 mutex_lock(&dev_priv
->rps
.hw_lock
);
4496 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
4497 val
&= ~DSPFREQGUAR_MASK
;
4498 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
4499 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
4500 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
4501 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
4503 DRM_ERROR("timed out waiting for CDclk change\n");
4505 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4510 vco
= valleyview_get_vco(dev_priv
);
4511 divider
= ((vco
<< 1) / cdclk
) - 1;
4513 mutex_lock(&dev_priv
->dpio_lock
);
4514 /* adjust cdclk divider */
4515 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
4518 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
4519 mutex_unlock(&dev_priv
->dpio_lock
);
4522 mutex_lock(&dev_priv
->dpio_lock
);
4523 /* adjust self-refresh exit latency value */
4524 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
4528 * For high bandwidth configs, we set a higher latency in the bunit
4529 * so that the core display fetch happens in time to avoid underruns.
4532 val
|= 4500 / 250; /* 4.5 usec */
4534 val
|= 3000 / 250; /* 3.0 usec */
4535 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
4536 mutex_unlock(&dev_priv
->dpio_lock
);
4538 /* Since we changed the CDclk, we need to update the GMBUSFREQ too */
4539 intel_i2c_reset(dev
);
4542 int valleyview_cur_cdclk(struct drm_i915_private
*dev_priv
)
4547 vco
= valleyview_get_vco(dev_priv
);
4549 mutex_lock(&dev_priv
->dpio_lock
);
4550 divider
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
4551 mutex_unlock(&dev_priv
->dpio_lock
);
4555 cur_cdclk
= (vco
<< 1) / (divider
+ 1);
4560 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
4564 * Really only a few cases to deal with, as only 4 CDclks are supported:
4569 * So we check to see whether we're above 90% of the lower bin and
4572 if (max_pixclk
> 288000) {
4574 } else if (max_pixclk
> 240000) {
4578 /* Looks like the 200MHz CDclk freq doesn't work on some configs */
4581 /* compute the max pixel clock for new configuration */
4582 static int intel_mode_max_pixclk(struct drm_i915_private
*dev_priv
)
4584 struct drm_device
*dev
= dev_priv
->dev
;
4585 struct intel_crtc
*intel_crtc
;
4588 for_each_intel_crtc(dev
, intel_crtc
) {
4589 if (intel_crtc
->new_enabled
)
4590 max_pixclk
= max(max_pixclk
,
4591 intel_crtc
->new_config
->adjusted_mode
.crtc_clock
);
4597 static void valleyview_modeset_global_pipes(struct drm_device
*dev
,
4598 unsigned *prepare_pipes
)
4600 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4601 struct intel_crtc
*intel_crtc
;
4602 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4604 if (valleyview_calc_cdclk(dev_priv
, max_pixclk
) ==
4605 dev_priv
->vlv_cdclk_freq
)
4608 /* disable/enable all currently active pipes while we change cdclk */
4609 for_each_intel_crtc(dev
, intel_crtc
)
4610 if (intel_crtc
->base
.enabled
)
4611 *prepare_pipes
|= (1 << intel_crtc
->pipe
);
4614 static void valleyview_modeset_global_resources(struct drm_device
*dev
)
4616 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4617 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4618 int req_cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
4620 if (req_cdclk
!= dev_priv
->vlv_cdclk_freq
)
4621 valleyview_set_cdclk(dev
, req_cdclk
);
4622 modeset_update_crtc_power_domains(dev
);
4625 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
4627 struct drm_device
*dev
= crtc
->dev
;
4628 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4629 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4630 struct intel_encoder
*encoder
;
4631 int pipe
= intel_crtc
->pipe
;
4632 int plane
= intel_crtc
->plane
;
4636 WARN_ON(!crtc
->enabled
);
4638 if (intel_crtc
->active
)
4641 is_dsi
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
);
4643 if (!is_dsi
&& !IS_CHERRYVIEW(dev
))
4644 vlv_prepare_pll(intel_crtc
);
4646 /* Set up the display plane register */
4647 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
4649 if (intel_crtc
->config
.has_dp_encoder
)
4650 intel_dp_set_m_n(intel_crtc
);
4652 intel_set_pipe_timings(intel_crtc
);
4654 /* pipesrc and dspsize control the size that is scaled from,
4655 * which should always be the user's requested size.
4657 I915_WRITE(DSPSIZE(plane
),
4658 ((intel_crtc
->config
.pipe_src_h
- 1) << 16) |
4659 (intel_crtc
->config
.pipe_src_w
- 1));
4660 I915_WRITE(DSPPOS(plane
), 0);
4662 i9xx_set_pipeconf(intel_crtc
);
4664 I915_WRITE(DSPCNTR(plane
), dspcntr
);
4665 POSTING_READ(DSPCNTR(plane
));
4667 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4670 intel_crtc
->active
= true;
4672 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4674 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4675 if (encoder
->pre_pll_enable
)
4676 encoder
->pre_pll_enable(encoder
);
4679 if (IS_CHERRYVIEW(dev
))
4680 chv_enable_pll(intel_crtc
);
4682 vlv_enable_pll(intel_crtc
);
4685 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4686 if (encoder
->pre_enable
)
4687 encoder
->pre_enable(encoder
);
4689 i9xx_pfit_enable(intel_crtc
);
4691 intel_crtc_load_lut(crtc
);
4693 intel_update_watermarks(crtc
);
4694 intel_enable_pipe(intel_crtc
);
4696 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4697 encoder
->enable(encoder
);
4699 intel_crtc_enable_planes(crtc
);
4701 /* Underruns don't raise interrupts, so check manually. */
4702 i9xx_check_fifo_underruns(dev
);
4705 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
4707 struct drm_device
*dev
= crtc
->base
.dev
;
4708 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4710 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp0
);
4711 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp1
);
4714 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
4716 struct drm_device
*dev
= crtc
->dev
;
4717 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4718 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4719 struct intel_encoder
*encoder
;
4720 int pipe
= intel_crtc
->pipe
;
4721 int plane
= intel_crtc
->plane
;
4724 WARN_ON(!crtc
->enabled
);
4726 if (intel_crtc
->active
)
4729 i9xx_set_pll_dividers(intel_crtc
);
4731 /* Set up the display plane register */
4732 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
4735 dspcntr
&= ~DISPPLANE_SEL_PIPE_MASK
;
4737 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
4739 if (intel_crtc
->config
.has_dp_encoder
)
4740 intel_dp_set_m_n(intel_crtc
);
4742 intel_set_pipe_timings(intel_crtc
);
4744 /* pipesrc and dspsize control the size that is scaled from,
4745 * which should always be the user's requested size.
4747 I915_WRITE(DSPSIZE(plane
),
4748 ((intel_crtc
->config
.pipe_src_h
- 1) << 16) |
4749 (intel_crtc
->config
.pipe_src_w
- 1));
4750 I915_WRITE(DSPPOS(plane
), 0);
4752 i9xx_set_pipeconf(intel_crtc
);
4754 I915_WRITE(DSPCNTR(plane
), dspcntr
);
4755 POSTING_READ(DSPCNTR(plane
));
4757 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4760 intel_crtc
->active
= true;
4763 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4765 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4766 if (encoder
->pre_enable
)
4767 encoder
->pre_enable(encoder
);
4769 i9xx_enable_pll(intel_crtc
);
4771 i9xx_pfit_enable(intel_crtc
);
4773 intel_crtc_load_lut(crtc
);
4775 intel_update_watermarks(crtc
);
4776 intel_enable_pipe(intel_crtc
);
4778 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4779 encoder
->enable(encoder
);
4781 intel_crtc_enable_planes(crtc
);
4784 * Gen2 reports pipe underruns whenever all planes are disabled.
4785 * So don't enable underrun reporting before at least some planes
4787 * FIXME: Need to fix the logic to work when we turn off all planes
4788 * but leave the pipe running.
4791 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4793 /* Underruns don't raise interrupts, so check manually. */
4794 i9xx_check_fifo_underruns(dev
);
4797 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
4799 struct drm_device
*dev
= crtc
->base
.dev
;
4800 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4802 if (!crtc
->config
.gmch_pfit
.control
)
4805 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4807 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
4808 I915_READ(PFIT_CONTROL
));
4809 I915_WRITE(PFIT_CONTROL
, 0);
4812 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
4814 struct drm_device
*dev
= crtc
->dev
;
4815 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4816 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4817 struct intel_encoder
*encoder
;
4818 int pipe
= intel_crtc
->pipe
;
4820 if (!intel_crtc
->active
)
4824 * Gen2 reports pipe underruns whenever all planes are disabled.
4825 * So diasble underrun reporting before all the planes get disabled.
4826 * FIXME: Need to fix the logic to work when we turn off all planes
4827 * but leave the pipe running.
4830 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, false);
4832 intel_crtc_disable_planes(crtc
);
4834 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4835 encoder
->disable(encoder
);
4838 * On gen2 planes are double buffered but the pipe isn't, so we must
4839 * wait for planes to fully turn off before disabling the pipe.
4842 intel_wait_for_vblank(dev
, pipe
);
4844 intel_disable_pipe(dev_priv
, pipe
);
4846 i9xx_pfit_disable(intel_crtc
);
4848 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4849 if (encoder
->post_disable
)
4850 encoder
->post_disable(encoder
);
4852 if (!intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
)) {
4853 if (IS_CHERRYVIEW(dev
))
4854 chv_disable_pll(dev_priv
, pipe
);
4855 else if (IS_VALLEYVIEW(dev
))
4856 vlv_disable_pll(dev_priv
, pipe
);
4858 i9xx_disable_pll(dev_priv
, pipe
);
4862 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, false);
4864 intel_crtc
->active
= false;
4865 intel_update_watermarks(crtc
);
4867 mutex_lock(&dev
->struct_mutex
);
4868 intel_update_fbc(dev
);
4869 mutex_unlock(&dev
->struct_mutex
);
4872 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
4876 static void intel_crtc_update_sarea(struct drm_crtc
*crtc
,
4879 struct drm_device
*dev
= crtc
->dev
;
4880 struct drm_i915_master_private
*master_priv
;
4881 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4882 int pipe
= intel_crtc
->pipe
;
4884 if (!dev
->primary
->master
)
4887 master_priv
= dev
->primary
->master
->driver_priv
;
4888 if (!master_priv
->sarea_priv
)
4893 master_priv
->sarea_priv
->pipeA_w
= enabled
? crtc
->mode
.hdisplay
: 0;
4894 master_priv
->sarea_priv
->pipeA_h
= enabled
? crtc
->mode
.vdisplay
: 0;
4897 master_priv
->sarea_priv
->pipeB_w
= enabled
? crtc
->mode
.hdisplay
: 0;
4898 master_priv
->sarea_priv
->pipeB_h
= enabled
? crtc
->mode
.vdisplay
: 0;
4901 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe
));
4907 * Sets the power management mode of the pipe and plane.
4909 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
4911 struct drm_device
*dev
= crtc
->dev
;
4912 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4913 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4914 struct intel_encoder
*intel_encoder
;
4915 enum intel_display_power_domain domain
;
4916 unsigned long domains
;
4917 bool enable
= false;
4919 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
4920 enable
|= intel_encoder
->connectors_active
;
4923 if (!intel_crtc
->active
) {
4925 * FIXME: DDI plls and relevant code isn't converted
4926 * yet, so do runtime PM for DPMS only for all other
4927 * platforms for now.
4929 if (!HAS_DDI(dev
)) {
4930 domains
= get_crtc_power_domains(crtc
);
4931 for_each_power_domain(domain
, domains
)
4932 intel_display_power_get(dev_priv
, domain
);
4933 intel_crtc
->enabled_power_domains
= domains
;
4936 dev_priv
->display
.crtc_enable(crtc
);
4939 if (intel_crtc
->active
) {
4940 dev_priv
->display
.crtc_disable(crtc
);
4942 if (!HAS_DDI(dev
)) {
4943 domains
= intel_crtc
->enabled_power_domains
;
4944 for_each_power_domain(domain
, domains
)
4945 intel_display_power_put(dev_priv
, domain
);
4946 intel_crtc
->enabled_power_domains
= 0;
4951 intel_crtc_update_sarea(crtc
, enable
);
4954 static void intel_crtc_disable(struct drm_crtc
*crtc
)
4956 struct drm_device
*dev
= crtc
->dev
;
4957 struct drm_connector
*connector
;
4958 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4959 struct drm_i915_gem_object
*old_obj
;
4960 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
4962 /* crtc should still be enabled when we disable it. */
4963 WARN_ON(!crtc
->enabled
);
4965 dev_priv
->display
.crtc_disable(crtc
);
4966 intel_crtc_update_sarea(crtc
, false);
4967 dev_priv
->display
.off(crtc
);
4969 assert_plane_disabled(dev
->dev_private
, to_intel_crtc(crtc
)->plane
);
4970 assert_cursor_disabled(dev_priv
, pipe
);
4971 assert_pipe_disabled(dev
->dev_private
, pipe
);
4973 if (crtc
->primary
->fb
) {
4974 old_obj
= to_intel_framebuffer(crtc
->primary
->fb
)->obj
;
4975 mutex_lock(&dev
->struct_mutex
);
4976 intel_unpin_fb_obj(old_obj
);
4977 i915_gem_track_fb(old_obj
, NULL
,
4978 INTEL_FRONTBUFFER_PRIMARY(pipe
));
4979 mutex_unlock(&dev
->struct_mutex
);
4980 crtc
->primary
->fb
= NULL
;
4983 /* Update computed state. */
4984 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
4985 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
4988 if (connector
->encoder
->crtc
!= crtc
)
4991 connector
->dpms
= DRM_MODE_DPMS_OFF
;
4992 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
4996 void intel_encoder_destroy(struct drm_encoder
*encoder
)
4998 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
5000 drm_encoder_cleanup(encoder
);
5001 kfree(intel_encoder
);
5004 /* Simple dpms helper for encoders with just one connector, no cloning and only
5005 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
5006 * state of the entire output pipe. */
5007 static void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
5009 if (mode
== DRM_MODE_DPMS_ON
) {
5010 encoder
->connectors_active
= true;
5012 intel_crtc_update_dpms(encoder
->base
.crtc
);
5014 encoder
->connectors_active
= false;
5016 intel_crtc_update_dpms(encoder
->base
.crtc
);
5020 /* Cross check the actual hw state with our own modeset state tracking (and it's
5021 * internal consistency). */
5022 static void intel_connector_check_state(struct intel_connector
*connector
)
5024 if (connector
->get_hw_state(connector
)) {
5025 struct intel_encoder
*encoder
= connector
->encoder
;
5026 struct drm_crtc
*crtc
;
5027 bool encoder_enabled
;
5030 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5031 connector
->base
.base
.id
,
5032 connector
->base
.name
);
5034 WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
5035 "wrong connector dpms state\n");
5036 WARN(connector
->base
.encoder
!= &encoder
->base
,
5037 "active connector not linked to encoder\n");
5038 WARN(!encoder
->connectors_active
,
5039 "encoder->connectors_active not set\n");
5041 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
5042 WARN(!encoder_enabled
, "encoder not enabled\n");
5043 if (WARN_ON(!encoder
->base
.crtc
))
5046 crtc
= encoder
->base
.crtc
;
5048 WARN(!crtc
->enabled
, "crtc not enabled\n");
5049 WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
5050 WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
5051 "encoder active on the wrong pipe\n");
5055 /* Even simpler default implementation, if there's really no special case to
5057 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
5059 /* All the simple cases only support two dpms states. */
5060 if (mode
!= DRM_MODE_DPMS_ON
)
5061 mode
= DRM_MODE_DPMS_OFF
;
5063 if (mode
== connector
->dpms
)
5066 connector
->dpms
= mode
;
5068 /* Only need to change hw state when actually enabled */
5069 if (connector
->encoder
)
5070 intel_encoder_dpms(to_intel_encoder(connector
->encoder
), mode
);
5072 intel_modeset_check_state(connector
->dev
);
5075 /* Simple connector->get_hw_state implementation for encoders that support only
5076 * one connector and no cloning and hence the encoder state determines the state
5077 * of the connector. */
5078 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
5081 struct intel_encoder
*encoder
= connector
->encoder
;
5083 return encoder
->get_hw_state(encoder
, &pipe
);
5086 static bool ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
5087 struct intel_crtc_config
*pipe_config
)
5089 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5090 struct intel_crtc
*pipe_B_crtc
=
5091 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
5093 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
5094 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5095 if (pipe_config
->fdi_lanes
> 4) {
5096 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
5097 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5101 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
5102 if (pipe_config
->fdi_lanes
> 2) {
5103 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
5104 pipe_config
->fdi_lanes
);
5111 if (INTEL_INFO(dev
)->num_pipes
== 2)
5114 /* Ivybridge 3 pipe is really complicated */
5119 if (dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]->enabled
&&
5120 pipe_config
->fdi_lanes
> 2) {
5121 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5122 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5127 if (!pipe_has_enabled_pch(pipe_B_crtc
) ||
5128 pipe_B_crtc
->config
.fdi_lanes
<= 2) {
5129 if (pipe_config
->fdi_lanes
> 2) {
5130 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5131 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5135 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5145 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
5146 struct intel_crtc_config
*pipe_config
)
5148 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5149 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5150 int lane
, link_bw
, fdi_dotclock
;
5151 bool setup_ok
, needs_recompute
= false;
5154 /* FDI is a binary signal running at ~2.7GHz, encoding
5155 * each output octet as 10 bits. The actual frequency
5156 * is stored as a divider into a 100MHz clock, and the
5157 * mode pixel clock is stored in units of 1KHz.
5158 * Hence the bw of each lane in terms of the mode signal
5161 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
5163 fdi_dotclock
= adjusted_mode
->crtc_clock
;
5165 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
5166 pipe_config
->pipe_bpp
);
5168 pipe_config
->fdi_lanes
= lane
;
5170 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
5171 link_bw
, &pipe_config
->fdi_m_n
);
5173 setup_ok
= ironlake_check_fdi_lanes(intel_crtc
->base
.dev
,
5174 intel_crtc
->pipe
, pipe_config
);
5175 if (!setup_ok
&& pipe_config
->pipe_bpp
> 6*3) {
5176 pipe_config
->pipe_bpp
-= 2*3;
5177 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
5178 pipe_config
->pipe_bpp
);
5179 needs_recompute
= true;
5180 pipe_config
->bw_constrained
= true;
5185 if (needs_recompute
)
5188 return setup_ok
? 0 : -EINVAL
;
5191 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
5192 struct intel_crtc_config
*pipe_config
)
5194 pipe_config
->ips_enabled
= i915
.enable_ips
&&
5195 hsw_crtc_supports_ips(crtc
) &&
5196 pipe_config
->pipe_bpp
<= 24;
5199 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
5200 struct intel_crtc_config
*pipe_config
)
5202 struct drm_device
*dev
= crtc
->base
.dev
;
5203 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5205 /* FIXME should check pixel clock limits on all platforms */
5206 if (INTEL_INFO(dev
)->gen
< 4) {
5207 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5209 dev_priv
->display
.get_display_clock_speed(dev
);
5212 * Enable pixel doubling when the dot clock
5213 * is > 90% of the (display) core speed.
5215 * GDG double wide on either pipe,
5216 * otherwise pipe A only.
5218 if ((crtc
->pipe
== PIPE_A
|| IS_I915G(dev
)) &&
5219 adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10) {
5221 pipe_config
->double_wide
= true;
5224 if (adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10)
5229 * Pipe horizontal size must be even in:
5231 * - LVDS dual channel mode
5232 * - Double wide pipe
5234 if ((intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5235 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
5236 pipe_config
->pipe_src_w
&= ~1;
5238 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
5239 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
5241 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
5242 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
5245 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) && pipe_config
->pipe_bpp
> 10*3) {
5246 pipe_config
->pipe_bpp
= 10*3; /* 12bpc is gen5+ */
5247 } else if (INTEL_INFO(dev
)->gen
<= 4 && pipe_config
->pipe_bpp
> 8*3) {
5248 /* only a 8bpc pipe, with 6bpc dither through the panel fitter
5250 pipe_config
->pipe_bpp
= 8*3;
5254 hsw_compute_ips_config(crtc
, pipe_config
);
5256 /* XXX: PCH clock sharing is done in ->mode_set, so make sure the old
5257 * clock survives for now. */
5258 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
5259 pipe_config
->shared_dpll
= crtc
->config
.shared_dpll
;
5261 if (pipe_config
->has_pch_encoder
)
5262 return ironlake_fdi_compute_config(crtc
, pipe_config
);
5267 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
5269 return 400000; /* FIXME */
5272 static int i945_get_display_clock_speed(struct drm_device
*dev
)
5277 static int i915_get_display_clock_speed(struct drm_device
*dev
)
5282 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
5287 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
5291 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5293 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5294 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
5296 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
5298 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
5300 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
5303 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
5304 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
5306 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
5311 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
5315 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5317 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
5320 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5321 case GC_DISPLAY_CLOCK_333_MHZ
:
5324 case GC_DISPLAY_CLOCK_190_200_MHZ
:
5330 static int i865_get_display_clock_speed(struct drm_device
*dev
)
5335 static int i855_get_display_clock_speed(struct drm_device
*dev
)
5338 /* Assume that the hardware is in the high speed state. This
5339 * should be the default.
5341 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
5342 case GC_CLOCK_133_200
:
5343 case GC_CLOCK_100_200
:
5345 case GC_CLOCK_166_250
:
5347 case GC_CLOCK_100_133
:
5351 /* Shouldn't happen */
5355 static int i830_get_display_clock_speed(struct drm_device
*dev
)
5361 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
5363 while (*num
> DATA_LINK_M_N_MASK
||
5364 *den
> DATA_LINK_M_N_MASK
) {
5370 static void compute_m_n(unsigned int m
, unsigned int n
,
5371 uint32_t *ret_m
, uint32_t *ret_n
)
5373 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
5374 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
5375 intel_reduce_m_n_ratio(ret_m
, ret_n
);
5379 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
5380 int pixel_clock
, int link_clock
,
5381 struct intel_link_m_n
*m_n
)
5385 compute_m_n(bits_per_pixel
* pixel_clock
,
5386 link_clock
* nlanes
* 8,
5387 &m_n
->gmch_m
, &m_n
->gmch_n
);
5389 compute_m_n(pixel_clock
, link_clock
,
5390 &m_n
->link_m
, &m_n
->link_n
);
5393 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
5395 if (i915
.panel_use_ssc
>= 0)
5396 return i915
.panel_use_ssc
!= 0;
5397 return dev_priv
->vbt
.lvds_use_ssc
5398 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
5401 static int i9xx_get_refclk(struct drm_crtc
*crtc
, int num_connectors
)
5403 struct drm_device
*dev
= crtc
->dev
;
5404 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5407 if (IS_VALLEYVIEW(dev
)) {
5409 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
5410 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
5411 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
5412 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
5413 } else if (!IS_GEN2(dev
)) {
5422 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
5424 return (1 << dpll
->n
) << 16 | dpll
->m2
;
5427 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
5429 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
5432 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
5433 intel_clock_t
*reduced_clock
)
5435 struct drm_device
*dev
= crtc
->base
.dev
;
5438 if (IS_PINEVIEW(dev
)) {
5439 fp
= pnv_dpll_compute_fp(&crtc
->config
.dpll
);
5441 fp2
= pnv_dpll_compute_fp(reduced_clock
);
5443 fp
= i9xx_dpll_compute_fp(&crtc
->config
.dpll
);
5445 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
5448 crtc
->config
.dpll_hw_state
.fp0
= fp
;
5450 crtc
->lowfreq_avail
= false;
5451 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5452 reduced_clock
&& i915
.powersave
) {
5453 crtc
->config
.dpll_hw_state
.fp1
= fp2
;
5454 crtc
->lowfreq_avail
= true;
5456 crtc
->config
.dpll_hw_state
.fp1
= fp
;
5460 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
5466 * PLLB opamp always calibrates to max value of 0x3f, force enable it
5467 * and set it to a reasonable value instead.
5469 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5470 reg_val
&= 0xffffff00;
5471 reg_val
|= 0x00000030;
5472 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5474 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5475 reg_val
&= 0x8cffffff;
5476 reg_val
= 0x8c000000;
5477 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5479 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5480 reg_val
&= 0xffffff00;
5481 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5483 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5484 reg_val
&= 0x00ffffff;
5485 reg_val
|= 0xb0000000;
5486 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5489 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
5490 struct intel_link_m_n
*m_n
)
5492 struct drm_device
*dev
= crtc
->base
.dev
;
5493 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5494 int pipe
= crtc
->pipe
;
5496 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5497 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
5498 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
5499 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
5502 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
5503 struct intel_link_m_n
*m_n
)
5505 struct drm_device
*dev
= crtc
->base
.dev
;
5506 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5507 int pipe
= crtc
->pipe
;
5508 enum transcoder transcoder
= crtc
->config
.cpu_transcoder
;
5510 if (INTEL_INFO(dev
)->gen
>= 5) {
5511 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5512 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
5513 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
5514 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
5516 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5517 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
5518 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
5519 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
5523 static void intel_dp_set_m_n(struct intel_crtc
*crtc
)
5525 if (crtc
->config
.has_pch_encoder
)
5526 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
5528 intel_cpu_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
5531 static void vlv_update_pll(struct intel_crtc
*crtc
)
5536 * Enable DPIO clock input. We should never disable the reference
5537 * clock for pipe B, since VGA hotplug / manual detection depends
5540 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
5541 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
5542 /* We should never disable this, set it here for state tracking */
5543 if (crtc
->pipe
== PIPE_B
)
5544 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5545 dpll
|= DPLL_VCO_ENABLE
;
5546 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5548 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
5549 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5550 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
5553 static void vlv_prepare_pll(struct intel_crtc
*crtc
)
5555 struct drm_device
*dev
= crtc
->base
.dev
;
5556 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5557 int pipe
= crtc
->pipe
;
5559 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
5560 u32 coreclk
, reg_val
;
5562 mutex_lock(&dev_priv
->dpio_lock
);
5564 bestn
= crtc
->config
.dpll
.n
;
5565 bestm1
= crtc
->config
.dpll
.m1
;
5566 bestm2
= crtc
->config
.dpll
.m2
;
5567 bestp1
= crtc
->config
.dpll
.p1
;
5568 bestp2
= crtc
->config
.dpll
.p2
;
5570 /* See eDP HDMI DPIO driver vbios notes doc */
5572 /* PLL B needs special handling */
5574 vlv_pllb_recal_opamp(dev_priv
, pipe
);
5576 /* Set up Tx target for periodic Rcomp update */
5577 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
5579 /* Disable target IRef on PLL */
5580 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
5581 reg_val
&= 0x00ffffff;
5582 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
5584 /* Disable fast lock */
5585 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
5587 /* Set idtafcrecal before PLL is enabled */
5588 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
5589 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
5590 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
5591 mdiv
|= (1 << DPIO_K_SHIFT
);
5594 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
5595 * but we don't support that).
5596 * Note: don't use the DAC post divider as it seems unstable.
5598 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
5599 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5601 mdiv
|= DPIO_ENABLE_CALIBRATION
;
5602 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5604 /* Set HBR and RBR LPF coefficients */
5605 if (crtc
->config
.port_clock
== 162000 ||
5606 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_ANALOG
) ||
5607 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
))
5608 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5611 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5614 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
) ||
5615 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
)) {
5616 /* Use SSC source */
5618 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5621 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5623 } else { /* HDMI or VGA */
5624 /* Use bend source */
5626 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5629 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5633 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
5634 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
5635 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
) ||
5636 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
))
5637 coreclk
|= 0x01000000;
5638 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
5640 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
5641 mutex_unlock(&dev_priv
->dpio_lock
);
5644 static void chv_update_pll(struct intel_crtc
*crtc
)
5646 struct drm_device
*dev
= crtc
->base
.dev
;
5647 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5648 int pipe
= crtc
->pipe
;
5649 int dpll_reg
= DPLL(crtc
->pipe
);
5650 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
5651 u32 loopfilter
, intcoeff
;
5652 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
5655 crtc
->config
.dpll_hw_state
.dpll
= DPLL_SSC_REF_CLOCK_CHV
|
5656 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
|
5659 crtc
->config
.dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5661 crtc
->config
.dpll_hw_state
.dpll_md
=
5662 (crtc
->config
.pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5664 bestn
= crtc
->config
.dpll
.n
;
5665 bestm2_frac
= crtc
->config
.dpll
.m2
& 0x3fffff;
5666 bestm1
= crtc
->config
.dpll
.m1
;
5667 bestm2
= crtc
->config
.dpll
.m2
>> 22;
5668 bestp1
= crtc
->config
.dpll
.p1
;
5669 bestp2
= crtc
->config
.dpll
.p2
;
5672 * Enable Refclk and SSC
5674 I915_WRITE(dpll_reg
,
5675 crtc
->config
.dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
5677 mutex_lock(&dev_priv
->dpio_lock
);
5679 /* p1 and p2 divider */
5680 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
5681 5 << DPIO_CHV_S1_DIV_SHIFT
|
5682 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
5683 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
5684 1 << DPIO_CHV_K_DIV_SHIFT
);
5686 /* Feedback post-divider - m2 */
5687 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
5689 /* Feedback refclk divider - n and m1 */
5690 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
5691 DPIO_CHV_M1_DIV_BY_2
|
5692 1 << DPIO_CHV_N_DIV_SHIFT
);
5694 /* M2 fraction division */
5695 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
5697 /* M2 fraction division enable */
5698 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
),
5699 DPIO_CHV_FRAC_DIV_EN
|
5700 (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
));
5703 refclk
= i9xx_get_refclk(&crtc
->base
, 0);
5704 loopfilter
= 5 << DPIO_CHV_PROP_COEFF_SHIFT
|
5705 2 << DPIO_CHV_GAIN_CTRL_SHIFT
;
5706 if (refclk
== 100000)
5708 else if (refclk
== 38400)
5712 loopfilter
|= intcoeff
<< DPIO_CHV_INT_COEFF_SHIFT
;
5713 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
5716 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
5717 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
5720 mutex_unlock(&dev_priv
->dpio_lock
);
5723 static void i9xx_update_pll(struct intel_crtc
*crtc
,
5724 intel_clock_t
*reduced_clock
,
5727 struct drm_device
*dev
= crtc
->base
.dev
;
5728 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5731 struct dpll
*clock
= &crtc
->config
.dpll
;
5733 i9xx_update_pll_dividers(crtc
, reduced_clock
);
5735 is_sdvo
= intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_SDVO
) ||
5736 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
);
5738 dpll
= DPLL_VGA_MODE_DIS
;
5740 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
))
5741 dpll
|= DPLLB_MODE_LVDS
;
5743 dpll
|= DPLLB_MODE_DAC_SERIAL
;
5745 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
5746 dpll
|= (crtc
->config
.pixel_multiplier
- 1)
5747 << SDVO_MULTIPLIER_SHIFT_HIRES
;
5751 dpll
|= DPLL_SDVO_HIGH_SPEED
;
5753 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
))
5754 dpll
|= DPLL_SDVO_HIGH_SPEED
;
5756 /* compute bitmask from p1 value */
5757 if (IS_PINEVIEW(dev
))
5758 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
5760 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5761 if (IS_G4X(dev
) && reduced_clock
)
5762 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
5764 switch (clock
->p2
) {
5766 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
5769 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
5772 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
5775 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
5778 if (INTEL_INFO(dev
)->gen
>= 4)
5779 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
5781 if (crtc
->config
.sdvo_tv_clock
)
5782 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
5783 else if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5784 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5785 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5787 dpll
|= PLL_REF_INPUT_DREFCLK
;
5789 dpll
|= DPLL_VCO_ENABLE
;
5790 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5792 if (INTEL_INFO(dev
)->gen
>= 4) {
5793 u32 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
5794 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5795 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
5799 static void i8xx_update_pll(struct intel_crtc
*crtc
,
5800 intel_clock_t
*reduced_clock
,
5803 struct drm_device
*dev
= crtc
->base
.dev
;
5804 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5806 struct dpll
*clock
= &crtc
->config
.dpll
;
5808 i9xx_update_pll_dividers(crtc
, reduced_clock
);
5810 dpll
= DPLL_VGA_MODE_DIS
;
5812 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
)) {
5813 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5816 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
5818 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5820 dpll
|= PLL_P2_DIVIDE_BY_4
;
5823 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DVO
))
5824 dpll
|= DPLL_DVO_2X_MODE
;
5826 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5827 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5828 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5830 dpll
|= PLL_REF_INPUT_DREFCLK
;
5832 dpll
|= DPLL_VCO_ENABLE
;
5833 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5836 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
5838 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5839 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5840 enum pipe pipe
= intel_crtc
->pipe
;
5841 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
5842 struct drm_display_mode
*adjusted_mode
=
5843 &intel_crtc
->config
.adjusted_mode
;
5844 uint32_t crtc_vtotal
, crtc_vblank_end
;
5847 /* We need to be careful not to changed the adjusted mode, for otherwise
5848 * the hw state checker will get angry at the mismatch. */
5849 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
5850 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
5852 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
5853 /* the chip adds 2 halflines automatically */
5855 crtc_vblank_end
-= 1;
5857 if (intel_pipe_has_type(&intel_crtc
->base
, INTEL_OUTPUT_SDVO
))
5858 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
5860 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
5861 adjusted_mode
->crtc_htotal
/ 2;
5863 vsyncshift
+= adjusted_mode
->crtc_htotal
;
5866 if (INTEL_INFO(dev
)->gen
> 3)
5867 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
5869 I915_WRITE(HTOTAL(cpu_transcoder
),
5870 (adjusted_mode
->crtc_hdisplay
- 1) |
5871 ((adjusted_mode
->crtc_htotal
- 1) << 16));
5872 I915_WRITE(HBLANK(cpu_transcoder
),
5873 (adjusted_mode
->crtc_hblank_start
- 1) |
5874 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
5875 I915_WRITE(HSYNC(cpu_transcoder
),
5876 (adjusted_mode
->crtc_hsync_start
- 1) |
5877 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
5879 I915_WRITE(VTOTAL(cpu_transcoder
),
5880 (adjusted_mode
->crtc_vdisplay
- 1) |
5881 ((crtc_vtotal
- 1) << 16));
5882 I915_WRITE(VBLANK(cpu_transcoder
),
5883 (adjusted_mode
->crtc_vblank_start
- 1) |
5884 ((crtc_vblank_end
- 1) << 16));
5885 I915_WRITE(VSYNC(cpu_transcoder
),
5886 (adjusted_mode
->crtc_vsync_start
- 1) |
5887 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
5889 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
5890 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
5891 * documented on the DDI_FUNC_CTL register description, EDP Input Select
5893 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
5894 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
5895 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
5897 /* pipesrc controls the size that is scaled from, which should
5898 * always be the user's requested size.
5900 I915_WRITE(PIPESRC(pipe
),
5901 ((intel_crtc
->config
.pipe_src_w
- 1) << 16) |
5902 (intel_crtc
->config
.pipe_src_h
- 1));
5905 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
5906 struct intel_crtc_config
*pipe_config
)
5908 struct drm_device
*dev
= crtc
->base
.dev
;
5909 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5910 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
5913 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
5914 pipe_config
->adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
5915 pipe_config
->adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
5916 tmp
= I915_READ(HBLANK(cpu_transcoder
));
5917 pipe_config
->adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
5918 pipe_config
->adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
5919 tmp
= I915_READ(HSYNC(cpu_transcoder
));
5920 pipe_config
->adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
5921 pipe_config
->adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
5923 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
5924 pipe_config
->adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
5925 pipe_config
->adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
5926 tmp
= I915_READ(VBLANK(cpu_transcoder
));
5927 pipe_config
->adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
5928 pipe_config
->adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
5929 tmp
= I915_READ(VSYNC(cpu_transcoder
));
5930 pipe_config
->adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
5931 pipe_config
->adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
5933 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
5934 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
5935 pipe_config
->adjusted_mode
.crtc_vtotal
+= 1;
5936 pipe_config
->adjusted_mode
.crtc_vblank_end
+= 1;
5939 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
5940 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
5941 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
5943 pipe_config
->requested_mode
.vdisplay
= pipe_config
->pipe_src_h
;
5944 pipe_config
->requested_mode
.hdisplay
= pipe_config
->pipe_src_w
;
5947 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
5948 struct intel_crtc_config
*pipe_config
)
5950 mode
->hdisplay
= pipe_config
->adjusted_mode
.crtc_hdisplay
;
5951 mode
->htotal
= pipe_config
->adjusted_mode
.crtc_htotal
;
5952 mode
->hsync_start
= pipe_config
->adjusted_mode
.crtc_hsync_start
;
5953 mode
->hsync_end
= pipe_config
->adjusted_mode
.crtc_hsync_end
;
5955 mode
->vdisplay
= pipe_config
->adjusted_mode
.crtc_vdisplay
;
5956 mode
->vtotal
= pipe_config
->adjusted_mode
.crtc_vtotal
;
5957 mode
->vsync_start
= pipe_config
->adjusted_mode
.crtc_vsync_start
;
5958 mode
->vsync_end
= pipe_config
->adjusted_mode
.crtc_vsync_end
;
5960 mode
->flags
= pipe_config
->adjusted_mode
.flags
;
5962 mode
->clock
= pipe_config
->adjusted_mode
.crtc_clock
;
5963 mode
->flags
|= pipe_config
->adjusted_mode
.flags
;
5966 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
5968 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5969 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5974 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
5975 I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
)
5976 pipeconf
|= PIPECONF_ENABLE
;
5978 if (intel_crtc
->config
.double_wide
)
5979 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
5981 /* only g4x and later have fancy bpc/dither controls */
5982 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
5983 /* Bspec claims that we can't use dithering for 30bpp pipes. */
5984 if (intel_crtc
->config
.dither
&& intel_crtc
->config
.pipe_bpp
!= 30)
5985 pipeconf
|= PIPECONF_DITHER_EN
|
5986 PIPECONF_DITHER_TYPE_SP
;
5988 switch (intel_crtc
->config
.pipe_bpp
) {
5990 pipeconf
|= PIPECONF_6BPC
;
5993 pipeconf
|= PIPECONF_8BPC
;
5996 pipeconf
|= PIPECONF_10BPC
;
5999 /* Case prevented by intel_choose_pipe_bpp_dither. */
6004 if (HAS_PIPE_CXSR(dev
)) {
6005 if (intel_crtc
->lowfreq_avail
) {
6006 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
6007 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
6009 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
6013 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
6014 if (INTEL_INFO(dev
)->gen
< 4 ||
6015 intel_pipe_has_type(&intel_crtc
->base
, INTEL_OUTPUT_SDVO
))
6016 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
6018 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
6020 pipeconf
|= PIPECONF_PROGRESSIVE
;
6022 if (IS_VALLEYVIEW(dev
) && intel_crtc
->config
.limited_color_range
)
6023 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
6025 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
6026 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
6029 static int i9xx_crtc_mode_set(struct drm_crtc
*crtc
,
6031 struct drm_framebuffer
*fb
)
6033 struct drm_device
*dev
= crtc
->dev
;
6034 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6035 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6036 int refclk
, num_connectors
= 0;
6037 intel_clock_t clock
, reduced_clock
;
6038 bool ok
, has_reduced_clock
= false;
6039 bool is_lvds
= false, is_dsi
= false;
6040 struct intel_encoder
*encoder
;
6041 const intel_limit_t
*limit
;
6043 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
6044 switch (encoder
->type
) {
6045 case INTEL_OUTPUT_LVDS
:
6048 case INTEL_OUTPUT_DSI
:
6059 if (!intel_crtc
->config
.clock_set
) {
6060 refclk
= i9xx_get_refclk(crtc
, num_connectors
);
6063 * Returns a set of divisors for the desired target clock with
6064 * the given refclk, or FALSE. The returned values represent
6065 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
6068 limit
= intel_limit(crtc
, refclk
);
6069 ok
= dev_priv
->display
.find_dpll(limit
, crtc
,
6070 intel_crtc
->config
.port_clock
,
6071 refclk
, NULL
, &clock
);
6073 DRM_ERROR("Couldn't find PLL settings for mode!\n");
6077 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
6079 * Ensure we match the reduced clock's P to the target
6080 * clock. If the clocks don't match, we can't switch
6081 * the display clock by using the FP0/FP1. In such case
6082 * we will disable the LVDS downclock feature.
6085 dev_priv
->display
.find_dpll(limit
, crtc
,
6086 dev_priv
->lvds_downclock
,
6090 /* Compat-code for transition, will disappear. */
6091 intel_crtc
->config
.dpll
.n
= clock
.n
;
6092 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
6093 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
6094 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
6095 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
6099 i8xx_update_pll(intel_crtc
,
6100 has_reduced_clock
? &reduced_clock
: NULL
,
6102 } else if (IS_CHERRYVIEW(dev
)) {
6103 chv_update_pll(intel_crtc
);
6104 } else if (IS_VALLEYVIEW(dev
)) {
6105 vlv_update_pll(intel_crtc
);
6107 i9xx_update_pll(intel_crtc
,
6108 has_reduced_clock
? &reduced_clock
: NULL
,
6115 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
6116 struct intel_crtc_config
*pipe_config
)
6118 struct drm_device
*dev
= crtc
->base
.dev
;
6119 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6122 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
6125 tmp
= I915_READ(PFIT_CONTROL
);
6126 if (!(tmp
& PFIT_ENABLE
))
6129 /* Check whether the pfit is attached to our pipe. */
6130 if (INTEL_INFO(dev
)->gen
< 4) {
6131 if (crtc
->pipe
!= PIPE_B
)
6134 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
6138 pipe_config
->gmch_pfit
.control
= tmp
;
6139 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
6140 if (INTEL_INFO(dev
)->gen
< 5)
6141 pipe_config
->gmch_pfit
.lvds_border_bits
=
6142 I915_READ(LVDS
) & LVDS_BORDER_ENABLE
;
6145 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
6146 struct intel_crtc_config
*pipe_config
)
6148 struct drm_device
*dev
= crtc
->base
.dev
;
6149 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6150 int pipe
= pipe_config
->cpu_transcoder
;
6151 intel_clock_t clock
;
6153 int refclk
= 100000;
6155 mutex_lock(&dev_priv
->dpio_lock
);
6156 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
6157 mutex_unlock(&dev_priv
->dpio_lock
);
6159 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
6160 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
6161 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
6162 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
6163 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
6165 vlv_clock(refclk
, &clock
);
6167 /* clock.dot is the fast clock */
6168 pipe_config
->port_clock
= clock
.dot
/ 5;
6171 static void i9xx_get_plane_config(struct intel_crtc
*crtc
,
6172 struct intel_plane_config
*plane_config
)
6174 struct drm_device
*dev
= crtc
->base
.dev
;
6175 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6176 u32 val
, base
, offset
;
6177 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
6178 int fourcc
, pixel_format
;
6181 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
6182 if (!crtc
->base
.primary
->fb
) {
6183 DRM_DEBUG_KMS("failed to alloc fb\n");
6187 val
= I915_READ(DSPCNTR(plane
));
6189 if (INTEL_INFO(dev
)->gen
>= 4)
6190 if (val
& DISPPLANE_TILED
)
6191 plane_config
->tiled
= true;
6193 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
6194 fourcc
= intel_format_to_fourcc(pixel_format
);
6195 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
6196 crtc
->base
.primary
->fb
->bits_per_pixel
=
6197 drm_format_plane_cpp(fourcc
, 0) * 8;
6199 if (INTEL_INFO(dev
)->gen
>= 4) {
6200 if (plane_config
->tiled
)
6201 offset
= I915_READ(DSPTILEOFF(plane
));
6203 offset
= I915_READ(DSPLINOFF(plane
));
6204 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
6206 base
= I915_READ(DSPADDR(plane
));
6208 plane_config
->base
= base
;
6210 val
= I915_READ(PIPESRC(pipe
));
6211 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
6212 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
6214 val
= I915_READ(DSPSTRIDE(pipe
));
6215 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffff80;
6217 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
6218 plane_config
->tiled
);
6220 plane_config
->size
= ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
6221 aligned_height
, PAGE_SIZE
);
6223 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
6224 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
6225 crtc
->base
.primary
->fb
->height
,
6226 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
6227 crtc
->base
.primary
->fb
->pitches
[0],
6228 plane_config
->size
);
6232 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
6233 struct intel_crtc_config
*pipe_config
)
6235 struct drm_device
*dev
= crtc
->base
.dev
;
6236 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6237 int pipe
= pipe_config
->cpu_transcoder
;
6238 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6239 intel_clock_t clock
;
6240 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
;
6241 int refclk
= 100000;
6243 mutex_lock(&dev_priv
->dpio_lock
);
6244 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
6245 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
6246 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
6247 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
6248 mutex_unlock(&dev_priv
->dpio_lock
);
6250 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
6251 clock
.m2
= ((pll_dw0
& 0xff) << 22) | (pll_dw2
& 0x3fffff);
6252 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
6253 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
6254 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
6256 chv_clock(refclk
, &clock
);
6258 /* clock.dot is the fast clock */
6259 pipe_config
->port_clock
= clock
.dot
/ 5;
6262 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
6263 struct intel_crtc_config
*pipe_config
)
6265 struct drm_device
*dev
= crtc
->base
.dev
;
6266 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6269 if (!intel_display_power_enabled(dev_priv
,
6270 POWER_DOMAIN_PIPE(crtc
->pipe
)))
6273 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
6274 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
6276 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
6277 if (!(tmp
& PIPECONF_ENABLE
))
6280 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
6281 switch (tmp
& PIPECONF_BPC_MASK
) {
6283 pipe_config
->pipe_bpp
= 18;
6286 pipe_config
->pipe_bpp
= 24;
6288 case PIPECONF_10BPC
:
6289 pipe_config
->pipe_bpp
= 30;
6296 if (IS_VALLEYVIEW(dev
) && (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
6297 pipe_config
->limited_color_range
= true;
6299 if (INTEL_INFO(dev
)->gen
< 4)
6300 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
6302 intel_get_pipe_timings(crtc
, pipe_config
);
6304 i9xx_get_pfit_config(crtc
, pipe_config
);
6306 if (INTEL_INFO(dev
)->gen
>= 4) {
6307 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
6308 pipe_config
->pixel_multiplier
=
6309 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
6310 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
6311 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
6312 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
6313 tmp
= I915_READ(DPLL(crtc
->pipe
));
6314 pipe_config
->pixel_multiplier
=
6315 ((tmp
& SDVO_MULTIPLIER_MASK
)
6316 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
6318 /* Note that on i915G/GM the pixel multiplier is in the sdvo
6319 * port and will be fixed up in the encoder->get_config
6321 pipe_config
->pixel_multiplier
= 1;
6323 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
6324 if (!IS_VALLEYVIEW(dev
)) {
6325 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
6326 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
6328 /* Mask out read-only status bits. */
6329 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
6330 DPLL_PORTC_READY_MASK
|
6331 DPLL_PORTB_READY_MASK
);
6334 if (IS_CHERRYVIEW(dev
))
6335 chv_crtc_clock_get(crtc
, pipe_config
);
6336 else if (IS_VALLEYVIEW(dev
))
6337 vlv_crtc_clock_get(crtc
, pipe_config
);
6339 i9xx_crtc_clock_get(crtc
, pipe_config
);
6344 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
6346 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6347 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
6348 struct intel_encoder
*encoder
;
6350 bool has_lvds
= false;
6351 bool has_cpu_edp
= false;
6352 bool has_panel
= false;
6353 bool has_ck505
= false;
6354 bool can_ssc
= false;
6356 /* We need to take the global config into account */
6357 list_for_each_entry(encoder
, &mode_config
->encoder_list
,
6359 switch (encoder
->type
) {
6360 case INTEL_OUTPUT_LVDS
:
6364 case INTEL_OUTPUT_EDP
:
6366 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
6372 if (HAS_PCH_IBX(dev
)) {
6373 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
6374 can_ssc
= has_ck505
;
6380 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
6381 has_panel
, has_lvds
, has_ck505
);
6383 /* Ironlake: try to setup display ref clock before DPLL
6384 * enabling. This is only under driver's control after
6385 * PCH B stepping, previous chipset stepping should be
6386 * ignoring this setting.
6388 val
= I915_READ(PCH_DREF_CONTROL
);
6390 /* As we must carefully and slowly disable/enable each source in turn,
6391 * compute the final state we want first and check if we need to
6392 * make any changes at all.
6395 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6397 final
|= DREF_NONSPREAD_CK505_ENABLE
;
6399 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6401 final
&= ~DREF_SSC_SOURCE_MASK
;
6402 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6403 final
&= ~DREF_SSC1_ENABLE
;
6406 final
|= DREF_SSC_SOURCE_ENABLE
;
6408 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6409 final
|= DREF_SSC1_ENABLE
;
6412 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6413 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6415 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6417 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6419 final
|= DREF_SSC_SOURCE_DISABLE
;
6420 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6426 /* Always enable nonspread source */
6427 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6430 val
|= DREF_NONSPREAD_CK505_ENABLE
;
6432 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6435 val
&= ~DREF_SSC_SOURCE_MASK
;
6436 val
|= DREF_SSC_SOURCE_ENABLE
;
6438 /* SSC must be turned on before enabling the CPU output */
6439 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6440 DRM_DEBUG_KMS("Using SSC on panel\n");
6441 val
|= DREF_SSC1_ENABLE
;
6443 val
&= ~DREF_SSC1_ENABLE
;
6445 /* Get SSC going before enabling the outputs */
6446 I915_WRITE(PCH_DREF_CONTROL
, val
);
6447 POSTING_READ(PCH_DREF_CONTROL
);
6450 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6452 /* Enable CPU source on CPU attached eDP */
6454 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6455 DRM_DEBUG_KMS("Using SSC on eDP\n");
6456 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6458 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6460 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6462 I915_WRITE(PCH_DREF_CONTROL
, val
);
6463 POSTING_READ(PCH_DREF_CONTROL
);
6466 DRM_DEBUG_KMS("Disabling SSC entirely\n");
6468 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6470 /* Turn off CPU output */
6471 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6473 I915_WRITE(PCH_DREF_CONTROL
, val
);
6474 POSTING_READ(PCH_DREF_CONTROL
);
6477 /* Turn off the SSC source */
6478 val
&= ~DREF_SSC_SOURCE_MASK
;
6479 val
|= DREF_SSC_SOURCE_DISABLE
;
6482 val
&= ~DREF_SSC1_ENABLE
;
6484 I915_WRITE(PCH_DREF_CONTROL
, val
);
6485 POSTING_READ(PCH_DREF_CONTROL
);
6489 BUG_ON(val
!= final
);
6492 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
6496 tmp
= I915_READ(SOUTH_CHICKEN2
);
6497 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
6498 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6500 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
6501 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
6502 DRM_ERROR("FDI mPHY reset assert timeout\n");
6504 tmp
= I915_READ(SOUTH_CHICKEN2
);
6505 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
6506 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6508 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
6509 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
6510 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
6513 /* WaMPhyProgramming:hsw */
6514 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
6518 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
6519 tmp
&= ~(0xFF << 24);
6520 tmp
|= (0x12 << 24);
6521 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
6523 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
6525 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
6527 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
6529 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
6531 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
6532 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6533 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
6535 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
6536 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6537 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
6539 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
6542 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
6544 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
6547 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
6549 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
6552 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
6554 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
6557 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
6559 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
6560 tmp
&= ~(0xFF << 16);
6561 tmp
|= (0x1C << 16);
6562 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
6564 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
6565 tmp
&= ~(0xFF << 16);
6566 tmp
|= (0x1C << 16);
6567 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
6569 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
6571 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
6573 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
6575 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
6577 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
6578 tmp
&= ~(0xF << 28);
6580 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
6582 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
6583 tmp
&= ~(0xF << 28);
6585 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
6588 /* Implements 3 different sequences from BSpec chapter "Display iCLK
6589 * Programming" based on the parameters passed:
6590 * - Sequence to enable CLKOUT_DP
6591 * - Sequence to enable CLKOUT_DP without spread
6592 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
6594 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
6597 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6600 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
6602 if (WARN(dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
&&
6603 with_fdi
, "LP PCH doesn't have FDI\n"))
6606 mutex_lock(&dev_priv
->dpio_lock
);
6608 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6609 tmp
&= ~SBI_SSCCTL_DISABLE
;
6610 tmp
|= SBI_SSCCTL_PATHALT
;
6611 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6616 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6617 tmp
&= ~SBI_SSCCTL_PATHALT
;
6618 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6621 lpt_reset_fdi_mphy(dev_priv
);
6622 lpt_program_fdi_mphy(dev_priv
);
6626 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6627 SBI_GEN0
: SBI_DBUFF0
;
6628 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6629 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6630 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6632 mutex_unlock(&dev_priv
->dpio_lock
);
6635 /* Sequence to disable CLKOUT_DP */
6636 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
6638 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6641 mutex_lock(&dev_priv
->dpio_lock
);
6643 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6644 SBI_GEN0
: SBI_DBUFF0
;
6645 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6646 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6647 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6649 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6650 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
6651 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
6652 tmp
|= SBI_SSCCTL_PATHALT
;
6653 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6656 tmp
|= SBI_SSCCTL_DISABLE
;
6657 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6660 mutex_unlock(&dev_priv
->dpio_lock
);
6663 static void lpt_init_pch_refclk(struct drm_device
*dev
)
6665 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
6666 struct intel_encoder
*encoder
;
6667 bool has_vga
= false;
6669 list_for_each_entry(encoder
, &mode_config
->encoder_list
, base
.head
) {
6670 switch (encoder
->type
) {
6671 case INTEL_OUTPUT_ANALOG
:
6678 lpt_enable_clkout_dp(dev
, true, true);
6680 lpt_disable_clkout_dp(dev
);
6684 * Initialize reference clocks when the driver loads
6686 void intel_init_pch_refclk(struct drm_device
*dev
)
6688 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
6689 ironlake_init_pch_refclk(dev
);
6690 else if (HAS_PCH_LPT(dev
))
6691 lpt_init_pch_refclk(dev
);
6694 static int ironlake_get_refclk(struct drm_crtc
*crtc
)
6696 struct drm_device
*dev
= crtc
->dev
;
6697 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6698 struct intel_encoder
*encoder
;
6699 int num_connectors
= 0;
6700 bool is_lvds
= false;
6702 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
6703 switch (encoder
->type
) {
6704 case INTEL_OUTPUT_LVDS
:
6711 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
6712 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
6713 dev_priv
->vbt
.lvds_ssc_freq
);
6714 return dev_priv
->vbt
.lvds_ssc_freq
;
6720 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
6722 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
6723 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6724 int pipe
= intel_crtc
->pipe
;
6729 switch (intel_crtc
->config
.pipe_bpp
) {
6731 val
|= PIPECONF_6BPC
;
6734 val
|= PIPECONF_8BPC
;
6737 val
|= PIPECONF_10BPC
;
6740 val
|= PIPECONF_12BPC
;
6743 /* Case prevented by intel_choose_pipe_bpp_dither. */
6747 if (intel_crtc
->config
.dither
)
6748 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
6750 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
6751 val
|= PIPECONF_INTERLACED_ILK
;
6753 val
|= PIPECONF_PROGRESSIVE
;
6755 if (intel_crtc
->config
.limited_color_range
)
6756 val
|= PIPECONF_COLOR_RANGE_SELECT
;
6758 I915_WRITE(PIPECONF(pipe
), val
);
6759 POSTING_READ(PIPECONF(pipe
));
6763 * Set up the pipe CSC unit.
6765 * Currently only full range RGB to limited range RGB conversion
6766 * is supported, but eventually this should handle various
6767 * RGB<->YCbCr scenarios as well.
6769 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
6771 struct drm_device
*dev
= crtc
->dev
;
6772 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6773 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6774 int pipe
= intel_crtc
->pipe
;
6775 uint16_t coeff
= 0x7800; /* 1.0 */
6778 * TODO: Check what kind of values actually come out of the pipe
6779 * with these coeff/postoff values and adjust to get the best
6780 * accuracy. Perhaps we even need to take the bpc value into
6784 if (intel_crtc
->config
.limited_color_range
)
6785 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
6788 * GY/GU and RY/RU should be the other way around according
6789 * to BSpec, but reality doesn't agree. Just set them up in
6790 * a way that results in the correct picture.
6792 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
6793 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
6795 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
6796 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
6798 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
6799 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
6801 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
6802 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
6803 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
6805 if (INTEL_INFO(dev
)->gen
> 6) {
6806 uint16_t postoff
= 0;
6808 if (intel_crtc
->config
.limited_color_range
)
6809 postoff
= (16 * (1 << 12) / 255) & 0x1fff;
6811 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
6812 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
6813 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
6815 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
6817 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
6819 if (intel_crtc
->config
.limited_color_range
)
6820 mode
|= CSC_BLACK_SCREEN_OFFSET
;
6822 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
6826 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
6828 struct drm_device
*dev
= crtc
->dev
;
6829 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6830 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6831 enum pipe pipe
= intel_crtc
->pipe
;
6832 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
6837 if (IS_HASWELL(dev
) && intel_crtc
->config
.dither
)
6838 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
6840 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
6841 val
|= PIPECONF_INTERLACED_ILK
;
6843 val
|= PIPECONF_PROGRESSIVE
;
6845 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
6846 POSTING_READ(PIPECONF(cpu_transcoder
));
6848 I915_WRITE(GAMMA_MODE(intel_crtc
->pipe
), GAMMA_MODE_MODE_8BIT
);
6849 POSTING_READ(GAMMA_MODE(intel_crtc
->pipe
));
6851 if (IS_BROADWELL(dev
)) {
6854 switch (intel_crtc
->config
.pipe_bpp
) {
6856 val
|= PIPEMISC_DITHER_6_BPC
;
6859 val
|= PIPEMISC_DITHER_8_BPC
;
6862 val
|= PIPEMISC_DITHER_10_BPC
;
6865 val
|= PIPEMISC_DITHER_12_BPC
;
6868 /* Case prevented by pipe_config_set_bpp. */
6872 if (intel_crtc
->config
.dither
)
6873 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
6875 I915_WRITE(PIPEMISC(pipe
), val
);
6879 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
6880 intel_clock_t
*clock
,
6881 bool *has_reduced_clock
,
6882 intel_clock_t
*reduced_clock
)
6884 struct drm_device
*dev
= crtc
->dev
;
6885 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6886 struct intel_encoder
*intel_encoder
;
6888 const intel_limit_t
*limit
;
6889 bool ret
, is_lvds
= false;
6891 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
6892 switch (intel_encoder
->type
) {
6893 case INTEL_OUTPUT_LVDS
:
6899 refclk
= ironlake_get_refclk(crtc
);
6902 * Returns a set of divisors for the desired target clock with the given
6903 * refclk, or FALSE. The returned values represent the clock equation:
6904 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
6906 limit
= intel_limit(crtc
, refclk
);
6907 ret
= dev_priv
->display
.find_dpll(limit
, crtc
,
6908 to_intel_crtc(crtc
)->config
.port_clock
,
6909 refclk
, NULL
, clock
);
6913 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
6915 * Ensure we match the reduced clock's P to the target clock.
6916 * If the clocks don't match, we can't switch the display clock
6917 * by using the FP0/FP1. In such case we will disable the LVDS
6918 * downclock feature.
6920 *has_reduced_clock
=
6921 dev_priv
->display
.find_dpll(limit
, crtc
,
6922 dev_priv
->lvds_downclock
,
6930 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
6933 * Account for spread spectrum to avoid
6934 * oversubscribing the link. Max center spread
6935 * is 2.5%; use 5% for safety's sake.
6937 u32 bps
= target_clock
* bpp
* 21 / 20;
6938 return DIV_ROUND_UP(bps
, link_bw
* 8);
6941 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
6943 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
6946 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
6948 intel_clock_t
*reduced_clock
, u32
*fp2
)
6950 struct drm_crtc
*crtc
= &intel_crtc
->base
;
6951 struct drm_device
*dev
= crtc
->dev
;
6952 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6953 struct intel_encoder
*intel_encoder
;
6955 int factor
, num_connectors
= 0;
6956 bool is_lvds
= false, is_sdvo
= false;
6958 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
6959 switch (intel_encoder
->type
) {
6960 case INTEL_OUTPUT_LVDS
:
6963 case INTEL_OUTPUT_SDVO
:
6964 case INTEL_OUTPUT_HDMI
:
6972 /* Enable autotuning of the PLL clock (if permissible) */
6975 if ((intel_panel_use_ssc(dev_priv
) &&
6976 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
6977 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
6979 } else if (intel_crtc
->config
.sdvo_tv_clock
)
6982 if (ironlake_needs_fb_cb_tune(&intel_crtc
->config
.dpll
, factor
))
6985 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
6991 dpll
|= DPLLB_MODE_LVDS
;
6993 dpll
|= DPLLB_MODE_DAC_SERIAL
;
6995 dpll
|= (intel_crtc
->config
.pixel_multiplier
- 1)
6996 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
6999 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7000 if (intel_crtc
->config
.has_dp_encoder
)
7001 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7003 /* compute bitmask from p1 value */
7004 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7006 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
7008 switch (intel_crtc
->config
.dpll
.p2
) {
7010 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
7013 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
7016 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
7019 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
7023 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
7024 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7026 dpll
|= PLL_REF_INPUT_DREFCLK
;
7028 return dpll
| DPLL_VCO_ENABLE
;
7031 static int ironlake_crtc_mode_set(struct drm_crtc
*crtc
,
7033 struct drm_framebuffer
*fb
)
7035 struct drm_device
*dev
= crtc
->dev
;
7036 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7037 int num_connectors
= 0;
7038 intel_clock_t clock
, reduced_clock
;
7039 u32 dpll
= 0, fp
= 0, fp2
= 0;
7040 bool ok
, has_reduced_clock
= false;
7041 bool is_lvds
= false;
7042 struct intel_encoder
*encoder
;
7043 struct intel_shared_dpll
*pll
;
7045 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
7046 switch (encoder
->type
) {
7047 case INTEL_OUTPUT_LVDS
:
7055 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
7056 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
7058 ok
= ironlake_compute_clocks(crtc
, &clock
,
7059 &has_reduced_clock
, &reduced_clock
);
7060 if (!ok
&& !intel_crtc
->config
.clock_set
) {
7061 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7064 /* Compat-code for transition, will disappear. */
7065 if (!intel_crtc
->config
.clock_set
) {
7066 intel_crtc
->config
.dpll
.n
= clock
.n
;
7067 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
7068 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
7069 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
7070 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
7073 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
7074 if (intel_crtc
->config
.has_pch_encoder
) {
7075 fp
= i9xx_dpll_compute_fp(&intel_crtc
->config
.dpll
);
7076 if (has_reduced_clock
)
7077 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
7079 dpll
= ironlake_compute_dpll(intel_crtc
,
7080 &fp
, &reduced_clock
,
7081 has_reduced_clock
? &fp2
: NULL
);
7083 intel_crtc
->config
.dpll_hw_state
.dpll
= dpll
;
7084 intel_crtc
->config
.dpll_hw_state
.fp0
= fp
;
7085 if (has_reduced_clock
)
7086 intel_crtc
->config
.dpll_hw_state
.fp1
= fp2
;
7088 intel_crtc
->config
.dpll_hw_state
.fp1
= fp
;
7090 pll
= intel_get_shared_dpll(intel_crtc
);
7092 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
7093 pipe_name(intel_crtc
->pipe
));
7097 intel_put_shared_dpll(intel_crtc
);
7099 if (is_lvds
&& has_reduced_clock
&& i915
.powersave
)
7100 intel_crtc
->lowfreq_avail
= true;
7102 intel_crtc
->lowfreq_avail
= false;
7107 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
7108 struct intel_link_m_n
*m_n
)
7110 struct drm_device
*dev
= crtc
->base
.dev
;
7111 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7112 enum pipe pipe
= crtc
->pipe
;
7114 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
7115 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
7116 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
7118 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
7119 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
7120 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7123 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
7124 enum transcoder transcoder
,
7125 struct intel_link_m_n
*m_n
)
7127 struct drm_device
*dev
= crtc
->base
.dev
;
7128 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7129 enum pipe pipe
= crtc
->pipe
;
7131 if (INTEL_INFO(dev
)->gen
>= 5) {
7132 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
7133 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
7134 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
7136 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
7137 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
7138 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7140 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
7141 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
7142 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
7144 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
7145 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
7146 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7150 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
7151 struct intel_crtc_config
*pipe_config
)
7153 if (crtc
->config
.has_pch_encoder
)
7154 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
7156 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7157 &pipe_config
->dp_m_n
);
7160 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
7161 struct intel_crtc_config
*pipe_config
)
7163 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7164 &pipe_config
->fdi_m_n
);
7167 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
7168 struct intel_crtc_config
*pipe_config
)
7170 struct drm_device
*dev
= crtc
->base
.dev
;
7171 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7174 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
7176 if (tmp
& PF_ENABLE
) {
7177 pipe_config
->pch_pfit
.enabled
= true;
7178 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
7179 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
7181 /* We currently do not free assignements of panel fitters on
7182 * ivb/hsw (since we don't use the higher upscaling modes which
7183 * differentiates them) so just WARN about this case for now. */
7185 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
7186 PF_PIPE_SEL_IVB(crtc
->pipe
));
7191 static void ironlake_get_plane_config(struct intel_crtc
*crtc
,
7192 struct intel_plane_config
*plane_config
)
7194 struct drm_device
*dev
= crtc
->base
.dev
;
7195 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7196 u32 val
, base
, offset
;
7197 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7198 int fourcc
, pixel_format
;
7201 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
7202 if (!crtc
->base
.primary
->fb
) {
7203 DRM_DEBUG_KMS("failed to alloc fb\n");
7207 val
= I915_READ(DSPCNTR(plane
));
7209 if (INTEL_INFO(dev
)->gen
>= 4)
7210 if (val
& DISPPLANE_TILED
)
7211 plane_config
->tiled
= true;
7213 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7214 fourcc
= intel_format_to_fourcc(pixel_format
);
7215 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
7216 crtc
->base
.primary
->fb
->bits_per_pixel
=
7217 drm_format_plane_cpp(fourcc
, 0) * 8;
7219 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7220 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
7221 offset
= I915_READ(DSPOFFSET(plane
));
7223 if (plane_config
->tiled
)
7224 offset
= I915_READ(DSPTILEOFF(plane
));
7226 offset
= I915_READ(DSPLINOFF(plane
));
7228 plane_config
->base
= base
;
7230 val
= I915_READ(PIPESRC(pipe
));
7231 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
7232 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
7234 val
= I915_READ(DSPSTRIDE(pipe
));
7235 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffff80;
7237 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
7238 plane_config
->tiled
);
7240 plane_config
->size
= ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
7241 aligned_height
, PAGE_SIZE
);
7243 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7244 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
7245 crtc
->base
.primary
->fb
->height
,
7246 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
7247 crtc
->base
.primary
->fb
->pitches
[0],
7248 plane_config
->size
);
7251 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
7252 struct intel_crtc_config
*pipe_config
)
7254 struct drm_device
*dev
= crtc
->base
.dev
;
7255 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7258 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7259 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7261 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7262 if (!(tmp
& PIPECONF_ENABLE
))
7265 switch (tmp
& PIPECONF_BPC_MASK
) {
7267 pipe_config
->pipe_bpp
= 18;
7270 pipe_config
->pipe_bpp
= 24;
7272 case PIPECONF_10BPC
:
7273 pipe_config
->pipe_bpp
= 30;
7275 case PIPECONF_12BPC
:
7276 pipe_config
->pipe_bpp
= 36;
7282 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
7283 pipe_config
->limited_color_range
= true;
7285 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
7286 struct intel_shared_dpll
*pll
;
7288 pipe_config
->has_pch_encoder
= true;
7290 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
7291 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7292 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7294 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7296 if (HAS_PCH_IBX(dev_priv
->dev
)) {
7297 pipe_config
->shared_dpll
=
7298 (enum intel_dpll_id
) crtc
->pipe
;
7300 tmp
= I915_READ(PCH_DPLL_SEL
);
7301 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
7302 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_B
;
7304 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_A
;
7307 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
7309 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
7310 &pipe_config
->dpll_hw_state
));
7312 tmp
= pipe_config
->dpll_hw_state
.dpll
;
7313 pipe_config
->pixel_multiplier
=
7314 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
7315 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
7317 ironlake_pch_clock_get(crtc
, pipe_config
);
7319 pipe_config
->pixel_multiplier
= 1;
7322 intel_get_pipe_timings(crtc
, pipe_config
);
7324 ironlake_get_pfit_config(crtc
, pipe_config
);
7329 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
7331 struct drm_device
*dev
= dev_priv
->dev
;
7332 struct intel_ddi_plls
*plls
= &dev_priv
->ddi_plls
;
7333 struct intel_crtc
*crtc
;
7335 for_each_intel_crtc(dev
, crtc
)
7336 WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
7337 pipe_name(crtc
->pipe
));
7339 WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
7340 WARN(plls
->spll_refcount
, "SPLL enabled\n");
7341 WARN(plls
->wrpll1_refcount
, "WRPLL1 enabled\n");
7342 WARN(plls
->wrpll2_refcount
, "WRPLL2 enabled\n");
7343 WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
7344 WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
7345 "CPU PWM1 enabled\n");
7346 WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
7347 "CPU PWM2 enabled\n");
7348 WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
7349 "PCH PWM1 enabled\n");
7350 WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
7351 "Utility pin enabled\n");
7352 WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
7355 * In theory we can still leave IRQs enabled, as long as only the HPD
7356 * interrupts remain enabled. We used to check for that, but since it's
7357 * gen-specific and since we only disable LCPLL after we fully disable
7358 * the interrupts, the check below should be enough.
7360 WARN(!dev_priv
->pm
.irqs_disabled
, "IRQs enabled\n");
7363 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
7365 struct drm_device
*dev
= dev_priv
->dev
;
7367 if (IS_HASWELL(dev
)) {
7368 mutex_lock(&dev_priv
->rps
.hw_lock
);
7369 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
7371 DRM_ERROR("Failed to disable D_COMP\n");
7372 mutex_unlock(&dev_priv
->rps
.hw_lock
);
7374 I915_WRITE(D_COMP
, val
);
7376 POSTING_READ(D_COMP
);
7380 * This function implements pieces of two sequences from BSpec:
7381 * - Sequence for display software to disable LCPLL
7382 * - Sequence for display software to allow package C8+
7383 * The steps implemented here are just the steps that actually touch the LCPLL
7384 * register. Callers should take care of disabling all the display engine
7385 * functions, doing the mode unset, fixing interrupts, etc.
7387 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
7388 bool switch_to_fclk
, bool allow_power_down
)
7392 assert_can_disable_lcpll(dev_priv
);
7394 val
= I915_READ(LCPLL_CTL
);
7396 if (switch_to_fclk
) {
7397 val
|= LCPLL_CD_SOURCE_FCLK
;
7398 I915_WRITE(LCPLL_CTL
, val
);
7400 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
7401 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
7402 DRM_ERROR("Switching to FCLK failed\n");
7404 val
= I915_READ(LCPLL_CTL
);
7407 val
|= LCPLL_PLL_DISABLE
;
7408 I915_WRITE(LCPLL_CTL
, val
);
7409 POSTING_READ(LCPLL_CTL
);
7411 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
7412 DRM_ERROR("LCPLL still locked\n");
7414 val
= I915_READ(D_COMP
);
7415 val
|= D_COMP_COMP_DISABLE
;
7416 hsw_write_dcomp(dev_priv
, val
);
7419 if (wait_for((I915_READ(D_COMP
) & D_COMP_RCOMP_IN_PROGRESS
) == 0, 1))
7420 DRM_ERROR("D_COMP RCOMP still in progress\n");
7422 if (allow_power_down
) {
7423 val
= I915_READ(LCPLL_CTL
);
7424 val
|= LCPLL_POWER_DOWN_ALLOW
;
7425 I915_WRITE(LCPLL_CTL
, val
);
7426 POSTING_READ(LCPLL_CTL
);
7431 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
7434 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
7437 unsigned long irqflags
;
7439 val
= I915_READ(LCPLL_CTL
);
7441 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
7442 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
7446 * Make sure we're not on PC8 state before disabling PC8, otherwise
7447 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
7449 * The other problem is that hsw_restore_lcpll() is called as part of
7450 * the runtime PM resume sequence, so we can't just call
7451 * gen6_gt_force_wake_get() because that function calls
7452 * intel_runtime_pm_get(), and we can't change the runtime PM refcount
7453 * while we are on the resume sequence. So to solve this problem we have
7454 * to call special forcewake code that doesn't touch runtime PM and
7455 * doesn't enable the forcewake delayed work.
7457 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
7458 if (dev_priv
->uncore
.forcewake_count
++ == 0)
7459 dev_priv
->uncore
.funcs
.force_wake_get(dev_priv
, FORCEWAKE_ALL
);
7460 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
7462 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
7463 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
7464 I915_WRITE(LCPLL_CTL
, val
);
7465 POSTING_READ(LCPLL_CTL
);
7468 val
= I915_READ(D_COMP
);
7469 val
|= D_COMP_COMP_FORCE
;
7470 val
&= ~D_COMP_COMP_DISABLE
;
7471 hsw_write_dcomp(dev_priv
, val
);
7473 val
= I915_READ(LCPLL_CTL
);
7474 val
&= ~LCPLL_PLL_DISABLE
;
7475 I915_WRITE(LCPLL_CTL
, val
);
7477 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
7478 DRM_ERROR("LCPLL not locked yet\n");
7480 if (val
& LCPLL_CD_SOURCE_FCLK
) {
7481 val
= I915_READ(LCPLL_CTL
);
7482 val
&= ~LCPLL_CD_SOURCE_FCLK
;
7483 I915_WRITE(LCPLL_CTL
, val
);
7485 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
7486 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
7487 DRM_ERROR("Switching back to LCPLL failed\n");
7490 /* See the big comment above. */
7491 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
7492 if (--dev_priv
->uncore
.forcewake_count
== 0)
7493 dev_priv
->uncore
.funcs
.force_wake_put(dev_priv
, FORCEWAKE_ALL
);
7494 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
7498 * Package states C8 and deeper are really deep PC states that can only be
7499 * reached when all the devices on the system allow it, so even if the graphics
7500 * device allows PC8+, it doesn't mean the system will actually get to these
7501 * states. Our driver only allows PC8+ when going into runtime PM.
7503 * The requirements for PC8+ are that all the outputs are disabled, the power
7504 * well is disabled and most interrupts are disabled, and these are also
7505 * requirements for runtime PM. When these conditions are met, we manually do
7506 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
7507 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
7510 * When we really reach PC8 or deeper states (not just when we allow it) we lose
7511 * the state of some registers, so when we come back from PC8+ we need to
7512 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
7513 * need to take care of the registers kept by RC6. Notice that this happens even
7514 * if we don't put the device in PCI D3 state (which is what currently happens
7515 * because of the runtime PM support).
7517 * For more, read "Display Sequences for Package C8" on the hardware
7520 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
7522 struct drm_device
*dev
= dev_priv
->dev
;
7525 DRM_DEBUG_KMS("Enabling package C8+\n");
7527 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7528 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7529 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
7530 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7533 lpt_disable_clkout_dp(dev
);
7534 hsw_disable_lcpll(dev_priv
, true, true);
7537 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
7539 struct drm_device
*dev
= dev_priv
->dev
;
7542 DRM_DEBUG_KMS("Disabling package C8+\n");
7544 hsw_restore_lcpll(dev_priv
);
7545 lpt_init_pch_refclk(dev
);
7547 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7548 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7549 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
7550 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7553 intel_prepare_ddi(dev
);
7556 static void snb_modeset_global_resources(struct drm_device
*dev
)
7558 modeset_update_crtc_power_domains(dev
);
7561 static void haswell_modeset_global_resources(struct drm_device
*dev
)
7563 modeset_update_crtc_power_domains(dev
);
7566 static int haswell_crtc_mode_set(struct drm_crtc
*crtc
,
7568 struct drm_framebuffer
*fb
)
7570 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7572 if (!intel_ddi_pll_select(intel_crtc
))
7574 intel_ddi_pll_enable(intel_crtc
);
7576 intel_crtc
->lowfreq_avail
= false;
7581 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
7582 struct intel_crtc_config
*pipe_config
)
7584 struct drm_device
*dev
= crtc
->base
.dev
;
7585 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7586 enum intel_display_power_domain pfit_domain
;
7589 if (!intel_display_power_enabled(dev_priv
,
7590 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7593 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7594 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7596 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
7597 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
7598 enum pipe trans_edp_pipe
;
7599 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
7601 WARN(1, "unknown pipe linked to edp transcoder\n");
7602 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
7603 case TRANS_DDI_EDP_INPUT_A_ON
:
7604 trans_edp_pipe
= PIPE_A
;
7606 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
7607 trans_edp_pipe
= PIPE_B
;
7609 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
7610 trans_edp_pipe
= PIPE_C
;
7614 if (trans_edp_pipe
== crtc
->pipe
)
7615 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
7618 if (!intel_display_power_enabled(dev_priv
,
7619 POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
)))
7622 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
7623 if (!(tmp
& PIPECONF_ENABLE
))
7627 * Haswell has only FDI/PCH transcoder A. It is which is connected to
7628 * DDI E. So just check whether this pipe is wired to DDI E and whether
7629 * the PCH transcoder is on.
7631 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
7632 if ((tmp
& TRANS_DDI_PORT_MASK
) == TRANS_DDI_SELECT_PORT(PORT_E
) &&
7633 I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
7634 pipe_config
->has_pch_encoder
= true;
7636 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
7637 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7638 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7640 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7643 intel_get_pipe_timings(crtc
, pipe_config
);
7645 pfit_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
7646 if (intel_display_power_enabled(dev_priv
, pfit_domain
))
7647 ironlake_get_pfit_config(crtc
, pipe_config
);
7649 if (IS_HASWELL(dev
))
7650 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
7651 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
7653 pipe_config
->pixel_multiplier
= 1;
7661 } hdmi_audio_clock
[] = {
7662 { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175
},
7663 { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200
}, /* default per bspec */
7664 { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000
},
7665 { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027
},
7666 { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000
},
7667 { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054
},
7668 { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176
},
7669 { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250
},
7670 { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352
},
7671 { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500
},
7674 /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
7675 static u32
audio_config_hdmi_pixel_clock(struct drm_display_mode
*mode
)
7679 for (i
= 0; i
< ARRAY_SIZE(hdmi_audio_clock
); i
++) {
7680 if (mode
->clock
== hdmi_audio_clock
[i
].clock
)
7684 if (i
== ARRAY_SIZE(hdmi_audio_clock
)) {
7685 DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode
->clock
);
7689 DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
7690 hdmi_audio_clock
[i
].clock
,
7691 hdmi_audio_clock
[i
].config
);
7693 return hdmi_audio_clock
[i
].config
;
7696 static bool intel_eld_uptodate(struct drm_connector
*connector
,
7697 int reg_eldv
, uint32_t bits_eldv
,
7698 int reg_elda
, uint32_t bits_elda
,
7701 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7702 uint8_t *eld
= connector
->eld
;
7705 i
= I915_READ(reg_eldv
);
7714 i
= I915_READ(reg_elda
);
7716 I915_WRITE(reg_elda
, i
);
7718 for (i
= 0; i
< eld
[2]; i
++)
7719 if (I915_READ(reg_edid
) != *((uint32_t *)eld
+ i
))
7725 static void g4x_write_eld(struct drm_connector
*connector
,
7726 struct drm_crtc
*crtc
,
7727 struct drm_display_mode
*mode
)
7729 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7730 uint8_t *eld
= connector
->eld
;
7735 i
= I915_READ(G4X_AUD_VID_DID
);
7737 if (i
== INTEL_AUDIO_DEVBLC
|| i
== INTEL_AUDIO_DEVCL
)
7738 eldv
= G4X_ELDV_DEVCL_DEVBLC
;
7740 eldv
= G4X_ELDV_DEVCTG
;
7742 if (intel_eld_uptodate(connector
,
7743 G4X_AUD_CNTL_ST
, eldv
,
7744 G4X_AUD_CNTL_ST
, G4X_ELD_ADDR
,
7745 G4X_HDMIW_HDMIEDID
))
7748 i
= I915_READ(G4X_AUD_CNTL_ST
);
7749 i
&= ~(eldv
| G4X_ELD_ADDR
);
7750 len
= (i
>> 9) & 0x1f; /* ELD buffer size */
7751 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
7756 len
= min_t(uint8_t, eld
[2], len
);
7757 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7758 for (i
= 0; i
< len
; i
++)
7759 I915_WRITE(G4X_HDMIW_HDMIEDID
, *((uint32_t *)eld
+ i
));
7761 i
= I915_READ(G4X_AUD_CNTL_ST
);
7763 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
7766 static void haswell_write_eld(struct drm_connector
*connector
,
7767 struct drm_crtc
*crtc
,
7768 struct drm_display_mode
*mode
)
7770 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7771 uint8_t *eld
= connector
->eld
;
7775 int pipe
= to_intel_crtc(crtc
)->pipe
;
7778 int hdmiw_hdmiedid
= HSW_AUD_EDID_DATA(pipe
);
7779 int aud_cntl_st
= HSW_AUD_DIP_ELD_CTRL(pipe
);
7780 int aud_config
= HSW_AUD_CFG(pipe
);
7781 int aud_cntrl_st2
= HSW_AUD_PIN_ELD_CP_VLD
;
7783 /* Audio output enable */
7784 DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
7785 tmp
= I915_READ(aud_cntrl_st2
);
7786 tmp
|= (AUDIO_OUTPUT_ENABLE_A
<< (pipe
* 4));
7787 I915_WRITE(aud_cntrl_st2
, tmp
);
7788 POSTING_READ(aud_cntrl_st2
);
7790 assert_pipe_disabled(dev_priv
, to_intel_crtc(crtc
)->pipe
);
7792 /* Set ELD valid state */
7793 tmp
= I915_READ(aud_cntrl_st2
);
7794 DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp
);
7795 tmp
|= (AUDIO_ELD_VALID_A
<< (pipe
* 4));
7796 I915_WRITE(aud_cntrl_st2
, tmp
);
7797 tmp
= I915_READ(aud_cntrl_st2
);
7798 DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp
);
7800 /* Enable HDMI mode */
7801 tmp
= I915_READ(aud_config
);
7802 DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp
);
7803 /* clear N_programing_enable and N_value_index */
7804 tmp
&= ~(AUD_CONFIG_N_VALUE_INDEX
| AUD_CONFIG_N_PROG_ENABLE
);
7805 I915_WRITE(aud_config
, tmp
);
7807 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
7809 eldv
= AUDIO_ELD_VALID_A
<< (pipe
* 4);
7811 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
7812 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
7813 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
7814 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
7816 I915_WRITE(aud_config
, audio_config_hdmi_pixel_clock(mode
));
7819 if (intel_eld_uptodate(connector
,
7820 aud_cntrl_st2
, eldv
,
7821 aud_cntl_st
, IBX_ELD_ADDRESS
,
7825 i
= I915_READ(aud_cntrl_st2
);
7827 I915_WRITE(aud_cntrl_st2
, i
);
7832 i
= I915_READ(aud_cntl_st
);
7833 i
&= ~IBX_ELD_ADDRESS
;
7834 I915_WRITE(aud_cntl_st
, i
);
7835 i
= (i
>> 29) & DIP_PORT_SEL_MASK
; /* DIP_Port_Select, 0x1 = PortB */
7836 DRM_DEBUG_DRIVER("port num:%d\n", i
);
7838 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
7839 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7840 for (i
= 0; i
< len
; i
++)
7841 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
7843 i
= I915_READ(aud_cntrl_st2
);
7845 I915_WRITE(aud_cntrl_st2
, i
);
7849 static void ironlake_write_eld(struct drm_connector
*connector
,
7850 struct drm_crtc
*crtc
,
7851 struct drm_display_mode
*mode
)
7853 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7854 uint8_t *eld
= connector
->eld
;
7862 int pipe
= to_intel_crtc(crtc
)->pipe
;
7864 if (HAS_PCH_IBX(connector
->dev
)) {
7865 hdmiw_hdmiedid
= IBX_HDMIW_HDMIEDID(pipe
);
7866 aud_config
= IBX_AUD_CFG(pipe
);
7867 aud_cntl_st
= IBX_AUD_CNTL_ST(pipe
);
7868 aud_cntrl_st2
= IBX_AUD_CNTL_ST2
;
7869 } else if (IS_VALLEYVIEW(connector
->dev
)) {
7870 hdmiw_hdmiedid
= VLV_HDMIW_HDMIEDID(pipe
);
7871 aud_config
= VLV_AUD_CFG(pipe
);
7872 aud_cntl_st
= VLV_AUD_CNTL_ST(pipe
);
7873 aud_cntrl_st2
= VLV_AUD_CNTL_ST2
;
7875 hdmiw_hdmiedid
= CPT_HDMIW_HDMIEDID(pipe
);
7876 aud_config
= CPT_AUD_CFG(pipe
);
7877 aud_cntl_st
= CPT_AUD_CNTL_ST(pipe
);
7878 aud_cntrl_st2
= CPT_AUD_CNTRL_ST2
;
7881 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
7883 if (IS_VALLEYVIEW(connector
->dev
)) {
7884 struct intel_encoder
*intel_encoder
;
7885 struct intel_digital_port
*intel_dig_port
;
7887 intel_encoder
= intel_attached_encoder(connector
);
7888 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
7889 i
= intel_dig_port
->port
;
7891 i
= I915_READ(aud_cntl_st
);
7892 i
= (i
>> 29) & DIP_PORT_SEL_MASK
;
7893 /* DIP_Port_Select, 0x1 = PortB */
7897 DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
7898 /* operate blindly on all ports */
7899 eldv
= IBX_ELD_VALIDB
;
7900 eldv
|= IBX_ELD_VALIDB
<< 4;
7901 eldv
|= IBX_ELD_VALIDB
<< 8;
7903 DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i
));
7904 eldv
= IBX_ELD_VALIDB
<< ((i
- 1) * 4);
7907 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
7908 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
7909 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
7910 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
7912 I915_WRITE(aud_config
, audio_config_hdmi_pixel_clock(mode
));
7915 if (intel_eld_uptodate(connector
,
7916 aud_cntrl_st2
, eldv
,
7917 aud_cntl_st
, IBX_ELD_ADDRESS
,
7921 i
= I915_READ(aud_cntrl_st2
);
7923 I915_WRITE(aud_cntrl_st2
, i
);
7928 i
= I915_READ(aud_cntl_st
);
7929 i
&= ~IBX_ELD_ADDRESS
;
7930 I915_WRITE(aud_cntl_st
, i
);
7932 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
7933 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7934 for (i
= 0; i
< len
; i
++)
7935 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
7937 i
= I915_READ(aud_cntrl_st2
);
7939 I915_WRITE(aud_cntrl_st2
, i
);
7942 void intel_write_eld(struct drm_encoder
*encoder
,
7943 struct drm_display_mode
*mode
)
7945 struct drm_crtc
*crtc
= encoder
->crtc
;
7946 struct drm_connector
*connector
;
7947 struct drm_device
*dev
= encoder
->dev
;
7948 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7950 connector
= drm_select_eld(encoder
, mode
);
7954 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
7957 connector
->encoder
->base
.id
,
7958 connector
->encoder
->name
);
7960 connector
->eld
[6] = drm_av_sync_delay(connector
, mode
) / 2;
7962 if (dev_priv
->display
.write_eld
)
7963 dev_priv
->display
.write_eld(connector
, crtc
, mode
);
7966 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
7968 struct drm_device
*dev
= crtc
->dev
;
7969 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7970 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7973 if (base
!= intel_crtc
->cursor_base
) {
7974 /* On these chipsets we can only modify the base whilst
7975 * the cursor is disabled.
7977 if (intel_crtc
->cursor_cntl
) {
7978 I915_WRITE(_CURACNTR
, 0);
7979 POSTING_READ(_CURACNTR
);
7980 intel_crtc
->cursor_cntl
= 0;
7983 I915_WRITE(_CURABASE
, base
);
7984 POSTING_READ(_CURABASE
);
7987 /* XXX width must be 64, stride 256 => 0x00 << 28 */
7990 cntl
= (CURSOR_ENABLE
|
7991 CURSOR_GAMMA_ENABLE
|
7992 CURSOR_FORMAT_ARGB
);
7993 if (intel_crtc
->cursor_cntl
!= cntl
) {
7994 I915_WRITE(_CURACNTR
, cntl
);
7995 POSTING_READ(_CURACNTR
);
7996 intel_crtc
->cursor_cntl
= cntl
;
8000 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8002 struct drm_device
*dev
= crtc
->dev
;
8003 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8004 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8005 int pipe
= intel_crtc
->pipe
;
8010 cntl
= MCURSOR_GAMMA_ENABLE
;
8011 switch (intel_crtc
->cursor_width
) {
8013 cntl
|= CURSOR_MODE_64_ARGB_AX
;
8016 cntl
|= CURSOR_MODE_128_ARGB_AX
;
8019 cntl
|= CURSOR_MODE_256_ARGB_AX
;
8025 cntl
|= pipe
<< 28; /* Connect to correct pipe */
8027 if (intel_crtc
->cursor_cntl
!= cntl
) {
8028 I915_WRITE(CURCNTR(pipe
), cntl
);
8029 POSTING_READ(CURCNTR(pipe
));
8030 intel_crtc
->cursor_cntl
= cntl
;
8033 /* and commit changes on next vblank */
8034 I915_WRITE(CURBASE(pipe
), base
);
8035 POSTING_READ(CURBASE(pipe
));
8038 static void ivb_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8040 struct drm_device
*dev
= crtc
->dev
;
8041 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8042 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8043 int pipe
= intel_crtc
->pipe
;
8048 cntl
= MCURSOR_GAMMA_ENABLE
;
8049 switch (intel_crtc
->cursor_width
) {
8051 cntl
|= CURSOR_MODE_64_ARGB_AX
;
8054 cntl
|= CURSOR_MODE_128_ARGB_AX
;
8057 cntl
|= CURSOR_MODE_256_ARGB_AX
;
8064 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
8065 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
8067 if (intel_crtc
->cursor_cntl
!= cntl
) {
8068 I915_WRITE(CURCNTR(pipe
), cntl
);
8069 POSTING_READ(CURCNTR(pipe
));
8070 intel_crtc
->cursor_cntl
= cntl
;
8073 /* and commit changes on next vblank */
8074 I915_WRITE(CURBASE(pipe
), base
);
8075 POSTING_READ(CURBASE(pipe
));
8078 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
8079 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
8082 struct drm_device
*dev
= crtc
->dev
;
8083 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8084 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8085 int pipe
= intel_crtc
->pipe
;
8086 int x
= crtc
->cursor_x
;
8087 int y
= crtc
->cursor_y
;
8088 u32 base
= 0, pos
= 0;
8091 base
= intel_crtc
->cursor_addr
;
8093 if (x
>= intel_crtc
->config
.pipe_src_w
)
8096 if (y
>= intel_crtc
->config
.pipe_src_h
)
8100 if (x
+ intel_crtc
->cursor_width
<= 0)
8103 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
8106 pos
|= x
<< CURSOR_X_SHIFT
;
8109 if (y
+ intel_crtc
->cursor_height
<= 0)
8112 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
8115 pos
|= y
<< CURSOR_Y_SHIFT
;
8117 if (base
== 0 && intel_crtc
->cursor_base
== 0)
8120 I915_WRITE(CURPOS(pipe
), pos
);
8122 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
) || IS_BROADWELL(dev
))
8123 ivb_update_cursor(crtc
, base
);
8124 else if (IS_845G(dev
) || IS_I865G(dev
))
8125 i845_update_cursor(crtc
, base
);
8127 i9xx_update_cursor(crtc
, base
);
8128 intel_crtc
->cursor_base
= base
;
8132 * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
8134 * Note that the object's reference will be consumed if the update fails. If
8135 * the update succeeds, the reference of the old object (if any) will be
8138 static int intel_crtc_cursor_set_obj(struct drm_crtc
*crtc
,
8139 struct drm_i915_gem_object
*obj
,
8140 uint32_t width
, uint32_t height
)
8142 struct drm_device
*dev
= crtc
->dev
;
8143 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8144 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8145 enum pipe pipe
= intel_crtc
->pipe
;
8150 /* if we want to turn off the cursor ignore width and height */
8152 DRM_DEBUG_KMS("cursor off\n");
8155 mutex_lock(&dev
->struct_mutex
);
8159 /* Check for which cursor types we support */
8160 if (!((width
== 64 && height
== 64) ||
8161 (width
== 128 && height
== 128 && !IS_GEN2(dev
)) ||
8162 (width
== 256 && height
== 256 && !IS_GEN2(dev
)))) {
8163 DRM_DEBUG("Cursor dimension not supported\n");
8167 if (obj
->base
.size
< width
* height
* 4) {
8168 DRM_DEBUG_KMS("buffer is too small\n");
8173 /* we only need to pin inside GTT if cursor is non-phy */
8174 mutex_lock(&dev
->struct_mutex
);
8175 if (!INTEL_INFO(dev
)->cursor_needs_physical
) {
8178 if (obj
->tiling_mode
) {
8179 DRM_DEBUG_KMS("cursor cannot be tiled\n");
8184 /* Note that the w/a also requires 2 PTE of padding following
8185 * the bo. We currently fill all unused PTE with the shadow
8186 * page and so we should always have valid PTE following the
8187 * cursor preventing the VT-d warning.
8190 if (need_vtd_wa(dev
))
8191 alignment
= 64*1024;
8193 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, NULL
);
8195 DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
8199 ret
= i915_gem_object_put_fence(obj
);
8201 DRM_DEBUG_KMS("failed to release fence for cursor");
8205 addr
= i915_gem_obj_ggtt_offset(obj
);
8207 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
8208 ret
= i915_gem_object_attach_phys(obj
, align
);
8210 DRM_DEBUG_KMS("failed to attach phys object\n");
8213 addr
= obj
->phys_handle
->busaddr
;
8217 I915_WRITE(CURSIZE
, (height
<< 12) | width
);
8220 if (intel_crtc
->cursor_bo
) {
8221 if (!INTEL_INFO(dev
)->cursor_needs_physical
)
8222 i915_gem_object_unpin_from_display_plane(intel_crtc
->cursor_bo
);
8225 i915_gem_track_fb(intel_crtc
->cursor_bo
, obj
,
8226 INTEL_FRONTBUFFER_CURSOR(pipe
));
8227 mutex_unlock(&dev
->struct_mutex
);
8229 old_width
= intel_crtc
->cursor_width
;
8231 intel_crtc
->cursor_addr
= addr
;
8232 intel_crtc
->cursor_bo
= obj
;
8233 intel_crtc
->cursor_width
= width
;
8234 intel_crtc
->cursor_height
= height
;
8236 if (intel_crtc
->active
) {
8237 if (old_width
!= width
)
8238 intel_update_watermarks(crtc
);
8239 intel_crtc_update_cursor(crtc
, intel_crtc
->cursor_bo
!= NULL
);
8242 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_CURSOR(pipe
));
8246 i915_gem_object_unpin_from_display_plane(obj
);
8248 mutex_unlock(&dev
->struct_mutex
);
8250 drm_gem_object_unreference_unlocked(&obj
->base
);
8254 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
8255 u16
*blue
, uint32_t start
, uint32_t size
)
8257 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
8258 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8260 for (i
= start
; i
< end
; i
++) {
8261 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
8262 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
8263 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
8266 intel_crtc_load_lut(crtc
);
8269 /* VESA 640x480x72Hz mode to set on the pipe */
8270 static struct drm_display_mode load_detect_mode
= {
8271 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
8272 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
8275 struct drm_framebuffer
*
8276 __intel_framebuffer_create(struct drm_device
*dev
,
8277 struct drm_mode_fb_cmd2
*mode_cmd
,
8278 struct drm_i915_gem_object
*obj
)
8280 struct intel_framebuffer
*intel_fb
;
8283 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8285 drm_gem_object_unreference_unlocked(&obj
->base
);
8286 return ERR_PTR(-ENOMEM
);
8289 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
8293 return &intel_fb
->base
;
8295 drm_gem_object_unreference_unlocked(&obj
->base
);
8298 return ERR_PTR(ret
);
8301 static struct drm_framebuffer
*
8302 intel_framebuffer_create(struct drm_device
*dev
,
8303 struct drm_mode_fb_cmd2
*mode_cmd
,
8304 struct drm_i915_gem_object
*obj
)
8306 struct drm_framebuffer
*fb
;
8309 ret
= i915_mutex_lock_interruptible(dev
);
8311 return ERR_PTR(ret
);
8312 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
8313 mutex_unlock(&dev
->struct_mutex
);
8319 intel_framebuffer_pitch_for_width(int width
, int bpp
)
8321 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
8322 return ALIGN(pitch
, 64);
8326 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
8328 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
8329 return ALIGN(pitch
* mode
->vdisplay
, PAGE_SIZE
);
8332 static struct drm_framebuffer
*
8333 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
8334 struct drm_display_mode
*mode
,
8337 struct drm_i915_gem_object
*obj
;
8338 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
8340 obj
= i915_gem_alloc_object(dev
,
8341 intel_framebuffer_size_for_mode(mode
, bpp
));
8343 return ERR_PTR(-ENOMEM
);
8345 mode_cmd
.width
= mode
->hdisplay
;
8346 mode_cmd
.height
= mode
->vdisplay
;
8347 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
8349 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
8351 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
8354 static struct drm_framebuffer
*
8355 mode_fits_in_fbdev(struct drm_device
*dev
,
8356 struct drm_display_mode
*mode
)
8358 #ifdef CONFIG_DRM_I915_FBDEV
8359 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8360 struct drm_i915_gem_object
*obj
;
8361 struct drm_framebuffer
*fb
;
8363 if (!dev_priv
->fbdev
)
8366 if (!dev_priv
->fbdev
->fb
)
8369 obj
= dev_priv
->fbdev
->fb
->obj
;
8372 fb
= &dev_priv
->fbdev
->fb
->base
;
8373 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
8374 fb
->bits_per_pixel
))
8377 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
8386 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
8387 struct drm_display_mode
*mode
,
8388 struct intel_load_detect_pipe
*old
,
8389 struct drm_modeset_acquire_ctx
*ctx
)
8391 struct intel_crtc
*intel_crtc
;
8392 struct intel_encoder
*intel_encoder
=
8393 intel_attached_encoder(connector
);
8394 struct drm_crtc
*possible_crtc
;
8395 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8396 struct drm_crtc
*crtc
= NULL
;
8397 struct drm_device
*dev
= encoder
->dev
;
8398 struct drm_framebuffer
*fb
;
8399 struct drm_mode_config
*config
= &dev
->mode_config
;
8402 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8403 connector
->base
.id
, connector
->name
,
8404 encoder
->base
.id
, encoder
->name
);
8406 drm_modeset_acquire_init(ctx
, 0);
8409 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
8414 * Algorithm gets a little messy:
8416 * - if the connector already has an assigned crtc, use it (but make
8417 * sure it's on first)
8419 * - try to find the first unused crtc that can drive this connector,
8420 * and use that if we find one
8423 /* See if we already have a CRTC for this connector */
8424 if (encoder
->crtc
) {
8425 crtc
= encoder
->crtc
;
8427 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8431 old
->dpms_mode
= connector
->dpms
;
8432 old
->load_detect_temp
= false;
8434 /* Make sure the crtc and connector are running */
8435 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
8436 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
8441 /* Find an unused one (if possible) */
8442 for_each_crtc(dev
, possible_crtc
) {
8444 if (!(encoder
->possible_crtcs
& (1 << i
)))
8446 if (!possible_crtc
->enabled
) {
8447 crtc
= possible_crtc
;
8453 * If we didn't find an unused CRTC, don't use any.
8456 DRM_DEBUG_KMS("no pipe available for load-detect\n");
8460 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8463 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
8464 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
8466 intel_crtc
= to_intel_crtc(crtc
);
8467 intel_crtc
->new_enabled
= true;
8468 intel_crtc
->new_config
= &intel_crtc
->config
;
8469 old
->dpms_mode
= connector
->dpms
;
8470 old
->load_detect_temp
= true;
8471 old
->release_fb
= NULL
;
8474 mode
= &load_detect_mode
;
8476 /* We need a framebuffer large enough to accommodate all accesses
8477 * that the plane may generate whilst we perform load detection.
8478 * We can not rely on the fbcon either being present (we get called
8479 * during its initialisation to detect all boot displays, or it may
8480 * not even exist) or that it is large enough to satisfy the
8483 fb
= mode_fits_in_fbdev(dev
, mode
);
8485 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
8486 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
8487 old
->release_fb
= fb
;
8489 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
8491 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
8495 if (intel_set_mode(crtc
, mode
, 0, 0, fb
)) {
8496 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
8497 if (old
->release_fb
)
8498 old
->release_fb
->funcs
->destroy(old
->release_fb
);
8502 /* let the connector get through one full cycle before testing */
8503 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
8507 intel_crtc
->new_enabled
= crtc
->enabled
;
8508 if (intel_crtc
->new_enabled
)
8509 intel_crtc
->new_config
= &intel_crtc
->config
;
8511 intel_crtc
->new_config
= NULL
;
8513 if (ret
== -EDEADLK
) {
8514 drm_modeset_backoff(ctx
);
8518 drm_modeset_drop_locks(ctx
);
8519 drm_modeset_acquire_fini(ctx
);
8524 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
8525 struct intel_load_detect_pipe
*old
,
8526 struct drm_modeset_acquire_ctx
*ctx
)
8528 struct intel_encoder
*intel_encoder
=
8529 intel_attached_encoder(connector
);
8530 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8531 struct drm_crtc
*crtc
= encoder
->crtc
;
8532 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8534 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8535 connector
->base
.id
, connector
->name
,
8536 encoder
->base
.id
, encoder
->name
);
8538 if (old
->load_detect_temp
) {
8539 to_intel_connector(connector
)->new_encoder
= NULL
;
8540 intel_encoder
->new_crtc
= NULL
;
8541 intel_crtc
->new_enabled
= false;
8542 intel_crtc
->new_config
= NULL
;
8543 intel_set_mode(crtc
, NULL
, 0, 0, NULL
);
8545 if (old
->release_fb
) {
8546 drm_framebuffer_unregister_private(old
->release_fb
);
8547 drm_framebuffer_unreference(old
->release_fb
);
8554 /* Switch crtc and encoder back off if necessary */
8555 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
8556 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
8559 drm_modeset_drop_locks(ctx
);
8560 drm_modeset_acquire_fini(ctx
);
8563 static int i9xx_pll_refclk(struct drm_device
*dev
,
8564 const struct intel_crtc_config
*pipe_config
)
8566 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8567 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8569 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
8570 return dev_priv
->vbt
.lvds_ssc_freq
;
8571 else if (HAS_PCH_SPLIT(dev
))
8573 else if (!IS_GEN2(dev
))
8579 /* Returns the clock of the currently programmed mode of the given pipe. */
8580 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
8581 struct intel_crtc_config
*pipe_config
)
8583 struct drm_device
*dev
= crtc
->base
.dev
;
8584 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8585 int pipe
= pipe_config
->cpu_transcoder
;
8586 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8588 intel_clock_t clock
;
8589 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
8591 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
8592 fp
= pipe_config
->dpll_hw_state
.fp0
;
8594 fp
= pipe_config
->dpll_hw_state
.fp1
;
8596 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
8597 if (IS_PINEVIEW(dev
)) {
8598 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
8599 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8601 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
8602 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8605 if (!IS_GEN2(dev
)) {
8606 if (IS_PINEVIEW(dev
))
8607 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
8608 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
8610 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
8611 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8613 switch (dpll
& DPLL_MODE_MASK
) {
8614 case DPLLB_MODE_DAC_SERIAL
:
8615 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
8618 case DPLLB_MODE_LVDS
:
8619 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
8623 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
8624 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
8628 if (IS_PINEVIEW(dev
))
8629 pineview_clock(refclk
, &clock
);
8631 i9xx_clock(refclk
, &clock
);
8633 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
8634 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
8637 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
8638 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8640 if (lvds
& LVDS_CLKB_POWER_UP
)
8645 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
8648 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
8649 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
8651 if (dpll
& PLL_P2_DIVIDE_BY_4
)
8657 i9xx_clock(refclk
, &clock
);
8661 * This value includes pixel_multiplier. We will use
8662 * port_clock to compute adjusted_mode.crtc_clock in the
8663 * encoder's get_config() function.
8665 pipe_config
->port_clock
= clock
.dot
;
8668 int intel_dotclock_calculate(int link_freq
,
8669 const struct intel_link_m_n
*m_n
)
8672 * The calculation for the data clock is:
8673 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
8674 * But we want to avoid losing precison if possible, so:
8675 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
8677 * and the link clock is simpler:
8678 * link_clock = (m * link_clock) / n
8684 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
8687 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
8688 struct intel_crtc_config
*pipe_config
)
8690 struct drm_device
*dev
= crtc
->base
.dev
;
8692 /* read out port_clock from the DPLL */
8693 i9xx_crtc_clock_get(crtc
, pipe_config
);
8696 * This value does not include pixel_multiplier.
8697 * We will check that port_clock and adjusted_mode.crtc_clock
8698 * agree once we know their relationship in the encoder's
8699 * get_config() function.
8701 pipe_config
->adjusted_mode
.crtc_clock
=
8702 intel_dotclock_calculate(intel_fdi_link_freq(dev
) * 10000,
8703 &pipe_config
->fdi_m_n
);
8706 /** Returns the currently programmed mode of the given pipe. */
8707 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
8708 struct drm_crtc
*crtc
)
8710 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8711 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8712 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
8713 struct drm_display_mode
*mode
;
8714 struct intel_crtc_config pipe_config
;
8715 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
8716 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
8717 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
8718 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
8719 enum pipe pipe
= intel_crtc
->pipe
;
8721 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
8726 * Construct a pipe_config sufficient for getting the clock info
8727 * back out of crtc_clock_get.
8729 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
8730 * to use a real value here instead.
8732 pipe_config
.cpu_transcoder
= (enum transcoder
) pipe
;
8733 pipe_config
.pixel_multiplier
= 1;
8734 pipe_config
.dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
8735 pipe_config
.dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
8736 pipe_config
.dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
8737 i9xx_crtc_clock_get(intel_crtc
, &pipe_config
);
8739 mode
->clock
= pipe_config
.port_clock
/ pipe_config
.pixel_multiplier
;
8740 mode
->hdisplay
= (htot
& 0xffff) + 1;
8741 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
8742 mode
->hsync_start
= (hsync
& 0xffff) + 1;
8743 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
8744 mode
->vdisplay
= (vtot
& 0xffff) + 1;
8745 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
8746 mode
->vsync_start
= (vsync
& 0xffff) + 1;
8747 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
8749 drm_mode_set_name(mode
);
8754 static void intel_increase_pllclock(struct drm_device
*dev
,
8757 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8758 int dpll_reg
= DPLL(pipe
);
8761 if (HAS_PCH_SPLIT(dev
))
8764 if (!dev_priv
->lvds_downclock_avail
)
8767 dpll
= I915_READ(dpll_reg
);
8768 if (!HAS_PIPE_CXSR(dev
) && (dpll
& DISPLAY_RATE_SELECT_FPA1
)) {
8769 DRM_DEBUG_DRIVER("upclocking LVDS\n");
8771 assert_panel_unlocked(dev_priv
, pipe
);
8773 dpll
&= ~DISPLAY_RATE_SELECT_FPA1
;
8774 I915_WRITE(dpll_reg
, dpll
);
8775 intel_wait_for_vblank(dev
, pipe
);
8777 dpll
= I915_READ(dpll_reg
);
8778 if (dpll
& DISPLAY_RATE_SELECT_FPA1
)
8779 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
8783 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
8785 struct drm_device
*dev
= crtc
->dev
;
8786 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8787 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8789 if (HAS_PCH_SPLIT(dev
))
8792 if (!dev_priv
->lvds_downclock_avail
)
8796 * Since this is called by a timer, we should never get here in
8799 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
8800 int pipe
= intel_crtc
->pipe
;
8801 int dpll_reg
= DPLL(pipe
);
8804 DRM_DEBUG_DRIVER("downclocking LVDS\n");
8806 assert_panel_unlocked(dev_priv
, pipe
);
8808 dpll
= I915_READ(dpll_reg
);
8809 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
8810 I915_WRITE(dpll_reg
, dpll
);
8811 intel_wait_for_vblank(dev
, pipe
);
8812 dpll
= I915_READ(dpll_reg
);
8813 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
8814 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
8819 void intel_mark_busy(struct drm_device
*dev
)
8821 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8823 if (dev_priv
->mm
.busy
)
8826 intel_runtime_pm_get(dev_priv
);
8827 i915_update_gfx_val(dev_priv
);
8828 dev_priv
->mm
.busy
= true;
8831 void intel_mark_idle(struct drm_device
*dev
)
8833 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8834 struct drm_crtc
*crtc
;
8836 if (!dev_priv
->mm
.busy
)
8839 dev_priv
->mm
.busy
= false;
8841 if (!i915
.powersave
)
8844 for_each_crtc(dev
, crtc
) {
8845 if (!crtc
->primary
->fb
)
8848 intel_decrease_pllclock(crtc
);
8851 if (INTEL_INFO(dev
)->gen
>= 6)
8852 gen6_rps_idle(dev
->dev_private
);
8855 intel_runtime_pm_put(dev_priv
);
8860 * intel_mark_fb_busy - mark given planes as busy
8862 * @frontbuffer_bits: bits for the affected planes
8863 * @ring: optional ring for asynchronous commands
8865 * This function gets called every time the screen contents change. It can be
8866 * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
8868 static void intel_mark_fb_busy(struct drm_device
*dev
,
8869 unsigned frontbuffer_bits
,
8870 struct intel_engine_cs
*ring
)
8874 if (!i915
.powersave
)
8877 for_each_pipe(pipe
) {
8878 if (!(frontbuffer_bits
& INTEL_FRONTBUFFER_ALL_MASK(pipe
)))
8881 intel_increase_pllclock(dev
, pipe
);
8882 if (ring
&& intel_fbc_enabled(dev
))
8883 ring
->fbc_dirty
= true;
8888 * intel_fb_obj_invalidate - invalidate frontbuffer object
8889 * @obj: GEM object to invalidate
8890 * @ring: set for asynchronous rendering
8892 * This function gets called every time rendering on the given object starts and
8893 * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
8894 * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
8895 * until the rendering completes or a flip on this frontbuffer plane is
8898 void intel_fb_obj_invalidate(struct drm_i915_gem_object
*obj
,
8899 struct intel_engine_cs
*ring
)
8901 struct drm_device
*dev
= obj
->base
.dev
;
8902 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8904 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
8906 if (!obj
->frontbuffer_bits
)
8910 mutex_lock(&dev_priv
->fb_tracking
.lock
);
8911 dev_priv
->fb_tracking
.busy_bits
8912 |= obj
->frontbuffer_bits
;
8913 dev_priv
->fb_tracking
.flip_bits
8914 &= ~obj
->frontbuffer_bits
;
8915 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
8918 intel_mark_fb_busy(dev
, obj
->frontbuffer_bits
, ring
);
8920 intel_edp_psr_exit(dev
);
8924 * intel_frontbuffer_flush - flush frontbuffer
8926 * @frontbuffer_bits: frontbuffer plane tracking bits
8928 * This function gets called every time rendering on the given planes has
8929 * completed and frontbuffer caching can be started again. Flushes will get
8930 * delayed if they're blocked by some oustanding asynchronous rendering.
8932 * Can be called without any locks held.
8934 void intel_frontbuffer_flush(struct drm_device
*dev
,
8935 unsigned frontbuffer_bits
)
8937 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8939 /* Delay flushing when rings are still busy.*/
8940 mutex_lock(&dev_priv
->fb_tracking
.lock
);
8941 frontbuffer_bits
&= ~dev_priv
->fb_tracking
.busy_bits
;
8942 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
8944 intel_mark_fb_busy(dev
, frontbuffer_bits
, NULL
);
8946 intel_edp_psr_exit(dev
);
8950 * intel_fb_obj_flush - flush frontbuffer object
8951 * @obj: GEM object to flush
8952 * @retire: set when retiring asynchronous rendering
8954 * This function gets called every time rendering on the given object has
8955 * completed and frontbuffer caching can be started again. If @retire is true
8956 * then any delayed flushes will be unblocked.
8958 void intel_fb_obj_flush(struct drm_i915_gem_object
*obj
,
8961 struct drm_device
*dev
= obj
->base
.dev
;
8962 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8963 unsigned frontbuffer_bits
;
8965 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
8967 if (!obj
->frontbuffer_bits
)
8970 frontbuffer_bits
= obj
->frontbuffer_bits
;
8973 mutex_lock(&dev_priv
->fb_tracking
.lock
);
8974 /* Filter out new bits since rendering started. */
8975 frontbuffer_bits
&= dev_priv
->fb_tracking
.busy_bits
;
8977 dev_priv
->fb_tracking
.busy_bits
&= ~frontbuffer_bits
;
8978 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
8981 intel_frontbuffer_flush(dev
, frontbuffer_bits
);
8985 * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
8987 * @frontbuffer_bits: frontbuffer plane tracking bits
8989 * This function gets called after scheduling a flip on @obj. The actual
8990 * frontbuffer flushing will be delayed until completion is signalled with
8991 * intel_frontbuffer_flip_complete. If an invalidate happens in between this
8992 * flush will be cancelled.
8994 * Can be called without any locks held.
8996 void intel_frontbuffer_flip_prepare(struct drm_device
*dev
,
8997 unsigned frontbuffer_bits
)
8999 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9001 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9002 dev_priv
->fb_tracking
.flip_bits
9003 |= frontbuffer_bits
;
9004 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9008 * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
9010 * @frontbuffer_bits: frontbuffer plane tracking bits
9012 * This function gets called after the flip has been latched and will complete
9013 * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
9015 * Can be called without any locks held.
9017 void intel_frontbuffer_flip_complete(struct drm_device
*dev
,
9018 unsigned frontbuffer_bits
)
9020 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9022 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9023 /* Mask any cancelled flips. */
9024 frontbuffer_bits
&= dev_priv
->fb_tracking
.flip_bits
;
9025 dev_priv
->fb_tracking
.flip_bits
&= ~frontbuffer_bits
;
9026 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9028 intel_frontbuffer_flush(dev
, frontbuffer_bits
);
9031 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
9033 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9034 struct drm_device
*dev
= crtc
->dev
;
9035 struct intel_unpin_work
*work
;
9036 unsigned long flags
;
9038 spin_lock_irqsave(&dev
->event_lock
, flags
);
9039 work
= intel_crtc
->unpin_work
;
9040 intel_crtc
->unpin_work
= NULL
;
9041 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9044 cancel_work_sync(&work
->work
);
9048 drm_crtc_cleanup(crtc
);
9053 static void intel_unpin_work_fn(struct work_struct
*__work
)
9055 struct intel_unpin_work
*work
=
9056 container_of(__work
, struct intel_unpin_work
, work
);
9057 struct drm_device
*dev
= work
->crtc
->dev
;
9058 enum pipe pipe
= to_intel_crtc(work
->crtc
)->pipe
;
9060 mutex_lock(&dev
->struct_mutex
);
9061 intel_unpin_fb_obj(work
->old_fb_obj
);
9062 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
9063 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
9065 intel_update_fbc(dev
);
9066 mutex_unlock(&dev
->struct_mutex
);
9068 intel_frontbuffer_flip_complete(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
9070 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
9071 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
9076 static void do_intel_finish_page_flip(struct drm_device
*dev
,
9077 struct drm_crtc
*crtc
)
9079 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9080 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9081 struct intel_unpin_work
*work
;
9082 unsigned long flags
;
9084 /* Ignore early vblank irqs */
9085 if (intel_crtc
== NULL
)
9088 spin_lock_irqsave(&dev
->event_lock
, flags
);
9089 work
= intel_crtc
->unpin_work
;
9091 /* Ensure we don't miss a work->pending update ... */
9094 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
9095 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9099 /* and that the unpin work is consistent wrt ->pending. */
9102 intel_crtc
->unpin_work
= NULL
;
9105 drm_send_vblank_event(dev
, intel_crtc
->pipe
, work
->event
);
9107 drm_crtc_vblank_put(crtc
);
9109 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9111 wake_up_all(&dev_priv
->pending_flip_queue
);
9113 queue_work(dev_priv
->wq
, &work
->work
);
9115 trace_i915_flip_complete(intel_crtc
->plane
, work
->pending_flip_obj
);
9118 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
9120 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9121 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
9123 do_intel_finish_page_flip(dev
, crtc
);
9126 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
9128 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9129 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
9131 do_intel_finish_page_flip(dev
, crtc
);
9134 /* Is 'a' after or equal to 'b'? */
9135 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
9137 return !((a
- b
) & 0x80000000);
9140 static bool page_flip_finished(struct intel_crtc
*crtc
)
9142 struct drm_device
*dev
= crtc
->base
.dev
;
9143 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9146 * The relevant registers doen't exist on pre-ctg.
9147 * As the flip done interrupt doesn't trigger for mmio
9148 * flips on gmch platforms, a flip count check isn't
9149 * really needed there. But since ctg has the registers,
9150 * include it in the check anyway.
9152 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
9156 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
9157 * used the same base address. In that case the mmio flip might
9158 * have completed, but the CS hasn't even executed the flip yet.
9160 * A flip count check isn't enough as the CS might have updated
9161 * the base address just after start of vblank, but before we
9162 * managed to process the interrupt. This means we'd complete the
9165 * Combining both checks should get us a good enough result. It may
9166 * still happen that the CS flip has been executed, but has not
9167 * yet actually completed. But in case the base address is the same
9168 * anyway, we don't really care.
9170 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
9171 crtc
->unpin_work
->gtt_offset
&&
9172 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc
->pipe
)),
9173 crtc
->unpin_work
->flip_count
);
9176 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
9178 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9179 struct intel_crtc
*intel_crtc
=
9180 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
9181 unsigned long flags
;
9183 /* NB: An MMIO update of the plane base pointer will also
9184 * generate a page-flip completion irq, i.e. every modeset
9185 * is also accompanied by a spurious intel_prepare_page_flip().
9187 spin_lock_irqsave(&dev
->event_lock
, flags
);
9188 if (intel_crtc
->unpin_work
&& page_flip_finished(intel_crtc
))
9189 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
9190 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9193 static inline void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
9195 /* Ensure that the work item is consistent when activating it ... */
9197 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
9198 /* and that it is marked active as soon as the irq could fire. */
9202 static int intel_gen2_queue_flip(struct drm_device
*dev
,
9203 struct drm_crtc
*crtc
,
9204 struct drm_framebuffer
*fb
,
9205 struct drm_i915_gem_object
*obj
,
9206 struct intel_engine_cs
*ring
,
9209 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9213 ret
= intel_ring_begin(ring
, 6);
9217 /* Can't queue multiple flips, so wait for the previous
9218 * one to finish before executing the next.
9220 if (intel_crtc
->plane
)
9221 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9223 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9224 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9225 intel_ring_emit(ring
, MI_NOOP
);
9226 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9227 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9228 intel_ring_emit(ring
, fb
->pitches
[0]);
9229 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9230 intel_ring_emit(ring
, 0); /* aux display base address, unused */
9232 intel_mark_page_flip_active(intel_crtc
);
9233 __intel_ring_advance(ring
);
9237 static int intel_gen3_queue_flip(struct drm_device
*dev
,
9238 struct drm_crtc
*crtc
,
9239 struct drm_framebuffer
*fb
,
9240 struct drm_i915_gem_object
*obj
,
9241 struct intel_engine_cs
*ring
,
9244 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9248 ret
= intel_ring_begin(ring
, 6);
9252 if (intel_crtc
->plane
)
9253 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9255 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9256 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9257 intel_ring_emit(ring
, MI_NOOP
);
9258 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
9259 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9260 intel_ring_emit(ring
, fb
->pitches
[0]);
9261 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9262 intel_ring_emit(ring
, MI_NOOP
);
9264 intel_mark_page_flip_active(intel_crtc
);
9265 __intel_ring_advance(ring
);
9269 static int intel_gen4_queue_flip(struct drm_device
*dev
,
9270 struct drm_crtc
*crtc
,
9271 struct drm_framebuffer
*fb
,
9272 struct drm_i915_gem_object
*obj
,
9273 struct intel_engine_cs
*ring
,
9276 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9277 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9278 uint32_t pf
, pipesrc
;
9281 ret
= intel_ring_begin(ring
, 4);
9285 /* i965+ uses the linear or tiled offsets from the
9286 * Display Registers (which do not change across a page-flip)
9287 * so we need only reprogram the base address.
9289 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9290 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9291 intel_ring_emit(ring
, fb
->pitches
[0]);
9292 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
|
9295 /* XXX Enabling the panel-fitter across page-flip is so far
9296 * untested on non-native modes, so ignore it for now.
9297 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
9300 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9301 intel_ring_emit(ring
, pf
| pipesrc
);
9303 intel_mark_page_flip_active(intel_crtc
);
9304 __intel_ring_advance(ring
);
9308 static int intel_gen6_queue_flip(struct drm_device
*dev
,
9309 struct drm_crtc
*crtc
,
9310 struct drm_framebuffer
*fb
,
9311 struct drm_i915_gem_object
*obj
,
9312 struct intel_engine_cs
*ring
,
9315 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9316 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9317 uint32_t pf
, pipesrc
;
9320 ret
= intel_ring_begin(ring
, 4);
9324 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9325 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9326 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
9327 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9329 /* Contrary to the suggestions in the documentation,
9330 * "Enable Panel Fitter" does not seem to be required when page
9331 * flipping with a non-native mode, and worse causes a normal
9333 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
9336 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9337 intel_ring_emit(ring
, pf
| pipesrc
);
9339 intel_mark_page_flip_active(intel_crtc
);
9340 __intel_ring_advance(ring
);
9344 static int intel_gen7_queue_flip(struct drm_device
*dev
,
9345 struct drm_crtc
*crtc
,
9346 struct drm_framebuffer
*fb
,
9347 struct drm_i915_gem_object
*obj
,
9348 struct intel_engine_cs
*ring
,
9351 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9352 uint32_t plane_bit
= 0;
9355 switch (intel_crtc
->plane
) {
9357 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
9360 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
9363 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
9366 WARN_ONCE(1, "unknown plane in flip command\n");
9371 if (ring
->id
== RCS
) {
9374 * On Gen 8, SRM is now taking an extra dword to accommodate
9375 * 48bits addresses, and we need a NOOP for the batch size to
9383 * BSpec MI_DISPLAY_FLIP for IVB:
9384 * "The full packet must be contained within the same cache line."
9386 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
9387 * cacheline, if we ever start emitting more commands before
9388 * the MI_DISPLAY_FLIP we may need to first emit everything else,
9389 * then do the cacheline alignment, and finally emit the
9392 ret
= intel_ring_cacheline_align(ring
);
9396 ret
= intel_ring_begin(ring
, len
);
9400 /* Unmask the flip-done completion message. Note that the bspec says that
9401 * we should do this for both the BCS and RCS, and that we must not unmask
9402 * more than one flip event at any time (or ensure that one flip message
9403 * can be sent by waiting for flip-done prior to queueing new flips).
9404 * Experimentation says that BCS works despite DERRMR masking all
9405 * flip-done completion events and that unmasking all planes at once
9406 * for the RCS also doesn't appear to drop events. Setting the DERRMR
9407 * to zero does lead to lockups within MI_DISPLAY_FLIP.
9409 if (ring
->id
== RCS
) {
9410 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
9411 intel_ring_emit(ring
, DERRMR
);
9412 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
9413 DERRMR_PIPEB_PRI_FLIP_DONE
|
9414 DERRMR_PIPEC_PRI_FLIP_DONE
));
9416 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8(1) |
9417 MI_SRM_LRM_GLOBAL_GTT
);
9419 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM(1) |
9420 MI_SRM_LRM_GLOBAL_GTT
);
9421 intel_ring_emit(ring
, DERRMR
);
9422 intel_ring_emit(ring
, ring
->scratch
.gtt_offset
+ 256);
9424 intel_ring_emit(ring
, 0);
9425 intel_ring_emit(ring
, MI_NOOP
);
9429 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
9430 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
9431 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9432 intel_ring_emit(ring
, (MI_NOOP
));
9434 intel_mark_page_flip_active(intel_crtc
);
9435 __intel_ring_advance(ring
);
9439 static bool use_mmio_flip(struct intel_engine_cs
*ring
,
9440 struct drm_i915_gem_object
*obj
)
9443 * This is not being used for older platforms, because
9444 * non-availability of flip done interrupt forces us to use
9445 * CS flips. Older platforms derive flip done using some clever
9446 * tricks involving the flip_pending status bits and vblank irqs.
9447 * So using MMIO flips there would disrupt this mechanism.
9450 if (INTEL_INFO(ring
->dev
)->gen
< 5)
9453 if (i915
.use_mmio_flip
< 0)
9455 else if (i915
.use_mmio_flip
> 0)
9458 return ring
!= obj
->ring
;
9461 static void intel_do_mmio_flip(struct intel_crtc
*intel_crtc
)
9463 struct drm_device
*dev
= intel_crtc
->base
.dev
;
9464 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9465 struct intel_framebuffer
*intel_fb
=
9466 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
9467 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
9471 intel_mark_page_flip_active(intel_crtc
);
9473 reg
= DSPCNTR(intel_crtc
->plane
);
9474 dspcntr
= I915_READ(reg
);
9476 if (INTEL_INFO(dev
)->gen
>= 4) {
9477 if (obj
->tiling_mode
!= I915_TILING_NONE
)
9478 dspcntr
|= DISPPLANE_TILED
;
9480 dspcntr
&= ~DISPPLANE_TILED
;
9482 I915_WRITE(reg
, dspcntr
);
9484 I915_WRITE(DSPSURF(intel_crtc
->plane
),
9485 intel_crtc
->unpin_work
->gtt_offset
);
9486 POSTING_READ(DSPSURF(intel_crtc
->plane
));
9489 static int intel_postpone_flip(struct drm_i915_gem_object
*obj
)
9491 struct intel_engine_cs
*ring
;
9494 lockdep_assert_held(&obj
->base
.dev
->struct_mutex
);
9496 if (!obj
->last_write_seqno
)
9501 if (i915_seqno_passed(ring
->get_seqno(ring
, true),
9502 obj
->last_write_seqno
))
9505 ret
= i915_gem_check_olr(ring
, obj
->last_write_seqno
);
9509 if (WARN_ON(!ring
->irq_get(ring
)))
9515 void intel_notify_mmio_flip(struct intel_engine_cs
*ring
)
9517 struct drm_i915_private
*dev_priv
= to_i915(ring
->dev
);
9518 struct intel_crtc
*intel_crtc
;
9519 unsigned long irq_flags
;
9522 seqno
= ring
->get_seqno(ring
, false);
9524 spin_lock_irqsave(&dev_priv
->mmio_flip_lock
, irq_flags
);
9525 for_each_intel_crtc(ring
->dev
, intel_crtc
) {
9526 struct intel_mmio_flip
*mmio_flip
;
9528 mmio_flip
= &intel_crtc
->mmio_flip
;
9529 if (mmio_flip
->seqno
== 0)
9532 if (ring
->id
!= mmio_flip
->ring_id
)
9535 if (i915_seqno_passed(seqno
, mmio_flip
->seqno
)) {
9536 intel_do_mmio_flip(intel_crtc
);
9537 mmio_flip
->seqno
= 0;
9538 ring
->irq_put(ring
);
9541 spin_unlock_irqrestore(&dev_priv
->mmio_flip_lock
, irq_flags
);
9544 static int intel_queue_mmio_flip(struct drm_device
*dev
,
9545 struct drm_crtc
*crtc
,
9546 struct drm_framebuffer
*fb
,
9547 struct drm_i915_gem_object
*obj
,
9548 struct intel_engine_cs
*ring
,
9551 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9552 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9553 unsigned long irq_flags
;
9556 if (WARN_ON(intel_crtc
->mmio_flip
.seqno
))
9559 ret
= intel_postpone_flip(obj
);
9563 intel_do_mmio_flip(intel_crtc
);
9567 spin_lock_irqsave(&dev_priv
->mmio_flip_lock
, irq_flags
);
9568 intel_crtc
->mmio_flip
.seqno
= obj
->last_write_seqno
;
9569 intel_crtc
->mmio_flip
.ring_id
= obj
->ring
->id
;
9570 spin_unlock_irqrestore(&dev_priv
->mmio_flip_lock
, irq_flags
);
9573 * Double check to catch cases where irq fired before
9574 * mmio flip data was ready
9576 intel_notify_mmio_flip(obj
->ring
);
9580 static int intel_default_queue_flip(struct drm_device
*dev
,
9581 struct drm_crtc
*crtc
,
9582 struct drm_framebuffer
*fb
,
9583 struct drm_i915_gem_object
*obj
,
9584 struct intel_engine_cs
*ring
,
9590 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
9591 struct drm_framebuffer
*fb
,
9592 struct drm_pending_vblank_event
*event
,
9593 uint32_t page_flip_flags
)
9595 struct drm_device
*dev
= crtc
->dev
;
9596 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9597 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
9598 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(fb
)->obj
;
9599 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9600 enum pipe pipe
= intel_crtc
->pipe
;
9601 struct intel_unpin_work
*work
;
9602 struct intel_engine_cs
*ring
;
9603 unsigned long flags
;
9606 /* Can't change pixel format via MI display flips. */
9607 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
9611 * TILEOFF/LINOFF registers can't be changed via MI display flips.
9612 * Note that pitch changes could also affect these register.
9614 if (INTEL_INFO(dev
)->gen
> 3 &&
9615 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
9616 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
9619 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
9622 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
9626 work
->event
= event
;
9628 work
->old_fb_obj
= to_intel_framebuffer(old_fb
)->obj
;
9629 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
9631 ret
= drm_crtc_vblank_get(crtc
);
9635 /* We borrow the event spin lock for protecting unpin_work */
9636 spin_lock_irqsave(&dev
->event_lock
, flags
);
9637 if (intel_crtc
->unpin_work
) {
9638 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9640 drm_crtc_vblank_put(crtc
);
9642 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
9645 intel_crtc
->unpin_work
= work
;
9646 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9648 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
9649 flush_workqueue(dev_priv
->wq
);
9651 ret
= i915_mutex_lock_interruptible(dev
);
9655 /* Reference the objects for the scheduled work. */
9656 drm_gem_object_reference(&work
->old_fb_obj
->base
);
9657 drm_gem_object_reference(&obj
->base
);
9659 crtc
->primary
->fb
= fb
;
9661 work
->pending_flip_obj
= obj
;
9663 work
->enable_stall_check
= true;
9665 atomic_inc(&intel_crtc
->unpin_work_count
);
9666 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
9668 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
9669 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_GM45(pipe
)) + 1;
9671 if (IS_VALLEYVIEW(dev
)) {
9672 ring
= &dev_priv
->ring
[BCS
];
9673 } else if (INTEL_INFO(dev
)->gen
>= 7) {
9675 if (ring
== NULL
|| ring
->id
!= RCS
)
9676 ring
= &dev_priv
->ring
[BCS
];
9678 ring
= &dev_priv
->ring
[RCS
];
9681 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
9683 goto cleanup_pending
;
9686 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
;
9688 if (use_mmio_flip(ring
, obj
))
9689 ret
= intel_queue_mmio_flip(dev
, crtc
, fb
, obj
, ring
,
9692 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, ring
,
9697 i915_gem_track_fb(work
->old_fb_obj
, obj
,
9698 INTEL_FRONTBUFFER_PRIMARY(pipe
));
9700 intel_disable_fbc(dev
);
9701 intel_frontbuffer_flip_prepare(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
9702 mutex_unlock(&dev
->struct_mutex
);
9704 trace_i915_flip_request(intel_crtc
->plane
, obj
);
9709 intel_unpin_fb_obj(obj
);
9711 atomic_dec(&intel_crtc
->unpin_work_count
);
9712 crtc
->primary
->fb
= old_fb
;
9713 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
9714 drm_gem_object_unreference(&obj
->base
);
9715 mutex_unlock(&dev
->struct_mutex
);
9718 spin_lock_irqsave(&dev
->event_lock
, flags
);
9719 intel_crtc
->unpin_work
= NULL
;
9720 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9722 drm_crtc_vblank_put(crtc
);
9728 intel_crtc_wait_for_pending_flips(crtc
);
9729 ret
= intel_pipe_set_base(crtc
, crtc
->x
, crtc
->y
, fb
);
9730 if (ret
== 0 && event
)
9731 drm_send_vblank_event(dev
, pipe
, event
);
9736 static struct drm_crtc_helper_funcs intel_helper_funcs
= {
9737 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
9738 .load_lut
= intel_crtc_load_lut
,
9742 * intel_modeset_update_staged_output_state
9744 * Updates the staged output configuration state, e.g. after we've read out the
9747 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
9749 struct intel_crtc
*crtc
;
9750 struct intel_encoder
*encoder
;
9751 struct intel_connector
*connector
;
9753 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9755 connector
->new_encoder
=
9756 to_intel_encoder(connector
->base
.encoder
);
9759 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9762 to_intel_crtc(encoder
->base
.crtc
);
9765 for_each_intel_crtc(dev
, crtc
) {
9766 crtc
->new_enabled
= crtc
->base
.enabled
;
9768 if (crtc
->new_enabled
)
9769 crtc
->new_config
= &crtc
->config
;
9771 crtc
->new_config
= NULL
;
9776 * intel_modeset_commit_output_state
9778 * This function copies the stage display pipe configuration to the real one.
9780 static void intel_modeset_commit_output_state(struct drm_device
*dev
)
9782 struct intel_crtc
*crtc
;
9783 struct intel_encoder
*encoder
;
9784 struct intel_connector
*connector
;
9786 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9788 connector
->base
.encoder
= &connector
->new_encoder
->base
;
9791 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9793 encoder
->base
.crtc
= &encoder
->new_crtc
->base
;
9796 for_each_intel_crtc(dev
, crtc
) {
9797 crtc
->base
.enabled
= crtc
->new_enabled
;
9802 connected_sink_compute_bpp(struct intel_connector
*connector
,
9803 struct intel_crtc_config
*pipe_config
)
9805 int bpp
= pipe_config
->pipe_bpp
;
9807 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
9808 connector
->base
.base
.id
,
9809 connector
->base
.name
);
9811 /* Don't use an invalid EDID bpc value */
9812 if (connector
->base
.display_info
.bpc
&&
9813 connector
->base
.display_info
.bpc
* 3 < bpp
) {
9814 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
9815 bpp
, connector
->base
.display_info
.bpc
*3);
9816 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
9819 /* Clamp bpp to 8 on screens without EDID 1.4 */
9820 if (connector
->base
.display_info
.bpc
== 0 && bpp
> 24) {
9821 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
9823 pipe_config
->pipe_bpp
= 24;
9828 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
9829 struct drm_framebuffer
*fb
,
9830 struct intel_crtc_config
*pipe_config
)
9832 struct drm_device
*dev
= crtc
->base
.dev
;
9833 struct intel_connector
*connector
;
9836 switch (fb
->pixel_format
) {
9838 bpp
= 8*3; /* since we go through a colormap */
9840 case DRM_FORMAT_XRGB1555
:
9841 case DRM_FORMAT_ARGB1555
:
9842 /* checked in intel_framebuffer_init already */
9843 if (WARN_ON(INTEL_INFO(dev
)->gen
> 3))
9845 case DRM_FORMAT_RGB565
:
9846 bpp
= 6*3; /* min is 18bpp */
9848 case DRM_FORMAT_XBGR8888
:
9849 case DRM_FORMAT_ABGR8888
:
9850 /* checked in intel_framebuffer_init already */
9851 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
9853 case DRM_FORMAT_XRGB8888
:
9854 case DRM_FORMAT_ARGB8888
:
9857 case DRM_FORMAT_XRGB2101010
:
9858 case DRM_FORMAT_ARGB2101010
:
9859 case DRM_FORMAT_XBGR2101010
:
9860 case DRM_FORMAT_ABGR2101010
:
9861 /* checked in intel_framebuffer_init already */
9862 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
9866 /* TODO: gen4+ supports 16 bpc floating point, too. */
9868 DRM_DEBUG_KMS("unsupported depth\n");
9872 pipe_config
->pipe_bpp
= bpp
;
9874 /* Clamp display bpp to EDID value */
9875 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9877 if (!connector
->new_encoder
||
9878 connector
->new_encoder
->new_crtc
!= crtc
)
9881 connected_sink_compute_bpp(connector
, pipe_config
);
9887 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
9889 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
9890 "type: 0x%x flags: 0x%x\n",
9892 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
9893 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
9894 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
9895 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
9898 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
9899 struct intel_crtc_config
*pipe_config
,
9900 const char *context
)
9902 DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc
->base
.base
.id
,
9903 context
, pipe_name(crtc
->pipe
));
9905 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config
->cpu_transcoder
));
9906 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
9907 pipe_config
->pipe_bpp
, pipe_config
->dither
);
9908 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
9909 pipe_config
->has_pch_encoder
,
9910 pipe_config
->fdi_lanes
,
9911 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
9912 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
9913 pipe_config
->fdi_m_n
.tu
);
9914 DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
9915 pipe_config
->has_dp_encoder
,
9916 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
9917 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
9918 pipe_config
->dp_m_n
.tu
);
9919 DRM_DEBUG_KMS("requested mode:\n");
9920 drm_mode_debug_printmodeline(&pipe_config
->requested_mode
);
9921 DRM_DEBUG_KMS("adjusted mode:\n");
9922 drm_mode_debug_printmodeline(&pipe_config
->adjusted_mode
);
9923 intel_dump_crtc_timings(&pipe_config
->adjusted_mode
);
9924 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
9925 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
9926 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
9927 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
9928 pipe_config
->gmch_pfit
.control
,
9929 pipe_config
->gmch_pfit
.pgm_ratios
,
9930 pipe_config
->gmch_pfit
.lvds_border_bits
);
9931 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
9932 pipe_config
->pch_pfit
.pos
,
9933 pipe_config
->pch_pfit
.size
,
9934 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
9935 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
9936 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
9939 static bool encoders_cloneable(const struct intel_encoder
*a
,
9940 const struct intel_encoder
*b
)
9942 /* masks could be asymmetric, so check both ways */
9943 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
9944 b
->cloneable
& (1 << a
->type
));
9947 static bool check_single_encoder_cloning(struct intel_crtc
*crtc
,
9948 struct intel_encoder
*encoder
)
9950 struct drm_device
*dev
= crtc
->base
.dev
;
9951 struct intel_encoder
*source_encoder
;
9953 list_for_each_entry(source_encoder
,
9954 &dev
->mode_config
.encoder_list
, base
.head
) {
9955 if (source_encoder
->new_crtc
!= crtc
)
9958 if (!encoders_cloneable(encoder
, source_encoder
))
9965 static bool check_encoder_cloning(struct intel_crtc
*crtc
)
9967 struct drm_device
*dev
= crtc
->base
.dev
;
9968 struct intel_encoder
*encoder
;
9970 list_for_each_entry(encoder
,
9971 &dev
->mode_config
.encoder_list
, base
.head
) {
9972 if (encoder
->new_crtc
!= crtc
)
9975 if (!check_single_encoder_cloning(crtc
, encoder
))
9982 static struct intel_crtc_config
*
9983 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
9984 struct drm_framebuffer
*fb
,
9985 struct drm_display_mode
*mode
)
9987 struct drm_device
*dev
= crtc
->dev
;
9988 struct intel_encoder
*encoder
;
9989 struct intel_crtc_config
*pipe_config
;
9990 int plane_bpp
, ret
= -EINVAL
;
9993 if (!check_encoder_cloning(to_intel_crtc(crtc
))) {
9994 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
9995 return ERR_PTR(-EINVAL
);
9998 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
10000 return ERR_PTR(-ENOMEM
);
10002 drm_mode_copy(&pipe_config
->adjusted_mode
, mode
);
10003 drm_mode_copy(&pipe_config
->requested_mode
, mode
);
10005 pipe_config
->cpu_transcoder
=
10006 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
10007 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
10010 * Sanitize sync polarity flags based on requested ones. If neither
10011 * positive or negative polarity is requested, treat this as meaning
10012 * negative polarity.
10014 if (!(pipe_config
->adjusted_mode
.flags
&
10015 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
10016 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
10018 if (!(pipe_config
->adjusted_mode
.flags
&
10019 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
10020 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
10022 /* Compute a starting value for pipe_config->pipe_bpp taking the source
10023 * plane pixel format and any sink constraints into account. Returns the
10024 * source plane bpp so that dithering can be selected on mismatches
10025 * after encoders and crtc also have had their say. */
10026 plane_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
10032 * Determine the real pipe dimensions. Note that stereo modes can
10033 * increase the actual pipe size due to the frame doubling and
10034 * insertion of additional space for blanks between the frame. This
10035 * is stored in the crtc timings. We use the requested mode to do this
10036 * computation to clearly distinguish it from the adjusted mode, which
10037 * can be changed by the connectors in the below retry loop.
10039 drm_mode_set_crtcinfo(&pipe_config
->requested_mode
, CRTC_STEREO_DOUBLE
);
10040 pipe_config
->pipe_src_w
= pipe_config
->requested_mode
.crtc_hdisplay
;
10041 pipe_config
->pipe_src_h
= pipe_config
->requested_mode
.crtc_vdisplay
;
10044 /* Ensure the port clock defaults are reset when retrying. */
10045 pipe_config
->port_clock
= 0;
10046 pipe_config
->pixel_multiplier
= 1;
10048 /* Fill in default crtc timings, allow encoders to overwrite them. */
10049 drm_mode_set_crtcinfo(&pipe_config
->adjusted_mode
, CRTC_STEREO_DOUBLE
);
10051 /* Pass our mode to the connectors and the CRTC to give them a chance to
10052 * adjust it according to limitations or connector properties, and also
10053 * a chance to reject the mode entirely.
10055 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10058 if (&encoder
->new_crtc
->base
!= crtc
)
10061 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
10062 DRM_DEBUG_KMS("Encoder config failure\n");
10067 /* Set default port clock if not overwritten by the encoder. Needs to be
10068 * done afterwards in case the encoder adjusts the mode. */
10069 if (!pipe_config
->port_clock
)
10070 pipe_config
->port_clock
= pipe_config
->adjusted_mode
.crtc_clock
10071 * pipe_config
->pixel_multiplier
;
10073 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
10075 DRM_DEBUG_KMS("CRTC fixup failed\n");
10079 if (ret
== RETRY
) {
10080 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
10085 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
10087 goto encoder_retry
;
10090 pipe_config
->dither
= pipe_config
->pipe_bpp
!= plane_bpp
;
10091 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
10092 plane_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
10094 return pipe_config
;
10096 kfree(pipe_config
);
10097 return ERR_PTR(ret
);
10100 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
10101 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
10103 intel_modeset_affected_pipes(struct drm_crtc
*crtc
, unsigned *modeset_pipes
,
10104 unsigned *prepare_pipes
, unsigned *disable_pipes
)
10106 struct intel_crtc
*intel_crtc
;
10107 struct drm_device
*dev
= crtc
->dev
;
10108 struct intel_encoder
*encoder
;
10109 struct intel_connector
*connector
;
10110 struct drm_crtc
*tmp_crtc
;
10112 *disable_pipes
= *modeset_pipes
= *prepare_pipes
= 0;
10114 /* Check which crtcs have changed outputs connected to them, these need
10115 * to be part of the prepare_pipes mask. We don't (yet) support global
10116 * modeset across multiple crtcs, so modeset_pipes will only have one
10117 * bit set at most. */
10118 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10120 if (connector
->base
.encoder
== &connector
->new_encoder
->base
)
10123 if (connector
->base
.encoder
) {
10124 tmp_crtc
= connector
->base
.encoder
->crtc
;
10126 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
10129 if (connector
->new_encoder
)
10131 1 << connector
->new_encoder
->new_crtc
->pipe
;
10134 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10136 if (encoder
->base
.crtc
== &encoder
->new_crtc
->base
)
10139 if (encoder
->base
.crtc
) {
10140 tmp_crtc
= encoder
->base
.crtc
;
10142 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
10145 if (encoder
->new_crtc
)
10146 *prepare_pipes
|= 1 << encoder
->new_crtc
->pipe
;
10149 /* Check for pipes that will be enabled/disabled ... */
10150 for_each_intel_crtc(dev
, intel_crtc
) {
10151 if (intel_crtc
->base
.enabled
== intel_crtc
->new_enabled
)
10154 if (!intel_crtc
->new_enabled
)
10155 *disable_pipes
|= 1 << intel_crtc
->pipe
;
10157 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
10161 /* set_mode is also used to update properties on life display pipes. */
10162 intel_crtc
= to_intel_crtc(crtc
);
10163 if (intel_crtc
->new_enabled
)
10164 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
10167 * For simplicity do a full modeset on any pipe where the output routing
10168 * changed. We could be more clever, but that would require us to be
10169 * more careful with calling the relevant encoder->mode_set functions.
10171 if (*prepare_pipes
)
10172 *modeset_pipes
= *prepare_pipes
;
10174 /* ... and mask these out. */
10175 *modeset_pipes
&= ~(*disable_pipes
);
10176 *prepare_pipes
&= ~(*disable_pipes
);
10179 * HACK: We don't (yet) fully support global modesets. intel_set_config
10180 * obies this rule, but the modeset restore mode of
10181 * intel_modeset_setup_hw_state does not.
10183 *modeset_pipes
&= 1 << intel_crtc
->pipe
;
10184 *prepare_pipes
&= 1 << intel_crtc
->pipe
;
10186 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
10187 *modeset_pipes
, *prepare_pipes
, *disable_pipes
);
10190 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
10192 struct drm_encoder
*encoder
;
10193 struct drm_device
*dev
= crtc
->dev
;
10195 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
10196 if (encoder
->crtc
== crtc
)
10203 intel_modeset_update_state(struct drm_device
*dev
, unsigned prepare_pipes
)
10205 struct intel_encoder
*intel_encoder
;
10206 struct intel_crtc
*intel_crtc
;
10207 struct drm_connector
*connector
;
10209 list_for_each_entry(intel_encoder
, &dev
->mode_config
.encoder_list
,
10211 if (!intel_encoder
->base
.crtc
)
10214 intel_crtc
= to_intel_crtc(intel_encoder
->base
.crtc
);
10216 if (prepare_pipes
& (1 << intel_crtc
->pipe
))
10217 intel_encoder
->connectors_active
= false;
10220 intel_modeset_commit_output_state(dev
);
10222 /* Double check state. */
10223 for_each_intel_crtc(dev
, intel_crtc
) {
10224 WARN_ON(intel_crtc
->base
.enabled
!= intel_crtc_in_use(&intel_crtc
->base
));
10225 WARN_ON(intel_crtc
->new_config
&&
10226 intel_crtc
->new_config
!= &intel_crtc
->config
);
10227 WARN_ON(intel_crtc
->base
.enabled
!= !!intel_crtc
->new_config
);
10230 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
10231 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
10234 intel_crtc
= to_intel_crtc(connector
->encoder
->crtc
);
10236 if (prepare_pipes
& (1 << intel_crtc
->pipe
)) {
10237 struct drm_property
*dpms_property
=
10238 dev
->mode_config
.dpms_property
;
10240 connector
->dpms
= DRM_MODE_DPMS_ON
;
10241 drm_object_property_set_value(&connector
->base
,
10245 intel_encoder
= to_intel_encoder(connector
->encoder
);
10246 intel_encoder
->connectors_active
= true;
10252 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
10256 if (clock1
== clock2
)
10259 if (!clock1
|| !clock2
)
10262 diff
= abs(clock1
- clock2
);
10264 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
10270 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
10271 list_for_each_entry((intel_crtc), \
10272 &(dev)->mode_config.crtc_list, \
10274 if (mask & (1 <<(intel_crtc)->pipe))
10277 intel_pipe_config_compare(struct drm_device
*dev
,
10278 struct intel_crtc_config
*current_config
,
10279 struct intel_crtc_config
*pipe_config
)
10281 #define PIPE_CONF_CHECK_X(name) \
10282 if (current_config->name != pipe_config->name) { \
10283 DRM_ERROR("mismatch in " #name " " \
10284 "(expected 0x%08x, found 0x%08x)\n", \
10285 current_config->name, \
10286 pipe_config->name); \
10290 #define PIPE_CONF_CHECK_I(name) \
10291 if (current_config->name != pipe_config->name) { \
10292 DRM_ERROR("mismatch in " #name " " \
10293 "(expected %i, found %i)\n", \
10294 current_config->name, \
10295 pipe_config->name); \
10299 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
10300 if ((current_config->name ^ pipe_config->name) & (mask)) { \
10301 DRM_ERROR("mismatch in " #name "(" #mask ") " \
10302 "(expected %i, found %i)\n", \
10303 current_config->name & (mask), \
10304 pipe_config->name & (mask)); \
10308 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
10309 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
10310 DRM_ERROR("mismatch in " #name " " \
10311 "(expected %i, found %i)\n", \
10312 current_config->name, \
10313 pipe_config->name); \
10317 #define PIPE_CONF_QUIRK(quirk) \
10318 ((current_config->quirks | pipe_config->quirks) & (quirk))
10320 PIPE_CONF_CHECK_I(cpu_transcoder
);
10322 PIPE_CONF_CHECK_I(has_pch_encoder
);
10323 PIPE_CONF_CHECK_I(fdi_lanes
);
10324 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_m
);
10325 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_n
);
10326 PIPE_CONF_CHECK_I(fdi_m_n
.link_m
);
10327 PIPE_CONF_CHECK_I(fdi_m_n
.link_n
);
10328 PIPE_CONF_CHECK_I(fdi_m_n
.tu
);
10330 PIPE_CONF_CHECK_I(has_dp_encoder
);
10331 PIPE_CONF_CHECK_I(dp_m_n
.gmch_m
);
10332 PIPE_CONF_CHECK_I(dp_m_n
.gmch_n
);
10333 PIPE_CONF_CHECK_I(dp_m_n
.link_m
);
10334 PIPE_CONF_CHECK_I(dp_m_n
.link_n
);
10335 PIPE_CONF_CHECK_I(dp_m_n
.tu
);
10337 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hdisplay
);
10338 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_htotal
);
10339 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_start
);
10340 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_end
);
10341 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_start
);
10342 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_end
);
10344 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vdisplay
);
10345 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vtotal
);
10346 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_start
);
10347 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_end
);
10348 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_start
);
10349 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_end
);
10351 PIPE_CONF_CHECK_I(pixel_multiplier
);
10352 PIPE_CONF_CHECK_I(has_hdmi_sink
);
10353 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
10354 IS_VALLEYVIEW(dev
))
10355 PIPE_CONF_CHECK_I(limited_color_range
);
10357 PIPE_CONF_CHECK_I(has_audio
);
10359 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10360 DRM_MODE_FLAG_INTERLACE
);
10362 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
10363 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10364 DRM_MODE_FLAG_PHSYNC
);
10365 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10366 DRM_MODE_FLAG_NHSYNC
);
10367 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10368 DRM_MODE_FLAG_PVSYNC
);
10369 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10370 DRM_MODE_FLAG_NVSYNC
);
10373 PIPE_CONF_CHECK_I(pipe_src_w
);
10374 PIPE_CONF_CHECK_I(pipe_src_h
);
10377 * FIXME: BIOS likes to set up a cloned config with lvds+external
10378 * screen. Since we don't yet re-compute the pipe config when moving
10379 * just the lvds port away to another pipe the sw tracking won't match.
10381 * Proper atomic modesets with recomputed global state will fix this.
10382 * Until then just don't check gmch state for inherited modes.
10384 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE
)) {
10385 PIPE_CONF_CHECK_I(gmch_pfit
.control
);
10386 /* pfit ratios are autocomputed by the hw on gen4+ */
10387 if (INTEL_INFO(dev
)->gen
< 4)
10388 PIPE_CONF_CHECK_I(gmch_pfit
.pgm_ratios
);
10389 PIPE_CONF_CHECK_I(gmch_pfit
.lvds_border_bits
);
10392 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
10393 if (current_config
->pch_pfit
.enabled
) {
10394 PIPE_CONF_CHECK_I(pch_pfit
.pos
);
10395 PIPE_CONF_CHECK_I(pch_pfit
.size
);
10398 /* BDW+ don't expose a synchronous way to read the state */
10399 if (IS_HASWELL(dev
))
10400 PIPE_CONF_CHECK_I(ips_enabled
);
10402 PIPE_CONF_CHECK_I(double_wide
);
10404 PIPE_CONF_CHECK_I(shared_dpll
);
10405 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
10406 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
10407 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
10408 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
10410 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
10411 PIPE_CONF_CHECK_I(pipe_bpp
);
10413 PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode
.crtc_clock
);
10414 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
10416 #undef PIPE_CONF_CHECK_X
10417 #undef PIPE_CONF_CHECK_I
10418 #undef PIPE_CONF_CHECK_FLAGS
10419 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
10420 #undef PIPE_CONF_QUIRK
10426 check_connector_state(struct drm_device
*dev
)
10428 struct intel_connector
*connector
;
10430 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10432 /* This also checks the encoder/connector hw state with the
10433 * ->get_hw_state callbacks. */
10434 intel_connector_check_state(connector
);
10436 WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
10437 "connector's staged encoder doesn't match current encoder\n");
10442 check_encoder_state(struct drm_device
*dev
)
10444 struct intel_encoder
*encoder
;
10445 struct intel_connector
*connector
;
10447 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10449 bool enabled
= false;
10450 bool active
= false;
10451 enum pipe pipe
, tracked_pipe
;
10453 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
10454 encoder
->base
.base
.id
,
10455 encoder
->base
.name
);
10457 WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
10458 "encoder's stage crtc doesn't match current crtc\n");
10459 WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
10460 "encoder's active_connectors set, but no crtc\n");
10462 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10464 if (connector
->base
.encoder
!= &encoder
->base
)
10467 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
10470 WARN(!!encoder
->base
.crtc
!= enabled
,
10471 "encoder's enabled state mismatch "
10472 "(expected %i, found %i)\n",
10473 !!encoder
->base
.crtc
, enabled
);
10474 WARN(active
&& !encoder
->base
.crtc
,
10475 "active encoder with no crtc\n");
10477 WARN(encoder
->connectors_active
!= active
,
10478 "encoder's computed active state doesn't match tracked active state "
10479 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
10481 active
= encoder
->get_hw_state(encoder
, &pipe
);
10482 WARN(active
!= encoder
->connectors_active
,
10483 "encoder's hw state doesn't match sw tracking "
10484 "(expected %i, found %i)\n",
10485 encoder
->connectors_active
, active
);
10487 if (!encoder
->base
.crtc
)
10490 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
10491 WARN(active
&& pipe
!= tracked_pipe
,
10492 "active encoder's pipe doesn't match"
10493 "(expected %i, found %i)\n",
10494 tracked_pipe
, pipe
);
10500 check_crtc_state(struct drm_device
*dev
)
10502 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10503 struct intel_crtc
*crtc
;
10504 struct intel_encoder
*encoder
;
10505 struct intel_crtc_config pipe_config
;
10507 for_each_intel_crtc(dev
, crtc
) {
10508 bool enabled
= false;
10509 bool active
= false;
10511 memset(&pipe_config
, 0, sizeof(pipe_config
));
10513 DRM_DEBUG_KMS("[CRTC:%d]\n",
10514 crtc
->base
.base
.id
);
10516 WARN(crtc
->active
&& !crtc
->base
.enabled
,
10517 "active crtc, but not enabled in sw tracking\n");
10519 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10521 if (encoder
->base
.crtc
!= &crtc
->base
)
10524 if (encoder
->connectors_active
)
10528 WARN(active
!= crtc
->active
,
10529 "crtc's computed active state doesn't match tracked active state "
10530 "(expected %i, found %i)\n", active
, crtc
->active
);
10531 WARN(enabled
!= crtc
->base
.enabled
,
10532 "crtc's computed enabled state doesn't match tracked enabled state "
10533 "(expected %i, found %i)\n", enabled
, crtc
->base
.enabled
);
10535 active
= dev_priv
->display
.get_pipe_config(crtc
,
10538 /* hw state is inconsistent with the pipe A quirk */
10539 if (crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
)
10540 active
= crtc
->active
;
10542 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10545 if (encoder
->base
.crtc
!= &crtc
->base
)
10547 if (encoder
->get_hw_state(encoder
, &pipe
))
10548 encoder
->get_config(encoder
, &pipe_config
);
10551 WARN(crtc
->active
!= active
,
10552 "crtc active state doesn't match with hw state "
10553 "(expected %i, found %i)\n", crtc
->active
, active
);
10556 !intel_pipe_config_compare(dev
, &crtc
->config
, &pipe_config
)) {
10557 WARN(1, "pipe state doesn't match!\n");
10558 intel_dump_pipe_config(crtc
, &pipe_config
,
10560 intel_dump_pipe_config(crtc
, &crtc
->config
,
10567 check_shared_dpll_state(struct drm_device
*dev
)
10569 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10570 struct intel_crtc
*crtc
;
10571 struct intel_dpll_hw_state dpll_hw_state
;
10574 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
10575 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
10576 int enabled_crtcs
= 0, active_crtcs
= 0;
10579 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
10581 DRM_DEBUG_KMS("%s\n", pll
->name
);
10583 active
= pll
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
10585 WARN(pll
->active
> pll
->refcount
,
10586 "more active pll users than references: %i vs %i\n",
10587 pll
->active
, pll
->refcount
);
10588 WARN(pll
->active
&& !pll
->on
,
10589 "pll in active use but not on in sw tracking\n");
10590 WARN(pll
->on
&& !pll
->active
,
10591 "pll in on but not on in use in sw tracking\n");
10592 WARN(pll
->on
!= active
,
10593 "pll on state mismatch (expected %i, found %i)\n",
10596 for_each_intel_crtc(dev
, crtc
) {
10597 if (crtc
->base
.enabled
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10599 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10602 WARN(pll
->active
!= active_crtcs
,
10603 "pll active crtcs mismatch (expected %i, found %i)\n",
10604 pll
->active
, active_crtcs
);
10605 WARN(pll
->refcount
!= enabled_crtcs
,
10606 "pll enabled crtcs mismatch (expected %i, found %i)\n",
10607 pll
->refcount
, enabled_crtcs
);
10609 WARN(pll
->on
&& memcmp(&pll
->hw_state
, &dpll_hw_state
,
10610 sizeof(dpll_hw_state
)),
10611 "pll hw state mismatch\n");
10616 intel_modeset_check_state(struct drm_device
*dev
)
10618 check_connector_state(dev
);
10619 check_encoder_state(dev
);
10620 check_crtc_state(dev
);
10621 check_shared_dpll_state(dev
);
10624 void ironlake_check_encoder_dotclock(const struct intel_crtc_config
*pipe_config
,
10628 * FDI already provided one idea for the dotclock.
10629 * Yell if the encoder disagrees.
10631 WARN(!intel_fuzzy_clock_check(pipe_config
->adjusted_mode
.crtc_clock
, dotclock
),
10632 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
10633 pipe_config
->adjusted_mode
.crtc_clock
, dotclock
);
10636 static void update_scanline_offset(struct intel_crtc
*crtc
)
10638 struct drm_device
*dev
= crtc
->base
.dev
;
10641 * The scanline counter increments at the leading edge of hsync.
10643 * On most platforms it starts counting from vtotal-1 on the
10644 * first active line. That means the scanline counter value is
10645 * always one less than what we would expect. Ie. just after
10646 * start of vblank, which also occurs at start of hsync (on the
10647 * last active line), the scanline counter will read vblank_start-1.
10649 * On gen2 the scanline counter starts counting from 1 instead
10650 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
10651 * to keep the value positive), instead of adding one.
10653 * On HSW+ the behaviour of the scanline counter depends on the output
10654 * type. For DP ports it behaves like most other platforms, but on HDMI
10655 * there's an extra 1 line difference. So we need to add two instead of
10656 * one to the value.
10658 if (IS_GEN2(dev
)) {
10659 const struct drm_display_mode
*mode
= &crtc
->config
.adjusted_mode
;
10662 vtotal
= mode
->crtc_vtotal
;
10663 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
10666 crtc
->scanline_offset
= vtotal
- 1;
10667 } else if (HAS_DDI(dev
) &&
10668 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
)) {
10669 crtc
->scanline_offset
= 2;
10671 crtc
->scanline_offset
= 1;
10674 static int __intel_set_mode(struct drm_crtc
*crtc
,
10675 struct drm_display_mode
*mode
,
10676 int x
, int y
, struct drm_framebuffer
*fb
)
10678 struct drm_device
*dev
= crtc
->dev
;
10679 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10680 struct drm_display_mode
*saved_mode
;
10681 struct intel_crtc_config
*pipe_config
= NULL
;
10682 struct intel_crtc
*intel_crtc
;
10683 unsigned disable_pipes
, prepare_pipes
, modeset_pipes
;
10686 saved_mode
= kmalloc(sizeof(*saved_mode
), GFP_KERNEL
);
10690 intel_modeset_affected_pipes(crtc
, &modeset_pipes
,
10691 &prepare_pipes
, &disable_pipes
);
10693 *saved_mode
= crtc
->mode
;
10695 /* Hack: Because we don't (yet) support global modeset on multiple
10696 * crtcs, we don't keep track of the new mode for more than one crtc.
10697 * Hence simply check whether any bit is set in modeset_pipes in all the
10698 * pieces of code that are not yet converted to deal with mutliple crtcs
10699 * changing their mode at the same time. */
10700 if (modeset_pipes
) {
10701 pipe_config
= intel_modeset_pipe_config(crtc
, fb
, mode
);
10702 if (IS_ERR(pipe_config
)) {
10703 ret
= PTR_ERR(pipe_config
);
10704 pipe_config
= NULL
;
10708 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
10710 to_intel_crtc(crtc
)->new_config
= pipe_config
;
10714 * See if the config requires any additional preparation, e.g.
10715 * to adjust global state with pipes off. We need to do this
10716 * here so we can get the modeset_pipe updated config for the new
10717 * mode set on this crtc. For other crtcs we need to use the
10718 * adjusted_mode bits in the crtc directly.
10720 if (IS_VALLEYVIEW(dev
)) {
10721 valleyview_modeset_global_pipes(dev
, &prepare_pipes
);
10723 /* may have added more to prepare_pipes than we should */
10724 prepare_pipes
&= ~disable_pipes
;
10727 for_each_intel_crtc_masked(dev
, disable_pipes
, intel_crtc
)
10728 intel_crtc_disable(&intel_crtc
->base
);
10730 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
10731 if (intel_crtc
->base
.enabled
)
10732 dev_priv
->display
.crtc_disable(&intel_crtc
->base
);
10735 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
10736 * to set it here already despite that we pass it down the callchain.
10738 if (modeset_pipes
) {
10739 crtc
->mode
= *mode
;
10740 /* mode_set/enable/disable functions rely on a correct pipe
10742 to_intel_crtc(crtc
)->config
= *pipe_config
;
10743 to_intel_crtc(crtc
)->new_config
= &to_intel_crtc(crtc
)->config
;
10746 * Calculate and store various constants which
10747 * are later needed by vblank and swap-completion
10748 * timestamping. They are derived from true hwmode.
10750 drm_calc_timestamping_constants(crtc
,
10751 &pipe_config
->adjusted_mode
);
10754 /* Only after disabling all output pipelines that will be changed can we
10755 * update the the output configuration. */
10756 intel_modeset_update_state(dev
, prepare_pipes
);
10758 if (dev_priv
->display
.modeset_global_resources
)
10759 dev_priv
->display
.modeset_global_resources(dev
);
10761 /* Set up the DPLL and any encoders state that needs to adjust or depend
10764 for_each_intel_crtc_masked(dev
, modeset_pipes
, intel_crtc
) {
10765 struct drm_framebuffer
*old_fb
;
10766 struct drm_i915_gem_object
*old_obj
= NULL
;
10767 struct drm_i915_gem_object
*obj
=
10768 to_intel_framebuffer(fb
)->obj
;
10770 mutex_lock(&dev
->struct_mutex
);
10771 ret
= intel_pin_and_fence_fb_obj(dev
,
10775 DRM_ERROR("pin & fence failed\n");
10776 mutex_unlock(&dev
->struct_mutex
);
10779 old_fb
= crtc
->primary
->fb
;
10781 old_obj
= to_intel_framebuffer(old_fb
)->obj
;
10782 intel_unpin_fb_obj(old_obj
);
10784 i915_gem_track_fb(old_obj
, obj
,
10785 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
10786 mutex_unlock(&dev
->struct_mutex
);
10788 crtc
->primary
->fb
= fb
;
10792 ret
= dev_priv
->display
.crtc_mode_set(&intel_crtc
->base
,
10798 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
10799 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
10800 update_scanline_offset(intel_crtc
);
10802 dev_priv
->display
.crtc_enable(&intel_crtc
->base
);
10805 /* FIXME: add subpixel order */
10807 if (ret
&& crtc
->enabled
)
10808 crtc
->mode
= *saved_mode
;
10811 kfree(pipe_config
);
10816 static int intel_set_mode(struct drm_crtc
*crtc
,
10817 struct drm_display_mode
*mode
,
10818 int x
, int y
, struct drm_framebuffer
*fb
)
10822 ret
= __intel_set_mode(crtc
, mode
, x
, y
, fb
);
10825 intel_modeset_check_state(crtc
->dev
);
10830 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
10832 intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
, crtc
->primary
->fb
);
10835 #undef for_each_intel_crtc_masked
10837 static void intel_set_config_free(struct intel_set_config
*config
)
10842 kfree(config
->save_connector_encoders
);
10843 kfree(config
->save_encoder_crtcs
);
10844 kfree(config
->save_crtc_enabled
);
10848 static int intel_set_config_save_state(struct drm_device
*dev
,
10849 struct intel_set_config
*config
)
10851 struct drm_crtc
*crtc
;
10852 struct drm_encoder
*encoder
;
10853 struct drm_connector
*connector
;
10856 config
->save_crtc_enabled
=
10857 kcalloc(dev
->mode_config
.num_crtc
,
10858 sizeof(bool), GFP_KERNEL
);
10859 if (!config
->save_crtc_enabled
)
10862 config
->save_encoder_crtcs
=
10863 kcalloc(dev
->mode_config
.num_encoder
,
10864 sizeof(struct drm_crtc
*), GFP_KERNEL
);
10865 if (!config
->save_encoder_crtcs
)
10868 config
->save_connector_encoders
=
10869 kcalloc(dev
->mode_config
.num_connector
,
10870 sizeof(struct drm_encoder
*), GFP_KERNEL
);
10871 if (!config
->save_connector_encoders
)
10874 /* Copy data. Note that driver private data is not affected.
10875 * Should anything bad happen only the expected state is
10876 * restored, not the drivers personal bookkeeping.
10879 for_each_crtc(dev
, crtc
) {
10880 config
->save_crtc_enabled
[count
++] = crtc
->enabled
;
10884 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
10885 config
->save_encoder_crtcs
[count
++] = encoder
->crtc
;
10889 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
10890 config
->save_connector_encoders
[count
++] = connector
->encoder
;
10896 static void intel_set_config_restore_state(struct drm_device
*dev
,
10897 struct intel_set_config
*config
)
10899 struct intel_crtc
*crtc
;
10900 struct intel_encoder
*encoder
;
10901 struct intel_connector
*connector
;
10905 for_each_intel_crtc(dev
, crtc
) {
10906 crtc
->new_enabled
= config
->save_crtc_enabled
[count
++];
10908 if (crtc
->new_enabled
)
10909 crtc
->new_config
= &crtc
->config
;
10911 crtc
->new_config
= NULL
;
10915 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
10916 encoder
->new_crtc
=
10917 to_intel_crtc(config
->save_encoder_crtcs
[count
++]);
10921 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
10922 connector
->new_encoder
=
10923 to_intel_encoder(config
->save_connector_encoders
[count
++]);
10928 is_crtc_connector_off(struct drm_mode_set
*set
)
10932 if (set
->num_connectors
== 0)
10935 if (WARN_ON(set
->connectors
== NULL
))
10938 for (i
= 0; i
< set
->num_connectors
; i
++)
10939 if (set
->connectors
[i
]->encoder
&&
10940 set
->connectors
[i
]->encoder
->crtc
== set
->crtc
&&
10941 set
->connectors
[i
]->dpms
!= DRM_MODE_DPMS_ON
)
10948 intel_set_config_compute_mode_changes(struct drm_mode_set
*set
,
10949 struct intel_set_config
*config
)
10952 /* We should be able to check here if the fb has the same properties
10953 * and then just flip_or_move it */
10954 if (is_crtc_connector_off(set
)) {
10955 config
->mode_changed
= true;
10956 } else if (set
->crtc
->primary
->fb
!= set
->fb
) {
10958 * If we have no fb, we can only flip as long as the crtc is
10959 * active, otherwise we need a full mode set. The crtc may
10960 * be active if we've only disabled the primary plane, or
10961 * in fastboot situations.
10963 if (set
->crtc
->primary
->fb
== NULL
) {
10964 struct intel_crtc
*intel_crtc
=
10965 to_intel_crtc(set
->crtc
);
10967 if (intel_crtc
->active
) {
10968 DRM_DEBUG_KMS("crtc has no fb, will flip\n");
10969 config
->fb_changed
= true;
10971 DRM_DEBUG_KMS("inactive crtc, full mode set\n");
10972 config
->mode_changed
= true;
10974 } else if (set
->fb
== NULL
) {
10975 config
->mode_changed
= true;
10976 } else if (set
->fb
->pixel_format
!=
10977 set
->crtc
->primary
->fb
->pixel_format
) {
10978 config
->mode_changed
= true;
10980 config
->fb_changed
= true;
10984 if (set
->fb
&& (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
))
10985 config
->fb_changed
= true;
10987 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
10988 DRM_DEBUG_KMS("modes are different, full mode set\n");
10989 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
10990 drm_mode_debug_printmodeline(set
->mode
);
10991 config
->mode_changed
= true;
10994 DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
10995 set
->crtc
->base
.id
, config
->mode_changed
, config
->fb_changed
);
10999 intel_modeset_stage_output_state(struct drm_device
*dev
,
11000 struct drm_mode_set
*set
,
11001 struct intel_set_config
*config
)
11003 struct intel_connector
*connector
;
11004 struct intel_encoder
*encoder
;
11005 struct intel_crtc
*crtc
;
11008 /* The upper layers ensure that we either disable a crtc or have a list
11009 * of connectors. For paranoia, double-check this. */
11010 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
11011 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
11013 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
11015 /* Otherwise traverse passed in connector list and get encoders
11017 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
11018 if (set
->connectors
[ro
] == &connector
->base
) {
11019 connector
->new_encoder
= connector
->encoder
;
11024 /* If we disable the crtc, disable all its connectors. Also, if
11025 * the connector is on the changing crtc but not on the new
11026 * connector list, disable it. */
11027 if ((!set
->fb
|| ro
== set
->num_connectors
) &&
11028 connector
->base
.encoder
&&
11029 connector
->base
.encoder
->crtc
== set
->crtc
) {
11030 connector
->new_encoder
= NULL
;
11032 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
11033 connector
->base
.base
.id
,
11034 connector
->base
.name
);
11038 if (&connector
->new_encoder
->base
!= connector
->base
.encoder
) {
11039 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
11040 config
->mode_changed
= true;
11043 /* connector->new_encoder is now updated for all connectors. */
11045 /* Update crtc of enabled connectors. */
11046 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
11048 struct drm_crtc
*new_crtc
;
11050 if (!connector
->new_encoder
)
11053 new_crtc
= connector
->new_encoder
->base
.crtc
;
11055 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
11056 if (set
->connectors
[ro
] == &connector
->base
)
11057 new_crtc
= set
->crtc
;
11060 /* Make sure the new CRTC will work with the encoder */
11061 if (!drm_encoder_crtc_ok(&connector
->new_encoder
->base
,
11065 connector
->encoder
->new_crtc
= to_intel_crtc(new_crtc
);
11067 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
11068 connector
->base
.base
.id
,
11069 connector
->base
.name
,
11070 new_crtc
->base
.id
);
11073 /* Check for any encoders that needs to be disabled. */
11074 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
11076 int num_connectors
= 0;
11077 list_for_each_entry(connector
,
11078 &dev
->mode_config
.connector_list
,
11080 if (connector
->new_encoder
== encoder
) {
11081 WARN_ON(!connector
->new_encoder
->new_crtc
);
11086 if (num_connectors
== 0)
11087 encoder
->new_crtc
= NULL
;
11088 else if (num_connectors
> 1)
11091 /* Only now check for crtc changes so we don't miss encoders
11092 * that will be disabled. */
11093 if (&encoder
->new_crtc
->base
!= encoder
->base
.crtc
) {
11094 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
11095 config
->mode_changed
= true;
11098 /* Now we've also updated encoder->new_crtc for all encoders. */
11100 for_each_intel_crtc(dev
, crtc
) {
11101 crtc
->new_enabled
= false;
11103 list_for_each_entry(encoder
,
11104 &dev
->mode_config
.encoder_list
,
11106 if (encoder
->new_crtc
== crtc
) {
11107 crtc
->new_enabled
= true;
11112 if (crtc
->new_enabled
!= crtc
->base
.enabled
) {
11113 DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
11114 crtc
->new_enabled
? "en" : "dis");
11115 config
->mode_changed
= true;
11118 if (crtc
->new_enabled
)
11119 crtc
->new_config
= &crtc
->config
;
11121 crtc
->new_config
= NULL
;
11127 static void disable_crtc_nofb(struct intel_crtc
*crtc
)
11129 struct drm_device
*dev
= crtc
->base
.dev
;
11130 struct intel_encoder
*encoder
;
11131 struct intel_connector
*connector
;
11133 DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
11134 pipe_name(crtc
->pipe
));
11136 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
11137 if (connector
->new_encoder
&&
11138 connector
->new_encoder
->new_crtc
== crtc
)
11139 connector
->new_encoder
= NULL
;
11142 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
11143 if (encoder
->new_crtc
== crtc
)
11144 encoder
->new_crtc
= NULL
;
11147 crtc
->new_enabled
= false;
11148 crtc
->new_config
= NULL
;
11151 static int intel_crtc_set_config(struct drm_mode_set
*set
)
11153 struct drm_device
*dev
;
11154 struct drm_mode_set save_set
;
11155 struct intel_set_config
*config
;
11159 BUG_ON(!set
->crtc
);
11160 BUG_ON(!set
->crtc
->helper_private
);
11162 /* Enforce sane interface api - has been abused by the fb helper. */
11163 BUG_ON(!set
->mode
&& set
->fb
);
11164 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
11167 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
11168 set
->crtc
->base
.id
, set
->fb
->base
.id
,
11169 (int)set
->num_connectors
, set
->x
, set
->y
);
11171 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
11174 dev
= set
->crtc
->dev
;
11177 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
11181 ret
= intel_set_config_save_state(dev
, config
);
11185 save_set
.crtc
= set
->crtc
;
11186 save_set
.mode
= &set
->crtc
->mode
;
11187 save_set
.x
= set
->crtc
->x
;
11188 save_set
.y
= set
->crtc
->y
;
11189 save_set
.fb
= set
->crtc
->primary
->fb
;
11191 /* Compute whether we need a full modeset, only an fb base update or no
11192 * change at all. In the future we might also check whether only the
11193 * mode changed, e.g. for LVDS where we only change the panel fitter in
11195 intel_set_config_compute_mode_changes(set
, config
);
11197 ret
= intel_modeset_stage_output_state(dev
, set
, config
);
11201 if (config
->mode_changed
) {
11202 ret
= intel_set_mode(set
->crtc
, set
->mode
,
11203 set
->x
, set
->y
, set
->fb
);
11204 } else if (config
->fb_changed
) {
11205 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11206 struct intel_crtc
*intel_crtc
= to_intel_crtc(set
->crtc
);
11208 intel_crtc_wait_for_pending_flips(set
->crtc
);
11210 ret
= intel_pipe_set_base(set
->crtc
,
11211 set
->x
, set
->y
, set
->fb
);
11214 * We need to make sure the primary plane is re-enabled if it
11215 * has previously been turned off.
11217 if (!intel_crtc
->primary_enabled
&& ret
== 0) {
11218 WARN_ON(!intel_crtc
->active
);
11219 intel_enable_primary_hw_plane(dev_priv
, intel_crtc
->plane
,
11224 * In the fastboot case this may be our only check of the
11225 * state after boot. It would be better to only do it on
11226 * the first update, but we don't have a nice way of doing that
11227 * (and really, set_config isn't used much for high freq page
11228 * flipping, so increasing its cost here shouldn't be a big
11231 if (i915
.fastboot
&& ret
== 0)
11232 intel_modeset_check_state(set
->crtc
->dev
);
11236 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
11237 set
->crtc
->base
.id
, ret
);
11239 intel_set_config_restore_state(dev
, config
);
11242 * HACK: if the pipe was on, but we didn't have a framebuffer,
11243 * force the pipe off to avoid oopsing in the modeset code
11244 * due to fb==NULL. This should only happen during boot since
11245 * we don't yet reconstruct the FB from the hardware state.
11247 if (to_intel_crtc(save_set
.crtc
)->new_enabled
&& !save_set
.fb
)
11248 disable_crtc_nofb(to_intel_crtc(save_set
.crtc
));
11250 /* Try to restore the config */
11251 if (config
->mode_changed
&&
11252 intel_set_mode(save_set
.crtc
, save_set
.mode
,
11253 save_set
.x
, save_set
.y
, save_set
.fb
))
11254 DRM_ERROR("failed to restore config after modeset failure\n");
11258 intel_set_config_free(config
);
11262 static const struct drm_crtc_funcs intel_crtc_funcs
= {
11263 .gamma_set
= intel_crtc_gamma_set
,
11264 .set_config
= intel_crtc_set_config
,
11265 .destroy
= intel_crtc_destroy
,
11266 .page_flip
= intel_crtc_page_flip
,
11269 static void intel_cpu_pll_init(struct drm_device
*dev
)
11272 intel_ddi_pll_init(dev
);
11275 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private
*dev_priv
,
11276 struct intel_shared_dpll
*pll
,
11277 struct intel_dpll_hw_state
*hw_state
)
11281 val
= I915_READ(PCH_DPLL(pll
->id
));
11282 hw_state
->dpll
= val
;
11283 hw_state
->fp0
= I915_READ(PCH_FP0(pll
->id
));
11284 hw_state
->fp1
= I915_READ(PCH_FP1(pll
->id
));
11286 return val
& DPLL_VCO_ENABLE
;
11289 static void ibx_pch_dpll_mode_set(struct drm_i915_private
*dev_priv
,
11290 struct intel_shared_dpll
*pll
)
11292 I915_WRITE(PCH_FP0(pll
->id
), pll
->hw_state
.fp0
);
11293 I915_WRITE(PCH_FP1(pll
->id
), pll
->hw_state
.fp1
);
11296 static void ibx_pch_dpll_enable(struct drm_i915_private
*dev_priv
,
11297 struct intel_shared_dpll
*pll
)
11299 /* PCH refclock must be enabled first */
11300 ibx_assert_pch_refclk_enabled(dev_priv
);
11302 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11304 /* Wait for the clocks to stabilize. */
11305 POSTING_READ(PCH_DPLL(pll
->id
));
11308 /* The pixel multiplier can only be updated once the
11309 * DPLL is enabled and the clocks are stable.
11311 * So write it again.
11313 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11314 POSTING_READ(PCH_DPLL(pll
->id
));
11318 static void ibx_pch_dpll_disable(struct drm_i915_private
*dev_priv
,
11319 struct intel_shared_dpll
*pll
)
11321 struct drm_device
*dev
= dev_priv
->dev
;
11322 struct intel_crtc
*crtc
;
11324 /* Make sure no transcoder isn't still depending on us. */
11325 for_each_intel_crtc(dev
, crtc
) {
11326 if (intel_crtc_to_shared_dpll(crtc
) == pll
)
11327 assert_pch_transcoder_disabled(dev_priv
, crtc
->pipe
);
11330 I915_WRITE(PCH_DPLL(pll
->id
), 0);
11331 POSTING_READ(PCH_DPLL(pll
->id
));
11335 static char *ibx_pch_dpll_names
[] = {
11340 static void ibx_pch_dpll_init(struct drm_device
*dev
)
11342 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11345 dev_priv
->num_shared_dpll
= 2;
11347 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
11348 dev_priv
->shared_dplls
[i
].id
= i
;
11349 dev_priv
->shared_dplls
[i
].name
= ibx_pch_dpll_names
[i
];
11350 dev_priv
->shared_dplls
[i
].mode_set
= ibx_pch_dpll_mode_set
;
11351 dev_priv
->shared_dplls
[i
].enable
= ibx_pch_dpll_enable
;
11352 dev_priv
->shared_dplls
[i
].disable
= ibx_pch_dpll_disable
;
11353 dev_priv
->shared_dplls
[i
].get_hw_state
=
11354 ibx_pch_dpll_get_hw_state
;
11358 static void intel_shared_dpll_init(struct drm_device
*dev
)
11360 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11362 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
11363 ibx_pch_dpll_init(dev
);
11365 dev_priv
->num_shared_dpll
= 0;
11367 BUG_ON(dev_priv
->num_shared_dpll
> I915_NUM_PLLS
);
11371 intel_primary_plane_disable(struct drm_plane
*plane
)
11373 struct drm_device
*dev
= plane
->dev
;
11374 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11375 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11376 struct intel_crtc
*intel_crtc
;
11381 BUG_ON(!plane
->crtc
);
11383 intel_crtc
= to_intel_crtc(plane
->crtc
);
11386 * Even though we checked plane->fb above, it's still possible that
11387 * the primary plane has been implicitly disabled because the crtc
11388 * coordinates given weren't visible, or because we detected
11389 * that it was 100% covered by a sprite plane. Or, the CRTC may be
11390 * off and we've set a fb, but haven't actually turned on the CRTC yet.
11391 * In either case, we need to unpin the FB and let the fb pointer get
11392 * updated, but otherwise we don't need to touch the hardware.
11394 if (!intel_crtc
->primary_enabled
)
11395 goto disable_unpin
;
11397 intel_crtc_wait_for_pending_flips(plane
->crtc
);
11398 intel_disable_primary_hw_plane(dev_priv
, intel_plane
->plane
,
11399 intel_plane
->pipe
);
11401 i915_gem_track_fb(to_intel_framebuffer(plane
->fb
)->obj
, NULL
,
11402 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11403 intel_unpin_fb_obj(to_intel_framebuffer(plane
->fb
)->obj
);
11410 intel_primary_plane_setplane(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11411 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11412 unsigned int crtc_w
, unsigned int crtc_h
,
11413 uint32_t src_x
, uint32_t src_y
,
11414 uint32_t src_w
, uint32_t src_h
)
11416 struct drm_device
*dev
= crtc
->dev
;
11417 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11418 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11419 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11420 struct drm_i915_gem_object
*obj
, *old_obj
= NULL
;
11421 struct drm_rect dest
= {
11422 /* integer pixels */
11425 .x2
= crtc_x
+ crtc_w
,
11426 .y2
= crtc_y
+ crtc_h
,
11428 struct drm_rect src
= {
11429 /* 16.16 fixed point */
11432 .x2
= src_x
+ src_w
,
11433 .y2
= src_y
+ src_h
,
11435 const struct drm_rect clip
= {
11436 /* integer pixels */
11437 .x2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_w
: 0,
11438 .y2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_h
: 0,
11443 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
11444 &src
, &dest
, &clip
,
11445 DRM_PLANE_HELPER_NO_SCALING
,
11446 DRM_PLANE_HELPER_NO_SCALING
,
11447 false, true, &visible
);
11453 old_obj
= to_intel_framebuffer(plane
->fb
)->obj
;
11454 obj
= to_intel_framebuffer(fb
)->obj
;
11457 * If the CRTC isn't enabled, we're just pinning the framebuffer,
11458 * updating the fb pointer, and returning without touching the
11459 * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
11460 * turn on the display with all planes setup as desired.
11462 if (!crtc
->enabled
) {
11464 * If we already called setplane while the crtc was disabled,
11465 * we may have an fb pinned; unpin it.
11468 intel_unpin_fb_obj(old_obj
);
11470 i915_gem_track_fb(old_obj
, obj
,
11471 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11473 /* Pin and return without programming hardware */
11474 return intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
11477 intel_crtc_wait_for_pending_flips(crtc
);
11480 * If clipping results in a non-visible primary plane, we'll disable
11481 * the primary plane. Note that this is a bit different than what
11482 * happens if userspace explicitly disables the plane by passing fb=0
11483 * because plane->fb still gets set and pinned.
11487 * Try to pin the new fb first so that we can bail out if we
11490 if (plane
->fb
!= fb
) {
11491 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
11496 i915_gem_track_fb(old_obj
, obj
,
11497 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11499 if (intel_crtc
->primary_enabled
)
11500 intel_disable_primary_hw_plane(dev_priv
,
11501 intel_plane
->plane
,
11502 intel_plane
->pipe
);
11505 if (plane
->fb
!= fb
)
11507 intel_unpin_fb_obj(old_obj
);
11512 ret
= intel_pipe_set_base(crtc
, src
.x1
, src
.y1
, fb
);
11516 if (!intel_crtc
->primary_enabled
)
11517 intel_enable_primary_hw_plane(dev_priv
, intel_crtc
->plane
,
11523 /* Common destruction function for both primary and cursor planes */
11524 static void intel_plane_destroy(struct drm_plane
*plane
)
11526 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11527 drm_plane_cleanup(plane
);
11528 kfree(intel_plane
);
11531 static const struct drm_plane_funcs intel_primary_plane_funcs
= {
11532 .update_plane
= intel_primary_plane_setplane
,
11533 .disable_plane
= intel_primary_plane_disable
,
11534 .destroy
= intel_plane_destroy
,
11537 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
11540 struct intel_plane
*primary
;
11541 const uint32_t *intel_primary_formats
;
11544 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
11545 if (primary
== NULL
)
11548 primary
->can_scale
= false;
11549 primary
->max_downscale
= 1;
11550 primary
->pipe
= pipe
;
11551 primary
->plane
= pipe
;
11552 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
11553 primary
->plane
= !pipe
;
11555 if (INTEL_INFO(dev
)->gen
<= 3) {
11556 intel_primary_formats
= intel_primary_formats_gen2
;
11557 num_formats
= ARRAY_SIZE(intel_primary_formats_gen2
);
11559 intel_primary_formats
= intel_primary_formats_gen4
;
11560 num_formats
= ARRAY_SIZE(intel_primary_formats_gen4
);
11563 drm_universal_plane_init(dev
, &primary
->base
, 0,
11564 &intel_primary_plane_funcs
,
11565 intel_primary_formats
, num_formats
,
11566 DRM_PLANE_TYPE_PRIMARY
);
11567 return &primary
->base
;
11571 intel_cursor_plane_disable(struct drm_plane
*plane
)
11576 BUG_ON(!plane
->crtc
);
11578 return intel_crtc_cursor_set_obj(plane
->crtc
, NULL
, 0, 0);
11582 intel_cursor_plane_update(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11583 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11584 unsigned int crtc_w
, unsigned int crtc_h
,
11585 uint32_t src_x
, uint32_t src_y
,
11586 uint32_t src_w
, uint32_t src_h
)
11588 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11589 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11590 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11591 struct drm_rect dest
= {
11592 /* integer pixels */
11595 .x2
= crtc_x
+ crtc_w
,
11596 .y2
= crtc_y
+ crtc_h
,
11598 struct drm_rect src
= {
11599 /* 16.16 fixed point */
11602 .x2
= src_x
+ src_w
,
11603 .y2
= src_y
+ src_h
,
11605 const struct drm_rect clip
= {
11606 /* integer pixels */
11607 .x2
= intel_crtc
->config
.pipe_src_w
,
11608 .y2
= intel_crtc
->config
.pipe_src_h
,
11613 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
11614 &src
, &dest
, &clip
,
11615 DRM_PLANE_HELPER_NO_SCALING
,
11616 DRM_PLANE_HELPER_NO_SCALING
,
11617 true, true, &visible
);
11621 crtc
->cursor_x
= crtc_x
;
11622 crtc
->cursor_y
= crtc_y
;
11623 if (fb
!= crtc
->cursor
->fb
) {
11624 return intel_crtc_cursor_set_obj(crtc
, obj
, crtc_w
, crtc_h
);
11626 intel_crtc_update_cursor(crtc
, visible
);
11630 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
11631 .update_plane
= intel_cursor_plane_update
,
11632 .disable_plane
= intel_cursor_plane_disable
,
11633 .destroy
= intel_plane_destroy
,
11636 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
11639 struct intel_plane
*cursor
;
11641 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
11642 if (cursor
== NULL
)
11645 cursor
->can_scale
= false;
11646 cursor
->max_downscale
= 1;
11647 cursor
->pipe
= pipe
;
11648 cursor
->plane
= pipe
;
11650 drm_universal_plane_init(dev
, &cursor
->base
, 0,
11651 &intel_cursor_plane_funcs
,
11652 intel_cursor_formats
,
11653 ARRAY_SIZE(intel_cursor_formats
),
11654 DRM_PLANE_TYPE_CURSOR
);
11655 return &cursor
->base
;
11658 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
11660 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11661 struct intel_crtc
*intel_crtc
;
11662 struct drm_plane
*primary
= NULL
;
11663 struct drm_plane
*cursor
= NULL
;
11666 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
11667 if (intel_crtc
== NULL
)
11670 primary
= intel_primary_plane_create(dev
, pipe
);
11674 cursor
= intel_cursor_plane_create(dev
, pipe
);
11678 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
11679 cursor
, &intel_crtc_funcs
);
11683 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
11684 for (i
= 0; i
< 256; i
++) {
11685 intel_crtc
->lut_r
[i
] = i
;
11686 intel_crtc
->lut_g
[i
] = i
;
11687 intel_crtc
->lut_b
[i
] = i
;
11691 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
11692 * is hooked to pipe B. Hence we want plane A feeding pipe B.
11694 intel_crtc
->pipe
= pipe
;
11695 intel_crtc
->plane
= pipe
;
11696 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
11697 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
11698 intel_crtc
->plane
= !pipe
;
11701 intel_crtc
->cursor_base
= ~0;
11702 intel_crtc
->cursor_cntl
= ~0;
11704 init_waitqueue_head(&intel_crtc
->vbl_wait
);
11706 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
11707 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
11708 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
11709 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
11711 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
11713 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
11718 drm_plane_cleanup(primary
);
11720 drm_plane_cleanup(cursor
);
11724 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
11726 struct drm_encoder
*encoder
= connector
->base
.encoder
;
11727 struct drm_device
*dev
= connector
->base
.dev
;
11729 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
11732 return INVALID_PIPE
;
11734 return to_intel_crtc(encoder
->crtc
)->pipe
;
11737 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
11738 struct drm_file
*file
)
11740 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
11741 struct drm_mode_object
*drmmode_obj
;
11742 struct intel_crtc
*crtc
;
11744 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
11747 drmmode_obj
= drm_mode_object_find(dev
, pipe_from_crtc_id
->crtc_id
,
11748 DRM_MODE_OBJECT_CRTC
);
11750 if (!drmmode_obj
) {
11751 DRM_ERROR("no such CRTC id\n");
11755 crtc
= to_intel_crtc(obj_to_crtc(drmmode_obj
));
11756 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
11761 static int intel_encoder_clones(struct intel_encoder
*encoder
)
11763 struct drm_device
*dev
= encoder
->base
.dev
;
11764 struct intel_encoder
*source_encoder
;
11765 int index_mask
= 0;
11768 list_for_each_entry(source_encoder
,
11769 &dev
->mode_config
.encoder_list
, base
.head
) {
11770 if (encoders_cloneable(encoder
, source_encoder
))
11771 index_mask
|= (1 << entry
);
11779 static bool has_edp_a(struct drm_device
*dev
)
11781 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11783 if (!IS_MOBILE(dev
))
11786 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
11789 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
11795 const char *intel_output_name(int output
)
11797 static const char *names
[] = {
11798 [INTEL_OUTPUT_UNUSED
] = "Unused",
11799 [INTEL_OUTPUT_ANALOG
] = "Analog",
11800 [INTEL_OUTPUT_DVO
] = "DVO",
11801 [INTEL_OUTPUT_SDVO
] = "SDVO",
11802 [INTEL_OUTPUT_LVDS
] = "LVDS",
11803 [INTEL_OUTPUT_TVOUT
] = "TV",
11804 [INTEL_OUTPUT_HDMI
] = "HDMI",
11805 [INTEL_OUTPUT_DISPLAYPORT
] = "DisplayPort",
11806 [INTEL_OUTPUT_EDP
] = "eDP",
11807 [INTEL_OUTPUT_DSI
] = "DSI",
11808 [INTEL_OUTPUT_UNKNOWN
] = "Unknown",
11811 if (output
< 0 || output
>= ARRAY_SIZE(names
) || !names
[output
])
11814 return names
[output
];
11817 static bool intel_crt_present(struct drm_device
*dev
)
11819 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11824 if (IS_CHERRYVIEW(dev
))
11827 if (IS_VALLEYVIEW(dev
) && !dev_priv
->vbt
.int_crt_support
)
11833 static void intel_setup_outputs(struct drm_device
*dev
)
11835 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11836 struct intel_encoder
*encoder
;
11837 bool dpd_is_edp
= false;
11839 intel_lvds_init(dev
);
11841 if (intel_crt_present(dev
))
11842 intel_crt_init(dev
);
11844 if (HAS_DDI(dev
)) {
11847 /* Haswell uses DDI functions to detect digital outputs */
11848 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
11849 /* DDI A only supports eDP */
11851 intel_ddi_init(dev
, PORT_A
);
11853 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
11855 found
= I915_READ(SFUSE_STRAP
);
11857 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
11858 intel_ddi_init(dev
, PORT_B
);
11859 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
11860 intel_ddi_init(dev
, PORT_C
);
11861 if (found
& SFUSE_STRAP_DDID_DETECTED
)
11862 intel_ddi_init(dev
, PORT_D
);
11863 } else if (HAS_PCH_SPLIT(dev
)) {
11865 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
11867 if (has_edp_a(dev
))
11868 intel_dp_init(dev
, DP_A
, PORT_A
);
11870 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
11871 /* PCH SDVOB multiplex with HDMIB */
11872 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
11874 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
11875 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
11876 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
11879 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
11880 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
11882 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
11883 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
11885 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
11886 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
11888 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
11889 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
11890 } else if (IS_VALLEYVIEW(dev
)) {
11891 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
) {
11892 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
11894 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
)
11895 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
11898 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIC
) & SDVO_DETECTED
) {
11899 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIC
,
11901 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
)
11902 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
11905 if (IS_CHERRYVIEW(dev
)) {
11906 if (I915_READ(VLV_DISPLAY_BASE
+ CHV_HDMID
) & SDVO_DETECTED
) {
11907 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ CHV_HDMID
,
11909 if (I915_READ(VLV_DISPLAY_BASE
+ DP_D
) & DP_DETECTED
)
11910 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_D
, PORT_D
);
11914 intel_dsi_init(dev
);
11915 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
11916 bool found
= false;
11918 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
11919 DRM_DEBUG_KMS("probing SDVOB\n");
11920 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
11921 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
11922 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
11923 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
11926 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
))
11927 intel_dp_init(dev
, DP_B
, PORT_B
);
11930 /* Before G4X SDVOC doesn't have its own detect register */
11932 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
11933 DRM_DEBUG_KMS("probing SDVOC\n");
11934 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
11937 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
11939 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
11940 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
11941 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
11943 if (SUPPORTS_INTEGRATED_DP(dev
))
11944 intel_dp_init(dev
, DP_C
, PORT_C
);
11947 if (SUPPORTS_INTEGRATED_DP(dev
) &&
11948 (I915_READ(DP_D
) & DP_DETECTED
))
11949 intel_dp_init(dev
, DP_D
, PORT_D
);
11950 } else if (IS_GEN2(dev
))
11951 intel_dvo_init(dev
);
11953 if (SUPPORTS_TV(dev
))
11954 intel_tv_init(dev
);
11956 intel_edp_psr_init(dev
);
11958 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
11959 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
11960 encoder
->base
.possible_clones
=
11961 intel_encoder_clones(encoder
);
11964 intel_init_pch_refclk(dev
);
11966 drm_helper_move_panel_connectors_to_head(dev
);
11969 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
11971 struct drm_device
*dev
= fb
->dev
;
11972 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11974 drm_framebuffer_cleanup(fb
);
11975 mutex_lock(&dev
->struct_mutex
);
11976 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
11977 drm_gem_object_unreference(&intel_fb
->obj
->base
);
11978 mutex_unlock(&dev
->struct_mutex
);
11982 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
11983 struct drm_file
*file
,
11984 unsigned int *handle
)
11986 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11987 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11989 return drm_gem_handle_create(file
, &obj
->base
, handle
);
11992 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
11993 .destroy
= intel_user_framebuffer_destroy
,
11994 .create_handle
= intel_user_framebuffer_create_handle
,
11997 static int intel_framebuffer_init(struct drm_device
*dev
,
11998 struct intel_framebuffer
*intel_fb
,
11999 struct drm_mode_fb_cmd2
*mode_cmd
,
12000 struct drm_i915_gem_object
*obj
)
12002 int aligned_height
;
12006 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
12008 if (obj
->tiling_mode
== I915_TILING_Y
) {
12009 DRM_DEBUG("hardware does not support tiling Y\n");
12013 if (mode_cmd
->pitches
[0] & 63) {
12014 DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
12015 mode_cmd
->pitches
[0]);
12019 if (INTEL_INFO(dev
)->gen
>= 5 && !IS_VALLEYVIEW(dev
)) {
12020 pitch_limit
= 32*1024;
12021 } else if (INTEL_INFO(dev
)->gen
>= 4) {
12022 if (obj
->tiling_mode
)
12023 pitch_limit
= 16*1024;
12025 pitch_limit
= 32*1024;
12026 } else if (INTEL_INFO(dev
)->gen
>= 3) {
12027 if (obj
->tiling_mode
)
12028 pitch_limit
= 8*1024;
12030 pitch_limit
= 16*1024;
12032 /* XXX DSPC is limited to 4k tiled */
12033 pitch_limit
= 8*1024;
12035 if (mode_cmd
->pitches
[0] > pitch_limit
) {
12036 DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
12037 obj
->tiling_mode
? "tiled" : "linear",
12038 mode_cmd
->pitches
[0], pitch_limit
);
12042 if (obj
->tiling_mode
!= I915_TILING_NONE
&&
12043 mode_cmd
->pitches
[0] != obj
->stride
) {
12044 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
12045 mode_cmd
->pitches
[0], obj
->stride
);
12049 /* Reject formats not supported by any plane early. */
12050 switch (mode_cmd
->pixel_format
) {
12051 case DRM_FORMAT_C8
:
12052 case DRM_FORMAT_RGB565
:
12053 case DRM_FORMAT_XRGB8888
:
12054 case DRM_FORMAT_ARGB8888
:
12056 case DRM_FORMAT_XRGB1555
:
12057 case DRM_FORMAT_ARGB1555
:
12058 if (INTEL_INFO(dev
)->gen
> 3) {
12059 DRM_DEBUG("unsupported pixel format: %s\n",
12060 drm_get_format_name(mode_cmd
->pixel_format
));
12064 case DRM_FORMAT_XBGR8888
:
12065 case DRM_FORMAT_ABGR8888
:
12066 case DRM_FORMAT_XRGB2101010
:
12067 case DRM_FORMAT_ARGB2101010
:
12068 case DRM_FORMAT_XBGR2101010
:
12069 case DRM_FORMAT_ABGR2101010
:
12070 if (INTEL_INFO(dev
)->gen
< 4) {
12071 DRM_DEBUG("unsupported pixel format: %s\n",
12072 drm_get_format_name(mode_cmd
->pixel_format
));
12076 case DRM_FORMAT_YUYV
:
12077 case DRM_FORMAT_UYVY
:
12078 case DRM_FORMAT_YVYU
:
12079 case DRM_FORMAT_VYUY
:
12080 if (INTEL_INFO(dev
)->gen
< 5) {
12081 DRM_DEBUG("unsupported pixel format: %s\n",
12082 drm_get_format_name(mode_cmd
->pixel_format
));
12087 DRM_DEBUG("unsupported pixel format: %s\n",
12088 drm_get_format_name(mode_cmd
->pixel_format
));
12092 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
12093 if (mode_cmd
->offsets
[0] != 0)
12096 aligned_height
= intel_align_height(dev
, mode_cmd
->height
,
12098 /* FIXME drm helper for size checks (especially planar formats)? */
12099 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
12102 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
12103 intel_fb
->obj
= obj
;
12104 intel_fb
->obj
->framebuffer_references
++;
12106 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
12108 DRM_ERROR("framebuffer init failed %d\n", ret
);
12115 static struct drm_framebuffer
*
12116 intel_user_framebuffer_create(struct drm_device
*dev
,
12117 struct drm_file
*filp
,
12118 struct drm_mode_fb_cmd2
*mode_cmd
)
12120 struct drm_i915_gem_object
*obj
;
12122 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
12123 mode_cmd
->handles
[0]));
12124 if (&obj
->base
== NULL
)
12125 return ERR_PTR(-ENOENT
);
12127 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
12130 #ifndef CONFIG_DRM_I915_FBDEV
12131 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
12136 static const struct drm_mode_config_funcs intel_mode_funcs
= {
12137 .fb_create
= intel_user_framebuffer_create
,
12138 .output_poll_changed
= intel_fbdev_output_poll_changed
,
12141 /* Set up chip specific display functions */
12142 static void intel_init_display(struct drm_device
*dev
)
12144 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12146 if (HAS_PCH_SPLIT(dev
) || IS_G4X(dev
))
12147 dev_priv
->display
.find_dpll
= g4x_find_best_dpll
;
12148 else if (IS_CHERRYVIEW(dev
))
12149 dev_priv
->display
.find_dpll
= chv_find_best_dpll
;
12150 else if (IS_VALLEYVIEW(dev
))
12151 dev_priv
->display
.find_dpll
= vlv_find_best_dpll
;
12152 else if (IS_PINEVIEW(dev
))
12153 dev_priv
->display
.find_dpll
= pnv_find_best_dpll
;
12155 dev_priv
->display
.find_dpll
= i9xx_find_best_dpll
;
12157 if (HAS_DDI(dev
)) {
12158 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
12159 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
12160 dev_priv
->display
.crtc_mode_set
= haswell_crtc_mode_set
;
12161 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
12162 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
12163 dev_priv
->display
.off
= haswell_crtc_off
;
12164 dev_priv
->display
.update_primary_plane
=
12165 ironlake_update_primary_plane
;
12166 } else if (HAS_PCH_SPLIT(dev
)) {
12167 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
12168 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
12169 dev_priv
->display
.crtc_mode_set
= ironlake_crtc_mode_set
;
12170 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
12171 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
12172 dev_priv
->display
.off
= ironlake_crtc_off
;
12173 dev_priv
->display
.update_primary_plane
=
12174 ironlake_update_primary_plane
;
12175 } else if (IS_VALLEYVIEW(dev
)) {
12176 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
12177 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
12178 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
12179 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
12180 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
12181 dev_priv
->display
.off
= i9xx_crtc_off
;
12182 dev_priv
->display
.update_primary_plane
=
12183 i9xx_update_primary_plane
;
12185 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
12186 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
12187 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
12188 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
12189 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
12190 dev_priv
->display
.off
= i9xx_crtc_off
;
12191 dev_priv
->display
.update_primary_plane
=
12192 i9xx_update_primary_plane
;
12195 /* Returns the core display clock speed */
12196 if (IS_VALLEYVIEW(dev
))
12197 dev_priv
->display
.get_display_clock_speed
=
12198 valleyview_get_display_clock_speed
;
12199 else if (IS_I945G(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
12200 dev_priv
->display
.get_display_clock_speed
=
12201 i945_get_display_clock_speed
;
12202 else if (IS_I915G(dev
))
12203 dev_priv
->display
.get_display_clock_speed
=
12204 i915_get_display_clock_speed
;
12205 else if (IS_I945GM(dev
) || IS_845G(dev
))
12206 dev_priv
->display
.get_display_clock_speed
=
12207 i9xx_misc_get_display_clock_speed
;
12208 else if (IS_PINEVIEW(dev
))
12209 dev_priv
->display
.get_display_clock_speed
=
12210 pnv_get_display_clock_speed
;
12211 else if (IS_I915GM(dev
))
12212 dev_priv
->display
.get_display_clock_speed
=
12213 i915gm_get_display_clock_speed
;
12214 else if (IS_I865G(dev
))
12215 dev_priv
->display
.get_display_clock_speed
=
12216 i865_get_display_clock_speed
;
12217 else if (IS_I85X(dev
))
12218 dev_priv
->display
.get_display_clock_speed
=
12219 i855_get_display_clock_speed
;
12220 else /* 852, 830 */
12221 dev_priv
->display
.get_display_clock_speed
=
12222 i830_get_display_clock_speed
;
12224 if (HAS_PCH_SPLIT(dev
)) {
12225 if (IS_GEN5(dev
)) {
12226 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
12227 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12228 } else if (IS_GEN6(dev
)) {
12229 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
12230 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12231 dev_priv
->display
.modeset_global_resources
=
12232 snb_modeset_global_resources
;
12233 } else if (IS_IVYBRIDGE(dev
)) {
12234 /* FIXME: detect B0+ stepping and use auto training */
12235 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
12236 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12237 dev_priv
->display
.modeset_global_resources
=
12238 ivb_modeset_global_resources
;
12239 } else if (IS_HASWELL(dev
) || IS_GEN8(dev
)) {
12240 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
12241 dev_priv
->display
.write_eld
= haswell_write_eld
;
12242 dev_priv
->display
.modeset_global_resources
=
12243 haswell_modeset_global_resources
;
12245 } else if (IS_G4X(dev
)) {
12246 dev_priv
->display
.write_eld
= g4x_write_eld
;
12247 } else if (IS_VALLEYVIEW(dev
)) {
12248 dev_priv
->display
.modeset_global_resources
=
12249 valleyview_modeset_global_resources
;
12250 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12253 /* Default just returns -ENODEV to indicate unsupported */
12254 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
12256 switch (INTEL_INFO(dev
)->gen
) {
12258 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
12262 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
12267 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
12271 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
12274 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
12275 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
12279 intel_panel_init_backlight_funcs(dev
);
12283 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
12284 * resume, or other times. This quirk makes sure that's the case for
12285 * affected systems.
12287 static void quirk_pipea_force(struct drm_device
*dev
)
12289 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12291 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
12292 DRM_INFO("applying pipe a force quirk\n");
12296 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
12298 static void quirk_ssc_force_disable(struct drm_device
*dev
)
12300 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12301 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
12302 DRM_INFO("applying lvds SSC disable quirk\n");
12306 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
12309 static void quirk_invert_brightness(struct drm_device
*dev
)
12311 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12312 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
12313 DRM_INFO("applying inverted panel brightness quirk\n");
12316 struct intel_quirk
{
12318 int subsystem_vendor
;
12319 int subsystem_device
;
12320 void (*hook
)(struct drm_device
*dev
);
12323 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
12324 struct intel_dmi_quirk
{
12325 void (*hook
)(struct drm_device
*dev
);
12326 const struct dmi_system_id (*dmi_id_list
)[];
12329 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
12331 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
12335 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
12337 .dmi_id_list
= &(const struct dmi_system_id
[]) {
12339 .callback
= intel_dmi_reverse_brightness
,
12340 .ident
= "NCR Corporation",
12341 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
12342 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
12345 { } /* terminating entry */
12347 .hook
= quirk_invert_brightness
,
12351 static struct intel_quirk intel_quirks
[] = {
12352 /* HP Mini needs pipe A force quirk (LP: #322104) */
12353 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force
},
12355 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
12356 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
12358 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
12359 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
12361 /* Lenovo U160 cannot use SSC on LVDS */
12362 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
12364 /* Sony Vaio Y cannot use SSC on LVDS */
12365 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
12367 /* Acer Aspire 5734Z must invert backlight brightness */
12368 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
12370 /* Acer/eMachines G725 */
12371 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
12373 /* Acer/eMachines e725 */
12374 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
12376 /* Acer/Packard Bell NCL20 */
12377 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
12379 /* Acer Aspire 4736Z */
12380 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
12382 /* Acer Aspire 5336 */
12383 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
12386 static void intel_init_quirks(struct drm_device
*dev
)
12388 struct pci_dev
*d
= dev
->pdev
;
12391 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
12392 struct intel_quirk
*q
= &intel_quirks
[i
];
12394 if (d
->device
== q
->device
&&
12395 (d
->subsystem_vendor
== q
->subsystem_vendor
||
12396 q
->subsystem_vendor
== PCI_ANY_ID
) &&
12397 (d
->subsystem_device
== q
->subsystem_device
||
12398 q
->subsystem_device
== PCI_ANY_ID
))
12401 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
12402 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
12403 intel_dmi_quirks
[i
].hook(dev
);
12407 /* Disable the VGA plane that we never use */
12408 static void i915_disable_vga(struct drm_device
*dev
)
12410 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12412 u32 vga_reg
= i915_vgacntrl_reg(dev
);
12414 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
12415 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12416 outb(SR01
, VGA_SR_INDEX
);
12417 sr1
= inb(VGA_SR_DATA
);
12418 outb(sr1
| 1<<5, VGA_SR_DATA
);
12419 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12422 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
12423 POSTING_READ(vga_reg
);
12426 void intel_modeset_init_hw(struct drm_device
*dev
)
12428 intel_prepare_ddi(dev
);
12430 intel_init_clock_gating(dev
);
12432 intel_reset_dpio(dev
);
12434 intel_enable_gt_powersave(dev
);
12437 void intel_modeset_suspend_hw(struct drm_device
*dev
)
12439 intel_suspend_hw(dev
);
12442 void intel_modeset_init(struct drm_device
*dev
)
12444 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12447 struct intel_crtc
*crtc
;
12449 drm_mode_config_init(dev
);
12451 dev
->mode_config
.min_width
= 0;
12452 dev
->mode_config
.min_height
= 0;
12454 dev
->mode_config
.preferred_depth
= 24;
12455 dev
->mode_config
.prefer_shadow
= 1;
12457 dev
->mode_config
.funcs
= &intel_mode_funcs
;
12459 intel_init_quirks(dev
);
12461 intel_init_pm(dev
);
12463 if (INTEL_INFO(dev
)->num_pipes
== 0)
12466 intel_init_display(dev
);
12468 if (IS_GEN2(dev
)) {
12469 dev
->mode_config
.max_width
= 2048;
12470 dev
->mode_config
.max_height
= 2048;
12471 } else if (IS_GEN3(dev
)) {
12472 dev
->mode_config
.max_width
= 4096;
12473 dev
->mode_config
.max_height
= 4096;
12475 dev
->mode_config
.max_width
= 8192;
12476 dev
->mode_config
.max_height
= 8192;
12479 if (IS_GEN2(dev
)) {
12480 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
12481 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
12483 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
12484 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
12487 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
12489 DRM_DEBUG_KMS("%d display pipe%s available.\n",
12490 INTEL_INFO(dev
)->num_pipes
,
12491 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
12493 for_each_pipe(pipe
) {
12494 intel_crtc_init(dev
, pipe
);
12495 for_each_sprite(pipe
, sprite
) {
12496 ret
= intel_plane_init(dev
, pipe
, sprite
);
12498 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
12499 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
12503 intel_init_dpio(dev
);
12504 intel_reset_dpio(dev
);
12506 intel_cpu_pll_init(dev
);
12507 intel_shared_dpll_init(dev
);
12509 /* Just disable it once at startup */
12510 i915_disable_vga(dev
);
12511 intel_setup_outputs(dev
);
12513 /* Just in case the BIOS is doing something questionable. */
12514 intel_disable_fbc(dev
);
12516 drm_modeset_lock_all(dev
);
12517 intel_modeset_setup_hw_state(dev
, false);
12518 drm_modeset_unlock_all(dev
);
12520 for_each_intel_crtc(dev
, crtc
) {
12525 * Note that reserving the BIOS fb up front prevents us
12526 * from stuffing other stolen allocations like the ring
12527 * on top. This prevents some ugliness at boot time, and
12528 * can even allow for smooth boot transitions if the BIOS
12529 * fb is large enough for the active pipe configuration.
12531 if (dev_priv
->display
.get_plane_config
) {
12532 dev_priv
->display
.get_plane_config(crtc
,
12533 &crtc
->plane_config
);
12535 * If the fb is shared between multiple heads, we'll
12536 * just get the first one.
12538 intel_find_plane_obj(crtc
, &crtc
->plane_config
);
12543 static void intel_enable_pipe_a(struct drm_device
*dev
)
12545 struct intel_connector
*connector
;
12546 struct drm_connector
*crt
= NULL
;
12547 struct intel_load_detect_pipe load_detect_temp
;
12548 struct drm_modeset_acquire_ctx ctx
;
12550 /* We can't just switch on the pipe A, we need to set things up with a
12551 * proper mode and output configuration. As a gross hack, enable pipe A
12552 * by enabling the load detect pipe once. */
12553 list_for_each_entry(connector
,
12554 &dev
->mode_config
.connector_list
,
12556 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
12557 crt
= &connector
->base
;
12565 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, &ctx
))
12566 intel_release_load_detect_pipe(crt
, &load_detect_temp
, &ctx
);
12572 intel_check_plane_mapping(struct intel_crtc
*crtc
)
12574 struct drm_device
*dev
= crtc
->base
.dev
;
12575 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12578 if (INTEL_INFO(dev
)->num_pipes
== 1)
12581 reg
= DSPCNTR(!crtc
->plane
);
12582 val
= I915_READ(reg
);
12584 if ((val
& DISPLAY_PLANE_ENABLE
) &&
12585 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
12591 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
12593 struct drm_device
*dev
= crtc
->base
.dev
;
12594 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12597 /* Clear any frame start delays used for debugging left by the BIOS */
12598 reg
= PIPECONF(crtc
->config
.cpu_transcoder
);
12599 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
12601 /* restore vblank interrupts to correct state */
12603 drm_vblank_on(dev
, crtc
->pipe
);
12605 drm_vblank_off(dev
, crtc
->pipe
);
12607 /* We need to sanitize the plane -> pipe mapping first because this will
12608 * disable the crtc (and hence change the state) if it is wrong. Note
12609 * that gen4+ has a fixed plane -> pipe mapping. */
12610 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
12611 struct intel_connector
*connector
;
12614 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
12615 crtc
->base
.base
.id
);
12617 /* Pipe has the wrong plane attached and the plane is active.
12618 * Temporarily change the plane mapping and disable everything
12620 plane
= crtc
->plane
;
12621 crtc
->plane
= !plane
;
12622 dev_priv
->display
.crtc_disable(&crtc
->base
);
12623 crtc
->plane
= plane
;
12625 /* ... and break all links. */
12626 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12628 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
12631 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12632 connector
->base
.encoder
= NULL
;
12634 /* multiple connectors may have the same encoder:
12635 * handle them and break crtc link separately */
12636 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12638 if (connector
->encoder
->base
.crtc
== &crtc
->base
) {
12639 connector
->encoder
->base
.crtc
= NULL
;
12640 connector
->encoder
->connectors_active
= false;
12643 WARN_ON(crtc
->active
);
12644 crtc
->base
.enabled
= false;
12647 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
12648 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
12649 /* BIOS forgot to enable pipe A, this mostly happens after
12650 * resume. Force-enable the pipe to fix this, the update_dpms
12651 * call below we restore the pipe to the right state, but leave
12652 * the required bits on. */
12653 intel_enable_pipe_a(dev
);
12656 /* Adjust the state of the output pipe according to whether we
12657 * have active connectors/encoders. */
12658 intel_crtc_update_dpms(&crtc
->base
);
12660 if (crtc
->active
!= crtc
->base
.enabled
) {
12661 struct intel_encoder
*encoder
;
12663 /* This can happen either due to bugs in the get_hw_state
12664 * functions or because the pipe is force-enabled due to the
12666 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
12667 crtc
->base
.base
.id
,
12668 crtc
->base
.enabled
? "enabled" : "disabled",
12669 crtc
->active
? "enabled" : "disabled");
12671 crtc
->base
.enabled
= crtc
->active
;
12673 /* Because we only establish the connector -> encoder ->
12674 * crtc links if something is active, this means the
12675 * crtc is now deactivated. Break the links. connector
12676 * -> encoder links are only establish when things are
12677 * actually up, hence no need to break them. */
12678 WARN_ON(crtc
->active
);
12680 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
12681 WARN_ON(encoder
->connectors_active
);
12682 encoder
->base
.crtc
= NULL
;
12686 if (crtc
->active
|| IS_VALLEYVIEW(dev
) || INTEL_INFO(dev
)->gen
< 5) {
12688 * We start out with underrun reporting disabled to avoid races.
12689 * For correct bookkeeping mark this on active crtcs.
12691 * Also on gmch platforms we dont have any hardware bits to
12692 * disable the underrun reporting. Which means we need to start
12693 * out with underrun reporting disabled also on inactive pipes,
12694 * since otherwise we'll complain about the garbage we read when
12695 * e.g. coming up after runtime pm.
12697 * No protection against concurrent access is required - at
12698 * worst a fifo underrun happens which also sets this to false.
12700 crtc
->cpu_fifo_underrun_disabled
= true;
12701 crtc
->pch_fifo_underrun_disabled
= true;
12703 update_scanline_offset(crtc
);
12707 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
12709 struct intel_connector
*connector
;
12710 struct drm_device
*dev
= encoder
->base
.dev
;
12712 /* We need to check both for a crtc link (meaning that the
12713 * encoder is active and trying to read from a pipe) and the
12714 * pipe itself being active. */
12715 bool has_active_crtc
= encoder
->base
.crtc
&&
12716 to_intel_crtc(encoder
->base
.crtc
)->active
;
12718 if (encoder
->connectors_active
&& !has_active_crtc
) {
12719 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
12720 encoder
->base
.base
.id
,
12721 encoder
->base
.name
);
12723 /* Connector is active, but has no active pipe. This is
12724 * fallout from our resume register restoring. Disable
12725 * the encoder manually again. */
12726 if (encoder
->base
.crtc
) {
12727 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
12728 encoder
->base
.base
.id
,
12729 encoder
->base
.name
);
12730 encoder
->disable(encoder
);
12732 encoder
->base
.crtc
= NULL
;
12733 encoder
->connectors_active
= false;
12735 /* Inconsistent output/port/pipe state happens presumably due to
12736 * a bug in one of the get_hw_state functions. Or someplace else
12737 * in our code, like the register restore mess on resume. Clamp
12738 * things to off as a safer default. */
12739 list_for_each_entry(connector
,
12740 &dev
->mode_config
.connector_list
,
12742 if (connector
->encoder
!= encoder
)
12744 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12745 connector
->base
.encoder
= NULL
;
12748 /* Enabled encoders without active connectors will be fixed in
12749 * the crtc fixup. */
12752 void i915_redisable_vga_power_on(struct drm_device
*dev
)
12754 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12755 u32 vga_reg
= i915_vgacntrl_reg(dev
);
12757 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
12758 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
12759 i915_disable_vga(dev
);
12763 void i915_redisable_vga(struct drm_device
*dev
)
12765 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12767 /* This function can be called both from intel_modeset_setup_hw_state or
12768 * at a very early point in our resume sequence, where the power well
12769 * structures are not yet restored. Since this function is at a very
12770 * paranoid "someone might have enabled VGA while we were not looking"
12771 * level, just check if the power well is enabled instead of trying to
12772 * follow the "don't touch the power well if we don't need it" policy
12773 * the rest of the driver uses. */
12774 if (!intel_display_power_enabled(dev_priv
, POWER_DOMAIN_VGA
))
12777 i915_redisable_vga_power_on(dev
);
12780 static bool primary_get_hw_state(struct intel_crtc
*crtc
)
12782 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
12787 return I915_READ(DSPCNTR(crtc
->plane
)) & DISPLAY_PLANE_ENABLE
;
12790 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
12792 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12794 struct intel_crtc
*crtc
;
12795 struct intel_encoder
*encoder
;
12796 struct intel_connector
*connector
;
12799 for_each_intel_crtc(dev
, crtc
) {
12800 memset(&crtc
->config
, 0, sizeof(crtc
->config
));
12802 crtc
->config
.quirks
|= PIPE_CONFIG_QUIRK_INHERITED_MODE
;
12804 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
12807 crtc
->base
.enabled
= crtc
->active
;
12808 crtc
->primary_enabled
= primary_get_hw_state(crtc
);
12810 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
12811 crtc
->base
.base
.id
,
12812 crtc
->active
? "enabled" : "disabled");
12815 /* FIXME: Smash this into the new shared dpll infrastructure. */
12817 intel_ddi_setup_hw_pll_state(dev
);
12819 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
12820 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
12822 pll
->on
= pll
->get_hw_state(dev_priv
, pll
, &pll
->hw_state
);
12824 for_each_intel_crtc(dev
, crtc
) {
12825 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
12828 pll
->refcount
= pll
->active
;
12830 DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
12831 pll
->name
, pll
->refcount
, pll
->on
);
12834 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
12838 if (encoder
->get_hw_state(encoder
, &pipe
)) {
12839 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
12840 encoder
->base
.crtc
= &crtc
->base
;
12841 encoder
->get_config(encoder
, &crtc
->config
);
12843 encoder
->base
.crtc
= NULL
;
12846 encoder
->connectors_active
= false;
12847 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
12848 encoder
->base
.base
.id
,
12849 encoder
->base
.name
,
12850 encoder
->base
.crtc
? "enabled" : "disabled",
12854 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12856 if (connector
->get_hw_state(connector
)) {
12857 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
12858 connector
->encoder
->connectors_active
= true;
12859 connector
->base
.encoder
= &connector
->encoder
->base
;
12861 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12862 connector
->base
.encoder
= NULL
;
12864 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
12865 connector
->base
.base
.id
,
12866 connector
->base
.name
,
12867 connector
->base
.encoder
? "enabled" : "disabled");
12871 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
12872 * and i915 state tracking structures. */
12873 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
12874 bool force_restore
)
12876 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12878 struct intel_crtc
*crtc
;
12879 struct intel_encoder
*encoder
;
12882 intel_modeset_readout_hw_state(dev
);
12885 * Now that we have the config, copy it to each CRTC struct
12886 * Note that this could go away if we move to using crtc_config
12887 * checking everywhere.
12889 for_each_intel_crtc(dev
, crtc
) {
12890 if (crtc
->active
&& i915
.fastboot
) {
12891 intel_mode_from_pipe_config(&crtc
->base
.mode
, &crtc
->config
);
12892 DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
12893 crtc
->base
.base
.id
);
12894 drm_mode_debug_printmodeline(&crtc
->base
.mode
);
12898 /* HW state is read out, now we need to sanitize this mess. */
12899 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
12901 intel_sanitize_encoder(encoder
);
12904 for_each_pipe(pipe
) {
12905 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
12906 intel_sanitize_crtc(crtc
);
12907 intel_dump_pipe_config(crtc
, &crtc
->config
, "[setup_hw_state]");
12910 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
12911 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
12913 if (!pll
->on
|| pll
->active
)
12916 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
12918 pll
->disable(dev_priv
, pll
);
12922 if (HAS_PCH_SPLIT(dev
))
12923 ilk_wm_get_hw_state(dev
);
12925 if (force_restore
) {
12926 i915_redisable_vga(dev
);
12929 * We need to use raw interfaces for restoring state to avoid
12930 * checking (bogus) intermediate states.
12932 for_each_pipe(pipe
) {
12933 struct drm_crtc
*crtc
=
12934 dev_priv
->pipe_to_crtc_mapping
[pipe
];
12936 __intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
,
12937 crtc
->primary
->fb
);
12940 intel_modeset_update_staged_output_state(dev
);
12943 intel_modeset_check_state(dev
);
12946 void intel_modeset_gem_init(struct drm_device
*dev
)
12948 struct drm_crtc
*c
;
12949 struct intel_framebuffer
*fb
;
12951 mutex_lock(&dev
->struct_mutex
);
12952 intel_init_gt_powersave(dev
);
12953 mutex_unlock(&dev
->struct_mutex
);
12955 intel_modeset_init_hw(dev
);
12957 intel_setup_overlay(dev
);
12960 * Make sure any fbs we allocated at startup are properly
12961 * pinned & fenced. When we do the allocation it's too early
12964 mutex_lock(&dev
->struct_mutex
);
12965 for_each_crtc(dev
, c
) {
12966 if (!c
->primary
->fb
)
12969 fb
= to_intel_framebuffer(c
->primary
->fb
);
12970 if (intel_pin_and_fence_fb_obj(dev
, fb
->obj
, NULL
)) {
12971 DRM_ERROR("failed to pin boot fb on pipe %d\n",
12972 to_intel_crtc(c
)->pipe
);
12973 drm_framebuffer_unreference(c
->primary
->fb
);
12974 c
->primary
->fb
= NULL
;
12977 mutex_unlock(&dev
->struct_mutex
);
12980 void intel_connector_unregister(struct intel_connector
*intel_connector
)
12982 struct drm_connector
*connector
= &intel_connector
->base
;
12984 intel_panel_destroy_backlight(connector
);
12985 drm_connector_unregister(connector
);
12988 void intel_modeset_cleanup(struct drm_device
*dev
)
12990 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12991 struct drm_connector
*connector
;
12994 * Interrupts and polling as the first thing to avoid creating havoc.
12995 * Too much stuff here (turning of rps, connectors, ...) would
12996 * experience fancy races otherwise.
12998 drm_irq_uninstall(dev
);
12999 cancel_work_sync(&dev_priv
->hotplug_work
);
13001 * Due to the hpd irq storm handling the hotplug work can re-arm the
13002 * poll handlers. Hence disable polling after hpd handling is shut down.
13004 drm_kms_helper_poll_fini(dev
);
13006 mutex_lock(&dev
->struct_mutex
);
13008 intel_unregister_dsm_handler();
13010 intel_disable_fbc(dev
);
13012 intel_disable_gt_powersave(dev
);
13014 ironlake_teardown_rc6(dev
);
13016 mutex_unlock(&dev
->struct_mutex
);
13018 /* flush any delayed tasks or pending work */
13019 flush_scheduled_work();
13021 /* destroy the backlight and sysfs files before encoders/connectors */
13022 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
13023 struct intel_connector
*intel_connector
;
13025 intel_connector
= to_intel_connector(connector
);
13026 intel_connector
->unregister(intel_connector
);
13029 drm_mode_config_cleanup(dev
);
13031 intel_cleanup_overlay(dev
);
13033 mutex_lock(&dev
->struct_mutex
);
13034 intel_cleanup_gt_powersave(dev
);
13035 mutex_unlock(&dev
->struct_mutex
);
13039 * Return which encoder is currently attached for connector.
13041 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
13043 return &intel_attached_encoder(connector
)->base
;
13046 void intel_connector_attach_encoder(struct intel_connector
*connector
,
13047 struct intel_encoder
*encoder
)
13049 connector
->encoder
= encoder
;
13050 drm_mode_connector_attach_encoder(&connector
->base
,
13055 * set vga decode state - true == enable VGA decode
13057 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
13059 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13060 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
13063 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
13064 DRM_ERROR("failed to read control word\n");
13068 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
13072 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
13074 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
13076 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
13077 DRM_ERROR("failed to write control word\n");
13084 struct intel_display_error_state
{
13086 u32 power_well_driver
;
13088 int num_transcoders
;
13090 struct intel_cursor_error_state
{
13095 } cursor
[I915_MAX_PIPES
];
13097 struct intel_pipe_error_state
{
13098 bool power_domain_on
;
13101 } pipe
[I915_MAX_PIPES
];
13103 struct intel_plane_error_state
{
13111 } plane
[I915_MAX_PIPES
];
13113 struct intel_transcoder_error_state
{
13114 bool power_domain_on
;
13115 enum transcoder cpu_transcoder
;
13128 struct intel_display_error_state
*
13129 intel_display_capture_error_state(struct drm_device
*dev
)
13131 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13132 struct intel_display_error_state
*error
;
13133 int transcoders
[] = {
13141 if (INTEL_INFO(dev
)->num_pipes
== 0)
13144 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
13148 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
13149 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
13152 error
->pipe
[i
].power_domain_on
=
13153 intel_display_power_enabled_unlocked(dev_priv
,
13154 POWER_DOMAIN_PIPE(i
));
13155 if (!error
->pipe
[i
].power_domain_on
)
13158 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
13159 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
13160 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
13162 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
13163 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
13164 if (INTEL_INFO(dev
)->gen
<= 3) {
13165 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
13166 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
13168 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
13169 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
13170 if (INTEL_INFO(dev
)->gen
>= 4) {
13171 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
13172 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
13175 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
13177 if (!HAS_PCH_SPLIT(dev
))
13178 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
13181 error
->num_transcoders
= INTEL_INFO(dev
)->num_pipes
;
13182 if (HAS_DDI(dev_priv
->dev
))
13183 error
->num_transcoders
++; /* Account for eDP. */
13185 for (i
= 0; i
< error
->num_transcoders
; i
++) {
13186 enum transcoder cpu_transcoder
= transcoders
[i
];
13188 error
->transcoder
[i
].power_domain_on
=
13189 intel_display_power_enabled_unlocked(dev_priv
,
13190 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
13191 if (!error
->transcoder
[i
].power_domain_on
)
13194 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
13196 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
13197 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
13198 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
13199 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
13200 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
13201 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
13202 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
13208 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
13211 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
13212 struct drm_device
*dev
,
13213 struct intel_display_error_state
*error
)
13220 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
13221 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
13222 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
13223 error
->power_well_driver
);
13225 err_printf(m
, "Pipe [%d]:\n", i
);
13226 err_printf(m
, " Power: %s\n",
13227 error
->pipe
[i
].power_domain_on
? "on" : "off");
13228 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
13229 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
13231 err_printf(m
, "Plane [%d]:\n", i
);
13232 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
13233 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
13234 if (INTEL_INFO(dev
)->gen
<= 3) {
13235 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
13236 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
13238 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
13239 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
13240 if (INTEL_INFO(dev
)->gen
>= 4) {
13241 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
13242 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
13245 err_printf(m
, "Cursor [%d]:\n", i
);
13246 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
13247 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
13248 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
13251 for (i
= 0; i
< error
->num_transcoders
; i
++) {
13252 err_printf(m
, "CPU transcoder: %c\n",
13253 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
13254 err_printf(m
, " Power: %s\n",
13255 error
->transcoder
[i
].power_domain_on
? "on" : "off");
13256 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
13257 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
13258 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
13259 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
13260 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
13261 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
13262 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);