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 intel_crtc
*intel_crtc
=
2138 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
2142 /* If the pipe isn't enabled, we can't pump pixels and may hang */
2143 assert_pipe_enabled(dev_priv
, pipe
);
2145 if (intel_crtc
->primary_enabled
)
2148 intel_crtc
->primary_enabled
= true;
2150 reg
= DSPCNTR(plane
);
2151 val
= I915_READ(reg
);
2152 WARN_ON(val
& DISPLAY_PLANE_ENABLE
);
2154 I915_WRITE(reg
, val
| DISPLAY_PLANE_ENABLE
);
2155 intel_flush_primary_plane(dev_priv
, plane
);
2159 * intel_disable_primary_hw_plane - disable the primary hardware plane
2160 * @dev_priv: i915 private structure
2161 * @plane: plane to disable
2162 * @pipe: pipe consuming the data
2164 * Disable @plane; should be an independent operation.
2166 static void intel_disable_primary_hw_plane(struct drm_i915_private
*dev_priv
,
2167 enum plane plane
, enum pipe pipe
)
2169 struct intel_crtc
*intel_crtc
=
2170 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
2174 if (!intel_crtc
->primary_enabled
)
2177 intel_crtc
->primary_enabled
= false;
2179 reg
= DSPCNTR(plane
);
2180 val
= I915_READ(reg
);
2181 WARN_ON((val
& DISPLAY_PLANE_ENABLE
) == 0);
2183 I915_WRITE(reg
, val
& ~DISPLAY_PLANE_ENABLE
);
2184 intel_flush_primary_plane(dev_priv
, plane
);
2187 static bool need_vtd_wa(struct drm_device
*dev
)
2189 #ifdef CONFIG_INTEL_IOMMU
2190 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2196 static int intel_align_height(struct drm_device
*dev
, int height
, bool tiled
)
2200 tile_height
= tiled
? (IS_GEN2(dev
) ? 16 : 8) : 1;
2201 return ALIGN(height
, tile_height
);
2205 intel_pin_and_fence_fb_obj(struct drm_device
*dev
,
2206 struct drm_i915_gem_object
*obj
,
2207 struct intel_engine_cs
*pipelined
)
2209 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2213 switch (obj
->tiling_mode
) {
2214 case I915_TILING_NONE
:
2215 if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
2216 alignment
= 128 * 1024;
2217 else if (INTEL_INFO(dev
)->gen
>= 4)
2218 alignment
= 4 * 1024;
2220 alignment
= 64 * 1024;
2223 /* pin() will align the object as required by fence */
2227 WARN(1, "Y tiled bo slipped through, driver bug!\n");
2233 /* Note that the w/a also requires 64 PTE of padding following the
2234 * bo. We currently fill all unused PTE with the shadow page and so
2235 * we should always have valid PTE following the scanout preventing
2238 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2239 alignment
= 256 * 1024;
2241 dev_priv
->mm
.interruptible
= false;
2242 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
);
2244 goto err_interruptible
;
2246 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2247 * fence, whereas 965+ only requires a fence if using
2248 * framebuffer compression. For simplicity, we always install
2249 * a fence as the cost is not that onerous.
2251 ret
= i915_gem_object_get_fence(obj
);
2255 i915_gem_object_pin_fence(obj
);
2257 dev_priv
->mm
.interruptible
= true;
2261 i915_gem_object_unpin_from_display_plane(obj
);
2263 dev_priv
->mm
.interruptible
= true;
2267 void intel_unpin_fb_obj(struct drm_i915_gem_object
*obj
)
2269 i915_gem_object_unpin_fence(obj
);
2270 i915_gem_object_unpin_from_display_plane(obj
);
2273 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2274 * is assumed to be a power-of-two. */
2275 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
2276 unsigned int tiling_mode
,
2280 if (tiling_mode
!= I915_TILING_NONE
) {
2281 unsigned int tile_rows
, tiles
;
2286 tiles
= *x
/ (512/cpp
);
2289 return tile_rows
* pitch
* 8 + tiles
* 4096;
2291 unsigned int offset
;
2293 offset
= *y
* pitch
+ *x
* cpp
;
2295 *x
= (offset
& 4095) / cpp
;
2296 return offset
& -4096;
2300 int intel_format_to_fourcc(int format
)
2303 case DISPPLANE_8BPP
:
2304 return DRM_FORMAT_C8
;
2305 case DISPPLANE_BGRX555
:
2306 return DRM_FORMAT_XRGB1555
;
2307 case DISPPLANE_BGRX565
:
2308 return DRM_FORMAT_RGB565
;
2310 case DISPPLANE_BGRX888
:
2311 return DRM_FORMAT_XRGB8888
;
2312 case DISPPLANE_RGBX888
:
2313 return DRM_FORMAT_XBGR8888
;
2314 case DISPPLANE_BGRX101010
:
2315 return DRM_FORMAT_XRGB2101010
;
2316 case DISPPLANE_RGBX101010
:
2317 return DRM_FORMAT_XBGR2101010
;
2321 static bool intel_alloc_plane_obj(struct intel_crtc
*crtc
,
2322 struct intel_plane_config
*plane_config
)
2324 struct drm_device
*dev
= crtc
->base
.dev
;
2325 struct drm_i915_gem_object
*obj
= NULL
;
2326 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2327 u32 base
= plane_config
->base
;
2329 if (plane_config
->size
== 0)
2332 obj
= i915_gem_object_create_stolen_for_preallocated(dev
, base
, base
,
2333 plane_config
->size
);
2337 if (plane_config
->tiled
) {
2338 obj
->tiling_mode
= I915_TILING_X
;
2339 obj
->stride
= crtc
->base
.primary
->fb
->pitches
[0];
2342 mode_cmd
.pixel_format
= crtc
->base
.primary
->fb
->pixel_format
;
2343 mode_cmd
.width
= crtc
->base
.primary
->fb
->width
;
2344 mode_cmd
.height
= crtc
->base
.primary
->fb
->height
;
2345 mode_cmd
.pitches
[0] = crtc
->base
.primary
->fb
->pitches
[0];
2347 mutex_lock(&dev
->struct_mutex
);
2349 if (intel_framebuffer_init(dev
, to_intel_framebuffer(crtc
->base
.primary
->fb
),
2351 DRM_DEBUG_KMS("intel fb init failed\n");
2355 obj
->frontbuffer_bits
= INTEL_FRONTBUFFER_PRIMARY(crtc
->pipe
);
2356 mutex_unlock(&dev
->struct_mutex
);
2358 DRM_DEBUG_KMS("plane fb obj %p\n", obj
);
2362 drm_gem_object_unreference(&obj
->base
);
2363 mutex_unlock(&dev
->struct_mutex
);
2367 static void intel_find_plane_obj(struct intel_crtc
*intel_crtc
,
2368 struct intel_plane_config
*plane_config
)
2370 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2372 struct intel_crtc
*i
;
2373 struct intel_framebuffer
*fb
;
2375 if (!intel_crtc
->base
.primary
->fb
)
2378 if (intel_alloc_plane_obj(intel_crtc
, plane_config
))
2381 kfree(intel_crtc
->base
.primary
->fb
);
2382 intel_crtc
->base
.primary
->fb
= NULL
;
2385 * Failed to alloc the obj, check to see if we should share
2386 * an fb with another CRTC instead
2388 for_each_crtc(dev
, c
) {
2389 i
= to_intel_crtc(c
);
2391 if (c
== &intel_crtc
->base
)
2394 if (!i
->active
|| !c
->primary
->fb
)
2397 fb
= to_intel_framebuffer(c
->primary
->fb
);
2398 if (i915_gem_obj_ggtt_offset(fb
->obj
) == plane_config
->base
) {
2399 drm_framebuffer_reference(c
->primary
->fb
);
2400 intel_crtc
->base
.primary
->fb
= c
->primary
->fb
;
2401 fb
->obj
->frontbuffer_bits
|= INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
2407 static void i9xx_update_primary_plane(struct drm_crtc
*crtc
,
2408 struct drm_framebuffer
*fb
,
2411 struct drm_device
*dev
= crtc
->dev
;
2412 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2413 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2414 struct intel_framebuffer
*intel_fb
;
2415 struct drm_i915_gem_object
*obj
;
2416 int plane
= intel_crtc
->plane
;
2417 unsigned long linear_offset
;
2421 intel_fb
= to_intel_framebuffer(fb
);
2422 obj
= intel_fb
->obj
;
2424 reg
= DSPCNTR(plane
);
2425 dspcntr
= I915_READ(reg
);
2426 /* Mask out pixel format bits in case we change it */
2427 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
2428 switch (fb
->pixel_format
) {
2430 dspcntr
|= DISPPLANE_8BPP
;
2432 case DRM_FORMAT_XRGB1555
:
2433 case DRM_FORMAT_ARGB1555
:
2434 dspcntr
|= DISPPLANE_BGRX555
;
2436 case DRM_FORMAT_RGB565
:
2437 dspcntr
|= DISPPLANE_BGRX565
;
2439 case DRM_FORMAT_XRGB8888
:
2440 case DRM_FORMAT_ARGB8888
:
2441 dspcntr
|= DISPPLANE_BGRX888
;
2443 case DRM_FORMAT_XBGR8888
:
2444 case DRM_FORMAT_ABGR8888
:
2445 dspcntr
|= DISPPLANE_RGBX888
;
2447 case DRM_FORMAT_XRGB2101010
:
2448 case DRM_FORMAT_ARGB2101010
:
2449 dspcntr
|= DISPPLANE_BGRX101010
;
2451 case DRM_FORMAT_XBGR2101010
:
2452 case DRM_FORMAT_ABGR2101010
:
2453 dspcntr
|= DISPPLANE_RGBX101010
;
2459 if (INTEL_INFO(dev
)->gen
>= 4) {
2460 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2461 dspcntr
|= DISPPLANE_TILED
;
2463 dspcntr
&= ~DISPPLANE_TILED
;
2467 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2469 I915_WRITE(reg
, dspcntr
);
2471 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2473 if (INTEL_INFO(dev
)->gen
>= 4) {
2474 intel_crtc
->dspaddr_offset
=
2475 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2476 fb
->bits_per_pixel
/ 8,
2478 linear_offset
-= intel_crtc
->dspaddr_offset
;
2480 intel_crtc
->dspaddr_offset
= linear_offset
;
2483 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2484 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2486 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2487 if (INTEL_INFO(dev
)->gen
>= 4) {
2488 I915_WRITE(DSPSURF(plane
),
2489 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2490 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2491 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2493 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2497 static void ironlake_update_primary_plane(struct drm_crtc
*crtc
,
2498 struct drm_framebuffer
*fb
,
2501 struct drm_device
*dev
= crtc
->dev
;
2502 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2503 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2504 struct intel_framebuffer
*intel_fb
;
2505 struct drm_i915_gem_object
*obj
;
2506 int plane
= intel_crtc
->plane
;
2507 unsigned long linear_offset
;
2511 intel_fb
= to_intel_framebuffer(fb
);
2512 obj
= intel_fb
->obj
;
2514 reg
= DSPCNTR(plane
);
2515 dspcntr
= I915_READ(reg
);
2516 /* Mask out pixel format bits in case we change it */
2517 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
2518 switch (fb
->pixel_format
) {
2520 dspcntr
|= DISPPLANE_8BPP
;
2522 case DRM_FORMAT_RGB565
:
2523 dspcntr
|= DISPPLANE_BGRX565
;
2525 case DRM_FORMAT_XRGB8888
:
2526 case DRM_FORMAT_ARGB8888
:
2527 dspcntr
|= DISPPLANE_BGRX888
;
2529 case DRM_FORMAT_XBGR8888
:
2530 case DRM_FORMAT_ABGR8888
:
2531 dspcntr
|= DISPPLANE_RGBX888
;
2533 case DRM_FORMAT_XRGB2101010
:
2534 case DRM_FORMAT_ARGB2101010
:
2535 dspcntr
|= DISPPLANE_BGRX101010
;
2537 case DRM_FORMAT_XBGR2101010
:
2538 case DRM_FORMAT_ABGR2101010
:
2539 dspcntr
|= DISPPLANE_RGBX101010
;
2545 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2546 dspcntr
|= DISPPLANE_TILED
;
2548 dspcntr
&= ~DISPPLANE_TILED
;
2550 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2551 dspcntr
&= ~DISPPLANE_TRICKLE_FEED_DISABLE
;
2553 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2555 I915_WRITE(reg
, dspcntr
);
2557 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2558 intel_crtc
->dspaddr_offset
=
2559 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2560 fb
->bits_per_pixel
/ 8,
2562 linear_offset
-= intel_crtc
->dspaddr_offset
;
2564 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2565 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2567 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2568 I915_WRITE(DSPSURF(plane
),
2569 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2570 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2571 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2573 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2574 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2579 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2581 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
2582 int x
, int y
, enum mode_set_atomic state
)
2584 struct drm_device
*dev
= crtc
->dev
;
2585 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2587 if (dev_priv
->display
.disable_fbc
)
2588 dev_priv
->display
.disable_fbc(dev
);
2589 intel_increase_pllclock(dev
, to_intel_crtc(crtc
)->pipe
);
2591 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2596 void intel_display_handle_reset(struct drm_device
*dev
)
2598 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2599 struct drm_crtc
*crtc
;
2602 * Flips in the rings have been nuked by the reset,
2603 * so complete all pending flips so that user space
2604 * will get its events and not get stuck.
2606 * Also update the base address of all primary
2607 * planes to the the last fb to make sure we're
2608 * showing the correct fb after a reset.
2610 * Need to make two loops over the crtcs so that we
2611 * don't try to grab a crtc mutex before the
2612 * pending_flip_queue really got woken up.
2615 for_each_crtc(dev
, crtc
) {
2616 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2617 enum plane plane
= intel_crtc
->plane
;
2619 intel_prepare_page_flip(dev
, plane
);
2620 intel_finish_page_flip_plane(dev
, plane
);
2623 for_each_crtc(dev
, crtc
) {
2624 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2626 drm_modeset_lock(&crtc
->mutex
, NULL
);
2628 * FIXME: Once we have proper support for primary planes (and
2629 * disabling them without disabling the entire crtc) allow again
2630 * a NULL crtc->primary->fb.
2632 if (intel_crtc
->active
&& crtc
->primary
->fb
)
2633 dev_priv
->display
.update_primary_plane(crtc
,
2637 drm_modeset_unlock(&crtc
->mutex
);
2642 intel_finish_fb(struct drm_framebuffer
*old_fb
)
2644 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(old_fb
)->obj
;
2645 struct drm_i915_private
*dev_priv
= obj
->base
.dev
->dev_private
;
2646 bool was_interruptible
= dev_priv
->mm
.interruptible
;
2649 /* Big Hammer, we also need to ensure that any pending
2650 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2651 * current scanout is retired before unpinning the old
2654 * This should only fail upon a hung GPU, in which case we
2655 * can safely continue.
2657 dev_priv
->mm
.interruptible
= false;
2658 ret
= i915_gem_object_finish_gpu(obj
);
2659 dev_priv
->mm
.interruptible
= was_interruptible
;
2664 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
2666 struct drm_device
*dev
= crtc
->dev
;
2667 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2668 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2669 unsigned long flags
;
2672 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
2673 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
2676 spin_lock_irqsave(&dev
->event_lock
, flags
);
2677 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
2678 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2684 intel_pipe_set_base(struct drm_crtc
*crtc
, int x
, int y
,
2685 struct drm_framebuffer
*fb
)
2687 struct drm_device
*dev
= crtc
->dev
;
2688 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2689 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2690 enum pipe pipe
= intel_crtc
->pipe
;
2691 struct drm_framebuffer
*old_fb
;
2692 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(fb
)->obj
;
2695 if (intel_crtc_has_pending_flip(crtc
)) {
2696 DRM_ERROR("pipe is still busy with an old pageflip\n");
2702 DRM_ERROR("No FB bound\n");
2706 if (intel_crtc
->plane
> INTEL_INFO(dev
)->num_pipes
) {
2707 DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
2708 plane_name(intel_crtc
->plane
),
2709 INTEL_INFO(dev
)->num_pipes
);
2713 old_fb
= crtc
->primary
->fb
;
2715 mutex_lock(&dev
->struct_mutex
);
2716 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
2718 i915_gem_track_fb(to_intel_framebuffer(old_fb
)->obj
, obj
,
2719 INTEL_FRONTBUFFER_PRIMARY(pipe
));
2720 mutex_unlock(&dev
->struct_mutex
);
2722 DRM_ERROR("pin & fence failed\n");
2727 * Update pipe size and adjust fitter if needed: the reason for this is
2728 * that in compute_mode_changes we check the native mode (not the pfit
2729 * mode) to see if we can flip rather than do a full mode set. In the
2730 * fastboot case, we'll flip, but if we don't update the pipesrc and
2731 * pfit state, we'll end up with a big fb scanned out into the wrong
2734 * To fix this properly, we need to hoist the checks up into
2735 * compute_mode_changes (or above), check the actual pfit state and
2736 * whether the platform allows pfit disable with pipe active, and only
2737 * then update the pipesrc and pfit state, even on the flip path.
2739 if (i915
.fastboot
) {
2740 const struct drm_display_mode
*adjusted_mode
=
2741 &intel_crtc
->config
.adjusted_mode
;
2743 I915_WRITE(PIPESRC(intel_crtc
->pipe
),
2744 ((adjusted_mode
->crtc_hdisplay
- 1) << 16) |
2745 (adjusted_mode
->crtc_vdisplay
- 1));
2746 if (!intel_crtc
->config
.pch_pfit
.enabled
&&
2747 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
2748 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
2749 I915_WRITE(PF_CTL(intel_crtc
->pipe
), 0);
2750 I915_WRITE(PF_WIN_POS(intel_crtc
->pipe
), 0);
2751 I915_WRITE(PF_WIN_SZ(intel_crtc
->pipe
), 0);
2753 intel_crtc
->config
.pipe_src_w
= adjusted_mode
->crtc_hdisplay
;
2754 intel_crtc
->config
.pipe_src_h
= adjusted_mode
->crtc_vdisplay
;
2757 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2759 crtc
->primary
->fb
= fb
;
2764 if (intel_crtc
->active
&& old_fb
!= fb
)
2765 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2766 mutex_lock(&dev
->struct_mutex
);
2767 intel_unpin_fb_obj(to_intel_framebuffer(old_fb
)->obj
);
2768 mutex_unlock(&dev
->struct_mutex
);
2771 mutex_lock(&dev
->struct_mutex
);
2772 intel_update_fbc(dev
);
2773 mutex_unlock(&dev
->struct_mutex
);
2778 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
2780 struct drm_device
*dev
= crtc
->dev
;
2781 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2782 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2783 int pipe
= intel_crtc
->pipe
;
2786 /* enable normal train */
2787 reg
= FDI_TX_CTL(pipe
);
2788 temp
= I915_READ(reg
);
2789 if (IS_IVYBRIDGE(dev
)) {
2790 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2791 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2793 temp
&= ~FDI_LINK_TRAIN_NONE
;
2794 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2796 I915_WRITE(reg
, temp
);
2798 reg
= FDI_RX_CTL(pipe
);
2799 temp
= I915_READ(reg
);
2800 if (HAS_PCH_CPT(dev
)) {
2801 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2802 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
2804 temp
&= ~FDI_LINK_TRAIN_NONE
;
2805 temp
|= FDI_LINK_TRAIN_NONE
;
2807 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
2809 /* wait one idle pattern time */
2813 /* IVB wants error correction enabled */
2814 if (IS_IVYBRIDGE(dev
))
2815 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
2816 FDI_FE_ERRC_ENABLE
);
2819 static bool pipe_has_enabled_pch(struct intel_crtc
*crtc
)
2821 return crtc
->base
.enabled
&& crtc
->active
&&
2822 crtc
->config
.has_pch_encoder
;
2825 static void ivb_modeset_global_resources(struct drm_device
*dev
)
2827 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2828 struct intel_crtc
*pipe_B_crtc
=
2829 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
2830 struct intel_crtc
*pipe_C_crtc
=
2831 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]);
2835 * When everything is off disable fdi C so that we could enable fdi B
2836 * with all lanes. Note that we don't care about enabled pipes without
2837 * an enabled pch encoder.
2839 if (!pipe_has_enabled_pch(pipe_B_crtc
) &&
2840 !pipe_has_enabled_pch(pipe_C_crtc
)) {
2841 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
2842 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
2844 temp
= I915_READ(SOUTH_CHICKEN1
);
2845 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
2846 DRM_DEBUG_KMS("disabling fdi C rx\n");
2847 I915_WRITE(SOUTH_CHICKEN1
, temp
);
2851 /* The FDI link training functions for ILK/Ibexpeak. */
2852 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
2854 struct drm_device
*dev
= crtc
->dev
;
2855 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2856 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2857 int pipe
= intel_crtc
->pipe
;
2858 u32 reg
, temp
, tries
;
2860 /* FDI needs bits from pipe first */
2861 assert_pipe_enabled(dev_priv
, pipe
);
2863 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2865 reg
= FDI_RX_IMR(pipe
);
2866 temp
= I915_READ(reg
);
2867 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2868 temp
&= ~FDI_RX_BIT_LOCK
;
2869 I915_WRITE(reg
, temp
);
2873 /* enable CPU FDI TX and PCH FDI RX */
2874 reg
= FDI_TX_CTL(pipe
);
2875 temp
= I915_READ(reg
);
2876 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2877 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2878 temp
&= ~FDI_LINK_TRAIN_NONE
;
2879 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2880 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2882 reg
= FDI_RX_CTL(pipe
);
2883 temp
= I915_READ(reg
);
2884 temp
&= ~FDI_LINK_TRAIN_NONE
;
2885 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2886 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2891 /* Ironlake workaround, enable clock pointer after FDI enable*/
2892 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
2893 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
2894 FDI_RX_PHASE_SYNC_POINTER_EN
);
2896 reg
= FDI_RX_IIR(pipe
);
2897 for (tries
= 0; tries
< 5; tries
++) {
2898 temp
= I915_READ(reg
);
2899 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2901 if ((temp
& FDI_RX_BIT_LOCK
)) {
2902 DRM_DEBUG_KMS("FDI train 1 done.\n");
2903 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2908 DRM_ERROR("FDI train 1 fail!\n");
2911 reg
= FDI_TX_CTL(pipe
);
2912 temp
= I915_READ(reg
);
2913 temp
&= ~FDI_LINK_TRAIN_NONE
;
2914 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2915 I915_WRITE(reg
, temp
);
2917 reg
= FDI_RX_CTL(pipe
);
2918 temp
= I915_READ(reg
);
2919 temp
&= ~FDI_LINK_TRAIN_NONE
;
2920 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2921 I915_WRITE(reg
, temp
);
2926 reg
= FDI_RX_IIR(pipe
);
2927 for (tries
= 0; tries
< 5; tries
++) {
2928 temp
= I915_READ(reg
);
2929 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2931 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2932 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2933 DRM_DEBUG_KMS("FDI train 2 done.\n");
2938 DRM_ERROR("FDI train 2 fail!\n");
2940 DRM_DEBUG_KMS("FDI train done\n");
2944 static const int snb_b_fdi_train_param
[] = {
2945 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
2946 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
2947 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
2948 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
2951 /* The FDI link training functions for SNB/Cougarpoint. */
2952 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
2954 struct drm_device
*dev
= crtc
->dev
;
2955 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2956 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2957 int pipe
= intel_crtc
->pipe
;
2958 u32 reg
, temp
, i
, retry
;
2960 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2962 reg
= FDI_RX_IMR(pipe
);
2963 temp
= I915_READ(reg
);
2964 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2965 temp
&= ~FDI_RX_BIT_LOCK
;
2966 I915_WRITE(reg
, temp
);
2971 /* enable CPU FDI TX and PCH FDI RX */
2972 reg
= FDI_TX_CTL(pipe
);
2973 temp
= I915_READ(reg
);
2974 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2975 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2976 temp
&= ~FDI_LINK_TRAIN_NONE
;
2977 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2978 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2980 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2981 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2983 I915_WRITE(FDI_RX_MISC(pipe
),
2984 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
2986 reg
= FDI_RX_CTL(pipe
);
2987 temp
= I915_READ(reg
);
2988 if (HAS_PCH_CPT(dev
)) {
2989 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2990 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2992 temp
&= ~FDI_LINK_TRAIN_NONE
;
2993 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2995 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3000 for (i
= 0; i
< 4; i
++) {
3001 reg
= FDI_TX_CTL(pipe
);
3002 temp
= I915_READ(reg
);
3003 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3004 temp
|= snb_b_fdi_train_param
[i
];
3005 I915_WRITE(reg
, temp
);
3010 for (retry
= 0; retry
< 5; retry
++) {
3011 reg
= FDI_RX_IIR(pipe
);
3012 temp
= I915_READ(reg
);
3013 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3014 if (temp
& FDI_RX_BIT_LOCK
) {
3015 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3016 DRM_DEBUG_KMS("FDI train 1 done.\n");
3025 DRM_ERROR("FDI train 1 fail!\n");
3028 reg
= FDI_TX_CTL(pipe
);
3029 temp
= I915_READ(reg
);
3030 temp
&= ~FDI_LINK_TRAIN_NONE
;
3031 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3033 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3035 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3037 I915_WRITE(reg
, temp
);
3039 reg
= FDI_RX_CTL(pipe
);
3040 temp
= I915_READ(reg
);
3041 if (HAS_PCH_CPT(dev
)) {
3042 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3043 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3045 temp
&= ~FDI_LINK_TRAIN_NONE
;
3046 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3048 I915_WRITE(reg
, temp
);
3053 for (i
= 0; i
< 4; i
++) {
3054 reg
= FDI_TX_CTL(pipe
);
3055 temp
= I915_READ(reg
);
3056 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3057 temp
|= snb_b_fdi_train_param
[i
];
3058 I915_WRITE(reg
, temp
);
3063 for (retry
= 0; retry
< 5; retry
++) {
3064 reg
= FDI_RX_IIR(pipe
);
3065 temp
= I915_READ(reg
);
3066 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3067 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3068 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3069 DRM_DEBUG_KMS("FDI train 2 done.\n");
3078 DRM_ERROR("FDI train 2 fail!\n");
3080 DRM_DEBUG_KMS("FDI train done.\n");
3083 /* Manual link training for Ivy Bridge A0 parts */
3084 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3086 struct drm_device
*dev
= crtc
->dev
;
3087 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3088 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3089 int pipe
= intel_crtc
->pipe
;
3090 u32 reg
, temp
, i
, j
;
3092 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3094 reg
= FDI_RX_IMR(pipe
);
3095 temp
= I915_READ(reg
);
3096 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3097 temp
&= ~FDI_RX_BIT_LOCK
;
3098 I915_WRITE(reg
, temp
);
3103 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3104 I915_READ(FDI_RX_IIR(pipe
)));
3106 /* Try each vswing and preemphasis setting twice before moving on */
3107 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3108 /* disable first in case we need to retry */
3109 reg
= FDI_TX_CTL(pipe
);
3110 temp
= I915_READ(reg
);
3111 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3112 temp
&= ~FDI_TX_ENABLE
;
3113 I915_WRITE(reg
, temp
);
3115 reg
= FDI_RX_CTL(pipe
);
3116 temp
= I915_READ(reg
);
3117 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3118 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3119 temp
&= ~FDI_RX_ENABLE
;
3120 I915_WRITE(reg
, temp
);
3122 /* enable CPU FDI TX and PCH FDI RX */
3123 reg
= FDI_TX_CTL(pipe
);
3124 temp
= I915_READ(reg
);
3125 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3126 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3127 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3128 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3129 temp
|= snb_b_fdi_train_param
[j
/2];
3130 temp
|= FDI_COMPOSITE_SYNC
;
3131 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3133 I915_WRITE(FDI_RX_MISC(pipe
),
3134 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3136 reg
= FDI_RX_CTL(pipe
);
3137 temp
= I915_READ(reg
);
3138 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3139 temp
|= FDI_COMPOSITE_SYNC
;
3140 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3143 udelay(1); /* should be 0.5us */
3145 for (i
= 0; i
< 4; i
++) {
3146 reg
= FDI_RX_IIR(pipe
);
3147 temp
= I915_READ(reg
);
3148 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3150 if (temp
& FDI_RX_BIT_LOCK
||
3151 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3152 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3153 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3157 udelay(1); /* should be 0.5us */
3160 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3165 reg
= FDI_TX_CTL(pipe
);
3166 temp
= I915_READ(reg
);
3167 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3168 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3169 I915_WRITE(reg
, temp
);
3171 reg
= FDI_RX_CTL(pipe
);
3172 temp
= I915_READ(reg
);
3173 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3174 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3175 I915_WRITE(reg
, temp
);
3178 udelay(2); /* should be 1.5us */
3180 for (i
= 0; i
< 4; i
++) {
3181 reg
= FDI_RX_IIR(pipe
);
3182 temp
= I915_READ(reg
);
3183 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3185 if (temp
& FDI_RX_SYMBOL_LOCK
||
3186 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3187 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3188 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3192 udelay(2); /* should be 1.5us */
3195 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3199 DRM_DEBUG_KMS("FDI train done.\n");
3202 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3204 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3205 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3206 int pipe
= intel_crtc
->pipe
;
3210 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3211 reg
= FDI_RX_CTL(pipe
);
3212 temp
= I915_READ(reg
);
3213 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3214 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3215 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3216 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3221 /* Switch from Rawclk to PCDclk */
3222 temp
= I915_READ(reg
);
3223 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3228 /* Enable CPU FDI TX PLL, always on for Ironlake */
3229 reg
= FDI_TX_CTL(pipe
);
3230 temp
= I915_READ(reg
);
3231 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3232 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3239 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3241 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3242 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3243 int pipe
= intel_crtc
->pipe
;
3246 /* Switch from PCDclk to Rawclk */
3247 reg
= FDI_RX_CTL(pipe
);
3248 temp
= I915_READ(reg
);
3249 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3251 /* Disable CPU FDI TX PLL */
3252 reg
= FDI_TX_CTL(pipe
);
3253 temp
= I915_READ(reg
);
3254 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3259 reg
= FDI_RX_CTL(pipe
);
3260 temp
= I915_READ(reg
);
3261 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3263 /* Wait for the clocks to turn off. */
3268 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3270 struct drm_device
*dev
= crtc
->dev
;
3271 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3272 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3273 int pipe
= intel_crtc
->pipe
;
3276 /* disable CPU FDI tx and PCH FDI rx */
3277 reg
= FDI_TX_CTL(pipe
);
3278 temp
= I915_READ(reg
);
3279 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3282 reg
= FDI_RX_CTL(pipe
);
3283 temp
= I915_READ(reg
);
3284 temp
&= ~(0x7 << 16);
3285 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3286 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3291 /* Ironlake workaround, disable clock pointer after downing FDI */
3292 if (HAS_PCH_IBX(dev
))
3293 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3295 /* still set train pattern 1 */
3296 reg
= FDI_TX_CTL(pipe
);
3297 temp
= I915_READ(reg
);
3298 temp
&= ~FDI_LINK_TRAIN_NONE
;
3299 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3300 I915_WRITE(reg
, temp
);
3302 reg
= FDI_RX_CTL(pipe
);
3303 temp
= I915_READ(reg
);
3304 if (HAS_PCH_CPT(dev
)) {
3305 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3306 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3308 temp
&= ~FDI_LINK_TRAIN_NONE
;
3309 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3311 /* BPC in FDI rx is consistent with that in PIPECONF */
3312 temp
&= ~(0x07 << 16);
3313 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3314 I915_WRITE(reg
, temp
);
3320 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3322 struct intel_crtc
*crtc
;
3324 /* Note that we don't need to be called with mode_config.lock here
3325 * as our list of CRTC objects is static for the lifetime of the
3326 * device and so cannot disappear as we iterate. Similarly, we can
3327 * happily treat the predicates as racy, atomic checks as userspace
3328 * cannot claim and pin a new fb without at least acquring the
3329 * struct_mutex and so serialising with us.
3331 for_each_intel_crtc(dev
, crtc
) {
3332 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3335 if (crtc
->unpin_work
)
3336 intel_wait_for_vblank(dev
, crtc
->pipe
);
3344 void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3346 struct drm_device
*dev
= crtc
->dev
;
3347 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3349 if (crtc
->primary
->fb
== NULL
)
3352 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3354 WARN_ON(wait_event_timeout(dev_priv
->pending_flip_queue
,
3355 !intel_crtc_has_pending_flip(crtc
),
3358 mutex_lock(&dev
->struct_mutex
);
3359 intel_finish_fb(crtc
->primary
->fb
);
3360 mutex_unlock(&dev
->struct_mutex
);
3363 /* Program iCLKIP clock to the desired frequency */
3364 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3366 struct drm_device
*dev
= crtc
->dev
;
3367 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3368 int clock
= to_intel_crtc(crtc
)->config
.adjusted_mode
.crtc_clock
;
3369 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3372 mutex_lock(&dev_priv
->dpio_lock
);
3374 /* It is necessary to ungate the pixclk gate prior to programming
3375 * the divisors, and gate it back when it is done.
3377 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3379 /* Disable SSCCTL */
3380 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
3381 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
3385 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3386 if (clock
== 20000) {
3391 /* The iCLK virtual clock root frequency is in MHz,
3392 * but the adjusted_mode->crtc_clock in in KHz. To get the
3393 * divisors, it is necessary to divide one by another, so we
3394 * convert the virtual clock precision to KHz here for higher
3397 u32 iclk_virtual_root_freq
= 172800 * 1000;
3398 u32 iclk_pi_range
= 64;
3399 u32 desired_divisor
, msb_divisor_value
, pi_value
;
3401 desired_divisor
= (iclk_virtual_root_freq
/ clock
);
3402 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
3403 pi_value
= desired_divisor
% iclk_pi_range
;
3406 divsel
= msb_divisor_value
- 2;
3407 phaseinc
= pi_value
;
3410 /* This should not happen with any sane values */
3411 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3412 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3413 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3414 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3416 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3423 /* Program SSCDIVINTPHASE6 */
3424 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3425 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
3426 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
3427 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
3428 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
3429 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
3430 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
3431 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
3433 /* Program SSCAUXDIV */
3434 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3435 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3436 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
3437 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
3439 /* Enable modulator and associated divider */
3440 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3441 temp
&= ~SBI_SSCCTL_DISABLE
;
3442 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3444 /* Wait for initialization time */
3447 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
3449 mutex_unlock(&dev_priv
->dpio_lock
);
3452 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
3453 enum pipe pch_transcoder
)
3455 struct drm_device
*dev
= crtc
->base
.dev
;
3456 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3457 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
3459 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
3460 I915_READ(HTOTAL(cpu_transcoder
)));
3461 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
3462 I915_READ(HBLANK(cpu_transcoder
)));
3463 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
3464 I915_READ(HSYNC(cpu_transcoder
)));
3466 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
3467 I915_READ(VTOTAL(cpu_transcoder
)));
3468 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
3469 I915_READ(VBLANK(cpu_transcoder
)));
3470 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
3471 I915_READ(VSYNC(cpu_transcoder
)));
3472 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
3473 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
3476 static void cpt_enable_fdi_bc_bifurcation(struct drm_device
*dev
)
3478 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3481 temp
= I915_READ(SOUTH_CHICKEN1
);
3482 if (temp
& FDI_BC_BIFURCATION_SELECT
)
3485 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
3486 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
3488 temp
|= FDI_BC_BIFURCATION_SELECT
;
3489 DRM_DEBUG_KMS("enabling fdi C rx\n");
3490 I915_WRITE(SOUTH_CHICKEN1
, temp
);
3491 POSTING_READ(SOUTH_CHICKEN1
);
3494 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
3496 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3497 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3499 switch (intel_crtc
->pipe
) {
3503 if (intel_crtc
->config
.fdi_lanes
> 2)
3504 WARN_ON(I915_READ(SOUTH_CHICKEN1
) & FDI_BC_BIFURCATION_SELECT
);
3506 cpt_enable_fdi_bc_bifurcation(dev
);
3510 cpt_enable_fdi_bc_bifurcation(dev
);
3519 * Enable PCH resources required for PCH ports:
3521 * - FDI training & RX/TX
3522 * - update transcoder timings
3523 * - DP transcoding bits
3526 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
3528 struct drm_device
*dev
= crtc
->dev
;
3529 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3530 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3531 int pipe
= intel_crtc
->pipe
;
3534 assert_pch_transcoder_disabled(dev_priv
, pipe
);
3536 if (IS_IVYBRIDGE(dev
))
3537 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
3539 /* Write the TU size bits before fdi link training, so that error
3540 * detection works. */
3541 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
3542 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
3544 /* For PCH output, training FDI link */
3545 dev_priv
->display
.fdi_link_train(crtc
);
3547 /* We need to program the right clock selection before writing the pixel
3548 * mutliplier into the DPLL. */
3549 if (HAS_PCH_CPT(dev
)) {
3552 temp
= I915_READ(PCH_DPLL_SEL
);
3553 temp
|= TRANS_DPLL_ENABLE(pipe
);
3554 sel
= TRANS_DPLLB_SEL(pipe
);
3555 if (intel_crtc
->config
.shared_dpll
== DPLL_ID_PCH_PLL_B
)
3559 I915_WRITE(PCH_DPLL_SEL
, temp
);
3562 /* XXX: pch pll's can be enabled any time before we enable the PCH
3563 * transcoder, and we actually should do this to not upset any PCH
3564 * transcoder that already use the clock when we share it.
3566 * Note that enable_shared_dpll tries to do the right thing, but
3567 * get_shared_dpll unconditionally resets the pll - we need that to have
3568 * the right LVDS enable sequence. */
3569 intel_enable_shared_dpll(intel_crtc
);
3571 /* set transcoder timing, panel must allow it */
3572 assert_panel_unlocked(dev_priv
, pipe
);
3573 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
3575 intel_fdi_normal_train(crtc
);
3577 /* For PCH DP, enable TRANS_DP_CTL */
3578 if (HAS_PCH_CPT(dev
) &&
3579 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
3580 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3581 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
3582 reg
= TRANS_DP_CTL(pipe
);
3583 temp
= I915_READ(reg
);
3584 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
3585 TRANS_DP_SYNC_MASK
|
3587 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
3588 TRANS_DP_ENH_FRAMING
);
3589 temp
|= bpc
<< 9; /* same format but at 11:9 */
3591 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
3592 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
3593 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
3594 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
3596 switch (intel_trans_dp_port_sel(crtc
)) {
3598 temp
|= TRANS_DP_PORT_SEL_B
;
3601 temp
|= TRANS_DP_PORT_SEL_C
;
3604 temp
|= TRANS_DP_PORT_SEL_D
;
3610 I915_WRITE(reg
, temp
);
3613 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
3616 static void lpt_pch_enable(struct drm_crtc
*crtc
)
3618 struct drm_device
*dev
= crtc
->dev
;
3619 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3620 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3621 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
3623 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
3625 lpt_program_iclkip(crtc
);
3627 /* Set transcoder timing. */
3628 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
3630 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
3633 static void intel_put_shared_dpll(struct intel_crtc
*crtc
)
3635 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3640 if (pll
->refcount
== 0) {
3641 WARN(1, "bad %s refcount\n", pll
->name
);
3645 if (--pll
->refcount
== 0) {
3647 WARN_ON(pll
->active
);
3650 crtc
->config
.shared_dpll
= DPLL_ID_PRIVATE
;
3653 static struct intel_shared_dpll
*intel_get_shared_dpll(struct intel_crtc
*crtc
)
3655 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
3656 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3657 enum intel_dpll_id i
;
3660 DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
3661 crtc
->base
.base
.id
, pll
->name
);
3662 intel_put_shared_dpll(crtc
);
3665 if (HAS_PCH_IBX(dev_priv
->dev
)) {
3666 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3667 i
= (enum intel_dpll_id
) crtc
->pipe
;
3668 pll
= &dev_priv
->shared_dplls
[i
];
3670 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
3671 crtc
->base
.base
.id
, pll
->name
);
3673 WARN_ON(pll
->refcount
);
3678 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3679 pll
= &dev_priv
->shared_dplls
[i
];
3681 /* Only want to check enabled timings first */
3682 if (pll
->refcount
== 0)
3685 if (memcmp(&crtc
->config
.dpll_hw_state
, &pll
->hw_state
,
3686 sizeof(pll
->hw_state
)) == 0) {
3687 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
3689 pll
->name
, pll
->refcount
, pll
->active
);
3695 /* Ok no matching timings, maybe there's a free one? */
3696 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3697 pll
= &dev_priv
->shared_dplls
[i
];
3698 if (pll
->refcount
== 0) {
3699 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
3700 crtc
->base
.base
.id
, pll
->name
);
3708 if (pll
->refcount
== 0)
3709 pll
->hw_state
= crtc
->config
.dpll_hw_state
;
3711 crtc
->config
.shared_dpll
= i
;
3712 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll
->name
,
3713 pipe_name(crtc
->pipe
));
3720 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
3722 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3723 int dslreg
= PIPEDSL(pipe
);
3726 temp
= I915_READ(dslreg
);
3728 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
3729 if (wait_for(I915_READ(dslreg
) != temp
, 5))
3730 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
3734 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
3736 struct drm_device
*dev
= crtc
->base
.dev
;
3737 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3738 int pipe
= crtc
->pipe
;
3740 if (crtc
->config
.pch_pfit
.enabled
) {
3741 /* Force use of hard-coded filter coefficients
3742 * as some pre-programmed values are broken,
3745 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
3746 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
3747 PF_PIPE_SEL_IVB(pipe
));
3749 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
3750 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
.pch_pfit
.pos
);
3751 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
.pch_pfit
.size
);
3755 static void intel_enable_planes(struct drm_crtc
*crtc
)
3757 struct drm_device
*dev
= crtc
->dev
;
3758 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3759 struct drm_plane
*plane
;
3760 struct intel_plane
*intel_plane
;
3762 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3763 intel_plane
= to_intel_plane(plane
);
3764 if (intel_plane
->pipe
== pipe
)
3765 intel_plane_restore(&intel_plane
->base
);
3769 static void intel_disable_planes(struct drm_crtc
*crtc
)
3771 struct drm_device
*dev
= crtc
->dev
;
3772 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3773 struct drm_plane
*plane
;
3774 struct intel_plane
*intel_plane
;
3776 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3777 intel_plane
= to_intel_plane(plane
);
3778 if (intel_plane
->pipe
== pipe
)
3779 intel_plane_disable(&intel_plane
->base
);
3783 void hsw_enable_ips(struct intel_crtc
*crtc
)
3785 struct drm_device
*dev
= crtc
->base
.dev
;
3786 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3788 if (!crtc
->config
.ips_enabled
)
3791 /* We can only enable IPS after we enable a plane and wait for a vblank */
3792 intel_wait_for_vblank(dev
, crtc
->pipe
);
3794 assert_plane_enabled(dev_priv
, crtc
->plane
);
3795 if (IS_BROADWELL(dev
)) {
3796 mutex_lock(&dev_priv
->rps
.hw_lock
);
3797 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
3798 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3799 /* Quoting Art Runyan: "its not safe to expect any particular
3800 * value in IPS_CTL bit 31 after enabling IPS through the
3801 * mailbox." Moreover, the mailbox may return a bogus state,
3802 * so we need to just enable it and continue on.
3805 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
3806 /* The bit only becomes 1 in the next vblank, so this wait here
3807 * is essentially intel_wait_for_vblank. If we don't have this
3808 * and don't wait for vblanks until the end of crtc_enable, then
3809 * the HW state readout code will complain that the expected
3810 * IPS_CTL value is not the one we read. */
3811 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
3812 DRM_ERROR("Timed out waiting for IPS enable\n");
3816 void hsw_disable_ips(struct intel_crtc
*crtc
)
3818 struct drm_device
*dev
= crtc
->base
.dev
;
3819 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3821 if (!crtc
->config
.ips_enabled
)
3824 assert_plane_enabled(dev_priv
, crtc
->plane
);
3825 if (IS_BROADWELL(dev
)) {
3826 mutex_lock(&dev_priv
->rps
.hw_lock
);
3827 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
3828 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3829 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
3830 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
3831 DRM_ERROR("Timed out waiting for IPS disable\n");
3833 I915_WRITE(IPS_CTL
, 0);
3834 POSTING_READ(IPS_CTL
);
3837 /* We need to wait for a vblank before we can disable the plane. */
3838 intel_wait_for_vblank(dev
, crtc
->pipe
);
3841 /** Loads the palette/gamma unit for the CRTC with the prepared values */
3842 static void intel_crtc_load_lut(struct drm_crtc
*crtc
)
3844 struct drm_device
*dev
= crtc
->dev
;
3845 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3846 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3847 enum pipe pipe
= intel_crtc
->pipe
;
3848 int palreg
= PALETTE(pipe
);
3850 bool reenable_ips
= false;
3852 /* The clocks have to be on to load the palette. */
3853 if (!crtc
->enabled
|| !intel_crtc
->active
)
3856 if (!HAS_PCH_SPLIT(dev_priv
->dev
)) {
3857 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
))
3858 assert_dsi_pll_enabled(dev_priv
);
3860 assert_pll_enabled(dev_priv
, pipe
);
3863 /* use legacy palette for Ironlake */
3864 if (HAS_PCH_SPLIT(dev
))
3865 palreg
= LGC_PALETTE(pipe
);
3867 /* Workaround : Do not read or write the pipe palette/gamma data while
3868 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
3870 if (IS_HASWELL(dev
) && intel_crtc
->config
.ips_enabled
&&
3871 ((I915_READ(GAMMA_MODE(pipe
)) & GAMMA_MODE_MODE_MASK
) ==
3872 GAMMA_MODE_MODE_SPLIT
)) {
3873 hsw_disable_ips(intel_crtc
);
3874 reenable_ips
= true;
3877 for (i
= 0; i
< 256; i
++) {
3878 I915_WRITE(palreg
+ 4 * i
,
3879 (intel_crtc
->lut_r
[i
] << 16) |
3880 (intel_crtc
->lut_g
[i
] << 8) |
3881 intel_crtc
->lut_b
[i
]);
3885 hsw_enable_ips(intel_crtc
);
3888 static void intel_crtc_dpms_overlay(struct intel_crtc
*intel_crtc
, bool enable
)
3890 if (!enable
&& intel_crtc
->overlay
) {
3891 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3892 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3894 mutex_lock(&dev
->struct_mutex
);
3895 dev_priv
->mm
.interruptible
= false;
3896 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
3897 dev_priv
->mm
.interruptible
= true;
3898 mutex_unlock(&dev
->struct_mutex
);
3901 /* Let userspace switch the overlay on again. In most cases userspace
3902 * has to recompute where to put it anyway.
3907 * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
3908 * cursor plane briefly if not already running after enabling the display
3910 * This workaround avoids occasional blank screens when self refresh is
3914 g4x_fixup_plane(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
3916 u32 cntl
= I915_READ(CURCNTR(pipe
));
3918 if ((cntl
& CURSOR_MODE
) == 0) {
3919 u32 fw_bcl_self
= I915_READ(FW_BLC_SELF
);
3921 I915_WRITE(FW_BLC_SELF
, fw_bcl_self
& ~FW_BLC_SELF_EN
);
3922 I915_WRITE(CURCNTR(pipe
), CURSOR_MODE_64_ARGB_AX
);
3923 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
3924 I915_WRITE(CURCNTR(pipe
), cntl
);
3925 I915_WRITE(CURBASE(pipe
), I915_READ(CURBASE(pipe
)));
3926 I915_WRITE(FW_BLC_SELF
, fw_bcl_self
);
3930 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
)
3932 struct drm_device
*dev
= crtc
->dev
;
3933 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3934 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3935 int pipe
= intel_crtc
->pipe
;
3936 int plane
= intel_crtc
->plane
;
3938 drm_vblank_on(dev
, pipe
);
3940 intel_enable_primary_hw_plane(dev_priv
, plane
, pipe
);
3941 intel_enable_planes(crtc
);
3942 /* The fixup needs to happen before cursor is enabled */
3944 g4x_fixup_plane(dev_priv
, pipe
);
3945 intel_crtc_update_cursor(crtc
, true);
3946 intel_crtc_dpms_overlay(intel_crtc
, true);
3948 hsw_enable_ips(intel_crtc
);
3950 mutex_lock(&dev
->struct_mutex
);
3951 intel_update_fbc(dev
);
3952 mutex_unlock(&dev
->struct_mutex
);
3955 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
)
3957 struct drm_device
*dev
= crtc
->dev
;
3958 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3959 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3960 int pipe
= intel_crtc
->pipe
;
3961 int plane
= intel_crtc
->plane
;
3963 intel_crtc_wait_for_pending_flips(crtc
);
3965 if (dev_priv
->fbc
.plane
== plane
)
3966 intel_disable_fbc(dev
);
3968 hsw_disable_ips(intel_crtc
);
3970 intel_crtc_dpms_overlay(intel_crtc
, false);
3971 intel_crtc_update_cursor(crtc
, false);
3972 intel_disable_planes(crtc
);
3973 intel_disable_primary_hw_plane(dev_priv
, plane
, pipe
);
3975 drm_vblank_off(dev
, pipe
);
3978 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
3980 struct drm_device
*dev
= crtc
->dev
;
3981 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3982 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3983 struct intel_encoder
*encoder
;
3984 int pipe
= intel_crtc
->pipe
;
3985 enum plane plane
= intel_crtc
->plane
;
3987 WARN_ON(!crtc
->enabled
);
3989 if (intel_crtc
->active
)
3992 if (intel_crtc
->config
.has_pch_encoder
)
3993 intel_prepare_shared_dpll(intel_crtc
);
3995 if (intel_crtc
->config
.has_dp_encoder
)
3996 intel_dp_set_m_n(intel_crtc
);
3998 intel_set_pipe_timings(intel_crtc
);
4000 if (intel_crtc
->config
.has_pch_encoder
) {
4001 intel_cpu_transcoder_set_m_n(intel_crtc
,
4002 &intel_crtc
->config
.fdi_m_n
);
4005 ironlake_set_pipeconf(crtc
);
4007 /* Set up the display plane register */
4008 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
);
4009 POSTING_READ(DSPCNTR(plane
));
4011 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4014 intel_crtc
->active
= true;
4016 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4017 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
4019 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4020 if (encoder
->pre_enable
)
4021 encoder
->pre_enable(encoder
);
4023 if (intel_crtc
->config
.has_pch_encoder
) {
4024 /* Note: FDI PLL enabling _must_ be done before we enable the
4025 * cpu pipes, hence this is separate from all the other fdi/pch
4027 ironlake_fdi_pll_enable(intel_crtc
);
4029 assert_fdi_tx_disabled(dev_priv
, pipe
);
4030 assert_fdi_rx_disabled(dev_priv
, pipe
);
4033 ironlake_pfit_enable(intel_crtc
);
4036 * On ILK+ LUT must be loaded before the pipe is running but with
4039 intel_crtc_load_lut(crtc
);
4041 intel_update_watermarks(crtc
);
4042 intel_enable_pipe(intel_crtc
);
4044 if (intel_crtc
->config
.has_pch_encoder
)
4045 ironlake_pch_enable(crtc
);
4047 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4048 encoder
->enable(encoder
);
4050 if (HAS_PCH_CPT(dev
))
4051 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4053 intel_crtc_enable_planes(crtc
);
4056 /* IPS only exists on ULT machines and is tied to pipe A. */
4057 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4059 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4063 * This implements the workaround described in the "notes" section of the mode
4064 * set sequence documentation. When going from no pipes or single pipe to
4065 * multiple pipes, and planes are enabled after the pipe, we need to wait at
4066 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
4068 static void haswell_mode_set_planes_workaround(struct intel_crtc
*crtc
)
4070 struct drm_device
*dev
= crtc
->base
.dev
;
4071 struct intel_crtc
*crtc_it
, *other_active_crtc
= NULL
;
4073 /* We want to get the other_active_crtc only if there's only 1 other
4075 for_each_intel_crtc(dev
, crtc_it
) {
4076 if (!crtc_it
->active
|| crtc_it
== crtc
)
4079 if (other_active_crtc
)
4082 other_active_crtc
= crtc_it
;
4084 if (!other_active_crtc
)
4087 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4088 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4091 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4093 struct drm_device
*dev
= crtc
->dev
;
4094 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4095 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4096 struct intel_encoder
*encoder
;
4097 int pipe
= intel_crtc
->pipe
;
4098 enum plane plane
= intel_crtc
->plane
;
4100 WARN_ON(!crtc
->enabled
);
4102 if (intel_crtc
->active
)
4105 if (intel_crtc
->config
.has_dp_encoder
)
4106 intel_dp_set_m_n(intel_crtc
);
4108 intel_set_pipe_timings(intel_crtc
);
4110 if (intel_crtc
->config
.has_pch_encoder
) {
4111 intel_cpu_transcoder_set_m_n(intel_crtc
,
4112 &intel_crtc
->config
.fdi_m_n
);
4115 haswell_set_pipeconf(crtc
);
4117 intel_set_pipe_csc(crtc
);
4119 /* Set up the display plane register */
4120 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
| DISPPLANE_PIPE_CSC_ENABLE
);
4121 POSTING_READ(DSPCNTR(plane
));
4123 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4126 intel_crtc
->active
= true;
4128 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4129 if (intel_crtc
->config
.has_pch_encoder
)
4130 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
4132 if (intel_crtc
->config
.has_pch_encoder
)
4133 dev_priv
->display
.fdi_link_train(crtc
);
4135 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4136 if (encoder
->pre_enable
)
4137 encoder
->pre_enable(encoder
);
4139 intel_ddi_enable_pipe_clock(intel_crtc
);
4141 ironlake_pfit_enable(intel_crtc
);
4144 * On ILK+ LUT must be loaded before the pipe is running but with
4147 intel_crtc_load_lut(crtc
);
4149 intel_ddi_set_pipe_settings(crtc
);
4150 intel_ddi_enable_transcoder_func(crtc
);
4152 intel_update_watermarks(crtc
);
4153 intel_enable_pipe(intel_crtc
);
4155 if (intel_crtc
->config
.has_pch_encoder
)
4156 lpt_pch_enable(crtc
);
4158 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4159 encoder
->enable(encoder
);
4160 intel_opregion_notify_encoder(encoder
, true);
4163 /* If we change the relative order between pipe/planes enabling, we need
4164 * to change the workaround. */
4165 haswell_mode_set_planes_workaround(intel_crtc
);
4166 intel_crtc_enable_planes(crtc
);
4169 static void ironlake_pfit_disable(struct intel_crtc
*crtc
)
4171 struct drm_device
*dev
= crtc
->base
.dev
;
4172 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4173 int pipe
= crtc
->pipe
;
4175 /* To avoid upsetting the power well on haswell only disable the pfit if
4176 * it's in use. The hw state code will make sure we get this right. */
4177 if (crtc
->config
.pch_pfit
.enabled
) {
4178 I915_WRITE(PF_CTL(pipe
), 0);
4179 I915_WRITE(PF_WIN_POS(pipe
), 0);
4180 I915_WRITE(PF_WIN_SZ(pipe
), 0);
4184 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
4186 struct drm_device
*dev
= crtc
->dev
;
4187 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4188 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4189 struct intel_encoder
*encoder
;
4190 int pipe
= intel_crtc
->pipe
;
4193 if (!intel_crtc
->active
)
4196 intel_crtc_disable_planes(crtc
);
4198 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4199 encoder
->disable(encoder
);
4201 if (intel_crtc
->config
.has_pch_encoder
)
4202 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, false);
4204 intel_disable_pipe(dev_priv
, pipe
);
4206 ironlake_pfit_disable(intel_crtc
);
4208 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4209 if (encoder
->post_disable
)
4210 encoder
->post_disable(encoder
);
4212 if (intel_crtc
->config
.has_pch_encoder
) {
4213 ironlake_fdi_disable(crtc
);
4215 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
4216 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
4218 if (HAS_PCH_CPT(dev
)) {
4219 /* disable TRANS_DP_CTL */
4220 reg
= TRANS_DP_CTL(pipe
);
4221 temp
= I915_READ(reg
);
4222 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
4223 TRANS_DP_PORT_SEL_MASK
);
4224 temp
|= TRANS_DP_PORT_SEL_NONE
;
4225 I915_WRITE(reg
, temp
);
4227 /* disable DPLL_SEL */
4228 temp
= I915_READ(PCH_DPLL_SEL
);
4229 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
4230 I915_WRITE(PCH_DPLL_SEL
, temp
);
4233 /* disable PCH DPLL */
4234 intel_disable_shared_dpll(intel_crtc
);
4236 ironlake_fdi_pll_disable(intel_crtc
);
4239 intel_crtc
->active
= false;
4240 intel_update_watermarks(crtc
);
4242 mutex_lock(&dev
->struct_mutex
);
4243 intel_update_fbc(dev
);
4244 mutex_unlock(&dev
->struct_mutex
);
4247 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
4249 struct drm_device
*dev
= crtc
->dev
;
4250 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4251 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4252 struct intel_encoder
*encoder
;
4253 int pipe
= intel_crtc
->pipe
;
4254 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
4256 if (!intel_crtc
->active
)
4259 intel_crtc_disable_planes(crtc
);
4261 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4262 intel_opregion_notify_encoder(encoder
, false);
4263 encoder
->disable(encoder
);
4266 if (intel_crtc
->config
.has_pch_encoder
)
4267 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, false);
4268 intel_disable_pipe(dev_priv
, pipe
);
4270 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
4272 ironlake_pfit_disable(intel_crtc
);
4274 intel_ddi_disable_pipe_clock(intel_crtc
);
4276 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4277 if (encoder
->post_disable
)
4278 encoder
->post_disable(encoder
);
4280 if (intel_crtc
->config
.has_pch_encoder
) {
4281 lpt_disable_pch_transcoder(dev_priv
);
4282 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
4283 intel_ddi_fdi_disable(crtc
);
4286 intel_crtc
->active
= false;
4287 intel_update_watermarks(crtc
);
4289 mutex_lock(&dev
->struct_mutex
);
4290 intel_update_fbc(dev
);
4291 mutex_unlock(&dev
->struct_mutex
);
4294 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
4296 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4297 intel_put_shared_dpll(intel_crtc
);
4300 static void haswell_crtc_off(struct drm_crtc
*crtc
)
4302 intel_ddi_put_crtc_pll(crtc
);
4305 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
4307 struct drm_device
*dev
= crtc
->base
.dev
;
4308 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4309 struct intel_crtc_config
*pipe_config
= &crtc
->config
;
4311 if (!crtc
->config
.gmch_pfit
.control
)
4315 * The panel fitter should only be adjusted whilst the pipe is disabled,
4316 * according to register description and PRM.
4318 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
4319 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4321 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
4322 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
4324 /* Border color in case we don't scale up to the full screen. Black by
4325 * default, change to something else for debugging. */
4326 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
4329 #define for_each_power_domain(domain, mask) \
4330 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
4331 if ((1 << (domain)) & (mask))
4333 enum intel_display_power_domain
4334 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
4336 struct drm_device
*dev
= intel_encoder
->base
.dev
;
4337 struct intel_digital_port
*intel_dig_port
;
4339 switch (intel_encoder
->type
) {
4340 case INTEL_OUTPUT_UNKNOWN
:
4341 /* Only DDI platforms should ever use this output type */
4342 WARN_ON_ONCE(!HAS_DDI(dev
));
4343 case INTEL_OUTPUT_DISPLAYPORT
:
4344 case INTEL_OUTPUT_HDMI
:
4345 case INTEL_OUTPUT_EDP
:
4346 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
4347 switch (intel_dig_port
->port
) {
4349 return POWER_DOMAIN_PORT_DDI_A_4_LANES
;
4351 return POWER_DOMAIN_PORT_DDI_B_4_LANES
;
4353 return POWER_DOMAIN_PORT_DDI_C_4_LANES
;
4355 return POWER_DOMAIN_PORT_DDI_D_4_LANES
;
4358 return POWER_DOMAIN_PORT_OTHER
;
4360 case INTEL_OUTPUT_ANALOG
:
4361 return POWER_DOMAIN_PORT_CRT
;
4362 case INTEL_OUTPUT_DSI
:
4363 return POWER_DOMAIN_PORT_DSI
;
4365 return POWER_DOMAIN_PORT_OTHER
;
4369 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
)
4371 struct drm_device
*dev
= crtc
->dev
;
4372 struct intel_encoder
*intel_encoder
;
4373 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4374 enum pipe pipe
= intel_crtc
->pipe
;
4375 bool pfit_enabled
= intel_crtc
->config
.pch_pfit
.enabled
;
4377 enum transcoder transcoder
;
4379 transcoder
= intel_pipe_to_cpu_transcoder(dev
->dev_private
, pipe
);
4381 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
4382 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
4384 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
4386 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
4387 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
4392 void intel_display_set_init_power(struct drm_i915_private
*dev_priv
,
4395 if (dev_priv
->power_domains
.init_power_on
== enable
)
4399 intel_display_power_get(dev_priv
, POWER_DOMAIN_INIT
);
4401 intel_display_power_put(dev_priv
, POWER_DOMAIN_INIT
);
4403 dev_priv
->power_domains
.init_power_on
= enable
;
4406 static void modeset_update_crtc_power_domains(struct drm_device
*dev
)
4408 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4409 unsigned long pipe_domains
[I915_MAX_PIPES
] = { 0, };
4410 struct intel_crtc
*crtc
;
4413 * First get all needed power domains, then put all unneeded, to avoid
4414 * any unnecessary toggling of the power wells.
4416 for_each_intel_crtc(dev
, crtc
) {
4417 enum intel_display_power_domain domain
;
4419 if (!crtc
->base
.enabled
)
4422 pipe_domains
[crtc
->pipe
] = get_crtc_power_domains(&crtc
->base
);
4424 for_each_power_domain(domain
, pipe_domains
[crtc
->pipe
])
4425 intel_display_power_get(dev_priv
, domain
);
4428 for_each_intel_crtc(dev
, crtc
) {
4429 enum intel_display_power_domain domain
;
4431 for_each_power_domain(domain
, crtc
->enabled_power_domains
)
4432 intel_display_power_put(dev_priv
, domain
);
4434 crtc
->enabled_power_domains
= pipe_domains
[crtc
->pipe
];
4437 intel_display_set_init_power(dev_priv
, false);
4440 int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
4442 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
4444 /* Obtain SKU information */
4445 mutex_lock(&dev_priv
->dpio_lock
);
4446 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
4447 CCK_FUSE_HPLL_FREQ_MASK
;
4448 mutex_unlock(&dev_priv
->dpio_lock
);
4450 return vco_freq
[hpll_freq
];
4453 /* Adjust CDclk dividers to allow high res or save power if possible */
4454 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
4456 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4459 WARN_ON(valleyview_cur_cdclk(dev_priv
) != dev_priv
->vlv_cdclk_freq
);
4460 dev_priv
->vlv_cdclk_freq
= cdclk
;
4462 if (cdclk
>= 320) /* jump to highest voltage for 400MHz too */
4464 else if (cdclk
== 266)
4469 mutex_lock(&dev_priv
->rps
.hw_lock
);
4470 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
4471 val
&= ~DSPFREQGUAR_MASK
;
4472 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
4473 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
4474 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
4475 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
4477 DRM_ERROR("timed out waiting for CDclk change\n");
4479 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4484 vco
= valleyview_get_vco(dev_priv
);
4485 divider
= ((vco
<< 1) / cdclk
) - 1;
4487 mutex_lock(&dev_priv
->dpio_lock
);
4488 /* adjust cdclk divider */
4489 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
4492 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
4493 mutex_unlock(&dev_priv
->dpio_lock
);
4496 mutex_lock(&dev_priv
->dpio_lock
);
4497 /* adjust self-refresh exit latency value */
4498 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
4502 * For high bandwidth configs, we set a higher latency in the bunit
4503 * so that the core display fetch happens in time to avoid underruns.
4506 val
|= 4500 / 250; /* 4.5 usec */
4508 val
|= 3000 / 250; /* 3.0 usec */
4509 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
4510 mutex_unlock(&dev_priv
->dpio_lock
);
4512 /* Since we changed the CDclk, we need to update the GMBUSFREQ too */
4513 intel_i2c_reset(dev
);
4516 int valleyview_cur_cdclk(struct drm_i915_private
*dev_priv
)
4521 vco
= valleyview_get_vco(dev_priv
);
4523 mutex_lock(&dev_priv
->dpio_lock
);
4524 divider
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
4525 mutex_unlock(&dev_priv
->dpio_lock
);
4529 cur_cdclk
= (vco
<< 1) / (divider
+ 1);
4534 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
4538 * Really only a few cases to deal with, as only 4 CDclks are supported:
4543 * So we check to see whether we're above 90% of the lower bin and
4546 if (max_pixclk
> 288000) {
4548 } else if (max_pixclk
> 240000) {
4552 /* Looks like the 200MHz CDclk freq doesn't work on some configs */
4555 /* compute the max pixel clock for new configuration */
4556 static int intel_mode_max_pixclk(struct drm_i915_private
*dev_priv
)
4558 struct drm_device
*dev
= dev_priv
->dev
;
4559 struct intel_crtc
*intel_crtc
;
4562 for_each_intel_crtc(dev
, intel_crtc
) {
4563 if (intel_crtc
->new_enabled
)
4564 max_pixclk
= max(max_pixclk
,
4565 intel_crtc
->new_config
->adjusted_mode
.crtc_clock
);
4571 static void valleyview_modeset_global_pipes(struct drm_device
*dev
,
4572 unsigned *prepare_pipes
)
4574 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4575 struct intel_crtc
*intel_crtc
;
4576 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4578 if (valleyview_calc_cdclk(dev_priv
, max_pixclk
) ==
4579 dev_priv
->vlv_cdclk_freq
)
4582 /* disable/enable all currently active pipes while we change cdclk */
4583 for_each_intel_crtc(dev
, intel_crtc
)
4584 if (intel_crtc
->base
.enabled
)
4585 *prepare_pipes
|= (1 << intel_crtc
->pipe
);
4588 static void valleyview_modeset_global_resources(struct drm_device
*dev
)
4590 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4591 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4592 int req_cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
4594 if (req_cdclk
!= dev_priv
->vlv_cdclk_freq
)
4595 valleyview_set_cdclk(dev
, req_cdclk
);
4596 modeset_update_crtc_power_domains(dev
);
4599 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
4601 struct drm_device
*dev
= crtc
->dev
;
4602 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4603 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4604 struct intel_encoder
*encoder
;
4605 int pipe
= intel_crtc
->pipe
;
4606 int plane
= intel_crtc
->plane
;
4610 WARN_ON(!crtc
->enabled
);
4612 if (intel_crtc
->active
)
4615 vlv_prepare_pll(intel_crtc
);
4617 /* Set up the display plane register */
4618 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
4620 if (intel_crtc
->config
.has_dp_encoder
)
4621 intel_dp_set_m_n(intel_crtc
);
4623 intel_set_pipe_timings(intel_crtc
);
4625 /* pipesrc and dspsize control the size that is scaled from,
4626 * which should always be the user's requested size.
4628 I915_WRITE(DSPSIZE(plane
),
4629 ((intel_crtc
->config
.pipe_src_h
- 1) << 16) |
4630 (intel_crtc
->config
.pipe_src_w
- 1));
4631 I915_WRITE(DSPPOS(plane
), 0);
4633 i9xx_set_pipeconf(intel_crtc
);
4635 I915_WRITE(DSPCNTR(plane
), dspcntr
);
4636 POSTING_READ(DSPCNTR(plane
));
4638 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4641 intel_crtc
->active
= true;
4643 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4645 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4646 if (encoder
->pre_pll_enable
)
4647 encoder
->pre_pll_enable(encoder
);
4649 is_dsi
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
);
4652 if (IS_CHERRYVIEW(dev
))
4653 chv_enable_pll(intel_crtc
);
4655 vlv_enable_pll(intel_crtc
);
4658 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4659 if (encoder
->pre_enable
)
4660 encoder
->pre_enable(encoder
);
4662 i9xx_pfit_enable(intel_crtc
);
4664 intel_crtc_load_lut(crtc
);
4666 intel_update_watermarks(crtc
);
4667 intel_enable_pipe(intel_crtc
);
4669 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4670 encoder
->enable(encoder
);
4672 intel_crtc_enable_planes(crtc
);
4674 /* Underruns don't raise interrupts, so check manually. */
4675 i9xx_check_fifo_underruns(dev
);
4678 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
4680 struct drm_device
*dev
= crtc
->base
.dev
;
4681 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4683 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp0
);
4684 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp1
);
4687 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
4689 struct drm_device
*dev
= crtc
->dev
;
4690 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4691 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4692 struct intel_encoder
*encoder
;
4693 int pipe
= intel_crtc
->pipe
;
4694 int plane
= intel_crtc
->plane
;
4697 WARN_ON(!crtc
->enabled
);
4699 if (intel_crtc
->active
)
4702 i9xx_set_pll_dividers(intel_crtc
);
4704 /* Set up the display plane register */
4705 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
4708 dspcntr
&= ~DISPPLANE_SEL_PIPE_MASK
;
4710 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
4712 if (intel_crtc
->config
.has_dp_encoder
)
4713 intel_dp_set_m_n(intel_crtc
);
4715 intel_set_pipe_timings(intel_crtc
);
4717 /* pipesrc and dspsize control the size that is scaled from,
4718 * which should always be the user's requested size.
4720 I915_WRITE(DSPSIZE(plane
),
4721 ((intel_crtc
->config
.pipe_src_h
- 1) << 16) |
4722 (intel_crtc
->config
.pipe_src_w
- 1));
4723 I915_WRITE(DSPPOS(plane
), 0);
4725 i9xx_set_pipeconf(intel_crtc
);
4727 I915_WRITE(DSPCNTR(plane
), dspcntr
);
4728 POSTING_READ(DSPCNTR(plane
));
4730 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4733 intel_crtc
->active
= true;
4736 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4738 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4739 if (encoder
->pre_enable
)
4740 encoder
->pre_enable(encoder
);
4742 i9xx_enable_pll(intel_crtc
);
4744 i9xx_pfit_enable(intel_crtc
);
4746 intel_crtc_load_lut(crtc
);
4748 intel_update_watermarks(crtc
);
4749 intel_enable_pipe(intel_crtc
);
4751 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4752 encoder
->enable(encoder
);
4754 intel_crtc_enable_planes(crtc
);
4757 * Gen2 reports pipe underruns whenever all planes are disabled.
4758 * So don't enable underrun reporting before at least some planes
4760 * FIXME: Need to fix the logic to work when we turn off all planes
4761 * but leave the pipe running.
4764 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4766 /* Underruns don't raise interrupts, so check manually. */
4767 i9xx_check_fifo_underruns(dev
);
4770 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
4772 struct drm_device
*dev
= crtc
->base
.dev
;
4773 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4775 if (!crtc
->config
.gmch_pfit
.control
)
4778 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4780 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
4781 I915_READ(PFIT_CONTROL
));
4782 I915_WRITE(PFIT_CONTROL
, 0);
4785 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
4787 struct drm_device
*dev
= crtc
->dev
;
4788 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4789 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4790 struct intel_encoder
*encoder
;
4791 int pipe
= intel_crtc
->pipe
;
4793 if (!intel_crtc
->active
)
4797 * Gen2 reports pipe underruns whenever all planes are disabled.
4798 * So diasble underrun reporting before all the planes get disabled.
4799 * FIXME: Need to fix the logic to work when we turn off all planes
4800 * but leave the pipe running.
4803 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, false);
4805 intel_crtc_disable_planes(crtc
);
4807 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4808 encoder
->disable(encoder
);
4811 * On gen2 planes are double buffered but the pipe isn't, so we must
4812 * wait for planes to fully turn off before disabling the pipe.
4815 intel_wait_for_vblank(dev
, pipe
);
4817 intel_disable_pipe(dev_priv
, pipe
);
4819 i9xx_pfit_disable(intel_crtc
);
4821 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4822 if (encoder
->post_disable
)
4823 encoder
->post_disable(encoder
);
4825 if (!intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
)) {
4826 if (IS_CHERRYVIEW(dev
))
4827 chv_disable_pll(dev_priv
, pipe
);
4828 else if (IS_VALLEYVIEW(dev
))
4829 vlv_disable_pll(dev_priv
, pipe
);
4831 i9xx_disable_pll(dev_priv
, pipe
);
4835 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, false);
4837 intel_crtc
->active
= false;
4838 intel_update_watermarks(crtc
);
4840 mutex_lock(&dev
->struct_mutex
);
4841 intel_update_fbc(dev
);
4842 mutex_unlock(&dev
->struct_mutex
);
4845 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
4849 static void intel_crtc_update_sarea(struct drm_crtc
*crtc
,
4852 struct drm_device
*dev
= crtc
->dev
;
4853 struct drm_i915_master_private
*master_priv
;
4854 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4855 int pipe
= intel_crtc
->pipe
;
4857 if (!dev
->primary
->master
)
4860 master_priv
= dev
->primary
->master
->driver_priv
;
4861 if (!master_priv
->sarea_priv
)
4866 master_priv
->sarea_priv
->pipeA_w
= enabled
? crtc
->mode
.hdisplay
: 0;
4867 master_priv
->sarea_priv
->pipeA_h
= enabled
? crtc
->mode
.vdisplay
: 0;
4870 master_priv
->sarea_priv
->pipeB_w
= enabled
? crtc
->mode
.hdisplay
: 0;
4871 master_priv
->sarea_priv
->pipeB_h
= enabled
? crtc
->mode
.vdisplay
: 0;
4874 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe
));
4880 * Sets the power management mode of the pipe and plane.
4882 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
4884 struct drm_device
*dev
= crtc
->dev
;
4885 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4886 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4887 struct intel_encoder
*intel_encoder
;
4888 enum intel_display_power_domain domain
;
4889 unsigned long domains
;
4890 bool enable
= false;
4892 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
4893 enable
|= intel_encoder
->connectors_active
;
4896 if (!intel_crtc
->active
) {
4898 * FIXME: DDI plls and relevant code isn't converted
4899 * yet, so do runtime PM for DPMS only for all other
4900 * platforms for now.
4902 if (!HAS_DDI(dev
)) {
4903 domains
= get_crtc_power_domains(crtc
);
4904 for_each_power_domain(domain
, domains
)
4905 intel_display_power_get(dev_priv
, domain
);
4906 intel_crtc
->enabled_power_domains
= domains
;
4909 dev_priv
->display
.crtc_enable(crtc
);
4912 if (intel_crtc
->active
) {
4913 dev_priv
->display
.crtc_disable(crtc
);
4915 if (!HAS_DDI(dev
)) {
4916 domains
= intel_crtc
->enabled_power_domains
;
4917 for_each_power_domain(domain
, domains
)
4918 intel_display_power_put(dev_priv
, domain
);
4919 intel_crtc
->enabled_power_domains
= 0;
4924 intel_crtc_update_sarea(crtc
, enable
);
4927 static void intel_crtc_disable(struct drm_crtc
*crtc
)
4929 struct drm_device
*dev
= crtc
->dev
;
4930 struct drm_connector
*connector
;
4931 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4932 struct drm_i915_gem_object
*old_obj
;
4933 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
4935 /* crtc should still be enabled when we disable it. */
4936 WARN_ON(!crtc
->enabled
);
4938 dev_priv
->display
.crtc_disable(crtc
);
4939 intel_crtc_update_sarea(crtc
, false);
4940 dev_priv
->display
.off(crtc
);
4942 assert_plane_disabled(dev
->dev_private
, to_intel_crtc(crtc
)->plane
);
4943 assert_cursor_disabled(dev_priv
, pipe
);
4944 assert_pipe_disabled(dev
->dev_private
, pipe
);
4946 if (crtc
->primary
->fb
) {
4947 old_obj
= to_intel_framebuffer(crtc
->primary
->fb
)->obj
;
4948 mutex_lock(&dev
->struct_mutex
);
4949 intel_unpin_fb_obj(old_obj
);
4950 i915_gem_track_fb(old_obj
, NULL
,
4951 INTEL_FRONTBUFFER_PRIMARY(pipe
));
4952 mutex_unlock(&dev
->struct_mutex
);
4953 crtc
->primary
->fb
= NULL
;
4956 /* Update computed state. */
4957 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
4958 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
4961 if (connector
->encoder
->crtc
!= crtc
)
4964 connector
->dpms
= DRM_MODE_DPMS_OFF
;
4965 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
4969 void intel_encoder_destroy(struct drm_encoder
*encoder
)
4971 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
4973 drm_encoder_cleanup(encoder
);
4974 kfree(intel_encoder
);
4977 /* Simple dpms helper for encoders with just one connector, no cloning and only
4978 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
4979 * state of the entire output pipe. */
4980 static void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
4982 if (mode
== DRM_MODE_DPMS_ON
) {
4983 encoder
->connectors_active
= true;
4985 intel_crtc_update_dpms(encoder
->base
.crtc
);
4987 encoder
->connectors_active
= false;
4989 intel_crtc_update_dpms(encoder
->base
.crtc
);
4993 /* Cross check the actual hw state with our own modeset state tracking (and it's
4994 * internal consistency). */
4995 static void intel_connector_check_state(struct intel_connector
*connector
)
4997 if (connector
->get_hw_state(connector
)) {
4998 struct intel_encoder
*encoder
= connector
->encoder
;
4999 struct drm_crtc
*crtc
;
5000 bool encoder_enabled
;
5003 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5004 connector
->base
.base
.id
,
5005 connector
->base
.name
);
5007 WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
5008 "wrong connector dpms state\n");
5009 WARN(connector
->base
.encoder
!= &encoder
->base
,
5010 "active connector not linked to encoder\n");
5011 WARN(!encoder
->connectors_active
,
5012 "encoder->connectors_active not set\n");
5014 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
5015 WARN(!encoder_enabled
, "encoder not enabled\n");
5016 if (WARN_ON(!encoder
->base
.crtc
))
5019 crtc
= encoder
->base
.crtc
;
5021 WARN(!crtc
->enabled
, "crtc not enabled\n");
5022 WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
5023 WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
5024 "encoder active on the wrong pipe\n");
5028 /* Even simpler default implementation, if there's really no special case to
5030 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
5032 /* All the simple cases only support two dpms states. */
5033 if (mode
!= DRM_MODE_DPMS_ON
)
5034 mode
= DRM_MODE_DPMS_OFF
;
5036 if (mode
== connector
->dpms
)
5039 connector
->dpms
= mode
;
5041 /* Only need to change hw state when actually enabled */
5042 if (connector
->encoder
)
5043 intel_encoder_dpms(to_intel_encoder(connector
->encoder
), mode
);
5045 intel_modeset_check_state(connector
->dev
);
5048 /* Simple connector->get_hw_state implementation for encoders that support only
5049 * one connector and no cloning and hence the encoder state determines the state
5050 * of the connector. */
5051 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
5054 struct intel_encoder
*encoder
= connector
->encoder
;
5056 return encoder
->get_hw_state(encoder
, &pipe
);
5059 static bool ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
5060 struct intel_crtc_config
*pipe_config
)
5062 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5063 struct intel_crtc
*pipe_B_crtc
=
5064 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
5066 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
5067 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5068 if (pipe_config
->fdi_lanes
> 4) {
5069 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
5070 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5074 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
5075 if (pipe_config
->fdi_lanes
> 2) {
5076 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
5077 pipe_config
->fdi_lanes
);
5084 if (INTEL_INFO(dev
)->num_pipes
== 2)
5087 /* Ivybridge 3 pipe is really complicated */
5092 if (dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]->enabled
&&
5093 pipe_config
->fdi_lanes
> 2) {
5094 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5095 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5100 if (!pipe_has_enabled_pch(pipe_B_crtc
) ||
5101 pipe_B_crtc
->config
.fdi_lanes
<= 2) {
5102 if (pipe_config
->fdi_lanes
> 2) {
5103 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5104 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5108 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5118 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
5119 struct intel_crtc_config
*pipe_config
)
5121 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5122 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5123 int lane
, link_bw
, fdi_dotclock
;
5124 bool setup_ok
, needs_recompute
= false;
5127 /* FDI is a binary signal running at ~2.7GHz, encoding
5128 * each output octet as 10 bits. The actual frequency
5129 * is stored as a divider into a 100MHz clock, and the
5130 * mode pixel clock is stored in units of 1KHz.
5131 * Hence the bw of each lane in terms of the mode signal
5134 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
5136 fdi_dotclock
= adjusted_mode
->crtc_clock
;
5138 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
5139 pipe_config
->pipe_bpp
);
5141 pipe_config
->fdi_lanes
= lane
;
5143 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
5144 link_bw
, &pipe_config
->fdi_m_n
);
5146 setup_ok
= ironlake_check_fdi_lanes(intel_crtc
->base
.dev
,
5147 intel_crtc
->pipe
, pipe_config
);
5148 if (!setup_ok
&& pipe_config
->pipe_bpp
> 6*3) {
5149 pipe_config
->pipe_bpp
-= 2*3;
5150 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
5151 pipe_config
->pipe_bpp
);
5152 needs_recompute
= true;
5153 pipe_config
->bw_constrained
= true;
5158 if (needs_recompute
)
5161 return setup_ok
? 0 : -EINVAL
;
5164 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
5165 struct intel_crtc_config
*pipe_config
)
5167 pipe_config
->ips_enabled
= i915
.enable_ips
&&
5168 hsw_crtc_supports_ips(crtc
) &&
5169 pipe_config
->pipe_bpp
<= 24;
5172 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
5173 struct intel_crtc_config
*pipe_config
)
5175 struct drm_device
*dev
= crtc
->base
.dev
;
5176 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5178 /* FIXME should check pixel clock limits on all platforms */
5179 if (INTEL_INFO(dev
)->gen
< 4) {
5180 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5182 dev_priv
->display
.get_display_clock_speed(dev
);
5185 * Enable pixel doubling when the dot clock
5186 * is > 90% of the (display) core speed.
5188 * GDG double wide on either pipe,
5189 * otherwise pipe A only.
5191 if ((crtc
->pipe
== PIPE_A
|| IS_I915G(dev
)) &&
5192 adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10) {
5194 pipe_config
->double_wide
= true;
5197 if (adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10)
5202 * Pipe horizontal size must be even in:
5204 * - LVDS dual channel mode
5205 * - Double wide pipe
5207 if ((intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5208 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
5209 pipe_config
->pipe_src_w
&= ~1;
5211 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
5212 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
5214 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
5215 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
5218 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) && pipe_config
->pipe_bpp
> 10*3) {
5219 pipe_config
->pipe_bpp
= 10*3; /* 12bpc is gen5+ */
5220 } else if (INTEL_INFO(dev
)->gen
<= 4 && pipe_config
->pipe_bpp
> 8*3) {
5221 /* only a 8bpc pipe, with 6bpc dither through the panel fitter
5223 pipe_config
->pipe_bpp
= 8*3;
5227 hsw_compute_ips_config(crtc
, pipe_config
);
5229 /* XXX: PCH clock sharing is done in ->mode_set, so make sure the old
5230 * clock survives for now. */
5231 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
5232 pipe_config
->shared_dpll
= crtc
->config
.shared_dpll
;
5234 if (pipe_config
->has_pch_encoder
)
5235 return ironlake_fdi_compute_config(crtc
, pipe_config
);
5240 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
5242 return 400000; /* FIXME */
5245 static int i945_get_display_clock_speed(struct drm_device
*dev
)
5250 static int i915_get_display_clock_speed(struct drm_device
*dev
)
5255 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
5260 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
5264 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5266 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5267 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
5269 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
5271 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
5273 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
5276 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
5277 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
5279 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
5284 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
5288 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5290 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
5293 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5294 case GC_DISPLAY_CLOCK_333_MHZ
:
5297 case GC_DISPLAY_CLOCK_190_200_MHZ
:
5303 static int i865_get_display_clock_speed(struct drm_device
*dev
)
5308 static int i855_get_display_clock_speed(struct drm_device
*dev
)
5311 /* Assume that the hardware is in the high speed state. This
5312 * should be the default.
5314 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
5315 case GC_CLOCK_133_200
:
5316 case GC_CLOCK_100_200
:
5318 case GC_CLOCK_166_250
:
5320 case GC_CLOCK_100_133
:
5324 /* Shouldn't happen */
5328 static int i830_get_display_clock_speed(struct drm_device
*dev
)
5334 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
5336 while (*num
> DATA_LINK_M_N_MASK
||
5337 *den
> DATA_LINK_M_N_MASK
) {
5343 static void compute_m_n(unsigned int m
, unsigned int n
,
5344 uint32_t *ret_m
, uint32_t *ret_n
)
5346 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
5347 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
5348 intel_reduce_m_n_ratio(ret_m
, ret_n
);
5352 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
5353 int pixel_clock
, int link_clock
,
5354 struct intel_link_m_n
*m_n
)
5358 compute_m_n(bits_per_pixel
* pixel_clock
,
5359 link_clock
* nlanes
* 8,
5360 &m_n
->gmch_m
, &m_n
->gmch_n
);
5362 compute_m_n(pixel_clock
, link_clock
,
5363 &m_n
->link_m
, &m_n
->link_n
);
5366 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
5368 if (i915
.panel_use_ssc
>= 0)
5369 return i915
.panel_use_ssc
!= 0;
5370 return dev_priv
->vbt
.lvds_use_ssc
5371 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
5374 static int i9xx_get_refclk(struct drm_crtc
*crtc
, int num_connectors
)
5376 struct drm_device
*dev
= crtc
->dev
;
5377 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5380 if (IS_VALLEYVIEW(dev
)) {
5382 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
5383 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
5384 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
5385 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
5386 } else if (!IS_GEN2(dev
)) {
5395 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
5397 return (1 << dpll
->n
) << 16 | dpll
->m2
;
5400 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
5402 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
5405 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
5406 intel_clock_t
*reduced_clock
)
5408 struct drm_device
*dev
= crtc
->base
.dev
;
5411 if (IS_PINEVIEW(dev
)) {
5412 fp
= pnv_dpll_compute_fp(&crtc
->config
.dpll
);
5414 fp2
= pnv_dpll_compute_fp(reduced_clock
);
5416 fp
= i9xx_dpll_compute_fp(&crtc
->config
.dpll
);
5418 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
5421 crtc
->config
.dpll_hw_state
.fp0
= fp
;
5423 crtc
->lowfreq_avail
= false;
5424 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5425 reduced_clock
&& i915
.powersave
) {
5426 crtc
->config
.dpll_hw_state
.fp1
= fp2
;
5427 crtc
->lowfreq_avail
= true;
5429 crtc
->config
.dpll_hw_state
.fp1
= fp
;
5433 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
5439 * PLLB opamp always calibrates to max value of 0x3f, force enable it
5440 * and set it to a reasonable value instead.
5442 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5443 reg_val
&= 0xffffff00;
5444 reg_val
|= 0x00000030;
5445 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5447 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5448 reg_val
&= 0x8cffffff;
5449 reg_val
= 0x8c000000;
5450 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5452 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5453 reg_val
&= 0xffffff00;
5454 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5456 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5457 reg_val
&= 0x00ffffff;
5458 reg_val
|= 0xb0000000;
5459 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5462 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
5463 struct intel_link_m_n
*m_n
)
5465 struct drm_device
*dev
= crtc
->base
.dev
;
5466 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5467 int pipe
= crtc
->pipe
;
5469 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5470 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
5471 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
5472 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
5475 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
5476 struct intel_link_m_n
*m_n
)
5478 struct drm_device
*dev
= crtc
->base
.dev
;
5479 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5480 int pipe
= crtc
->pipe
;
5481 enum transcoder transcoder
= crtc
->config
.cpu_transcoder
;
5483 if (INTEL_INFO(dev
)->gen
>= 5) {
5484 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5485 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
5486 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
5487 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
5489 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5490 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
5491 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
5492 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
5496 static void intel_dp_set_m_n(struct intel_crtc
*crtc
)
5498 if (crtc
->config
.has_pch_encoder
)
5499 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
5501 intel_cpu_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
5504 static void vlv_update_pll(struct intel_crtc
*crtc
)
5509 * Enable DPIO clock input. We should never disable the reference
5510 * clock for pipe B, since VGA hotplug / manual detection depends
5513 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
5514 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
5515 /* We should never disable this, set it here for state tracking */
5516 if (crtc
->pipe
== PIPE_B
)
5517 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5518 dpll
|= DPLL_VCO_ENABLE
;
5519 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5521 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
5522 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5523 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
5526 static void vlv_prepare_pll(struct intel_crtc
*crtc
)
5528 struct drm_device
*dev
= crtc
->base
.dev
;
5529 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5530 int pipe
= crtc
->pipe
;
5532 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
5533 u32 coreclk
, reg_val
;
5535 mutex_lock(&dev_priv
->dpio_lock
);
5537 bestn
= crtc
->config
.dpll
.n
;
5538 bestm1
= crtc
->config
.dpll
.m1
;
5539 bestm2
= crtc
->config
.dpll
.m2
;
5540 bestp1
= crtc
->config
.dpll
.p1
;
5541 bestp2
= crtc
->config
.dpll
.p2
;
5543 /* See eDP HDMI DPIO driver vbios notes doc */
5545 /* PLL B needs special handling */
5547 vlv_pllb_recal_opamp(dev_priv
, pipe
);
5549 /* Set up Tx target for periodic Rcomp update */
5550 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
5552 /* Disable target IRef on PLL */
5553 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
5554 reg_val
&= 0x00ffffff;
5555 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
5557 /* Disable fast lock */
5558 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
5560 /* Set idtafcrecal before PLL is enabled */
5561 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
5562 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
5563 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
5564 mdiv
|= (1 << DPIO_K_SHIFT
);
5567 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
5568 * but we don't support that).
5569 * Note: don't use the DAC post divider as it seems unstable.
5571 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
5572 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5574 mdiv
|= DPIO_ENABLE_CALIBRATION
;
5575 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5577 /* Set HBR and RBR LPF coefficients */
5578 if (crtc
->config
.port_clock
== 162000 ||
5579 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_ANALOG
) ||
5580 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
))
5581 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5584 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5587 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
) ||
5588 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
)) {
5589 /* Use SSC source */
5591 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5594 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5596 } else { /* HDMI or VGA */
5597 /* Use bend source */
5599 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5602 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5606 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
5607 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
5608 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
) ||
5609 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
))
5610 coreclk
|= 0x01000000;
5611 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
5613 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
5614 mutex_unlock(&dev_priv
->dpio_lock
);
5617 static void chv_update_pll(struct intel_crtc
*crtc
)
5619 struct drm_device
*dev
= crtc
->base
.dev
;
5620 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5621 int pipe
= crtc
->pipe
;
5622 int dpll_reg
= DPLL(crtc
->pipe
);
5623 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
5624 u32 loopfilter
, intcoeff
;
5625 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
5628 crtc
->config
.dpll_hw_state
.dpll
= DPLL_SSC_REF_CLOCK_CHV
|
5629 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
|
5632 crtc
->config
.dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5634 crtc
->config
.dpll_hw_state
.dpll_md
=
5635 (crtc
->config
.pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5637 bestn
= crtc
->config
.dpll
.n
;
5638 bestm2_frac
= crtc
->config
.dpll
.m2
& 0x3fffff;
5639 bestm1
= crtc
->config
.dpll
.m1
;
5640 bestm2
= crtc
->config
.dpll
.m2
>> 22;
5641 bestp1
= crtc
->config
.dpll
.p1
;
5642 bestp2
= crtc
->config
.dpll
.p2
;
5645 * Enable Refclk and SSC
5647 I915_WRITE(dpll_reg
,
5648 crtc
->config
.dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
5650 mutex_lock(&dev_priv
->dpio_lock
);
5652 /* p1 and p2 divider */
5653 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
5654 5 << DPIO_CHV_S1_DIV_SHIFT
|
5655 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
5656 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
5657 1 << DPIO_CHV_K_DIV_SHIFT
);
5659 /* Feedback post-divider - m2 */
5660 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
5662 /* Feedback refclk divider - n and m1 */
5663 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
5664 DPIO_CHV_M1_DIV_BY_2
|
5665 1 << DPIO_CHV_N_DIV_SHIFT
);
5667 /* M2 fraction division */
5668 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
5670 /* M2 fraction division enable */
5671 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
),
5672 DPIO_CHV_FRAC_DIV_EN
|
5673 (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
));
5676 refclk
= i9xx_get_refclk(&crtc
->base
, 0);
5677 loopfilter
= 5 << DPIO_CHV_PROP_COEFF_SHIFT
|
5678 2 << DPIO_CHV_GAIN_CTRL_SHIFT
;
5679 if (refclk
== 100000)
5681 else if (refclk
== 38400)
5685 loopfilter
|= intcoeff
<< DPIO_CHV_INT_COEFF_SHIFT
;
5686 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
5689 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
5690 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
5693 mutex_unlock(&dev_priv
->dpio_lock
);
5696 static void i9xx_update_pll(struct intel_crtc
*crtc
,
5697 intel_clock_t
*reduced_clock
,
5700 struct drm_device
*dev
= crtc
->base
.dev
;
5701 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5704 struct dpll
*clock
= &crtc
->config
.dpll
;
5706 i9xx_update_pll_dividers(crtc
, reduced_clock
);
5708 is_sdvo
= intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_SDVO
) ||
5709 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
);
5711 dpll
= DPLL_VGA_MODE_DIS
;
5713 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
))
5714 dpll
|= DPLLB_MODE_LVDS
;
5716 dpll
|= DPLLB_MODE_DAC_SERIAL
;
5718 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
5719 dpll
|= (crtc
->config
.pixel_multiplier
- 1)
5720 << SDVO_MULTIPLIER_SHIFT_HIRES
;
5724 dpll
|= DPLL_SDVO_HIGH_SPEED
;
5726 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
))
5727 dpll
|= DPLL_SDVO_HIGH_SPEED
;
5729 /* compute bitmask from p1 value */
5730 if (IS_PINEVIEW(dev
))
5731 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
5733 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5734 if (IS_G4X(dev
) && reduced_clock
)
5735 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
5737 switch (clock
->p2
) {
5739 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
5742 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
5745 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
5748 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
5751 if (INTEL_INFO(dev
)->gen
>= 4)
5752 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
5754 if (crtc
->config
.sdvo_tv_clock
)
5755 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
5756 else if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5757 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5758 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5760 dpll
|= PLL_REF_INPUT_DREFCLK
;
5762 dpll
|= DPLL_VCO_ENABLE
;
5763 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5765 if (INTEL_INFO(dev
)->gen
>= 4) {
5766 u32 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
5767 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5768 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
5772 static void i8xx_update_pll(struct intel_crtc
*crtc
,
5773 intel_clock_t
*reduced_clock
,
5776 struct drm_device
*dev
= crtc
->base
.dev
;
5777 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5779 struct dpll
*clock
= &crtc
->config
.dpll
;
5781 i9xx_update_pll_dividers(crtc
, reduced_clock
);
5783 dpll
= DPLL_VGA_MODE_DIS
;
5785 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
)) {
5786 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5789 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
5791 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5793 dpll
|= PLL_P2_DIVIDE_BY_4
;
5796 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DVO
))
5797 dpll
|= DPLL_DVO_2X_MODE
;
5799 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5800 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5801 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5803 dpll
|= PLL_REF_INPUT_DREFCLK
;
5805 dpll
|= DPLL_VCO_ENABLE
;
5806 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5809 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
5811 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5812 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5813 enum pipe pipe
= intel_crtc
->pipe
;
5814 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
5815 struct drm_display_mode
*adjusted_mode
=
5816 &intel_crtc
->config
.adjusted_mode
;
5817 uint32_t crtc_vtotal
, crtc_vblank_end
;
5820 /* We need to be careful not to changed the adjusted mode, for otherwise
5821 * the hw state checker will get angry at the mismatch. */
5822 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
5823 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
5825 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
5826 /* the chip adds 2 halflines automatically */
5828 crtc_vblank_end
-= 1;
5830 if (intel_pipe_has_type(&intel_crtc
->base
, INTEL_OUTPUT_SDVO
))
5831 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
5833 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
5834 adjusted_mode
->crtc_htotal
/ 2;
5836 vsyncshift
+= adjusted_mode
->crtc_htotal
;
5839 if (INTEL_INFO(dev
)->gen
> 3)
5840 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
5842 I915_WRITE(HTOTAL(cpu_transcoder
),
5843 (adjusted_mode
->crtc_hdisplay
- 1) |
5844 ((adjusted_mode
->crtc_htotal
- 1) << 16));
5845 I915_WRITE(HBLANK(cpu_transcoder
),
5846 (adjusted_mode
->crtc_hblank_start
- 1) |
5847 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
5848 I915_WRITE(HSYNC(cpu_transcoder
),
5849 (adjusted_mode
->crtc_hsync_start
- 1) |
5850 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
5852 I915_WRITE(VTOTAL(cpu_transcoder
),
5853 (adjusted_mode
->crtc_vdisplay
- 1) |
5854 ((crtc_vtotal
- 1) << 16));
5855 I915_WRITE(VBLANK(cpu_transcoder
),
5856 (adjusted_mode
->crtc_vblank_start
- 1) |
5857 ((crtc_vblank_end
- 1) << 16));
5858 I915_WRITE(VSYNC(cpu_transcoder
),
5859 (adjusted_mode
->crtc_vsync_start
- 1) |
5860 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
5862 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
5863 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
5864 * documented on the DDI_FUNC_CTL register description, EDP Input Select
5866 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
5867 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
5868 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
5870 /* pipesrc controls the size that is scaled from, which should
5871 * always be the user's requested size.
5873 I915_WRITE(PIPESRC(pipe
),
5874 ((intel_crtc
->config
.pipe_src_w
- 1) << 16) |
5875 (intel_crtc
->config
.pipe_src_h
- 1));
5878 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
5879 struct intel_crtc_config
*pipe_config
)
5881 struct drm_device
*dev
= crtc
->base
.dev
;
5882 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5883 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
5886 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
5887 pipe_config
->adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
5888 pipe_config
->adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
5889 tmp
= I915_READ(HBLANK(cpu_transcoder
));
5890 pipe_config
->adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
5891 pipe_config
->adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
5892 tmp
= I915_READ(HSYNC(cpu_transcoder
));
5893 pipe_config
->adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
5894 pipe_config
->adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
5896 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
5897 pipe_config
->adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
5898 pipe_config
->adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
5899 tmp
= I915_READ(VBLANK(cpu_transcoder
));
5900 pipe_config
->adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
5901 pipe_config
->adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
5902 tmp
= I915_READ(VSYNC(cpu_transcoder
));
5903 pipe_config
->adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
5904 pipe_config
->adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
5906 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
5907 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
5908 pipe_config
->adjusted_mode
.crtc_vtotal
+= 1;
5909 pipe_config
->adjusted_mode
.crtc_vblank_end
+= 1;
5912 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
5913 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
5914 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
5916 pipe_config
->requested_mode
.vdisplay
= pipe_config
->pipe_src_h
;
5917 pipe_config
->requested_mode
.hdisplay
= pipe_config
->pipe_src_w
;
5920 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
5921 struct intel_crtc_config
*pipe_config
)
5923 mode
->hdisplay
= pipe_config
->adjusted_mode
.crtc_hdisplay
;
5924 mode
->htotal
= pipe_config
->adjusted_mode
.crtc_htotal
;
5925 mode
->hsync_start
= pipe_config
->adjusted_mode
.crtc_hsync_start
;
5926 mode
->hsync_end
= pipe_config
->adjusted_mode
.crtc_hsync_end
;
5928 mode
->vdisplay
= pipe_config
->adjusted_mode
.crtc_vdisplay
;
5929 mode
->vtotal
= pipe_config
->adjusted_mode
.crtc_vtotal
;
5930 mode
->vsync_start
= pipe_config
->adjusted_mode
.crtc_vsync_start
;
5931 mode
->vsync_end
= pipe_config
->adjusted_mode
.crtc_vsync_end
;
5933 mode
->flags
= pipe_config
->adjusted_mode
.flags
;
5935 mode
->clock
= pipe_config
->adjusted_mode
.crtc_clock
;
5936 mode
->flags
|= pipe_config
->adjusted_mode
.flags
;
5939 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
5941 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5942 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5947 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
5948 I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
)
5949 pipeconf
|= PIPECONF_ENABLE
;
5951 if (intel_crtc
->config
.double_wide
)
5952 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
5954 /* only g4x and later have fancy bpc/dither controls */
5955 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
5956 /* Bspec claims that we can't use dithering for 30bpp pipes. */
5957 if (intel_crtc
->config
.dither
&& intel_crtc
->config
.pipe_bpp
!= 30)
5958 pipeconf
|= PIPECONF_DITHER_EN
|
5959 PIPECONF_DITHER_TYPE_SP
;
5961 switch (intel_crtc
->config
.pipe_bpp
) {
5963 pipeconf
|= PIPECONF_6BPC
;
5966 pipeconf
|= PIPECONF_8BPC
;
5969 pipeconf
|= PIPECONF_10BPC
;
5972 /* Case prevented by intel_choose_pipe_bpp_dither. */
5977 if (HAS_PIPE_CXSR(dev
)) {
5978 if (intel_crtc
->lowfreq_avail
) {
5979 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
5980 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
5982 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
5986 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
5987 if (INTEL_INFO(dev
)->gen
< 4 ||
5988 intel_pipe_has_type(&intel_crtc
->base
, INTEL_OUTPUT_SDVO
))
5989 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
5991 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
5993 pipeconf
|= PIPECONF_PROGRESSIVE
;
5995 if (IS_VALLEYVIEW(dev
) && intel_crtc
->config
.limited_color_range
)
5996 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
5998 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
5999 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
6002 static int i9xx_crtc_mode_set(struct drm_crtc
*crtc
,
6004 struct drm_framebuffer
*fb
)
6006 struct drm_device
*dev
= crtc
->dev
;
6007 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6008 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6009 int refclk
, num_connectors
= 0;
6010 intel_clock_t clock
, reduced_clock
;
6011 bool ok
, has_reduced_clock
= false;
6012 bool is_lvds
= false, is_dsi
= false;
6013 struct intel_encoder
*encoder
;
6014 const intel_limit_t
*limit
;
6016 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
6017 switch (encoder
->type
) {
6018 case INTEL_OUTPUT_LVDS
:
6021 case INTEL_OUTPUT_DSI
:
6032 if (!intel_crtc
->config
.clock_set
) {
6033 refclk
= i9xx_get_refclk(crtc
, num_connectors
);
6036 * Returns a set of divisors for the desired target clock with
6037 * the given refclk, or FALSE. The returned values represent
6038 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
6041 limit
= intel_limit(crtc
, refclk
);
6042 ok
= dev_priv
->display
.find_dpll(limit
, crtc
,
6043 intel_crtc
->config
.port_clock
,
6044 refclk
, NULL
, &clock
);
6046 DRM_ERROR("Couldn't find PLL settings for mode!\n");
6050 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
6052 * Ensure we match the reduced clock's P to the target
6053 * clock. If the clocks don't match, we can't switch
6054 * the display clock by using the FP0/FP1. In such case
6055 * we will disable the LVDS downclock feature.
6058 dev_priv
->display
.find_dpll(limit
, crtc
,
6059 dev_priv
->lvds_downclock
,
6063 /* Compat-code for transition, will disappear. */
6064 intel_crtc
->config
.dpll
.n
= clock
.n
;
6065 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
6066 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
6067 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
6068 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
6072 i8xx_update_pll(intel_crtc
,
6073 has_reduced_clock
? &reduced_clock
: NULL
,
6075 } else if (IS_CHERRYVIEW(dev
)) {
6076 chv_update_pll(intel_crtc
);
6077 } else if (IS_VALLEYVIEW(dev
)) {
6078 vlv_update_pll(intel_crtc
);
6080 i9xx_update_pll(intel_crtc
,
6081 has_reduced_clock
? &reduced_clock
: NULL
,
6088 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
6089 struct intel_crtc_config
*pipe_config
)
6091 struct drm_device
*dev
= crtc
->base
.dev
;
6092 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6095 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
6098 tmp
= I915_READ(PFIT_CONTROL
);
6099 if (!(tmp
& PFIT_ENABLE
))
6102 /* Check whether the pfit is attached to our pipe. */
6103 if (INTEL_INFO(dev
)->gen
< 4) {
6104 if (crtc
->pipe
!= PIPE_B
)
6107 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
6111 pipe_config
->gmch_pfit
.control
= tmp
;
6112 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
6113 if (INTEL_INFO(dev
)->gen
< 5)
6114 pipe_config
->gmch_pfit
.lvds_border_bits
=
6115 I915_READ(LVDS
) & LVDS_BORDER_ENABLE
;
6118 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
6119 struct intel_crtc_config
*pipe_config
)
6121 struct drm_device
*dev
= crtc
->base
.dev
;
6122 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6123 int pipe
= pipe_config
->cpu_transcoder
;
6124 intel_clock_t clock
;
6126 int refclk
= 100000;
6128 mutex_lock(&dev_priv
->dpio_lock
);
6129 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
6130 mutex_unlock(&dev_priv
->dpio_lock
);
6132 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
6133 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
6134 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
6135 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
6136 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
6138 vlv_clock(refclk
, &clock
);
6140 /* clock.dot is the fast clock */
6141 pipe_config
->port_clock
= clock
.dot
/ 5;
6144 static void i9xx_get_plane_config(struct intel_crtc
*crtc
,
6145 struct intel_plane_config
*plane_config
)
6147 struct drm_device
*dev
= crtc
->base
.dev
;
6148 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6149 u32 val
, base
, offset
;
6150 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
6151 int fourcc
, pixel_format
;
6154 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
6155 if (!crtc
->base
.primary
->fb
) {
6156 DRM_DEBUG_KMS("failed to alloc fb\n");
6160 val
= I915_READ(DSPCNTR(plane
));
6162 if (INTEL_INFO(dev
)->gen
>= 4)
6163 if (val
& DISPPLANE_TILED
)
6164 plane_config
->tiled
= true;
6166 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
6167 fourcc
= intel_format_to_fourcc(pixel_format
);
6168 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
6169 crtc
->base
.primary
->fb
->bits_per_pixel
=
6170 drm_format_plane_cpp(fourcc
, 0) * 8;
6172 if (INTEL_INFO(dev
)->gen
>= 4) {
6173 if (plane_config
->tiled
)
6174 offset
= I915_READ(DSPTILEOFF(plane
));
6176 offset
= I915_READ(DSPLINOFF(plane
));
6177 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
6179 base
= I915_READ(DSPADDR(plane
));
6181 plane_config
->base
= base
;
6183 val
= I915_READ(PIPESRC(pipe
));
6184 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
6185 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
6187 val
= I915_READ(DSPSTRIDE(pipe
));
6188 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffff80;
6190 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
6191 plane_config
->tiled
);
6193 plane_config
->size
= ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
6194 aligned_height
, PAGE_SIZE
);
6196 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
6197 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
6198 crtc
->base
.primary
->fb
->height
,
6199 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
6200 crtc
->base
.primary
->fb
->pitches
[0],
6201 plane_config
->size
);
6205 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
6206 struct intel_crtc_config
*pipe_config
)
6208 struct drm_device
*dev
= crtc
->base
.dev
;
6209 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6210 int pipe
= pipe_config
->cpu_transcoder
;
6211 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6212 intel_clock_t clock
;
6213 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
;
6214 int refclk
= 100000;
6216 mutex_lock(&dev_priv
->dpio_lock
);
6217 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
6218 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
6219 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
6220 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
6221 mutex_unlock(&dev_priv
->dpio_lock
);
6223 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
6224 clock
.m2
= ((pll_dw0
& 0xff) << 22) | (pll_dw2
& 0x3fffff);
6225 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
6226 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
6227 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
6229 chv_clock(refclk
, &clock
);
6231 /* clock.dot is the fast clock */
6232 pipe_config
->port_clock
= clock
.dot
/ 5;
6235 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
6236 struct intel_crtc_config
*pipe_config
)
6238 struct drm_device
*dev
= crtc
->base
.dev
;
6239 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6242 if (!intel_display_power_enabled(dev_priv
,
6243 POWER_DOMAIN_PIPE(crtc
->pipe
)))
6246 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
6247 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
6249 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
6250 if (!(tmp
& PIPECONF_ENABLE
))
6253 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
6254 switch (tmp
& PIPECONF_BPC_MASK
) {
6256 pipe_config
->pipe_bpp
= 18;
6259 pipe_config
->pipe_bpp
= 24;
6261 case PIPECONF_10BPC
:
6262 pipe_config
->pipe_bpp
= 30;
6269 if (IS_VALLEYVIEW(dev
) && (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
6270 pipe_config
->limited_color_range
= true;
6272 if (INTEL_INFO(dev
)->gen
< 4)
6273 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
6275 intel_get_pipe_timings(crtc
, pipe_config
);
6277 i9xx_get_pfit_config(crtc
, pipe_config
);
6279 if (INTEL_INFO(dev
)->gen
>= 4) {
6280 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
6281 pipe_config
->pixel_multiplier
=
6282 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
6283 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
6284 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
6285 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
6286 tmp
= I915_READ(DPLL(crtc
->pipe
));
6287 pipe_config
->pixel_multiplier
=
6288 ((tmp
& SDVO_MULTIPLIER_MASK
)
6289 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
6291 /* Note that on i915G/GM the pixel multiplier is in the sdvo
6292 * port and will be fixed up in the encoder->get_config
6294 pipe_config
->pixel_multiplier
= 1;
6296 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
6297 if (!IS_VALLEYVIEW(dev
)) {
6298 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
6299 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
6301 /* Mask out read-only status bits. */
6302 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
6303 DPLL_PORTC_READY_MASK
|
6304 DPLL_PORTB_READY_MASK
);
6307 if (IS_CHERRYVIEW(dev
))
6308 chv_crtc_clock_get(crtc
, pipe_config
);
6309 else if (IS_VALLEYVIEW(dev
))
6310 vlv_crtc_clock_get(crtc
, pipe_config
);
6312 i9xx_crtc_clock_get(crtc
, pipe_config
);
6317 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
6319 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6320 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
6321 struct intel_encoder
*encoder
;
6323 bool has_lvds
= false;
6324 bool has_cpu_edp
= false;
6325 bool has_panel
= false;
6326 bool has_ck505
= false;
6327 bool can_ssc
= false;
6329 /* We need to take the global config into account */
6330 list_for_each_entry(encoder
, &mode_config
->encoder_list
,
6332 switch (encoder
->type
) {
6333 case INTEL_OUTPUT_LVDS
:
6337 case INTEL_OUTPUT_EDP
:
6339 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
6345 if (HAS_PCH_IBX(dev
)) {
6346 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
6347 can_ssc
= has_ck505
;
6353 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
6354 has_panel
, has_lvds
, has_ck505
);
6356 /* Ironlake: try to setup display ref clock before DPLL
6357 * enabling. This is only under driver's control after
6358 * PCH B stepping, previous chipset stepping should be
6359 * ignoring this setting.
6361 val
= I915_READ(PCH_DREF_CONTROL
);
6363 /* As we must carefully and slowly disable/enable each source in turn,
6364 * compute the final state we want first and check if we need to
6365 * make any changes at all.
6368 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6370 final
|= DREF_NONSPREAD_CK505_ENABLE
;
6372 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6374 final
&= ~DREF_SSC_SOURCE_MASK
;
6375 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6376 final
&= ~DREF_SSC1_ENABLE
;
6379 final
|= DREF_SSC_SOURCE_ENABLE
;
6381 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6382 final
|= DREF_SSC1_ENABLE
;
6385 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6386 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6388 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6390 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6392 final
|= DREF_SSC_SOURCE_DISABLE
;
6393 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6399 /* Always enable nonspread source */
6400 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6403 val
|= DREF_NONSPREAD_CK505_ENABLE
;
6405 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6408 val
&= ~DREF_SSC_SOURCE_MASK
;
6409 val
|= DREF_SSC_SOURCE_ENABLE
;
6411 /* SSC must be turned on before enabling the CPU output */
6412 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6413 DRM_DEBUG_KMS("Using SSC on panel\n");
6414 val
|= DREF_SSC1_ENABLE
;
6416 val
&= ~DREF_SSC1_ENABLE
;
6418 /* Get SSC going before enabling the outputs */
6419 I915_WRITE(PCH_DREF_CONTROL
, val
);
6420 POSTING_READ(PCH_DREF_CONTROL
);
6423 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6425 /* Enable CPU source on CPU attached eDP */
6427 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6428 DRM_DEBUG_KMS("Using SSC on eDP\n");
6429 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6431 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6433 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6435 I915_WRITE(PCH_DREF_CONTROL
, val
);
6436 POSTING_READ(PCH_DREF_CONTROL
);
6439 DRM_DEBUG_KMS("Disabling SSC entirely\n");
6441 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6443 /* Turn off CPU output */
6444 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6446 I915_WRITE(PCH_DREF_CONTROL
, val
);
6447 POSTING_READ(PCH_DREF_CONTROL
);
6450 /* Turn off the SSC source */
6451 val
&= ~DREF_SSC_SOURCE_MASK
;
6452 val
|= DREF_SSC_SOURCE_DISABLE
;
6455 val
&= ~DREF_SSC1_ENABLE
;
6457 I915_WRITE(PCH_DREF_CONTROL
, val
);
6458 POSTING_READ(PCH_DREF_CONTROL
);
6462 BUG_ON(val
!= final
);
6465 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
6469 tmp
= I915_READ(SOUTH_CHICKEN2
);
6470 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
6471 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6473 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
6474 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
6475 DRM_ERROR("FDI mPHY reset assert timeout\n");
6477 tmp
= I915_READ(SOUTH_CHICKEN2
);
6478 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
6479 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6481 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
6482 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
6483 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
6486 /* WaMPhyProgramming:hsw */
6487 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
6491 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
6492 tmp
&= ~(0xFF << 24);
6493 tmp
|= (0x12 << 24);
6494 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
6496 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
6498 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
6500 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
6502 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
6504 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
6505 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6506 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
6508 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
6509 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6510 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
6512 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
6515 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
6517 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
6520 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
6522 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
6525 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
6527 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
6530 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
6532 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
6533 tmp
&= ~(0xFF << 16);
6534 tmp
|= (0x1C << 16);
6535 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
6537 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
6538 tmp
&= ~(0xFF << 16);
6539 tmp
|= (0x1C << 16);
6540 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
6542 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
6544 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
6546 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
6548 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
6550 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
6551 tmp
&= ~(0xF << 28);
6553 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
6555 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
6556 tmp
&= ~(0xF << 28);
6558 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
6561 /* Implements 3 different sequences from BSpec chapter "Display iCLK
6562 * Programming" based on the parameters passed:
6563 * - Sequence to enable CLKOUT_DP
6564 * - Sequence to enable CLKOUT_DP without spread
6565 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
6567 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
6570 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6573 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
6575 if (WARN(dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
&&
6576 with_fdi
, "LP PCH doesn't have FDI\n"))
6579 mutex_lock(&dev_priv
->dpio_lock
);
6581 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6582 tmp
&= ~SBI_SSCCTL_DISABLE
;
6583 tmp
|= SBI_SSCCTL_PATHALT
;
6584 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6589 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6590 tmp
&= ~SBI_SSCCTL_PATHALT
;
6591 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6594 lpt_reset_fdi_mphy(dev_priv
);
6595 lpt_program_fdi_mphy(dev_priv
);
6599 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6600 SBI_GEN0
: SBI_DBUFF0
;
6601 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6602 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6603 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6605 mutex_unlock(&dev_priv
->dpio_lock
);
6608 /* Sequence to disable CLKOUT_DP */
6609 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
6611 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6614 mutex_lock(&dev_priv
->dpio_lock
);
6616 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6617 SBI_GEN0
: SBI_DBUFF0
;
6618 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6619 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6620 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6622 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6623 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
6624 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
6625 tmp
|= SBI_SSCCTL_PATHALT
;
6626 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6629 tmp
|= SBI_SSCCTL_DISABLE
;
6630 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6633 mutex_unlock(&dev_priv
->dpio_lock
);
6636 static void lpt_init_pch_refclk(struct drm_device
*dev
)
6638 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
6639 struct intel_encoder
*encoder
;
6640 bool has_vga
= false;
6642 list_for_each_entry(encoder
, &mode_config
->encoder_list
, base
.head
) {
6643 switch (encoder
->type
) {
6644 case INTEL_OUTPUT_ANALOG
:
6651 lpt_enable_clkout_dp(dev
, true, true);
6653 lpt_disable_clkout_dp(dev
);
6657 * Initialize reference clocks when the driver loads
6659 void intel_init_pch_refclk(struct drm_device
*dev
)
6661 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
6662 ironlake_init_pch_refclk(dev
);
6663 else if (HAS_PCH_LPT(dev
))
6664 lpt_init_pch_refclk(dev
);
6667 static int ironlake_get_refclk(struct drm_crtc
*crtc
)
6669 struct drm_device
*dev
= crtc
->dev
;
6670 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6671 struct intel_encoder
*encoder
;
6672 int num_connectors
= 0;
6673 bool is_lvds
= false;
6675 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
6676 switch (encoder
->type
) {
6677 case INTEL_OUTPUT_LVDS
:
6684 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
6685 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
6686 dev_priv
->vbt
.lvds_ssc_freq
);
6687 return dev_priv
->vbt
.lvds_ssc_freq
;
6693 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
6695 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
6696 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6697 int pipe
= intel_crtc
->pipe
;
6702 switch (intel_crtc
->config
.pipe_bpp
) {
6704 val
|= PIPECONF_6BPC
;
6707 val
|= PIPECONF_8BPC
;
6710 val
|= PIPECONF_10BPC
;
6713 val
|= PIPECONF_12BPC
;
6716 /* Case prevented by intel_choose_pipe_bpp_dither. */
6720 if (intel_crtc
->config
.dither
)
6721 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
6723 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
6724 val
|= PIPECONF_INTERLACED_ILK
;
6726 val
|= PIPECONF_PROGRESSIVE
;
6728 if (intel_crtc
->config
.limited_color_range
)
6729 val
|= PIPECONF_COLOR_RANGE_SELECT
;
6731 I915_WRITE(PIPECONF(pipe
), val
);
6732 POSTING_READ(PIPECONF(pipe
));
6736 * Set up the pipe CSC unit.
6738 * Currently only full range RGB to limited range RGB conversion
6739 * is supported, but eventually this should handle various
6740 * RGB<->YCbCr scenarios as well.
6742 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
6744 struct drm_device
*dev
= crtc
->dev
;
6745 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6746 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6747 int pipe
= intel_crtc
->pipe
;
6748 uint16_t coeff
= 0x7800; /* 1.0 */
6751 * TODO: Check what kind of values actually come out of the pipe
6752 * with these coeff/postoff values and adjust to get the best
6753 * accuracy. Perhaps we even need to take the bpc value into
6757 if (intel_crtc
->config
.limited_color_range
)
6758 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
6761 * GY/GU and RY/RU should be the other way around according
6762 * to BSpec, but reality doesn't agree. Just set them up in
6763 * a way that results in the correct picture.
6765 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
6766 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
6768 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
6769 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
6771 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
6772 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
6774 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
6775 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
6776 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
6778 if (INTEL_INFO(dev
)->gen
> 6) {
6779 uint16_t postoff
= 0;
6781 if (intel_crtc
->config
.limited_color_range
)
6782 postoff
= (16 * (1 << 12) / 255) & 0x1fff;
6784 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
6785 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
6786 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
6788 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
6790 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
6792 if (intel_crtc
->config
.limited_color_range
)
6793 mode
|= CSC_BLACK_SCREEN_OFFSET
;
6795 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
6799 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
6801 struct drm_device
*dev
= crtc
->dev
;
6802 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6803 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6804 enum pipe pipe
= intel_crtc
->pipe
;
6805 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
6810 if (IS_HASWELL(dev
) && intel_crtc
->config
.dither
)
6811 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
6813 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
6814 val
|= PIPECONF_INTERLACED_ILK
;
6816 val
|= PIPECONF_PROGRESSIVE
;
6818 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
6819 POSTING_READ(PIPECONF(cpu_transcoder
));
6821 I915_WRITE(GAMMA_MODE(intel_crtc
->pipe
), GAMMA_MODE_MODE_8BIT
);
6822 POSTING_READ(GAMMA_MODE(intel_crtc
->pipe
));
6824 if (IS_BROADWELL(dev
)) {
6827 switch (intel_crtc
->config
.pipe_bpp
) {
6829 val
|= PIPEMISC_DITHER_6_BPC
;
6832 val
|= PIPEMISC_DITHER_8_BPC
;
6835 val
|= PIPEMISC_DITHER_10_BPC
;
6838 val
|= PIPEMISC_DITHER_12_BPC
;
6841 /* Case prevented by pipe_config_set_bpp. */
6845 if (intel_crtc
->config
.dither
)
6846 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
6848 I915_WRITE(PIPEMISC(pipe
), val
);
6852 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
6853 intel_clock_t
*clock
,
6854 bool *has_reduced_clock
,
6855 intel_clock_t
*reduced_clock
)
6857 struct drm_device
*dev
= crtc
->dev
;
6858 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6859 struct intel_encoder
*intel_encoder
;
6861 const intel_limit_t
*limit
;
6862 bool ret
, is_lvds
= false;
6864 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
6865 switch (intel_encoder
->type
) {
6866 case INTEL_OUTPUT_LVDS
:
6872 refclk
= ironlake_get_refclk(crtc
);
6875 * Returns a set of divisors for the desired target clock with the given
6876 * refclk, or FALSE. The returned values represent the clock equation:
6877 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
6879 limit
= intel_limit(crtc
, refclk
);
6880 ret
= dev_priv
->display
.find_dpll(limit
, crtc
,
6881 to_intel_crtc(crtc
)->config
.port_clock
,
6882 refclk
, NULL
, clock
);
6886 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
6888 * Ensure we match the reduced clock's P to the target clock.
6889 * If the clocks don't match, we can't switch the display clock
6890 * by using the FP0/FP1. In such case we will disable the LVDS
6891 * downclock feature.
6893 *has_reduced_clock
=
6894 dev_priv
->display
.find_dpll(limit
, crtc
,
6895 dev_priv
->lvds_downclock
,
6903 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
6906 * Account for spread spectrum to avoid
6907 * oversubscribing the link. Max center spread
6908 * is 2.5%; use 5% for safety's sake.
6910 u32 bps
= target_clock
* bpp
* 21 / 20;
6911 return DIV_ROUND_UP(bps
, link_bw
* 8);
6914 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
6916 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
6919 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
6921 intel_clock_t
*reduced_clock
, u32
*fp2
)
6923 struct drm_crtc
*crtc
= &intel_crtc
->base
;
6924 struct drm_device
*dev
= crtc
->dev
;
6925 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6926 struct intel_encoder
*intel_encoder
;
6928 int factor
, num_connectors
= 0;
6929 bool is_lvds
= false, is_sdvo
= false;
6931 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
6932 switch (intel_encoder
->type
) {
6933 case INTEL_OUTPUT_LVDS
:
6936 case INTEL_OUTPUT_SDVO
:
6937 case INTEL_OUTPUT_HDMI
:
6945 /* Enable autotuning of the PLL clock (if permissible) */
6948 if ((intel_panel_use_ssc(dev_priv
) &&
6949 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
6950 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
6952 } else if (intel_crtc
->config
.sdvo_tv_clock
)
6955 if (ironlake_needs_fb_cb_tune(&intel_crtc
->config
.dpll
, factor
))
6958 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
6964 dpll
|= DPLLB_MODE_LVDS
;
6966 dpll
|= DPLLB_MODE_DAC_SERIAL
;
6968 dpll
|= (intel_crtc
->config
.pixel_multiplier
- 1)
6969 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
6972 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6973 if (intel_crtc
->config
.has_dp_encoder
)
6974 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6976 /* compute bitmask from p1 value */
6977 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6979 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
6981 switch (intel_crtc
->config
.dpll
.p2
) {
6983 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
6986 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
6989 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
6992 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
6996 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
6997 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6999 dpll
|= PLL_REF_INPUT_DREFCLK
;
7001 return dpll
| DPLL_VCO_ENABLE
;
7004 static int ironlake_crtc_mode_set(struct drm_crtc
*crtc
,
7006 struct drm_framebuffer
*fb
)
7008 struct drm_device
*dev
= crtc
->dev
;
7009 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7010 int num_connectors
= 0;
7011 intel_clock_t clock
, reduced_clock
;
7012 u32 dpll
= 0, fp
= 0, fp2
= 0;
7013 bool ok
, has_reduced_clock
= false;
7014 bool is_lvds
= false;
7015 struct intel_encoder
*encoder
;
7016 struct intel_shared_dpll
*pll
;
7018 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
7019 switch (encoder
->type
) {
7020 case INTEL_OUTPUT_LVDS
:
7028 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
7029 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
7031 ok
= ironlake_compute_clocks(crtc
, &clock
,
7032 &has_reduced_clock
, &reduced_clock
);
7033 if (!ok
&& !intel_crtc
->config
.clock_set
) {
7034 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7037 /* Compat-code for transition, will disappear. */
7038 if (!intel_crtc
->config
.clock_set
) {
7039 intel_crtc
->config
.dpll
.n
= clock
.n
;
7040 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
7041 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
7042 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
7043 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
7046 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
7047 if (intel_crtc
->config
.has_pch_encoder
) {
7048 fp
= i9xx_dpll_compute_fp(&intel_crtc
->config
.dpll
);
7049 if (has_reduced_clock
)
7050 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
7052 dpll
= ironlake_compute_dpll(intel_crtc
,
7053 &fp
, &reduced_clock
,
7054 has_reduced_clock
? &fp2
: NULL
);
7056 intel_crtc
->config
.dpll_hw_state
.dpll
= dpll
;
7057 intel_crtc
->config
.dpll_hw_state
.fp0
= fp
;
7058 if (has_reduced_clock
)
7059 intel_crtc
->config
.dpll_hw_state
.fp1
= fp2
;
7061 intel_crtc
->config
.dpll_hw_state
.fp1
= fp
;
7063 pll
= intel_get_shared_dpll(intel_crtc
);
7065 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
7066 pipe_name(intel_crtc
->pipe
));
7070 intel_put_shared_dpll(intel_crtc
);
7072 if (is_lvds
&& has_reduced_clock
&& i915
.powersave
)
7073 intel_crtc
->lowfreq_avail
= true;
7075 intel_crtc
->lowfreq_avail
= false;
7080 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
7081 struct intel_link_m_n
*m_n
)
7083 struct drm_device
*dev
= crtc
->base
.dev
;
7084 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7085 enum pipe pipe
= crtc
->pipe
;
7087 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
7088 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
7089 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
7091 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
7092 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
7093 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7096 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
7097 enum transcoder transcoder
,
7098 struct intel_link_m_n
*m_n
)
7100 struct drm_device
*dev
= crtc
->base
.dev
;
7101 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7102 enum pipe pipe
= crtc
->pipe
;
7104 if (INTEL_INFO(dev
)->gen
>= 5) {
7105 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
7106 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
7107 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
7109 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
7110 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
7111 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7113 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
7114 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
7115 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
7117 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
7118 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
7119 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7123 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
7124 struct intel_crtc_config
*pipe_config
)
7126 if (crtc
->config
.has_pch_encoder
)
7127 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
7129 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7130 &pipe_config
->dp_m_n
);
7133 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
7134 struct intel_crtc_config
*pipe_config
)
7136 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7137 &pipe_config
->fdi_m_n
);
7140 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
7141 struct intel_crtc_config
*pipe_config
)
7143 struct drm_device
*dev
= crtc
->base
.dev
;
7144 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7147 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
7149 if (tmp
& PF_ENABLE
) {
7150 pipe_config
->pch_pfit
.enabled
= true;
7151 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
7152 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
7154 /* We currently do not free assignements of panel fitters on
7155 * ivb/hsw (since we don't use the higher upscaling modes which
7156 * differentiates them) so just WARN about this case for now. */
7158 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
7159 PF_PIPE_SEL_IVB(crtc
->pipe
));
7164 static void ironlake_get_plane_config(struct intel_crtc
*crtc
,
7165 struct intel_plane_config
*plane_config
)
7167 struct drm_device
*dev
= crtc
->base
.dev
;
7168 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7169 u32 val
, base
, offset
;
7170 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7171 int fourcc
, pixel_format
;
7174 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
7175 if (!crtc
->base
.primary
->fb
) {
7176 DRM_DEBUG_KMS("failed to alloc fb\n");
7180 val
= I915_READ(DSPCNTR(plane
));
7182 if (INTEL_INFO(dev
)->gen
>= 4)
7183 if (val
& DISPPLANE_TILED
)
7184 plane_config
->tiled
= true;
7186 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7187 fourcc
= intel_format_to_fourcc(pixel_format
);
7188 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
7189 crtc
->base
.primary
->fb
->bits_per_pixel
=
7190 drm_format_plane_cpp(fourcc
, 0) * 8;
7192 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7193 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
7194 offset
= I915_READ(DSPOFFSET(plane
));
7196 if (plane_config
->tiled
)
7197 offset
= I915_READ(DSPTILEOFF(plane
));
7199 offset
= I915_READ(DSPLINOFF(plane
));
7201 plane_config
->base
= base
;
7203 val
= I915_READ(PIPESRC(pipe
));
7204 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
7205 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
7207 val
= I915_READ(DSPSTRIDE(pipe
));
7208 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffff80;
7210 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
7211 plane_config
->tiled
);
7213 plane_config
->size
= ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
7214 aligned_height
, PAGE_SIZE
);
7216 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7217 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
7218 crtc
->base
.primary
->fb
->height
,
7219 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
7220 crtc
->base
.primary
->fb
->pitches
[0],
7221 plane_config
->size
);
7224 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
7225 struct intel_crtc_config
*pipe_config
)
7227 struct drm_device
*dev
= crtc
->base
.dev
;
7228 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7231 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7232 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7234 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7235 if (!(tmp
& PIPECONF_ENABLE
))
7238 switch (tmp
& PIPECONF_BPC_MASK
) {
7240 pipe_config
->pipe_bpp
= 18;
7243 pipe_config
->pipe_bpp
= 24;
7245 case PIPECONF_10BPC
:
7246 pipe_config
->pipe_bpp
= 30;
7248 case PIPECONF_12BPC
:
7249 pipe_config
->pipe_bpp
= 36;
7255 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
7256 pipe_config
->limited_color_range
= true;
7258 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
7259 struct intel_shared_dpll
*pll
;
7261 pipe_config
->has_pch_encoder
= true;
7263 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
7264 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7265 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7267 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7269 if (HAS_PCH_IBX(dev_priv
->dev
)) {
7270 pipe_config
->shared_dpll
=
7271 (enum intel_dpll_id
) crtc
->pipe
;
7273 tmp
= I915_READ(PCH_DPLL_SEL
);
7274 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
7275 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_B
;
7277 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_A
;
7280 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
7282 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
7283 &pipe_config
->dpll_hw_state
));
7285 tmp
= pipe_config
->dpll_hw_state
.dpll
;
7286 pipe_config
->pixel_multiplier
=
7287 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
7288 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
7290 ironlake_pch_clock_get(crtc
, pipe_config
);
7292 pipe_config
->pixel_multiplier
= 1;
7295 intel_get_pipe_timings(crtc
, pipe_config
);
7297 ironlake_get_pfit_config(crtc
, pipe_config
);
7302 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
7304 struct drm_device
*dev
= dev_priv
->dev
;
7305 struct intel_ddi_plls
*plls
= &dev_priv
->ddi_plls
;
7306 struct intel_crtc
*crtc
;
7308 for_each_intel_crtc(dev
, crtc
)
7309 WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
7310 pipe_name(crtc
->pipe
));
7312 WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
7313 WARN(plls
->spll_refcount
, "SPLL enabled\n");
7314 WARN(plls
->wrpll1_refcount
, "WRPLL1 enabled\n");
7315 WARN(plls
->wrpll2_refcount
, "WRPLL2 enabled\n");
7316 WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
7317 WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
7318 "CPU PWM1 enabled\n");
7319 WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
7320 "CPU PWM2 enabled\n");
7321 WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
7322 "PCH PWM1 enabled\n");
7323 WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
7324 "Utility pin enabled\n");
7325 WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
7328 * In theory we can still leave IRQs enabled, as long as only the HPD
7329 * interrupts remain enabled. We used to check for that, but since it's
7330 * gen-specific and since we only disable LCPLL after we fully disable
7331 * the interrupts, the check below should be enough.
7333 WARN(!dev_priv
->pm
.irqs_disabled
, "IRQs enabled\n");
7336 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
7338 struct drm_device
*dev
= dev_priv
->dev
;
7340 if (IS_HASWELL(dev
)) {
7341 mutex_lock(&dev_priv
->rps
.hw_lock
);
7342 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
7344 DRM_ERROR("Failed to disable D_COMP\n");
7345 mutex_unlock(&dev_priv
->rps
.hw_lock
);
7347 I915_WRITE(D_COMP
, val
);
7349 POSTING_READ(D_COMP
);
7353 * This function implements pieces of two sequences from BSpec:
7354 * - Sequence for display software to disable LCPLL
7355 * - Sequence for display software to allow package C8+
7356 * The steps implemented here are just the steps that actually touch the LCPLL
7357 * register. Callers should take care of disabling all the display engine
7358 * functions, doing the mode unset, fixing interrupts, etc.
7360 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
7361 bool switch_to_fclk
, bool allow_power_down
)
7365 assert_can_disable_lcpll(dev_priv
);
7367 val
= I915_READ(LCPLL_CTL
);
7369 if (switch_to_fclk
) {
7370 val
|= LCPLL_CD_SOURCE_FCLK
;
7371 I915_WRITE(LCPLL_CTL
, val
);
7373 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
7374 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
7375 DRM_ERROR("Switching to FCLK failed\n");
7377 val
= I915_READ(LCPLL_CTL
);
7380 val
|= LCPLL_PLL_DISABLE
;
7381 I915_WRITE(LCPLL_CTL
, val
);
7382 POSTING_READ(LCPLL_CTL
);
7384 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
7385 DRM_ERROR("LCPLL still locked\n");
7387 val
= I915_READ(D_COMP
);
7388 val
|= D_COMP_COMP_DISABLE
;
7389 hsw_write_dcomp(dev_priv
, val
);
7392 if (wait_for((I915_READ(D_COMP
) & D_COMP_RCOMP_IN_PROGRESS
) == 0, 1))
7393 DRM_ERROR("D_COMP RCOMP still in progress\n");
7395 if (allow_power_down
) {
7396 val
= I915_READ(LCPLL_CTL
);
7397 val
|= LCPLL_POWER_DOWN_ALLOW
;
7398 I915_WRITE(LCPLL_CTL
, val
);
7399 POSTING_READ(LCPLL_CTL
);
7404 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
7407 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
7410 unsigned long irqflags
;
7412 val
= I915_READ(LCPLL_CTL
);
7414 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
7415 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
7419 * Make sure we're not on PC8 state before disabling PC8, otherwise
7420 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
7422 * The other problem is that hsw_restore_lcpll() is called as part of
7423 * the runtime PM resume sequence, so we can't just call
7424 * gen6_gt_force_wake_get() because that function calls
7425 * intel_runtime_pm_get(), and we can't change the runtime PM refcount
7426 * while we are on the resume sequence. So to solve this problem we have
7427 * to call special forcewake code that doesn't touch runtime PM and
7428 * doesn't enable the forcewake delayed work.
7430 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
7431 if (dev_priv
->uncore
.forcewake_count
++ == 0)
7432 dev_priv
->uncore
.funcs
.force_wake_get(dev_priv
, FORCEWAKE_ALL
);
7433 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
7435 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
7436 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
7437 I915_WRITE(LCPLL_CTL
, val
);
7438 POSTING_READ(LCPLL_CTL
);
7441 val
= I915_READ(D_COMP
);
7442 val
|= D_COMP_COMP_FORCE
;
7443 val
&= ~D_COMP_COMP_DISABLE
;
7444 hsw_write_dcomp(dev_priv
, val
);
7446 val
= I915_READ(LCPLL_CTL
);
7447 val
&= ~LCPLL_PLL_DISABLE
;
7448 I915_WRITE(LCPLL_CTL
, val
);
7450 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
7451 DRM_ERROR("LCPLL not locked yet\n");
7453 if (val
& LCPLL_CD_SOURCE_FCLK
) {
7454 val
= I915_READ(LCPLL_CTL
);
7455 val
&= ~LCPLL_CD_SOURCE_FCLK
;
7456 I915_WRITE(LCPLL_CTL
, val
);
7458 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
7459 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
7460 DRM_ERROR("Switching back to LCPLL failed\n");
7463 /* See the big comment above. */
7464 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
7465 if (--dev_priv
->uncore
.forcewake_count
== 0)
7466 dev_priv
->uncore
.funcs
.force_wake_put(dev_priv
, FORCEWAKE_ALL
);
7467 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
7471 * Package states C8 and deeper are really deep PC states that can only be
7472 * reached when all the devices on the system allow it, so even if the graphics
7473 * device allows PC8+, it doesn't mean the system will actually get to these
7474 * states. Our driver only allows PC8+ when going into runtime PM.
7476 * The requirements for PC8+ are that all the outputs are disabled, the power
7477 * well is disabled and most interrupts are disabled, and these are also
7478 * requirements for runtime PM. When these conditions are met, we manually do
7479 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
7480 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
7483 * When we really reach PC8 or deeper states (not just when we allow it) we lose
7484 * the state of some registers, so when we come back from PC8+ we need to
7485 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
7486 * need to take care of the registers kept by RC6. Notice that this happens even
7487 * if we don't put the device in PCI D3 state (which is what currently happens
7488 * because of the runtime PM support).
7490 * For more, read "Display Sequences for Package C8" on the hardware
7493 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
7495 struct drm_device
*dev
= dev_priv
->dev
;
7498 DRM_DEBUG_KMS("Enabling package C8+\n");
7500 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7501 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7502 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
7503 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7506 lpt_disable_clkout_dp(dev
);
7507 hsw_disable_lcpll(dev_priv
, true, true);
7510 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
7512 struct drm_device
*dev
= dev_priv
->dev
;
7515 DRM_DEBUG_KMS("Disabling package C8+\n");
7517 hsw_restore_lcpll(dev_priv
);
7518 lpt_init_pch_refclk(dev
);
7520 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7521 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7522 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
7523 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7526 intel_prepare_ddi(dev
);
7529 static void snb_modeset_global_resources(struct drm_device
*dev
)
7531 modeset_update_crtc_power_domains(dev
);
7534 static void haswell_modeset_global_resources(struct drm_device
*dev
)
7536 modeset_update_crtc_power_domains(dev
);
7539 static int haswell_crtc_mode_set(struct drm_crtc
*crtc
,
7541 struct drm_framebuffer
*fb
)
7543 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7545 if (!intel_ddi_pll_select(intel_crtc
))
7547 intel_ddi_pll_enable(intel_crtc
);
7549 intel_crtc
->lowfreq_avail
= false;
7554 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
7555 struct intel_crtc_config
*pipe_config
)
7557 struct drm_device
*dev
= crtc
->base
.dev
;
7558 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7559 enum intel_display_power_domain pfit_domain
;
7562 if (!intel_display_power_enabled(dev_priv
,
7563 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7566 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7567 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7569 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
7570 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
7571 enum pipe trans_edp_pipe
;
7572 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
7574 WARN(1, "unknown pipe linked to edp transcoder\n");
7575 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
7576 case TRANS_DDI_EDP_INPUT_A_ON
:
7577 trans_edp_pipe
= PIPE_A
;
7579 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
7580 trans_edp_pipe
= PIPE_B
;
7582 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
7583 trans_edp_pipe
= PIPE_C
;
7587 if (trans_edp_pipe
== crtc
->pipe
)
7588 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
7591 if (!intel_display_power_enabled(dev_priv
,
7592 POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
)))
7595 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
7596 if (!(tmp
& PIPECONF_ENABLE
))
7600 * Haswell has only FDI/PCH transcoder A. It is which is connected to
7601 * DDI E. So just check whether this pipe is wired to DDI E and whether
7602 * the PCH transcoder is on.
7604 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
7605 if ((tmp
& TRANS_DDI_PORT_MASK
) == TRANS_DDI_SELECT_PORT(PORT_E
) &&
7606 I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
7607 pipe_config
->has_pch_encoder
= true;
7609 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
7610 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7611 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7613 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7616 intel_get_pipe_timings(crtc
, pipe_config
);
7618 pfit_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
7619 if (intel_display_power_enabled(dev_priv
, pfit_domain
))
7620 ironlake_get_pfit_config(crtc
, pipe_config
);
7622 if (IS_HASWELL(dev
))
7623 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
7624 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
7626 pipe_config
->pixel_multiplier
= 1;
7634 } hdmi_audio_clock
[] = {
7635 { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175
},
7636 { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200
}, /* default per bspec */
7637 { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000
},
7638 { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027
},
7639 { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000
},
7640 { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054
},
7641 { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176
},
7642 { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250
},
7643 { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352
},
7644 { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500
},
7647 /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
7648 static u32
audio_config_hdmi_pixel_clock(struct drm_display_mode
*mode
)
7652 for (i
= 0; i
< ARRAY_SIZE(hdmi_audio_clock
); i
++) {
7653 if (mode
->clock
== hdmi_audio_clock
[i
].clock
)
7657 if (i
== ARRAY_SIZE(hdmi_audio_clock
)) {
7658 DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode
->clock
);
7662 DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
7663 hdmi_audio_clock
[i
].clock
,
7664 hdmi_audio_clock
[i
].config
);
7666 return hdmi_audio_clock
[i
].config
;
7669 static bool intel_eld_uptodate(struct drm_connector
*connector
,
7670 int reg_eldv
, uint32_t bits_eldv
,
7671 int reg_elda
, uint32_t bits_elda
,
7674 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7675 uint8_t *eld
= connector
->eld
;
7678 i
= I915_READ(reg_eldv
);
7687 i
= I915_READ(reg_elda
);
7689 I915_WRITE(reg_elda
, i
);
7691 for (i
= 0; i
< eld
[2]; i
++)
7692 if (I915_READ(reg_edid
) != *((uint32_t *)eld
+ i
))
7698 static void g4x_write_eld(struct drm_connector
*connector
,
7699 struct drm_crtc
*crtc
,
7700 struct drm_display_mode
*mode
)
7702 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7703 uint8_t *eld
= connector
->eld
;
7708 i
= I915_READ(G4X_AUD_VID_DID
);
7710 if (i
== INTEL_AUDIO_DEVBLC
|| i
== INTEL_AUDIO_DEVCL
)
7711 eldv
= G4X_ELDV_DEVCL_DEVBLC
;
7713 eldv
= G4X_ELDV_DEVCTG
;
7715 if (intel_eld_uptodate(connector
,
7716 G4X_AUD_CNTL_ST
, eldv
,
7717 G4X_AUD_CNTL_ST
, G4X_ELD_ADDR
,
7718 G4X_HDMIW_HDMIEDID
))
7721 i
= I915_READ(G4X_AUD_CNTL_ST
);
7722 i
&= ~(eldv
| G4X_ELD_ADDR
);
7723 len
= (i
>> 9) & 0x1f; /* ELD buffer size */
7724 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
7729 len
= min_t(uint8_t, eld
[2], len
);
7730 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7731 for (i
= 0; i
< len
; i
++)
7732 I915_WRITE(G4X_HDMIW_HDMIEDID
, *((uint32_t *)eld
+ i
));
7734 i
= I915_READ(G4X_AUD_CNTL_ST
);
7736 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
7739 static void haswell_write_eld(struct drm_connector
*connector
,
7740 struct drm_crtc
*crtc
,
7741 struct drm_display_mode
*mode
)
7743 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7744 uint8_t *eld
= connector
->eld
;
7748 int pipe
= to_intel_crtc(crtc
)->pipe
;
7751 int hdmiw_hdmiedid
= HSW_AUD_EDID_DATA(pipe
);
7752 int aud_cntl_st
= HSW_AUD_DIP_ELD_CTRL(pipe
);
7753 int aud_config
= HSW_AUD_CFG(pipe
);
7754 int aud_cntrl_st2
= HSW_AUD_PIN_ELD_CP_VLD
;
7756 /* Audio output enable */
7757 DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
7758 tmp
= I915_READ(aud_cntrl_st2
);
7759 tmp
|= (AUDIO_OUTPUT_ENABLE_A
<< (pipe
* 4));
7760 I915_WRITE(aud_cntrl_st2
, tmp
);
7761 POSTING_READ(aud_cntrl_st2
);
7763 assert_pipe_disabled(dev_priv
, to_intel_crtc(crtc
)->pipe
);
7765 /* Set ELD valid state */
7766 tmp
= I915_READ(aud_cntrl_st2
);
7767 DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp
);
7768 tmp
|= (AUDIO_ELD_VALID_A
<< (pipe
* 4));
7769 I915_WRITE(aud_cntrl_st2
, tmp
);
7770 tmp
= I915_READ(aud_cntrl_st2
);
7771 DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp
);
7773 /* Enable HDMI mode */
7774 tmp
= I915_READ(aud_config
);
7775 DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp
);
7776 /* clear N_programing_enable and N_value_index */
7777 tmp
&= ~(AUD_CONFIG_N_VALUE_INDEX
| AUD_CONFIG_N_PROG_ENABLE
);
7778 I915_WRITE(aud_config
, tmp
);
7780 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
7782 eldv
= AUDIO_ELD_VALID_A
<< (pipe
* 4);
7784 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
7785 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
7786 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
7787 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
7789 I915_WRITE(aud_config
, audio_config_hdmi_pixel_clock(mode
));
7792 if (intel_eld_uptodate(connector
,
7793 aud_cntrl_st2
, eldv
,
7794 aud_cntl_st
, IBX_ELD_ADDRESS
,
7798 i
= I915_READ(aud_cntrl_st2
);
7800 I915_WRITE(aud_cntrl_st2
, i
);
7805 i
= I915_READ(aud_cntl_st
);
7806 i
&= ~IBX_ELD_ADDRESS
;
7807 I915_WRITE(aud_cntl_st
, i
);
7808 i
= (i
>> 29) & DIP_PORT_SEL_MASK
; /* DIP_Port_Select, 0x1 = PortB */
7809 DRM_DEBUG_DRIVER("port num:%d\n", i
);
7811 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
7812 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7813 for (i
= 0; i
< len
; i
++)
7814 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
7816 i
= I915_READ(aud_cntrl_st2
);
7818 I915_WRITE(aud_cntrl_st2
, i
);
7822 static void ironlake_write_eld(struct drm_connector
*connector
,
7823 struct drm_crtc
*crtc
,
7824 struct drm_display_mode
*mode
)
7826 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7827 uint8_t *eld
= connector
->eld
;
7835 int pipe
= to_intel_crtc(crtc
)->pipe
;
7837 if (HAS_PCH_IBX(connector
->dev
)) {
7838 hdmiw_hdmiedid
= IBX_HDMIW_HDMIEDID(pipe
);
7839 aud_config
= IBX_AUD_CFG(pipe
);
7840 aud_cntl_st
= IBX_AUD_CNTL_ST(pipe
);
7841 aud_cntrl_st2
= IBX_AUD_CNTL_ST2
;
7842 } else if (IS_VALLEYVIEW(connector
->dev
)) {
7843 hdmiw_hdmiedid
= VLV_HDMIW_HDMIEDID(pipe
);
7844 aud_config
= VLV_AUD_CFG(pipe
);
7845 aud_cntl_st
= VLV_AUD_CNTL_ST(pipe
);
7846 aud_cntrl_st2
= VLV_AUD_CNTL_ST2
;
7848 hdmiw_hdmiedid
= CPT_HDMIW_HDMIEDID(pipe
);
7849 aud_config
= CPT_AUD_CFG(pipe
);
7850 aud_cntl_st
= CPT_AUD_CNTL_ST(pipe
);
7851 aud_cntrl_st2
= CPT_AUD_CNTRL_ST2
;
7854 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
7856 if (IS_VALLEYVIEW(connector
->dev
)) {
7857 struct intel_encoder
*intel_encoder
;
7858 struct intel_digital_port
*intel_dig_port
;
7860 intel_encoder
= intel_attached_encoder(connector
);
7861 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
7862 i
= intel_dig_port
->port
;
7864 i
= I915_READ(aud_cntl_st
);
7865 i
= (i
>> 29) & DIP_PORT_SEL_MASK
;
7866 /* DIP_Port_Select, 0x1 = PortB */
7870 DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
7871 /* operate blindly on all ports */
7872 eldv
= IBX_ELD_VALIDB
;
7873 eldv
|= IBX_ELD_VALIDB
<< 4;
7874 eldv
|= IBX_ELD_VALIDB
<< 8;
7876 DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i
));
7877 eldv
= IBX_ELD_VALIDB
<< ((i
- 1) * 4);
7880 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
7881 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
7882 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
7883 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
7885 I915_WRITE(aud_config
, audio_config_hdmi_pixel_clock(mode
));
7888 if (intel_eld_uptodate(connector
,
7889 aud_cntrl_st2
, eldv
,
7890 aud_cntl_st
, IBX_ELD_ADDRESS
,
7894 i
= I915_READ(aud_cntrl_st2
);
7896 I915_WRITE(aud_cntrl_st2
, i
);
7901 i
= I915_READ(aud_cntl_st
);
7902 i
&= ~IBX_ELD_ADDRESS
;
7903 I915_WRITE(aud_cntl_st
, i
);
7905 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
7906 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7907 for (i
= 0; i
< len
; i
++)
7908 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
7910 i
= I915_READ(aud_cntrl_st2
);
7912 I915_WRITE(aud_cntrl_st2
, i
);
7915 void intel_write_eld(struct drm_encoder
*encoder
,
7916 struct drm_display_mode
*mode
)
7918 struct drm_crtc
*crtc
= encoder
->crtc
;
7919 struct drm_connector
*connector
;
7920 struct drm_device
*dev
= encoder
->dev
;
7921 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7923 connector
= drm_select_eld(encoder
, mode
);
7927 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
7930 connector
->encoder
->base
.id
,
7931 connector
->encoder
->name
);
7933 connector
->eld
[6] = drm_av_sync_delay(connector
, mode
) / 2;
7935 if (dev_priv
->display
.write_eld
)
7936 dev_priv
->display
.write_eld(connector
, crtc
, mode
);
7939 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
7941 struct drm_device
*dev
= crtc
->dev
;
7942 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7943 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7946 if (base
!= intel_crtc
->cursor_base
) {
7947 /* On these chipsets we can only modify the base whilst
7948 * the cursor is disabled.
7950 if (intel_crtc
->cursor_cntl
) {
7951 I915_WRITE(_CURACNTR
, 0);
7952 POSTING_READ(_CURACNTR
);
7953 intel_crtc
->cursor_cntl
= 0;
7956 I915_WRITE(_CURABASE
, base
);
7957 POSTING_READ(_CURABASE
);
7960 /* XXX width must be 64, stride 256 => 0x00 << 28 */
7963 cntl
= (CURSOR_ENABLE
|
7964 CURSOR_GAMMA_ENABLE
|
7965 CURSOR_FORMAT_ARGB
);
7966 if (intel_crtc
->cursor_cntl
!= cntl
) {
7967 I915_WRITE(_CURACNTR
, cntl
);
7968 POSTING_READ(_CURACNTR
);
7969 intel_crtc
->cursor_cntl
= cntl
;
7973 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
7975 struct drm_device
*dev
= crtc
->dev
;
7976 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7977 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7978 int pipe
= intel_crtc
->pipe
;
7983 cntl
= MCURSOR_GAMMA_ENABLE
;
7984 switch (intel_crtc
->cursor_width
) {
7986 cntl
|= CURSOR_MODE_64_ARGB_AX
;
7989 cntl
|= CURSOR_MODE_128_ARGB_AX
;
7992 cntl
|= CURSOR_MODE_256_ARGB_AX
;
7998 cntl
|= pipe
<< 28; /* Connect to correct pipe */
8000 if (intel_crtc
->cursor_cntl
!= cntl
) {
8001 I915_WRITE(CURCNTR(pipe
), cntl
);
8002 POSTING_READ(CURCNTR(pipe
));
8003 intel_crtc
->cursor_cntl
= cntl
;
8006 /* and commit changes on next vblank */
8007 I915_WRITE(CURBASE(pipe
), base
);
8008 POSTING_READ(CURBASE(pipe
));
8011 static void ivb_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8013 struct drm_device
*dev
= crtc
->dev
;
8014 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8015 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8016 int pipe
= intel_crtc
->pipe
;
8021 cntl
= MCURSOR_GAMMA_ENABLE
;
8022 switch (intel_crtc
->cursor_width
) {
8024 cntl
|= CURSOR_MODE_64_ARGB_AX
;
8027 cntl
|= CURSOR_MODE_128_ARGB_AX
;
8030 cntl
|= CURSOR_MODE_256_ARGB_AX
;
8037 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
8038 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
8040 if (intel_crtc
->cursor_cntl
!= cntl
) {
8041 I915_WRITE(CURCNTR(pipe
), cntl
);
8042 POSTING_READ(CURCNTR(pipe
));
8043 intel_crtc
->cursor_cntl
= cntl
;
8046 /* and commit changes on next vblank */
8047 I915_WRITE(CURBASE(pipe
), base
);
8048 POSTING_READ(CURBASE(pipe
));
8051 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
8052 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
8055 struct drm_device
*dev
= crtc
->dev
;
8056 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8057 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8058 int pipe
= intel_crtc
->pipe
;
8059 int x
= crtc
->cursor_x
;
8060 int y
= crtc
->cursor_y
;
8061 u32 base
= 0, pos
= 0;
8064 base
= intel_crtc
->cursor_addr
;
8066 if (x
>= intel_crtc
->config
.pipe_src_w
)
8069 if (y
>= intel_crtc
->config
.pipe_src_h
)
8073 if (x
+ intel_crtc
->cursor_width
<= 0)
8076 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
8079 pos
|= x
<< CURSOR_X_SHIFT
;
8082 if (y
+ intel_crtc
->cursor_height
<= 0)
8085 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
8088 pos
|= y
<< CURSOR_Y_SHIFT
;
8090 if (base
== 0 && intel_crtc
->cursor_base
== 0)
8093 I915_WRITE(CURPOS(pipe
), pos
);
8095 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
) || IS_BROADWELL(dev
))
8096 ivb_update_cursor(crtc
, base
);
8097 else if (IS_845G(dev
) || IS_I865G(dev
))
8098 i845_update_cursor(crtc
, base
);
8100 i9xx_update_cursor(crtc
, base
);
8101 intel_crtc
->cursor_base
= base
;
8105 * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
8107 * Note that the object's reference will be consumed if the update fails. If
8108 * the update succeeds, the reference of the old object (if any) will be
8111 static int intel_crtc_cursor_set_obj(struct drm_crtc
*crtc
,
8112 struct drm_i915_gem_object
*obj
,
8113 uint32_t width
, uint32_t height
)
8115 struct drm_device
*dev
= crtc
->dev
;
8116 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8117 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8118 enum pipe pipe
= intel_crtc
->pipe
;
8123 /* if we want to turn off the cursor ignore width and height */
8125 DRM_DEBUG_KMS("cursor off\n");
8128 mutex_lock(&dev
->struct_mutex
);
8132 /* Check for which cursor types we support */
8133 if (!((width
== 64 && height
== 64) ||
8134 (width
== 128 && height
== 128 && !IS_GEN2(dev
)) ||
8135 (width
== 256 && height
== 256 && !IS_GEN2(dev
)))) {
8136 DRM_DEBUG("Cursor dimension not supported\n");
8140 if (obj
->base
.size
< width
* height
* 4) {
8141 DRM_DEBUG_KMS("buffer is too small\n");
8146 /* we only need to pin inside GTT if cursor is non-phy */
8147 mutex_lock(&dev
->struct_mutex
);
8148 if (!INTEL_INFO(dev
)->cursor_needs_physical
) {
8151 if (obj
->tiling_mode
) {
8152 DRM_DEBUG_KMS("cursor cannot be tiled\n");
8157 /* Note that the w/a also requires 2 PTE of padding following
8158 * the bo. We currently fill all unused PTE with the shadow
8159 * page and so we should always have valid PTE following the
8160 * cursor preventing the VT-d warning.
8163 if (need_vtd_wa(dev
))
8164 alignment
= 64*1024;
8166 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, NULL
);
8168 DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
8172 ret
= i915_gem_object_put_fence(obj
);
8174 DRM_DEBUG_KMS("failed to release fence for cursor");
8178 addr
= i915_gem_obj_ggtt_offset(obj
);
8180 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
8181 ret
= i915_gem_object_attach_phys(obj
, align
);
8183 DRM_DEBUG_KMS("failed to attach phys object\n");
8186 addr
= obj
->phys_handle
->busaddr
;
8190 I915_WRITE(CURSIZE
, (height
<< 12) | width
);
8193 if (intel_crtc
->cursor_bo
) {
8194 if (!INTEL_INFO(dev
)->cursor_needs_physical
)
8195 i915_gem_object_unpin_from_display_plane(intel_crtc
->cursor_bo
);
8198 i915_gem_track_fb(intel_crtc
->cursor_bo
, obj
,
8199 INTEL_FRONTBUFFER_CURSOR(pipe
));
8200 mutex_unlock(&dev
->struct_mutex
);
8202 old_width
= intel_crtc
->cursor_width
;
8204 intel_crtc
->cursor_addr
= addr
;
8205 intel_crtc
->cursor_bo
= obj
;
8206 intel_crtc
->cursor_width
= width
;
8207 intel_crtc
->cursor_height
= height
;
8209 if (intel_crtc
->active
) {
8210 if (old_width
!= width
)
8211 intel_update_watermarks(crtc
);
8212 intel_crtc_update_cursor(crtc
, intel_crtc
->cursor_bo
!= NULL
);
8217 i915_gem_object_unpin_from_display_plane(obj
);
8219 mutex_unlock(&dev
->struct_mutex
);
8221 drm_gem_object_unreference_unlocked(&obj
->base
);
8225 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
8226 u16
*blue
, uint32_t start
, uint32_t size
)
8228 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
8229 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8231 for (i
= start
; i
< end
; i
++) {
8232 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
8233 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
8234 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
8237 intel_crtc_load_lut(crtc
);
8240 /* VESA 640x480x72Hz mode to set on the pipe */
8241 static struct drm_display_mode load_detect_mode
= {
8242 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
8243 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
8246 struct drm_framebuffer
*
8247 __intel_framebuffer_create(struct drm_device
*dev
,
8248 struct drm_mode_fb_cmd2
*mode_cmd
,
8249 struct drm_i915_gem_object
*obj
)
8251 struct intel_framebuffer
*intel_fb
;
8254 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8256 drm_gem_object_unreference_unlocked(&obj
->base
);
8257 return ERR_PTR(-ENOMEM
);
8260 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
8264 return &intel_fb
->base
;
8266 drm_gem_object_unreference_unlocked(&obj
->base
);
8269 return ERR_PTR(ret
);
8272 static struct drm_framebuffer
*
8273 intel_framebuffer_create(struct drm_device
*dev
,
8274 struct drm_mode_fb_cmd2
*mode_cmd
,
8275 struct drm_i915_gem_object
*obj
)
8277 struct drm_framebuffer
*fb
;
8280 ret
= i915_mutex_lock_interruptible(dev
);
8282 return ERR_PTR(ret
);
8283 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
8284 mutex_unlock(&dev
->struct_mutex
);
8290 intel_framebuffer_pitch_for_width(int width
, int bpp
)
8292 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
8293 return ALIGN(pitch
, 64);
8297 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
8299 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
8300 return ALIGN(pitch
* mode
->vdisplay
, PAGE_SIZE
);
8303 static struct drm_framebuffer
*
8304 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
8305 struct drm_display_mode
*mode
,
8308 struct drm_i915_gem_object
*obj
;
8309 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
8311 obj
= i915_gem_alloc_object(dev
,
8312 intel_framebuffer_size_for_mode(mode
, bpp
));
8314 return ERR_PTR(-ENOMEM
);
8316 mode_cmd
.width
= mode
->hdisplay
;
8317 mode_cmd
.height
= mode
->vdisplay
;
8318 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
8320 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
8322 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
8325 static struct drm_framebuffer
*
8326 mode_fits_in_fbdev(struct drm_device
*dev
,
8327 struct drm_display_mode
*mode
)
8329 #ifdef CONFIG_DRM_I915_FBDEV
8330 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8331 struct drm_i915_gem_object
*obj
;
8332 struct drm_framebuffer
*fb
;
8334 if (!dev_priv
->fbdev
)
8337 if (!dev_priv
->fbdev
->fb
)
8340 obj
= dev_priv
->fbdev
->fb
->obj
;
8343 fb
= &dev_priv
->fbdev
->fb
->base
;
8344 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
8345 fb
->bits_per_pixel
))
8348 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
8357 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
8358 struct drm_display_mode
*mode
,
8359 struct intel_load_detect_pipe
*old
,
8360 struct drm_modeset_acquire_ctx
*ctx
)
8362 struct intel_crtc
*intel_crtc
;
8363 struct intel_encoder
*intel_encoder
=
8364 intel_attached_encoder(connector
);
8365 struct drm_crtc
*possible_crtc
;
8366 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8367 struct drm_crtc
*crtc
= NULL
;
8368 struct drm_device
*dev
= encoder
->dev
;
8369 struct drm_framebuffer
*fb
;
8370 struct drm_mode_config
*config
= &dev
->mode_config
;
8373 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8374 connector
->base
.id
, connector
->name
,
8375 encoder
->base
.id
, encoder
->name
);
8377 drm_modeset_acquire_init(ctx
, 0);
8380 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
8385 * Algorithm gets a little messy:
8387 * - if the connector already has an assigned crtc, use it (but make
8388 * sure it's on first)
8390 * - try to find the first unused crtc that can drive this connector,
8391 * and use that if we find one
8394 /* See if we already have a CRTC for this connector */
8395 if (encoder
->crtc
) {
8396 crtc
= encoder
->crtc
;
8398 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8402 old
->dpms_mode
= connector
->dpms
;
8403 old
->load_detect_temp
= false;
8405 /* Make sure the crtc and connector are running */
8406 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
8407 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
8412 /* Find an unused one (if possible) */
8413 for_each_crtc(dev
, possible_crtc
) {
8415 if (!(encoder
->possible_crtcs
& (1 << i
)))
8417 if (!possible_crtc
->enabled
) {
8418 crtc
= possible_crtc
;
8424 * If we didn't find an unused CRTC, don't use any.
8427 DRM_DEBUG_KMS("no pipe available for load-detect\n");
8431 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8434 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
8435 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
8437 intel_crtc
= to_intel_crtc(crtc
);
8438 intel_crtc
->new_enabled
= true;
8439 intel_crtc
->new_config
= &intel_crtc
->config
;
8440 old
->dpms_mode
= connector
->dpms
;
8441 old
->load_detect_temp
= true;
8442 old
->release_fb
= NULL
;
8445 mode
= &load_detect_mode
;
8447 /* We need a framebuffer large enough to accommodate all accesses
8448 * that the plane may generate whilst we perform load detection.
8449 * We can not rely on the fbcon either being present (we get called
8450 * during its initialisation to detect all boot displays, or it may
8451 * not even exist) or that it is large enough to satisfy the
8454 fb
= mode_fits_in_fbdev(dev
, mode
);
8456 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
8457 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
8458 old
->release_fb
= fb
;
8460 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
8462 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
8466 if (intel_set_mode(crtc
, mode
, 0, 0, fb
)) {
8467 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
8468 if (old
->release_fb
)
8469 old
->release_fb
->funcs
->destroy(old
->release_fb
);
8473 /* let the connector get through one full cycle before testing */
8474 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
8478 intel_crtc
->new_enabled
= crtc
->enabled
;
8479 if (intel_crtc
->new_enabled
)
8480 intel_crtc
->new_config
= &intel_crtc
->config
;
8482 intel_crtc
->new_config
= NULL
;
8484 if (ret
== -EDEADLK
) {
8485 drm_modeset_backoff(ctx
);
8489 drm_modeset_drop_locks(ctx
);
8490 drm_modeset_acquire_fini(ctx
);
8495 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
8496 struct intel_load_detect_pipe
*old
,
8497 struct drm_modeset_acquire_ctx
*ctx
)
8499 struct intel_encoder
*intel_encoder
=
8500 intel_attached_encoder(connector
);
8501 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8502 struct drm_crtc
*crtc
= encoder
->crtc
;
8503 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8505 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8506 connector
->base
.id
, connector
->name
,
8507 encoder
->base
.id
, encoder
->name
);
8509 if (old
->load_detect_temp
) {
8510 to_intel_connector(connector
)->new_encoder
= NULL
;
8511 intel_encoder
->new_crtc
= NULL
;
8512 intel_crtc
->new_enabled
= false;
8513 intel_crtc
->new_config
= NULL
;
8514 intel_set_mode(crtc
, NULL
, 0, 0, NULL
);
8516 if (old
->release_fb
) {
8517 drm_framebuffer_unregister_private(old
->release_fb
);
8518 drm_framebuffer_unreference(old
->release_fb
);
8525 /* Switch crtc and encoder back off if necessary */
8526 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
8527 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
8530 drm_modeset_drop_locks(ctx
);
8531 drm_modeset_acquire_fini(ctx
);
8534 static int i9xx_pll_refclk(struct drm_device
*dev
,
8535 const struct intel_crtc_config
*pipe_config
)
8537 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8538 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8540 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
8541 return dev_priv
->vbt
.lvds_ssc_freq
;
8542 else if (HAS_PCH_SPLIT(dev
))
8544 else if (!IS_GEN2(dev
))
8550 /* Returns the clock of the currently programmed mode of the given pipe. */
8551 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
8552 struct intel_crtc_config
*pipe_config
)
8554 struct drm_device
*dev
= crtc
->base
.dev
;
8555 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8556 int pipe
= pipe_config
->cpu_transcoder
;
8557 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8559 intel_clock_t clock
;
8560 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
8562 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
8563 fp
= pipe_config
->dpll_hw_state
.fp0
;
8565 fp
= pipe_config
->dpll_hw_state
.fp1
;
8567 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
8568 if (IS_PINEVIEW(dev
)) {
8569 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
8570 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8572 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
8573 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8576 if (!IS_GEN2(dev
)) {
8577 if (IS_PINEVIEW(dev
))
8578 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
8579 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
8581 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
8582 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8584 switch (dpll
& DPLL_MODE_MASK
) {
8585 case DPLLB_MODE_DAC_SERIAL
:
8586 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
8589 case DPLLB_MODE_LVDS
:
8590 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
8594 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
8595 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
8599 if (IS_PINEVIEW(dev
))
8600 pineview_clock(refclk
, &clock
);
8602 i9xx_clock(refclk
, &clock
);
8604 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
8605 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
8608 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
8609 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8611 if (lvds
& LVDS_CLKB_POWER_UP
)
8616 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
8619 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
8620 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
8622 if (dpll
& PLL_P2_DIVIDE_BY_4
)
8628 i9xx_clock(refclk
, &clock
);
8632 * This value includes pixel_multiplier. We will use
8633 * port_clock to compute adjusted_mode.crtc_clock in the
8634 * encoder's get_config() function.
8636 pipe_config
->port_clock
= clock
.dot
;
8639 int intel_dotclock_calculate(int link_freq
,
8640 const struct intel_link_m_n
*m_n
)
8643 * The calculation for the data clock is:
8644 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
8645 * But we want to avoid losing precison if possible, so:
8646 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
8648 * and the link clock is simpler:
8649 * link_clock = (m * link_clock) / n
8655 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
8658 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
8659 struct intel_crtc_config
*pipe_config
)
8661 struct drm_device
*dev
= crtc
->base
.dev
;
8663 /* read out port_clock from the DPLL */
8664 i9xx_crtc_clock_get(crtc
, pipe_config
);
8667 * This value does not include pixel_multiplier.
8668 * We will check that port_clock and adjusted_mode.crtc_clock
8669 * agree once we know their relationship in the encoder's
8670 * get_config() function.
8672 pipe_config
->adjusted_mode
.crtc_clock
=
8673 intel_dotclock_calculate(intel_fdi_link_freq(dev
) * 10000,
8674 &pipe_config
->fdi_m_n
);
8677 /** Returns the currently programmed mode of the given pipe. */
8678 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
8679 struct drm_crtc
*crtc
)
8681 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8682 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8683 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
8684 struct drm_display_mode
*mode
;
8685 struct intel_crtc_config pipe_config
;
8686 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
8687 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
8688 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
8689 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
8690 enum pipe pipe
= intel_crtc
->pipe
;
8692 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
8697 * Construct a pipe_config sufficient for getting the clock info
8698 * back out of crtc_clock_get.
8700 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
8701 * to use a real value here instead.
8703 pipe_config
.cpu_transcoder
= (enum transcoder
) pipe
;
8704 pipe_config
.pixel_multiplier
= 1;
8705 pipe_config
.dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
8706 pipe_config
.dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
8707 pipe_config
.dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
8708 i9xx_crtc_clock_get(intel_crtc
, &pipe_config
);
8710 mode
->clock
= pipe_config
.port_clock
/ pipe_config
.pixel_multiplier
;
8711 mode
->hdisplay
= (htot
& 0xffff) + 1;
8712 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
8713 mode
->hsync_start
= (hsync
& 0xffff) + 1;
8714 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
8715 mode
->vdisplay
= (vtot
& 0xffff) + 1;
8716 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
8717 mode
->vsync_start
= (vsync
& 0xffff) + 1;
8718 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
8720 drm_mode_set_name(mode
);
8725 static void intel_increase_pllclock(struct drm_device
*dev
,
8728 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8729 int dpll_reg
= DPLL(pipe
);
8732 if (HAS_PCH_SPLIT(dev
))
8735 if (!dev_priv
->lvds_downclock_avail
)
8738 dpll
= I915_READ(dpll_reg
);
8739 if (!HAS_PIPE_CXSR(dev
) && (dpll
& DISPLAY_RATE_SELECT_FPA1
)) {
8740 DRM_DEBUG_DRIVER("upclocking LVDS\n");
8742 assert_panel_unlocked(dev_priv
, pipe
);
8744 dpll
&= ~DISPLAY_RATE_SELECT_FPA1
;
8745 I915_WRITE(dpll_reg
, dpll
);
8746 intel_wait_for_vblank(dev
, pipe
);
8748 dpll
= I915_READ(dpll_reg
);
8749 if (dpll
& DISPLAY_RATE_SELECT_FPA1
)
8750 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
8754 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
8756 struct drm_device
*dev
= crtc
->dev
;
8757 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8758 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8760 if (HAS_PCH_SPLIT(dev
))
8763 if (!dev_priv
->lvds_downclock_avail
)
8767 * Since this is called by a timer, we should never get here in
8770 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
8771 int pipe
= intel_crtc
->pipe
;
8772 int dpll_reg
= DPLL(pipe
);
8775 DRM_DEBUG_DRIVER("downclocking LVDS\n");
8777 assert_panel_unlocked(dev_priv
, pipe
);
8779 dpll
= I915_READ(dpll_reg
);
8780 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
8781 I915_WRITE(dpll_reg
, dpll
);
8782 intel_wait_for_vblank(dev
, pipe
);
8783 dpll
= I915_READ(dpll_reg
);
8784 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
8785 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
8790 void intel_mark_busy(struct drm_device
*dev
)
8792 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8794 if (dev_priv
->mm
.busy
)
8797 intel_runtime_pm_get(dev_priv
);
8798 i915_update_gfx_val(dev_priv
);
8799 dev_priv
->mm
.busy
= true;
8802 void intel_mark_idle(struct drm_device
*dev
)
8804 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8805 struct drm_crtc
*crtc
;
8807 if (!dev_priv
->mm
.busy
)
8810 dev_priv
->mm
.busy
= false;
8812 if (!i915
.powersave
)
8815 for_each_crtc(dev
, crtc
) {
8816 if (!crtc
->primary
->fb
)
8819 intel_decrease_pllclock(crtc
);
8822 if (INTEL_INFO(dev
)->gen
>= 6)
8823 gen6_rps_idle(dev
->dev_private
);
8826 intel_runtime_pm_put(dev_priv
);
8830 void intel_mark_fb_busy(struct drm_i915_gem_object
*obj
,
8831 struct intel_engine_cs
*ring
)
8833 struct drm_device
*dev
= obj
->base
.dev
;
8836 intel_edp_psr_exit(dev
);
8838 if (!i915
.powersave
)
8841 for_each_pipe(pipe
) {
8842 if (!(obj
->frontbuffer_bits
&
8843 INTEL_FRONTBUFFER_ALL_MASK(pipe
)))
8846 intel_increase_pllclock(dev
, pipe
);
8847 if (ring
&& intel_fbc_enabled(dev
))
8848 ring
->fbc_dirty
= true;
8852 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
8854 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8855 struct drm_device
*dev
= crtc
->dev
;
8856 struct intel_unpin_work
*work
;
8857 unsigned long flags
;
8859 spin_lock_irqsave(&dev
->event_lock
, flags
);
8860 work
= intel_crtc
->unpin_work
;
8861 intel_crtc
->unpin_work
= NULL
;
8862 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
8865 cancel_work_sync(&work
->work
);
8869 drm_crtc_cleanup(crtc
);
8874 static void intel_unpin_work_fn(struct work_struct
*__work
)
8876 struct intel_unpin_work
*work
=
8877 container_of(__work
, struct intel_unpin_work
, work
);
8878 struct drm_device
*dev
= work
->crtc
->dev
;
8880 mutex_lock(&dev
->struct_mutex
);
8881 intel_unpin_fb_obj(work
->old_fb_obj
);
8882 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
8883 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
8885 intel_update_fbc(dev
);
8886 mutex_unlock(&dev
->struct_mutex
);
8888 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
8889 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
8894 static void do_intel_finish_page_flip(struct drm_device
*dev
,
8895 struct drm_crtc
*crtc
)
8897 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8898 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8899 struct intel_unpin_work
*work
;
8900 unsigned long flags
;
8902 /* Ignore early vblank irqs */
8903 if (intel_crtc
== NULL
)
8906 spin_lock_irqsave(&dev
->event_lock
, flags
);
8907 work
= intel_crtc
->unpin_work
;
8909 /* Ensure we don't miss a work->pending update ... */
8912 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
8913 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
8917 /* and that the unpin work is consistent wrt ->pending. */
8920 intel_crtc
->unpin_work
= NULL
;
8923 drm_send_vblank_event(dev
, intel_crtc
->pipe
, work
->event
);
8925 drm_crtc_vblank_put(crtc
);
8927 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
8929 wake_up_all(&dev_priv
->pending_flip_queue
);
8931 queue_work(dev_priv
->wq
, &work
->work
);
8933 trace_i915_flip_complete(intel_crtc
->plane
, work
->pending_flip_obj
);
8936 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
8938 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8939 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
8941 do_intel_finish_page_flip(dev
, crtc
);
8944 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
8946 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8947 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
8949 do_intel_finish_page_flip(dev
, crtc
);
8952 /* Is 'a' after or equal to 'b'? */
8953 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
8955 return !((a
- b
) & 0x80000000);
8958 static bool page_flip_finished(struct intel_crtc
*crtc
)
8960 struct drm_device
*dev
= crtc
->base
.dev
;
8961 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8964 * The relevant registers doen't exist on pre-ctg.
8965 * As the flip done interrupt doesn't trigger for mmio
8966 * flips on gmch platforms, a flip count check isn't
8967 * really needed there. But since ctg has the registers,
8968 * include it in the check anyway.
8970 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
8974 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
8975 * used the same base address. In that case the mmio flip might
8976 * have completed, but the CS hasn't even executed the flip yet.
8978 * A flip count check isn't enough as the CS might have updated
8979 * the base address just after start of vblank, but before we
8980 * managed to process the interrupt. This means we'd complete the
8983 * Combining both checks should get us a good enough result. It may
8984 * still happen that the CS flip has been executed, but has not
8985 * yet actually completed. But in case the base address is the same
8986 * anyway, we don't really care.
8988 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
8989 crtc
->unpin_work
->gtt_offset
&&
8990 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc
->pipe
)),
8991 crtc
->unpin_work
->flip_count
);
8994 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
8996 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8997 struct intel_crtc
*intel_crtc
=
8998 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
8999 unsigned long flags
;
9001 /* NB: An MMIO update of the plane base pointer will also
9002 * generate a page-flip completion irq, i.e. every modeset
9003 * is also accompanied by a spurious intel_prepare_page_flip().
9005 spin_lock_irqsave(&dev
->event_lock
, flags
);
9006 if (intel_crtc
->unpin_work
&& page_flip_finished(intel_crtc
))
9007 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
9008 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9011 static inline void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
9013 /* Ensure that the work item is consistent when activating it ... */
9015 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
9016 /* and that it is marked active as soon as the irq could fire. */
9020 static int intel_gen2_queue_flip(struct drm_device
*dev
,
9021 struct drm_crtc
*crtc
,
9022 struct drm_framebuffer
*fb
,
9023 struct drm_i915_gem_object
*obj
,
9024 struct intel_engine_cs
*ring
,
9027 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9031 ret
= intel_ring_begin(ring
, 6);
9035 /* Can't queue multiple flips, so wait for the previous
9036 * one to finish before executing the next.
9038 if (intel_crtc
->plane
)
9039 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9041 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9042 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9043 intel_ring_emit(ring
, MI_NOOP
);
9044 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9045 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9046 intel_ring_emit(ring
, fb
->pitches
[0]);
9047 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9048 intel_ring_emit(ring
, 0); /* aux display base address, unused */
9050 intel_mark_page_flip_active(intel_crtc
);
9051 __intel_ring_advance(ring
);
9055 static int intel_gen3_queue_flip(struct drm_device
*dev
,
9056 struct drm_crtc
*crtc
,
9057 struct drm_framebuffer
*fb
,
9058 struct drm_i915_gem_object
*obj
,
9059 struct intel_engine_cs
*ring
,
9062 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9066 ret
= intel_ring_begin(ring
, 6);
9070 if (intel_crtc
->plane
)
9071 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9073 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9074 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9075 intel_ring_emit(ring
, MI_NOOP
);
9076 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
9077 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9078 intel_ring_emit(ring
, fb
->pitches
[0]);
9079 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9080 intel_ring_emit(ring
, MI_NOOP
);
9082 intel_mark_page_flip_active(intel_crtc
);
9083 __intel_ring_advance(ring
);
9087 static int intel_gen4_queue_flip(struct drm_device
*dev
,
9088 struct drm_crtc
*crtc
,
9089 struct drm_framebuffer
*fb
,
9090 struct drm_i915_gem_object
*obj
,
9091 struct intel_engine_cs
*ring
,
9094 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9095 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9096 uint32_t pf
, pipesrc
;
9099 ret
= intel_ring_begin(ring
, 4);
9103 /* i965+ uses the linear or tiled offsets from the
9104 * Display Registers (which do not change across a page-flip)
9105 * so we need only reprogram the base address.
9107 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9108 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9109 intel_ring_emit(ring
, fb
->pitches
[0]);
9110 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
|
9113 /* XXX Enabling the panel-fitter across page-flip is so far
9114 * untested on non-native modes, so ignore it for now.
9115 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
9118 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9119 intel_ring_emit(ring
, pf
| pipesrc
);
9121 intel_mark_page_flip_active(intel_crtc
);
9122 __intel_ring_advance(ring
);
9126 static int intel_gen6_queue_flip(struct drm_device
*dev
,
9127 struct drm_crtc
*crtc
,
9128 struct drm_framebuffer
*fb
,
9129 struct drm_i915_gem_object
*obj
,
9130 struct intel_engine_cs
*ring
,
9133 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9134 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9135 uint32_t pf
, pipesrc
;
9138 ret
= intel_ring_begin(ring
, 4);
9142 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9143 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9144 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
9145 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9147 /* Contrary to the suggestions in the documentation,
9148 * "Enable Panel Fitter" does not seem to be required when page
9149 * flipping with a non-native mode, and worse causes a normal
9151 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
9154 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9155 intel_ring_emit(ring
, pf
| pipesrc
);
9157 intel_mark_page_flip_active(intel_crtc
);
9158 __intel_ring_advance(ring
);
9162 static int intel_gen7_queue_flip(struct drm_device
*dev
,
9163 struct drm_crtc
*crtc
,
9164 struct drm_framebuffer
*fb
,
9165 struct drm_i915_gem_object
*obj
,
9166 struct intel_engine_cs
*ring
,
9169 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9170 uint32_t plane_bit
= 0;
9173 switch (intel_crtc
->plane
) {
9175 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
9178 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
9181 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
9184 WARN_ONCE(1, "unknown plane in flip command\n");
9189 if (ring
->id
== RCS
) {
9192 * On Gen 8, SRM is now taking an extra dword to accommodate
9193 * 48bits addresses, and we need a NOOP for the batch size to
9201 * BSpec MI_DISPLAY_FLIP for IVB:
9202 * "The full packet must be contained within the same cache line."
9204 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
9205 * cacheline, if we ever start emitting more commands before
9206 * the MI_DISPLAY_FLIP we may need to first emit everything else,
9207 * then do the cacheline alignment, and finally emit the
9210 ret
= intel_ring_cacheline_align(ring
);
9214 ret
= intel_ring_begin(ring
, len
);
9218 /* Unmask the flip-done completion message. Note that the bspec says that
9219 * we should do this for both the BCS and RCS, and that we must not unmask
9220 * more than one flip event at any time (or ensure that one flip message
9221 * can be sent by waiting for flip-done prior to queueing new flips).
9222 * Experimentation says that BCS works despite DERRMR masking all
9223 * flip-done completion events and that unmasking all planes at once
9224 * for the RCS also doesn't appear to drop events. Setting the DERRMR
9225 * to zero does lead to lockups within MI_DISPLAY_FLIP.
9227 if (ring
->id
== RCS
) {
9228 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
9229 intel_ring_emit(ring
, DERRMR
);
9230 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
9231 DERRMR_PIPEB_PRI_FLIP_DONE
|
9232 DERRMR_PIPEC_PRI_FLIP_DONE
));
9234 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8(1) |
9235 MI_SRM_LRM_GLOBAL_GTT
);
9237 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM(1) |
9238 MI_SRM_LRM_GLOBAL_GTT
);
9239 intel_ring_emit(ring
, DERRMR
);
9240 intel_ring_emit(ring
, ring
->scratch
.gtt_offset
+ 256);
9242 intel_ring_emit(ring
, 0);
9243 intel_ring_emit(ring
, MI_NOOP
);
9247 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
9248 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
9249 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9250 intel_ring_emit(ring
, (MI_NOOP
));
9252 intel_mark_page_flip_active(intel_crtc
);
9253 __intel_ring_advance(ring
);
9257 static bool use_mmio_flip(struct intel_engine_cs
*ring
,
9258 struct drm_i915_gem_object
*obj
)
9261 * This is not being used for older platforms, because
9262 * non-availability of flip done interrupt forces us to use
9263 * CS flips. Older platforms derive flip done using some clever
9264 * tricks involving the flip_pending status bits and vblank irqs.
9265 * So using MMIO flips there would disrupt this mechanism.
9268 if (INTEL_INFO(ring
->dev
)->gen
< 5)
9271 if (i915
.use_mmio_flip
< 0)
9273 else if (i915
.use_mmio_flip
> 0)
9276 return ring
!= obj
->ring
;
9279 static void intel_do_mmio_flip(struct intel_crtc
*intel_crtc
)
9281 struct drm_device
*dev
= intel_crtc
->base
.dev
;
9282 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9283 struct intel_framebuffer
*intel_fb
=
9284 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
9285 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
9289 intel_mark_page_flip_active(intel_crtc
);
9291 reg
= DSPCNTR(intel_crtc
->plane
);
9292 dspcntr
= I915_READ(reg
);
9294 if (INTEL_INFO(dev
)->gen
>= 4) {
9295 if (obj
->tiling_mode
!= I915_TILING_NONE
)
9296 dspcntr
|= DISPPLANE_TILED
;
9298 dspcntr
&= ~DISPPLANE_TILED
;
9300 I915_WRITE(reg
, dspcntr
);
9302 I915_WRITE(DSPSURF(intel_crtc
->plane
),
9303 intel_crtc
->unpin_work
->gtt_offset
);
9304 POSTING_READ(DSPSURF(intel_crtc
->plane
));
9307 static int intel_postpone_flip(struct drm_i915_gem_object
*obj
)
9309 struct intel_engine_cs
*ring
;
9312 lockdep_assert_held(&obj
->base
.dev
->struct_mutex
);
9314 if (!obj
->last_write_seqno
)
9319 if (i915_seqno_passed(ring
->get_seqno(ring
, true),
9320 obj
->last_write_seqno
))
9323 ret
= i915_gem_check_olr(ring
, obj
->last_write_seqno
);
9327 if (WARN_ON(!ring
->irq_get(ring
)))
9333 void intel_notify_mmio_flip(struct intel_engine_cs
*ring
)
9335 struct drm_i915_private
*dev_priv
= to_i915(ring
->dev
);
9336 struct intel_crtc
*intel_crtc
;
9337 unsigned long irq_flags
;
9340 seqno
= ring
->get_seqno(ring
, false);
9342 spin_lock_irqsave(&dev_priv
->mmio_flip_lock
, irq_flags
);
9343 for_each_intel_crtc(ring
->dev
, intel_crtc
) {
9344 struct intel_mmio_flip
*mmio_flip
;
9346 mmio_flip
= &intel_crtc
->mmio_flip
;
9347 if (mmio_flip
->seqno
== 0)
9350 if (ring
->id
!= mmio_flip
->ring_id
)
9353 if (i915_seqno_passed(seqno
, mmio_flip
->seqno
)) {
9354 intel_do_mmio_flip(intel_crtc
);
9355 mmio_flip
->seqno
= 0;
9356 ring
->irq_put(ring
);
9359 spin_unlock_irqrestore(&dev_priv
->mmio_flip_lock
, irq_flags
);
9362 static int intel_queue_mmio_flip(struct drm_device
*dev
,
9363 struct drm_crtc
*crtc
,
9364 struct drm_framebuffer
*fb
,
9365 struct drm_i915_gem_object
*obj
,
9366 struct intel_engine_cs
*ring
,
9369 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9370 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9371 unsigned long irq_flags
;
9374 if (WARN_ON(intel_crtc
->mmio_flip
.seqno
))
9377 ret
= intel_postpone_flip(obj
);
9381 intel_do_mmio_flip(intel_crtc
);
9385 spin_lock_irqsave(&dev_priv
->mmio_flip_lock
, irq_flags
);
9386 intel_crtc
->mmio_flip
.seqno
= obj
->last_write_seqno
;
9387 intel_crtc
->mmio_flip
.ring_id
= obj
->ring
->id
;
9388 spin_unlock_irqrestore(&dev_priv
->mmio_flip_lock
, irq_flags
);
9391 * Double check to catch cases where irq fired before
9392 * mmio flip data was ready
9394 intel_notify_mmio_flip(obj
->ring
);
9398 static int intel_default_queue_flip(struct drm_device
*dev
,
9399 struct drm_crtc
*crtc
,
9400 struct drm_framebuffer
*fb
,
9401 struct drm_i915_gem_object
*obj
,
9402 struct intel_engine_cs
*ring
,
9408 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
9409 struct drm_framebuffer
*fb
,
9410 struct drm_pending_vblank_event
*event
,
9411 uint32_t page_flip_flags
)
9413 struct drm_device
*dev
= crtc
->dev
;
9414 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9415 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
9416 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(fb
)->obj
;
9417 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9418 enum pipe pipe
= intel_crtc
->pipe
;
9419 struct intel_unpin_work
*work
;
9420 struct intel_engine_cs
*ring
;
9421 unsigned long flags
;
9424 /* Can't change pixel format via MI display flips. */
9425 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
9429 * TILEOFF/LINOFF registers can't be changed via MI display flips.
9430 * Note that pitch changes could also affect these register.
9432 if (INTEL_INFO(dev
)->gen
> 3 &&
9433 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
9434 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
9437 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
9440 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
9444 /* Exit PSR early in page flip */
9445 intel_edp_psr_exit(dev
);
9447 work
->event
= event
;
9449 work
->old_fb_obj
= to_intel_framebuffer(old_fb
)->obj
;
9450 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
9452 ret
= drm_crtc_vblank_get(crtc
);
9456 /* We borrow the event spin lock for protecting unpin_work */
9457 spin_lock_irqsave(&dev
->event_lock
, flags
);
9458 if (intel_crtc
->unpin_work
) {
9459 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9461 drm_crtc_vblank_put(crtc
);
9463 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
9466 intel_crtc
->unpin_work
= work
;
9467 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9469 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
9470 flush_workqueue(dev_priv
->wq
);
9472 ret
= i915_mutex_lock_interruptible(dev
);
9476 /* Reference the objects for the scheduled work. */
9477 drm_gem_object_reference(&work
->old_fb_obj
->base
);
9478 drm_gem_object_reference(&obj
->base
);
9480 crtc
->primary
->fb
= fb
;
9482 work
->pending_flip_obj
= obj
;
9484 work
->enable_stall_check
= true;
9486 atomic_inc(&intel_crtc
->unpin_work_count
);
9487 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
9489 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
9490 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_GM45(pipe
)) + 1;
9492 if (IS_VALLEYVIEW(dev
)) {
9493 ring
= &dev_priv
->ring
[BCS
];
9494 } else if (INTEL_INFO(dev
)->gen
>= 7) {
9496 if (ring
== NULL
|| ring
->id
!= RCS
)
9497 ring
= &dev_priv
->ring
[BCS
];
9499 ring
= &dev_priv
->ring
[RCS
];
9502 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
9504 goto cleanup_pending
;
9507 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
;
9509 if (use_mmio_flip(ring
, obj
))
9510 ret
= intel_queue_mmio_flip(dev
, crtc
, fb
, obj
, ring
,
9513 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, ring
,
9518 i915_gem_track_fb(work
->old_fb_obj
, obj
,
9519 INTEL_FRONTBUFFER_PRIMARY(pipe
));
9521 intel_disable_fbc(dev
);
9522 intel_mark_fb_busy(obj
, NULL
);
9523 mutex_unlock(&dev
->struct_mutex
);
9525 trace_i915_flip_request(intel_crtc
->plane
, obj
);
9530 intel_unpin_fb_obj(obj
);
9532 atomic_dec(&intel_crtc
->unpin_work_count
);
9533 crtc
->primary
->fb
= old_fb
;
9534 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
9535 drm_gem_object_unreference(&obj
->base
);
9536 mutex_unlock(&dev
->struct_mutex
);
9539 spin_lock_irqsave(&dev
->event_lock
, flags
);
9540 intel_crtc
->unpin_work
= NULL
;
9541 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9543 drm_crtc_vblank_put(crtc
);
9549 intel_crtc_wait_for_pending_flips(crtc
);
9550 ret
= intel_pipe_set_base(crtc
, crtc
->x
, crtc
->y
, fb
);
9551 if (ret
== 0 && event
)
9552 drm_send_vblank_event(dev
, pipe
, event
);
9557 static struct drm_crtc_helper_funcs intel_helper_funcs
= {
9558 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
9559 .load_lut
= intel_crtc_load_lut
,
9563 * intel_modeset_update_staged_output_state
9565 * Updates the staged output configuration state, e.g. after we've read out the
9568 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
9570 struct intel_crtc
*crtc
;
9571 struct intel_encoder
*encoder
;
9572 struct intel_connector
*connector
;
9574 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9576 connector
->new_encoder
=
9577 to_intel_encoder(connector
->base
.encoder
);
9580 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9583 to_intel_crtc(encoder
->base
.crtc
);
9586 for_each_intel_crtc(dev
, crtc
) {
9587 crtc
->new_enabled
= crtc
->base
.enabled
;
9589 if (crtc
->new_enabled
)
9590 crtc
->new_config
= &crtc
->config
;
9592 crtc
->new_config
= NULL
;
9597 * intel_modeset_commit_output_state
9599 * This function copies the stage display pipe configuration to the real one.
9601 static void intel_modeset_commit_output_state(struct drm_device
*dev
)
9603 struct intel_crtc
*crtc
;
9604 struct intel_encoder
*encoder
;
9605 struct intel_connector
*connector
;
9607 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9609 connector
->base
.encoder
= &connector
->new_encoder
->base
;
9612 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9614 encoder
->base
.crtc
= &encoder
->new_crtc
->base
;
9617 for_each_intel_crtc(dev
, crtc
) {
9618 crtc
->base
.enabled
= crtc
->new_enabled
;
9623 connected_sink_compute_bpp(struct intel_connector
*connector
,
9624 struct intel_crtc_config
*pipe_config
)
9626 int bpp
= pipe_config
->pipe_bpp
;
9628 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
9629 connector
->base
.base
.id
,
9630 connector
->base
.name
);
9632 /* Don't use an invalid EDID bpc value */
9633 if (connector
->base
.display_info
.bpc
&&
9634 connector
->base
.display_info
.bpc
* 3 < bpp
) {
9635 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
9636 bpp
, connector
->base
.display_info
.bpc
*3);
9637 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
9640 /* Clamp bpp to 8 on screens without EDID 1.4 */
9641 if (connector
->base
.display_info
.bpc
== 0 && bpp
> 24) {
9642 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
9644 pipe_config
->pipe_bpp
= 24;
9649 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
9650 struct drm_framebuffer
*fb
,
9651 struct intel_crtc_config
*pipe_config
)
9653 struct drm_device
*dev
= crtc
->base
.dev
;
9654 struct intel_connector
*connector
;
9657 switch (fb
->pixel_format
) {
9659 bpp
= 8*3; /* since we go through a colormap */
9661 case DRM_FORMAT_XRGB1555
:
9662 case DRM_FORMAT_ARGB1555
:
9663 /* checked in intel_framebuffer_init already */
9664 if (WARN_ON(INTEL_INFO(dev
)->gen
> 3))
9666 case DRM_FORMAT_RGB565
:
9667 bpp
= 6*3; /* min is 18bpp */
9669 case DRM_FORMAT_XBGR8888
:
9670 case DRM_FORMAT_ABGR8888
:
9671 /* checked in intel_framebuffer_init already */
9672 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
9674 case DRM_FORMAT_XRGB8888
:
9675 case DRM_FORMAT_ARGB8888
:
9678 case DRM_FORMAT_XRGB2101010
:
9679 case DRM_FORMAT_ARGB2101010
:
9680 case DRM_FORMAT_XBGR2101010
:
9681 case DRM_FORMAT_ABGR2101010
:
9682 /* checked in intel_framebuffer_init already */
9683 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
9687 /* TODO: gen4+ supports 16 bpc floating point, too. */
9689 DRM_DEBUG_KMS("unsupported depth\n");
9693 pipe_config
->pipe_bpp
= bpp
;
9695 /* Clamp display bpp to EDID value */
9696 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9698 if (!connector
->new_encoder
||
9699 connector
->new_encoder
->new_crtc
!= crtc
)
9702 connected_sink_compute_bpp(connector
, pipe_config
);
9708 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
9710 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
9711 "type: 0x%x flags: 0x%x\n",
9713 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
9714 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
9715 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
9716 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
9719 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
9720 struct intel_crtc_config
*pipe_config
,
9721 const char *context
)
9723 DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc
->base
.base
.id
,
9724 context
, pipe_name(crtc
->pipe
));
9726 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config
->cpu_transcoder
));
9727 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
9728 pipe_config
->pipe_bpp
, pipe_config
->dither
);
9729 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
9730 pipe_config
->has_pch_encoder
,
9731 pipe_config
->fdi_lanes
,
9732 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
9733 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
9734 pipe_config
->fdi_m_n
.tu
);
9735 DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
9736 pipe_config
->has_dp_encoder
,
9737 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
9738 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
9739 pipe_config
->dp_m_n
.tu
);
9740 DRM_DEBUG_KMS("requested mode:\n");
9741 drm_mode_debug_printmodeline(&pipe_config
->requested_mode
);
9742 DRM_DEBUG_KMS("adjusted mode:\n");
9743 drm_mode_debug_printmodeline(&pipe_config
->adjusted_mode
);
9744 intel_dump_crtc_timings(&pipe_config
->adjusted_mode
);
9745 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
9746 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
9747 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
9748 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
9749 pipe_config
->gmch_pfit
.control
,
9750 pipe_config
->gmch_pfit
.pgm_ratios
,
9751 pipe_config
->gmch_pfit
.lvds_border_bits
);
9752 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
9753 pipe_config
->pch_pfit
.pos
,
9754 pipe_config
->pch_pfit
.size
,
9755 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
9756 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
9757 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
9760 static bool encoders_cloneable(const struct intel_encoder
*a
,
9761 const struct intel_encoder
*b
)
9763 /* masks could be asymmetric, so check both ways */
9764 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
9765 b
->cloneable
& (1 << a
->type
));
9768 static bool check_single_encoder_cloning(struct intel_crtc
*crtc
,
9769 struct intel_encoder
*encoder
)
9771 struct drm_device
*dev
= crtc
->base
.dev
;
9772 struct intel_encoder
*source_encoder
;
9774 list_for_each_entry(source_encoder
,
9775 &dev
->mode_config
.encoder_list
, base
.head
) {
9776 if (source_encoder
->new_crtc
!= crtc
)
9779 if (!encoders_cloneable(encoder
, source_encoder
))
9786 static bool check_encoder_cloning(struct intel_crtc
*crtc
)
9788 struct drm_device
*dev
= crtc
->base
.dev
;
9789 struct intel_encoder
*encoder
;
9791 list_for_each_entry(encoder
,
9792 &dev
->mode_config
.encoder_list
, base
.head
) {
9793 if (encoder
->new_crtc
!= crtc
)
9796 if (!check_single_encoder_cloning(crtc
, encoder
))
9803 static struct intel_crtc_config
*
9804 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
9805 struct drm_framebuffer
*fb
,
9806 struct drm_display_mode
*mode
)
9808 struct drm_device
*dev
= crtc
->dev
;
9809 struct intel_encoder
*encoder
;
9810 struct intel_crtc_config
*pipe_config
;
9811 int plane_bpp
, ret
= -EINVAL
;
9814 if (!check_encoder_cloning(to_intel_crtc(crtc
))) {
9815 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
9816 return ERR_PTR(-EINVAL
);
9819 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
9821 return ERR_PTR(-ENOMEM
);
9823 drm_mode_copy(&pipe_config
->adjusted_mode
, mode
);
9824 drm_mode_copy(&pipe_config
->requested_mode
, mode
);
9826 pipe_config
->cpu_transcoder
=
9827 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
9828 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
9831 * Sanitize sync polarity flags based on requested ones. If neither
9832 * positive or negative polarity is requested, treat this as meaning
9833 * negative polarity.
9835 if (!(pipe_config
->adjusted_mode
.flags
&
9836 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
9837 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
9839 if (!(pipe_config
->adjusted_mode
.flags
&
9840 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
9841 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
9843 /* Compute a starting value for pipe_config->pipe_bpp taking the source
9844 * plane pixel format and any sink constraints into account. Returns the
9845 * source plane bpp so that dithering can be selected on mismatches
9846 * after encoders and crtc also have had their say. */
9847 plane_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
9853 * Determine the real pipe dimensions. Note that stereo modes can
9854 * increase the actual pipe size due to the frame doubling and
9855 * insertion of additional space for blanks between the frame. This
9856 * is stored in the crtc timings. We use the requested mode to do this
9857 * computation to clearly distinguish it from the adjusted mode, which
9858 * can be changed by the connectors in the below retry loop.
9860 drm_mode_set_crtcinfo(&pipe_config
->requested_mode
, CRTC_STEREO_DOUBLE
);
9861 pipe_config
->pipe_src_w
= pipe_config
->requested_mode
.crtc_hdisplay
;
9862 pipe_config
->pipe_src_h
= pipe_config
->requested_mode
.crtc_vdisplay
;
9865 /* Ensure the port clock defaults are reset when retrying. */
9866 pipe_config
->port_clock
= 0;
9867 pipe_config
->pixel_multiplier
= 1;
9869 /* Fill in default crtc timings, allow encoders to overwrite them. */
9870 drm_mode_set_crtcinfo(&pipe_config
->adjusted_mode
, CRTC_STEREO_DOUBLE
);
9872 /* Pass our mode to the connectors and the CRTC to give them a chance to
9873 * adjust it according to limitations or connector properties, and also
9874 * a chance to reject the mode entirely.
9876 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9879 if (&encoder
->new_crtc
->base
!= crtc
)
9882 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
9883 DRM_DEBUG_KMS("Encoder config failure\n");
9888 /* Set default port clock if not overwritten by the encoder. Needs to be
9889 * done afterwards in case the encoder adjusts the mode. */
9890 if (!pipe_config
->port_clock
)
9891 pipe_config
->port_clock
= pipe_config
->adjusted_mode
.crtc_clock
9892 * pipe_config
->pixel_multiplier
;
9894 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
9896 DRM_DEBUG_KMS("CRTC fixup failed\n");
9901 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
9906 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
9911 pipe_config
->dither
= pipe_config
->pipe_bpp
!= plane_bpp
;
9912 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
9913 plane_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
9918 return ERR_PTR(ret
);
9921 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
9922 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
9924 intel_modeset_affected_pipes(struct drm_crtc
*crtc
, unsigned *modeset_pipes
,
9925 unsigned *prepare_pipes
, unsigned *disable_pipes
)
9927 struct intel_crtc
*intel_crtc
;
9928 struct drm_device
*dev
= crtc
->dev
;
9929 struct intel_encoder
*encoder
;
9930 struct intel_connector
*connector
;
9931 struct drm_crtc
*tmp_crtc
;
9933 *disable_pipes
= *modeset_pipes
= *prepare_pipes
= 0;
9935 /* Check which crtcs have changed outputs connected to them, these need
9936 * to be part of the prepare_pipes mask. We don't (yet) support global
9937 * modeset across multiple crtcs, so modeset_pipes will only have one
9938 * bit set at most. */
9939 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9941 if (connector
->base
.encoder
== &connector
->new_encoder
->base
)
9944 if (connector
->base
.encoder
) {
9945 tmp_crtc
= connector
->base
.encoder
->crtc
;
9947 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
9950 if (connector
->new_encoder
)
9952 1 << connector
->new_encoder
->new_crtc
->pipe
;
9955 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9957 if (encoder
->base
.crtc
== &encoder
->new_crtc
->base
)
9960 if (encoder
->base
.crtc
) {
9961 tmp_crtc
= encoder
->base
.crtc
;
9963 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
9966 if (encoder
->new_crtc
)
9967 *prepare_pipes
|= 1 << encoder
->new_crtc
->pipe
;
9970 /* Check for pipes that will be enabled/disabled ... */
9971 for_each_intel_crtc(dev
, intel_crtc
) {
9972 if (intel_crtc
->base
.enabled
== intel_crtc
->new_enabled
)
9975 if (!intel_crtc
->new_enabled
)
9976 *disable_pipes
|= 1 << intel_crtc
->pipe
;
9978 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
9982 /* set_mode is also used to update properties on life display pipes. */
9983 intel_crtc
= to_intel_crtc(crtc
);
9984 if (intel_crtc
->new_enabled
)
9985 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
9988 * For simplicity do a full modeset on any pipe where the output routing
9989 * changed. We could be more clever, but that would require us to be
9990 * more careful with calling the relevant encoder->mode_set functions.
9993 *modeset_pipes
= *prepare_pipes
;
9995 /* ... and mask these out. */
9996 *modeset_pipes
&= ~(*disable_pipes
);
9997 *prepare_pipes
&= ~(*disable_pipes
);
10000 * HACK: We don't (yet) fully support global modesets. intel_set_config
10001 * obies this rule, but the modeset restore mode of
10002 * intel_modeset_setup_hw_state does not.
10004 *modeset_pipes
&= 1 << intel_crtc
->pipe
;
10005 *prepare_pipes
&= 1 << intel_crtc
->pipe
;
10007 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
10008 *modeset_pipes
, *prepare_pipes
, *disable_pipes
);
10011 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
10013 struct drm_encoder
*encoder
;
10014 struct drm_device
*dev
= crtc
->dev
;
10016 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
10017 if (encoder
->crtc
== crtc
)
10024 intel_modeset_update_state(struct drm_device
*dev
, unsigned prepare_pipes
)
10026 struct intel_encoder
*intel_encoder
;
10027 struct intel_crtc
*intel_crtc
;
10028 struct drm_connector
*connector
;
10030 list_for_each_entry(intel_encoder
, &dev
->mode_config
.encoder_list
,
10032 if (!intel_encoder
->base
.crtc
)
10035 intel_crtc
= to_intel_crtc(intel_encoder
->base
.crtc
);
10037 if (prepare_pipes
& (1 << intel_crtc
->pipe
))
10038 intel_encoder
->connectors_active
= false;
10041 intel_modeset_commit_output_state(dev
);
10043 /* Double check state. */
10044 for_each_intel_crtc(dev
, intel_crtc
) {
10045 WARN_ON(intel_crtc
->base
.enabled
!= intel_crtc_in_use(&intel_crtc
->base
));
10046 WARN_ON(intel_crtc
->new_config
&&
10047 intel_crtc
->new_config
!= &intel_crtc
->config
);
10048 WARN_ON(intel_crtc
->base
.enabled
!= !!intel_crtc
->new_config
);
10051 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
10052 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
10055 intel_crtc
= to_intel_crtc(connector
->encoder
->crtc
);
10057 if (prepare_pipes
& (1 << intel_crtc
->pipe
)) {
10058 struct drm_property
*dpms_property
=
10059 dev
->mode_config
.dpms_property
;
10061 connector
->dpms
= DRM_MODE_DPMS_ON
;
10062 drm_object_property_set_value(&connector
->base
,
10066 intel_encoder
= to_intel_encoder(connector
->encoder
);
10067 intel_encoder
->connectors_active
= true;
10073 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
10077 if (clock1
== clock2
)
10080 if (!clock1
|| !clock2
)
10083 diff
= abs(clock1
- clock2
);
10085 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
10091 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
10092 list_for_each_entry((intel_crtc), \
10093 &(dev)->mode_config.crtc_list, \
10095 if (mask & (1 <<(intel_crtc)->pipe))
10098 intel_pipe_config_compare(struct drm_device
*dev
,
10099 struct intel_crtc_config
*current_config
,
10100 struct intel_crtc_config
*pipe_config
)
10102 #define PIPE_CONF_CHECK_X(name) \
10103 if (current_config->name != pipe_config->name) { \
10104 DRM_ERROR("mismatch in " #name " " \
10105 "(expected 0x%08x, found 0x%08x)\n", \
10106 current_config->name, \
10107 pipe_config->name); \
10111 #define PIPE_CONF_CHECK_I(name) \
10112 if (current_config->name != pipe_config->name) { \
10113 DRM_ERROR("mismatch in " #name " " \
10114 "(expected %i, found %i)\n", \
10115 current_config->name, \
10116 pipe_config->name); \
10120 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
10121 if ((current_config->name ^ pipe_config->name) & (mask)) { \
10122 DRM_ERROR("mismatch in " #name "(" #mask ") " \
10123 "(expected %i, found %i)\n", \
10124 current_config->name & (mask), \
10125 pipe_config->name & (mask)); \
10129 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
10130 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
10131 DRM_ERROR("mismatch in " #name " " \
10132 "(expected %i, found %i)\n", \
10133 current_config->name, \
10134 pipe_config->name); \
10138 #define PIPE_CONF_QUIRK(quirk) \
10139 ((current_config->quirks | pipe_config->quirks) & (quirk))
10141 PIPE_CONF_CHECK_I(cpu_transcoder
);
10143 PIPE_CONF_CHECK_I(has_pch_encoder
);
10144 PIPE_CONF_CHECK_I(fdi_lanes
);
10145 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_m
);
10146 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_n
);
10147 PIPE_CONF_CHECK_I(fdi_m_n
.link_m
);
10148 PIPE_CONF_CHECK_I(fdi_m_n
.link_n
);
10149 PIPE_CONF_CHECK_I(fdi_m_n
.tu
);
10151 PIPE_CONF_CHECK_I(has_dp_encoder
);
10152 PIPE_CONF_CHECK_I(dp_m_n
.gmch_m
);
10153 PIPE_CONF_CHECK_I(dp_m_n
.gmch_n
);
10154 PIPE_CONF_CHECK_I(dp_m_n
.link_m
);
10155 PIPE_CONF_CHECK_I(dp_m_n
.link_n
);
10156 PIPE_CONF_CHECK_I(dp_m_n
.tu
);
10158 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hdisplay
);
10159 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_htotal
);
10160 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_start
);
10161 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_end
);
10162 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_start
);
10163 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_end
);
10165 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vdisplay
);
10166 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vtotal
);
10167 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_start
);
10168 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_end
);
10169 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_start
);
10170 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_end
);
10172 PIPE_CONF_CHECK_I(pixel_multiplier
);
10173 PIPE_CONF_CHECK_I(has_hdmi_sink
);
10174 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
10175 IS_VALLEYVIEW(dev
))
10176 PIPE_CONF_CHECK_I(limited_color_range
);
10178 PIPE_CONF_CHECK_I(has_audio
);
10180 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10181 DRM_MODE_FLAG_INTERLACE
);
10183 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
10184 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10185 DRM_MODE_FLAG_PHSYNC
);
10186 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10187 DRM_MODE_FLAG_NHSYNC
);
10188 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10189 DRM_MODE_FLAG_PVSYNC
);
10190 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10191 DRM_MODE_FLAG_NVSYNC
);
10194 PIPE_CONF_CHECK_I(pipe_src_w
);
10195 PIPE_CONF_CHECK_I(pipe_src_h
);
10198 * FIXME: BIOS likes to set up a cloned config with lvds+external
10199 * screen. Since we don't yet re-compute the pipe config when moving
10200 * just the lvds port away to another pipe the sw tracking won't match.
10202 * Proper atomic modesets with recomputed global state will fix this.
10203 * Until then just don't check gmch state for inherited modes.
10205 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE
)) {
10206 PIPE_CONF_CHECK_I(gmch_pfit
.control
);
10207 /* pfit ratios are autocomputed by the hw on gen4+ */
10208 if (INTEL_INFO(dev
)->gen
< 4)
10209 PIPE_CONF_CHECK_I(gmch_pfit
.pgm_ratios
);
10210 PIPE_CONF_CHECK_I(gmch_pfit
.lvds_border_bits
);
10213 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
10214 if (current_config
->pch_pfit
.enabled
) {
10215 PIPE_CONF_CHECK_I(pch_pfit
.pos
);
10216 PIPE_CONF_CHECK_I(pch_pfit
.size
);
10219 /* BDW+ don't expose a synchronous way to read the state */
10220 if (IS_HASWELL(dev
))
10221 PIPE_CONF_CHECK_I(ips_enabled
);
10223 PIPE_CONF_CHECK_I(double_wide
);
10225 PIPE_CONF_CHECK_I(shared_dpll
);
10226 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
10227 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
10228 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
10229 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
10231 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
10232 PIPE_CONF_CHECK_I(pipe_bpp
);
10234 PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode
.crtc_clock
);
10235 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
10237 #undef PIPE_CONF_CHECK_X
10238 #undef PIPE_CONF_CHECK_I
10239 #undef PIPE_CONF_CHECK_FLAGS
10240 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
10241 #undef PIPE_CONF_QUIRK
10247 check_connector_state(struct drm_device
*dev
)
10249 struct intel_connector
*connector
;
10251 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10253 /* This also checks the encoder/connector hw state with the
10254 * ->get_hw_state callbacks. */
10255 intel_connector_check_state(connector
);
10257 WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
10258 "connector's staged encoder doesn't match current encoder\n");
10263 check_encoder_state(struct drm_device
*dev
)
10265 struct intel_encoder
*encoder
;
10266 struct intel_connector
*connector
;
10268 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10270 bool enabled
= false;
10271 bool active
= false;
10272 enum pipe pipe
, tracked_pipe
;
10274 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
10275 encoder
->base
.base
.id
,
10276 encoder
->base
.name
);
10278 WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
10279 "encoder's stage crtc doesn't match current crtc\n");
10280 WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
10281 "encoder's active_connectors set, but no crtc\n");
10283 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10285 if (connector
->base
.encoder
!= &encoder
->base
)
10288 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
10291 WARN(!!encoder
->base
.crtc
!= enabled
,
10292 "encoder's enabled state mismatch "
10293 "(expected %i, found %i)\n",
10294 !!encoder
->base
.crtc
, enabled
);
10295 WARN(active
&& !encoder
->base
.crtc
,
10296 "active encoder with no crtc\n");
10298 WARN(encoder
->connectors_active
!= active
,
10299 "encoder's computed active state doesn't match tracked active state "
10300 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
10302 active
= encoder
->get_hw_state(encoder
, &pipe
);
10303 WARN(active
!= encoder
->connectors_active
,
10304 "encoder's hw state doesn't match sw tracking "
10305 "(expected %i, found %i)\n",
10306 encoder
->connectors_active
, active
);
10308 if (!encoder
->base
.crtc
)
10311 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
10312 WARN(active
&& pipe
!= tracked_pipe
,
10313 "active encoder's pipe doesn't match"
10314 "(expected %i, found %i)\n",
10315 tracked_pipe
, pipe
);
10321 check_crtc_state(struct drm_device
*dev
)
10323 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10324 struct intel_crtc
*crtc
;
10325 struct intel_encoder
*encoder
;
10326 struct intel_crtc_config pipe_config
;
10328 for_each_intel_crtc(dev
, crtc
) {
10329 bool enabled
= false;
10330 bool active
= false;
10332 memset(&pipe_config
, 0, sizeof(pipe_config
));
10334 DRM_DEBUG_KMS("[CRTC:%d]\n",
10335 crtc
->base
.base
.id
);
10337 WARN(crtc
->active
&& !crtc
->base
.enabled
,
10338 "active crtc, but not enabled in sw tracking\n");
10340 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10342 if (encoder
->base
.crtc
!= &crtc
->base
)
10345 if (encoder
->connectors_active
)
10349 WARN(active
!= crtc
->active
,
10350 "crtc's computed active state doesn't match tracked active state "
10351 "(expected %i, found %i)\n", active
, crtc
->active
);
10352 WARN(enabled
!= crtc
->base
.enabled
,
10353 "crtc's computed enabled state doesn't match tracked enabled state "
10354 "(expected %i, found %i)\n", enabled
, crtc
->base
.enabled
);
10356 active
= dev_priv
->display
.get_pipe_config(crtc
,
10359 /* hw state is inconsistent with the pipe A quirk */
10360 if (crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
)
10361 active
= crtc
->active
;
10363 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10366 if (encoder
->base
.crtc
!= &crtc
->base
)
10368 if (encoder
->get_hw_state(encoder
, &pipe
))
10369 encoder
->get_config(encoder
, &pipe_config
);
10372 WARN(crtc
->active
!= active
,
10373 "crtc active state doesn't match with hw state "
10374 "(expected %i, found %i)\n", crtc
->active
, active
);
10377 !intel_pipe_config_compare(dev
, &crtc
->config
, &pipe_config
)) {
10378 WARN(1, "pipe state doesn't match!\n");
10379 intel_dump_pipe_config(crtc
, &pipe_config
,
10381 intel_dump_pipe_config(crtc
, &crtc
->config
,
10388 check_shared_dpll_state(struct drm_device
*dev
)
10390 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10391 struct intel_crtc
*crtc
;
10392 struct intel_dpll_hw_state dpll_hw_state
;
10395 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
10396 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
10397 int enabled_crtcs
= 0, active_crtcs
= 0;
10400 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
10402 DRM_DEBUG_KMS("%s\n", pll
->name
);
10404 active
= pll
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
10406 WARN(pll
->active
> pll
->refcount
,
10407 "more active pll users than references: %i vs %i\n",
10408 pll
->active
, pll
->refcount
);
10409 WARN(pll
->active
&& !pll
->on
,
10410 "pll in active use but not on in sw tracking\n");
10411 WARN(pll
->on
&& !pll
->active
,
10412 "pll in on but not on in use in sw tracking\n");
10413 WARN(pll
->on
!= active
,
10414 "pll on state mismatch (expected %i, found %i)\n",
10417 for_each_intel_crtc(dev
, crtc
) {
10418 if (crtc
->base
.enabled
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10420 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10423 WARN(pll
->active
!= active_crtcs
,
10424 "pll active crtcs mismatch (expected %i, found %i)\n",
10425 pll
->active
, active_crtcs
);
10426 WARN(pll
->refcount
!= enabled_crtcs
,
10427 "pll enabled crtcs mismatch (expected %i, found %i)\n",
10428 pll
->refcount
, enabled_crtcs
);
10430 WARN(pll
->on
&& memcmp(&pll
->hw_state
, &dpll_hw_state
,
10431 sizeof(dpll_hw_state
)),
10432 "pll hw state mismatch\n");
10437 intel_modeset_check_state(struct drm_device
*dev
)
10439 check_connector_state(dev
);
10440 check_encoder_state(dev
);
10441 check_crtc_state(dev
);
10442 check_shared_dpll_state(dev
);
10445 void ironlake_check_encoder_dotclock(const struct intel_crtc_config
*pipe_config
,
10449 * FDI already provided one idea for the dotclock.
10450 * Yell if the encoder disagrees.
10452 WARN(!intel_fuzzy_clock_check(pipe_config
->adjusted_mode
.crtc_clock
, dotclock
),
10453 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
10454 pipe_config
->adjusted_mode
.crtc_clock
, dotclock
);
10457 static void update_scanline_offset(struct intel_crtc
*crtc
)
10459 struct drm_device
*dev
= crtc
->base
.dev
;
10462 * The scanline counter increments at the leading edge of hsync.
10464 * On most platforms it starts counting from vtotal-1 on the
10465 * first active line. That means the scanline counter value is
10466 * always one less than what we would expect. Ie. just after
10467 * start of vblank, which also occurs at start of hsync (on the
10468 * last active line), the scanline counter will read vblank_start-1.
10470 * On gen2 the scanline counter starts counting from 1 instead
10471 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
10472 * to keep the value positive), instead of adding one.
10474 * On HSW+ the behaviour of the scanline counter depends on the output
10475 * type. For DP ports it behaves like most other platforms, but on HDMI
10476 * there's an extra 1 line difference. So we need to add two instead of
10477 * one to the value.
10479 if (IS_GEN2(dev
)) {
10480 const struct drm_display_mode
*mode
= &crtc
->config
.adjusted_mode
;
10483 vtotal
= mode
->crtc_vtotal
;
10484 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
10487 crtc
->scanline_offset
= vtotal
- 1;
10488 } else if (HAS_DDI(dev
) &&
10489 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
)) {
10490 crtc
->scanline_offset
= 2;
10492 crtc
->scanline_offset
= 1;
10495 static int __intel_set_mode(struct drm_crtc
*crtc
,
10496 struct drm_display_mode
*mode
,
10497 int x
, int y
, struct drm_framebuffer
*fb
)
10499 struct drm_device
*dev
= crtc
->dev
;
10500 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10501 struct drm_display_mode
*saved_mode
;
10502 struct intel_crtc_config
*pipe_config
= NULL
;
10503 struct intel_crtc
*intel_crtc
;
10504 unsigned disable_pipes
, prepare_pipes
, modeset_pipes
;
10507 saved_mode
= kmalloc(sizeof(*saved_mode
), GFP_KERNEL
);
10511 intel_modeset_affected_pipes(crtc
, &modeset_pipes
,
10512 &prepare_pipes
, &disable_pipes
);
10514 *saved_mode
= crtc
->mode
;
10516 /* Hack: Because we don't (yet) support global modeset on multiple
10517 * crtcs, we don't keep track of the new mode for more than one crtc.
10518 * Hence simply check whether any bit is set in modeset_pipes in all the
10519 * pieces of code that are not yet converted to deal with mutliple crtcs
10520 * changing their mode at the same time. */
10521 if (modeset_pipes
) {
10522 pipe_config
= intel_modeset_pipe_config(crtc
, fb
, mode
);
10523 if (IS_ERR(pipe_config
)) {
10524 ret
= PTR_ERR(pipe_config
);
10525 pipe_config
= NULL
;
10529 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
10531 to_intel_crtc(crtc
)->new_config
= pipe_config
;
10535 * See if the config requires any additional preparation, e.g.
10536 * to adjust global state with pipes off. We need to do this
10537 * here so we can get the modeset_pipe updated config for the new
10538 * mode set on this crtc. For other crtcs we need to use the
10539 * adjusted_mode bits in the crtc directly.
10541 if (IS_VALLEYVIEW(dev
)) {
10542 valleyview_modeset_global_pipes(dev
, &prepare_pipes
);
10544 /* may have added more to prepare_pipes than we should */
10545 prepare_pipes
&= ~disable_pipes
;
10548 for_each_intel_crtc_masked(dev
, disable_pipes
, intel_crtc
)
10549 intel_crtc_disable(&intel_crtc
->base
);
10551 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
10552 if (intel_crtc
->base
.enabled
)
10553 dev_priv
->display
.crtc_disable(&intel_crtc
->base
);
10556 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
10557 * to set it here already despite that we pass it down the callchain.
10559 if (modeset_pipes
) {
10560 crtc
->mode
= *mode
;
10561 /* mode_set/enable/disable functions rely on a correct pipe
10563 to_intel_crtc(crtc
)->config
= *pipe_config
;
10564 to_intel_crtc(crtc
)->new_config
= &to_intel_crtc(crtc
)->config
;
10567 * Calculate and store various constants which
10568 * are later needed by vblank and swap-completion
10569 * timestamping. They are derived from true hwmode.
10571 drm_calc_timestamping_constants(crtc
,
10572 &pipe_config
->adjusted_mode
);
10575 /* Only after disabling all output pipelines that will be changed can we
10576 * update the the output configuration. */
10577 intel_modeset_update_state(dev
, prepare_pipes
);
10579 if (dev_priv
->display
.modeset_global_resources
)
10580 dev_priv
->display
.modeset_global_resources(dev
);
10582 /* Set up the DPLL and any encoders state that needs to adjust or depend
10585 for_each_intel_crtc_masked(dev
, modeset_pipes
, intel_crtc
) {
10586 struct drm_framebuffer
*old_fb
;
10587 struct drm_i915_gem_object
*old_obj
= NULL
;
10588 struct drm_i915_gem_object
*obj
=
10589 to_intel_framebuffer(fb
)->obj
;
10591 mutex_lock(&dev
->struct_mutex
);
10592 ret
= intel_pin_and_fence_fb_obj(dev
,
10596 DRM_ERROR("pin & fence failed\n");
10597 mutex_unlock(&dev
->struct_mutex
);
10600 old_fb
= crtc
->primary
->fb
;
10602 old_obj
= to_intel_framebuffer(old_fb
)->obj
;
10603 intel_unpin_fb_obj(old_obj
);
10605 i915_gem_track_fb(old_obj
, obj
,
10606 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
10607 mutex_unlock(&dev
->struct_mutex
);
10609 crtc
->primary
->fb
= fb
;
10613 ret
= dev_priv
->display
.crtc_mode_set(&intel_crtc
->base
,
10619 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
10620 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
10621 update_scanline_offset(intel_crtc
);
10623 dev_priv
->display
.crtc_enable(&intel_crtc
->base
);
10626 /* FIXME: add subpixel order */
10628 if (ret
&& crtc
->enabled
)
10629 crtc
->mode
= *saved_mode
;
10632 kfree(pipe_config
);
10637 static int intel_set_mode(struct drm_crtc
*crtc
,
10638 struct drm_display_mode
*mode
,
10639 int x
, int y
, struct drm_framebuffer
*fb
)
10643 ret
= __intel_set_mode(crtc
, mode
, x
, y
, fb
);
10646 intel_modeset_check_state(crtc
->dev
);
10651 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
10653 intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
, crtc
->primary
->fb
);
10656 #undef for_each_intel_crtc_masked
10658 static void intel_set_config_free(struct intel_set_config
*config
)
10663 kfree(config
->save_connector_encoders
);
10664 kfree(config
->save_encoder_crtcs
);
10665 kfree(config
->save_crtc_enabled
);
10669 static int intel_set_config_save_state(struct drm_device
*dev
,
10670 struct intel_set_config
*config
)
10672 struct drm_crtc
*crtc
;
10673 struct drm_encoder
*encoder
;
10674 struct drm_connector
*connector
;
10677 config
->save_crtc_enabled
=
10678 kcalloc(dev
->mode_config
.num_crtc
,
10679 sizeof(bool), GFP_KERNEL
);
10680 if (!config
->save_crtc_enabled
)
10683 config
->save_encoder_crtcs
=
10684 kcalloc(dev
->mode_config
.num_encoder
,
10685 sizeof(struct drm_crtc
*), GFP_KERNEL
);
10686 if (!config
->save_encoder_crtcs
)
10689 config
->save_connector_encoders
=
10690 kcalloc(dev
->mode_config
.num_connector
,
10691 sizeof(struct drm_encoder
*), GFP_KERNEL
);
10692 if (!config
->save_connector_encoders
)
10695 /* Copy data. Note that driver private data is not affected.
10696 * Should anything bad happen only the expected state is
10697 * restored, not the drivers personal bookkeeping.
10700 for_each_crtc(dev
, crtc
) {
10701 config
->save_crtc_enabled
[count
++] = crtc
->enabled
;
10705 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
10706 config
->save_encoder_crtcs
[count
++] = encoder
->crtc
;
10710 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
10711 config
->save_connector_encoders
[count
++] = connector
->encoder
;
10717 static void intel_set_config_restore_state(struct drm_device
*dev
,
10718 struct intel_set_config
*config
)
10720 struct intel_crtc
*crtc
;
10721 struct intel_encoder
*encoder
;
10722 struct intel_connector
*connector
;
10726 for_each_intel_crtc(dev
, crtc
) {
10727 crtc
->new_enabled
= config
->save_crtc_enabled
[count
++];
10729 if (crtc
->new_enabled
)
10730 crtc
->new_config
= &crtc
->config
;
10732 crtc
->new_config
= NULL
;
10736 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
10737 encoder
->new_crtc
=
10738 to_intel_crtc(config
->save_encoder_crtcs
[count
++]);
10742 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
10743 connector
->new_encoder
=
10744 to_intel_encoder(config
->save_connector_encoders
[count
++]);
10749 is_crtc_connector_off(struct drm_mode_set
*set
)
10753 if (set
->num_connectors
== 0)
10756 if (WARN_ON(set
->connectors
== NULL
))
10759 for (i
= 0; i
< set
->num_connectors
; i
++)
10760 if (set
->connectors
[i
]->encoder
&&
10761 set
->connectors
[i
]->encoder
->crtc
== set
->crtc
&&
10762 set
->connectors
[i
]->dpms
!= DRM_MODE_DPMS_ON
)
10769 intel_set_config_compute_mode_changes(struct drm_mode_set
*set
,
10770 struct intel_set_config
*config
)
10773 /* We should be able to check here if the fb has the same properties
10774 * and then just flip_or_move it */
10775 if (is_crtc_connector_off(set
)) {
10776 config
->mode_changed
= true;
10777 } else if (set
->crtc
->primary
->fb
!= set
->fb
) {
10779 * If we have no fb, we can only flip as long as the crtc is
10780 * active, otherwise we need a full mode set. The crtc may
10781 * be active if we've only disabled the primary plane, or
10782 * in fastboot situations.
10784 if (set
->crtc
->primary
->fb
== NULL
) {
10785 struct intel_crtc
*intel_crtc
=
10786 to_intel_crtc(set
->crtc
);
10788 if (intel_crtc
->active
) {
10789 DRM_DEBUG_KMS("crtc has no fb, will flip\n");
10790 config
->fb_changed
= true;
10792 DRM_DEBUG_KMS("inactive crtc, full mode set\n");
10793 config
->mode_changed
= true;
10795 } else if (set
->fb
== NULL
) {
10796 config
->mode_changed
= true;
10797 } else if (set
->fb
->pixel_format
!=
10798 set
->crtc
->primary
->fb
->pixel_format
) {
10799 config
->mode_changed
= true;
10801 config
->fb_changed
= true;
10805 if (set
->fb
&& (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
))
10806 config
->fb_changed
= true;
10808 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
10809 DRM_DEBUG_KMS("modes are different, full mode set\n");
10810 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
10811 drm_mode_debug_printmodeline(set
->mode
);
10812 config
->mode_changed
= true;
10815 DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
10816 set
->crtc
->base
.id
, config
->mode_changed
, config
->fb_changed
);
10820 intel_modeset_stage_output_state(struct drm_device
*dev
,
10821 struct drm_mode_set
*set
,
10822 struct intel_set_config
*config
)
10824 struct intel_connector
*connector
;
10825 struct intel_encoder
*encoder
;
10826 struct intel_crtc
*crtc
;
10829 /* The upper layers ensure that we either disable a crtc or have a list
10830 * of connectors. For paranoia, double-check this. */
10831 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
10832 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
10834 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10836 /* Otherwise traverse passed in connector list and get encoders
10838 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
10839 if (set
->connectors
[ro
] == &connector
->base
) {
10840 connector
->new_encoder
= connector
->encoder
;
10845 /* If we disable the crtc, disable all its connectors. Also, if
10846 * the connector is on the changing crtc but not on the new
10847 * connector list, disable it. */
10848 if ((!set
->fb
|| ro
== set
->num_connectors
) &&
10849 connector
->base
.encoder
&&
10850 connector
->base
.encoder
->crtc
== set
->crtc
) {
10851 connector
->new_encoder
= NULL
;
10853 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
10854 connector
->base
.base
.id
,
10855 connector
->base
.name
);
10859 if (&connector
->new_encoder
->base
!= connector
->base
.encoder
) {
10860 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
10861 config
->mode_changed
= true;
10864 /* connector->new_encoder is now updated for all connectors. */
10866 /* Update crtc of enabled connectors. */
10867 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10869 struct drm_crtc
*new_crtc
;
10871 if (!connector
->new_encoder
)
10874 new_crtc
= connector
->new_encoder
->base
.crtc
;
10876 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
10877 if (set
->connectors
[ro
] == &connector
->base
)
10878 new_crtc
= set
->crtc
;
10881 /* Make sure the new CRTC will work with the encoder */
10882 if (!drm_encoder_crtc_ok(&connector
->new_encoder
->base
,
10886 connector
->encoder
->new_crtc
= to_intel_crtc(new_crtc
);
10888 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
10889 connector
->base
.base
.id
,
10890 connector
->base
.name
,
10891 new_crtc
->base
.id
);
10894 /* Check for any encoders that needs to be disabled. */
10895 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10897 int num_connectors
= 0;
10898 list_for_each_entry(connector
,
10899 &dev
->mode_config
.connector_list
,
10901 if (connector
->new_encoder
== encoder
) {
10902 WARN_ON(!connector
->new_encoder
->new_crtc
);
10907 if (num_connectors
== 0)
10908 encoder
->new_crtc
= NULL
;
10909 else if (num_connectors
> 1)
10912 /* Only now check for crtc changes so we don't miss encoders
10913 * that will be disabled. */
10914 if (&encoder
->new_crtc
->base
!= encoder
->base
.crtc
) {
10915 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
10916 config
->mode_changed
= true;
10919 /* Now we've also updated encoder->new_crtc for all encoders. */
10921 for_each_intel_crtc(dev
, crtc
) {
10922 crtc
->new_enabled
= false;
10924 list_for_each_entry(encoder
,
10925 &dev
->mode_config
.encoder_list
,
10927 if (encoder
->new_crtc
== crtc
) {
10928 crtc
->new_enabled
= true;
10933 if (crtc
->new_enabled
!= crtc
->base
.enabled
) {
10934 DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
10935 crtc
->new_enabled
? "en" : "dis");
10936 config
->mode_changed
= true;
10939 if (crtc
->new_enabled
)
10940 crtc
->new_config
= &crtc
->config
;
10942 crtc
->new_config
= NULL
;
10948 static void disable_crtc_nofb(struct intel_crtc
*crtc
)
10950 struct drm_device
*dev
= crtc
->base
.dev
;
10951 struct intel_encoder
*encoder
;
10952 struct intel_connector
*connector
;
10954 DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
10955 pipe_name(crtc
->pipe
));
10957 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
10958 if (connector
->new_encoder
&&
10959 connector
->new_encoder
->new_crtc
== crtc
)
10960 connector
->new_encoder
= NULL
;
10963 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
10964 if (encoder
->new_crtc
== crtc
)
10965 encoder
->new_crtc
= NULL
;
10968 crtc
->new_enabled
= false;
10969 crtc
->new_config
= NULL
;
10972 static int intel_crtc_set_config(struct drm_mode_set
*set
)
10974 struct drm_device
*dev
;
10975 struct drm_mode_set save_set
;
10976 struct intel_set_config
*config
;
10980 BUG_ON(!set
->crtc
);
10981 BUG_ON(!set
->crtc
->helper_private
);
10983 /* Enforce sane interface api - has been abused by the fb helper. */
10984 BUG_ON(!set
->mode
&& set
->fb
);
10985 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
10988 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
10989 set
->crtc
->base
.id
, set
->fb
->base
.id
,
10990 (int)set
->num_connectors
, set
->x
, set
->y
);
10992 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
10995 dev
= set
->crtc
->dev
;
10998 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
11002 ret
= intel_set_config_save_state(dev
, config
);
11006 save_set
.crtc
= set
->crtc
;
11007 save_set
.mode
= &set
->crtc
->mode
;
11008 save_set
.x
= set
->crtc
->x
;
11009 save_set
.y
= set
->crtc
->y
;
11010 save_set
.fb
= set
->crtc
->primary
->fb
;
11012 /* Compute whether we need a full modeset, only an fb base update or no
11013 * change at all. In the future we might also check whether only the
11014 * mode changed, e.g. for LVDS where we only change the panel fitter in
11016 intel_set_config_compute_mode_changes(set
, config
);
11018 ret
= intel_modeset_stage_output_state(dev
, set
, config
);
11022 if (config
->mode_changed
) {
11023 ret
= intel_set_mode(set
->crtc
, set
->mode
,
11024 set
->x
, set
->y
, set
->fb
);
11025 } else if (config
->fb_changed
) {
11026 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11027 struct intel_crtc
*intel_crtc
= to_intel_crtc(set
->crtc
);
11029 intel_crtc_wait_for_pending_flips(set
->crtc
);
11031 ret
= intel_pipe_set_base(set
->crtc
,
11032 set
->x
, set
->y
, set
->fb
);
11035 * We need to make sure the primary plane is re-enabled if it
11036 * has previously been turned off.
11038 if (!intel_crtc
->primary_enabled
&& ret
== 0) {
11039 WARN_ON(!intel_crtc
->active
);
11040 intel_enable_primary_hw_plane(dev_priv
, intel_crtc
->plane
,
11045 * In the fastboot case this may be our only check of the
11046 * state after boot. It would be better to only do it on
11047 * the first update, but we don't have a nice way of doing that
11048 * (and really, set_config isn't used much for high freq page
11049 * flipping, so increasing its cost here shouldn't be a big
11052 if (i915
.fastboot
&& ret
== 0)
11053 intel_modeset_check_state(set
->crtc
->dev
);
11057 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
11058 set
->crtc
->base
.id
, ret
);
11060 intel_set_config_restore_state(dev
, config
);
11063 * HACK: if the pipe was on, but we didn't have a framebuffer,
11064 * force the pipe off to avoid oopsing in the modeset code
11065 * due to fb==NULL. This should only happen during boot since
11066 * we don't yet reconstruct the FB from the hardware state.
11068 if (to_intel_crtc(save_set
.crtc
)->new_enabled
&& !save_set
.fb
)
11069 disable_crtc_nofb(to_intel_crtc(save_set
.crtc
));
11071 /* Try to restore the config */
11072 if (config
->mode_changed
&&
11073 intel_set_mode(save_set
.crtc
, save_set
.mode
,
11074 save_set
.x
, save_set
.y
, save_set
.fb
))
11075 DRM_ERROR("failed to restore config after modeset failure\n");
11079 intel_set_config_free(config
);
11083 static const struct drm_crtc_funcs intel_crtc_funcs
= {
11084 .gamma_set
= intel_crtc_gamma_set
,
11085 .set_config
= intel_crtc_set_config
,
11086 .destroy
= intel_crtc_destroy
,
11087 .page_flip
= intel_crtc_page_flip
,
11090 static void intel_cpu_pll_init(struct drm_device
*dev
)
11093 intel_ddi_pll_init(dev
);
11096 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private
*dev_priv
,
11097 struct intel_shared_dpll
*pll
,
11098 struct intel_dpll_hw_state
*hw_state
)
11102 val
= I915_READ(PCH_DPLL(pll
->id
));
11103 hw_state
->dpll
= val
;
11104 hw_state
->fp0
= I915_READ(PCH_FP0(pll
->id
));
11105 hw_state
->fp1
= I915_READ(PCH_FP1(pll
->id
));
11107 return val
& DPLL_VCO_ENABLE
;
11110 static void ibx_pch_dpll_mode_set(struct drm_i915_private
*dev_priv
,
11111 struct intel_shared_dpll
*pll
)
11113 I915_WRITE(PCH_FP0(pll
->id
), pll
->hw_state
.fp0
);
11114 I915_WRITE(PCH_FP1(pll
->id
), pll
->hw_state
.fp1
);
11117 static void ibx_pch_dpll_enable(struct drm_i915_private
*dev_priv
,
11118 struct intel_shared_dpll
*pll
)
11120 /* PCH refclock must be enabled first */
11121 ibx_assert_pch_refclk_enabled(dev_priv
);
11123 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11125 /* Wait for the clocks to stabilize. */
11126 POSTING_READ(PCH_DPLL(pll
->id
));
11129 /* The pixel multiplier can only be updated once the
11130 * DPLL is enabled and the clocks are stable.
11132 * So write it again.
11134 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11135 POSTING_READ(PCH_DPLL(pll
->id
));
11139 static void ibx_pch_dpll_disable(struct drm_i915_private
*dev_priv
,
11140 struct intel_shared_dpll
*pll
)
11142 struct drm_device
*dev
= dev_priv
->dev
;
11143 struct intel_crtc
*crtc
;
11145 /* Make sure no transcoder isn't still depending on us. */
11146 for_each_intel_crtc(dev
, crtc
) {
11147 if (intel_crtc_to_shared_dpll(crtc
) == pll
)
11148 assert_pch_transcoder_disabled(dev_priv
, crtc
->pipe
);
11151 I915_WRITE(PCH_DPLL(pll
->id
), 0);
11152 POSTING_READ(PCH_DPLL(pll
->id
));
11156 static char *ibx_pch_dpll_names
[] = {
11161 static void ibx_pch_dpll_init(struct drm_device
*dev
)
11163 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11166 dev_priv
->num_shared_dpll
= 2;
11168 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
11169 dev_priv
->shared_dplls
[i
].id
= i
;
11170 dev_priv
->shared_dplls
[i
].name
= ibx_pch_dpll_names
[i
];
11171 dev_priv
->shared_dplls
[i
].mode_set
= ibx_pch_dpll_mode_set
;
11172 dev_priv
->shared_dplls
[i
].enable
= ibx_pch_dpll_enable
;
11173 dev_priv
->shared_dplls
[i
].disable
= ibx_pch_dpll_disable
;
11174 dev_priv
->shared_dplls
[i
].get_hw_state
=
11175 ibx_pch_dpll_get_hw_state
;
11179 static void intel_shared_dpll_init(struct drm_device
*dev
)
11181 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11183 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
11184 ibx_pch_dpll_init(dev
);
11186 dev_priv
->num_shared_dpll
= 0;
11188 BUG_ON(dev_priv
->num_shared_dpll
> I915_NUM_PLLS
);
11192 intel_primary_plane_disable(struct drm_plane
*plane
)
11194 struct drm_device
*dev
= plane
->dev
;
11195 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11196 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11197 struct intel_crtc
*intel_crtc
;
11202 BUG_ON(!plane
->crtc
);
11204 intel_crtc
= to_intel_crtc(plane
->crtc
);
11207 * Even though we checked plane->fb above, it's still possible that
11208 * the primary plane has been implicitly disabled because the crtc
11209 * coordinates given weren't visible, or because we detected
11210 * that it was 100% covered by a sprite plane. Or, the CRTC may be
11211 * off and we've set a fb, but haven't actually turned on the CRTC yet.
11212 * In either case, we need to unpin the FB and let the fb pointer get
11213 * updated, but otherwise we don't need to touch the hardware.
11215 if (!intel_crtc
->primary_enabled
)
11216 goto disable_unpin
;
11218 intel_crtc_wait_for_pending_flips(plane
->crtc
);
11219 intel_disable_primary_hw_plane(dev_priv
, intel_plane
->plane
,
11220 intel_plane
->pipe
);
11222 i915_gem_track_fb(to_intel_framebuffer(plane
->fb
)->obj
, NULL
,
11223 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11224 intel_unpin_fb_obj(to_intel_framebuffer(plane
->fb
)->obj
);
11231 intel_primary_plane_setplane(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11232 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11233 unsigned int crtc_w
, unsigned int crtc_h
,
11234 uint32_t src_x
, uint32_t src_y
,
11235 uint32_t src_w
, uint32_t src_h
)
11237 struct drm_device
*dev
= crtc
->dev
;
11238 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11239 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11240 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11241 struct drm_i915_gem_object
*obj
, *old_obj
= NULL
;
11242 struct drm_rect dest
= {
11243 /* integer pixels */
11246 .x2
= crtc_x
+ crtc_w
,
11247 .y2
= crtc_y
+ crtc_h
,
11249 struct drm_rect src
= {
11250 /* 16.16 fixed point */
11253 .x2
= src_x
+ src_w
,
11254 .y2
= src_y
+ src_h
,
11256 const struct drm_rect clip
= {
11257 /* integer pixels */
11258 .x2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_w
: 0,
11259 .y2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_h
: 0,
11264 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
11265 &src
, &dest
, &clip
,
11266 DRM_PLANE_HELPER_NO_SCALING
,
11267 DRM_PLANE_HELPER_NO_SCALING
,
11268 false, true, &visible
);
11274 old_obj
= to_intel_framebuffer(plane
->fb
)->obj
;
11275 obj
= to_intel_framebuffer(fb
)->obj
;
11278 * If the CRTC isn't enabled, we're just pinning the framebuffer,
11279 * updating the fb pointer, and returning without touching the
11280 * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
11281 * turn on the display with all planes setup as desired.
11283 if (!crtc
->enabled
) {
11285 * If we already called setplane while the crtc was disabled,
11286 * we may have an fb pinned; unpin it.
11289 intel_unpin_fb_obj(old_obj
);
11291 i915_gem_track_fb(old_obj
, obj
,
11292 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11294 /* Pin and return without programming hardware */
11295 return intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
11298 intel_crtc_wait_for_pending_flips(crtc
);
11301 * If clipping results in a non-visible primary plane, we'll disable
11302 * the primary plane. Note that this is a bit different than what
11303 * happens if userspace explicitly disables the plane by passing fb=0
11304 * because plane->fb still gets set and pinned.
11308 * Try to pin the new fb first so that we can bail out if we
11311 if (plane
->fb
!= fb
) {
11312 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
11317 i915_gem_track_fb(old_obj
, obj
,
11318 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11320 if (intel_crtc
->primary_enabled
)
11321 intel_disable_primary_hw_plane(dev_priv
,
11322 intel_plane
->plane
,
11323 intel_plane
->pipe
);
11326 if (plane
->fb
!= fb
)
11328 intel_unpin_fb_obj(old_obj
);
11333 ret
= intel_pipe_set_base(crtc
, src
.x1
, src
.y1
, fb
);
11337 if (!intel_crtc
->primary_enabled
)
11338 intel_enable_primary_hw_plane(dev_priv
, intel_crtc
->plane
,
11344 /* Common destruction function for both primary and cursor planes */
11345 static void intel_plane_destroy(struct drm_plane
*plane
)
11347 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11348 drm_plane_cleanup(plane
);
11349 kfree(intel_plane
);
11352 static const struct drm_plane_funcs intel_primary_plane_funcs
= {
11353 .update_plane
= intel_primary_plane_setplane
,
11354 .disable_plane
= intel_primary_plane_disable
,
11355 .destroy
= intel_plane_destroy
,
11358 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
11361 struct intel_plane
*primary
;
11362 const uint32_t *intel_primary_formats
;
11365 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
11366 if (primary
== NULL
)
11369 primary
->can_scale
= false;
11370 primary
->max_downscale
= 1;
11371 primary
->pipe
= pipe
;
11372 primary
->plane
= pipe
;
11373 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
11374 primary
->plane
= !pipe
;
11376 if (INTEL_INFO(dev
)->gen
<= 3) {
11377 intel_primary_formats
= intel_primary_formats_gen2
;
11378 num_formats
= ARRAY_SIZE(intel_primary_formats_gen2
);
11380 intel_primary_formats
= intel_primary_formats_gen4
;
11381 num_formats
= ARRAY_SIZE(intel_primary_formats_gen4
);
11384 drm_universal_plane_init(dev
, &primary
->base
, 0,
11385 &intel_primary_plane_funcs
,
11386 intel_primary_formats
, num_formats
,
11387 DRM_PLANE_TYPE_PRIMARY
);
11388 return &primary
->base
;
11392 intel_cursor_plane_disable(struct drm_plane
*plane
)
11397 BUG_ON(!plane
->crtc
);
11399 return intel_crtc_cursor_set_obj(plane
->crtc
, NULL
, 0, 0);
11403 intel_cursor_plane_update(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11404 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11405 unsigned int crtc_w
, unsigned int crtc_h
,
11406 uint32_t src_x
, uint32_t src_y
,
11407 uint32_t src_w
, uint32_t src_h
)
11409 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11410 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11411 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11412 struct drm_rect dest
= {
11413 /* integer pixels */
11416 .x2
= crtc_x
+ crtc_w
,
11417 .y2
= crtc_y
+ crtc_h
,
11419 struct drm_rect src
= {
11420 /* 16.16 fixed point */
11423 .x2
= src_x
+ src_w
,
11424 .y2
= src_y
+ src_h
,
11426 const struct drm_rect clip
= {
11427 /* integer pixels */
11428 .x2
= intel_crtc
->config
.pipe_src_w
,
11429 .y2
= intel_crtc
->config
.pipe_src_h
,
11434 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
11435 &src
, &dest
, &clip
,
11436 DRM_PLANE_HELPER_NO_SCALING
,
11437 DRM_PLANE_HELPER_NO_SCALING
,
11438 true, true, &visible
);
11442 crtc
->cursor_x
= crtc_x
;
11443 crtc
->cursor_y
= crtc_y
;
11444 if (fb
!= crtc
->cursor
->fb
) {
11445 return intel_crtc_cursor_set_obj(crtc
, obj
, crtc_w
, crtc_h
);
11447 intel_crtc_update_cursor(crtc
, visible
);
11451 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
11452 .update_plane
= intel_cursor_plane_update
,
11453 .disable_plane
= intel_cursor_plane_disable
,
11454 .destroy
= intel_plane_destroy
,
11457 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
11460 struct intel_plane
*cursor
;
11462 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
11463 if (cursor
== NULL
)
11466 cursor
->can_scale
= false;
11467 cursor
->max_downscale
= 1;
11468 cursor
->pipe
= pipe
;
11469 cursor
->plane
= pipe
;
11471 drm_universal_plane_init(dev
, &cursor
->base
, 0,
11472 &intel_cursor_plane_funcs
,
11473 intel_cursor_formats
,
11474 ARRAY_SIZE(intel_cursor_formats
),
11475 DRM_PLANE_TYPE_CURSOR
);
11476 return &cursor
->base
;
11479 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
11481 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11482 struct intel_crtc
*intel_crtc
;
11483 struct drm_plane
*primary
= NULL
;
11484 struct drm_plane
*cursor
= NULL
;
11487 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
11488 if (intel_crtc
== NULL
)
11491 primary
= intel_primary_plane_create(dev
, pipe
);
11495 cursor
= intel_cursor_plane_create(dev
, pipe
);
11499 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
11500 cursor
, &intel_crtc_funcs
);
11504 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
11505 for (i
= 0; i
< 256; i
++) {
11506 intel_crtc
->lut_r
[i
] = i
;
11507 intel_crtc
->lut_g
[i
] = i
;
11508 intel_crtc
->lut_b
[i
] = i
;
11512 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
11513 * is hooked to pipe B. Hence we want plane A feeding pipe B.
11515 intel_crtc
->pipe
= pipe
;
11516 intel_crtc
->plane
= pipe
;
11517 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
11518 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
11519 intel_crtc
->plane
= !pipe
;
11522 intel_crtc
->cursor_base
= ~0;
11523 intel_crtc
->cursor_cntl
= ~0;
11525 init_waitqueue_head(&intel_crtc
->vbl_wait
);
11527 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
11528 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
11529 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
11530 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
11532 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
11534 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
11539 drm_plane_cleanup(primary
);
11541 drm_plane_cleanup(cursor
);
11545 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
11547 struct drm_encoder
*encoder
= connector
->base
.encoder
;
11548 struct drm_device
*dev
= connector
->base
.dev
;
11550 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
11553 return INVALID_PIPE
;
11555 return to_intel_crtc(encoder
->crtc
)->pipe
;
11558 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
11559 struct drm_file
*file
)
11561 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
11562 struct drm_mode_object
*drmmode_obj
;
11563 struct intel_crtc
*crtc
;
11565 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
11568 drmmode_obj
= drm_mode_object_find(dev
, pipe_from_crtc_id
->crtc_id
,
11569 DRM_MODE_OBJECT_CRTC
);
11571 if (!drmmode_obj
) {
11572 DRM_ERROR("no such CRTC id\n");
11576 crtc
= to_intel_crtc(obj_to_crtc(drmmode_obj
));
11577 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
11582 static int intel_encoder_clones(struct intel_encoder
*encoder
)
11584 struct drm_device
*dev
= encoder
->base
.dev
;
11585 struct intel_encoder
*source_encoder
;
11586 int index_mask
= 0;
11589 list_for_each_entry(source_encoder
,
11590 &dev
->mode_config
.encoder_list
, base
.head
) {
11591 if (encoders_cloneable(encoder
, source_encoder
))
11592 index_mask
|= (1 << entry
);
11600 static bool has_edp_a(struct drm_device
*dev
)
11602 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11604 if (!IS_MOBILE(dev
))
11607 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
11610 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
11616 const char *intel_output_name(int output
)
11618 static const char *names
[] = {
11619 [INTEL_OUTPUT_UNUSED
] = "Unused",
11620 [INTEL_OUTPUT_ANALOG
] = "Analog",
11621 [INTEL_OUTPUT_DVO
] = "DVO",
11622 [INTEL_OUTPUT_SDVO
] = "SDVO",
11623 [INTEL_OUTPUT_LVDS
] = "LVDS",
11624 [INTEL_OUTPUT_TVOUT
] = "TV",
11625 [INTEL_OUTPUT_HDMI
] = "HDMI",
11626 [INTEL_OUTPUT_DISPLAYPORT
] = "DisplayPort",
11627 [INTEL_OUTPUT_EDP
] = "eDP",
11628 [INTEL_OUTPUT_DSI
] = "DSI",
11629 [INTEL_OUTPUT_UNKNOWN
] = "Unknown",
11632 if (output
< 0 || output
>= ARRAY_SIZE(names
) || !names
[output
])
11635 return names
[output
];
11638 static void intel_setup_outputs(struct drm_device
*dev
)
11640 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11641 struct intel_encoder
*encoder
;
11642 bool dpd_is_edp
= false;
11644 intel_lvds_init(dev
);
11646 if (!IS_ULT(dev
) && !IS_CHERRYVIEW(dev
) && dev_priv
->vbt
.int_crt_support
)
11647 intel_crt_init(dev
);
11649 if (HAS_DDI(dev
)) {
11652 /* Haswell uses DDI functions to detect digital outputs */
11653 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
11654 /* DDI A only supports eDP */
11656 intel_ddi_init(dev
, PORT_A
);
11658 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
11660 found
= I915_READ(SFUSE_STRAP
);
11662 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
11663 intel_ddi_init(dev
, PORT_B
);
11664 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
11665 intel_ddi_init(dev
, PORT_C
);
11666 if (found
& SFUSE_STRAP_DDID_DETECTED
)
11667 intel_ddi_init(dev
, PORT_D
);
11668 } else if (HAS_PCH_SPLIT(dev
)) {
11670 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
11672 if (has_edp_a(dev
))
11673 intel_dp_init(dev
, DP_A
, PORT_A
);
11675 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
11676 /* PCH SDVOB multiplex with HDMIB */
11677 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
11679 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
11680 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
11681 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
11684 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
11685 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
11687 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
11688 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
11690 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
11691 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
11693 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
11694 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
11695 } else if (IS_VALLEYVIEW(dev
)) {
11696 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
) {
11697 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
11699 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
)
11700 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
11703 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIC
) & SDVO_DETECTED
) {
11704 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIC
,
11706 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
)
11707 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
11710 if (IS_CHERRYVIEW(dev
)) {
11711 if (I915_READ(VLV_DISPLAY_BASE
+ CHV_HDMID
) & SDVO_DETECTED
) {
11712 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ CHV_HDMID
,
11714 if (I915_READ(VLV_DISPLAY_BASE
+ DP_D
) & DP_DETECTED
)
11715 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_D
, PORT_D
);
11719 intel_dsi_init(dev
);
11720 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
11721 bool found
= false;
11723 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
11724 DRM_DEBUG_KMS("probing SDVOB\n");
11725 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
11726 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
11727 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
11728 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
11731 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
))
11732 intel_dp_init(dev
, DP_B
, PORT_B
);
11735 /* Before G4X SDVOC doesn't have its own detect register */
11737 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
11738 DRM_DEBUG_KMS("probing SDVOC\n");
11739 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
11742 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
11744 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
11745 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
11746 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
11748 if (SUPPORTS_INTEGRATED_DP(dev
))
11749 intel_dp_init(dev
, DP_C
, PORT_C
);
11752 if (SUPPORTS_INTEGRATED_DP(dev
) &&
11753 (I915_READ(DP_D
) & DP_DETECTED
))
11754 intel_dp_init(dev
, DP_D
, PORT_D
);
11755 } else if (IS_GEN2(dev
))
11756 intel_dvo_init(dev
);
11758 if (SUPPORTS_TV(dev
))
11759 intel_tv_init(dev
);
11761 intel_edp_psr_init(dev
);
11763 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
11764 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
11765 encoder
->base
.possible_clones
=
11766 intel_encoder_clones(encoder
);
11769 intel_init_pch_refclk(dev
);
11771 drm_helper_move_panel_connectors_to_head(dev
);
11774 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
11776 struct drm_device
*dev
= fb
->dev
;
11777 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11779 drm_framebuffer_cleanup(fb
);
11780 mutex_lock(&dev
->struct_mutex
);
11781 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
11782 drm_gem_object_unreference(&intel_fb
->obj
->base
);
11783 mutex_unlock(&dev
->struct_mutex
);
11787 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
11788 struct drm_file
*file
,
11789 unsigned int *handle
)
11791 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11792 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11794 return drm_gem_handle_create(file
, &obj
->base
, handle
);
11797 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
11798 .destroy
= intel_user_framebuffer_destroy
,
11799 .create_handle
= intel_user_framebuffer_create_handle
,
11802 static int intel_framebuffer_init(struct drm_device
*dev
,
11803 struct intel_framebuffer
*intel_fb
,
11804 struct drm_mode_fb_cmd2
*mode_cmd
,
11805 struct drm_i915_gem_object
*obj
)
11807 int aligned_height
;
11811 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
11813 if (obj
->tiling_mode
== I915_TILING_Y
) {
11814 DRM_DEBUG("hardware does not support tiling Y\n");
11818 if (mode_cmd
->pitches
[0] & 63) {
11819 DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
11820 mode_cmd
->pitches
[0]);
11824 if (INTEL_INFO(dev
)->gen
>= 5 && !IS_VALLEYVIEW(dev
)) {
11825 pitch_limit
= 32*1024;
11826 } else if (INTEL_INFO(dev
)->gen
>= 4) {
11827 if (obj
->tiling_mode
)
11828 pitch_limit
= 16*1024;
11830 pitch_limit
= 32*1024;
11831 } else if (INTEL_INFO(dev
)->gen
>= 3) {
11832 if (obj
->tiling_mode
)
11833 pitch_limit
= 8*1024;
11835 pitch_limit
= 16*1024;
11837 /* XXX DSPC is limited to 4k tiled */
11838 pitch_limit
= 8*1024;
11840 if (mode_cmd
->pitches
[0] > pitch_limit
) {
11841 DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
11842 obj
->tiling_mode
? "tiled" : "linear",
11843 mode_cmd
->pitches
[0], pitch_limit
);
11847 if (obj
->tiling_mode
!= I915_TILING_NONE
&&
11848 mode_cmd
->pitches
[0] != obj
->stride
) {
11849 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
11850 mode_cmd
->pitches
[0], obj
->stride
);
11854 /* Reject formats not supported by any plane early. */
11855 switch (mode_cmd
->pixel_format
) {
11856 case DRM_FORMAT_C8
:
11857 case DRM_FORMAT_RGB565
:
11858 case DRM_FORMAT_XRGB8888
:
11859 case DRM_FORMAT_ARGB8888
:
11861 case DRM_FORMAT_XRGB1555
:
11862 case DRM_FORMAT_ARGB1555
:
11863 if (INTEL_INFO(dev
)->gen
> 3) {
11864 DRM_DEBUG("unsupported pixel format: %s\n",
11865 drm_get_format_name(mode_cmd
->pixel_format
));
11869 case DRM_FORMAT_XBGR8888
:
11870 case DRM_FORMAT_ABGR8888
:
11871 case DRM_FORMAT_XRGB2101010
:
11872 case DRM_FORMAT_ARGB2101010
:
11873 case DRM_FORMAT_XBGR2101010
:
11874 case DRM_FORMAT_ABGR2101010
:
11875 if (INTEL_INFO(dev
)->gen
< 4) {
11876 DRM_DEBUG("unsupported pixel format: %s\n",
11877 drm_get_format_name(mode_cmd
->pixel_format
));
11881 case DRM_FORMAT_YUYV
:
11882 case DRM_FORMAT_UYVY
:
11883 case DRM_FORMAT_YVYU
:
11884 case DRM_FORMAT_VYUY
:
11885 if (INTEL_INFO(dev
)->gen
< 5) {
11886 DRM_DEBUG("unsupported pixel format: %s\n",
11887 drm_get_format_name(mode_cmd
->pixel_format
));
11892 DRM_DEBUG("unsupported pixel format: %s\n",
11893 drm_get_format_name(mode_cmd
->pixel_format
));
11897 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
11898 if (mode_cmd
->offsets
[0] != 0)
11901 aligned_height
= intel_align_height(dev
, mode_cmd
->height
,
11903 /* FIXME drm helper for size checks (especially planar formats)? */
11904 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
11907 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
11908 intel_fb
->obj
= obj
;
11909 intel_fb
->obj
->framebuffer_references
++;
11911 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
11913 DRM_ERROR("framebuffer init failed %d\n", ret
);
11920 static struct drm_framebuffer
*
11921 intel_user_framebuffer_create(struct drm_device
*dev
,
11922 struct drm_file
*filp
,
11923 struct drm_mode_fb_cmd2
*mode_cmd
)
11925 struct drm_i915_gem_object
*obj
;
11927 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
11928 mode_cmd
->handles
[0]));
11929 if (&obj
->base
== NULL
)
11930 return ERR_PTR(-ENOENT
);
11932 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
11935 #ifndef CONFIG_DRM_I915_FBDEV
11936 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
11941 static const struct drm_mode_config_funcs intel_mode_funcs
= {
11942 .fb_create
= intel_user_framebuffer_create
,
11943 .output_poll_changed
= intel_fbdev_output_poll_changed
,
11946 /* Set up chip specific display functions */
11947 static void intel_init_display(struct drm_device
*dev
)
11949 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11951 if (HAS_PCH_SPLIT(dev
) || IS_G4X(dev
))
11952 dev_priv
->display
.find_dpll
= g4x_find_best_dpll
;
11953 else if (IS_CHERRYVIEW(dev
))
11954 dev_priv
->display
.find_dpll
= chv_find_best_dpll
;
11955 else if (IS_VALLEYVIEW(dev
))
11956 dev_priv
->display
.find_dpll
= vlv_find_best_dpll
;
11957 else if (IS_PINEVIEW(dev
))
11958 dev_priv
->display
.find_dpll
= pnv_find_best_dpll
;
11960 dev_priv
->display
.find_dpll
= i9xx_find_best_dpll
;
11962 if (HAS_DDI(dev
)) {
11963 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
11964 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
11965 dev_priv
->display
.crtc_mode_set
= haswell_crtc_mode_set
;
11966 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
11967 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
11968 dev_priv
->display
.off
= haswell_crtc_off
;
11969 dev_priv
->display
.update_primary_plane
=
11970 ironlake_update_primary_plane
;
11971 } else if (HAS_PCH_SPLIT(dev
)) {
11972 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
11973 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
11974 dev_priv
->display
.crtc_mode_set
= ironlake_crtc_mode_set
;
11975 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
11976 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
11977 dev_priv
->display
.off
= ironlake_crtc_off
;
11978 dev_priv
->display
.update_primary_plane
=
11979 ironlake_update_primary_plane
;
11980 } else if (IS_VALLEYVIEW(dev
)) {
11981 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
11982 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
11983 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
11984 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
11985 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
11986 dev_priv
->display
.off
= i9xx_crtc_off
;
11987 dev_priv
->display
.update_primary_plane
=
11988 i9xx_update_primary_plane
;
11990 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
11991 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
11992 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
11993 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
11994 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
11995 dev_priv
->display
.off
= i9xx_crtc_off
;
11996 dev_priv
->display
.update_primary_plane
=
11997 i9xx_update_primary_plane
;
12000 /* Returns the core display clock speed */
12001 if (IS_VALLEYVIEW(dev
))
12002 dev_priv
->display
.get_display_clock_speed
=
12003 valleyview_get_display_clock_speed
;
12004 else if (IS_I945G(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
12005 dev_priv
->display
.get_display_clock_speed
=
12006 i945_get_display_clock_speed
;
12007 else if (IS_I915G(dev
))
12008 dev_priv
->display
.get_display_clock_speed
=
12009 i915_get_display_clock_speed
;
12010 else if (IS_I945GM(dev
) || IS_845G(dev
))
12011 dev_priv
->display
.get_display_clock_speed
=
12012 i9xx_misc_get_display_clock_speed
;
12013 else if (IS_PINEVIEW(dev
))
12014 dev_priv
->display
.get_display_clock_speed
=
12015 pnv_get_display_clock_speed
;
12016 else if (IS_I915GM(dev
))
12017 dev_priv
->display
.get_display_clock_speed
=
12018 i915gm_get_display_clock_speed
;
12019 else if (IS_I865G(dev
))
12020 dev_priv
->display
.get_display_clock_speed
=
12021 i865_get_display_clock_speed
;
12022 else if (IS_I85X(dev
))
12023 dev_priv
->display
.get_display_clock_speed
=
12024 i855_get_display_clock_speed
;
12025 else /* 852, 830 */
12026 dev_priv
->display
.get_display_clock_speed
=
12027 i830_get_display_clock_speed
;
12029 if (HAS_PCH_SPLIT(dev
)) {
12030 if (IS_GEN5(dev
)) {
12031 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
12032 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12033 } else if (IS_GEN6(dev
)) {
12034 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
12035 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12036 dev_priv
->display
.modeset_global_resources
=
12037 snb_modeset_global_resources
;
12038 } else if (IS_IVYBRIDGE(dev
)) {
12039 /* FIXME: detect B0+ stepping and use auto training */
12040 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
12041 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12042 dev_priv
->display
.modeset_global_resources
=
12043 ivb_modeset_global_resources
;
12044 } else if (IS_HASWELL(dev
) || IS_GEN8(dev
)) {
12045 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
12046 dev_priv
->display
.write_eld
= haswell_write_eld
;
12047 dev_priv
->display
.modeset_global_resources
=
12048 haswell_modeset_global_resources
;
12050 } else if (IS_G4X(dev
)) {
12051 dev_priv
->display
.write_eld
= g4x_write_eld
;
12052 } else if (IS_VALLEYVIEW(dev
)) {
12053 dev_priv
->display
.modeset_global_resources
=
12054 valleyview_modeset_global_resources
;
12055 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12058 /* Default just returns -ENODEV to indicate unsupported */
12059 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
12061 switch (INTEL_INFO(dev
)->gen
) {
12063 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
12067 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
12072 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
12076 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
12079 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
12080 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
12084 intel_panel_init_backlight_funcs(dev
);
12088 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
12089 * resume, or other times. This quirk makes sure that's the case for
12090 * affected systems.
12092 static void quirk_pipea_force(struct drm_device
*dev
)
12094 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12096 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
12097 DRM_INFO("applying pipe a force quirk\n");
12101 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
12103 static void quirk_ssc_force_disable(struct drm_device
*dev
)
12105 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12106 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
12107 DRM_INFO("applying lvds SSC disable quirk\n");
12111 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
12114 static void quirk_invert_brightness(struct drm_device
*dev
)
12116 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12117 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
12118 DRM_INFO("applying inverted panel brightness quirk\n");
12121 struct intel_quirk
{
12123 int subsystem_vendor
;
12124 int subsystem_device
;
12125 void (*hook
)(struct drm_device
*dev
);
12128 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
12129 struct intel_dmi_quirk
{
12130 void (*hook
)(struct drm_device
*dev
);
12131 const struct dmi_system_id (*dmi_id_list
)[];
12134 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
12136 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
12140 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
12142 .dmi_id_list
= &(const struct dmi_system_id
[]) {
12144 .callback
= intel_dmi_reverse_brightness
,
12145 .ident
= "NCR Corporation",
12146 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
12147 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
12150 { } /* terminating entry */
12152 .hook
= quirk_invert_brightness
,
12156 static struct intel_quirk intel_quirks
[] = {
12157 /* HP Mini needs pipe A force quirk (LP: #322104) */
12158 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force
},
12160 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
12161 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
12163 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
12164 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
12166 /* Lenovo U160 cannot use SSC on LVDS */
12167 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
12169 /* Sony Vaio Y cannot use SSC on LVDS */
12170 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
12172 /* Acer Aspire 5734Z must invert backlight brightness */
12173 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
12175 /* Acer/eMachines G725 */
12176 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
12178 /* Acer/eMachines e725 */
12179 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
12181 /* Acer/Packard Bell NCL20 */
12182 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
12184 /* Acer Aspire 4736Z */
12185 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
12187 /* Acer Aspire 5336 */
12188 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
12191 static void intel_init_quirks(struct drm_device
*dev
)
12193 struct pci_dev
*d
= dev
->pdev
;
12196 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
12197 struct intel_quirk
*q
= &intel_quirks
[i
];
12199 if (d
->device
== q
->device
&&
12200 (d
->subsystem_vendor
== q
->subsystem_vendor
||
12201 q
->subsystem_vendor
== PCI_ANY_ID
) &&
12202 (d
->subsystem_device
== q
->subsystem_device
||
12203 q
->subsystem_device
== PCI_ANY_ID
))
12206 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
12207 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
12208 intel_dmi_quirks
[i
].hook(dev
);
12212 /* Disable the VGA plane that we never use */
12213 static void i915_disable_vga(struct drm_device
*dev
)
12215 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12217 u32 vga_reg
= i915_vgacntrl_reg(dev
);
12219 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
12220 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12221 outb(SR01
, VGA_SR_INDEX
);
12222 sr1
= inb(VGA_SR_DATA
);
12223 outb(sr1
| 1<<5, VGA_SR_DATA
);
12224 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12227 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
12228 POSTING_READ(vga_reg
);
12231 void intel_modeset_init_hw(struct drm_device
*dev
)
12233 intel_prepare_ddi(dev
);
12235 intel_init_clock_gating(dev
);
12237 intel_reset_dpio(dev
);
12239 intel_enable_gt_powersave(dev
);
12242 void intel_modeset_suspend_hw(struct drm_device
*dev
)
12244 intel_suspend_hw(dev
);
12247 void intel_modeset_init(struct drm_device
*dev
)
12249 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12252 struct intel_crtc
*crtc
;
12254 drm_mode_config_init(dev
);
12256 dev
->mode_config
.min_width
= 0;
12257 dev
->mode_config
.min_height
= 0;
12259 dev
->mode_config
.preferred_depth
= 24;
12260 dev
->mode_config
.prefer_shadow
= 1;
12262 dev
->mode_config
.funcs
= &intel_mode_funcs
;
12264 intel_init_quirks(dev
);
12266 intel_init_pm(dev
);
12268 if (INTEL_INFO(dev
)->num_pipes
== 0)
12271 intel_init_display(dev
);
12273 if (IS_GEN2(dev
)) {
12274 dev
->mode_config
.max_width
= 2048;
12275 dev
->mode_config
.max_height
= 2048;
12276 } else if (IS_GEN3(dev
)) {
12277 dev
->mode_config
.max_width
= 4096;
12278 dev
->mode_config
.max_height
= 4096;
12280 dev
->mode_config
.max_width
= 8192;
12281 dev
->mode_config
.max_height
= 8192;
12284 if (IS_GEN2(dev
)) {
12285 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
12286 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
12288 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
12289 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
12292 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
12294 DRM_DEBUG_KMS("%d display pipe%s available.\n",
12295 INTEL_INFO(dev
)->num_pipes
,
12296 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
12298 for_each_pipe(pipe
) {
12299 intel_crtc_init(dev
, pipe
);
12300 for_each_sprite(pipe
, sprite
) {
12301 ret
= intel_plane_init(dev
, pipe
, sprite
);
12303 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
12304 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
12308 intel_init_dpio(dev
);
12309 intel_reset_dpio(dev
);
12311 intel_cpu_pll_init(dev
);
12312 intel_shared_dpll_init(dev
);
12314 /* Just disable it once at startup */
12315 i915_disable_vga(dev
);
12316 intel_setup_outputs(dev
);
12318 /* Just in case the BIOS is doing something questionable. */
12319 intel_disable_fbc(dev
);
12321 drm_modeset_lock_all(dev
);
12322 intel_modeset_setup_hw_state(dev
, false);
12323 drm_modeset_unlock_all(dev
);
12325 for_each_intel_crtc(dev
, crtc
) {
12330 * Note that reserving the BIOS fb up front prevents us
12331 * from stuffing other stolen allocations like the ring
12332 * on top. This prevents some ugliness at boot time, and
12333 * can even allow for smooth boot transitions if the BIOS
12334 * fb is large enough for the active pipe configuration.
12336 if (dev_priv
->display
.get_plane_config
) {
12337 dev_priv
->display
.get_plane_config(crtc
,
12338 &crtc
->plane_config
);
12340 * If the fb is shared between multiple heads, we'll
12341 * just get the first one.
12343 intel_find_plane_obj(crtc
, &crtc
->plane_config
);
12348 static void intel_enable_pipe_a(struct drm_device
*dev
)
12350 struct intel_connector
*connector
;
12351 struct drm_connector
*crt
= NULL
;
12352 struct intel_load_detect_pipe load_detect_temp
;
12353 struct drm_modeset_acquire_ctx ctx
;
12355 /* We can't just switch on the pipe A, we need to set things up with a
12356 * proper mode and output configuration. As a gross hack, enable pipe A
12357 * by enabling the load detect pipe once. */
12358 list_for_each_entry(connector
,
12359 &dev
->mode_config
.connector_list
,
12361 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
12362 crt
= &connector
->base
;
12370 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, &ctx
))
12371 intel_release_load_detect_pipe(crt
, &load_detect_temp
, &ctx
);
12377 intel_check_plane_mapping(struct intel_crtc
*crtc
)
12379 struct drm_device
*dev
= crtc
->base
.dev
;
12380 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12383 if (INTEL_INFO(dev
)->num_pipes
== 1)
12386 reg
= DSPCNTR(!crtc
->plane
);
12387 val
= I915_READ(reg
);
12389 if ((val
& DISPLAY_PLANE_ENABLE
) &&
12390 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
12396 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
12398 struct drm_device
*dev
= crtc
->base
.dev
;
12399 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12402 /* Clear any frame start delays used for debugging left by the BIOS */
12403 reg
= PIPECONF(crtc
->config
.cpu_transcoder
);
12404 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
12406 /* restore vblank interrupts to correct state */
12408 drm_vblank_on(dev
, crtc
->pipe
);
12410 drm_vblank_off(dev
, crtc
->pipe
);
12412 /* We need to sanitize the plane -> pipe mapping first because this will
12413 * disable the crtc (and hence change the state) if it is wrong. Note
12414 * that gen4+ has a fixed plane -> pipe mapping. */
12415 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
12416 struct intel_connector
*connector
;
12419 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
12420 crtc
->base
.base
.id
);
12422 /* Pipe has the wrong plane attached and the plane is active.
12423 * Temporarily change the plane mapping and disable everything
12425 plane
= crtc
->plane
;
12426 crtc
->plane
= !plane
;
12427 dev_priv
->display
.crtc_disable(&crtc
->base
);
12428 crtc
->plane
= plane
;
12430 /* ... and break all links. */
12431 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12433 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
12436 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12437 connector
->base
.encoder
= NULL
;
12439 /* multiple connectors may have the same encoder:
12440 * handle them and break crtc link separately */
12441 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12443 if (connector
->encoder
->base
.crtc
== &crtc
->base
) {
12444 connector
->encoder
->base
.crtc
= NULL
;
12445 connector
->encoder
->connectors_active
= false;
12448 WARN_ON(crtc
->active
);
12449 crtc
->base
.enabled
= false;
12452 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
12453 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
12454 /* BIOS forgot to enable pipe A, this mostly happens after
12455 * resume. Force-enable the pipe to fix this, the update_dpms
12456 * call below we restore the pipe to the right state, but leave
12457 * the required bits on. */
12458 intel_enable_pipe_a(dev
);
12461 /* Adjust the state of the output pipe according to whether we
12462 * have active connectors/encoders. */
12463 intel_crtc_update_dpms(&crtc
->base
);
12465 if (crtc
->active
!= crtc
->base
.enabled
) {
12466 struct intel_encoder
*encoder
;
12468 /* This can happen either due to bugs in the get_hw_state
12469 * functions or because the pipe is force-enabled due to the
12471 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
12472 crtc
->base
.base
.id
,
12473 crtc
->base
.enabled
? "enabled" : "disabled",
12474 crtc
->active
? "enabled" : "disabled");
12476 crtc
->base
.enabled
= crtc
->active
;
12478 /* Because we only establish the connector -> encoder ->
12479 * crtc links if something is active, this means the
12480 * crtc is now deactivated. Break the links. connector
12481 * -> encoder links are only establish when things are
12482 * actually up, hence no need to break them. */
12483 WARN_ON(crtc
->active
);
12485 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
12486 WARN_ON(encoder
->connectors_active
);
12487 encoder
->base
.crtc
= NULL
;
12491 if (crtc
->active
|| IS_VALLEYVIEW(dev
) || INTEL_INFO(dev
)->gen
< 5) {
12493 * We start out with underrun reporting disabled to avoid races.
12494 * For correct bookkeeping mark this on active crtcs.
12496 * Also on gmch platforms we dont have any hardware bits to
12497 * disable the underrun reporting. Which means we need to start
12498 * out with underrun reporting disabled also on inactive pipes,
12499 * since otherwise we'll complain about the garbage we read when
12500 * e.g. coming up after runtime pm.
12502 * No protection against concurrent access is required - at
12503 * worst a fifo underrun happens which also sets this to false.
12505 crtc
->cpu_fifo_underrun_disabled
= true;
12506 crtc
->pch_fifo_underrun_disabled
= true;
12508 update_scanline_offset(crtc
);
12512 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
12514 struct intel_connector
*connector
;
12515 struct drm_device
*dev
= encoder
->base
.dev
;
12517 /* We need to check both for a crtc link (meaning that the
12518 * encoder is active and trying to read from a pipe) and the
12519 * pipe itself being active. */
12520 bool has_active_crtc
= encoder
->base
.crtc
&&
12521 to_intel_crtc(encoder
->base
.crtc
)->active
;
12523 if (encoder
->connectors_active
&& !has_active_crtc
) {
12524 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
12525 encoder
->base
.base
.id
,
12526 encoder
->base
.name
);
12528 /* Connector is active, but has no active pipe. This is
12529 * fallout from our resume register restoring. Disable
12530 * the encoder manually again. */
12531 if (encoder
->base
.crtc
) {
12532 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
12533 encoder
->base
.base
.id
,
12534 encoder
->base
.name
);
12535 encoder
->disable(encoder
);
12537 encoder
->base
.crtc
= NULL
;
12538 encoder
->connectors_active
= false;
12540 /* Inconsistent output/port/pipe state happens presumably due to
12541 * a bug in one of the get_hw_state functions. Or someplace else
12542 * in our code, like the register restore mess on resume. Clamp
12543 * things to off as a safer default. */
12544 list_for_each_entry(connector
,
12545 &dev
->mode_config
.connector_list
,
12547 if (connector
->encoder
!= encoder
)
12549 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12550 connector
->base
.encoder
= NULL
;
12553 /* Enabled encoders without active connectors will be fixed in
12554 * the crtc fixup. */
12557 void i915_redisable_vga_power_on(struct drm_device
*dev
)
12559 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12560 u32 vga_reg
= i915_vgacntrl_reg(dev
);
12562 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
12563 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
12564 i915_disable_vga(dev
);
12568 void i915_redisable_vga(struct drm_device
*dev
)
12570 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12572 /* This function can be called both from intel_modeset_setup_hw_state or
12573 * at a very early point in our resume sequence, where the power well
12574 * structures are not yet restored. Since this function is at a very
12575 * paranoid "someone might have enabled VGA while we were not looking"
12576 * level, just check if the power well is enabled instead of trying to
12577 * follow the "don't touch the power well if we don't need it" policy
12578 * the rest of the driver uses. */
12579 if (!intel_display_power_enabled(dev_priv
, POWER_DOMAIN_VGA
))
12582 i915_redisable_vga_power_on(dev
);
12585 static bool primary_get_hw_state(struct intel_crtc
*crtc
)
12587 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
12592 return I915_READ(DSPCNTR(crtc
->plane
)) & DISPLAY_PLANE_ENABLE
;
12595 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
12597 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12599 struct intel_crtc
*crtc
;
12600 struct intel_encoder
*encoder
;
12601 struct intel_connector
*connector
;
12604 for_each_intel_crtc(dev
, crtc
) {
12605 memset(&crtc
->config
, 0, sizeof(crtc
->config
));
12607 crtc
->config
.quirks
|= PIPE_CONFIG_QUIRK_INHERITED_MODE
;
12609 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
12612 crtc
->base
.enabled
= crtc
->active
;
12613 crtc
->primary_enabled
= primary_get_hw_state(crtc
);
12615 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
12616 crtc
->base
.base
.id
,
12617 crtc
->active
? "enabled" : "disabled");
12620 /* FIXME: Smash this into the new shared dpll infrastructure. */
12622 intel_ddi_setup_hw_pll_state(dev
);
12624 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
12625 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
12627 pll
->on
= pll
->get_hw_state(dev_priv
, pll
, &pll
->hw_state
);
12629 for_each_intel_crtc(dev
, crtc
) {
12630 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
12633 pll
->refcount
= pll
->active
;
12635 DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
12636 pll
->name
, pll
->refcount
, pll
->on
);
12639 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
12643 if (encoder
->get_hw_state(encoder
, &pipe
)) {
12644 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
12645 encoder
->base
.crtc
= &crtc
->base
;
12646 encoder
->get_config(encoder
, &crtc
->config
);
12648 encoder
->base
.crtc
= NULL
;
12651 encoder
->connectors_active
= false;
12652 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
12653 encoder
->base
.base
.id
,
12654 encoder
->base
.name
,
12655 encoder
->base
.crtc
? "enabled" : "disabled",
12659 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12661 if (connector
->get_hw_state(connector
)) {
12662 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
12663 connector
->encoder
->connectors_active
= true;
12664 connector
->base
.encoder
= &connector
->encoder
->base
;
12666 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12667 connector
->base
.encoder
= NULL
;
12669 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
12670 connector
->base
.base
.id
,
12671 connector
->base
.name
,
12672 connector
->base
.encoder
? "enabled" : "disabled");
12676 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
12677 * and i915 state tracking structures. */
12678 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
12679 bool force_restore
)
12681 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12683 struct intel_crtc
*crtc
;
12684 struct intel_encoder
*encoder
;
12687 intel_modeset_readout_hw_state(dev
);
12690 * Now that we have the config, copy it to each CRTC struct
12691 * Note that this could go away if we move to using crtc_config
12692 * checking everywhere.
12694 for_each_intel_crtc(dev
, crtc
) {
12695 if (crtc
->active
&& i915
.fastboot
) {
12696 intel_mode_from_pipe_config(&crtc
->base
.mode
, &crtc
->config
);
12697 DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
12698 crtc
->base
.base
.id
);
12699 drm_mode_debug_printmodeline(&crtc
->base
.mode
);
12703 /* HW state is read out, now we need to sanitize this mess. */
12704 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
12706 intel_sanitize_encoder(encoder
);
12709 for_each_pipe(pipe
) {
12710 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
12711 intel_sanitize_crtc(crtc
);
12712 intel_dump_pipe_config(crtc
, &crtc
->config
, "[setup_hw_state]");
12715 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
12716 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
12718 if (!pll
->on
|| pll
->active
)
12721 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
12723 pll
->disable(dev_priv
, pll
);
12727 if (HAS_PCH_SPLIT(dev
))
12728 ilk_wm_get_hw_state(dev
);
12730 if (force_restore
) {
12731 i915_redisable_vga(dev
);
12734 * We need to use raw interfaces for restoring state to avoid
12735 * checking (bogus) intermediate states.
12737 for_each_pipe(pipe
) {
12738 struct drm_crtc
*crtc
=
12739 dev_priv
->pipe_to_crtc_mapping
[pipe
];
12741 __intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
,
12742 crtc
->primary
->fb
);
12745 intel_modeset_update_staged_output_state(dev
);
12748 intel_modeset_check_state(dev
);
12751 void intel_modeset_gem_init(struct drm_device
*dev
)
12753 struct drm_crtc
*c
;
12754 struct intel_framebuffer
*fb
;
12756 mutex_lock(&dev
->struct_mutex
);
12757 intel_init_gt_powersave(dev
);
12758 mutex_unlock(&dev
->struct_mutex
);
12760 intel_modeset_init_hw(dev
);
12762 intel_setup_overlay(dev
);
12765 * Make sure any fbs we allocated at startup are properly
12766 * pinned & fenced. When we do the allocation it's too early
12769 mutex_lock(&dev
->struct_mutex
);
12770 for_each_crtc(dev
, c
) {
12771 if (!c
->primary
->fb
)
12774 fb
= to_intel_framebuffer(c
->primary
->fb
);
12775 if (intel_pin_and_fence_fb_obj(dev
, fb
->obj
, NULL
)) {
12776 DRM_ERROR("failed to pin boot fb on pipe %d\n",
12777 to_intel_crtc(c
)->pipe
);
12778 drm_framebuffer_unreference(c
->primary
->fb
);
12779 c
->primary
->fb
= NULL
;
12782 mutex_unlock(&dev
->struct_mutex
);
12785 void intel_connector_unregister(struct intel_connector
*intel_connector
)
12787 struct drm_connector
*connector
= &intel_connector
->base
;
12789 intel_panel_destroy_backlight(connector
);
12790 drm_sysfs_connector_remove(connector
);
12793 void intel_modeset_cleanup(struct drm_device
*dev
)
12795 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12796 struct drm_connector
*connector
;
12799 * Interrupts and polling as the first thing to avoid creating havoc.
12800 * Too much stuff here (turning of rps, connectors, ...) would
12801 * experience fancy races otherwise.
12803 drm_irq_uninstall(dev
);
12804 cancel_work_sync(&dev_priv
->hotplug_work
);
12806 * Due to the hpd irq storm handling the hotplug work can re-arm the
12807 * poll handlers. Hence disable polling after hpd handling is shut down.
12809 drm_kms_helper_poll_fini(dev
);
12811 mutex_lock(&dev
->struct_mutex
);
12813 intel_unregister_dsm_handler();
12815 intel_disable_fbc(dev
);
12817 intel_disable_gt_powersave(dev
);
12819 ironlake_teardown_rc6(dev
);
12821 mutex_unlock(&dev
->struct_mutex
);
12823 /* flush any delayed tasks or pending work */
12824 flush_scheduled_work();
12826 /* destroy the backlight and sysfs files before encoders/connectors */
12827 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
12828 struct intel_connector
*intel_connector
;
12830 intel_connector
= to_intel_connector(connector
);
12831 intel_connector
->unregister(intel_connector
);
12834 drm_mode_config_cleanup(dev
);
12836 intel_cleanup_overlay(dev
);
12838 mutex_lock(&dev
->struct_mutex
);
12839 intel_cleanup_gt_powersave(dev
);
12840 mutex_unlock(&dev
->struct_mutex
);
12844 * Return which encoder is currently attached for connector.
12846 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
12848 return &intel_attached_encoder(connector
)->base
;
12851 void intel_connector_attach_encoder(struct intel_connector
*connector
,
12852 struct intel_encoder
*encoder
)
12854 connector
->encoder
= encoder
;
12855 drm_mode_connector_attach_encoder(&connector
->base
,
12860 * set vga decode state - true == enable VGA decode
12862 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
12864 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12865 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
12868 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
12869 DRM_ERROR("failed to read control word\n");
12873 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
12877 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
12879 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
12881 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
12882 DRM_ERROR("failed to write control word\n");
12889 struct intel_display_error_state
{
12891 u32 power_well_driver
;
12893 int num_transcoders
;
12895 struct intel_cursor_error_state
{
12900 } cursor
[I915_MAX_PIPES
];
12902 struct intel_pipe_error_state
{
12903 bool power_domain_on
;
12906 } pipe
[I915_MAX_PIPES
];
12908 struct intel_plane_error_state
{
12916 } plane
[I915_MAX_PIPES
];
12918 struct intel_transcoder_error_state
{
12919 bool power_domain_on
;
12920 enum transcoder cpu_transcoder
;
12933 struct intel_display_error_state
*
12934 intel_display_capture_error_state(struct drm_device
*dev
)
12936 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12937 struct intel_display_error_state
*error
;
12938 int transcoders
[] = {
12946 if (INTEL_INFO(dev
)->num_pipes
== 0)
12949 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
12953 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
12954 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
12957 error
->pipe
[i
].power_domain_on
=
12958 intel_display_power_enabled_sw(dev_priv
,
12959 POWER_DOMAIN_PIPE(i
));
12960 if (!error
->pipe
[i
].power_domain_on
)
12963 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
12964 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
12965 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
12967 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
12968 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
12969 if (INTEL_INFO(dev
)->gen
<= 3) {
12970 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
12971 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
12973 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
12974 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
12975 if (INTEL_INFO(dev
)->gen
>= 4) {
12976 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
12977 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
12980 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
12982 if (!HAS_PCH_SPLIT(dev
))
12983 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
12986 error
->num_transcoders
= INTEL_INFO(dev
)->num_pipes
;
12987 if (HAS_DDI(dev_priv
->dev
))
12988 error
->num_transcoders
++; /* Account for eDP. */
12990 for (i
= 0; i
< error
->num_transcoders
; i
++) {
12991 enum transcoder cpu_transcoder
= transcoders
[i
];
12993 error
->transcoder
[i
].power_domain_on
=
12994 intel_display_power_enabled_sw(dev_priv
,
12995 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
12996 if (!error
->transcoder
[i
].power_domain_on
)
12999 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
13001 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
13002 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
13003 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
13004 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
13005 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
13006 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
13007 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
13013 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
13016 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
13017 struct drm_device
*dev
,
13018 struct intel_display_error_state
*error
)
13025 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
13026 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
13027 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
13028 error
->power_well_driver
);
13030 err_printf(m
, "Pipe [%d]:\n", i
);
13031 err_printf(m
, " Power: %s\n",
13032 error
->pipe
[i
].power_domain_on
? "on" : "off");
13033 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
13034 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
13036 err_printf(m
, "Plane [%d]:\n", i
);
13037 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
13038 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
13039 if (INTEL_INFO(dev
)->gen
<= 3) {
13040 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
13041 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
13043 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
13044 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
13045 if (INTEL_INFO(dev
)->gen
>= 4) {
13046 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
13047 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
13050 err_printf(m
, "Cursor [%d]:\n", i
);
13051 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
13052 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
13053 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
13056 for (i
= 0; i
< error
->num_transcoders
; i
++) {
13057 err_printf(m
, "CPU transcoder: %c\n",
13058 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
13059 err_printf(m
, " Power: %s\n",
13060 error
->transcoder
[i
].power_domain_on
? "on" : "off");
13061 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
13062 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
13063 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
13064 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
13065 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
13066 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
13067 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);