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_crtc
*crtc
);
80 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
, bool on
);
82 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
83 struct intel_crtc_config
*pipe_config
);
84 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
85 struct intel_crtc_config
*pipe_config
);
87 static int intel_set_mode(struct drm_crtc
*crtc
, struct drm_display_mode
*mode
,
88 int x
, int y
, struct drm_framebuffer
*old_fb
);
89 static int intel_framebuffer_init(struct drm_device
*dev
,
90 struct intel_framebuffer
*ifb
,
91 struct drm_mode_fb_cmd2
*mode_cmd
,
92 struct drm_i915_gem_object
*obj
);
93 static void intel_dp_set_m_n(struct intel_crtc
*crtc
);
94 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
);
95 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
);
96 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
97 struct intel_link_m_n
*m_n
);
98 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
99 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
100 static void intel_set_pipe_csc(struct drm_crtc
*crtc
);
101 static void vlv_prepare_pll(struct intel_crtc
*crtc
);
109 int p2_slow
, p2_fast
;
112 typedef struct intel_limit intel_limit_t
;
114 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
119 intel_pch_rawclk(struct drm_device
*dev
)
121 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
123 WARN_ON(!HAS_PCH_SPLIT(dev
));
125 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
128 static inline u32
/* units of 100MHz */
129 intel_fdi_link_freq(struct drm_device
*dev
)
132 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
133 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
138 static const intel_limit_t intel_limits_i8xx_dac
= {
139 .dot
= { .min
= 25000, .max
= 350000 },
140 .vco
= { .min
= 908000, .max
= 1512000 },
141 .n
= { .min
= 2, .max
= 16 },
142 .m
= { .min
= 96, .max
= 140 },
143 .m1
= { .min
= 18, .max
= 26 },
144 .m2
= { .min
= 6, .max
= 16 },
145 .p
= { .min
= 4, .max
= 128 },
146 .p1
= { .min
= 2, .max
= 33 },
147 .p2
= { .dot_limit
= 165000,
148 .p2_slow
= 4, .p2_fast
= 2 },
151 static const intel_limit_t intel_limits_i8xx_dvo
= {
152 .dot
= { .min
= 25000, .max
= 350000 },
153 .vco
= { .min
= 908000, .max
= 1512000 },
154 .n
= { .min
= 2, .max
= 16 },
155 .m
= { .min
= 96, .max
= 140 },
156 .m1
= { .min
= 18, .max
= 26 },
157 .m2
= { .min
= 6, .max
= 16 },
158 .p
= { .min
= 4, .max
= 128 },
159 .p1
= { .min
= 2, .max
= 33 },
160 .p2
= { .dot_limit
= 165000,
161 .p2_slow
= 4, .p2_fast
= 4 },
164 static const intel_limit_t intel_limits_i8xx_lvds
= {
165 .dot
= { .min
= 25000, .max
= 350000 },
166 .vco
= { .min
= 908000, .max
= 1512000 },
167 .n
= { .min
= 2, .max
= 16 },
168 .m
= { .min
= 96, .max
= 140 },
169 .m1
= { .min
= 18, .max
= 26 },
170 .m2
= { .min
= 6, .max
= 16 },
171 .p
= { .min
= 4, .max
= 128 },
172 .p1
= { .min
= 1, .max
= 6 },
173 .p2
= { .dot_limit
= 165000,
174 .p2_slow
= 14, .p2_fast
= 7 },
177 static const intel_limit_t intel_limits_i9xx_sdvo
= {
178 .dot
= { .min
= 20000, .max
= 400000 },
179 .vco
= { .min
= 1400000, .max
= 2800000 },
180 .n
= { .min
= 1, .max
= 6 },
181 .m
= { .min
= 70, .max
= 120 },
182 .m1
= { .min
= 8, .max
= 18 },
183 .m2
= { .min
= 3, .max
= 7 },
184 .p
= { .min
= 5, .max
= 80 },
185 .p1
= { .min
= 1, .max
= 8 },
186 .p2
= { .dot_limit
= 200000,
187 .p2_slow
= 10, .p2_fast
= 5 },
190 static const intel_limit_t intel_limits_i9xx_lvds
= {
191 .dot
= { .min
= 20000, .max
= 400000 },
192 .vco
= { .min
= 1400000, .max
= 2800000 },
193 .n
= { .min
= 1, .max
= 6 },
194 .m
= { .min
= 70, .max
= 120 },
195 .m1
= { .min
= 8, .max
= 18 },
196 .m2
= { .min
= 3, .max
= 7 },
197 .p
= { .min
= 7, .max
= 98 },
198 .p1
= { .min
= 1, .max
= 8 },
199 .p2
= { .dot_limit
= 112000,
200 .p2_slow
= 14, .p2_fast
= 7 },
204 static const intel_limit_t intel_limits_g4x_sdvo
= {
205 .dot
= { .min
= 25000, .max
= 270000 },
206 .vco
= { .min
= 1750000, .max
= 3500000},
207 .n
= { .min
= 1, .max
= 4 },
208 .m
= { .min
= 104, .max
= 138 },
209 .m1
= { .min
= 17, .max
= 23 },
210 .m2
= { .min
= 5, .max
= 11 },
211 .p
= { .min
= 10, .max
= 30 },
212 .p1
= { .min
= 1, .max
= 3},
213 .p2
= { .dot_limit
= 270000,
219 static const intel_limit_t intel_limits_g4x_hdmi
= {
220 .dot
= { .min
= 22000, .max
= 400000 },
221 .vco
= { .min
= 1750000, .max
= 3500000},
222 .n
= { .min
= 1, .max
= 4 },
223 .m
= { .min
= 104, .max
= 138 },
224 .m1
= { .min
= 16, .max
= 23 },
225 .m2
= { .min
= 5, .max
= 11 },
226 .p
= { .min
= 5, .max
= 80 },
227 .p1
= { .min
= 1, .max
= 8},
228 .p2
= { .dot_limit
= 165000,
229 .p2_slow
= 10, .p2_fast
= 5 },
232 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
233 .dot
= { .min
= 20000, .max
= 115000 },
234 .vco
= { .min
= 1750000, .max
= 3500000 },
235 .n
= { .min
= 1, .max
= 3 },
236 .m
= { .min
= 104, .max
= 138 },
237 .m1
= { .min
= 17, .max
= 23 },
238 .m2
= { .min
= 5, .max
= 11 },
239 .p
= { .min
= 28, .max
= 112 },
240 .p1
= { .min
= 2, .max
= 8 },
241 .p2
= { .dot_limit
= 0,
242 .p2_slow
= 14, .p2_fast
= 14
246 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
247 .dot
= { .min
= 80000, .max
= 224000 },
248 .vco
= { .min
= 1750000, .max
= 3500000 },
249 .n
= { .min
= 1, .max
= 3 },
250 .m
= { .min
= 104, .max
= 138 },
251 .m1
= { .min
= 17, .max
= 23 },
252 .m2
= { .min
= 5, .max
= 11 },
253 .p
= { .min
= 14, .max
= 42 },
254 .p1
= { .min
= 2, .max
= 6 },
255 .p2
= { .dot_limit
= 0,
256 .p2_slow
= 7, .p2_fast
= 7
260 static const intel_limit_t intel_limits_pineview_sdvo
= {
261 .dot
= { .min
= 20000, .max
= 400000},
262 .vco
= { .min
= 1700000, .max
= 3500000 },
263 /* Pineview's Ncounter is a ring counter */
264 .n
= { .min
= 3, .max
= 6 },
265 .m
= { .min
= 2, .max
= 256 },
266 /* Pineview only has one combined m divider, which we treat as m2. */
267 .m1
= { .min
= 0, .max
= 0 },
268 .m2
= { .min
= 0, .max
= 254 },
269 .p
= { .min
= 5, .max
= 80 },
270 .p1
= { .min
= 1, .max
= 8 },
271 .p2
= { .dot_limit
= 200000,
272 .p2_slow
= 10, .p2_fast
= 5 },
275 static const intel_limit_t intel_limits_pineview_lvds
= {
276 .dot
= { .min
= 20000, .max
= 400000 },
277 .vco
= { .min
= 1700000, .max
= 3500000 },
278 .n
= { .min
= 3, .max
= 6 },
279 .m
= { .min
= 2, .max
= 256 },
280 .m1
= { .min
= 0, .max
= 0 },
281 .m2
= { .min
= 0, .max
= 254 },
282 .p
= { .min
= 7, .max
= 112 },
283 .p1
= { .min
= 1, .max
= 8 },
284 .p2
= { .dot_limit
= 112000,
285 .p2_slow
= 14, .p2_fast
= 14 },
288 /* Ironlake / Sandybridge
290 * We calculate clock using (register_value + 2) for N/M1/M2, so here
291 * the range value for them is (actual_value - 2).
293 static const intel_limit_t intel_limits_ironlake_dac
= {
294 .dot
= { .min
= 25000, .max
= 350000 },
295 .vco
= { .min
= 1760000, .max
= 3510000 },
296 .n
= { .min
= 1, .max
= 5 },
297 .m
= { .min
= 79, .max
= 127 },
298 .m1
= { .min
= 12, .max
= 22 },
299 .m2
= { .min
= 5, .max
= 9 },
300 .p
= { .min
= 5, .max
= 80 },
301 .p1
= { .min
= 1, .max
= 8 },
302 .p2
= { .dot_limit
= 225000,
303 .p2_slow
= 10, .p2_fast
= 5 },
306 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
307 .dot
= { .min
= 25000, .max
= 350000 },
308 .vco
= { .min
= 1760000, .max
= 3510000 },
309 .n
= { .min
= 1, .max
= 3 },
310 .m
= { .min
= 79, .max
= 118 },
311 .m1
= { .min
= 12, .max
= 22 },
312 .m2
= { .min
= 5, .max
= 9 },
313 .p
= { .min
= 28, .max
= 112 },
314 .p1
= { .min
= 2, .max
= 8 },
315 .p2
= { .dot_limit
= 225000,
316 .p2_slow
= 14, .p2_fast
= 14 },
319 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
320 .dot
= { .min
= 25000, .max
= 350000 },
321 .vco
= { .min
= 1760000, .max
= 3510000 },
322 .n
= { .min
= 1, .max
= 3 },
323 .m
= { .min
= 79, .max
= 127 },
324 .m1
= { .min
= 12, .max
= 22 },
325 .m2
= { .min
= 5, .max
= 9 },
326 .p
= { .min
= 14, .max
= 56 },
327 .p1
= { .min
= 2, .max
= 8 },
328 .p2
= { .dot_limit
= 225000,
329 .p2_slow
= 7, .p2_fast
= 7 },
332 /* LVDS 100mhz refclk limits. */
333 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
334 .dot
= { .min
= 25000, .max
= 350000 },
335 .vco
= { .min
= 1760000, .max
= 3510000 },
336 .n
= { .min
= 1, .max
= 2 },
337 .m
= { .min
= 79, .max
= 126 },
338 .m1
= { .min
= 12, .max
= 22 },
339 .m2
= { .min
= 5, .max
= 9 },
340 .p
= { .min
= 28, .max
= 112 },
341 .p1
= { .min
= 2, .max
= 8 },
342 .p2
= { .dot_limit
= 225000,
343 .p2_slow
= 14, .p2_fast
= 14 },
346 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
347 .dot
= { .min
= 25000, .max
= 350000 },
348 .vco
= { .min
= 1760000, .max
= 3510000 },
349 .n
= { .min
= 1, .max
= 3 },
350 .m
= { .min
= 79, .max
= 126 },
351 .m1
= { .min
= 12, .max
= 22 },
352 .m2
= { .min
= 5, .max
= 9 },
353 .p
= { .min
= 14, .max
= 42 },
354 .p1
= { .min
= 2, .max
= 6 },
355 .p2
= { .dot_limit
= 225000,
356 .p2_slow
= 7, .p2_fast
= 7 },
359 static const intel_limit_t intel_limits_vlv
= {
361 * These are the data rate limits (measured in fast clocks)
362 * since those are the strictest limits we have. The fast
363 * clock and actual rate limits are more relaxed, so checking
364 * them would make no difference.
366 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
367 .vco
= { .min
= 4000000, .max
= 6000000 },
368 .n
= { .min
= 1, .max
= 7 },
369 .m1
= { .min
= 2, .max
= 3 },
370 .m2
= { .min
= 11, .max
= 156 },
371 .p1
= { .min
= 2, .max
= 3 },
372 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
375 static const intel_limit_t intel_limits_chv
= {
377 * These are the data rate limits (measured in fast clocks)
378 * since those are the strictest limits we have. The fast
379 * clock and actual rate limits are more relaxed, so checking
380 * them would make no difference.
382 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
383 .vco
= { .min
= 4860000, .max
= 6700000 },
384 .n
= { .min
= 1, .max
= 1 },
385 .m1
= { .min
= 2, .max
= 2 },
386 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
387 .p1
= { .min
= 2, .max
= 4 },
388 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
391 static void vlv_clock(int refclk
, intel_clock_t
*clock
)
393 clock
->m
= clock
->m1
* clock
->m2
;
394 clock
->p
= clock
->p1
* clock
->p2
;
395 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
397 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
398 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
402 * Returns whether any output on the specified pipe is of the specified type
404 static bool intel_pipe_has_type(struct drm_crtc
*crtc
, int type
)
406 struct drm_device
*dev
= crtc
->dev
;
407 struct intel_encoder
*encoder
;
409 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
410 if (encoder
->type
== type
)
416 static const intel_limit_t
*intel_ironlake_limit(struct drm_crtc
*crtc
,
419 struct drm_device
*dev
= crtc
->dev
;
420 const intel_limit_t
*limit
;
422 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
423 if (intel_is_dual_link_lvds(dev
)) {
424 if (refclk
== 100000)
425 limit
= &intel_limits_ironlake_dual_lvds_100m
;
427 limit
= &intel_limits_ironlake_dual_lvds
;
429 if (refclk
== 100000)
430 limit
= &intel_limits_ironlake_single_lvds_100m
;
432 limit
= &intel_limits_ironlake_single_lvds
;
435 limit
= &intel_limits_ironlake_dac
;
440 static const intel_limit_t
*intel_g4x_limit(struct drm_crtc
*crtc
)
442 struct drm_device
*dev
= crtc
->dev
;
443 const intel_limit_t
*limit
;
445 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
446 if (intel_is_dual_link_lvds(dev
))
447 limit
= &intel_limits_g4x_dual_channel_lvds
;
449 limit
= &intel_limits_g4x_single_channel_lvds
;
450 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
) ||
451 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
452 limit
= &intel_limits_g4x_hdmi
;
453 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
)) {
454 limit
= &intel_limits_g4x_sdvo
;
455 } else /* The option is for other outputs */
456 limit
= &intel_limits_i9xx_sdvo
;
461 static const intel_limit_t
*intel_limit(struct drm_crtc
*crtc
, int refclk
)
463 struct drm_device
*dev
= crtc
->dev
;
464 const intel_limit_t
*limit
;
466 if (HAS_PCH_SPLIT(dev
))
467 limit
= intel_ironlake_limit(crtc
, refclk
);
468 else if (IS_G4X(dev
)) {
469 limit
= intel_g4x_limit(crtc
);
470 } else if (IS_PINEVIEW(dev
)) {
471 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
472 limit
= &intel_limits_pineview_lvds
;
474 limit
= &intel_limits_pineview_sdvo
;
475 } else if (IS_CHERRYVIEW(dev
)) {
476 limit
= &intel_limits_chv
;
477 } else if (IS_VALLEYVIEW(dev
)) {
478 limit
= &intel_limits_vlv
;
479 } else if (!IS_GEN2(dev
)) {
480 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
481 limit
= &intel_limits_i9xx_lvds
;
483 limit
= &intel_limits_i9xx_sdvo
;
485 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
486 limit
= &intel_limits_i8xx_lvds
;
487 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
))
488 limit
= &intel_limits_i8xx_dvo
;
490 limit
= &intel_limits_i8xx_dac
;
495 /* m1 is reserved as 0 in Pineview, n is a ring counter */
496 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
498 clock
->m
= clock
->m2
+ 2;
499 clock
->p
= clock
->p1
* clock
->p2
;
500 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
502 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
503 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
506 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
508 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
511 static void i9xx_clock(int refclk
, intel_clock_t
*clock
)
513 clock
->m
= i9xx_dpll_compute_m(clock
);
514 clock
->p
= clock
->p1
* clock
->p2
;
515 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
517 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
518 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
521 static void chv_clock(int refclk
, intel_clock_t
*clock
)
523 clock
->m
= clock
->m1
* clock
->m2
;
524 clock
->p
= clock
->p1
* clock
->p2
;
525 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
527 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
529 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
532 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
534 * Returns whether the given set of divisors are valid for a given refclk with
535 * the given connectors.
538 static bool intel_PLL_is_valid(struct drm_device
*dev
,
539 const intel_limit_t
*limit
,
540 const intel_clock_t
*clock
)
542 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
543 INTELPllInvalid("n out of range\n");
544 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
545 INTELPllInvalid("p1 out of range\n");
546 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
547 INTELPllInvalid("m2 out of range\n");
548 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
549 INTELPllInvalid("m1 out of range\n");
551 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
))
552 if (clock
->m1
<= clock
->m2
)
553 INTELPllInvalid("m1 <= m2\n");
555 if (!IS_VALLEYVIEW(dev
)) {
556 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
557 INTELPllInvalid("p out of range\n");
558 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
559 INTELPllInvalid("m out of range\n");
562 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
563 INTELPllInvalid("vco out of range\n");
564 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
565 * connector, etc., rather than just a single range.
567 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
568 INTELPllInvalid("dot out of range\n");
574 i9xx_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
575 int target
, int refclk
, intel_clock_t
*match_clock
,
576 intel_clock_t
*best_clock
)
578 struct drm_device
*dev
= crtc
->dev
;
582 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
584 * For LVDS just rely on its current settings for dual-channel.
585 * We haven't figured out how to reliably set up different
586 * single/dual channel state, if we even can.
588 if (intel_is_dual_link_lvds(dev
))
589 clock
.p2
= limit
->p2
.p2_fast
;
591 clock
.p2
= limit
->p2
.p2_slow
;
593 if (target
< limit
->p2
.dot_limit
)
594 clock
.p2
= limit
->p2
.p2_slow
;
596 clock
.p2
= limit
->p2
.p2_fast
;
599 memset(best_clock
, 0, sizeof(*best_clock
));
601 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
603 for (clock
.m2
= limit
->m2
.min
;
604 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
605 if (clock
.m2
>= clock
.m1
)
607 for (clock
.n
= limit
->n
.min
;
608 clock
.n
<= limit
->n
.max
; clock
.n
++) {
609 for (clock
.p1
= limit
->p1
.min
;
610 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
613 i9xx_clock(refclk
, &clock
);
614 if (!intel_PLL_is_valid(dev
, limit
,
618 clock
.p
!= match_clock
->p
)
621 this_err
= abs(clock
.dot
- target
);
622 if (this_err
< err
) {
631 return (err
!= target
);
635 pnv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
636 int target
, int refclk
, intel_clock_t
*match_clock
,
637 intel_clock_t
*best_clock
)
639 struct drm_device
*dev
= crtc
->dev
;
643 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
645 * For LVDS just rely on its current settings for dual-channel.
646 * We haven't figured out how to reliably set up different
647 * single/dual channel state, if we even can.
649 if (intel_is_dual_link_lvds(dev
))
650 clock
.p2
= limit
->p2
.p2_fast
;
652 clock
.p2
= limit
->p2
.p2_slow
;
654 if (target
< limit
->p2
.dot_limit
)
655 clock
.p2
= limit
->p2
.p2_slow
;
657 clock
.p2
= limit
->p2
.p2_fast
;
660 memset(best_clock
, 0, sizeof(*best_clock
));
662 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
664 for (clock
.m2
= limit
->m2
.min
;
665 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
666 for (clock
.n
= limit
->n
.min
;
667 clock
.n
<= limit
->n
.max
; clock
.n
++) {
668 for (clock
.p1
= limit
->p1
.min
;
669 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
672 pineview_clock(refclk
, &clock
);
673 if (!intel_PLL_is_valid(dev
, limit
,
677 clock
.p
!= match_clock
->p
)
680 this_err
= abs(clock
.dot
- target
);
681 if (this_err
< err
) {
690 return (err
!= target
);
694 g4x_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
695 int target
, int refclk
, intel_clock_t
*match_clock
,
696 intel_clock_t
*best_clock
)
698 struct drm_device
*dev
= crtc
->dev
;
702 /* approximately equals target * 0.00585 */
703 int err_most
= (target
>> 8) + (target
>> 9);
706 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
707 if (intel_is_dual_link_lvds(dev
))
708 clock
.p2
= limit
->p2
.p2_fast
;
710 clock
.p2
= limit
->p2
.p2_slow
;
712 if (target
< limit
->p2
.dot_limit
)
713 clock
.p2
= limit
->p2
.p2_slow
;
715 clock
.p2
= limit
->p2
.p2_fast
;
718 memset(best_clock
, 0, sizeof(*best_clock
));
719 max_n
= limit
->n
.max
;
720 /* based on hardware requirement, prefer smaller n to precision */
721 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
722 /* based on hardware requirement, prefere larger m1,m2 */
723 for (clock
.m1
= limit
->m1
.max
;
724 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
725 for (clock
.m2
= limit
->m2
.max
;
726 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
727 for (clock
.p1
= limit
->p1
.max
;
728 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
731 i9xx_clock(refclk
, &clock
);
732 if (!intel_PLL_is_valid(dev
, limit
,
736 this_err
= abs(clock
.dot
- target
);
737 if (this_err
< err_most
) {
751 vlv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
752 int target
, int refclk
, intel_clock_t
*match_clock
,
753 intel_clock_t
*best_clock
)
755 struct drm_device
*dev
= crtc
->dev
;
757 unsigned int bestppm
= 1000000;
758 /* min update 19.2 MHz */
759 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
762 target
*= 5; /* fast clock */
764 memset(best_clock
, 0, sizeof(*best_clock
));
766 /* based on hardware requirement, prefer smaller n to precision */
767 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
768 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
769 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
770 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
771 clock
.p
= clock
.p1
* clock
.p2
;
772 /* based on hardware requirement, prefer bigger m1,m2 values */
773 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
774 unsigned int ppm
, diff
;
776 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
779 vlv_clock(refclk
, &clock
);
781 if (!intel_PLL_is_valid(dev
, limit
,
785 diff
= abs(clock
.dot
- target
);
786 ppm
= div_u64(1000000ULL * diff
, target
);
788 if (ppm
< 100 && clock
.p
> best_clock
->p
) {
794 if (bestppm
>= 10 && ppm
< bestppm
- 10) {
808 chv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
809 int target
, int refclk
, intel_clock_t
*match_clock
,
810 intel_clock_t
*best_clock
)
812 struct drm_device
*dev
= crtc
->dev
;
817 memset(best_clock
, 0, sizeof(*best_clock
));
820 * Based on hardware doc, the n always set to 1, and m1 always
821 * set to 2. If requires to support 200Mhz refclk, we need to
822 * revisit this because n may not 1 anymore.
824 clock
.n
= 1, clock
.m1
= 2;
825 target
*= 5; /* fast clock */
827 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
828 for (clock
.p2
= limit
->p2
.p2_fast
;
829 clock
.p2
>= limit
->p2
.p2_slow
;
830 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
832 clock
.p
= clock
.p1
* clock
.p2
;
834 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
835 clock
.n
) << 22, refclk
* clock
.m1
);
837 if (m2
> INT_MAX
/clock
.m1
)
842 chv_clock(refclk
, &clock
);
844 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
847 /* based on hardware requirement, prefer bigger p
849 if (clock
.p
> best_clock
->p
) {
859 bool intel_crtc_active(struct drm_crtc
*crtc
)
861 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
863 /* Be paranoid as we can arrive here with only partial
864 * state retrieved from the hardware during setup.
866 * We can ditch the adjusted_mode.crtc_clock check as soon
867 * as Haswell has gained clock readout/fastboot support.
869 * We can ditch the crtc->primary->fb check as soon as we can
870 * properly reconstruct framebuffers.
872 return intel_crtc
->active
&& crtc
->primary
->fb
&&
873 intel_crtc
->config
.adjusted_mode
.crtc_clock
;
876 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
879 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
880 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
882 return intel_crtc
->config
.cpu_transcoder
;
885 static void g4x_wait_for_vblank(struct drm_device
*dev
, int pipe
)
887 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
888 u32 frame
, frame_reg
= PIPE_FRMCOUNT_GM45(pipe
);
890 frame
= I915_READ(frame_reg
);
892 if (wait_for(I915_READ_NOTRACE(frame_reg
) != frame
, 50))
893 WARN(1, "vblank wait timed out\n");
897 * intel_wait_for_vblank - wait for vblank on a given pipe
899 * @pipe: pipe to wait for
901 * Wait for vblank to occur on a given pipe. Needed for various bits of
904 void intel_wait_for_vblank(struct drm_device
*dev
, int pipe
)
906 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
907 int pipestat_reg
= PIPESTAT(pipe
);
909 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5) {
910 g4x_wait_for_vblank(dev
, pipe
);
914 /* Clear existing vblank status. Note this will clear any other
915 * sticky status fields as well.
917 * This races with i915_driver_irq_handler() with the result
918 * that either function could miss a vblank event. Here it is not
919 * fatal, as we will either wait upon the next vblank interrupt or
920 * timeout. Generally speaking intel_wait_for_vblank() is only
921 * called during modeset at which time the GPU should be idle and
922 * should *not* be performing page flips and thus not waiting on
924 * Currently, the result of us stealing a vblank from the irq
925 * handler is that a single frame will be skipped during swapbuffers.
927 I915_WRITE(pipestat_reg
,
928 I915_READ(pipestat_reg
) | PIPE_VBLANK_INTERRUPT_STATUS
);
930 /* Wait for vblank interrupt bit to set */
931 if (wait_for(I915_READ(pipestat_reg
) &
932 PIPE_VBLANK_INTERRUPT_STATUS
,
934 DRM_DEBUG_KMS("vblank wait timed out\n");
937 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
939 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
940 u32 reg
= PIPEDSL(pipe
);
945 line_mask
= DSL_LINEMASK_GEN2
;
947 line_mask
= DSL_LINEMASK_GEN3
;
949 line1
= I915_READ(reg
) & line_mask
;
951 line2
= I915_READ(reg
) & line_mask
;
953 return line1
== line2
;
957 * intel_wait_for_pipe_off - wait for pipe to turn off
959 * @pipe: pipe to wait for
961 * After disabling a pipe, we can't wait for vblank in the usual way,
962 * spinning on the vblank interrupt status bit, since we won't actually
963 * see an interrupt when the pipe is disabled.
966 * wait for the pipe register state bit to turn off
969 * wait for the display line value to settle (it usually
970 * ends up stopping at the start of the next frame).
973 void intel_wait_for_pipe_off(struct drm_device
*dev
, int pipe
)
975 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
976 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
979 if (INTEL_INFO(dev
)->gen
>= 4) {
980 int reg
= PIPECONF(cpu_transcoder
);
982 /* Wait for the Pipe State to go off */
983 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
985 WARN(1, "pipe_off wait timed out\n");
987 /* Wait for the display line to settle */
988 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
989 WARN(1, "pipe_off wait timed out\n");
994 * ibx_digital_port_connected - is the specified port connected?
995 * @dev_priv: i915 private structure
996 * @port: the port to test
998 * Returns true if @port is connected, false otherwise.
1000 bool ibx_digital_port_connected(struct drm_i915_private
*dev_priv
,
1001 struct intel_digital_port
*port
)
1005 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1006 switch (port
->port
) {
1008 bit
= SDE_PORTB_HOTPLUG
;
1011 bit
= SDE_PORTC_HOTPLUG
;
1014 bit
= SDE_PORTD_HOTPLUG
;
1020 switch (port
->port
) {
1022 bit
= SDE_PORTB_HOTPLUG_CPT
;
1025 bit
= SDE_PORTC_HOTPLUG_CPT
;
1028 bit
= SDE_PORTD_HOTPLUG_CPT
;
1035 return I915_READ(SDEISR
) & bit
;
1038 static const char *state_string(bool enabled
)
1040 return enabled
? "on" : "off";
1043 /* Only for pre-ILK configs */
1044 void assert_pll(struct drm_i915_private
*dev_priv
,
1045 enum pipe pipe
, bool state
)
1052 val
= I915_READ(reg
);
1053 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1054 WARN(cur_state
!= state
,
1055 "PLL state assertion failure (expected %s, current %s)\n",
1056 state_string(state
), state_string(cur_state
));
1059 /* XXX: the dsi pll is shared between MIPI DSI ports */
1060 static void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1065 mutex_lock(&dev_priv
->dpio_lock
);
1066 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1067 mutex_unlock(&dev_priv
->dpio_lock
);
1069 cur_state
= val
& DSI_PLL_VCO_EN
;
1070 WARN(cur_state
!= state
,
1071 "DSI PLL state assertion failure (expected %s, current %s)\n",
1072 state_string(state
), state_string(cur_state
));
1074 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
1075 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
1077 struct intel_shared_dpll
*
1078 intel_crtc_to_shared_dpll(struct intel_crtc
*crtc
)
1080 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
1082 if (crtc
->config
.shared_dpll
< 0)
1085 return &dev_priv
->shared_dplls
[crtc
->config
.shared_dpll
];
1089 void assert_shared_dpll(struct drm_i915_private
*dev_priv
,
1090 struct intel_shared_dpll
*pll
,
1094 struct intel_dpll_hw_state hw_state
;
1096 if (HAS_PCH_LPT(dev_priv
->dev
)) {
1097 DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
1102 "asserting DPLL %s with no DPLL\n", state_string(state
)))
1105 cur_state
= pll
->get_hw_state(dev_priv
, pll
, &hw_state
);
1106 WARN(cur_state
!= state
,
1107 "%s assertion failure (expected %s, current %s)\n",
1108 pll
->name
, state_string(state
), state_string(cur_state
));
1111 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1112 enum pipe pipe
, bool state
)
1117 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1120 if (HAS_DDI(dev_priv
->dev
)) {
1121 /* DDI does not have a specific FDI_TX register */
1122 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1123 val
= I915_READ(reg
);
1124 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1126 reg
= FDI_TX_CTL(pipe
);
1127 val
= I915_READ(reg
);
1128 cur_state
= !!(val
& FDI_TX_ENABLE
);
1130 WARN(cur_state
!= state
,
1131 "FDI TX state assertion failure (expected %s, current %s)\n",
1132 state_string(state
), state_string(cur_state
));
1134 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1135 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1137 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1138 enum pipe pipe
, bool state
)
1144 reg
= FDI_RX_CTL(pipe
);
1145 val
= I915_READ(reg
);
1146 cur_state
= !!(val
& FDI_RX_ENABLE
);
1147 WARN(cur_state
!= state
,
1148 "FDI RX state assertion failure (expected %s, current %s)\n",
1149 state_string(state
), state_string(cur_state
));
1151 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1152 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1154 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1160 /* ILK FDI PLL is always enabled */
1161 if (INTEL_INFO(dev_priv
->dev
)->gen
== 5)
1164 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1165 if (HAS_DDI(dev_priv
->dev
))
1168 reg
= FDI_TX_CTL(pipe
);
1169 val
= I915_READ(reg
);
1170 WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1173 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1174 enum pipe pipe
, bool state
)
1180 reg
= FDI_RX_CTL(pipe
);
1181 val
= I915_READ(reg
);
1182 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1183 WARN(cur_state
!= state
,
1184 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1185 state_string(state
), state_string(cur_state
));
1188 static void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1191 int pp_reg
, lvds_reg
;
1193 enum pipe panel_pipe
= PIPE_A
;
1196 if (HAS_PCH_SPLIT(dev_priv
->dev
)) {
1197 pp_reg
= PCH_PP_CONTROL
;
1198 lvds_reg
= PCH_LVDS
;
1200 pp_reg
= PP_CONTROL
;
1204 val
= I915_READ(pp_reg
);
1205 if (!(val
& PANEL_POWER_ON
) ||
1206 ((val
& PANEL_UNLOCK_REGS
) == PANEL_UNLOCK_REGS
))
1209 if (I915_READ(lvds_reg
) & LVDS_PIPEB_SELECT
)
1210 panel_pipe
= PIPE_B
;
1212 WARN(panel_pipe
== pipe
&& locked
,
1213 "panel assertion failure, pipe %c regs locked\n",
1217 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1218 enum pipe pipe
, bool state
)
1220 struct drm_device
*dev
= dev_priv
->dev
;
1223 if (IS_845G(dev
) || IS_I865G(dev
))
1224 cur_state
= I915_READ(_CURACNTR
) & CURSOR_ENABLE
;
1226 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1228 WARN(cur_state
!= state
,
1229 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1230 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1232 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1233 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1235 void assert_pipe(struct drm_i915_private
*dev_priv
,
1236 enum pipe pipe
, bool state
)
1241 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1244 /* if we need the pipe A quirk it must be always on */
1245 if (pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
)
1248 if (!intel_display_power_enabled(dev_priv
,
1249 POWER_DOMAIN_TRANSCODER(cpu_transcoder
))) {
1252 reg
= PIPECONF(cpu_transcoder
);
1253 val
= I915_READ(reg
);
1254 cur_state
= !!(val
& PIPECONF_ENABLE
);
1257 WARN(cur_state
!= state
,
1258 "pipe %c assertion failure (expected %s, current %s)\n",
1259 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1262 static void assert_plane(struct drm_i915_private
*dev_priv
,
1263 enum plane plane
, bool state
)
1269 reg
= DSPCNTR(plane
);
1270 val
= I915_READ(reg
);
1271 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1272 WARN(cur_state
!= state
,
1273 "plane %c assertion failure (expected %s, current %s)\n",
1274 plane_name(plane
), state_string(state
), state_string(cur_state
));
1277 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1278 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1280 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1283 struct drm_device
*dev
= dev_priv
->dev
;
1288 /* Primary planes are fixed to pipes on gen4+ */
1289 if (INTEL_INFO(dev
)->gen
>= 4) {
1290 reg
= DSPCNTR(pipe
);
1291 val
= I915_READ(reg
);
1292 WARN(val
& DISPLAY_PLANE_ENABLE
,
1293 "plane %c assertion failure, should be disabled but not\n",
1298 /* Need to check both planes against the pipe */
1301 val
= I915_READ(reg
);
1302 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1303 DISPPLANE_SEL_PIPE_SHIFT
;
1304 WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1305 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1306 plane_name(i
), pipe_name(pipe
));
1310 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1313 struct drm_device
*dev
= dev_priv
->dev
;
1317 if (IS_VALLEYVIEW(dev
)) {
1318 for_each_sprite(pipe
, sprite
) {
1319 reg
= SPCNTR(pipe
, sprite
);
1320 val
= I915_READ(reg
);
1321 WARN(val
& SP_ENABLE
,
1322 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1323 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1325 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1327 val
= I915_READ(reg
);
1328 WARN(val
& SPRITE_ENABLE
,
1329 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1330 plane_name(pipe
), pipe_name(pipe
));
1331 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1332 reg
= DVSCNTR(pipe
);
1333 val
= I915_READ(reg
);
1334 WARN(val
& DVS_ENABLE
,
1335 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1336 plane_name(pipe
), pipe_name(pipe
));
1340 static void ibx_assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1345 WARN_ON(!(HAS_PCH_IBX(dev_priv
->dev
) || HAS_PCH_CPT(dev_priv
->dev
)));
1347 val
= I915_READ(PCH_DREF_CONTROL
);
1348 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1349 DREF_SUPERSPREAD_SOURCE_MASK
));
1350 WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1353 static void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1360 reg
= PCH_TRANSCONF(pipe
);
1361 val
= I915_READ(reg
);
1362 enabled
= !!(val
& TRANS_ENABLE
);
1364 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1368 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1369 enum pipe pipe
, u32 port_sel
, u32 val
)
1371 if ((val
& DP_PORT_EN
) == 0)
1374 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1375 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1376 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1377 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1379 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1380 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1383 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1389 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1390 enum pipe pipe
, u32 val
)
1392 if ((val
& SDVO_ENABLE
) == 0)
1395 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1396 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1398 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1399 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1402 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1408 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1409 enum pipe pipe
, u32 val
)
1411 if ((val
& LVDS_PORT_EN
) == 0)
1414 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1415 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1418 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1424 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1425 enum pipe pipe
, u32 val
)
1427 if ((val
& ADPA_DAC_ENABLE
) == 0)
1429 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1430 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1433 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1439 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1440 enum pipe pipe
, int reg
, u32 port_sel
)
1442 u32 val
= I915_READ(reg
);
1443 WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1444 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1445 reg
, pipe_name(pipe
));
1447 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1448 && (val
& DP_PIPEB_SELECT
),
1449 "IBX PCH dp port still using transcoder B\n");
1452 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1453 enum pipe pipe
, int reg
)
1455 u32 val
= I915_READ(reg
);
1456 WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1457 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1458 reg
, pipe_name(pipe
));
1460 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& SDVO_ENABLE
) == 0
1461 && (val
& SDVO_PIPE_B_SELECT
),
1462 "IBX PCH hdmi port still using transcoder B\n");
1465 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1471 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1472 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1473 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1476 val
= I915_READ(reg
);
1477 WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1478 "PCH VGA enabled on transcoder %c, should be disabled\n",
1482 val
= I915_READ(reg
);
1483 WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1484 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1487 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1488 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1489 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1492 static void intel_init_dpio(struct drm_device
*dev
)
1494 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1496 if (!IS_VALLEYVIEW(dev
))
1500 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
1501 * CHV x1 PHY (DP/HDMI D)
1502 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
1504 if (IS_CHERRYVIEW(dev
)) {
1505 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO_2
;
1506 DPIO_PHY_IOSF_PORT(DPIO_PHY1
) = IOSF_PORT_DPIO
;
1508 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO
;
1512 static void intel_reset_dpio(struct drm_device
*dev
)
1514 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1516 if (!IS_VALLEYVIEW(dev
))
1519 if (IS_CHERRYVIEW(dev
)) {
1523 for (phy
= DPIO_PHY0
; phy
< I915_NUM_PHYS_VLV
; phy
++) {
1524 /* Poll for phypwrgood signal */
1525 if (wait_for(I915_READ(DISPLAY_PHY_STATUS
) &
1526 PHY_POWERGOOD(phy
), 1))
1527 DRM_ERROR("Display PHY %d is not power up\n", phy
);
1530 * Deassert common lane reset for PHY.
1532 * This should only be done on init and resume from S3
1533 * with both PLLs disabled, or we risk losing DPIO and
1534 * PLL synchronization.
1536 val
= I915_READ(DISPLAY_PHY_CONTROL
);
1537 I915_WRITE(DISPLAY_PHY_CONTROL
,
1538 PHY_COM_LANE_RESET_DEASSERT(phy
, val
));
1543 * If DPIO has already been reset, e.g. by BIOS, just skip all
1546 if (I915_READ(DPIO_CTL
) & DPIO_CMNRST
)
1550 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
1551 * Need to assert and de-assert PHY SB reset by gating the
1552 * common lane power, then un-gating it.
1553 * Simply ungating isn't enough to reset the PHY enough to get
1554 * ports and lanes running.
1556 __vlv_set_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
,
1558 __vlv_set_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
,
1563 static void vlv_enable_pll(struct intel_crtc
*crtc
)
1565 struct drm_device
*dev
= crtc
->base
.dev
;
1566 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1567 int reg
= DPLL(crtc
->pipe
);
1568 u32 dpll
= crtc
->config
.dpll_hw_state
.dpll
;
1570 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1572 /* No really, not for ILK+ */
1573 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
));
1575 /* PLL is protected by panel, make sure we can write it */
1576 if (IS_MOBILE(dev_priv
->dev
) && !IS_I830(dev_priv
->dev
))
1577 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1579 I915_WRITE(reg
, dpll
);
1583 if (wait_for(((I915_READ(reg
) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1584 DRM_ERROR("DPLL %d failed to lock\n", crtc
->pipe
);
1586 I915_WRITE(DPLL_MD(crtc
->pipe
), crtc
->config
.dpll_hw_state
.dpll_md
);
1587 POSTING_READ(DPLL_MD(crtc
->pipe
));
1589 /* We do this three times for luck */
1590 I915_WRITE(reg
, dpll
);
1592 udelay(150); /* wait for warmup */
1593 I915_WRITE(reg
, dpll
);
1595 udelay(150); /* wait for warmup */
1596 I915_WRITE(reg
, dpll
);
1598 udelay(150); /* wait for warmup */
1601 static void chv_enable_pll(struct intel_crtc
*crtc
)
1603 struct drm_device
*dev
= crtc
->base
.dev
;
1604 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1605 int pipe
= crtc
->pipe
;
1606 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1609 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1611 BUG_ON(!IS_CHERRYVIEW(dev_priv
->dev
));
1613 mutex_lock(&dev_priv
->dpio_lock
);
1615 /* Enable back the 10bit clock to display controller */
1616 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1617 tmp
|= DPIO_DCLKP_EN
;
1618 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1621 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1626 I915_WRITE(DPLL(pipe
), crtc
->config
.dpll_hw_state
.dpll
);
1628 /* Check PLL is locked */
1629 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1630 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1632 /* not sure when this should be written */
1633 I915_WRITE(DPLL_MD(pipe
), crtc
->config
.dpll_hw_state
.dpll_md
);
1634 POSTING_READ(DPLL_MD(pipe
));
1636 mutex_unlock(&dev_priv
->dpio_lock
);
1639 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1641 struct drm_device
*dev
= crtc
->base
.dev
;
1642 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1643 int reg
= DPLL(crtc
->pipe
);
1644 u32 dpll
= crtc
->config
.dpll_hw_state
.dpll
;
1646 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1648 /* No really, not for ILK+ */
1649 BUG_ON(INTEL_INFO(dev
)->gen
>= 5);
1651 /* PLL is protected by panel, make sure we can write it */
1652 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1653 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1655 I915_WRITE(reg
, dpll
);
1657 /* Wait for the clocks to stabilize. */
1661 if (INTEL_INFO(dev
)->gen
>= 4) {
1662 I915_WRITE(DPLL_MD(crtc
->pipe
),
1663 crtc
->config
.dpll_hw_state
.dpll_md
);
1665 /* The pixel multiplier can only be updated once the
1666 * DPLL is enabled and the clocks are stable.
1668 * So write it again.
1670 I915_WRITE(reg
, dpll
);
1673 /* We do this three times for luck */
1674 I915_WRITE(reg
, dpll
);
1676 udelay(150); /* wait for warmup */
1677 I915_WRITE(reg
, dpll
);
1679 udelay(150); /* wait for warmup */
1680 I915_WRITE(reg
, dpll
);
1682 udelay(150); /* wait for warmup */
1686 * i9xx_disable_pll - disable a PLL
1687 * @dev_priv: i915 private structure
1688 * @pipe: pipe PLL to disable
1690 * Disable the PLL for @pipe, making sure the pipe is off first.
1692 * Note! This is for pre-ILK only.
1694 static void i9xx_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1696 /* Don't disable pipe A or pipe A PLLs if needed */
1697 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
1700 /* Make sure the pipe isn't still relying on us */
1701 assert_pipe_disabled(dev_priv
, pipe
);
1703 I915_WRITE(DPLL(pipe
), 0);
1704 POSTING_READ(DPLL(pipe
));
1707 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1711 /* Make sure the pipe isn't still relying on us */
1712 assert_pipe_disabled(dev_priv
, pipe
);
1715 * Leave integrated clock source and reference clock enabled for pipe B.
1716 * The latter is needed for VGA hotplug / manual detection.
1719 val
= DPLL_INTEGRATED_CRI_CLK_VLV
| DPLL_REFA_CLK_ENABLE_VLV
;
1720 I915_WRITE(DPLL(pipe
), val
);
1721 POSTING_READ(DPLL(pipe
));
1725 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1727 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1730 /* Make sure the pipe isn't still relying on us */
1731 assert_pipe_disabled(dev_priv
, pipe
);
1733 /* Set PLL en = 0 */
1734 val
= DPLL_SSC_REF_CLOCK_CHV
;
1736 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1737 I915_WRITE(DPLL(pipe
), val
);
1738 POSTING_READ(DPLL(pipe
));
1740 mutex_lock(&dev_priv
->dpio_lock
);
1742 /* Disable 10bit clock to display controller */
1743 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1744 val
&= ~DPIO_DCLKP_EN
;
1745 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1747 /* disable left/right clock distribution */
1748 if (pipe
!= PIPE_B
) {
1749 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
);
1750 val
&= ~(CHV_BUFLEFTENA1_MASK
| CHV_BUFRIGHTENA1_MASK
);
1751 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
, val
);
1753 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
);
1754 val
&= ~(CHV_BUFLEFTENA2_MASK
| CHV_BUFRIGHTENA2_MASK
);
1755 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
, val
);
1758 mutex_unlock(&dev_priv
->dpio_lock
);
1761 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1762 struct intel_digital_port
*dport
)
1767 switch (dport
->port
) {
1769 port_mask
= DPLL_PORTB_READY_MASK
;
1773 port_mask
= DPLL_PORTC_READY_MASK
;
1777 port_mask
= DPLL_PORTD_READY_MASK
;
1778 dpll_reg
= DPIO_PHY_STATUS
;
1784 if (wait_for((I915_READ(dpll_reg
) & port_mask
) == 0, 1000))
1785 WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
1786 port_name(dport
->port
), I915_READ(dpll_reg
));
1789 static void intel_prepare_shared_dpll(struct intel_crtc
*crtc
)
1791 struct drm_device
*dev
= crtc
->base
.dev
;
1792 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1793 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1795 if (WARN_ON(pll
== NULL
))
1798 WARN_ON(!pll
->refcount
);
1799 if (pll
->active
== 0) {
1800 DRM_DEBUG_DRIVER("setting up %s\n", pll
->name
);
1802 assert_shared_dpll_disabled(dev_priv
, pll
);
1804 pll
->mode_set(dev_priv
, pll
);
1809 * intel_enable_shared_dpll - enable PCH PLL
1810 * @dev_priv: i915 private structure
1811 * @pipe: pipe PLL to enable
1813 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1814 * drives the transcoder clock.
1816 static void intel_enable_shared_dpll(struct intel_crtc
*crtc
)
1818 struct drm_device
*dev
= crtc
->base
.dev
;
1819 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1820 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1822 if (WARN_ON(pll
== NULL
))
1825 if (WARN_ON(pll
->refcount
== 0))
1828 DRM_DEBUG_KMS("enable %s (active %d, on? %d)for crtc %d\n",
1829 pll
->name
, pll
->active
, pll
->on
,
1830 crtc
->base
.base
.id
);
1832 if (pll
->active
++) {
1834 assert_shared_dpll_enabled(dev_priv
, pll
);
1839 DRM_DEBUG_KMS("enabling %s\n", pll
->name
);
1840 pll
->enable(dev_priv
, pll
);
1844 static void intel_disable_shared_dpll(struct intel_crtc
*crtc
)
1846 struct drm_device
*dev
= crtc
->base
.dev
;
1847 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1848 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1850 /* PCH only available on ILK+ */
1851 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1852 if (WARN_ON(pll
== NULL
))
1855 if (WARN_ON(pll
->refcount
== 0))
1858 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1859 pll
->name
, pll
->active
, pll
->on
,
1860 crtc
->base
.base
.id
);
1862 if (WARN_ON(pll
->active
== 0)) {
1863 assert_shared_dpll_disabled(dev_priv
, pll
);
1867 assert_shared_dpll_enabled(dev_priv
, pll
);
1872 DRM_DEBUG_KMS("disabling %s\n", pll
->name
);
1873 pll
->disable(dev_priv
, pll
);
1877 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1880 struct drm_device
*dev
= dev_priv
->dev
;
1881 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1882 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1883 uint32_t reg
, val
, pipeconf_val
;
1885 /* PCH only available on ILK+ */
1886 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1888 /* Make sure PCH DPLL is enabled */
1889 assert_shared_dpll_enabled(dev_priv
,
1890 intel_crtc_to_shared_dpll(intel_crtc
));
1892 /* FDI must be feeding us bits for PCH ports */
1893 assert_fdi_tx_enabled(dev_priv
, pipe
);
1894 assert_fdi_rx_enabled(dev_priv
, pipe
);
1896 if (HAS_PCH_CPT(dev
)) {
1897 /* Workaround: Set the timing override bit before enabling the
1898 * pch transcoder. */
1899 reg
= TRANS_CHICKEN2(pipe
);
1900 val
= I915_READ(reg
);
1901 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1902 I915_WRITE(reg
, val
);
1905 reg
= PCH_TRANSCONF(pipe
);
1906 val
= I915_READ(reg
);
1907 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1909 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1911 * make the BPC in transcoder be consistent with
1912 * that in pipeconf reg.
1914 val
&= ~PIPECONF_BPC_MASK
;
1915 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1918 val
&= ~TRANS_INTERLACE_MASK
;
1919 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1920 if (HAS_PCH_IBX(dev_priv
->dev
) &&
1921 intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
))
1922 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1924 val
|= TRANS_INTERLACED
;
1926 val
|= TRANS_PROGRESSIVE
;
1928 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1929 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
1930 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1933 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1934 enum transcoder cpu_transcoder
)
1936 u32 val
, pipeconf_val
;
1938 /* PCH only available on ILK+ */
1939 BUG_ON(INTEL_INFO(dev_priv
->dev
)->gen
< 5);
1941 /* FDI must be feeding us bits for PCH ports */
1942 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1943 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1945 /* Workaround: set timing override bit. */
1946 val
= I915_READ(_TRANSA_CHICKEN2
);
1947 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1948 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1951 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1953 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1954 PIPECONF_INTERLACED_ILK
)
1955 val
|= TRANS_INTERLACED
;
1957 val
|= TRANS_PROGRESSIVE
;
1959 I915_WRITE(LPT_TRANSCONF
, val
);
1960 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
1961 DRM_ERROR("Failed to enable PCH transcoder\n");
1964 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1967 struct drm_device
*dev
= dev_priv
->dev
;
1970 /* FDI relies on the transcoder */
1971 assert_fdi_tx_disabled(dev_priv
, pipe
);
1972 assert_fdi_rx_disabled(dev_priv
, pipe
);
1974 /* Ports must be off as well */
1975 assert_pch_ports_disabled(dev_priv
, pipe
);
1977 reg
= PCH_TRANSCONF(pipe
);
1978 val
= I915_READ(reg
);
1979 val
&= ~TRANS_ENABLE
;
1980 I915_WRITE(reg
, val
);
1981 /* wait for PCH transcoder off, transcoder state */
1982 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
1983 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1985 if (!HAS_PCH_IBX(dev
)) {
1986 /* Workaround: Clear the timing override chicken bit again. */
1987 reg
= TRANS_CHICKEN2(pipe
);
1988 val
= I915_READ(reg
);
1989 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1990 I915_WRITE(reg
, val
);
1994 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1998 val
= I915_READ(LPT_TRANSCONF
);
1999 val
&= ~TRANS_ENABLE
;
2000 I915_WRITE(LPT_TRANSCONF
, val
);
2001 /* wait for PCH transcoder off, transcoder state */
2002 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
2003 DRM_ERROR("Failed to disable PCH transcoder\n");
2005 /* Workaround: clear timing override bit. */
2006 val
= I915_READ(_TRANSA_CHICKEN2
);
2007 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
2008 I915_WRITE(_TRANSA_CHICKEN2
, val
);
2012 * intel_enable_pipe - enable a pipe, asserting requirements
2013 * @crtc: crtc responsible for the pipe
2015 * Enable @crtc's pipe, making sure that various hardware specific requirements
2016 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
2018 static void intel_enable_pipe(struct intel_crtc
*crtc
)
2020 struct drm_device
*dev
= crtc
->base
.dev
;
2021 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2022 enum pipe pipe
= crtc
->pipe
;
2023 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
2025 enum pipe pch_transcoder
;
2029 assert_planes_disabled(dev_priv
, pipe
);
2030 assert_cursor_disabled(dev_priv
, pipe
);
2031 assert_sprites_disabled(dev_priv
, pipe
);
2033 if (HAS_PCH_LPT(dev_priv
->dev
))
2034 pch_transcoder
= TRANSCODER_A
;
2036 pch_transcoder
= pipe
;
2039 * A pipe without a PLL won't actually be able to drive bits from
2040 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
2043 if (!HAS_PCH_SPLIT(dev_priv
->dev
))
2044 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DSI
))
2045 assert_dsi_pll_enabled(dev_priv
);
2047 assert_pll_enabled(dev_priv
, pipe
);
2049 if (crtc
->config
.has_pch_encoder
) {
2050 /* if driving the PCH, we need FDI enabled */
2051 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
2052 assert_fdi_tx_pll_enabled(dev_priv
,
2053 (enum pipe
) cpu_transcoder
);
2055 /* FIXME: assert CPU port conditions for SNB+ */
2058 reg
= PIPECONF(cpu_transcoder
);
2059 val
= I915_READ(reg
);
2060 if (val
& PIPECONF_ENABLE
) {
2061 WARN_ON(!(pipe
== PIPE_A
&&
2062 dev_priv
->quirks
& QUIRK_PIPEA_FORCE
));
2066 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
2071 * intel_disable_pipe - disable a pipe, asserting requirements
2072 * @dev_priv: i915 private structure
2073 * @pipe: pipe to disable
2075 * Disable @pipe, making sure that various hardware specific requirements
2076 * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
2078 * @pipe should be %PIPE_A or %PIPE_B.
2080 * Will wait until the pipe has shut down before returning.
2082 static void intel_disable_pipe(struct drm_i915_private
*dev_priv
,
2085 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
2091 * Make sure planes won't keep trying to pump pixels to us,
2092 * or we might hang the display.
2094 assert_planes_disabled(dev_priv
, pipe
);
2095 assert_cursor_disabled(dev_priv
, pipe
);
2096 assert_sprites_disabled(dev_priv
, pipe
);
2098 /* Don't disable pipe A or pipe A PLLs if needed */
2099 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
2102 reg
= PIPECONF(cpu_transcoder
);
2103 val
= I915_READ(reg
);
2104 if ((val
& PIPECONF_ENABLE
) == 0)
2107 I915_WRITE(reg
, val
& ~PIPECONF_ENABLE
);
2108 intel_wait_for_pipe_off(dev_priv
->dev
, pipe
);
2112 * Plane regs are double buffered, going from enabled->disabled needs a
2113 * trigger in order to latch. The display address reg provides this.
2115 void intel_flush_primary_plane(struct drm_i915_private
*dev_priv
,
2118 struct drm_device
*dev
= dev_priv
->dev
;
2119 u32 reg
= INTEL_INFO(dev
)->gen
>= 4 ? DSPSURF(plane
) : DSPADDR(plane
);
2121 I915_WRITE(reg
, I915_READ(reg
));
2126 * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
2127 * @dev_priv: i915 private structure
2128 * @plane: plane to enable
2129 * @pipe: pipe being fed
2131 * Enable @plane on @pipe, making sure that @pipe is running first.
2133 static void intel_enable_primary_hw_plane(struct drm_i915_private
*dev_priv
,
2134 enum plane plane
, enum pipe pipe
)
2136 struct intel_crtc
*intel_crtc
=
2137 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
2141 /* If the pipe isn't enabled, we can't pump pixels and may hang */
2142 assert_pipe_enabled(dev_priv
, pipe
);
2144 if (intel_crtc
->primary_enabled
)
2147 intel_crtc
->primary_enabled
= true;
2149 reg
= DSPCNTR(plane
);
2150 val
= I915_READ(reg
);
2151 WARN_ON(val
& DISPLAY_PLANE_ENABLE
);
2153 I915_WRITE(reg
, val
| DISPLAY_PLANE_ENABLE
);
2154 intel_flush_primary_plane(dev_priv
, plane
);
2158 * intel_disable_primary_hw_plane - disable the primary hardware plane
2159 * @dev_priv: i915 private structure
2160 * @plane: plane to disable
2161 * @pipe: pipe consuming the data
2163 * Disable @plane; should be an independent operation.
2165 static void intel_disable_primary_hw_plane(struct drm_i915_private
*dev_priv
,
2166 enum plane plane
, enum pipe pipe
)
2168 struct intel_crtc
*intel_crtc
=
2169 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
2173 if (!intel_crtc
->primary_enabled
)
2176 intel_crtc
->primary_enabled
= false;
2178 reg
= DSPCNTR(plane
);
2179 val
= I915_READ(reg
);
2180 WARN_ON((val
& DISPLAY_PLANE_ENABLE
) == 0);
2182 I915_WRITE(reg
, val
& ~DISPLAY_PLANE_ENABLE
);
2183 intel_flush_primary_plane(dev_priv
, plane
);
2186 static bool need_vtd_wa(struct drm_device
*dev
)
2188 #ifdef CONFIG_INTEL_IOMMU
2189 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2195 static int intel_align_height(struct drm_device
*dev
, int height
, bool tiled
)
2199 tile_height
= tiled
? (IS_GEN2(dev
) ? 16 : 8) : 1;
2200 return ALIGN(height
, tile_height
);
2204 intel_pin_and_fence_fb_obj(struct drm_device
*dev
,
2205 struct drm_i915_gem_object
*obj
,
2206 struct intel_engine_cs
*pipelined
)
2208 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2212 switch (obj
->tiling_mode
) {
2213 case I915_TILING_NONE
:
2214 if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
2215 alignment
= 128 * 1024;
2216 else if (INTEL_INFO(dev
)->gen
>= 4)
2217 alignment
= 4 * 1024;
2219 alignment
= 64 * 1024;
2222 /* pin() will align the object as required by fence */
2226 WARN(1, "Y tiled bo slipped through, driver bug!\n");
2232 /* Note that the w/a also requires 64 PTE of padding following the
2233 * bo. We currently fill all unused PTE with the shadow page and so
2234 * we should always have valid PTE following the scanout preventing
2237 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2238 alignment
= 256 * 1024;
2240 dev_priv
->mm
.interruptible
= false;
2241 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
);
2243 goto err_interruptible
;
2245 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2246 * fence, whereas 965+ only requires a fence if using
2247 * framebuffer compression. For simplicity, we always install
2248 * a fence as the cost is not that onerous.
2250 ret
= i915_gem_object_get_fence(obj
);
2254 i915_gem_object_pin_fence(obj
);
2256 dev_priv
->mm
.interruptible
= true;
2260 i915_gem_object_unpin_from_display_plane(obj
);
2262 dev_priv
->mm
.interruptible
= true;
2266 void intel_unpin_fb_obj(struct drm_i915_gem_object
*obj
)
2268 i915_gem_object_unpin_fence(obj
);
2269 i915_gem_object_unpin_from_display_plane(obj
);
2272 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2273 * is assumed to be a power-of-two. */
2274 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
2275 unsigned int tiling_mode
,
2279 if (tiling_mode
!= I915_TILING_NONE
) {
2280 unsigned int tile_rows
, tiles
;
2285 tiles
= *x
/ (512/cpp
);
2288 return tile_rows
* pitch
* 8 + tiles
* 4096;
2290 unsigned int offset
;
2292 offset
= *y
* pitch
+ *x
* cpp
;
2294 *x
= (offset
& 4095) / cpp
;
2295 return offset
& -4096;
2299 int intel_format_to_fourcc(int format
)
2302 case DISPPLANE_8BPP
:
2303 return DRM_FORMAT_C8
;
2304 case DISPPLANE_BGRX555
:
2305 return DRM_FORMAT_XRGB1555
;
2306 case DISPPLANE_BGRX565
:
2307 return DRM_FORMAT_RGB565
;
2309 case DISPPLANE_BGRX888
:
2310 return DRM_FORMAT_XRGB8888
;
2311 case DISPPLANE_RGBX888
:
2312 return DRM_FORMAT_XBGR8888
;
2313 case DISPPLANE_BGRX101010
:
2314 return DRM_FORMAT_XRGB2101010
;
2315 case DISPPLANE_RGBX101010
:
2316 return DRM_FORMAT_XBGR2101010
;
2320 static bool intel_alloc_plane_obj(struct intel_crtc
*crtc
,
2321 struct intel_plane_config
*plane_config
)
2323 struct drm_device
*dev
= crtc
->base
.dev
;
2324 struct drm_i915_gem_object
*obj
= NULL
;
2325 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2326 u32 base
= plane_config
->base
;
2328 if (plane_config
->size
== 0)
2331 obj
= i915_gem_object_create_stolen_for_preallocated(dev
, base
, base
,
2332 plane_config
->size
);
2336 if (plane_config
->tiled
) {
2337 obj
->tiling_mode
= I915_TILING_X
;
2338 obj
->stride
= crtc
->base
.primary
->fb
->pitches
[0];
2341 mode_cmd
.pixel_format
= crtc
->base
.primary
->fb
->pixel_format
;
2342 mode_cmd
.width
= crtc
->base
.primary
->fb
->width
;
2343 mode_cmd
.height
= crtc
->base
.primary
->fb
->height
;
2344 mode_cmd
.pitches
[0] = crtc
->base
.primary
->fb
->pitches
[0];
2346 mutex_lock(&dev
->struct_mutex
);
2348 if (intel_framebuffer_init(dev
, to_intel_framebuffer(crtc
->base
.primary
->fb
),
2350 DRM_DEBUG_KMS("intel fb init failed\n");
2354 mutex_unlock(&dev
->struct_mutex
);
2356 DRM_DEBUG_KMS("plane fb obj %p\n", obj
);
2360 drm_gem_object_unreference(&obj
->base
);
2361 mutex_unlock(&dev
->struct_mutex
);
2365 static void intel_find_plane_obj(struct intel_crtc
*intel_crtc
,
2366 struct intel_plane_config
*plane_config
)
2368 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2370 struct intel_crtc
*i
;
2371 struct intel_framebuffer
*fb
;
2373 if (!intel_crtc
->base
.primary
->fb
)
2376 if (intel_alloc_plane_obj(intel_crtc
, plane_config
))
2379 kfree(intel_crtc
->base
.primary
->fb
);
2380 intel_crtc
->base
.primary
->fb
= NULL
;
2383 * Failed to alloc the obj, check to see if we should share
2384 * an fb with another CRTC instead
2386 for_each_crtc(dev
, c
) {
2387 i
= to_intel_crtc(c
);
2389 if (c
== &intel_crtc
->base
)
2392 if (!i
->active
|| !c
->primary
->fb
)
2395 fb
= to_intel_framebuffer(c
->primary
->fb
);
2396 if (i915_gem_obj_ggtt_offset(fb
->obj
) == plane_config
->base
) {
2397 drm_framebuffer_reference(c
->primary
->fb
);
2398 intel_crtc
->base
.primary
->fb
= c
->primary
->fb
;
2404 static void i9xx_update_primary_plane(struct drm_crtc
*crtc
,
2405 struct drm_framebuffer
*fb
,
2408 struct drm_device
*dev
= crtc
->dev
;
2409 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2410 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2411 struct intel_framebuffer
*intel_fb
;
2412 struct drm_i915_gem_object
*obj
;
2413 int plane
= intel_crtc
->plane
;
2414 unsigned long linear_offset
;
2418 intel_fb
= to_intel_framebuffer(fb
);
2419 obj
= intel_fb
->obj
;
2421 reg
= DSPCNTR(plane
);
2422 dspcntr
= I915_READ(reg
);
2423 /* Mask out pixel format bits in case we change it */
2424 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
2425 switch (fb
->pixel_format
) {
2427 dspcntr
|= DISPPLANE_8BPP
;
2429 case DRM_FORMAT_XRGB1555
:
2430 case DRM_FORMAT_ARGB1555
:
2431 dspcntr
|= DISPPLANE_BGRX555
;
2433 case DRM_FORMAT_RGB565
:
2434 dspcntr
|= DISPPLANE_BGRX565
;
2436 case DRM_FORMAT_XRGB8888
:
2437 case DRM_FORMAT_ARGB8888
:
2438 dspcntr
|= DISPPLANE_BGRX888
;
2440 case DRM_FORMAT_XBGR8888
:
2441 case DRM_FORMAT_ABGR8888
:
2442 dspcntr
|= DISPPLANE_RGBX888
;
2444 case DRM_FORMAT_XRGB2101010
:
2445 case DRM_FORMAT_ARGB2101010
:
2446 dspcntr
|= DISPPLANE_BGRX101010
;
2448 case DRM_FORMAT_XBGR2101010
:
2449 case DRM_FORMAT_ABGR2101010
:
2450 dspcntr
|= DISPPLANE_RGBX101010
;
2456 if (INTEL_INFO(dev
)->gen
>= 4) {
2457 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2458 dspcntr
|= DISPPLANE_TILED
;
2460 dspcntr
&= ~DISPPLANE_TILED
;
2464 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2466 I915_WRITE(reg
, dspcntr
);
2468 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2470 if (INTEL_INFO(dev
)->gen
>= 4) {
2471 intel_crtc
->dspaddr_offset
=
2472 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2473 fb
->bits_per_pixel
/ 8,
2475 linear_offset
-= intel_crtc
->dspaddr_offset
;
2477 intel_crtc
->dspaddr_offset
= linear_offset
;
2480 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2481 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2483 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2484 if (INTEL_INFO(dev
)->gen
>= 4) {
2485 I915_WRITE(DSPSURF(plane
),
2486 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2487 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2488 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2490 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2494 static void ironlake_update_primary_plane(struct drm_crtc
*crtc
,
2495 struct drm_framebuffer
*fb
,
2498 struct drm_device
*dev
= crtc
->dev
;
2499 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2500 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2501 struct intel_framebuffer
*intel_fb
;
2502 struct drm_i915_gem_object
*obj
;
2503 int plane
= intel_crtc
->plane
;
2504 unsigned long linear_offset
;
2508 intel_fb
= to_intel_framebuffer(fb
);
2509 obj
= intel_fb
->obj
;
2511 reg
= DSPCNTR(plane
);
2512 dspcntr
= I915_READ(reg
);
2513 /* Mask out pixel format bits in case we change it */
2514 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
2515 switch (fb
->pixel_format
) {
2517 dspcntr
|= DISPPLANE_8BPP
;
2519 case DRM_FORMAT_RGB565
:
2520 dspcntr
|= DISPPLANE_BGRX565
;
2522 case DRM_FORMAT_XRGB8888
:
2523 case DRM_FORMAT_ARGB8888
:
2524 dspcntr
|= DISPPLANE_BGRX888
;
2526 case DRM_FORMAT_XBGR8888
:
2527 case DRM_FORMAT_ABGR8888
:
2528 dspcntr
|= DISPPLANE_RGBX888
;
2530 case DRM_FORMAT_XRGB2101010
:
2531 case DRM_FORMAT_ARGB2101010
:
2532 dspcntr
|= DISPPLANE_BGRX101010
;
2534 case DRM_FORMAT_XBGR2101010
:
2535 case DRM_FORMAT_ABGR2101010
:
2536 dspcntr
|= DISPPLANE_RGBX101010
;
2542 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2543 dspcntr
|= DISPPLANE_TILED
;
2545 dspcntr
&= ~DISPPLANE_TILED
;
2547 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2548 dspcntr
&= ~DISPPLANE_TRICKLE_FEED_DISABLE
;
2550 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2552 I915_WRITE(reg
, dspcntr
);
2554 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2555 intel_crtc
->dspaddr_offset
=
2556 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2557 fb
->bits_per_pixel
/ 8,
2559 linear_offset
-= intel_crtc
->dspaddr_offset
;
2561 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2562 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2564 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2565 I915_WRITE(DSPSURF(plane
),
2566 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2567 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2568 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2570 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2571 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2576 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2578 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
2579 int x
, int y
, enum mode_set_atomic state
)
2581 struct drm_device
*dev
= crtc
->dev
;
2582 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2584 if (dev_priv
->display
.disable_fbc
)
2585 dev_priv
->display
.disable_fbc(dev
);
2586 intel_increase_pllclock(crtc
);
2588 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2593 void intel_display_handle_reset(struct drm_device
*dev
)
2595 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2596 struct drm_crtc
*crtc
;
2599 * Flips in the rings have been nuked by the reset,
2600 * so complete all pending flips so that user space
2601 * will get its events and not get stuck.
2603 * Also update the base address of all primary
2604 * planes to the the last fb to make sure we're
2605 * showing the correct fb after a reset.
2607 * Need to make two loops over the crtcs so that we
2608 * don't try to grab a crtc mutex before the
2609 * pending_flip_queue really got woken up.
2612 for_each_crtc(dev
, crtc
) {
2613 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2614 enum plane plane
= intel_crtc
->plane
;
2616 intel_prepare_page_flip(dev
, plane
);
2617 intel_finish_page_flip_plane(dev
, plane
);
2620 for_each_crtc(dev
, crtc
) {
2621 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2623 drm_modeset_lock(&crtc
->mutex
, NULL
);
2625 * FIXME: Once we have proper support for primary planes (and
2626 * disabling them without disabling the entire crtc) allow again
2627 * a NULL crtc->primary->fb.
2629 if (intel_crtc
->active
&& crtc
->primary
->fb
)
2630 dev_priv
->display
.update_primary_plane(crtc
,
2634 drm_modeset_unlock(&crtc
->mutex
);
2639 intel_finish_fb(struct drm_framebuffer
*old_fb
)
2641 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(old_fb
)->obj
;
2642 struct drm_i915_private
*dev_priv
= obj
->base
.dev
->dev_private
;
2643 bool was_interruptible
= dev_priv
->mm
.interruptible
;
2646 /* Big Hammer, we also need to ensure that any pending
2647 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2648 * current scanout is retired before unpinning the old
2651 * This should only fail upon a hung GPU, in which case we
2652 * can safely continue.
2654 dev_priv
->mm
.interruptible
= false;
2655 ret
= i915_gem_object_finish_gpu(obj
);
2656 dev_priv
->mm
.interruptible
= was_interruptible
;
2661 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
2663 struct drm_device
*dev
= crtc
->dev
;
2664 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2665 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2666 unsigned long flags
;
2669 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
2670 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
2673 spin_lock_irqsave(&dev
->event_lock
, flags
);
2674 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
2675 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2681 intel_pipe_set_base(struct drm_crtc
*crtc
, int x
, int y
,
2682 struct drm_framebuffer
*fb
)
2684 struct drm_device
*dev
= crtc
->dev
;
2685 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2686 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2687 struct drm_framebuffer
*old_fb
;
2690 if (intel_crtc_has_pending_flip(crtc
)) {
2691 DRM_ERROR("pipe is still busy with an old pageflip\n");
2697 DRM_ERROR("No FB bound\n");
2701 if (intel_crtc
->plane
> INTEL_INFO(dev
)->num_pipes
) {
2702 DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
2703 plane_name(intel_crtc
->plane
),
2704 INTEL_INFO(dev
)->num_pipes
);
2708 mutex_lock(&dev
->struct_mutex
);
2709 ret
= intel_pin_and_fence_fb_obj(dev
,
2710 to_intel_framebuffer(fb
)->obj
,
2712 mutex_unlock(&dev
->struct_mutex
);
2714 DRM_ERROR("pin & fence failed\n");
2719 * Update pipe size and adjust fitter if needed: the reason for this is
2720 * that in compute_mode_changes we check the native mode (not the pfit
2721 * mode) to see if we can flip rather than do a full mode set. In the
2722 * fastboot case, we'll flip, but if we don't update the pipesrc and
2723 * pfit state, we'll end up with a big fb scanned out into the wrong
2726 * To fix this properly, we need to hoist the checks up into
2727 * compute_mode_changes (or above), check the actual pfit state and
2728 * whether the platform allows pfit disable with pipe active, and only
2729 * then update the pipesrc and pfit state, even on the flip path.
2731 if (i915
.fastboot
) {
2732 const struct drm_display_mode
*adjusted_mode
=
2733 &intel_crtc
->config
.adjusted_mode
;
2735 I915_WRITE(PIPESRC(intel_crtc
->pipe
),
2736 ((adjusted_mode
->crtc_hdisplay
- 1) << 16) |
2737 (adjusted_mode
->crtc_vdisplay
- 1));
2738 if (!intel_crtc
->config
.pch_pfit
.enabled
&&
2739 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
2740 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
2741 I915_WRITE(PF_CTL(intel_crtc
->pipe
), 0);
2742 I915_WRITE(PF_WIN_POS(intel_crtc
->pipe
), 0);
2743 I915_WRITE(PF_WIN_SZ(intel_crtc
->pipe
), 0);
2745 intel_crtc
->config
.pipe_src_w
= adjusted_mode
->crtc_hdisplay
;
2746 intel_crtc
->config
.pipe_src_h
= adjusted_mode
->crtc_vdisplay
;
2749 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2751 old_fb
= crtc
->primary
->fb
;
2752 crtc
->primary
->fb
= fb
;
2757 if (intel_crtc
->active
&& old_fb
!= fb
)
2758 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2759 mutex_lock(&dev
->struct_mutex
);
2760 intel_unpin_fb_obj(to_intel_framebuffer(old_fb
)->obj
);
2761 mutex_unlock(&dev
->struct_mutex
);
2764 mutex_lock(&dev
->struct_mutex
);
2765 intel_update_fbc(dev
);
2766 mutex_unlock(&dev
->struct_mutex
);
2771 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
2773 struct drm_device
*dev
= crtc
->dev
;
2774 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2775 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2776 int pipe
= intel_crtc
->pipe
;
2779 /* enable normal train */
2780 reg
= FDI_TX_CTL(pipe
);
2781 temp
= I915_READ(reg
);
2782 if (IS_IVYBRIDGE(dev
)) {
2783 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2784 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2786 temp
&= ~FDI_LINK_TRAIN_NONE
;
2787 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2789 I915_WRITE(reg
, temp
);
2791 reg
= FDI_RX_CTL(pipe
);
2792 temp
= I915_READ(reg
);
2793 if (HAS_PCH_CPT(dev
)) {
2794 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2795 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
2797 temp
&= ~FDI_LINK_TRAIN_NONE
;
2798 temp
|= FDI_LINK_TRAIN_NONE
;
2800 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
2802 /* wait one idle pattern time */
2806 /* IVB wants error correction enabled */
2807 if (IS_IVYBRIDGE(dev
))
2808 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
2809 FDI_FE_ERRC_ENABLE
);
2812 static bool pipe_has_enabled_pch(struct intel_crtc
*crtc
)
2814 return crtc
->base
.enabled
&& crtc
->active
&&
2815 crtc
->config
.has_pch_encoder
;
2818 static void ivb_modeset_global_resources(struct drm_device
*dev
)
2820 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2821 struct intel_crtc
*pipe_B_crtc
=
2822 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
2823 struct intel_crtc
*pipe_C_crtc
=
2824 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]);
2828 * When everything is off disable fdi C so that we could enable fdi B
2829 * with all lanes. Note that we don't care about enabled pipes without
2830 * an enabled pch encoder.
2832 if (!pipe_has_enabled_pch(pipe_B_crtc
) &&
2833 !pipe_has_enabled_pch(pipe_C_crtc
)) {
2834 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
2835 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
2837 temp
= I915_READ(SOUTH_CHICKEN1
);
2838 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
2839 DRM_DEBUG_KMS("disabling fdi C rx\n");
2840 I915_WRITE(SOUTH_CHICKEN1
, temp
);
2844 /* The FDI link training functions for ILK/Ibexpeak. */
2845 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
2847 struct drm_device
*dev
= crtc
->dev
;
2848 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2849 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2850 int pipe
= intel_crtc
->pipe
;
2851 u32 reg
, temp
, tries
;
2853 /* FDI needs bits from pipe first */
2854 assert_pipe_enabled(dev_priv
, pipe
);
2856 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2858 reg
= FDI_RX_IMR(pipe
);
2859 temp
= I915_READ(reg
);
2860 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2861 temp
&= ~FDI_RX_BIT_LOCK
;
2862 I915_WRITE(reg
, temp
);
2866 /* enable CPU FDI TX and PCH FDI RX */
2867 reg
= FDI_TX_CTL(pipe
);
2868 temp
= I915_READ(reg
);
2869 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2870 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2871 temp
&= ~FDI_LINK_TRAIN_NONE
;
2872 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2873 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2875 reg
= FDI_RX_CTL(pipe
);
2876 temp
= I915_READ(reg
);
2877 temp
&= ~FDI_LINK_TRAIN_NONE
;
2878 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2879 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2884 /* Ironlake workaround, enable clock pointer after FDI enable*/
2885 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
2886 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
2887 FDI_RX_PHASE_SYNC_POINTER_EN
);
2889 reg
= FDI_RX_IIR(pipe
);
2890 for (tries
= 0; tries
< 5; tries
++) {
2891 temp
= I915_READ(reg
);
2892 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2894 if ((temp
& FDI_RX_BIT_LOCK
)) {
2895 DRM_DEBUG_KMS("FDI train 1 done.\n");
2896 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2901 DRM_ERROR("FDI train 1 fail!\n");
2904 reg
= FDI_TX_CTL(pipe
);
2905 temp
= I915_READ(reg
);
2906 temp
&= ~FDI_LINK_TRAIN_NONE
;
2907 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2908 I915_WRITE(reg
, temp
);
2910 reg
= FDI_RX_CTL(pipe
);
2911 temp
= I915_READ(reg
);
2912 temp
&= ~FDI_LINK_TRAIN_NONE
;
2913 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2914 I915_WRITE(reg
, temp
);
2919 reg
= FDI_RX_IIR(pipe
);
2920 for (tries
= 0; tries
< 5; tries
++) {
2921 temp
= I915_READ(reg
);
2922 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2924 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2925 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2926 DRM_DEBUG_KMS("FDI train 2 done.\n");
2931 DRM_ERROR("FDI train 2 fail!\n");
2933 DRM_DEBUG_KMS("FDI train done\n");
2937 static const int snb_b_fdi_train_param
[] = {
2938 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
2939 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
2940 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
2941 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
2944 /* The FDI link training functions for SNB/Cougarpoint. */
2945 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
2947 struct drm_device
*dev
= crtc
->dev
;
2948 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2949 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2950 int pipe
= intel_crtc
->pipe
;
2951 u32 reg
, temp
, i
, retry
;
2953 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2955 reg
= FDI_RX_IMR(pipe
);
2956 temp
= I915_READ(reg
);
2957 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2958 temp
&= ~FDI_RX_BIT_LOCK
;
2959 I915_WRITE(reg
, temp
);
2964 /* enable CPU FDI TX and PCH FDI RX */
2965 reg
= FDI_TX_CTL(pipe
);
2966 temp
= I915_READ(reg
);
2967 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2968 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2969 temp
&= ~FDI_LINK_TRAIN_NONE
;
2970 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2971 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2973 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2974 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2976 I915_WRITE(FDI_RX_MISC(pipe
),
2977 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
2979 reg
= FDI_RX_CTL(pipe
);
2980 temp
= I915_READ(reg
);
2981 if (HAS_PCH_CPT(dev
)) {
2982 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2983 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2985 temp
&= ~FDI_LINK_TRAIN_NONE
;
2986 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2988 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2993 for (i
= 0; i
< 4; i
++) {
2994 reg
= FDI_TX_CTL(pipe
);
2995 temp
= I915_READ(reg
);
2996 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2997 temp
|= snb_b_fdi_train_param
[i
];
2998 I915_WRITE(reg
, temp
);
3003 for (retry
= 0; retry
< 5; retry
++) {
3004 reg
= FDI_RX_IIR(pipe
);
3005 temp
= I915_READ(reg
);
3006 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3007 if (temp
& FDI_RX_BIT_LOCK
) {
3008 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3009 DRM_DEBUG_KMS("FDI train 1 done.\n");
3018 DRM_ERROR("FDI train 1 fail!\n");
3021 reg
= FDI_TX_CTL(pipe
);
3022 temp
= I915_READ(reg
);
3023 temp
&= ~FDI_LINK_TRAIN_NONE
;
3024 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3026 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3028 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3030 I915_WRITE(reg
, temp
);
3032 reg
= FDI_RX_CTL(pipe
);
3033 temp
= I915_READ(reg
);
3034 if (HAS_PCH_CPT(dev
)) {
3035 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3036 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3038 temp
&= ~FDI_LINK_TRAIN_NONE
;
3039 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3041 I915_WRITE(reg
, temp
);
3046 for (i
= 0; i
< 4; i
++) {
3047 reg
= FDI_TX_CTL(pipe
);
3048 temp
= I915_READ(reg
);
3049 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3050 temp
|= snb_b_fdi_train_param
[i
];
3051 I915_WRITE(reg
, temp
);
3056 for (retry
= 0; retry
< 5; retry
++) {
3057 reg
= FDI_RX_IIR(pipe
);
3058 temp
= I915_READ(reg
);
3059 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3060 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3061 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3062 DRM_DEBUG_KMS("FDI train 2 done.\n");
3071 DRM_ERROR("FDI train 2 fail!\n");
3073 DRM_DEBUG_KMS("FDI train done.\n");
3076 /* Manual link training for Ivy Bridge A0 parts */
3077 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3079 struct drm_device
*dev
= crtc
->dev
;
3080 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3081 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3082 int pipe
= intel_crtc
->pipe
;
3083 u32 reg
, temp
, i
, j
;
3085 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3087 reg
= FDI_RX_IMR(pipe
);
3088 temp
= I915_READ(reg
);
3089 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3090 temp
&= ~FDI_RX_BIT_LOCK
;
3091 I915_WRITE(reg
, temp
);
3096 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3097 I915_READ(FDI_RX_IIR(pipe
)));
3099 /* Try each vswing and preemphasis setting twice before moving on */
3100 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3101 /* disable first in case we need to retry */
3102 reg
= FDI_TX_CTL(pipe
);
3103 temp
= I915_READ(reg
);
3104 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3105 temp
&= ~FDI_TX_ENABLE
;
3106 I915_WRITE(reg
, temp
);
3108 reg
= FDI_RX_CTL(pipe
);
3109 temp
= I915_READ(reg
);
3110 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3111 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3112 temp
&= ~FDI_RX_ENABLE
;
3113 I915_WRITE(reg
, temp
);
3115 /* enable CPU FDI TX and PCH FDI RX */
3116 reg
= FDI_TX_CTL(pipe
);
3117 temp
= I915_READ(reg
);
3118 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3119 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3120 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3121 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3122 temp
|= snb_b_fdi_train_param
[j
/2];
3123 temp
|= FDI_COMPOSITE_SYNC
;
3124 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3126 I915_WRITE(FDI_RX_MISC(pipe
),
3127 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3129 reg
= FDI_RX_CTL(pipe
);
3130 temp
= I915_READ(reg
);
3131 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3132 temp
|= FDI_COMPOSITE_SYNC
;
3133 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3136 udelay(1); /* should be 0.5us */
3138 for (i
= 0; i
< 4; i
++) {
3139 reg
= FDI_RX_IIR(pipe
);
3140 temp
= I915_READ(reg
);
3141 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3143 if (temp
& FDI_RX_BIT_LOCK
||
3144 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3145 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3146 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3150 udelay(1); /* should be 0.5us */
3153 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3158 reg
= FDI_TX_CTL(pipe
);
3159 temp
= I915_READ(reg
);
3160 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3161 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3162 I915_WRITE(reg
, temp
);
3164 reg
= FDI_RX_CTL(pipe
);
3165 temp
= I915_READ(reg
);
3166 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3167 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3168 I915_WRITE(reg
, temp
);
3171 udelay(2); /* should be 1.5us */
3173 for (i
= 0; i
< 4; i
++) {
3174 reg
= FDI_RX_IIR(pipe
);
3175 temp
= I915_READ(reg
);
3176 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3178 if (temp
& FDI_RX_SYMBOL_LOCK
||
3179 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3180 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3181 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3185 udelay(2); /* should be 1.5us */
3188 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3192 DRM_DEBUG_KMS("FDI train done.\n");
3195 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3197 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3198 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3199 int pipe
= intel_crtc
->pipe
;
3203 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3204 reg
= FDI_RX_CTL(pipe
);
3205 temp
= I915_READ(reg
);
3206 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3207 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3208 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3209 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3214 /* Switch from Rawclk to PCDclk */
3215 temp
= I915_READ(reg
);
3216 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3221 /* Enable CPU FDI TX PLL, always on for Ironlake */
3222 reg
= FDI_TX_CTL(pipe
);
3223 temp
= I915_READ(reg
);
3224 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3225 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3232 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3234 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3235 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3236 int pipe
= intel_crtc
->pipe
;
3239 /* Switch from PCDclk to Rawclk */
3240 reg
= FDI_RX_CTL(pipe
);
3241 temp
= I915_READ(reg
);
3242 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3244 /* Disable CPU FDI TX PLL */
3245 reg
= FDI_TX_CTL(pipe
);
3246 temp
= I915_READ(reg
);
3247 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3252 reg
= FDI_RX_CTL(pipe
);
3253 temp
= I915_READ(reg
);
3254 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3256 /* Wait for the clocks to turn off. */
3261 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3263 struct drm_device
*dev
= crtc
->dev
;
3264 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3265 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3266 int pipe
= intel_crtc
->pipe
;
3269 /* disable CPU FDI tx and PCH FDI rx */
3270 reg
= FDI_TX_CTL(pipe
);
3271 temp
= I915_READ(reg
);
3272 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3275 reg
= FDI_RX_CTL(pipe
);
3276 temp
= I915_READ(reg
);
3277 temp
&= ~(0x7 << 16);
3278 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3279 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3284 /* Ironlake workaround, disable clock pointer after downing FDI */
3285 if (HAS_PCH_IBX(dev
))
3286 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3288 /* still set train pattern 1 */
3289 reg
= FDI_TX_CTL(pipe
);
3290 temp
= I915_READ(reg
);
3291 temp
&= ~FDI_LINK_TRAIN_NONE
;
3292 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3293 I915_WRITE(reg
, temp
);
3295 reg
= FDI_RX_CTL(pipe
);
3296 temp
= I915_READ(reg
);
3297 if (HAS_PCH_CPT(dev
)) {
3298 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3299 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3301 temp
&= ~FDI_LINK_TRAIN_NONE
;
3302 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3304 /* BPC in FDI rx is consistent with that in PIPECONF */
3305 temp
&= ~(0x07 << 16);
3306 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3307 I915_WRITE(reg
, temp
);
3313 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3315 struct intel_crtc
*crtc
;
3317 /* Note that we don't need to be called with mode_config.lock here
3318 * as our list of CRTC objects is static for the lifetime of the
3319 * device and so cannot disappear as we iterate. Similarly, we can
3320 * happily treat the predicates as racy, atomic checks as userspace
3321 * cannot claim and pin a new fb without at least acquring the
3322 * struct_mutex and so serialising with us.
3324 for_each_intel_crtc(dev
, crtc
) {
3325 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3328 if (crtc
->unpin_work
)
3329 intel_wait_for_vblank(dev
, crtc
->pipe
);
3337 void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3339 struct drm_device
*dev
= crtc
->dev
;
3340 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3342 if (crtc
->primary
->fb
== NULL
)
3345 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3347 WARN_ON(wait_event_timeout(dev_priv
->pending_flip_queue
,
3348 !intel_crtc_has_pending_flip(crtc
),
3351 mutex_lock(&dev
->struct_mutex
);
3352 intel_finish_fb(crtc
->primary
->fb
);
3353 mutex_unlock(&dev
->struct_mutex
);
3356 /* Program iCLKIP clock to the desired frequency */
3357 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3359 struct drm_device
*dev
= crtc
->dev
;
3360 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3361 int clock
= to_intel_crtc(crtc
)->config
.adjusted_mode
.crtc_clock
;
3362 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3365 mutex_lock(&dev_priv
->dpio_lock
);
3367 /* It is necessary to ungate the pixclk gate prior to programming
3368 * the divisors, and gate it back when it is done.
3370 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3372 /* Disable SSCCTL */
3373 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
3374 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
3378 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3379 if (clock
== 20000) {
3384 /* The iCLK virtual clock root frequency is in MHz,
3385 * but the adjusted_mode->crtc_clock in in KHz. To get the
3386 * divisors, it is necessary to divide one by another, so we
3387 * convert the virtual clock precision to KHz here for higher
3390 u32 iclk_virtual_root_freq
= 172800 * 1000;
3391 u32 iclk_pi_range
= 64;
3392 u32 desired_divisor
, msb_divisor_value
, pi_value
;
3394 desired_divisor
= (iclk_virtual_root_freq
/ clock
);
3395 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
3396 pi_value
= desired_divisor
% iclk_pi_range
;
3399 divsel
= msb_divisor_value
- 2;
3400 phaseinc
= pi_value
;
3403 /* This should not happen with any sane values */
3404 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3405 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3406 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3407 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3409 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3416 /* Program SSCDIVINTPHASE6 */
3417 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3418 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
3419 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
3420 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
3421 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
3422 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
3423 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
3424 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
3426 /* Program SSCAUXDIV */
3427 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3428 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3429 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
3430 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
3432 /* Enable modulator and associated divider */
3433 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3434 temp
&= ~SBI_SSCCTL_DISABLE
;
3435 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3437 /* Wait for initialization time */
3440 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
3442 mutex_unlock(&dev_priv
->dpio_lock
);
3445 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
3446 enum pipe pch_transcoder
)
3448 struct drm_device
*dev
= crtc
->base
.dev
;
3449 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3450 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
3452 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
3453 I915_READ(HTOTAL(cpu_transcoder
)));
3454 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
3455 I915_READ(HBLANK(cpu_transcoder
)));
3456 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
3457 I915_READ(HSYNC(cpu_transcoder
)));
3459 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
3460 I915_READ(VTOTAL(cpu_transcoder
)));
3461 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
3462 I915_READ(VBLANK(cpu_transcoder
)));
3463 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
3464 I915_READ(VSYNC(cpu_transcoder
)));
3465 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
3466 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
3469 static void cpt_enable_fdi_bc_bifurcation(struct drm_device
*dev
)
3471 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3474 temp
= I915_READ(SOUTH_CHICKEN1
);
3475 if (temp
& FDI_BC_BIFURCATION_SELECT
)
3478 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
3479 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
3481 temp
|= FDI_BC_BIFURCATION_SELECT
;
3482 DRM_DEBUG_KMS("enabling fdi C rx\n");
3483 I915_WRITE(SOUTH_CHICKEN1
, temp
);
3484 POSTING_READ(SOUTH_CHICKEN1
);
3487 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
3489 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3490 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3492 switch (intel_crtc
->pipe
) {
3496 if (intel_crtc
->config
.fdi_lanes
> 2)
3497 WARN_ON(I915_READ(SOUTH_CHICKEN1
) & FDI_BC_BIFURCATION_SELECT
);
3499 cpt_enable_fdi_bc_bifurcation(dev
);
3503 cpt_enable_fdi_bc_bifurcation(dev
);
3512 * Enable PCH resources required for PCH ports:
3514 * - FDI training & RX/TX
3515 * - update transcoder timings
3516 * - DP transcoding bits
3519 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
3521 struct drm_device
*dev
= crtc
->dev
;
3522 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3523 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3524 int pipe
= intel_crtc
->pipe
;
3527 assert_pch_transcoder_disabled(dev_priv
, pipe
);
3529 if (IS_IVYBRIDGE(dev
))
3530 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
3532 /* Write the TU size bits before fdi link training, so that error
3533 * detection works. */
3534 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
3535 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
3537 /* For PCH output, training FDI link */
3538 dev_priv
->display
.fdi_link_train(crtc
);
3540 /* We need to program the right clock selection before writing the pixel
3541 * mutliplier into the DPLL. */
3542 if (HAS_PCH_CPT(dev
)) {
3545 temp
= I915_READ(PCH_DPLL_SEL
);
3546 temp
|= TRANS_DPLL_ENABLE(pipe
);
3547 sel
= TRANS_DPLLB_SEL(pipe
);
3548 if (intel_crtc
->config
.shared_dpll
== DPLL_ID_PCH_PLL_B
)
3552 I915_WRITE(PCH_DPLL_SEL
, temp
);
3555 /* XXX: pch pll's can be enabled any time before we enable the PCH
3556 * transcoder, and we actually should do this to not upset any PCH
3557 * transcoder that already use the clock when we share it.
3559 * Note that enable_shared_dpll tries to do the right thing, but
3560 * get_shared_dpll unconditionally resets the pll - we need that to have
3561 * the right LVDS enable sequence. */
3562 intel_enable_shared_dpll(intel_crtc
);
3564 /* set transcoder timing, panel must allow it */
3565 assert_panel_unlocked(dev_priv
, pipe
);
3566 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
3568 intel_fdi_normal_train(crtc
);
3570 /* For PCH DP, enable TRANS_DP_CTL */
3571 if (HAS_PCH_CPT(dev
) &&
3572 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
3573 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3574 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
3575 reg
= TRANS_DP_CTL(pipe
);
3576 temp
= I915_READ(reg
);
3577 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
3578 TRANS_DP_SYNC_MASK
|
3580 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
3581 TRANS_DP_ENH_FRAMING
);
3582 temp
|= bpc
<< 9; /* same format but at 11:9 */
3584 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
3585 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
3586 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
3587 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
3589 switch (intel_trans_dp_port_sel(crtc
)) {
3591 temp
|= TRANS_DP_PORT_SEL_B
;
3594 temp
|= TRANS_DP_PORT_SEL_C
;
3597 temp
|= TRANS_DP_PORT_SEL_D
;
3603 I915_WRITE(reg
, temp
);
3606 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
3609 static void lpt_pch_enable(struct drm_crtc
*crtc
)
3611 struct drm_device
*dev
= crtc
->dev
;
3612 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3613 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3614 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
3616 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
3618 lpt_program_iclkip(crtc
);
3620 /* Set transcoder timing. */
3621 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
3623 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
3626 static void intel_put_shared_dpll(struct intel_crtc
*crtc
)
3628 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3633 if (pll
->refcount
== 0) {
3634 WARN(1, "bad %s refcount\n", pll
->name
);
3638 if (--pll
->refcount
== 0) {
3640 WARN_ON(pll
->active
);
3643 crtc
->config
.shared_dpll
= DPLL_ID_PRIVATE
;
3646 static struct intel_shared_dpll
*intel_get_shared_dpll(struct intel_crtc
*crtc
)
3648 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
3649 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3650 enum intel_dpll_id i
;
3653 DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
3654 crtc
->base
.base
.id
, pll
->name
);
3655 intel_put_shared_dpll(crtc
);
3658 if (HAS_PCH_IBX(dev_priv
->dev
)) {
3659 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3660 i
= (enum intel_dpll_id
) crtc
->pipe
;
3661 pll
= &dev_priv
->shared_dplls
[i
];
3663 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
3664 crtc
->base
.base
.id
, pll
->name
);
3666 WARN_ON(pll
->refcount
);
3671 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3672 pll
= &dev_priv
->shared_dplls
[i
];
3674 /* Only want to check enabled timings first */
3675 if (pll
->refcount
== 0)
3678 if (memcmp(&crtc
->config
.dpll_hw_state
, &pll
->hw_state
,
3679 sizeof(pll
->hw_state
)) == 0) {
3680 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
3682 pll
->name
, pll
->refcount
, pll
->active
);
3688 /* Ok no matching timings, maybe there's a free one? */
3689 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3690 pll
= &dev_priv
->shared_dplls
[i
];
3691 if (pll
->refcount
== 0) {
3692 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
3693 crtc
->base
.base
.id
, pll
->name
);
3701 if (pll
->refcount
== 0)
3702 pll
->hw_state
= crtc
->config
.dpll_hw_state
;
3704 crtc
->config
.shared_dpll
= i
;
3705 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll
->name
,
3706 pipe_name(crtc
->pipe
));
3713 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
3715 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3716 int dslreg
= PIPEDSL(pipe
);
3719 temp
= I915_READ(dslreg
);
3721 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
3722 if (wait_for(I915_READ(dslreg
) != temp
, 5))
3723 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
3727 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
3729 struct drm_device
*dev
= crtc
->base
.dev
;
3730 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3731 int pipe
= crtc
->pipe
;
3733 if (crtc
->config
.pch_pfit
.enabled
) {
3734 /* Force use of hard-coded filter coefficients
3735 * as some pre-programmed values are broken,
3738 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
3739 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
3740 PF_PIPE_SEL_IVB(pipe
));
3742 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
3743 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
.pch_pfit
.pos
);
3744 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
.pch_pfit
.size
);
3748 static void intel_enable_planes(struct drm_crtc
*crtc
)
3750 struct drm_device
*dev
= crtc
->dev
;
3751 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3752 struct drm_plane
*plane
;
3753 struct intel_plane
*intel_plane
;
3755 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3756 intel_plane
= to_intel_plane(plane
);
3757 if (intel_plane
->pipe
== pipe
)
3758 intel_plane_restore(&intel_plane
->base
);
3762 static void intel_disable_planes(struct drm_crtc
*crtc
)
3764 struct drm_device
*dev
= crtc
->dev
;
3765 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3766 struct drm_plane
*plane
;
3767 struct intel_plane
*intel_plane
;
3769 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3770 intel_plane
= to_intel_plane(plane
);
3771 if (intel_plane
->pipe
== pipe
)
3772 intel_plane_disable(&intel_plane
->base
);
3776 void hsw_enable_ips(struct intel_crtc
*crtc
)
3778 struct drm_device
*dev
= crtc
->base
.dev
;
3779 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3781 if (!crtc
->config
.ips_enabled
)
3784 /* We can only enable IPS after we enable a plane and wait for a vblank */
3785 intel_wait_for_vblank(dev
, crtc
->pipe
);
3787 assert_plane_enabled(dev_priv
, crtc
->plane
);
3788 if (IS_BROADWELL(dev
)) {
3789 mutex_lock(&dev_priv
->rps
.hw_lock
);
3790 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
3791 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3792 /* Quoting Art Runyan: "its not safe to expect any particular
3793 * value in IPS_CTL bit 31 after enabling IPS through the
3794 * mailbox." Moreover, the mailbox may return a bogus state,
3795 * so we need to just enable it and continue on.
3798 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
3799 /* The bit only becomes 1 in the next vblank, so this wait here
3800 * is essentially intel_wait_for_vblank. If we don't have this
3801 * and don't wait for vblanks until the end of crtc_enable, then
3802 * the HW state readout code will complain that the expected
3803 * IPS_CTL value is not the one we read. */
3804 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
3805 DRM_ERROR("Timed out waiting for IPS enable\n");
3809 void hsw_disable_ips(struct intel_crtc
*crtc
)
3811 struct drm_device
*dev
= crtc
->base
.dev
;
3812 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3814 if (!crtc
->config
.ips_enabled
)
3817 assert_plane_enabled(dev_priv
, crtc
->plane
);
3818 if (IS_BROADWELL(dev
)) {
3819 mutex_lock(&dev_priv
->rps
.hw_lock
);
3820 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
3821 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3822 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
3823 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
3824 DRM_ERROR("Timed out waiting for IPS disable\n");
3826 I915_WRITE(IPS_CTL
, 0);
3827 POSTING_READ(IPS_CTL
);
3830 /* We need to wait for a vblank before we can disable the plane. */
3831 intel_wait_for_vblank(dev
, crtc
->pipe
);
3834 /** Loads the palette/gamma unit for the CRTC with the prepared values */
3835 static void intel_crtc_load_lut(struct drm_crtc
*crtc
)
3837 struct drm_device
*dev
= crtc
->dev
;
3838 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3839 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3840 enum pipe pipe
= intel_crtc
->pipe
;
3841 int palreg
= PALETTE(pipe
);
3843 bool reenable_ips
= false;
3845 /* The clocks have to be on to load the palette. */
3846 if (!crtc
->enabled
|| !intel_crtc
->active
)
3849 if (!HAS_PCH_SPLIT(dev_priv
->dev
)) {
3850 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
))
3851 assert_dsi_pll_enabled(dev_priv
);
3853 assert_pll_enabled(dev_priv
, pipe
);
3856 /* use legacy palette for Ironlake */
3857 if (HAS_PCH_SPLIT(dev
))
3858 palreg
= LGC_PALETTE(pipe
);
3860 /* Workaround : Do not read or write the pipe palette/gamma data while
3861 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
3863 if (IS_HASWELL(dev
) && intel_crtc
->config
.ips_enabled
&&
3864 ((I915_READ(GAMMA_MODE(pipe
)) & GAMMA_MODE_MODE_MASK
) ==
3865 GAMMA_MODE_MODE_SPLIT
)) {
3866 hsw_disable_ips(intel_crtc
);
3867 reenable_ips
= true;
3870 for (i
= 0; i
< 256; i
++) {
3871 I915_WRITE(palreg
+ 4 * i
,
3872 (intel_crtc
->lut_r
[i
] << 16) |
3873 (intel_crtc
->lut_g
[i
] << 8) |
3874 intel_crtc
->lut_b
[i
]);
3878 hsw_enable_ips(intel_crtc
);
3881 static void intel_crtc_dpms_overlay(struct intel_crtc
*intel_crtc
, bool enable
)
3883 if (!enable
&& intel_crtc
->overlay
) {
3884 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3885 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3887 mutex_lock(&dev
->struct_mutex
);
3888 dev_priv
->mm
.interruptible
= false;
3889 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
3890 dev_priv
->mm
.interruptible
= true;
3891 mutex_unlock(&dev
->struct_mutex
);
3894 /* Let userspace switch the overlay on again. In most cases userspace
3895 * has to recompute where to put it anyway.
3900 * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
3901 * cursor plane briefly if not already running after enabling the display
3903 * This workaround avoids occasional blank screens when self refresh is
3907 g4x_fixup_plane(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
3909 u32 cntl
= I915_READ(CURCNTR(pipe
));
3911 if ((cntl
& CURSOR_MODE
) == 0) {
3912 u32 fw_bcl_self
= I915_READ(FW_BLC_SELF
);
3914 I915_WRITE(FW_BLC_SELF
, fw_bcl_self
& ~FW_BLC_SELF_EN
);
3915 I915_WRITE(CURCNTR(pipe
), CURSOR_MODE_64_ARGB_AX
);
3916 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
3917 I915_WRITE(CURCNTR(pipe
), cntl
);
3918 I915_WRITE(CURBASE(pipe
), I915_READ(CURBASE(pipe
)));
3919 I915_WRITE(FW_BLC_SELF
, fw_bcl_self
);
3923 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
)
3925 struct drm_device
*dev
= crtc
->dev
;
3926 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3927 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3928 int pipe
= intel_crtc
->pipe
;
3929 int plane
= intel_crtc
->plane
;
3931 drm_vblank_on(dev
, pipe
);
3933 intel_enable_primary_hw_plane(dev_priv
, plane
, pipe
);
3934 intel_enable_planes(crtc
);
3935 /* The fixup needs to happen before cursor is enabled */
3937 g4x_fixup_plane(dev_priv
, pipe
);
3938 intel_crtc_update_cursor(crtc
, true);
3939 intel_crtc_dpms_overlay(intel_crtc
, true);
3941 hsw_enable_ips(intel_crtc
);
3943 mutex_lock(&dev
->struct_mutex
);
3944 intel_update_fbc(dev
);
3945 mutex_unlock(&dev
->struct_mutex
);
3948 static void intel_crtc_disable_planes(struct drm_crtc
*crtc
)
3950 struct drm_device
*dev
= crtc
->dev
;
3951 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3952 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3953 int pipe
= intel_crtc
->pipe
;
3954 int plane
= intel_crtc
->plane
;
3956 intel_crtc_wait_for_pending_flips(crtc
);
3958 if (dev_priv
->fbc
.plane
== plane
)
3959 intel_disable_fbc(dev
);
3961 hsw_disable_ips(intel_crtc
);
3963 intel_crtc_dpms_overlay(intel_crtc
, false);
3964 intel_crtc_update_cursor(crtc
, false);
3965 intel_disable_planes(crtc
);
3966 intel_disable_primary_hw_plane(dev_priv
, plane
, pipe
);
3968 drm_vblank_off(dev
, pipe
);
3971 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
3973 struct drm_device
*dev
= crtc
->dev
;
3974 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3975 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3976 struct intel_encoder
*encoder
;
3977 int pipe
= intel_crtc
->pipe
;
3978 enum plane plane
= intel_crtc
->plane
;
3980 WARN_ON(!crtc
->enabled
);
3982 if (intel_crtc
->active
)
3985 if (intel_crtc
->config
.has_pch_encoder
)
3986 intel_prepare_shared_dpll(intel_crtc
);
3988 if (intel_crtc
->config
.has_dp_encoder
)
3989 intel_dp_set_m_n(intel_crtc
);
3991 intel_set_pipe_timings(intel_crtc
);
3993 if (intel_crtc
->config
.has_pch_encoder
) {
3994 intel_cpu_transcoder_set_m_n(intel_crtc
,
3995 &intel_crtc
->config
.fdi_m_n
);
3998 ironlake_set_pipeconf(crtc
);
4000 /* Set up the display plane register */
4001 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
);
4002 POSTING_READ(DSPCNTR(plane
));
4004 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4007 intel_crtc
->active
= true;
4009 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4010 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
4012 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4013 if (encoder
->pre_enable
)
4014 encoder
->pre_enable(encoder
);
4016 if (intel_crtc
->config
.has_pch_encoder
) {
4017 /* Note: FDI PLL enabling _must_ be done before we enable the
4018 * cpu pipes, hence this is separate from all the other fdi/pch
4020 ironlake_fdi_pll_enable(intel_crtc
);
4022 assert_fdi_tx_disabled(dev_priv
, pipe
);
4023 assert_fdi_rx_disabled(dev_priv
, pipe
);
4026 ironlake_pfit_enable(intel_crtc
);
4029 * On ILK+ LUT must be loaded before the pipe is running but with
4032 intel_crtc_load_lut(crtc
);
4034 intel_update_watermarks(crtc
);
4035 intel_enable_pipe(intel_crtc
);
4037 if (intel_crtc
->config
.has_pch_encoder
)
4038 ironlake_pch_enable(crtc
);
4040 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4041 encoder
->enable(encoder
);
4043 if (HAS_PCH_CPT(dev
))
4044 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4046 intel_crtc_enable_planes(crtc
);
4049 /* IPS only exists on ULT machines and is tied to pipe A. */
4050 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4052 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4056 * This implements the workaround described in the "notes" section of the mode
4057 * set sequence documentation. When going from no pipes or single pipe to
4058 * multiple pipes, and planes are enabled after the pipe, we need to wait at
4059 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
4061 static void haswell_mode_set_planes_workaround(struct intel_crtc
*crtc
)
4063 struct drm_device
*dev
= crtc
->base
.dev
;
4064 struct intel_crtc
*crtc_it
, *other_active_crtc
= NULL
;
4066 /* We want to get the other_active_crtc only if there's only 1 other
4068 for_each_intel_crtc(dev
, crtc_it
) {
4069 if (!crtc_it
->active
|| crtc_it
== crtc
)
4072 if (other_active_crtc
)
4075 other_active_crtc
= crtc_it
;
4077 if (!other_active_crtc
)
4080 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4081 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4084 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4086 struct drm_device
*dev
= crtc
->dev
;
4087 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4088 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4089 struct intel_encoder
*encoder
;
4090 int pipe
= intel_crtc
->pipe
;
4091 enum plane plane
= intel_crtc
->plane
;
4093 WARN_ON(!crtc
->enabled
);
4095 if (intel_crtc
->active
)
4098 if (intel_crtc
->config
.has_dp_encoder
)
4099 intel_dp_set_m_n(intel_crtc
);
4101 intel_set_pipe_timings(intel_crtc
);
4103 if (intel_crtc
->config
.has_pch_encoder
) {
4104 intel_cpu_transcoder_set_m_n(intel_crtc
,
4105 &intel_crtc
->config
.fdi_m_n
);
4108 haswell_set_pipeconf(crtc
);
4110 intel_set_pipe_csc(crtc
);
4112 /* Set up the display plane register */
4113 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
| DISPPLANE_PIPE_CSC_ENABLE
);
4114 POSTING_READ(DSPCNTR(plane
));
4116 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4119 intel_crtc
->active
= true;
4121 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4122 if (intel_crtc
->config
.has_pch_encoder
)
4123 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
4125 if (intel_crtc
->config
.has_pch_encoder
)
4126 dev_priv
->display
.fdi_link_train(crtc
);
4128 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4129 if (encoder
->pre_enable
)
4130 encoder
->pre_enable(encoder
);
4132 intel_ddi_enable_pipe_clock(intel_crtc
);
4134 ironlake_pfit_enable(intel_crtc
);
4137 * On ILK+ LUT must be loaded before the pipe is running but with
4140 intel_crtc_load_lut(crtc
);
4142 intel_ddi_set_pipe_settings(crtc
);
4143 intel_ddi_enable_transcoder_func(crtc
);
4145 intel_update_watermarks(crtc
);
4146 intel_enable_pipe(intel_crtc
);
4148 if (intel_crtc
->config
.has_pch_encoder
)
4149 lpt_pch_enable(crtc
);
4151 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4152 encoder
->enable(encoder
);
4153 intel_opregion_notify_encoder(encoder
, true);
4156 /* If we change the relative order between pipe/planes enabling, we need
4157 * to change the workaround. */
4158 haswell_mode_set_planes_workaround(intel_crtc
);
4159 intel_crtc_enable_planes(crtc
);
4162 static void ironlake_pfit_disable(struct intel_crtc
*crtc
)
4164 struct drm_device
*dev
= crtc
->base
.dev
;
4165 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4166 int pipe
= crtc
->pipe
;
4168 /* To avoid upsetting the power well on haswell only disable the pfit if
4169 * it's in use. The hw state code will make sure we get this right. */
4170 if (crtc
->config
.pch_pfit
.enabled
) {
4171 I915_WRITE(PF_CTL(pipe
), 0);
4172 I915_WRITE(PF_WIN_POS(pipe
), 0);
4173 I915_WRITE(PF_WIN_SZ(pipe
), 0);
4177 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
4179 struct drm_device
*dev
= crtc
->dev
;
4180 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4181 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4182 struct intel_encoder
*encoder
;
4183 int pipe
= intel_crtc
->pipe
;
4186 if (!intel_crtc
->active
)
4189 intel_crtc_disable_planes(crtc
);
4191 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4192 encoder
->disable(encoder
);
4194 if (intel_crtc
->config
.has_pch_encoder
)
4195 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, false);
4197 intel_disable_pipe(dev_priv
, pipe
);
4199 ironlake_pfit_disable(intel_crtc
);
4201 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4202 if (encoder
->post_disable
)
4203 encoder
->post_disable(encoder
);
4205 if (intel_crtc
->config
.has_pch_encoder
) {
4206 ironlake_fdi_disable(crtc
);
4208 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
4209 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
4211 if (HAS_PCH_CPT(dev
)) {
4212 /* disable TRANS_DP_CTL */
4213 reg
= TRANS_DP_CTL(pipe
);
4214 temp
= I915_READ(reg
);
4215 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
4216 TRANS_DP_PORT_SEL_MASK
);
4217 temp
|= TRANS_DP_PORT_SEL_NONE
;
4218 I915_WRITE(reg
, temp
);
4220 /* disable DPLL_SEL */
4221 temp
= I915_READ(PCH_DPLL_SEL
);
4222 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
4223 I915_WRITE(PCH_DPLL_SEL
, temp
);
4226 /* disable PCH DPLL */
4227 intel_disable_shared_dpll(intel_crtc
);
4229 ironlake_fdi_pll_disable(intel_crtc
);
4232 intel_crtc
->active
= false;
4233 intel_update_watermarks(crtc
);
4235 mutex_lock(&dev
->struct_mutex
);
4236 intel_update_fbc(dev
);
4237 mutex_unlock(&dev
->struct_mutex
);
4240 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
4242 struct drm_device
*dev
= crtc
->dev
;
4243 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4244 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4245 struct intel_encoder
*encoder
;
4246 int pipe
= intel_crtc
->pipe
;
4247 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
4249 if (!intel_crtc
->active
)
4252 intel_crtc_disable_planes(crtc
);
4254 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4255 intel_opregion_notify_encoder(encoder
, false);
4256 encoder
->disable(encoder
);
4259 if (intel_crtc
->config
.has_pch_encoder
)
4260 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, false);
4261 intel_disable_pipe(dev_priv
, pipe
);
4263 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
4265 ironlake_pfit_disable(intel_crtc
);
4267 intel_ddi_disable_pipe_clock(intel_crtc
);
4269 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4270 if (encoder
->post_disable
)
4271 encoder
->post_disable(encoder
);
4273 if (intel_crtc
->config
.has_pch_encoder
) {
4274 lpt_disable_pch_transcoder(dev_priv
);
4275 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
4276 intel_ddi_fdi_disable(crtc
);
4279 intel_crtc
->active
= false;
4280 intel_update_watermarks(crtc
);
4282 mutex_lock(&dev
->struct_mutex
);
4283 intel_update_fbc(dev
);
4284 mutex_unlock(&dev
->struct_mutex
);
4287 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
4289 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4290 intel_put_shared_dpll(intel_crtc
);
4293 static void haswell_crtc_off(struct drm_crtc
*crtc
)
4295 intel_ddi_put_crtc_pll(crtc
);
4298 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
4300 struct drm_device
*dev
= crtc
->base
.dev
;
4301 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4302 struct intel_crtc_config
*pipe_config
= &crtc
->config
;
4304 if (!crtc
->config
.gmch_pfit
.control
)
4308 * The panel fitter should only be adjusted whilst the pipe is disabled,
4309 * according to register description and PRM.
4311 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
4312 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4314 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
4315 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
4317 /* Border color in case we don't scale up to the full screen. Black by
4318 * default, change to something else for debugging. */
4319 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
4322 #define for_each_power_domain(domain, mask) \
4323 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
4324 if ((1 << (domain)) & (mask))
4326 enum intel_display_power_domain
4327 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
4329 struct drm_device
*dev
= intel_encoder
->base
.dev
;
4330 struct intel_digital_port
*intel_dig_port
;
4332 switch (intel_encoder
->type
) {
4333 case INTEL_OUTPUT_UNKNOWN
:
4334 /* Only DDI platforms should ever use this output type */
4335 WARN_ON_ONCE(!HAS_DDI(dev
));
4336 case INTEL_OUTPUT_DISPLAYPORT
:
4337 case INTEL_OUTPUT_HDMI
:
4338 case INTEL_OUTPUT_EDP
:
4339 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
4340 switch (intel_dig_port
->port
) {
4342 return POWER_DOMAIN_PORT_DDI_A_4_LANES
;
4344 return POWER_DOMAIN_PORT_DDI_B_4_LANES
;
4346 return POWER_DOMAIN_PORT_DDI_C_4_LANES
;
4348 return POWER_DOMAIN_PORT_DDI_D_4_LANES
;
4351 return POWER_DOMAIN_PORT_OTHER
;
4353 case INTEL_OUTPUT_ANALOG
:
4354 return POWER_DOMAIN_PORT_CRT
;
4355 case INTEL_OUTPUT_DSI
:
4356 return POWER_DOMAIN_PORT_DSI
;
4358 return POWER_DOMAIN_PORT_OTHER
;
4362 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
)
4364 struct drm_device
*dev
= crtc
->dev
;
4365 struct intel_encoder
*intel_encoder
;
4366 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4367 enum pipe pipe
= intel_crtc
->pipe
;
4368 bool pfit_enabled
= intel_crtc
->config
.pch_pfit
.enabled
;
4370 enum transcoder transcoder
;
4372 transcoder
= intel_pipe_to_cpu_transcoder(dev
->dev_private
, pipe
);
4374 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
4375 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
4377 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
4379 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
4380 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
4385 void intel_display_set_init_power(struct drm_i915_private
*dev_priv
,
4388 if (dev_priv
->power_domains
.init_power_on
== enable
)
4392 intel_display_power_get(dev_priv
, POWER_DOMAIN_INIT
);
4394 intel_display_power_put(dev_priv
, POWER_DOMAIN_INIT
);
4396 dev_priv
->power_domains
.init_power_on
= enable
;
4399 static void modeset_update_crtc_power_domains(struct drm_device
*dev
)
4401 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4402 unsigned long pipe_domains
[I915_MAX_PIPES
] = { 0, };
4403 struct intel_crtc
*crtc
;
4406 * First get all needed power domains, then put all unneeded, to avoid
4407 * any unnecessary toggling of the power wells.
4409 for_each_intel_crtc(dev
, crtc
) {
4410 enum intel_display_power_domain domain
;
4412 if (!crtc
->base
.enabled
)
4415 pipe_domains
[crtc
->pipe
] = get_crtc_power_domains(&crtc
->base
);
4417 for_each_power_domain(domain
, pipe_domains
[crtc
->pipe
])
4418 intel_display_power_get(dev_priv
, domain
);
4421 for_each_intel_crtc(dev
, crtc
) {
4422 enum intel_display_power_domain domain
;
4424 for_each_power_domain(domain
, crtc
->enabled_power_domains
)
4425 intel_display_power_put(dev_priv
, domain
);
4427 crtc
->enabled_power_domains
= pipe_domains
[crtc
->pipe
];
4430 intel_display_set_init_power(dev_priv
, false);
4433 int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
4435 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
4437 /* Obtain SKU information */
4438 mutex_lock(&dev_priv
->dpio_lock
);
4439 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
4440 CCK_FUSE_HPLL_FREQ_MASK
;
4441 mutex_unlock(&dev_priv
->dpio_lock
);
4443 return vco_freq
[hpll_freq
];
4446 /* Adjust CDclk dividers to allow high res or save power if possible */
4447 static void valleyview_set_cdclk(struct drm_device
*dev
, int cdclk
)
4449 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4452 WARN_ON(valleyview_cur_cdclk(dev_priv
) != dev_priv
->vlv_cdclk_freq
);
4453 dev_priv
->vlv_cdclk_freq
= cdclk
;
4455 if (cdclk
>= 320) /* jump to highest voltage for 400MHz too */
4457 else if (cdclk
== 266)
4462 mutex_lock(&dev_priv
->rps
.hw_lock
);
4463 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
4464 val
&= ~DSPFREQGUAR_MASK
;
4465 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
4466 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
4467 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
4468 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
4470 DRM_ERROR("timed out waiting for CDclk change\n");
4472 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4477 vco
= valleyview_get_vco(dev_priv
);
4478 divider
= ((vco
<< 1) / cdclk
) - 1;
4480 mutex_lock(&dev_priv
->dpio_lock
);
4481 /* adjust cdclk divider */
4482 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
4485 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
4486 mutex_unlock(&dev_priv
->dpio_lock
);
4489 mutex_lock(&dev_priv
->dpio_lock
);
4490 /* adjust self-refresh exit latency value */
4491 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
4495 * For high bandwidth configs, we set a higher latency in the bunit
4496 * so that the core display fetch happens in time to avoid underruns.
4499 val
|= 4500 / 250; /* 4.5 usec */
4501 val
|= 3000 / 250; /* 3.0 usec */
4502 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
4503 mutex_unlock(&dev_priv
->dpio_lock
);
4505 /* Since we changed the CDclk, we need to update the GMBUSFREQ too */
4506 intel_i2c_reset(dev
);
4509 int valleyview_cur_cdclk(struct drm_i915_private
*dev_priv
)
4514 vco
= valleyview_get_vco(dev_priv
);
4516 mutex_lock(&dev_priv
->dpio_lock
);
4517 divider
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
4518 mutex_unlock(&dev_priv
->dpio_lock
);
4522 cur_cdclk
= (vco
<< 1) / (divider
+ 1);
4527 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
4531 * Really only a few cases to deal with, as only 4 CDclks are supported:
4536 * So we check to see whether we're above 90% of the lower bin and
4539 if (max_pixclk
> 288000) {
4541 } else if (max_pixclk
> 240000) {
4545 /* Looks like the 200MHz CDclk freq doesn't work on some configs */
4548 /* compute the max pixel clock for new configuration */
4549 static int intel_mode_max_pixclk(struct drm_i915_private
*dev_priv
)
4551 struct drm_device
*dev
= dev_priv
->dev
;
4552 struct intel_crtc
*intel_crtc
;
4555 for_each_intel_crtc(dev
, intel_crtc
) {
4556 if (intel_crtc
->new_enabled
)
4557 max_pixclk
= max(max_pixclk
,
4558 intel_crtc
->new_config
->adjusted_mode
.crtc_clock
);
4564 static void valleyview_modeset_global_pipes(struct drm_device
*dev
,
4565 unsigned *prepare_pipes
)
4567 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4568 struct intel_crtc
*intel_crtc
;
4569 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4571 if (valleyview_calc_cdclk(dev_priv
, max_pixclk
) ==
4572 dev_priv
->vlv_cdclk_freq
)
4575 /* disable/enable all currently active pipes while we change cdclk */
4576 for_each_intel_crtc(dev
, intel_crtc
)
4577 if (intel_crtc
->base
.enabled
)
4578 *prepare_pipes
|= (1 << intel_crtc
->pipe
);
4581 static void valleyview_modeset_global_resources(struct drm_device
*dev
)
4583 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4584 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4585 int req_cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
4587 if (req_cdclk
!= dev_priv
->vlv_cdclk_freq
)
4588 valleyview_set_cdclk(dev
, req_cdclk
);
4589 modeset_update_crtc_power_domains(dev
);
4592 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
4594 struct drm_device
*dev
= crtc
->dev
;
4595 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4596 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4597 struct intel_encoder
*encoder
;
4598 int pipe
= intel_crtc
->pipe
;
4599 int plane
= intel_crtc
->plane
;
4603 WARN_ON(!crtc
->enabled
);
4605 if (intel_crtc
->active
)
4608 vlv_prepare_pll(intel_crtc
);
4610 /* Set up the display plane register */
4611 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
4613 if (intel_crtc
->config
.has_dp_encoder
)
4614 intel_dp_set_m_n(intel_crtc
);
4616 intel_set_pipe_timings(intel_crtc
);
4618 /* pipesrc and dspsize control the size that is scaled from,
4619 * which should always be the user's requested size.
4621 I915_WRITE(DSPSIZE(plane
),
4622 ((intel_crtc
->config
.pipe_src_h
- 1) << 16) |
4623 (intel_crtc
->config
.pipe_src_w
- 1));
4624 I915_WRITE(DSPPOS(plane
), 0);
4626 i9xx_set_pipeconf(intel_crtc
);
4628 I915_WRITE(DSPCNTR(plane
), dspcntr
);
4629 POSTING_READ(DSPCNTR(plane
));
4631 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4634 intel_crtc
->active
= true;
4636 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4638 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4639 if (encoder
->pre_pll_enable
)
4640 encoder
->pre_pll_enable(encoder
);
4642 is_dsi
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
);
4645 if (IS_CHERRYVIEW(dev
))
4646 chv_enable_pll(intel_crtc
);
4648 vlv_enable_pll(intel_crtc
);
4651 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4652 if (encoder
->pre_enable
)
4653 encoder
->pre_enable(encoder
);
4655 i9xx_pfit_enable(intel_crtc
);
4657 intel_crtc_load_lut(crtc
);
4659 intel_update_watermarks(crtc
);
4660 intel_enable_pipe(intel_crtc
);
4662 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4663 encoder
->enable(encoder
);
4665 intel_crtc_enable_planes(crtc
);
4667 /* Underruns don't raise interrupts, so check manually. */
4668 i9xx_check_fifo_underruns(dev
);
4671 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
4673 struct drm_device
*dev
= crtc
->base
.dev
;
4674 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4676 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp0
);
4677 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp1
);
4680 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
4682 struct drm_device
*dev
= crtc
->dev
;
4683 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4684 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4685 struct intel_encoder
*encoder
;
4686 int pipe
= intel_crtc
->pipe
;
4687 int plane
= intel_crtc
->plane
;
4690 WARN_ON(!crtc
->enabled
);
4692 if (intel_crtc
->active
)
4695 i9xx_set_pll_dividers(intel_crtc
);
4697 /* Set up the display plane register */
4698 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
4701 dspcntr
&= ~DISPPLANE_SEL_PIPE_MASK
;
4703 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
4705 if (intel_crtc
->config
.has_dp_encoder
)
4706 intel_dp_set_m_n(intel_crtc
);
4708 intel_set_pipe_timings(intel_crtc
);
4710 /* pipesrc and dspsize control the size that is scaled from,
4711 * which should always be the user's requested size.
4713 I915_WRITE(DSPSIZE(plane
),
4714 ((intel_crtc
->config
.pipe_src_h
- 1) << 16) |
4715 (intel_crtc
->config
.pipe_src_w
- 1));
4716 I915_WRITE(DSPPOS(plane
), 0);
4718 i9xx_set_pipeconf(intel_crtc
);
4720 I915_WRITE(DSPCNTR(plane
), dspcntr
);
4721 POSTING_READ(DSPCNTR(plane
));
4723 dev_priv
->display
.update_primary_plane(crtc
, crtc
->primary
->fb
,
4726 intel_crtc
->active
= true;
4729 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4731 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4732 if (encoder
->pre_enable
)
4733 encoder
->pre_enable(encoder
);
4735 i9xx_enable_pll(intel_crtc
);
4737 i9xx_pfit_enable(intel_crtc
);
4739 intel_crtc_load_lut(crtc
);
4741 intel_update_watermarks(crtc
);
4742 intel_enable_pipe(intel_crtc
);
4744 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4745 encoder
->enable(encoder
);
4747 intel_crtc_enable_planes(crtc
);
4750 * Gen2 reports pipe underruns whenever all planes are disabled.
4751 * So don't enable underrun reporting before at least some planes
4753 * FIXME: Need to fix the logic to work when we turn off all planes
4754 * but leave the pipe running.
4757 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4759 /* Underruns don't raise interrupts, so check manually. */
4760 i9xx_check_fifo_underruns(dev
);
4763 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
4765 struct drm_device
*dev
= crtc
->base
.dev
;
4766 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4768 if (!crtc
->config
.gmch_pfit
.control
)
4771 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4773 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
4774 I915_READ(PFIT_CONTROL
));
4775 I915_WRITE(PFIT_CONTROL
, 0);
4778 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
4780 struct drm_device
*dev
= crtc
->dev
;
4781 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4782 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4783 struct intel_encoder
*encoder
;
4784 int pipe
= intel_crtc
->pipe
;
4786 if (!intel_crtc
->active
)
4790 * Gen2 reports pipe underruns whenever all planes are disabled.
4791 * So diasble underrun reporting before all the planes get disabled.
4792 * FIXME: Need to fix the logic to work when we turn off all planes
4793 * but leave the pipe running.
4796 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, false);
4798 intel_crtc_disable_planes(crtc
);
4800 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4801 encoder
->disable(encoder
);
4804 * On gen2 planes are double buffered but the pipe isn't, so we must
4805 * wait for planes to fully turn off before disabling the pipe.
4808 intel_wait_for_vblank(dev
, pipe
);
4810 intel_disable_pipe(dev_priv
, pipe
);
4812 i9xx_pfit_disable(intel_crtc
);
4814 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4815 if (encoder
->post_disable
)
4816 encoder
->post_disable(encoder
);
4818 if (!intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
)) {
4819 if (IS_CHERRYVIEW(dev
))
4820 chv_disable_pll(dev_priv
, pipe
);
4821 else if (IS_VALLEYVIEW(dev
))
4822 vlv_disable_pll(dev_priv
, pipe
);
4824 i9xx_disable_pll(dev_priv
, pipe
);
4828 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, false);
4830 intel_crtc
->active
= false;
4831 intel_update_watermarks(crtc
);
4833 mutex_lock(&dev
->struct_mutex
);
4834 intel_update_fbc(dev
);
4835 mutex_unlock(&dev
->struct_mutex
);
4838 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
4842 static void intel_crtc_update_sarea(struct drm_crtc
*crtc
,
4845 struct drm_device
*dev
= crtc
->dev
;
4846 struct drm_i915_master_private
*master_priv
;
4847 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4848 int pipe
= intel_crtc
->pipe
;
4850 if (!dev
->primary
->master
)
4853 master_priv
= dev
->primary
->master
->driver_priv
;
4854 if (!master_priv
->sarea_priv
)
4859 master_priv
->sarea_priv
->pipeA_w
= enabled
? crtc
->mode
.hdisplay
: 0;
4860 master_priv
->sarea_priv
->pipeA_h
= enabled
? crtc
->mode
.vdisplay
: 0;
4863 master_priv
->sarea_priv
->pipeB_w
= enabled
? crtc
->mode
.hdisplay
: 0;
4864 master_priv
->sarea_priv
->pipeB_h
= enabled
? crtc
->mode
.vdisplay
: 0;
4867 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe
));
4873 * Sets the power management mode of the pipe and plane.
4875 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
4877 struct drm_device
*dev
= crtc
->dev
;
4878 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4879 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4880 struct intel_encoder
*intel_encoder
;
4881 enum intel_display_power_domain domain
;
4882 unsigned long domains
;
4883 bool enable
= false;
4885 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
4886 enable
|= intel_encoder
->connectors_active
;
4889 if (!intel_crtc
->active
) {
4891 * FIXME: DDI plls and relevant code isn't converted
4892 * yet, so do runtime PM for DPMS only for all other
4893 * platforms for now.
4895 if (!HAS_DDI(dev
)) {
4896 domains
= get_crtc_power_domains(crtc
);
4897 for_each_power_domain(domain
, domains
)
4898 intel_display_power_get(dev_priv
, domain
);
4899 intel_crtc
->enabled_power_domains
= domains
;
4902 dev_priv
->display
.crtc_enable(crtc
);
4905 if (intel_crtc
->active
) {
4906 dev_priv
->display
.crtc_disable(crtc
);
4908 if (!HAS_DDI(dev
)) {
4909 domains
= intel_crtc
->enabled_power_domains
;
4910 for_each_power_domain(domain
, domains
)
4911 intel_display_power_put(dev_priv
, domain
);
4912 intel_crtc
->enabled_power_domains
= 0;
4917 intel_crtc_update_sarea(crtc
, enable
);
4920 static void intel_crtc_disable(struct drm_crtc
*crtc
)
4922 struct drm_device
*dev
= crtc
->dev
;
4923 struct drm_connector
*connector
;
4924 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4926 /* crtc should still be enabled when we disable it. */
4927 WARN_ON(!crtc
->enabled
);
4929 dev_priv
->display
.crtc_disable(crtc
);
4930 intel_crtc_update_sarea(crtc
, false);
4931 dev_priv
->display
.off(crtc
);
4933 assert_plane_disabled(dev
->dev_private
, to_intel_crtc(crtc
)->plane
);
4934 assert_cursor_disabled(dev_priv
, to_intel_crtc(crtc
)->pipe
);
4935 assert_pipe_disabled(dev
->dev_private
, to_intel_crtc(crtc
)->pipe
);
4937 if (crtc
->primary
->fb
) {
4938 mutex_lock(&dev
->struct_mutex
);
4939 intel_unpin_fb_obj(to_intel_framebuffer(crtc
->primary
->fb
)->obj
);
4940 mutex_unlock(&dev
->struct_mutex
);
4941 crtc
->primary
->fb
= NULL
;
4944 /* Update computed state. */
4945 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
4946 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
4949 if (connector
->encoder
->crtc
!= crtc
)
4952 connector
->dpms
= DRM_MODE_DPMS_OFF
;
4953 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
4957 void intel_encoder_destroy(struct drm_encoder
*encoder
)
4959 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
4961 drm_encoder_cleanup(encoder
);
4962 kfree(intel_encoder
);
4965 /* Simple dpms helper for encoders with just one connector, no cloning and only
4966 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
4967 * state of the entire output pipe. */
4968 static void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
4970 if (mode
== DRM_MODE_DPMS_ON
) {
4971 encoder
->connectors_active
= true;
4973 intel_crtc_update_dpms(encoder
->base
.crtc
);
4975 encoder
->connectors_active
= false;
4977 intel_crtc_update_dpms(encoder
->base
.crtc
);
4981 /* Cross check the actual hw state with our own modeset state tracking (and it's
4982 * internal consistency). */
4983 static void intel_connector_check_state(struct intel_connector
*connector
)
4985 if (connector
->get_hw_state(connector
)) {
4986 struct intel_encoder
*encoder
= connector
->encoder
;
4987 struct drm_crtc
*crtc
;
4988 bool encoder_enabled
;
4991 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4992 connector
->base
.base
.id
,
4993 connector
->base
.name
);
4995 WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
4996 "wrong connector dpms state\n");
4997 WARN(connector
->base
.encoder
!= &encoder
->base
,
4998 "active connector not linked to encoder\n");
4999 WARN(!encoder
->connectors_active
,
5000 "encoder->connectors_active not set\n");
5002 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
5003 WARN(!encoder_enabled
, "encoder not enabled\n");
5004 if (WARN_ON(!encoder
->base
.crtc
))
5007 crtc
= encoder
->base
.crtc
;
5009 WARN(!crtc
->enabled
, "crtc not enabled\n");
5010 WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
5011 WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
5012 "encoder active on the wrong pipe\n");
5016 /* Even simpler default implementation, if there's really no special case to
5018 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
5020 /* All the simple cases only support two dpms states. */
5021 if (mode
!= DRM_MODE_DPMS_ON
)
5022 mode
= DRM_MODE_DPMS_OFF
;
5024 if (mode
== connector
->dpms
)
5027 connector
->dpms
= mode
;
5029 /* Only need to change hw state when actually enabled */
5030 if (connector
->encoder
)
5031 intel_encoder_dpms(to_intel_encoder(connector
->encoder
), mode
);
5033 intel_modeset_check_state(connector
->dev
);
5036 /* Simple connector->get_hw_state implementation for encoders that support only
5037 * one connector and no cloning and hence the encoder state determines the state
5038 * of the connector. */
5039 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
5042 struct intel_encoder
*encoder
= connector
->encoder
;
5044 return encoder
->get_hw_state(encoder
, &pipe
);
5047 static bool ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
5048 struct intel_crtc_config
*pipe_config
)
5050 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5051 struct intel_crtc
*pipe_B_crtc
=
5052 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
5054 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
5055 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5056 if (pipe_config
->fdi_lanes
> 4) {
5057 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
5058 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5062 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
5063 if (pipe_config
->fdi_lanes
> 2) {
5064 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
5065 pipe_config
->fdi_lanes
);
5072 if (INTEL_INFO(dev
)->num_pipes
== 2)
5075 /* Ivybridge 3 pipe is really complicated */
5080 if (dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]->enabled
&&
5081 pipe_config
->fdi_lanes
> 2) {
5082 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5083 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5088 if (!pipe_has_enabled_pch(pipe_B_crtc
) ||
5089 pipe_B_crtc
->config
.fdi_lanes
<= 2) {
5090 if (pipe_config
->fdi_lanes
> 2) {
5091 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5092 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5096 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5106 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
5107 struct intel_crtc_config
*pipe_config
)
5109 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5110 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5111 int lane
, link_bw
, fdi_dotclock
;
5112 bool setup_ok
, needs_recompute
= false;
5115 /* FDI is a binary signal running at ~2.7GHz, encoding
5116 * each output octet as 10 bits. The actual frequency
5117 * is stored as a divider into a 100MHz clock, and the
5118 * mode pixel clock is stored in units of 1KHz.
5119 * Hence the bw of each lane in terms of the mode signal
5122 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
5124 fdi_dotclock
= adjusted_mode
->crtc_clock
;
5126 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
5127 pipe_config
->pipe_bpp
);
5129 pipe_config
->fdi_lanes
= lane
;
5131 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
5132 link_bw
, &pipe_config
->fdi_m_n
);
5134 setup_ok
= ironlake_check_fdi_lanes(intel_crtc
->base
.dev
,
5135 intel_crtc
->pipe
, pipe_config
);
5136 if (!setup_ok
&& pipe_config
->pipe_bpp
> 6*3) {
5137 pipe_config
->pipe_bpp
-= 2*3;
5138 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
5139 pipe_config
->pipe_bpp
);
5140 needs_recompute
= true;
5141 pipe_config
->bw_constrained
= true;
5146 if (needs_recompute
)
5149 return setup_ok
? 0 : -EINVAL
;
5152 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
5153 struct intel_crtc_config
*pipe_config
)
5155 pipe_config
->ips_enabled
= i915
.enable_ips
&&
5156 hsw_crtc_supports_ips(crtc
) &&
5157 pipe_config
->pipe_bpp
<= 24;
5160 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
5161 struct intel_crtc_config
*pipe_config
)
5163 struct drm_device
*dev
= crtc
->base
.dev
;
5164 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5166 /* FIXME should check pixel clock limits on all platforms */
5167 if (INTEL_INFO(dev
)->gen
< 4) {
5168 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5170 dev_priv
->display
.get_display_clock_speed(dev
);
5173 * Enable pixel doubling when the dot clock
5174 * is > 90% of the (display) core speed.
5176 * GDG double wide on either pipe,
5177 * otherwise pipe A only.
5179 if ((crtc
->pipe
== PIPE_A
|| IS_I915G(dev
)) &&
5180 adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10) {
5182 pipe_config
->double_wide
= true;
5185 if (adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10)
5190 * Pipe horizontal size must be even in:
5192 * - LVDS dual channel mode
5193 * - Double wide pipe
5195 if ((intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5196 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
5197 pipe_config
->pipe_src_w
&= ~1;
5199 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
5200 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
5202 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
5203 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
5206 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) && pipe_config
->pipe_bpp
> 10*3) {
5207 pipe_config
->pipe_bpp
= 10*3; /* 12bpc is gen5+ */
5208 } else if (INTEL_INFO(dev
)->gen
<= 4 && pipe_config
->pipe_bpp
> 8*3) {
5209 /* only a 8bpc pipe, with 6bpc dither through the panel fitter
5211 pipe_config
->pipe_bpp
= 8*3;
5215 hsw_compute_ips_config(crtc
, pipe_config
);
5217 /* XXX: PCH clock sharing is done in ->mode_set, so make sure the old
5218 * clock survives for now. */
5219 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
5220 pipe_config
->shared_dpll
= crtc
->config
.shared_dpll
;
5222 if (pipe_config
->has_pch_encoder
)
5223 return ironlake_fdi_compute_config(crtc
, pipe_config
);
5228 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
5230 return 400000; /* FIXME */
5233 static int i945_get_display_clock_speed(struct drm_device
*dev
)
5238 static int i915_get_display_clock_speed(struct drm_device
*dev
)
5243 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
5248 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
5252 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5254 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5255 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
5257 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
5259 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
5261 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
5264 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
5265 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
5267 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
5272 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
5276 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5278 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
5281 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5282 case GC_DISPLAY_CLOCK_333_MHZ
:
5285 case GC_DISPLAY_CLOCK_190_200_MHZ
:
5291 static int i865_get_display_clock_speed(struct drm_device
*dev
)
5296 static int i855_get_display_clock_speed(struct drm_device
*dev
)
5299 /* Assume that the hardware is in the high speed state. This
5300 * should be the default.
5302 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
5303 case GC_CLOCK_133_200
:
5304 case GC_CLOCK_100_200
:
5306 case GC_CLOCK_166_250
:
5308 case GC_CLOCK_100_133
:
5312 /* Shouldn't happen */
5316 static int i830_get_display_clock_speed(struct drm_device
*dev
)
5322 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
5324 while (*num
> DATA_LINK_M_N_MASK
||
5325 *den
> DATA_LINK_M_N_MASK
) {
5331 static void compute_m_n(unsigned int m
, unsigned int n
,
5332 uint32_t *ret_m
, uint32_t *ret_n
)
5334 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
5335 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
5336 intel_reduce_m_n_ratio(ret_m
, ret_n
);
5340 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
5341 int pixel_clock
, int link_clock
,
5342 struct intel_link_m_n
*m_n
)
5346 compute_m_n(bits_per_pixel
* pixel_clock
,
5347 link_clock
* nlanes
* 8,
5348 &m_n
->gmch_m
, &m_n
->gmch_n
);
5350 compute_m_n(pixel_clock
, link_clock
,
5351 &m_n
->link_m
, &m_n
->link_n
);
5354 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
5356 if (i915
.panel_use_ssc
>= 0)
5357 return i915
.panel_use_ssc
!= 0;
5358 return dev_priv
->vbt
.lvds_use_ssc
5359 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
5362 static int i9xx_get_refclk(struct drm_crtc
*crtc
, int num_connectors
)
5364 struct drm_device
*dev
= crtc
->dev
;
5365 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5368 if (IS_VALLEYVIEW(dev
)) {
5370 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
5371 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
5372 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
5373 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
5374 } else if (!IS_GEN2(dev
)) {
5383 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
5385 return (1 << dpll
->n
) << 16 | dpll
->m2
;
5388 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
5390 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
5393 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
5394 intel_clock_t
*reduced_clock
)
5396 struct drm_device
*dev
= crtc
->base
.dev
;
5399 if (IS_PINEVIEW(dev
)) {
5400 fp
= pnv_dpll_compute_fp(&crtc
->config
.dpll
);
5402 fp2
= pnv_dpll_compute_fp(reduced_clock
);
5404 fp
= i9xx_dpll_compute_fp(&crtc
->config
.dpll
);
5406 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
5409 crtc
->config
.dpll_hw_state
.fp0
= fp
;
5411 crtc
->lowfreq_avail
= false;
5412 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5413 reduced_clock
&& i915
.powersave
) {
5414 crtc
->config
.dpll_hw_state
.fp1
= fp2
;
5415 crtc
->lowfreq_avail
= true;
5417 crtc
->config
.dpll_hw_state
.fp1
= fp
;
5421 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
5427 * PLLB opamp always calibrates to max value of 0x3f, force enable it
5428 * and set it to a reasonable value instead.
5430 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5431 reg_val
&= 0xffffff00;
5432 reg_val
|= 0x00000030;
5433 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5435 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5436 reg_val
&= 0x8cffffff;
5437 reg_val
= 0x8c000000;
5438 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5440 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5441 reg_val
&= 0xffffff00;
5442 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5444 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5445 reg_val
&= 0x00ffffff;
5446 reg_val
|= 0xb0000000;
5447 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5450 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
5451 struct intel_link_m_n
*m_n
)
5453 struct drm_device
*dev
= crtc
->base
.dev
;
5454 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5455 int pipe
= crtc
->pipe
;
5457 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5458 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
5459 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
5460 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
5463 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
5464 struct intel_link_m_n
*m_n
)
5466 struct drm_device
*dev
= crtc
->base
.dev
;
5467 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5468 int pipe
= crtc
->pipe
;
5469 enum transcoder transcoder
= crtc
->config
.cpu_transcoder
;
5471 if (INTEL_INFO(dev
)->gen
>= 5) {
5472 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5473 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
5474 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
5475 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
5477 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5478 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
5479 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
5480 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
5484 static void intel_dp_set_m_n(struct intel_crtc
*crtc
)
5486 if (crtc
->config
.has_pch_encoder
)
5487 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
5489 intel_cpu_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
5492 static void vlv_update_pll(struct intel_crtc
*crtc
)
5497 * Enable DPIO clock input. We should never disable the reference
5498 * clock for pipe B, since VGA hotplug / manual detection depends
5501 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
5502 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
5503 /* We should never disable this, set it here for state tracking */
5504 if (crtc
->pipe
== PIPE_B
)
5505 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5506 dpll
|= DPLL_VCO_ENABLE
;
5507 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5509 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
5510 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5511 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
5514 static void vlv_prepare_pll(struct intel_crtc
*crtc
)
5516 struct drm_device
*dev
= crtc
->base
.dev
;
5517 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5518 int pipe
= crtc
->pipe
;
5520 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
5521 u32 coreclk
, reg_val
;
5523 mutex_lock(&dev_priv
->dpio_lock
);
5525 bestn
= crtc
->config
.dpll
.n
;
5526 bestm1
= crtc
->config
.dpll
.m1
;
5527 bestm2
= crtc
->config
.dpll
.m2
;
5528 bestp1
= crtc
->config
.dpll
.p1
;
5529 bestp2
= crtc
->config
.dpll
.p2
;
5531 /* See eDP HDMI DPIO driver vbios notes doc */
5533 /* PLL B needs special handling */
5535 vlv_pllb_recal_opamp(dev_priv
, pipe
);
5537 /* Set up Tx target for periodic Rcomp update */
5538 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
5540 /* Disable target IRef on PLL */
5541 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
5542 reg_val
&= 0x00ffffff;
5543 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
5545 /* Disable fast lock */
5546 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
5548 /* Set idtafcrecal before PLL is enabled */
5549 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
5550 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
5551 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
5552 mdiv
|= (1 << DPIO_K_SHIFT
);
5555 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
5556 * but we don't support that).
5557 * Note: don't use the DAC post divider as it seems unstable.
5559 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
5560 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5562 mdiv
|= DPIO_ENABLE_CALIBRATION
;
5563 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5565 /* Set HBR and RBR LPF coefficients */
5566 if (crtc
->config
.port_clock
== 162000 ||
5567 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_ANALOG
) ||
5568 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
))
5569 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5572 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5575 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
) ||
5576 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
)) {
5577 /* Use SSC source */
5579 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5582 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5584 } else { /* HDMI or VGA */
5585 /* Use bend source */
5587 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5590 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5594 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
5595 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
5596 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
) ||
5597 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
))
5598 coreclk
|= 0x01000000;
5599 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
5601 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
5602 mutex_unlock(&dev_priv
->dpio_lock
);
5605 static void chv_update_pll(struct intel_crtc
*crtc
)
5607 struct drm_device
*dev
= crtc
->base
.dev
;
5608 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5609 int pipe
= crtc
->pipe
;
5610 int dpll_reg
= DPLL(crtc
->pipe
);
5611 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
5612 u32 loopfilter
, intcoeff
;
5613 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
5616 crtc
->config
.dpll_hw_state
.dpll
= DPLL_SSC_REF_CLOCK_CHV
|
5617 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
|
5620 crtc
->config
.dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5622 crtc
->config
.dpll_hw_state
.dpll_md
=
5623 (crtc
->config
.pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5625 bestn
= crtc
->config
.dpll
.n
;
5626 bestm2_frac
= crtc
->config
.dpll
.m2
& 0x3fffff;
5627 bestm1
= crtc
->config
.dpll
.m1
;
5628 bestm2
= crtc
->config
.dpll
.m2
>> 22;
5629 bestp1
= crtc
->config
.dpll
.p1
;
5630 bestp2
= crtc
->config
.dpll
.p2
;
5633 * Enable Refclk and SSC
5635 I915_WRITE(dpll_reg
,
5636 crtc
->config
.dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
5638 mutex_lock(&dev_priv
->dpio_lock
);
5640 /* p1 and p2 divider */
5641 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
5642 5 << DPIO_CHV_S1_DIV_SHIFT
|
5643 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
5644 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
5645 1 << DPIO_CHV_K_DIV_SHIFT
);
5647 /* Feedback post-divider - m2 */
5648 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
5650 /* Feedback refclk divider - n and m1 */
5651 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
5652 DPIO_CHV_M1_DIV_BY_2
|
5653 1 << DPIO_CHV_N_DIV_SHIFT
);
5655 /* M2 fraction division */
5656 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
5658 /* M2 fraction division enable */
5659 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
),
5660 DPIO_CHV_FRAC_DIV_EN
|
5661 (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
));
5664 refclk
= i9xx_get_refclk(&crtc
->base
, 0);
5665 loopfilter
= 5 << DPIO_CHV_PROP_COEFF_SHIFT
|
5666 2 << DPIO_CHV_GAIN_CTRL_SHIFT
;
5667 if (refclk
== 100000)
5669 else if (refclk
== 38400)
5673 loopfilter
|= intcoeff
<< DPIO_CHV_INT_COEFF_SHIFT
;
5674 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
5677 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
5678 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
5681 mutex_unlock(&dev_priv
->dpio_lock
);
5684 static void i9xx_update_pll(struct intel_crtc
*crtc
,
5685 intel_clock_t
*reduced_clock
,
5688 struct drm_device
*dev
= crtc
->base
.dev
;
5689 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5692 struct dpll
*clock
= &crtc
->config
.dpll
;
5694 i9xx_update_pll_dividers(crtc
, reduced_clock
);
5696 is_sdvo
= intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_SDVO
) ||
5697 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
);
5699 dpll
= DPLL_VGA_MODE_DIS
;
5701 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
))
5702 dpll
|= DPLLB_MODE_LVDS
;
5704 dpll
|= DPLLB_MODE_DAC_SERIAL
;
5706 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
5707 dpll
|= (crtc
->config
.pixel_multiplier
- 1)
5708 << SDVO_MULTIPLIER_SHIFT_HIRES
;
5712 dpll
|= DPLL_SDVO_HIGH_SPEED
;
5714 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
))
5715 dpll
|= DPLL_SDVO_HIGH_SPEED
;
5717 /* compute bitmask from p1 value */
5718 if (IS_PINEVIEW(dev
))
5719 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
5721 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5722 if (IS_G4X(dev
) && reduced_clock
)
5723 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
5725 switch (clock
->p2
) {
5727 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
5730 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
5733 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
5736 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
5739 if (INTEL_INFO(dev
)->gen
>= 4)
5740 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
5742 if (crtc
->config
.sdvo_tv_clock
)
5743 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
5744 else if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5745 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5746 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5748 dpll
|= PLL_REF_INPUT_DREFCLK
;
5750 dpll
|= DPLL_VCO_ENABLE
;
5751 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5753 if (INTEL_INFO(dev
)->gen
>= 4) {
5754 u32 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
5755 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5756 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
5760 static void i8xx_update_pll(struct intel_crtc
*crtc
,
5761 intel_clock_t
*reduced_clock
,
5764 struct drm_device
*dev
= crtc
->base
.dev
;
5765 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5767 struct dpll
*clock
= &crtc
->config
.dpll
;
5769 i9xx_update_pll_dividers(crtc
, reduced_clock
);
5771 dpll
= DPLL_VGA_MODE_DIS
;
5773 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
)) {
5774 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5777 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
5779 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5781 dpll
|= PLL_P2_DIVIDE_BY_4
;
5784 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DVO
))
5785 dpll
|= DPLL_DVO_2X_MODE
;
5787 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5788 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5789 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5791 dpll
|= PLL_REF_INPUT_DREFCLK
;
5793 dpll
|= DPLL_VCO_ENABLE
;
5794 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5797 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
5799 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5800 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5801 enum pipe pipe
= intel_crtc
->pipe
;
5802 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
5803 struct drm_display_mode
*adjusted_mode
=
5804 &intel_crtc
->config
.adjusted_mode
;
5805 uint32_t crtc_vtotal
, crtc_vblank_end
;
5808 /* We need to be careful not to changed the adjusted mode, for otherwise
5809 * the hw state checker will get angry at the mismatch. */
5810 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
5811 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
5813 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
5814 /* the chip adds 2 halflines automatically */
5816 crtc_vblank_end
-= 1;
5818 if (intel_pipe_has_type(&intel_crtc
->base
, INTEL_OUTPUT_SDVO
))
5819 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
5821 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
5822 adjusted_mode
->crtc_htotal
/ 2;
5824 vsyncshift
+= adjusted_mode
->crtc_htotal
;
5827 if (INTEL_INFO(dev
)->gen
> 3)
5828 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
5830 I915_WRITE(HTOTAL(cpu_transcoder
),
5831 (adjusted_mode
->crtc_hdisplay
- 1) |
5832 ((adjusted_mode
->crtc_htotal
- 1) << 16));
5833 I915_WRITE(HBLANK(cpu_transcoder
),
5834 (adjusted_mode
->crtc_hblank_start
- 1) |
5835 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
5836 I915_WRITE(HSYNC(cpu_transcoder
),
5837 (adjusted_mode
->crtc_hsync_start
- 1) |
5838 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
5840 I915_WRITE(VTOTAL(cpu_transcoder
),
5841 (adjusted_mode
->crtc_vdisplay
- 1) |
5842 ((crtc_vtotal
- 1) << 16));
5843 I915_WRITE(VBLANK(cpu_transcoder
),
5844 (adjusted_mode
->crtc_vblank_start
- 1) |
5845 ((crtc_vblank_end
- 1) << 16));
5846 I915_WRITE(VSYNC(cpu_transcoder
),
5847 (adjusted_mode
->crtc_vsync_start
- 1) |
5848 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
5850 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
5851 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
5852 * documented on the DDI_FUNC_CTL register description, EDP Input Select
5854 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
5855 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
5856 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
5858 /* pipesrc controls the size that is scaled from, which should
5859 * always be the user's requested size.
5861 I915_WRITE(PIPESRC(pipe
),
5862 ((intel_crtc
->config
.pipe_src_w
- 1) << 16) |
5863 (intel_crtc
->config
.pipe_src_h
- 1));
5866 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
5867 struct intel_crtc_config
*pipe_config
)
5869 struct drm_device
*dev
= crtc
->base
.dev
;
5870 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5871 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
5874 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
5875 pipe_config
->adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
5876 pipe_config
->adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
5877 tmp
= I915_READ(HBLANK(cpu_transcoder
));
5878 pipe_config
->adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
5879 pipe_config
->adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
5880 tmp
= I915_READ(HSYNC(cpu_transcoder
));
5881 pipe_config
->adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
5882 pipe_config
->adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
5884 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
5885 pipe_config
->adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
5886 pipe_config
->adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
5887 tmp
= I915_READ(VBLANK(cpu_transcoder
));
5888 pipe_config
->adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
5889 pipe_config
->adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
5890 tmp
= I915_READ(VSYNC(cpu_transcoder
));
5891 pipe_config
->adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
5892 pipe_config
->adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
5894 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
5895 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
5896 pipe_config
->adjusted_mode
.crtc_vtotal
+= 1;
5897 pipe_config
->adjusted_mode
.crtc_vblank_end
+= 1;
5900 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
5901 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
5902 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
5904 pipe_config
->requested_mode
.vdisplay
= pipe_config
->pipe_src_h
;
5905 pipe_config
->requested_mode
.hdisplay
= pipe_config
->pipe_src_w
;
5908 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
5909 struct intel_crtc_config
*pipe_config
)
5911 mode
->hdisplay
= pipe_config
->adjusted_mode
.crtc_hdisplay
;
5912 mode
->htotal
= pipe_config
->adjusted_mode
.crtc_htotal
;
5913 mode
->hsync_start
= pipe_config
->adjusted_mode
.crtc_hsync_start
;
5914 mode
->hsync_end
= pipe_config
->adjusted_mode
.crtc_hsync_end
;
5916 mode
->vdisplay
= pipe_config
->adjusted_mode
.crtc_vdisplay
;
5917 mode
->vtotal
= pipe_config
->adjusted_mode
.crtc_vtotal
;
5918 mode
->vsync_start
= pipe_config
->adjusted_mode
.crtc_vsync_start
;
5919 mode
->vsync_end
= pipe_config
->adjusted_mode
.crtc_vsync_end
;
5921 mode
->flags
= pipe_config
->adjusted_mode
.flags
;
5923 mode
->clock
= pipe_config
->adjusted_mode
.crtc_clock
;
5924 mode
->flags
|= pipe_config
->adjusted_mode
.flags
;
5927 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
5929 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5930 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5935 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
5936 I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
)
5937 pipeconf
|= PIPECONF_ENABLE
;
5939 if (intel_crtc
->config
.double_wide
)
5940 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
5942 /* only g4x and later have fancy bpc/dither controls */
5943 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
5944 /* Bspec claims that we can't use dithering for 30bpp pipes. */
5945 if (intel_crtc
->config
.dither
&& intel_crtc
->config
.pipe_bpp
!= 30)
5946 pipeconf
|= PIPECONF_DITHER_EN
|
5947 PIPECONF_DITHER_TYPE_SP
;
5949 switch (intel_crtc
->config
.pipe_bpp
) {
5951 pipeconf
|= PIPECONF_6BPC
;
5954 pipeconf
|= PIPECONF_8BPC
;
5957 pipeconf
|= PIPECONF_10BPC
;
5960 /* Case prevented by intel_choose_pipe_bpp_dither. */
5965 if (HAS_PIPE_CXSR(dev
)) {
5966 if (intel_crtc
->lowfreq_avail
) {
5967 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
5968 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
5970 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
5974 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
5975 if (INTEL_INFO(dev
)->gen
< 4 ||
5976 intel_pipe_has_type(&intel_crtc
->base
, INTEL_OUTPUT_SDVO
))
5977 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
5979 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
5981 pipeconf
|= PIPECONF_PROGRESSIVE
;
5983 if (IS_VALLEYVIEW(dev
) && intel_crtc
->config
.limited_color_range
)
5984 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
5986 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
5987 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
5990 static int i9xx_crtc_mode_set(struct drm_crtc
*crtc
,
5992 struct drm_framebuffer
*fb
)
5994 struct drm_device
*dev
= crtc
->dev
;
5995 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5996 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5997 int refclk
, num_connectors
= 0;
5998 intel_clock_t clock
, reduced_clock
;
5999 bool ok
, has_reduced_clock
= false;
6000 bool is_lvds
= false, is_dsi
= false;
6001 struct intel_encoder
*encoder
;
6002 const intel_limit_t
*limit
;
6004 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
6005 switch (encoder
->type
) {
6006 case INTEL_OUTPUT_LVDS
:
6009 case INTEL_OUTPUT_DSI
:
6020 if (!intel_crtc
->config
.clock_set
) {
6021 refclk
= i9xx_get_refclk(crtc
, num_connectors
);
6024 * Returns a set of divisors for the desired target clock with
6025 * the given refclk, or FALSE. The returned values represent
6026 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
6029 limit
= intel_limit(crtc
, refclk
);
6030 ok
= dev_priv
->display
.find_dpll(limit
, crtc
,
6031 intel_crtc
->config
.port_clock
,
6032 refclk
, NULL
, &clock
);
6034 DRM_ERROR("Couldn't find PLL settings for mode!\n");
6038 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
6040 * Ensure we match the reduced clock's P to the target
6041 * clock. If the clocks don't match, we can't switch
6042 * the display clock by using the FP0/FP1. In such case
6043 * we will disable the LVDS downclock feature.
6046 dev_priv
->display
.find_dpll(limit
, crtc
,
6047 dev_priv
->lvds_downclock
,
6051 /* Compat-code for transition, will disappear. */
6052 intel_crtc
->config
.dpll
.n
= clock
.n
;
6053 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
6054 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
6055 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
6056 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
6060 i8xx_update_pll(intel_crtc
,
6061 has_reduced_clock
? &reduced_clock
: NULL
,
6063 } else if (IS_CHERRYVIEW(dev
)) {
6064 chv_update_pll(intel_crtc
);
6065 } else if (IS_VALLEYVIEW(dev
)) {
6066 vlv_update_pll(intel_crtc
);
6068 i9xx_update_pll(intel_crtc
,
6069 has_reduced_clock
? &reduced_clock
: NULL
,
6076 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
6077 struct intel_crtc_config
*pipe_config
)
6079 struct drm_device
*dev
= crtc
->base
.dev
;
6080 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6083 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
6086 tmp
= I915_READ(PFIT_CONTROL
);
6087 if (!(tmp
& PFIT_ENABLE
))
6090 /* Check whether the pfit is attached to our pipe. */
6091 if (INTEL_INFO(dev
)->gen
< 4) {
6092 if (crtc
->pipe
!= PIPE_B
)
6095 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
6099 pipe_config
->gmch_pfit
.control
= tmp
;
6100 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
6101 if (INTEL_INFO(dev
)->gen
< 5)
6102 pipe_config
->gmch_pfit
.lvds_border_bits
=
6103 I915_READ(LVDS
) & LVDS_BORDER_ENABLE
;
6106 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
6107 struct intel_crtc_config
*pipe_config
)
6109 struct drm_device
*dev
= crtc
->base
.dev
;
6110 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6111 int pipe
= pipe_config
->cpu_transcoder
;
6112 intel_clock_t clock
;
6114 int refclk
= 100000;
6116 mutex_lock(&dev_priv
->dpio_lock
);
6117 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
6118 mutex_unlock(&dev_priv
->dpio_lock
);
6120 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
6121 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
6122 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
6123 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
6124 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
6126 vlv_clock(refclk
, &clock
);
6128 /* clock.dot is the fast clock */
6129 pipe_config
->port_clock
= clock
.dot
/ 5;
6132 static void i9xx_get_plane_config(struct intel_crtc
*crtc
,
6133 struct intel_plane_config
*plane_config
)
6135 struct drm_device
*dev
= crtc
->base
.dev
;
6136 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6137 u32 val
, base
, offset
;
6138 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
6139 int fourcc
, pixel_format
;
6142 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
6143 if (!crtc
->base
.primary
->fb
) {
6144 DRM_DEBUG_KMS("failed to alloc fb\n");
6148 val
= I915_READ(DSPCNTR(plane
));
6150 if (INTEL_INFO(dev
)->gen
>= 4)
6151 if (val
& DISPPLANE_TILED
)
6152 plane_config
->tiled
= true;
6154 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
6155 fourcc
= intel_format_to_fourcc(pixel_format
);
6156 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
6157 crtc
->base
.primary
->fb
->bits_per_pixel
=
6158 drm_format_plane_cpp(fourcc
, 0) * 8;
6160 if (INTEL_INFO(dev
)->gen
>= 4) {
6161 if (plane_config
->tiled
)
6162 offset
= I915_READ(DSPTILEOFF(plane
));
6164 offset
= I915_READ(DSPLINOFF(plane
));
6165 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
6167 base
= I915_READ(DSPADDR(plane
));
6169 plane_config
->base
= base
;
6171 val
= I915_READ(PIPESRC(pipe
));
6172 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
6173 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
6175 val
= I915_READ(DSPSTRIDE(pipe
));
6176 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffff80;
6178 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
6179 plane_config
->tiled
);
6181 plane_config
->size
= ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
6182 aligned_height
, PAGE_SIZE
);
6184 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
6185 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
6186 crtc
->base
.primary
->fb
->height
,
6187 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
6188 crtc
->base
.primary
->fb
->pitches
[0],
6189 plane_config
->size
);
6193 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
6194 struct intel_crtc_config
*pipe_config
)
6196 struct drm_device
*dev
= crtc
->base
.dev
;
6197 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6198 int pipe
= pipe_config
->cpu_transcoder
;
6199 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6200 intel_clock_t clock
;
6201 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
;
6202 int refclk
= 100000;
6204 mutex_lock(&dev_priv
->dpio_lock
);
6205 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
6206 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
6207 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
6208 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
6209 mutex_unlock(&dev_priv
->dpio_lock
);
6211 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
6212 clock
.m2
= ((pll_dw0
& 0xff) << 22) | (pll_dw2
& 0x3fffff);
6213 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
6214 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
6215 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
6217 chv_clock(refclk
, &clock
);
6219 /* clock.dot is the fast clock */
6220 pipe_config
->port_clock
= clock
.dot
/ 5;
6223 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
6224 struct intel_crtc_config
*pipe_config
)
6226 struct drm_device
*dev
= crtc
->base
.dev
;
6227 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6230 if (!intel_display_power_enabled(dev_priv
,
6231 POWER_DOMAIN_PIPE(crtc
->pipe
)))
6234 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
6235 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
6237 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
6238 if (!(tmp
& PIPECONF_ENABLE
))
6241 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
6242 switch (tmp
& PIPECONF_BPC_MASK
) {
6244 pipe_config
->pipe_bpp
= 18;
6247 pipe_config
->pipe_bpp
= 24;
6249 case PIPECONF_10BPC
:
6250 pipe_config
->pipe_bpp
= 30;
6257 if (IS_VALLEYVIEW(dev
) && (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
6258 pipe_config
->limited_color_range
= true;
6260 if (INTEL_INFO(dev
)->gen
< 4)
6261 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
6263 intel_get_pipe_timings(crtc
, pipe_config
);
6265 i9xx_get_pfit_config(crtc
, pipe_config
);
6267 if (INTEL_INFO(dev
)->gen
>= 4) {
6268 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
6269 pipe_config
->pixel_multiplier
=
6270 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
6271 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
6272 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
6273 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
6274 tmp
= I915_READ(DPLL(crtc
->pipe
));
6275 pipe_config
->pixel_multiplier
=
6276 ((tmp
& SDVO_MULTIPLIER_MASK
)
6277 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
6279 /* Note that on i915G/GM the pixel multiplier is in the sdvo
6280 * port and will be fixed up in the encoder->get_config
6282 pipe_config
->pixel_multiplier
= 1;
6284 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
6285 if (!IS_VALLEYVIEW(dev
)) {
6286 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
6287 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
6289 /* Mask out read-only status bits. */
6290 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
6291 DPLL_PORTC_READY_MASK
|
6292 DPLL_PORTB_READY_MASK
);
6295 if (IS_CHERRYVIEW(dev
))
6296 chv_crtc_clock_get(crtc
, pipe_config
);
6297 else if (IS_VALLEYVIEW(dev
))
6298 vlv_crtc_clock_get(crtc
, pipe_config
);
6300 i9xx_crtc_clock_get(crtc
, pipe_config
);
6305 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
6307 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6308 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
6309 struct intel_encoder
*encoder
;
6311 bool has_lvds
= false;
6312 bool has_cpu_edp
= false;
6313 bool has_panel
= false;
6314 bool has_ck505
= false;
6315 bool can_ssc
= false;
6317 /* We need to take the global config into account */
6318 list_for_each_entry(encoder
, &mode_config
->encoder_list
,
6320 switch (encoder
->type
) {
6321 case INTEL_OUTPUT_LVDS
:
6325 case INTEL_OUTPUT_EDP
:
6327 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
6333 if (HAS_PCH_IBX(dev
)) {
6334 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
6335 can_ssc
= has_ck505
;
6341 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
6342 has_panel
, has_lvds
, has_ck505
);
6344 /* Ironlake: try to setup display ref clock before DPLL
6345 * enabling. This is only under driver's control after
6346 * PCH B stepping, previous chipset stepping should be
6347 * ignoring this setting.
6349 val
= I915_READ(PCH_DREF_CONTROL
);
6351 /* As we must carefully and slowly disable/enable each source in turn,
6352 * compute the final state we want first and check if we need to
6353 * make any changes at all.
6356 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6358 final
|= DREF_NONSPREAD_CK505_ENABLE
;
6360 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6362 final
&= ~DREF_SSC_SOURCE_MASK
;
6363 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6364 final
&= ~DREF_SSC1_ENABLE
;
6367 final
|= DREF_SSC_SOURCE_ENABLE
;
6369 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6370 final
|= DREF_SSC1_ENABLE
;
6373 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6374 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6376 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6378 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6380 final
|= DREF_SSC_SOURCE_DISABLE
;
6381 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6387 /* Always enable nonspread source */
6388 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6391 val
|= DREF_NONSPREAD_CK505_ENABLE
;
6393 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6396 val
&= ~DREF_SSC_SOURCE_MASK
;
6397 val
|= DREF_SSC_SOURCE_ENABLE
;
6399 /* SSC must be turned on before enabling the CPU output */
6400 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6401 DRM_DEBUG_KMS("Using SSC on panel\n");
6402 val
|= DREF_SSC1_ENABLE
;
6404 val
&= ~DREF_SSC1_ENABLE
;
6406 /* Get SSC going before enabling the outputs */
6407 I915_WRITE(PCH_DREF_CONTROL
, val
);
6408 POSTING_READ(PCH_DREF_CONTROL
);
6411 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6413 /* Enable CPU source on CPU attached eDP */
6415 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6416 DRM_DEBUG_KMS("Using SSC on eDP\n");
6417 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6419 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6421 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6423 I915_WRITE(PCH_DREF_CONTROL
, val
);
6424 POSTING_READ(PCH_DREF_CONTROL
);
6427 DRM_DEBUG_KMS("Disabling SSC entirely\n");
6429 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6431 /* Turn off CPU output */
6432 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6434 I915_WRITE(PCH_DREF_CONTROL
, val
);
6435 POSTING_READ(PCH_DREF_CONTROL
);
6438 /* Turn off the SSC source */
6439 val
&= ~DREF_SSC_SOURCE_MASK
;
6440 val
|= DREF_SSC_SOURCE_DISABLE
;
6443 val
&= ~DREF_SSC1_ENABLE
;
6445 I915_WRITE(PCH_DREF_CONTROL
, val
);
6446 POSTING_READ(PCH_DREF_CONTROL
);
6450 BUG_ON(val
!= final
);
6453 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
6457 tmp
= I915_READ(SOUTH_CHICKEN2
);
6458 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
6459 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6461 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
6462 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
6463 DRM_ERROR("FDI mPHY reset assert timeout\n");
6465 tmp
= I915_READ(SOUTH_CHICKEN2
);
6466 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
6467 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6469 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
6470 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
6471 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
6474 /* WaMPhyProgramming:hsw */
6475 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
6479 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
6480 tmp
&= ~(0xFF << 24);
6481 tmp
|= (0x12 << 24);
6482 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
6484 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
6486 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
6488 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
6490 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
6492 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
6493 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6494 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
6496 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
6497 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6498 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
6500 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
6503 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
6505 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
6508 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
6510 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
6513 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
6515 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
6518 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
6520 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
6521 tmp
&= ~(0xFF << 16);
6522 tmp
|= (0x1C << 16);
6523 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
6525 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
6526 tmp
&= ~(0xFF << 16);
6527 tmp
|= (0x1C << 16);
6528 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
6530 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
6532 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
6534 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
6536 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
6538 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
6539 tmp
&= ~(0xF << 28);
6541 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
6543 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
6544 tmp
&= ~(0xF << 28);
6546 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
6549 /* Implements 3 different sequences from BSpec chapter "Display iCLK
6550 * Programming" based on the parameters passed:
6551 * - Sequence to enable CLKOUT_DP
6552 * - Sequence to enable CLKOUT_DP without spread
6553 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
6555 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
6558 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6561 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
6563 if (WARN(dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
&&
6564 with_fdi
, "LP PCH doesn't have FDI\n"))
6567 mutex_lock(&dev_priv
->dpio_lock
);
6569 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6570 tmp
&= ~SBI_SSCCTL_DISABLE
;
6571 tmp
|= SBI_SSCCTL_PATHALT
;
6572 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6577 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6578 tmp
&= ~SBI_SSCCTL_PATHALT
;
6579 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6582 lpt_reset_fdi_mphy(dev_priv
);
6583 lpt_program_fdi_mphy(dev_priv
);
6587 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6588 SBI_GEN0
: SBI_DBUFF0
;
6589 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6590 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6591 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6593 mutex_unlock(&dev_priv
->dpio_lock
);
6596 /* Sequence to disable CLKOUT_DP */
6597 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
6599 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6602 mutex_lock(&dev_priv
->dpio_lock
);
6604 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6605 SBI_GEN0
: SBI_DBUFF0
;
6606 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6607 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6608 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6610 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6611 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
6612 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
6613 tmp
|= SBI_SSCCTL_PATHALT
;
6614 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6617 tmp
|= SBI_SSCCTL_DISABLE
;
6618 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6621 mutex_unlock(&dev_priv
->dpio_lock
);
6624 static void lpt_init_pch_refclk(struct drm_device
*dev
)
6626 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
6627 struct intel_encoder
*encoder
;
6628 bool has_vga
= false;
6630 list_for_each_entry(encoder
, &mode_config
->encoder_list
, base
.head
) {
6631 switch (encoder
->type
) {
6632 case INTEL_OUTPUT_ANALOG
:
6639 lpt_enable_clkout_dp(dev
, true, true);
6641 lpt_disable_clkout_dp(dev
);
6645 * Initialize reference clocks when the driver loads
6647 void intel_init_pch_refclk(struct drm_device
*dev
)
6649 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
6650 ironlake_init_pch_refclk(dev
);
6651 else if (HAS_PCH_LPT(dev
))
6652 lpt_init_pch_refclk(dev
);
6655 static int ironlake_get_refclk(struct drm_crtc
*crtc
)
6657 struct drm_device
*dev
= crtc
->dev
;
6658 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6659 struct intel_encoder
*encoder
;
6660 int num_connectors
= 0;
6661 bool is_lvds
= false;
6663 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
6664 switch (encoder
->type
) {
6665 case INTEL_OUTPUT_LVDS
:
6672 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
6673 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
6674 dev_priv
->vbt
.lvds_ssc_freq
);
6675 return dev_priv
->vbt
.lvds_ssc_freq
;
6681 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
6683 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
6684 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6685 int pipe
= intel_crtc
->pipe
;
6690 switch (intel_crtc
->config
.pipe_bpp
) {
6692 val
|= PIPECONF_6BPC
;
6695 val
|= PIPECONF_8BPC
;
6698 val
|= PIPECONF_10BPC
;
6701 val
|= PIPECONF_12BPC
;
6704 /* Case prevented by intel_choose_pipe_bpp_dither. */
6708 if (intel_crtc
->config
.dither
)
6709 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
6711 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
6712 val
|= PIPECONF_INTERLACED_ILK
;
6714 val
|= PIPECONF_PROGRESSIVE
;
6716 if (intel_crtc
->config
.limited_color_range
)
6717 val
|= PIPECONF_COLOR_RANGE_SELECT
;
6719 I915_WRITE(PIPECONF(pipe
), val
);
6720 POSTING_READ(PIPECONF(pipe
));
6724 * Set up the pipe CSC unit.
6726 * Currently only full range RGB to limited range RGB conversion
6727 * is supported, but eventually this should handle various
6728 * RGB<->YCbCr scenarios as well.
6730 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
6732 struct drm_device
*dev
= crtc
->dev
;
6733 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6734 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6735 int pipe
= intel_crtc
->pipe
;
6736 uint16_t coeff
= 0x7800; /* 1.0 */
6739 * TODO: Check what kind of values actually come out of the pipe
6740 * with these coeff/postoff values and adjust to get the best
6741 * accuracy. Perhaps we even need to take the bpc value into
6745 if (intel_crtc
->config
.limited_color_range
)
6746 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
6749 * GY/GU and RY/RU should be the other way around according
6750 * to BSpec, but reality doesn't agree. Just set them up in
6751 * a way that results in the correct picture.
6753 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
6754 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
6756 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
6757 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
6759 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
6760 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
6762 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
6763 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
6764 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
6766 if (INTEL_INFO(dev
)->gen
> 6) {
6767 uint16_t postoff
= 0;
6769 if (intel_crtc
->config
.limited_color_range
)
6770 postoff
= (16 * (1 << 12) / 255) & 0x1fff;
6772 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
6773 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
6774 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
6776 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
6778 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
6780 if (intel_crtc
->config
.limited_color_range
)
6781 mode
|= CSC_BLACK_SCREEN_OFFSET
;
6783 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
6787 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
6789 struct drm_device
*dev
= crtc
->dev
;
6790 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6791 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6792 enum pipe pipe
= intel_crtc
->pipe
;
6793 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
6798 if (IS_HASWELL(dev
) && intel_crtc
->config
.dither
)
6799 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
6801 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
6802 val
|= PIPECONF_INTERLACED_ILK
;
6804 val
|= PIPECONF_PROGRESSIVE
;
6806 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
6807 POSTING_READ(PIPECONF(cpu_transcoder
));
6809 I915_WRITE(GAMMA_MODE(intel_crtc
->pipe
), GAMMA_MODE_MODE_8BIT
);
6810 POSTING_READ(GAMMA_MODE(intel_crtc
->pipe
));
6812 if (IS_BROADWELL(dev
)) {
6815 switch (intel_crtc
->config
.pipe_bpp
) {
6817 val
|= PIPEMISC_DITHER_6_BPC
;
6820 val
|= PIPEMISC_DITHER_8_BPC
;
6823 val
|= PIPEMISC_DITHER_10_BPC
;
6826 val
|= PIPEMISC_DITHER_12_BPC
;
6829 /* Case prevented by pipe_config_set_bpp. */
6833 if (intel_crtc
->config
.dither
)
6834 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
6836 I915_WRITE(PIPEMISC(pipe
), val
);
6840 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
6841 intel_clock_t
*clock
,
6842 bool *has_reduced_clock
,
6843 intel_clock_t
*reduced_clock
)
6845 struct drm_device
*dev
= crtc
->dev
;
6846 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6847 struct intel_encoder
*intel_encoder
;
6849 const intel_limit_t
*limit
;
6850 bool ret
, is_lvds
= false;
6852 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
6853 switch (intel_encoder
->type
) {
6854 case INTEL_OUTPUT_LVDS
:
6860 refclk
= ironlake_get_refclk(crtc
);
6863 * Returns a set of divisors for the desired target clock with the given
6864 * refclk, or FALSE. The returned values represent the clock equation:
6865 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
6867 limit
= intel_limit(crtc
, refclk
);
6868 ret
= dev_priv
->display
.find_dpll(limit
, crtc
,
6869 to_intel_crtc(crtc
)->config
.port_clock
,
6870 refclk
, NULL
, clock
);
6874 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
6876 * Ensure we match the reduced clock's P to the target clock.
6877 * If the clocks don't match, we can't switch the display clock
6878 * by using the FP0/FP1. In such case we will disable the LVDS
6879 * downclock feature.
6881 *has_reduced_clock
=
6882 dev_priv
->display
.find_dpll(limit
, crtc
,
6883 dev_priv
->lvds_downclock
,
6891 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
6894 * Account for spread spectrum to avoid
6895 * oversubscribing the link. Max center spread
6896 * is 2.5%; use 5% for safety's sake.
6898 u32 bps
= target_clock
* bpp
* 21 / 20;
6899 return DIV_ROUND_UP(bps
, link_bw
* 8);
6902 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
6904 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
6907 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
6909 intel_clock_t
*reduced_clock
, u32
*fp2
)
6911 struct drm_crtc
*crtc
= &intel_crtc
->base
;
6912 struct drm_device
*dev
= crtc
->dev
;
6913 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6914 struct intel_encoder
*intel_encoder
;
6916 int factor
, num_connectors
= 0;
6917 bool is_lvds
= false, is_sdvo
= false;
6919 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
6920 switch (intel_encoder
->type
) {
6921 case INTEL_OUTPUT_LVDS
:
6924 case INTEL_OUTPUT_SDVO
:
6925 case INTEL_OUTPUT_HDMI
:
6933 /* Enable autotuning of the PLL clock (if permissible) */
6936 if ((intel_panel_use_ssc(dev_priv
) &&
6937 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
6938 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
6940 } else if (intel_crtc
->config
.sdvo_tv_clock
)
6943 if (ironlake_needs_fb_cb_tune(&intel_crtc
->config
.dpll
, factor
))
6946 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
6952 dpll
|= DPLLB_MODE_LVDS
;
6954 dpll
|= DPLLB_MODE_DAC_SERIAL
;
6956 dpll
|= (intel_crtc
->config
.pixel_multiplier
- 1)
6957 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
6960 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6961 if (intel_crtc
->config
.has_dp_encoder
)
6962 dpll
|= DPLL_SDVO_HIGH_SPEED
;
6964 /* compute bitmask from p1 value */
6965 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
6967 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
6969 switch (intel_crtc
->config
.dpll
.p2
) {
6971 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
6974 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
6977 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
6980 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
6984 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
6985 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
6987 dpll
|= PLL_REF_INPUT_DREFCLK
;
6989 return dpll
| DPLL_VCO_ENABLE
;
6992 static int ironlake_crtc_mode_set(struct drm_crtc
*crtc
,
6994 struct drm_framebuffer
*fb
)
6996 struct drm_device
*dev
= crtc
->dev
;
6997 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6998 int num_connectors
= 0;
6999 intel_clock_t clock
, reduced_clock
;
7000 u32 dpll
= 0, fp
= 0, fp2
= 0;
7001 bool ok
, has_reduced_clock
= false;
7002 bool is_lvds
= false;
7003 struct intel_encoder
*encoder
;
7004 struct intel_shared_dpll
*pll
;
7006 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
7007 switch (encoder
->type
) {
7008 case INTEL_OUTPUT_LVDS
:
7016 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
7017 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
7019 ok
= ironlake_compute_clocks(crtc
, &clock
,
7020 &has_reduced_clock
, &reduced_clock
);
7021 if (!ok
&& !intel_crtc
->config
.clock_set
) {
7022 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7025 /* Compat-code for transition, will disappear. */
7026 if (!intel_crtc
->config
.clock_set
) {
7027 intel_crtc
->config
.dpll
.n
= clock
.n
;
7028 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
7029 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
7030 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
7031 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
7034 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
7035 if (intel_crtc
->config
.has_pch_encoder
) {
7036 fp
= i9xx_dpll_compute_fp(&intel_crtc
->config
.dpll
);
7037 if (has_reduced_clock
)
7038 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
7040 dpll
= ironlake_compute_dpll(intel_crtc
,
7041 &fp
, &reduced_clock
,
7042 has_reduced_clock
? &fp2
: NULL
);
7044 intel_crtc
->config
.dpll_hw_state
.dpll
= dpll
;
7045 intel_crtc
->config
.dpll_hw_state
.fp0
= fp
;
7046 if (has_reduced_clock
)
7047 intel_crtc
->config
.dpll_hw_state
.fp1
= fp2
;
7049 intel_crtc
->config
.dpll_hw_state
.fp1
= fp
;
7051 pll
= intel_get_shared_dpll(intel_crtc
);
7053 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
7054 pipe_name(intel_crtc
->pipe
));
7058 intel_put_shared_dpll(intel_crtc
);
7060 if (is_lvds
&& has_reduced_clock
&& i915
.powersave
)
7061 intel_crtc
->lowfreq_avail
= true;
7063 intel_crtc
->lowfreq_avail
= false;
7068 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
7069 struct intel_link_m_n
*m_n
)
7071 struct drm_device
*dev
= crtc
->base
.dev
;
7072 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7073 enum pipe pipe
= crtc
->pipe
;
7075 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
7076 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
7077 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
7079 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
7080 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
7081 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7084 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
7085 enum transcoder transcoder
,
7086 struct intel_link_m_n
*m_n
)
7088 struct drm_device
*dev
= crtc
->base
.dev
;
7089 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7090 enum pipe pipe
= crtc
->pipe
;
7092 if (INTEL_INFO(dev
)->gen
>= 5) {
7093 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
7094 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
7095 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
7097 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
7098 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
7099 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7101 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
7102 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
7103 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
7105 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
7106 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
7107 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7111 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
7112 struct intel_crtc_config
*pipe_config
)
7114 if (crtc
->config
.has_pch_encoder
)
7115 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
7117 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7118 &pipe_config
->dp_m_n
);
7121 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
7122 struct intel_crtc_config
*pipe_config
)
7124 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7125 &pipe_config
->fdi_m_n
);
7128 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
7129 struct intel_crtc_config
*pipe_config
)
7131 struct drm_device
*dev
= crtc
->base
.dev
;
7132 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7135 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
7137 if (tmp
& PF_ENABLE
) {
7138 pipe_config
->pch_pfit
.enabled
= true;
7139 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
7140 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
7142 /* We currently do not free assignements of panel fitters on
7143 * ivb/hsw (since we don't use the higher upscaling modes which
7144 * differentiates them) so just WARN about this case for now. */
7146 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
7147 PF_PIPE_SEL_IVB(crtc
->pipe
));
7152 static void ironlake_get_plane_config(struct intel_crtc
*crtc
,
7153 struct intel_plane_config
*plane_config
)
7155 struct drm_device
*dev
= crtc
->base
.dev
;
7156 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7157 u32 val
, base
, offset
;
7158 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7159 int fourcc
, pixel_format
;
7162 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
7163 if (!crtc
->base
.primary
->fb
) {
7164 DRM_DEBUG_KMS("failed to alloc fb\n");
7168 val
= I915_READ(DSPCNTR(plane
));
7170 if (INTEL_INFO(dev
)->gen
>= 4)
7171 if (val
& DISPPLANE_TILED
)
7172 plane_config
->tiled
= true;
7174 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7175 fourcc
= intel_format_to_fourcc(pixel_format
);
7176 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
7177 crtc
->base
.primary
->fb
->bits_per_pixel
=
7178 drm_format_plane_cpp(fourcc
, 0) * 8;
7180 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7181 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
7182 offset
= I915_READ(DSPOFFSET(plane
));
7184 if (plane_config
->tiled
)
7185 offset
= I915_READ(DSPTILEOFF(plane
));
7187 offset
= I915_READ(DSPLINOFF(plane
));
7189 plane_config
->base
= base
;
7191 val
= I915_READ(PIPESRC(pipe
));
7192 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
7193 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
7195 val
= I915_READ(DSPSTRIDE(pipe
));
7196 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffff80;
7198 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
7199 plane_config
->tiled
);
7201 plane_config
->size
= ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
7202 aligned_height
, PAGE_SIZE
);
7204 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7205 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
7206 crtc
->base
.primary
->fb
->height
,
7207 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
7208 crtc
->base
.primary
->fb
->pitches
[0],
7209 plane_config
->size
);
7212 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
7213 struct intel_crtc_config
*pipe_config
)
7215 struct drm_device
*dev
= crtc
->base
.dev
;
7216 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7219 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7220 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7222 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7223 if (!(tmp
& PIPECONF_ENABLE
))
7226 switch (tmp
& PIPECONF_BPC_MASK
) {
7228 pipe_config
->pipe_bpp
= 18;
7231 pipe_config
->pipe_bpp
= 24;
7233 case PIPECONF_10BPC
:
7234 pipe_config
->pipe_bpp
= 30;
7236 case PIPECONF_12BPC
:
7237 pipe_config
->pipe_bpp
= 36;
7243 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
7244 pipe_config
->limited_color_range
= true;
7246 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
7247 struct intel_shared_dpll
*pll
;
7249 pipe_config
->has_pch_encoder
= true;
7251 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
7252 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7253 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7255 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7257 if (HAS_PCH_IBX(dev_priv
->dev
)) {
7258 pipe_config
->shared_dpll
=
7259 (enum intel_dpll_id
) crtc
->pipe
;
7261 tmp
= I915_READ(PCH_DPLL_SEL
);
7262 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
7263 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_B
;
7265 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_A
;
7268 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
7270 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
7271 &pipe_config
->dpll_hw_state
));
7273 tmp
= pipe_config
->dpll_hw_state
.dpll
;
7274 pipe_config
->pixel_multiplier
=
7275 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
7276 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
7278 ironlake_pch_clock_get(crtc
, pipe_config
);
7280 pipe_config
->pixel_multiplier
= 1;
7283 intel_get_pipe_timings(crtc
, pipe_config
);
7285 ironlake_get_pfit_config(crtc
, pipe_config
);
7290 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
7292 struct drm_device
*dev
= dev_priv
->dev
;
7293 struct intel_ddi_plls
*plls
= &dev_priv
->ddi_plls
;
7294 struct intel_crtc
*crtc
;
7296 for_each_intel_crtc(dev
, crtc
)
7297 WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
7298 pipe_name(crtc
->pipe
));
7300 WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
7301 WARN(plls
->spll_refcount
, "SPLL enabled\n");
7302 WARN(plls
->wrpll1_refcount
, "WRPLL1 enabled\n");
7303 WARN(plls
->wrpll2_refcount
, "WRPLL2 enabled\n");
7304 WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
7305 WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
7306 "CPU PWM1 enabled\n");
7307 WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
7308 "CPU PWM2 enabled\n");
7309 WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
7310 "PCH PWM1 enabled\n");
7311 WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
7312 "Utility pin enabled\n");
7313 WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
7316 * In theory we can still leave IRQs enabled, as long as only the HPD
7317 * interrupts remain enabled. We used to check for that, but since it's
7318 * gen-specific and since we only disable LCPLL after we fully disable
7319 * the interrupts, the check below should be enough.
7321 WARN(!dev_priv
->pm
.irqs_disabled
, "IRQs enabled\n");
7324 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
7326 struct drm_device
*dev
= dev_priv
->dev
;
7328 if (IS_HASWELL(dev
)) {
7329 mutex_lock(&dev_priv
->rps
.hw_lock
);
7330 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
7332 DRM_ERROR("Failed to disable D_COMP\n");
7333 mutex_unlock(&dev_priv
->rps
.hw_lock
);
7335 I915_WRITE(D_COMP
, val
);
7337 POSTING_READ(D_COMP
);
7341 * This function implements pieces of two sequences from BSpec:
7342 * - Sequence for display software to disable LCPLL
7343 * - Sequence for display software to allow package C8+
7344 * The steps implemented here are just the steps that actually touch the LCPLL
7345 * register. Callers should take care of disabling all the display engine
7346 * functions, doing the mode unset, fixing interrupts, etc.
7348 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
7349 bool switch_to_fclk
, bool allow_power_down
)
7353 assert_can_disable_lcpll(dev_priv
);
7355 val
= I915_READ(LCPLL_CTL
);
7357 if (switch_to_fclk
) {
7358 val
|= LCPLL_CD_SOURCE_FCLK
;
7359 I915_WRITE(LCPLL_CTL
, val
);
7361 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
7362 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
7363 DRM_ERROR("Switching to FCLK failed\n");
7365 val
= I915_READ(LCPLL_CTL
);
7368 val
|= LCPLL_PLL_DISABLE
;
7369 I915_WRITE(LCPLL_CTL
, val
);
7370 POSTING_READ(LCPLL_CTL
);
7372 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
7373 DRM_ERROR("LCPLL still locked\n");
7375 val
= I915_READ(D_COMP
);
7376 val
|= D_COMP_COMP_DISABLE
;
7377 hsw_write_dcomp(dev_priv
, val
);
7380 if (wait_for((I915_READ(D_COMP
) & D_COMP_RCOMP_IN_PROGRESS
) == 0, 1))
7381 DRM_ERROR("D_COMP RCOMP still in progress\n");
7383 if (allow_power_down
) {
7384 val
= I915_READ(LCPLL_CTL
);
7385 val
|= LCPLL_POWER_DOWN_ALLOW
;
7386 I915_WRITE(LCPLL_CTL
, val
);
7387 POSTING_READ(LCPLL_CTL
);
7392 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
7395 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
7398 unsigned long irqflags
;
7400 val
= I915_READ(LCPLL_CTL
);
7402 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
7403 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
7407 * Make sure we're not on PC8 state before disabling PC8, otherwise
7408 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
7410 * The other problem is that hsw_restore_lcpll() is called as part of
7411 * the runtime PM resume sequence, so we can't just call
7412 * gen6_gt_force_wake_get() because that function calls
7413 * intel_runtime_pm_get(), and we can't change the runtime PM refcount
7414 * while we are on the resume sequence. So to solve this problem we have
7415 * to call special forcewake code that doesn't touch runtime PM and
7416 * doesn't enable the forcewake delayed work.
7418 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
7419 if (dev_priv
->uncore
.forcewake_count
++ == 0)
7420 dev_priv
->uncore
.funcs
.force_wake_get(dev_priv
, FORCEWAKE_ALL
);
7421 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
7423 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
7424 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
7425 I915_WRITE(LCPLL_CTL
, val
);
7426 POSTING_READ(LCPLL_CTL
);
7429 val
= I915_READ(D_COMP
);
7430 val
|= D_COMP_COMP_FORCE
;
7431 val
&= ~D_COMP_COMP_DISABLE
;
7432 hsw_write_dcomp(dev_priv
, val
);
7434 val
= I915_READ(LCPLL_CTL
);
7435 val
&= ~LCPLL_PLL_DISABLE
;
7436 I915_WRITE(LCPLL_CTL
, val
);
7438 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
7439 DRM_ERROR("LCPLL not locked yet\n");
7441 if (val
& LCPLL_CD_SOURCE_FCLK
) {
7442 val
= I915_READ(LCPLL_CTL
);
7443 val
&= ~LCPLL_CD_SOURCE_FCLK
;
7444 I915_WRITE(LCPLL_CTL
, val
);
7446 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
7447 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
7448 DRM_ERROR("Switching back to LCPLL failed\n");
7451 /* See the big comment above. */
7452 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
7453 if (--dev_priv
->uncore
.forcewake_count
== 0)
7454 dev_priv
->uncore
.funcs
.force_wake_put(dev_priv
, FORCEWAKE_ALL
);
7455 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
7459 * Package states C8 and deeper are really deep PC states that can only be
7460 * reached when all the devices on the system allow it, so even if the graphics
7461 * device allows PC8+, it doesn't mean the system will actually get to these
7462 * states. Our driver only allows PC8+ when going into runtime PM.
7464 * The requirements for PC8+ are that all the outputs are disabled, the power
7465 * well is disabled and most interrupts are disabled, and these are also
7466 * requirements for runtime PM. When these conditions are met, we manually do
7467 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
7468 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
7471 * When we really reach PC8 or deeper states (not just when we allow it) we lose
7472 * the state of some registers, so when we come back from PC8+ we need to
7473 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
7474 * need to take care of the registers kept by RC6. Notice that this happens even
7475 * if we don't put the device in PCI D3 state (which is what currently happens
7476 * because of the runtime PM support).
7478 * For more, read "Display Sequences for Package C8" on the hardware
7481 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
7483 struct drm_device
*dev
= dev_priv
->dev
;
7486 DRM_DEBUG_KMS("Enabling package C8+\n");
7488 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7489 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7490 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
7491 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7494 lpt_disable_clkout_dp(dev
);
7495 hsw_disable_lcpll(dev_priv
, true, true);
7498 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
7500 struct drm_device
*dev
= dev_priv
->dev
;
7503 DRM_DEBUG_KMS("Disabling package C8+\n");
7505 hsw_restore_lcpll(dev_priv
);
7506 lpt_init_pch_refclk(dev
);
7508 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7509 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7510 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
7511 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7514 intel_prepare_ddi(dev
);
7517 static void snb_modeset_global_resources(struct drm_device
*dev
)
7519 modeset_update_crtc_power_domains(dev
);
7522 static void haswell_modeset_global_resources(struct drm_device
*dev
)
7524 modeset_update_crtc_power_domains(dev
);
7527 static int haswell_crtc_mode_set(struct drm_crtc
*crtc
,
7529 struct drm_framebuffer
*fb
)
7531 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7533 if (!intel_ddi_pll_select(intel_crtc
))
7535 intel_ddi_pll_enable(intel_crtc
);
7537 intel_crtc
->lowfreq_avail
= false;
7542 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
7543 struct intel_crtc_config
*pipe_config
)
7545 struct drm_device
*dev
= crtc
->base
.dev
;
7546 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7547 enum intel_display_power_domain pfit_domain
;
7550 if (!intel_display_power_enabled(dev_priv
,
7551 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7554 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7555 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7557 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
7558 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
7559 enum pipe trans_edp_pipe
;
7560 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
7562 WARN(1, "unknown pipe linked to edp transcoder\n");
7563 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
7564 case TRANS_DDI_EDP_INPUT_A_ON
:
7565 trans_edp_pipe
= PIPE_A
;
7567 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
7568 trans_edp_pipe
= PIPE_B
;
7570 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
7571 trans_edp_pipe
= PIPE_C
;
7575 if (trans_edp_pipe
== crtc
->pipe
)
7576 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
7579 if (!intel_display_power_enabled(dev_priv
,
7580 POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
)))
7583 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
7584 if (!(tmp
& PIPECONF_ENABLE
))
7588 * Haswell has only FDI/PCH transcoder A. It is which is connected to
7589 * DDI E. So just check whether this pipe is wired to DDI E and whether
7590 * the PCH transcoder is on.
7592 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
7593 if ((tmp
& TRANS_DDI_PORT_MASK
) == TRANS_DDI_SELECT_PORT(PORT_E
) &&
7594 I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
7595 pipe_config
->has_pch_encoder
= true;
7597 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
7598 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7599 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7601 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7604 intel_get_pipe_timings(crtc
, pipe_config
);
7606 pfit_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
7607 if (intel_display_power_enabled(dev_priv
, pfit_domain
))
7608 ironlake_get_pfit_config(crtc
, pipe_config
);
7610 if (IS_HASWELL(dev
))
7611 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
7612 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
7614 pipe_config
->pixel_multiplier
= 1;
7622 } hdmi_audio_clock
[] = {
7623 { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175
},
7624 { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200
}, /* default per bspec */
7625 { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000
},
7626 { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027
},
7627 { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000
},
7628 { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054
},
7629 { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176
},
7630 { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250
},
7631 { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352
},
7632 { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500
},
7635 /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
7636 static u32
audio_config_hdmi_pixel_clock(struct drm_display_mode
*mode
)
7640 for (i
= 0; i
< ARRAY_SIZE(hdmi_audio_clock
); i
++) {
7641 if (mode
->clock
== hdmi_audio_clock
[i
].clock
)
7645 if (i
== ARRAY_SIZE(hdmi_audio_clock
)) {
7646 DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode
->clock
);
7650 DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
7651 hdmi_audio_clock
[i
].clock
,
7652 hdmi_audio_clock
[i
].config
);
7654 return hdmi_audio_clock
[i
].config
;
7657 static bool intel_eld_uptodate(struct drm_connector
*connector
,
7658 int reg_eldv
, uint32_t bits_eldv
,
7659 int reg_elda
, uint32_t bits_elda
,
7662 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7663 uint8_t *eld
= connector
->eld
;
7666 i
= I915_READ(reg_eldv
);
7675 i
= I915_READ(reg_elda
);
7677 I915_WRITE(reg_elda
, i
);
7679 for (i
= 0; i
< eld
[2]; i
++)
7680 if (I915_READ(reg_edid
) != *((uint32_t *)eld
+ i
))
7686 static void g4x_write_eld(struct drm_connector
*connector
,
7687 struct drm_crtc
*crtc
,
7688 struct drm_display_mode
*mode
)
7690 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7691 uint8_t *eld
= connector
->eld
;
7696 i
= I915_READ(G4X_AUD_VID_DID
);
7698 if (i
== INTEL_AUDIO_DEVBLC
|| i
== INTEL_AUDIO_DEVCL
)
7699 eldv
= G4X_ELDV_DEVCL_DEVBLC
;
7701 eldv
= G4X_ELDV_DEVCTG
;
7703 if (intel_eld_uptodate(connector
,
7704 G4X_AUD_CNTL_ST
, eldv
,
7705 G4X_AUD_CNTL_ST
, G4X_ELD_ADDR
,
7706 G4X_HDMIW_HDMIEDID
))
7709 i
= I915_READ(G4X_AUD_CNTL_ST
);
7710 i
&= ~(eldv
| G4X_ELD_ADDR
);
7711 len
= (i
>> 9) & 0x1f; /* ELD buffer size */
7712 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
7717 len
= min_t(uint8_t, eld
[2], len
);
7718 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7719 for (i
= 0; i
< len
; i
++)
7720 I915_WRITE(G4X_HDMIW_HDMIEDID
, *((uint32_t *)eld
+ i
));
7722 i
= I915_READ(G4X_AUD_CNTL_ST
);
7724 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
7727 static void haswell_write_eld(struct drm_connector
*connector
,
7728 struct drm_crtc
*crtc
,
7729 struct drm_display_mode
*mode
)
7731 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7732 uint8_t *eld
= connector
->eld
;
7736 int pipe
= to_intel_crtc(crtc
)->pipe
;
7739 int hdmiw_hdmiedid
= HSW_AUD_EDID_DATA(pipe
);
7740 int aud_cntl_st
= HSW_AUD_DIP_ELD_CTRL(pipe
);
7741 int aud_config
= HSW_AUD_CFG(pipe
);
7742 int aud_cntrl_st2
= HSW_AUD_PIN_ELD_CP_VLD
;
7744 /* Audio output enable */
7745 DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
7746 tmp
= I915_READ(aud_cntrl_st2
);
7747 tmp
|= (AUDIO_OUTPUT_ENABLE_A
<< (pipe
* 4));
7748 I915_WRITE(aud_cntrl_st2
, tmp
);
7749 POSTING_READ(aud_cntrl_st2
);
7751 assert_pipe_disabled(dev_priv
, to_intel_crtc(crtc
)->pipe
);
7753 /* Set ELD valid state */
7754 tmp
= I915_READ(aud_cntrl_st2
);
7755 DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp
);
7756 tmp
|= (AUDIO_ELD_VALID_A
<< (pipe
* 4));
7757 I915_WRITE(aud_cntrl_st2
, tmp
);
7758 tmp
= I915_READ(aud_cntrl_st2
);
7759 DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp
);
7761 /* Enable HDMI mode */
7762 tmp
= I915_READ(aud_config
);
7763 DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp
);
7764 /* clear N_programing_enable and N_value_index */
7765 tmp
&= ~(AUD_CONFIG_N_VALUE_INDEX
| AUD_CONFIG_N_PROG_ENABLE
);
7766 I915_WRITE(aud_config
, tmp
);
7768 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
7770 eldv
= AUDIO_ELD_VALID_A
<< (pipe
* 4);
7772 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
7773 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
7774 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
7775 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
7777 I915_WRITE(aud_config
, audio_config_hdmi_pixel_clock(mode
));
7780 if (intel_eld_uptodate(connector
,
7781 aud_cntrl_st2
, eldv
,
7782 aud_cntl_st
, IBX_ELD_ADDRESS
,
7786 i
= I915_READ(aud_cntrl_st2
);
7788 I915_WRITE(aud_cntrl_st2
, i
);
7793 i
= I915_READ(aud_cntl_st
);
7794 i
&= ~IBX_ELD_ADDRESS
;
7795 I915_WRITE(aud_cntl_st
, i
);
7796 i
= (i
>> 29) & DIP_PORT_SEL_MASK
; /* DIP_Port_Select, 0x1 = PortB */
7797 DRM_DEBUG_DRIVER("port num:%d\n", i
);
7799 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
7800 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7801 for (i
= 0; i
< len
; i
++)
7802 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
7804 i
= I915_READ(aud_cntrl_st2
);
7806 I915_WRITE(aud_cntrl_st2
, i
);
7810 static void ironlake_write_eld(struct drm_connector
*connector
,
7811 struct drm_crtc
*crtc
,
7812 struct drm_display_mode
*mode
)
7814 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7815 uint8_t *eld
= connector
->eld
;
7823 int pipe
= to_intel_crtc(crtc
)->pipe
;
7825 if (HAS_PCH_IBX(connector
->dev
)) {
7826 hdmiw_hdmiedid
= IBX_HDMIW_HDMIEDID(pipe
);
7827 aud_config
= IBX_AUD_CFG(pipe
);
7828 aud_cntl_st
= IBX_AUD_CNTL_ST(pipe
);
7829 aud_cntrl_st2
= IBX_AUD_CNTL_ST2
;
7830 } else if (IS_VALLEYVIEW(connector
->dev
)) {
7831 hdmiw_hdmiedid
= VLV_HDMIW_HDMIEDID(pipe
);
7832 aud_config
= VLV_AUD_CFG(pipe
);
7833 aud_cntl_st
= VLV_AUD_CNTL_ST(pipe
);
7834 aud_cntrl_st2
= VLV_AUD_CNTL_ST2
;
7836 hdmiw_hdmiedid
= CPT_HDMIW_HDMIEDID(pipe
);
7837 aud_config
= CPT_AUD_CFG(pipe
);
7838 aud_cntl_st
= CPT_AUD_CNTL_ST(pipe
);
7839 aud_cntrl_st2
= CPT_AUD_CNTRL_ST2
;
7842 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
7844 if (IS_VALLEYVIEW(connector
->dev
)) {
7845 struct intel_encoder
*intel_encoder
;
7846 struct intel_digital_port
*intel_dig_port
;
7848 intel_encoder
= intel_attached_encoder(connector
);
7849 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
7850 i
= intel_dig_port
->port
;
7852 i
= I915_READ(aud_cntl_st
);
7853 i
= (i
>> 29) & DIP_PORT_SEL_MASK
;
7854 /* DIP_Port_Select, 0x1 = PortB */
7858 DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
7859 /* operate blindly on all ports */
7860 eldv
= IBX_ELD_VALIDB
;
7861 eldv
|= IBX_ELD_VALIDB
<< 4;
7862 eldv
|= IBX_ELD_VALIDB
<< 8;
7864 DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i
));
7865 eldv
= IBX_ELD_VALIDB
<< ((i
- 1) * 4);
7868 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
7869 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
7870 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
7871 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
7873 I915_WRITE(aud_config
, audio_config_hdmi_pixel_clock(mode
));
7876 if (intel_eld_uptodate(connector
,
7877 aud_cntrl_st2
, eldv
,
7878 aud_cntl_st
, IBX_ELD_ADDRESS
,
7882 i
= I915_READ(aud_cntrl_st2
);
7884 I915_WRITE(aud_cntrl_st2
, i
);
7889 i
= I915_READ(aud_cntl_st
);
7890 i
&= ~IBX_ELD_ADDRESS
;
7891 I915_WRITE(aud_cntl_st
, i
);
7893 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
7894 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7895 for (i
= 0; i
< len
; i
++)
7896 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
7898 i
= I915_READ(aud_cntrl_st2
);
7900 I915_WRITE(aud_cntrl_st2
, i
);
7903 void intel_write_eld(struct drm_encoder
*encoder
,
7904 struct drm_display_mode
*mode
)
7906 struct drm_crtc
*crtc
= encoder
->crtc
;
7907 struct drm_connector
*connector
;
7908 struct drm_device
*dev
= encoder
->dev
;
7909 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7911 connector
= drm_select_eld(encoder
, mode
);
7915 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
7918 connector
->encoder
->base
.id
,
7919 connector
->encoder
->name
);
7921 connector
->eld
[6] = drm_av_sync_delay(connector
, mode
) / 2;
7923 if (dev_priv
->display
.write_eld
)
7924 dev_priv
->display
.write_eld(connector
, crtc
, mode
);
7927 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
7929 struct drm_device
*dev
= crtc
->dev
;
7930 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7931 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7934 if (base
!= intel_crtc
->cursor_base
) {
7935 /* On these chipsets we can only modify the base whilst
7936 * the cursor is disabled.
7938 if (intel_crtc
->cursor_cntl
) {
7939 I915_WRITE(_CURACNTR
, 0);
7940 POSTING_READ(_CURACNTR
);
7941 intel_crtc
->cursor_cntl
= 0;
7944 I915_WRITE(_CURABASE
, base
);
7945 POSTING_READ(_CURABASE
);
7948 /* XXX width must be 64, stride 256 => 0x00 << 28 */
7951 cntl
= (CURSOR_ENABLE
|
7952 CURSOR_GAMMA_ENABLE
|
7953 CURSOR_FORMAT_ARGB
);
7954 if (intel_crtc
->cursor_cntl
!= cntl
) {
7955 I915_WRITE(_CURACNTR
, cntl
);
7956 POSTING_READ(_CURACNTR
);
7957 intel_crtc
->cursor_cntl
= cntl
;
7961 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
7963 struct drm_device
*dev
= crtc
->dev
;
7964 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7965 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7966 int pipe
= intel_crtc
->pipe
;
7971 cntl
= MCURSOR_GAMMA_ENABLE
;
7972 switch (intel_crtc
->cursor_width
) {
7974 cntl
|= CURSOR_MODE_64_ARGB_AX
;
7977 cntl
|= CURSOR_MODE_128_ARGB_AX
;
7980 cntl
|= CURSOR_MODE_256_ARGB_AX
;
7986 cntl
|= pipe
<< 28; /* Connect to correct pipe */
7988 if (intel_crtc
->cursor_cntl
!= cntl
) {
7989 I915_WRITE(CURCNTR(pipe
), cntl
);
7990 POSTING_READ(CURCNTR(pipe
));
7991 intel_crtc
->cursor_cntl
= cntl
;
7994 /* and commit changes on next vblank */
7995 I915_WRITE(CURBASE(pipe
), base
);
7996 POSTING_READ(CURBASE(pipe
));
7999 static void ivb_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8001 struct drm_device
*dev
= crtc
->dev
;
8002 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8003 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8004 int pipe
= intel_crtc
->pipe
;
8009 cntl
= MCURSOR_GAMMA_ENABLE
;
8010 switch (intel_crtc
->cursor_width
) {
8012 cntl
|= CURSOR_MODE_64_ARGB_AX
;
8015 cntl
|= CURSOR_MODE_128_ARGB_AX
;
8018 cntl
|= CURSOR_MODE_256_ARGB_AX
;
8025 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
8026 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
8028 if (intel_crtc
->cursor_cntl
!= cntl
) {
8029 I915_WRITE(CURCNTR(pipe
), cntl
);
8030 POSTING_READ(CURCNTR(pipe
));
8031 intel_crtc
->cursor_cntl
= cntl
;
8034 /* and commit changes on next vblank */
8035 I915_WRITE(CURBASE(pipe
), base
);
8036 POSTING_READ(CURBASE(pipe
));
8039 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
8040 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
8043 struct drm_device
*dev
= crtc
->dev
;
8044 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8045 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8046 int pipe
= intel_crtc
->pipe
;
8047 int x
= crtc
->cursor_x
;
8048 int y
= crtc
->cursor_y
;
8049 u32 base
= 0, pos
= 0;
8052 base
= intel_crtc
->cursor_addr
;
8054 if (x
>= intel_crtc
->config
.pipe_src_w
)
8057 if (y
>= intel_crtc
->config
.pipe_src_h
)
8061 if (x
+ intel_crtc
->cursor_width
<= 0)
8064 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
8067 pos
|= x
<< CURSOR_X_SHIFT
;
8070 if (y
+ intel_crtc
->cursor_height
<= 0)
8073 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
8076 pos
|= y
<< CURSOR_Y_SHIFT
;
8078 if (base
== 0 && intel_crtc
->cursor_base
== 0)
8081 I915_WRITE(CURPOS(pipe
), pos
);
8083 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
) || IS_BROADWELL(dev
))
8084 ivb_update_cursor(crtc
, base
);
8085 else if (IS_845G(dev
) || IS_I865G(dev
))
8086 i845_update_cursor(crtc
, base
);
8088 i9xx_update_cursor(crtc
, base
);
8089 intel_crtc
->cursor_base
= base
;
8093 * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
8095 * Note that the object's reference will be consumed if the update fails. If
8096 * the update succeeds, the reference of the old object (if any) will be
8099 static int intel_crtc_cursor_set_obj(struct drm_crtc
*crtc
,
8100 struct drm_i915_gem_object
*obj
,
8101 uint32_t width
, uint32_t height
)
8103 struct drm_device
*dev
= crtc
->dev
;
8104 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8105 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8110 /* if we want to turn off the cursor ignore width and height */
8112 DRM_DEBUG_KMS("cursor off\n");
8115 mutex_lock(&dev
->struct_mutex
);
8119 /* Check for which cursor types we support */
8120 if (!((width
== 64 && height
== 64) ||
8121 (width
== 128 && height
== 128 && !IS_GEN2(dev
)) ||
8122 (width
== 256 && height
== 256 && !IS_GEN2(dev
)))) {
8123 DRM_DEBUG("Cursor dimension not supported\n");
8127 if (obj
->base
.size
< width
* height
* 4) {
8128 DRM_DEBUG_KMS("buffer is too small\n");
8133 /* we only need to pin inside GTT if cursor is non-phy */
8134 mutex_lock(&dev
->struct_mutex
);
8135 if (!INTEL_INFO(dev
)->cursor_needs_physical
) {
8138 if (obj
->tiling_mode
) {
8139 DRM_DEBUG_KMS("cursor cannot be tiled\n");
8144 /* Note that the w/a also requires 2 PTE of padding following
8145 * the bo. We currently fill all unused PTE with the shadow
8146 * page and so we should always have valid PTE following the
8147 * cursor preventing the VT-d warning.
8150 if (need_vtd_wa(dev
))
8151 alignment
= 64*1024;
8153 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, NULL
);
8155 DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
8159 ret
= i915_gem_object_put_fence(obj
);
8161 DRM_DEBUG_KMS("failed to release fence for cursor");
8165 addr
= i915_gem_obj_ggtt_offset(obj
);
8167 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
8168 ret
= i915_gem_object_attach_phys(obj
, align
);
8170 DRM_DEBUG_KMS("failed to attach phys object\n");
8173 addr
= obj
->phys_handle
->busaddr
;
8177 I915_WRITE(CURSIZE
, (height
<< 12) | width
);
8180 if (intel_crtc
->cursor_bo
) {
8181 if (!INTEL_INFO(dev
)->cursor_needs_physical
)
8182 i915_gem_object_unpin_from_display_plane(intel_crtc
->cursor_bo
);
8185 mutex_unlock(&dev
->struct_mutex
);
8187 old_width
= intel_crtc
->cursor_width
;
8189 intel_crtc
->cursor_addr
= addr
;
8190 intel_crtc
->cursor_bo
= obj
;
8191 intel_crtc
->cursor_width
= width
;
8192 intel_crtc
->cursor_height
= height
;
8194 if (intel_crtc
->active
) {
8195 if (old_width
!= width
)
8196 intel_update_watermarks(crtc
);
8197 intel_crtc_update_cursor(crtc
, intel_crtc
->cursor_bo
!= NULL
);
8202 i915_gem_object_unpin_from_display_plane(obj
);
8204 mutex_unlock(&dev
->struct_mutex
);
8206 drm_gem_object_unreference_unlocked(&obj
->base
);
8210 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
8211 u16
*blue
, uint32_t start
, uint32_t size
)
8213 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
8214 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8216 for (i
= start
; i
< end
; i
++) {
8217 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
8218 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
8219 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
8222 intel_crtc_load_lut(crtc
);
8225 /* VESA 640x480x72Hz mode to set on the pipe */
8226 static struct drm_display_mode load_detect_mode
= {
8227 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
8228 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
8231 struct drm_framebuffer
*
8232 __intel_framebuffer_create(struct drm_device
*dev
,
8233 struct drm_mode_fb_cmd2
*mode_cmd
,
8234 struct drm_i915_gem_object
*obj
)
8236 struct intel_framebuffer
*intel_fb
;
8239 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8241 drm_gem_object_unreference_unlocked(&obj
->base
);
8242 return ERR_PTR(-ENOMEM
);
8245 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
8249 return &intel_fb
->base
;
8251 drm_gem_object_unreference_unlocked(&obj
->base
);
8254 return ERR_PTR(ret
);
8257 static struct drm_framebuffer
*
8258 intel_framebuffer_create(struct drm_device
*dev
,
8259 struct drm_mode_fb_cmd2
*mode_cmd
,
8260 struct drm_i915_gem_object
*obj
)
8262 struct drm_framebuffer
*fb
;
8265 ret
= i915_mutex_lock_interruptible(dev
);
8267 return ERR_PTR(ret
);
8268 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
8269 mutex_unlock(&dev
->struct_mutex
);
8275 intel_framebuffer_pitch_for_width(int width
, int bpp
)
8277 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
8278 return ALIGN(pitch
, 64);
8282 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
8284 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
8285 return ALIGN(pitch
* mode
->vdisplay
, PAGE_SIZE
);
8288 static struct drm_framebuffer
*
8289 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
8290 struct drm_display_mode
*mode
,
8293 struct drm_i915_gem_object
*obj
;
8294 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
8296 obj
= i915_gem_alloc_object(dev
,
8297 intel_framebuffer_size_for_mode(mode
, bpp
));
8299 return ERR_PTR(-ENOMEM
);
8301 mode_cmd
.width
= mode
->hdisplay
;
8302 mode_cmd
.height
= mode
->vdisplay
;
8303 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
8305 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
8307 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
8310 static struct drm_framebuffer
*
8311 mode_fits_in_fbdev(struct drm_device
*dev
,
8312 struct drm_display_mode
*mode
)
8314 #ifdef CONFIG_DRM_I915_FBDEV
8315 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8316 struct drm_i915_gem_object
*obj
;
8317 struct drm_framebuffer
*fb
;
8319 if (!dev_priv
->fbdev
)
8322 if (!dev_priv
->fbdev
->fb
)
8325 obj
= dev_priv
->fbdev
->fb
->obj
;
8328 fb
= &dev_priv
->fbdev
->fb
->base
;
8329 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
8330 fb
->bits_per_pixel
))
8333 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
8342 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
8343 struct drm_display_mode
*mode
,
8344 struct intel_load_detect_pipe
*old
,
8345 struct drm_modeset_acquire_ctx
*ctx
)
8347 struct intel_crtc
*intel_crtc
;
8348 struct intel_encoder
*intel_encoder
=
8349 intel_attached_encoder(connector
);
8350 struct drm_crtc
*possible_crtc
;
8351 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8352 struct drm_crtc
*crtc
= NULL
;
8353 struct drm_device
*dev
= encoder
->dev
;
8354 struct drm_framebuffer
*fb
;
8355 struct drm_mode_config
*config
= &dev
->mode_config
;
8358 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8359 connector
->base
.id
, connector
->name
,
8360 encoder
->base
.id
, encoder
->name
);
8362 drm_modeset_acquire_init(ctx
, 0);
8365 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
8370 * Algorithm gets a little messy:
8372 * - if the connector already has an assigned crtc, use it (but make
8373 * sure it's on first)
8375 * - try to find the first unused crtc that can drive this connector,
8376 * and use that if we find one
8379 /* See if we already have a CRTC for this connector */
8380 if (encoder
->crtc
) {
8381 crtc
= encoder
->crtc
;
8383 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8387 old
->dpms_mode
= connector
->dpms
;
8388 old
->load_detect_temp
= false;
8390 /* Make sure the crtc and connector are running */
8391 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
8392 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
8397 /* Find an unused one (if possible) */
8398 for_each_crtc(dev
, possible_crtc
) {
8400 if (!(encoder
->possible_crtcs
& (1 << i
)))
8402 if (!possible_crtc
->enabled
) {
8403 crtc
= possible_crtc
;
8409 * If we didn't find an unused CRTC, don't use any.
8412 DRM_DEBUG_KMS("no pipe available for load-detect\n");
8416 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8419 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
8420 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
8422 intel_crtc
= to_intel_crtc(crtc
);
8423 intel_crtc
->new_enabled
= true;
8424 intel_crtc
->new_config
= &intel_crtc
->config
;
8425 old
->dpms_mode
= connector
->dpms
;
8426 old
->load_detect_temp
= true;
8427 old
->release_fb
= NULL
;
8430 mode
= &load_detect_mode
;
8432 /* We need a framebuffer large enough to accommodate all accesses
8433 * that the plane may generate whilst we perform load detection.
8434 * We can not rely on the fbcon either being present (we get called
8435 * during its initialisation to detect all boot displays, or it may
8436 * not even exist) or that it is large enough to satisfy the
8439 fb
= mode_fits_in_fbdev(dev
, mode
);
8441 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
8442 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
8443 old
->release_fb
= fb
;
8445 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
8447 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
8451 if (intel_set_mode(crtc
, mode
, 0, 0, fb
)) {
8452 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
8453 if (old
->release_fb
)
8454 old
->release_fb
->funcs
->destroy(old
->release_fb
);
8458 /* let the connector get through one full cycle before testing */
8459 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
8463 intel_crtc
->new_enabled
= crtc
->enabled
;
8464 if (intel_crtc
->new_enabled
)
8465 intel_crtc
->new_config
= &intel_crtc
->config
;
8467 intel_crtc
->new_config
= NULL
;
8469 if (ret
== -EDEADLK
) {
8470 drm_modeset_backoff(ctx
);
8474 drm_modeset_drop_locks(ctx
);
8475 drm_modeset_acquire_fini(ctx
);
8480 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
8481 struct intel_load_detect_pipe
*old
,
8482 struct drm_modeset_acquire_ctx
*ctx
)
8484 struct intel_encoder
*intel_encoder
=
8485 intel_attached_encoder(connector
);
8486 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8487 struct drm_crtc
*crtc
= encoder
->crtc
;
8488 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8490 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8491 connector
->base
.id
, connector
->name
,
8492 encoder
->base
.id
, encoder
->name
);
8494 if (old
->load_detect_temp
) {
8495 to_intel_connector(connector
)->new_encoder
= NULL
;
8496 intel_encoder
->new_crtc
= NULL
;
8497 intel_crtc
->new_enabled
= false;
8498 intel_crtc
->new_config
= NULL
;
8499 intel_set_mode(crtc
, NULL
, 0, 0, NULL
);
8501 if (old
->release_fb
) {
8502 drm_framebuffer_unregister_private(old
->release_fb
);
8503 drm_framebuffer_unreference(old
->release_fb
);
8510 /* Switch crtc and encoder back off if necessary */
8511 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
8512 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
8515 drm_modeset_drop_locks(ctx
);
8516 drm_modeset_acquire_fini(ctx
);
8519 static int i9xx_pll_refclk(struct drm_device
*dev
,
8520 const struct intel_crtc_config
*pipe_config
)
8522 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8523 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8525 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
8526 return dev_priv
->vbt
.lvds_ssc_freq
;
8527 else if (HAS_PCH_SPLIT(dev
))
8529 else if (!IS_GEN2(dev
))
8535 /* Returns the clock of the currently programmed mode of the given pipe. */
8536 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
8537 struct intel_crtc_config
*pipe_config
)
8539 struct drm_device
*dev
= crtc
->base
.dev
;
8540 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8541 int pipe
= pipe_config
->cpu_transcoder
;
8542 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8544 intel_clock_t clock
;
8545 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
8547 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
8548 fp
= pipe_config
->dpll_hw_state
.fp0
;
8550 fp
= pipe_config
->dpll_hw_state
.fp1
;
8552 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
8553 if (IS_PINEVIEW(dev
)) {
8554 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
8555 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8557 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
8558 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8561 if (!IS_GEN2(dev
)) {
8562 if (IS_PINEVIEW(dev
))
8563 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
8564 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
8566 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
8567 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8569 switch (dpll
& DPLL_MODE_MASK
) {
8570 case DPLLB_MODE_DAC_SERIAL
:
8571 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
8574 case DPLLB_MODE_LVDS
:
8575 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
8579 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
8580 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
8584 if (IS_PINEVIEW(dev
))
8585 pineview_clock(refclk
, &clock
);
8587 i9xx_clock(refclk
, &clock
);
8589 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
8590 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
8593 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
8594 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8596 if (lvds
& LVDS_CLKB_POWER_UP
)
8601 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
8604 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
8605 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
8607 if (dpll
& PLL_P2_DIVIDE_BY_4
)
8613 i9xx_clock(refclk
, &clock
);
8617 * This value includes pixel_multiplier. We will use
8618 * port_clock to compute adjusted_mode.crtc_clock in the
8619 * encoder's get_config() function.
8621 pipe_config
->port_clock
= clock
.dot
;
8624 int intel_dotclock_calculate(int link_freq
,
8625 const struct intel_link_m_n
*m_n
)
8628 * The calculation for the data clock is:
8629 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
8630 * But we want to avoid losing precison if possible, so:
8631 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
8633 * and the link clock is simpler:
8634 * link_clock = (m * link_clock) / n
8640 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
8643 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
8644 struct intel_crtc_config
*pipe_config
)
8646 struct drm_device
*dev
= crtc
->base
.dev
;
8648 /* read out port_clock from the DPLL */
8649 i9xx_crtc_clock_get(crtc
, pipe_config
);
8652 * This value does not include pixel_multiplier.
8653 * We will check that port_clock and adjusted_mode.crtc_clock
8654 * agree once we know their relationship in the encoder's
8655 * get_config() function.
8657 pipe_config
->adjusted_mode
.crtc_clock
=
8658 intel_dotclock_calculate(intel_fdi_link_freq(dev
) * 10000,
8659 &pipe_config
->fdi_m_n
);
8662 /** Returns the currently programmed mode of the given pipe. */
8663 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
8664 struct drm_crtc
*crtc
)
8666 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8667 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8668 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
8669 struct drm_display_mode
*mode
;
8670 struct intel_crtc_config pipe_config
;
8671 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
8672 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
8673 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
8674 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
8675 enum pipe pipe
= intel_crtc
->pipe
;
8677 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
8682 * Construct a pipe_config sufficient for getting the clock info
8683 * back out of crtc_clock_get.
8685 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
8686 * to use a real value here instead.
8688 pipe_config
.cpu_transcoder
= (enum transcoder
) pipe
;
8689 pipe_config
.pixel_multiplier
= 1;
8690 pipe_config
.dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
8691 pipe_config
.dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
8692 pipe_config
.dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
8693 i9xx_crtc_clock_get(intel_crtc
, &pipe_config
);
8695 mode
->clock
= pipe_config
.port_clock
/ pipe_config
.pixel_multiplier
;
8696 mode
->hdisplay
= (htot
& 0xffff) + 1;
8697 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
8698 mode
->hsync_start
= (hsync
& 0xffff) + 1;
8699 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
8700 mode
->vdisplay
= (vtot
& 0xffff) + 1;
8701 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
8702 mode
->vsync_start
= (vsync
& 0xffff) + 1;
8703 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
8705 drm_mode_set_name(mode
);
8710 static void intel_increase_pllclock(struct drm_crtc
*crtc
)
8712 struct drm_device
*dev
= crtc
->dev
;
8713 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8714 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8715 int pipe
= intel_crtc
->pipe
;
8716 int dpll_reg
= DPLL(pipe
);
8719 if (HAS_PCH_SPLIT(dev
))
8722 if (!dev_priv
->lvds_downclock_avail
)
8725 dpll
= I915_READ(dpll_reg
);
8726 if (!HAS_PIPE_CXSR(dev
) && (dpll
& DISPLAY_RATE_SELECT_FPA1
)) {
8727 DRM_DEBUG_DRIVER("upclocking LVDS\n");
8729 assert_panel_unlocked(dev_priv
, pipe
);
8731 dpll
&= ~DISPLAY_RATE_SELECT_FPA1
;
8732 I915_WRITE(dpll_reg
, dpll
);
8733 intel_wait_for_vblank(dev
, pipe
);
8735 dpll
= I915_READ(dpll_reg
);
8736 if (dpll
& DISPLAY_RATE_SELECT_FPA1
)
8737 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
8741 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
8743 struct drm_device
*dev
= crtc
->dev
;
8744 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8745 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8747 if (HAS_PCH_SPLIT(dev
))
8750 if (!dev_priv
->lvds_downclock_avail
)
8754 * Since this is called by a timer, we should never get here in
8757 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
8758 int pipe
= intel_crtc
->pipe
;
8759 int dpll_reg
= DPLL(pipe
);
8762 DRM_DEBUG_DRIVER("downclocking LVDS\n");
8764 assert_panel_unlocked(dev_priv
, pipe
);
8766 dpll
= I915_READ(dpll_reg
);
8767 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
8768 I915_WRITE(dpll_reg
, dpll
);
8769 intel_wait_for_vblank(dev
, pipe
);
8770 dpll
= I915_READ(dpll_reg
);
8771 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
8772 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
8777 void intel_mark_busy(struct drm_device
*dev
)
8779 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8781 if (dev_priv
->mm
.busy
)
8784 intel_runtime_pm_get(dev_priv
);
8785 i915_update_gfx_val(dev_priv
);
8786 dev_priv
->mm
.busy
= true;
8789 void intel_mark_idle(struct drm_device
*dev
)
8791 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8792 struct drm_crtc
*crtc
;
8794 if (!dev_priv
->mm
.busy
)
8797 dev_priv
->mm
.busy
= false;
8799 if (!i915
.powersave
)
8802 for_each_crtc(dev
, crtc
) {
8803 if (!crtc
->primary
->fb
)
8806 intel_decrease_pllclock(crtc
);
8809 if (INTEL_INFO(dev
)->gen
>= 6)
8810 gen6_rps_idle(dev
->dev_private
);
8813 intel_runtime_pm_put(dev_priv
);
8817 void intel_mark_fb_busy(struct drm_i915_gem_object
*obj
,
8818 struct intel_engine_cs
*ring
)
8820 struct drm_device
*dev
= obj
->base
.dev
;
8821 struct drm_crtc
*crtc
;
8823 intel_edp_psr_exit(dev
);
8825 if (!i915
.powersave
)
8828 for_each_crtc(dev
, crtc
) {
8829 if (!crtc
->primary
->fb
)
8832 if (to_intel_framebuffer(crtc
->primary
->fb
)->obj
!= obj
)
8835 intel_increase_pllclock(crtc
);
8836 if (ring
&& intel_fbc_enabled(dev
))
8837 ring
->fbc_dirty
= true;
8841 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
8843 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8844 struct drm_device
*dev
= crtc
->dev
;
8845 struct intel_unpin_work
*work
;
8846 unsigned long flags
;
8848 spin_lock_irqsave(&dev
->event_lock
, flags
);
8849 work
= intel_crtc
->unpin_work
;
8850 intel_crtc
->unpin_work
= NULL
;
8851 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
8854 cancel_work_sync(&work
->work
);
8858 drm_crtc_cleanup(crtc
);
8863 static void intel_unpin_work_fn(struct work_struct
*__work
)
8865 struct intel_unpin_work
*work
=
8866 container_of(__work
, struct intel_unpin_work
, work
);
8867 struct drm_device
*dev
= work
->crtc
->dev
;
8869 mutex_lock(&dev
->struct_mutex
);
8870 intel_unpin_fb_obj(work
->old_fb_obj
);
8871 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
8872 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
8874 intel_update_fbc(dev
);
8875 mutex_unlock(&dev
->struct_mutex
);
8877 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
8878 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
8883 static void do_intel_finish_page_flip(struct drm_device
*dev
,
8884 struct drm_crtc
*crtc
)
8886 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8887 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8888 struct intel_unpin_work
*work
;
8889 unsigned long flags
;
8891 /* Ignore early vblank irqs */
8892 if (intel_crtc
== NULL
)
8895 spin_lock_irqsave(&dev
->event_lock
, flags
);
8896 work
= intel_crtc
->unpin_work
;
8898 /* Ensure we don't miss a work->pending update ... */
8901 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
8902 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
8906 /* and that the unpin work is consistent wrt ->pending. */
8909 intel_crtc
->unpin_work
= NULL
;
8912 drm_send_vblank_event(dev
, intel_crtc
->pipe
, work
->event
);
8914 drm_crtc_vblank_put(crtc
);
8916 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
8918 wake_up_all(&dev_priv
->pending_flip_queue
);
8920 queue_work(dev_priv
->wq
, &work
->work
);
8922 trace_i915_flip_complete(intel_crtc
->plane
, work
->pending_flip_obj
);
8925 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
8927 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8928 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
8930 do_intel_finish_page_flip(dev
, crtc
);
8933 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
8935 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8936 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
8938 do_intel_finish_page_flip(dev
, crtc
);
8941 /* Is 'a' after or equal to 'b'? */
8942 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
8944 return !((a
- b
) & 0x80000000);
8947 static bool page_flip_finished(struct intel_crtc
*crtc
)
8949 struct drm_device
*dev
= crtc
->base
.dev
;
8950 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8953 * The relevant registers doen't exist on pre-ctg.
8954 * As the flip done interrupt doesn't trigger for mmio
8955 * flips on gmch platforms, a flip count check isn't
8956 * really needed there. But since ctg has the registers,
8957 * include it in the check anyway.
8959 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
8963 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
8964 * used the same base address. In that case the mmio flip might
8965 * have completed, but the CS hasn't even executed the flip yet.
8967 * A flip count check isn't enough as the CS might have updated
8968 * the base address just after start of vblank, but before we
8969 * managed to process the interrupt. This means we'd complete the
8972 * Combining both checks should get us a good enough result. It may
8973 * still happen that the CS flip has been executed, but has not
8974 * yet actually completed. But in case the base address is the same
8975 * anyway, we don't really care.
8977 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
8978 crtc
->unpin_work
->gtt_offset
&&
8979 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc
->pipe
)),
8980 crtc
->unpin_work
->flip_count
);
8983 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
8985 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8986 struct intel_crtc
*intel_crtc
=
8987 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
8988 unsigned long flags
;
8990 /* NB: An MMIO update of the plane base pointer will also
8991 * generate a page-flip completion irq, i.e. every modeset
8992 * is also accompanied by a spurious intel_prepare_page_flip().
8994 spin_lock_irqsave(&dev
->event_lock
, flags
);
8995 if (intel_crtc
->unpin_work
&& page_flip_finished(intel_crtc
))
8996 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
8997 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9000 static inline void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
9002 /* Ensure that the work item is consistent when activating it ... */
9004 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
9005 /* and that it is marked active as soon as the irq could fire. */
9009 static int intel_gen2_queue_flip(struct drm_device
*dev
,
9010 struct drm_crtc
*crtc
,
9011 struct drm_framebuffer
*fb
,
9012 struct drm_i915_gem_object
*obj
,
9013 struct intel_engine_cs
*ring
,
9016 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9020 ret
= intel_ring_begin(ring
, 6);
9024 /* Can't queue multiple flips, so wait for the previous
9025 * one to finish before executing the next.
9027 if (intel_crtc
->plane
)
9028 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9030 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9031 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9032 intel_ring_emit(ring
, MI_NOOP
);
9033 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9034 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9035 intel_ring_emit(ring
, fb
->pitches
[0]);
9036 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9037 intel_ring_emit(ring
, 0); /* aux display base address, unused */
9039 intel_mark_page_flip_active(intel_crtc
);
9040 __intel_ring_advance(ring
);
9044 static int intel_gen3_queue_flip(struct drm_device
*dev
,
9045 struct drm_crtc
*crtc
,
9046 struct drm_framebuffer
*fb
,
9047 struct drm_i915_gem_object
*obj
,
9048 struct intel_engine_cs
*ring
,
9051 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9055 ret
= intel_ring_begin(ring
, 6);
9059 if (intel_crtc
->plane
)
9060 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9062 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9063 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9064 intel_ring_emit(ring
, MI_NOOP
);
9065 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
9066 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9067 intel_ring_emit(ring
, fb
->pitches
[0]);
9068 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9069 intel_ring_emit(ring
, MI_NOOP
);
9071 intel_mark_page_flip_active(intel_crtc
);
9072 __intel_ring_advance(ring
);
9076 static int intel_gen4_queue_flip(struct drm_device
*dev
,
9077 struct drm_crtc
*crtc
,
9078 struct drm_framebuffer
*fb
,
9079 struct drm_i915_gem_object
*obj
,
9080 struct intel_engine_cs
*ring
,
9083 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9084 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9085 uint32_t pf
, pipesrc
;
9088 ret
= intel_ring_begin(ring
, 4);
9092 /* i965+ uses the linear or tiled offsets from the
9093 * Display Registers (which do not change across a page-flip)
9094 * so we need only reprogram the base address.
9096 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9097 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9098 intel_ring_emit(ring
, fb
->pitches
[0]);
9099 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
|
9102 /* XXX Enabling the panel-fitter across page-flip is so far
9103 * untested on non-native modes, so ignore it for now.
9104 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
9107 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9108 intel_ring_emit(ring
, pf
| pipesrc
);
9110 intel_mark_page_flip_active(intel_crtc
);
9111 __intel_ring_advance(ring
);
9115 static int intel_gen6_queue_flip(struct drm_device
*dev
,
9116 struct drm_crtc
*crtc
,
9117 struct drm_framebuffer
*fb
,
9118 struct drm_i915_gem_object
*obj
,
9119 struct intel_engine_cs
*ring
,
9122 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9123 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9124 uint32_t pf
, pipesrc
;
9127 ret
= intel_ring_begin(ring
, 4);
9131 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9132 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9133 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
9134 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9136 /* Contrary to the suggestions in the documentation,
9137 * "Enable Panel Fitter" does not seem to be required when page
9138 * flipping with a non-native mode, and worse causes a normal
9140 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
9143 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9144 intel_ring_emit(ring
, pf
| pipesrc
);
9146 intel_mark_page_flip_active(intel_crtc
);
9147 __intel_ring_advance(ring
);
9151 static int intel_gen7_queue_flip(struct drm_device
*dev
,
9152 struct drm_crtc
*crtc
,
9153 struct drm_framebuffer
*fb
,
9154 struct drm_i915_gem_object
*obj
,
9155 struct intel_engine_cs
*ring
,
9158 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9159 uint32_t plane_bit
= 0;
9162 switch (intel_crtc
->plane
) {
9164 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
9167 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
9170 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
9173 WARN_ONCE(1, "unknown plane in flip command\n");
9178 if (ring
->id
== RCS
) {
9181 * On Gen 8, SRM is now taking an extra dword to accommodate
9182 * 48bits addresses, and we need a NOOP for the batch size to
9190 * BSpec MI_DISPLAY_FLIP for IVB:
9191 * "The full packet must be contained within the same cache line."
9193 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
9194 * cacheline, if we ever start emitting more commands before
9195 * the MI_DISPLAY_FLIP we may need to first emit everything else,
9196 * then do the cacheline alignment, and finally emit the
9199 ret
= intel_ring_cacheline_align(ring
);
9203 ret
= intel_ring_begin(ring
, len
);
9207 /* Unmask the flip-done completion message. Note that the bspec says that
9208 * we should do this for both the BCS and RCS, and that we must not unmask
9209 * more than one flip event at any time (or ensure that one flip message
9210 * can be sent by waiting for flip-done prior to queueing new flips).
9211 * Experimentation says that BCS works despite DERRMR masking all
9212 * flip-done completion events and that unmasking all planes at once
9213 * for the RCS also doesn't appear to drop events. Setting the DERRMR
9214 * to zero does lead to lockups within MI_DISPLAY_FLIP.
9216 if (ring
->id
== RCS
) {
9217 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
9218 intel_ring_emit(ring
, DERRMR
);
9219 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
9220 DERRMR_PIPEB_PRI_FLIP_DONE
|
9221 DERRMR_PIPEC_PRI_FLIP_DONE
));
9223 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8(1) |
9224 MI_SRM_LRM_GLOBAL_GTT
);
9226 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM(1) |
9227 MI_SRM_LRM_GLOBAL_GTT
);
9228 intel_ring_emit(ring
, DERRMR
);
9229 intel_ring_emit(ring
, ring
->scratch
.gtt_offset
+ 256);
9231 intel_ring_emit(ring
, 0);
9232 intel_ring_emit(ring
, MI_NOOP
);
9236 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
9237 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
9238 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9239 intel_ring_emit(ring
, (MI_NOOP
));
9241 intel_mark_page_flip_active(intel_crtc
);
9242 __intel_ring_advance(ring
);
9246 static bool use_mmio_flip(struct intel_engine_cs
*ring
,
9247 struct drm_i915_gem_object
*obj
)
9250 * This is not being used for older platforms, because
9251 * non-availability of flip done interrupt forces us to use
9252 * CS flips. Older platforms derive flip done using some clever
9253 * tricks involving the flip_pending status bits and vblank irqs.
9254 * So using MMIO flips there would disrupt this mechanism.
9257 if (INTEL_INFO(ring
->dev
)->gen
< 5)
9260 if (i915
.use_mmio_flip
< 0)
9262 else if (i915
.use_mmio_flip
> 0)
9265 return ring
!= obj
->ring
;
9268 static void intel_do_mmio_flip(struct intel_crtc
*intel_crtc
)
9270 struct drm_device
*dev
= intel_crtc
->base
.dev
;
9271 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9272 struct intel_framebuffer
*intel_fb
=
9273 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
9274 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
9278 intel_mark_page_flip_active(intel_crtc
);
9280 reg
= DSPCNTR(intel_crtc
->plane
);
9281 dspcntr
= I915_READ(reg
);
9283 if (INTEL_INFO(dev
)->gen
>= 4) {
9284 if (obj
->tiling_mode
!= I915_TILING_NONE
)
9285 dspcntr
|= DISPPLANE_TILED
;
9287 dspcntr
&= ~DISPPLANE_TILED
;
9289 I915_WRITE(reg
, dspcntr
);
9291 I915_WRITE(DSPSURF(intel_crtc
->plane
),
9292 intel_crtc
->unpin_work
->gtt_offset
);
9293 POSTING_READ(DSPSURF(intel_crtc
->plane
));
9296 static int intel_postpone_flip(struct drm_i915_gem_object
*obj
)
9298 struct intel_engine_cs
*ring
;
9301 lockdep_assert_held(&obj
->base
.dev
->struct_mutex
);
9303 if (!obj
->last_write_seqno
)
9308 if (i915_seqno_passed(ring
->get_seqno(ring
, true),
9309 obj
->last_write_seqno
))
9312 ret
= i915_gem_check_olr(ring
, obj
->last_write_seqno
);
9316 if (WARN_ON(!ring
->irq_get(ring
)))
9322 void intel_notify_mmio_flip(struct intel_engine_cs
*ring
)
9324 struct drm_i915_private
*dev_priv
= to_i915(ring
->dev
);
9325 struct intel_crtc
*intel_crtc
;
9326 unsigned long irq_flags
;
9329 seqno
= ring
->get_seqno(ring
, false);
9331 spin_lock_irqsave(&dev_priv
->mmio_flip_lock
, irq_flags
);
9332 for_each_intel_crtc(ring
->dev
, intel_crtc
) {
9333 struct intel_mmio_flip
*mmio_flip
;
9335 mmio_flip
= &intel_crtc
->mmio_flip
;
9336 if (mmio_flip
->seqno
== 0)
9339 if (ring
->id
!= mmio_flip
->ring_id
)
9342 if (i915_seqno_passed(seqno
, mmio_flip
->seqno
)) {
9343 intel_do_mmio_flip(intel_crtc
);
9344 mmio_flip
->seqno
= 0;
9345 ring
->irq_put(ring
);
9348 spin_unlock_irqrestore(&dev_priv
->mmio_flip_lock
, irq_flags
);
9351 static int intel_queue_mmio_flip(struct drm_device
*dev
,
9352 struct drm_crtc
*crtc
,
9353 struct drm_framebuffer
*fb
,
9354 struct drm_i915_gem_object
*obj
,
9355 struct intel_engine_cs
*ring
,
9358 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9359 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9360 unsigned long irq_flags
;
9363 if (WARN_ON(intel_crtc
->mmio_flip
.seqno
))
9366 ret
= intel_postpone_flip(obj
);
9370 intel_do_mmio_flip(intel_crtc
);
9374 spin_lock_irqsave(&dev_priv
->mmio_flip_lock
, irq_flags
);
9375 intel_crtc
->mmio_flip
.seqno
= obj
->last_write_seqno
;
9376 intel_crtc
->mmio_flip
.ring_id
= obj
->ring
->id
;
9377 spin_unlock_irqrestore(&dev_priv
->mmio_flip_lock
, irq_flags
);
9380 * Double check to catch cases where irq fired before
9381 * mmio flip data was ready
9383 intel_notify_mmio_flip(obj
->ring
);
9387 static int intel_default_queue_flip(struct drm_device
*dev
,
9388 struct drm_crtc
*crtc
,
9389 struct drm_framebuffer
*fb
,
9390 struct drm_i915_gem_object
*obj
,
9391 struct intel_engine_cs
*ring
,
9397 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
9398 struct drm_framebuffer
*fb
,
9399 struct drm_pending_vblank_event
*event
,
9400 uint32_t page_flip_flags
)
9402 struct drm_device
*dev
= crtc
->dev
;
9403 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9404 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
9405 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(fb
)->obj
;
9406 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9407 struct intel_unpin_work
*work
;
9408 struct intel_engine_cs
*ring
;
9409 unsigned long flags
;
9412 /* Can't change pixel format via MI display flips. */
9413 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
9417 * TILEOFF/LINOFF registers can't be changed via MI display flips.
9418 * Note that pitch changes could also affect these register.
9420 if (INTEL_INFO(dev
)->gen
> 3 &&
9421 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
9422 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
9425 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
9428 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
9432 /* Exit PSR early in page flip */
9433 intel_edp_psr_exit(dev
);
9435 work
->event
= event
;
9437 work
->old_fb_obj
= to_intel_framebuffer(old_fb
)->obj
;
9438 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
9440 ret
= drm_crtc_vblank_get(crtc
);
9444 /* We borrow the event spin lock for protecting unpin_work */
9445 spin_lock_irqsave(&dev
->event_lock
, flags
);
9446 if (intel_crtc
->unpin_work
) {
9447 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9449 drm_crtc_vblank_put(crtc
);
9451 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
9454 intel_crtc
->unpin_work
= work
;
9455 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9457 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
9458 flush_workqueue(dev_priv
->wq
);
9460 ret
= i915_mutex_lock_interruptible(dev
);
9464 /* Reference the objects for the scheduled work. */
9465 drm_gem_object_reference(&work
->old_fb_obj
->base
);
9466 drm_gem_object_reference(&obj
->base
);
9468 crtc
->primary
->fb
= fb
;
9470 work
->pending_flip_obj
= obj
;
9472 work
->enable_stall_check
= true;
9474 atomic_inc(&intel_crtc
->unpin_work_count
);
9475 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
9477 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
9478 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_GM45(intel_crtc
->pipe
)) + 1;
9480 if (IS_VALLEYVIEW(dev
)) {
9481 ring
= &dev_priv
->ring
[BCS
];
9482 } else if (INTEL_INFO(dev
)->gen
>= 7) {
9484 if (ring
== NULL
|| ring
->id
!= RCS
)
9485 ring
= &dev_priv
->ring
[BCS
];
9487 ring
= &dev_priv
->ring
[RCS
];
9490 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
9492 goto cleanup_pending
;
9495 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
;
9497 if (use_mmio_flip(ring
, obj
))
9498 ret
= intel_queue_mmio_flip(dev
, crtc
, fb
, obj
, ring
,
9501 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, ring
,
9506 intel_disable_fbc(dev
);
9507 intel_mark_fb_busy(obj
, NULL
);
9508 mutex_unlock(&dev
->struct_mutex
);
9510 trace_i915_flip_request(intel_crtc
->plane
, obj
);
9515 intel_unpin_fb_obj(obj
);
9517 atomic_dec(&intel_crtc
->unpin_work_count
);
9518 crtc
->primary
->fb
= old_fb
;
9519 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
9520 drm_gem_object_unreference(&obj
->base
);
9521 mutex_unlock(&dev
->struct_mutex
);
9524 spin_lock_irqsave(&dev
->event_lock
, flags
);
9525 intel_crtc
->unpin_work
= NULL
;
9526 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9528 drm_crtc_vblank_put(crtc
);
9534 intel_crtc_wait_for_pending_flips(crtc
);
9535 ret
= intel_pipe_set_base(crtc
, crtc
->x
, crtc
->y
, fb
);
9536 if (ret
== 0 && event
)
9537 drm_send_vblank_event(dev
, intel_crtc
->pipe
, event
);
9542 static struct drm_crtc_helper_funcs intel_helper_funcs
= {
9543 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
9544 .load_lut
= intel_crtc_load_lut
,
9548 * intel_modeset_update_staged_output_state
9550 * Updates the staged output configuration state, e.g. after we've read out the
9553 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
9555 struct intel_crtc
*crtc
;
9556 struct intel_encoder
*encoder
;
9557 struct intel_connector
*connector
;
9559 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9561 connector
->new_encoder
=
9562 to_intel_encoder(connector
->base
.encoder
);
9565 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9568 to_intel_crtc(encoder
->base
.crtc
);
9571 for_each_intel_crtc(dev
, crtc
) {
9572 crtc
->new_enabled
= crtc
->base
.enabled
;
9574 if (crtc
->new_enabled
)
9575 crtc
->new_config
= &crtc
->config
;
9577 crtc
->new_config
= NULL
;
9582 * intel_modeset_commit_output_state
9584 * This function copies the stage display pipe configuration to the real one.
9586 static void intel_modeset_commit_output_state(struct drm_device
*dev
)
9588 struct intel_crtc
*crtc
;
9589 struct intel_encoder
*encoder
;
9590 struct intel_connector
*connector
;
9592 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9594 connector
->base
.encoder
= &connector
->new_encoder
->base
;
9597 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9599 encoder
->base
.crtc
= &encoder
->new_crtc
->base
;
9602 for_each_intel_crtc(dev
, crtc
) {
9603 crtc
->base
.enabled
= crtc
->new_enabled
;
9608 connected_sink_compute_bpp(struct intel_connector
*connector
,
9609 struct intel_crtc_config
*pipe_config
)
9611 int bpp
= pipe_config
->pipe_bpp
;
9613 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
9614 connector
->base
.base
.id
,
9615 connector
->base
.name
);
9617 /* Don't use an invalid EDID bpc value */
9618 if (connector
->base
.display_info
.bpc
&&
9619 connector
->base
.display_info
.bpc
* 3 < bpp
) {
9620 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
9621 bpp
, connector
->base
.display_info
.bpc
*3);
9622 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
9625 /* Clamp bpp to 8 on screens without EDID 1.4 */
9626 if (connector
->base
.display_info
.bpc
== 0 && bpp
> 24) {
9627 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
9629 pipe_config
->pipe_bpp
= 24;
9634 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
9635 struct drm_framebuffer
*fb
,
9636 struct intel_crtc_config
*pipe_config
)
9638 struct drm_device
*dev
= crtc
->base
.dev
;
9639 struct intel_connector
*connector
;
9642 switch (fb
->pixel_format
) {
9644 bpp
= 8*3; /* since we go through a colormap */
9646 case DRM_FORMAT_XRGB1555
:
9647 case DRM_FORMAT_ARGB1555
:
9648 /* checked in intel_framebuffer_init already */
9649 if (WARN_ON(INTEL_INFO(dev
)->gen
> 3))
9651 case DRM_FORMAT_RGB565
:
9652 bpp
= 6*3; /* min is 18bpp */
9654 case DRM_FORMAT_XBGR8888
:
9655 case DRM_FORMAT_ABGR8888
:
9656 /* checked in intel_framebuffer_init already */
9657 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
9659 case DRM_FORMAT_XRGB8888
:
9660 case DRM_FORMAT_ARGB8888
:
9663 case DRM_FORMAT_XRGB2101010
:
9664 case DRM_FORMAT_ARGB2101010
:
9665 case DRM_FORMAT_XBGR2101010
:
9666 case DRM_FORMAT_ABGR2101010
:
9667 /* checked in intel_framebuffer_init already */
9668 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
9672 /* TODO: gen4+ supports 16 bpc floating point, too. */
9674 DRM_DEBUG_KMS("unsupported depth\n");
9678 pipe_config
->pipe_bpp
= bpp
;
9680 /* Clamp display bpp to EDID value */
9681 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9683 if (!connector
->new_encoder
||
9684 connector
->new_encoder
->new_crtc
!= crtc
)
9687 connected_sink_compute_bpp(connector
, pipe_config
);
9693 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
9695 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
9696 "type: 0x%x flags: 0x%x\n",
9698 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
9699 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
9700 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
9701 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
9704 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
9705 struct intel_crtc_config
*pipe_config
,
9706 const char *context
)
9708 DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc
->base
.base
.id
,
9709 context
, pipe_name(crtc
->pipe
));
9711 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config
->cpu_transcoder
));
9712 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
9713 pipe_config
->pipe_bpp
, pipe_config
->dither
);
9714 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
9715 pipe_config
->has_pch_encoder
,
9716 pipe_config
->fdi_lanes
,
9717 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
9718 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
9719 pipe_config
->fdi_m_n
.tu
);
9720 DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
9721 pipe_config
->has_dp_encoder
,
9722 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
9723 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
9724 pipe_config
->dp_m_n
.tu
);
9725 DRM_DEBUG_KMS("requested mode:\n");
9726 drm_mode_debug_printmodeline(&pipe_config
->requested_mode
);
9727 DRM_DEBUG_KMS("adjusted mode:\n");
9728 drm_mode_debug_printmodeline(&pipe_config
->adjusted_mode
);
9729 intel_dump_crtc_timings(&pipe_config
->adjusted_mode
);
9730 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
9731 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
9732 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
9733 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
9734 pipe_config
->gmch_pfit
.control
,
9735 pipe_config
->gmch_pfit
.pgm_ratios
,
9736 pipe_config
->gmch_pfit
.lvds_border_bits
);
9737 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
9738 pipe_config
->pch_pfit
.pos
,
9739 pipe_config
->pch_pfit
.size
,
9740 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
9741 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
9742 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
9745 static bool encoders_cloneable(const struct intel_encoder
*a
,
9746 const struct intel_encoder
*b
)
9748 /* masks could be asymmetric, so check both ways */
9749 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
9750 b
->cloneable
& (1 << a
->type
));
9753 static bool check_single_encoder_cloning(struct intel_crtc
*crtc
,
9754 struct intel_encoder
*encoder
)
9756 struct drm_device
*dev
= crtc
->base
.dev
;
9757 struct intel_encoder
*source_encoder
;
9759 list_for_each_entry(source_encoder
,
9760 &dev
->mode_config
.encoder_list
, base
.head
) {
9761 if (source_encoder
->new_crtc
!= crtc
)
9764 if (!encoders_cloneable(encoder
, source_encoder
))
9771 static bool check_encoder_cloning(struct intel_crtc
*crtc
)
9773 struct drm_device
*dev
= crtc
->base
.dev
;
9774 struct intel_encoder
*encoder
;
9776 list_for_each_entry(encoder
,
9777 &dev
->mode_config
.encoder_list
, base
.head
) {
9778 if (encoder
->new_crtc
!= crtc
)
9781 if (!check_single_encoder_cloning(crtc
, encoder
))
9788 static struct intel_crtc_config
*
9789 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
9790 struct drm_framebuffer
*fb
,
9791 struct drm_display_mode
*mode
)
9793 struct drm_device
*dev
= crtc
->dev
;
9794 struct intel_encoder
*encoder
;
9795 struct intel_crtc_config
*pipe_config
;
9796 int plane_bpp
, ret
= -EINVAL
;
9799 if (!check_encoder_cloning(to_intel_crtc(crtc
))) {
9800 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
9801 return ERR_PTR(-EINVAL
);
9804 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
9806 return ERR_PTR(-ENOMEM
);
9808 drm_mode_copy(&pipe_config
->adjusted_mode
, mode
);
9809 drm_mode_copy(&pipe_config
->requested_mode
, mode
);
9811 pipe_config
->cpu_transcoder
=
9812 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
9813 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
9816 * Sanitize sync polarity flags based on requested ones. If neither
9817 * positive or negative polarity is requested, treat this as meaning
9818 * negative polarity.
9820 if (!(pipe_config
->adjusted_mode
.flags
&
9821 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
9822 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
9824 if (!(pipe_config
->adjusted_mode
.flags
&
9825 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
9826 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
9828 /* Compute a starting value for pipe_config->pipe_bpp taking the source
9829 * plane pixel format and any sink constraints into account. Returns the
9830 * source plane bpp so that dithering can be selected on mismatches
9831 * after encoders and crtc also have had their say. */
9832 plane_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
9838 * Determine the real pipe dimensions. Note that stereo modes can
9839 * increase the actual pipe size due to the frame doubling and
9840 * insertion of additional space for blanks between the frame. This
9841 * is stored in the crtc timings. We use the requested mode to do this
9842 * computation to clearly distinguish it from the adjusted mode, which
9843 * can be changed by the connectors in the below retry loop.
9845 drm_mode_set_crtcinfo(&pipe_config
->requested_mode
, CRTC_STEREO_DOUBLE
);
9846 pipe_config
->pipe_src_w
= pipe_config
->requested_mode
.crtc_hdisplay
;
9847 pipe_config
->pipe_src_h
= pipe_config
->requested_mode
.crtc_vdisplay
;
9850 /* Ensure the port clock defaults are reset when retrying. */
9851 pipe_config
->port_clock
= 0;
9852 pipe_config
->pixel_multiplier
= 1;
9854 /* Fill in default crtc timings, allow encoders to overwrite them. */
9855 drm_mode_set_crtcinfo(&pipe_config
->adjusted_mode
, CRTC_STEREO_DOUBLE
);
9857 /* Pass our mode to the connectors and the CRTC to give them a chance to
9858 * adjust it according to limitations or connector properties, and also
9859 * a chance to reject the mode entirely.
9861 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9864 if (&encoder
->new_crtc
->base
!= crtc
)
9867 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
9868 DRM_DEBUG_KMS("Encoder config failure\n");
9873 /* Set default port clock if not overwritten by the encoder. Needs to be
9874 * done afterwards in case the encoder adjusts the mode. */
9875 if (!pipe_config
->port_clock
)
9876 pipe_config
->port_clock
= pipe_config
->adjusted_mode
.crtc_clock
9877 * pipe_config
->pixel_multiplier
;
9879 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
9881 DRM_DEBUG_KMS("CRTC fixup failed\n");
9886 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
9891 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
9896 pipe_config
->dither
= pipe_config
->pipe_bpp
!= plane_bpp
;
9897 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
9898 plane_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
9903 return ERR_PTR(ret
);
9906 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
9907 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
9909 intel_modeset_affected_pipes(struct drm_crtc
*crtc
, unsigned *modeset_pipes
,
9910 unsigned *prepare_pipes
, unsigned *disable_pipes
)
9912 struct intel_crtc
*intel_crtc
;
9913 struct drm_device
*dev
= crtc
->dev
;
9914 struct intel_encoder
*encoder
;
9915 struct intel_connector
*connector
;
9916 struct drm_crtc
*tmp_crtc
;
9918 *disable_pipes
= *modeset_pipes
= *prepare_pipes
= 0;
9920 /* Check which crtcs have changed outputs connected to them, these need
9921 * to be part of the prepare_pipes mask. We don't (yet) support global
9922 * modeset across multiple crtcs, so modeset_pipes will only have one
9923 * bit set at most. */
9924 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9926 if (connector
->base
.encoder
== &connector
->new_encoder
->base
)
9929 if (connector
->base
.encoder
) {
9930 tmp_crtc
= connector
->base
.encoder
->crtc
;
9932 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
9935 if (connector
->new_encoder
)
9937 1 << connector
->new_encoder
->new_crtc
->pipe
;
9940 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9942 if (encoder
->base
.crtc
== &encoder
->new_crtc
->base
)
9945 if (encoder
->base
.crtc
) {
9946 tmp_crtc
= encoder
->base
.crtc
;
9948 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
9951 if (encoder
->new_crtc
)
9952 *prepare_pipes
|= 1 << encoder
->new_crtc
->pipe
;
9955 /* Check for pipes that will be enabled/disabled ... */
9956 for_each_intel_crtc(dev
, intel_crtc
) {
9957 if (intel_crtc
->base
.enabled
== intel_crtc
->new_enabled
)
9960 if (!intel_crtc
->new_enabled
)
9961 *disable_pipes
|= 1 << intel_crtc
->pipe
;
9963 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
9967 /* set_mode is also used to update properties on life display pipes. */
9968 intel_crtc
= to_intel_crtc(crtc
);
9969 if (intel_crtc
->new_enabled
)
9970 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
9973 * For simplicity do a full modeset on any pipe where the output routing
9974 * changed. We could be more clever, but that would require us to be
9975 * more careful with calling the relevant encoder->mode_set functions.
9978 *modeset_pipes
= *prepare_pipes
;
9980 /* ... and mask these out. */
9981 *modeset_pipes
&= ~(*disable_pipes
);
9982 *prepare_pipes
&= ~(*disable_pipes
);
9985 * HACK: We don't (yet) fully support global modesets. intel_set_config
9986 * obies this rule, but the modeset restore mode of
9987 * intel_modeset_setup_hw_state does not.
9989 *modeset_pipes
&= 1 << intel_crtc
->pipe
;
9990 *prepare_pipes
&= 1 << intel_crtc
->pipe
;
9992 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
9993 *modeset_pipes
, *prepare_pipes
, *disable_pipes
);
9996 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
9998 struct drm_encoder
*encoder
;
9999 struct drm_device
*dev
= crtc
->dev
;
10001 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
10002 if (encoder
->crtc
== crtc
)
10009 intel_modeset_update_state(struct drm_device
*dev
, unsigned prepare_pipes
)
10011 struct intel_encoder
*intel_encoder
;
10012 struct intel_crtc
*intel_crtc
;
10013 struct drm_connector
*connector
;
10015 list_for_each_entry(intel_encoder
, &dev
->mode_config
.encoder_list
,
10017 if (!intel_encoder
->base
.crtc
)
10020 intel_crtc
= to_intel_crtc(intel_encoder
->base
.crtc
);
10022 if (prepare_pipes
& (1 << intel_crtc
->pipe
))
10023 intel_encoder
->connectors_active
= false;
10026 intel_modeset_commit_output_state(dev
);
10028 /* Double check state. */
10029 for_each_intel_crtc(dev
, intel_crtc
) {
10030 WARN_ON(intel_crtc
->base
.enabled
!= intel_crtc_in_use(&intel_crtc
->base
));
10031 WARN_ON(intel_crtc
->new_config
&&
10032 intel_crtc
->new_config
!= &intel_crtc
->config
);
10033 WARN_ON(intel_crtc
->base
.enabled
!= !!intel_crtc
->new_config
);
10036 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
10037 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
10040 intel_crtc
= to_intel_crtc(connector
->encoder
->crtc
);
10042 if (prepare_pipes
& (1 << intel_crtc
->pipe
)) {
10043 struct drm_property
*dpms_property
=
10044 dev
->mode_config
.dpms_property
;
10046 connector
->dpms
= DRM_MODE_DPMS_ON
;
10047 drm_object_property_set_value(&connector
->base
,
10051 intel_encoder
= to_intel_encoder(connector
->encoder
);
10052 intel_encoder
->connectors_active
= true;
10058 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
10062 if (clock1
== clock2
)
10065 if (!clock1
|| !clock2
)
10068 diff
= abs(clock1
- clock2
);
10070 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
10076 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
10077 list_for_each_entry((intel_crtc), \
10078 &(dev)->mode_config.crtc_list, \
10080 if (mask & (1 <<(intel_crtc)->pipe))
10083 intel_pipe_config_compare(struct drm_device
*dev
,
10084 struct intel_crtc_config
*current_config
,
10085 struct intel_crtc_config
*pipe_config
)
10087 #define PIPE_CONF_CHECK_X(name) \
10088 if (current_config->name != pipe_config->name) { \
10089 DRM_ERROR("mismatch in " #name " " \
10090 "(expected 0x%08x, found 0x%08x)\n", \
10091 current_config->name, \
10092 pipe_config->name); \
10096 #define PIPE_CONF_CHECK_I(name) \
10097 if (current_config->name != pipe_config->name) { \
10098 DRM_ERROR("mismatch in " #name " " \
10099 "(expected %i, found %i)\n", \
10100 current_config->name, \
10101 pipe_config->name); \
10105 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
10106 if ((current_config->name ^ pipe_config->name) & (mask)) { \
10107 DRM_ERROR("mismatch in " #name "(" #mask ") " \
10108 "(expected %i, found %i)\n", \
10109 current_config->name & (mask), \
10110 pipe_config->name & (mask)); \
10114 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
10115 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
10116 DRM_ERROR("mismatch in " #name " " \
10117 "(expected %i, found %i)\n", \
10118 current_config->name, \
10119 pipe_config->name); \
10123 #define PIPE_CONF_QUIRK(quirk) \
10124 ((current_config->quirks | pipe_config->quirks) & (quirk))
10126 PIPE_CONF_CHECK_I(cpu_transcoder
);
10128 PIPE_CONF_CHECK_I(has_pch_encoder
);
10129 PIPE_CONF_CHECK_I(fdi_lanes
);
10130 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_m
);
10131 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_n
);
10132 PIPE_CONF_CHECK_I(fdi_m_n
.link_m
);
10133 PIPE_CONF_CHECK_I(fdi_m_n
.link_n
);
10134 PIPE_CONF_CHECK_I(fdi_m_n
.tu
);
10136 PIPE_CONF_CHECK_I(has_dp_encoder
);
10137 PIPE_CONF_CHECK_I(dp_m_n
.gmch_m
);
10138 PIPE_CONF_CHECK_I(dp_m_n
.gmch_n
);
10139 PIPE_CONF_CHECK_I(dp_m_n
.link_m
);
10140 PIPE_CONF_CHECK_I(dp_m_n
.link_n
);
10141 PIPE_CONF_CHECK_I(dp_m_n
.tu
);
10143 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hdisplay
);
10144 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_htotal
);
10145 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_start
);
10146 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_end
);
10147 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_start
);
10148 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_end
);
10150 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vdisplay
);
10151 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vtotal
);
10152 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_start
);
10153 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_end
);
10154 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_start
);
10155 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_end
);
10157 PIPE_CONF_CHECK_I(pixel_multiplier
);
10158 PIPE_CONF_CHECK_I(has_hdmi_sink
);
10159 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
10160 IS_VALLEYVIEW(dev
))
10161 PIPE_CONF_CHECK_I(limited_color_range
);
10163 PIPE_CONF_CHECK_I(has_audio
);
10165 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10166 DRM_MODE_FLAG_INTERLACE
);
10168 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
10169 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10170 DRM_MODE_FLAG_PHSYNC
);
10171 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10172 DRM_MODE_FLAG_NHSYNC
);
10173 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10174 DRM_MODE_FLAG_PVSYNC
);
10175 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10176 DRM_MODE_FLAG_NVSYNC
);
10179 PIPE_CONF_CHECK_I(pipe_src_w
);
10180 PIPE_CONF_CHECK_I(pipe_src_h
);
10183 * FIXME: BIOS likes to set up a cloned config with lvds+external
10184 * screen. Since we don't yet re-compute the pipe config when moving
10185 * just the lvds port away to another pipe the sw tracking won't match.
10187 * Proper atomic modesets with recomputed global state will fix this.
10188 * Until then just don't check gmch state for inherited modes.
10190 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE
)) {
10191 PIPE_CONF_CHECK_I(gmch_pfit
.control
);
10192 /* pfit ratios are autocomputed by the hw on gen4+ */
10193 if (INTEL_INFO(dev
)->gen
< 4)
10194 PIPE_CONF_CHECK_I(gmch_pfit
.pgm_ratios
);
10195 PIPE_CONF_CHECK_I(gmch_pfit
.lvds_border_bits
);
10198 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
10199 if (current_config
->pch_pfit
.enabled
) {
10200 PIPE_CONF_CHECK_I(pch_pfit
.pos
);
10201 PIPE_CONF_CHECK_I(pch_pfit
.size
);
10204 /* BDW+ don't expose a synchronous way to read the state */
10205 if (IS_HASWELL(dev
))
10206 PIPE_CONF_CHECK_I(ips_enabled
);
10208 PIPE_CONF_CHECK_I(double_wide
);
10210 PIPE_CONF_CHECK_I(shared_dpll
);
10211 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
10212 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
10213 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
10214 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
10216 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
10217 PIPE_CONF_CHECK_I(pipe_bpp
);
10219 PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode
.crtc_clock
);
10220 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
10222 #undef PIPE_CONF_CHECK_X
10223 #undef PIPE_CONF_CHECK_I
10224 #undef PIPE_CONF_CHECK_FLAGS
10225 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
10226 #undef PIPE_CONF_QUIRK
10232 check_connector_state(struct drm_device
*dev
)
10234 struct intel_connector
*connector
;
10236 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10238 /* This also checks the encoder/connector hw state with the
10239 * ->get_hw_state callbacks. */
10240 intel_connector_check_state(connector
);
10242 WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
10243 "connector's staged encoder doesn't match current encoder\n");
10248 check_encoder_state(struct drm_device
*dev
)
10250 struct intel_encoder
*encoder
;
10251 struct intel_connector
*connector
;
10253 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10255 bool enabled
= false;
10256 bool active
= false;
10257 enum pipe pipe
, tracked_pipe
;
10259 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
10260 encoder
->base
.base
.id
,
10261 encoder
->base
.name
);
10263 WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
10264 "encoder's stage crtc doesn't match current crtc\n");
10265 WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
10266 "encoder's active_connectors set, but no crtc\n");
10268 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10270 if (connector
->base
.encoder
!= &encoder
->base
)
10273 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
10276 WARN(!!encoder
->base
.crtc
!= enabled
,
10277 "encoder's enabled state mismatch "
10278 "(expected %i, found %i)\n",
10279 !!encoder
->base
.crtc
, enabled
);
10280 WARN(active
&& !encoder
->base
.crtc
,
10281 "active encoder with no crtc\n");
10283 WARN(encoder
->connectors_active
!= active
,
10284 "encoder's computed active state doesn't match tracked active state "
10285 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
10287 active
= encoder
->get_hw_state(encoder
, &pipe
);
10288 WARN(active
!= encoder
->connectors_active
,
10289 "encoder's hw state doesn't match sw tracking "
10290 "(expected %i, found %i)\n",
10291 encoder
->connectors_active
, active
);
10293 if (!encoder
->base
.crtc
)
10296 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
10297 WARN(active
&& pipe
!= tracked_pipe
,
10298 "active encoder's pipe doesn't match"
10299 "(expected %i, found %i)\n",
10300 tracked_pipe
, pipe
);
10306 check_crtc_state(struct drm_device
*dev
)
10308 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10309 struct intel_crtc
*crtc
;
10310 struct intel_encoder
*encoder
;
10311 struct intel_crtc_config pipe_config
;
10313 for_each_intel_crtc(dev
, crtc
) {
10314 bool enabled
= false;
10315 bool active
= false;
10317 memset(&pipe_config
, 0, sizeof(pipe_config
));
10319 DRM_DEBUG_KMS("[CRTC:%d]\n",
10320 crtc
->base
.base
.id
);
10322 WARN(crtc
->active
&& !crtc
->base
.enabled
,
10323 "active crtc, but not enabled in sw tracking\n");
10325 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10327 if (encoder
->base
.crtc
!= &crtc
->base
)
10330 if (encoder
->connectors_active
)
10334 WARN(active
!= crtc
->active
,
10335 "crtc's computed active state doesn't match tracked active state "
10336 "(expected %i, found %i)\n", active
, crtc
->active
);
10337 WARN(enabled
!= crtc
->base
.enabled
,
10338 "crtc's computed enabled state doesn't match tracked enabled state "
10339 "(expected %i, found %i)\n", enabled
, crtc
->base
.enabled
);
10341 active
= dev_priv
->display
.get_pipe_config(crtc
,
10344 /* hw state is inconsistent with the pipe A quirk */
10345 if (crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
)
10346 active
= crtc
->active
;
10348 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10351 if (encoder
->base
.crtc
!= &crtc
->base
)
10353 if (encoder
->get_hw_state(encoder
, &pipe
))
10354 encoder
->get_config(encoder
, &pipe_config
);
10357 WARN(crtc
->active
!= active
,
10358 "crtc active state doesn't match with hw state "
10359 "(expected %i, found %i)\n", crtc
->active
, active
);
10362 !intel_pipe_config_compare(dev
, &crtc
->config
, &pipe_config
)) {
10363 WARN(1, "pipe state doesn't match!\n");
10364 intel_dump_pipe_config(crtc
, &pipe_config
,
10366 intel_dump_pipe_config(crtc
, &crtc
->config
,
10373 check_shared_dpll_state(struct drm_device
*dev
)
10375 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10376 struct intel_crtc
*crtc
;
10377 struct intel_dpll_hw_state dpll_hw_state
;
10380 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
10381 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
10382 int enabled_crtcs
= 0, active_crtcs
= 0;
10385 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
10387 DRM_DEBUG_KMS("%s\n", pll
->name
);
10389 active
= pll
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
10391 WARN(pll
->active
> pll
->refcount
,
10392 "more active pll users than references: %i vs %i\n",
10393 pll
->active
, pll
->refcount
);
10394 WARN(pll
->active
&& !pll
->on
,
10395 "pll in active use but not on in sw tracking\n");
10396 WARN(pll
->on
&& !pll
->active
,
10397 "pll in on but not on in use in sw tracking\n");
10398 WARN(pll
->on
!= active
,
10399 "pll on state mismatch (expected %i, found %i)\n",
10402 for_each_intel_crtc(dev
, crtc
) {
10403 if (crtc
->base
.enabled
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10405 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10408 WARN(pll
->active
!= active_crtcs
,
10409 "pll active crtcs mismatch (expected %i, found %i)\n",
10410 pll
->active
, active_crtcs
);
10411 WARN(pll
->refcount
!= enabled_crtcs
,
10412 "pll enabled crtcs mismatch (expected %i, found %i)\n",
10413 pll
->refcount
, enabled_crtcs
);
10415 WARN(pll
->on
&& memcmp(&pll
->hw_state
, &dpll_hw_state
,
10416 sizeof(dpll_hw_state
)),
10417 "pll hw state mismatch\n");
10422 intel_modeset_check_state(struct drm_device
*dev
)
10424 check_connector_state(dev
);
10425 check_encoder_state(dev
);
10426 check_crtc_state(dev
);
10427 check_shared_dpll_state(dev
);
10430 void ironlake_check_encoder_dotclock(const struct intel_crtc_config
*pipe_config
,
10434 * FDI already provided one idea for the dotclock.
10435 * Yell if the encoder disagrees.
10437 WARN(!intel_fuzzy_clock_check(pipe_config
->adjusted_mode
.crtc_clock
, dotclock
),
10438 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
10439 pipe_config
->adjusted_mode
.crtc_clock
, dotclock
);
10442 static void update_scanline_offset(struct intel_crtc
*crtc
)
10444 struct drm_device
*dev
= crtc
->base
.dev
;
10447 * The scanline counter increments at the leading edge of hsync.
10449 * On most platforms it starts counting from vtotal-1 on the
10450 * first active line. That means the scanline counter value is
10451 * always one less than what we would expect. Ie. just after
10452 * start of vblank, which also occurs at start of hsync (on the
10453 * last active line), the scanline counter will read vblank_start-1.
10455 * On gen2 the scanline counter starts counting from 1 instead
10456 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
10457 * to keep the value positive), instead of adding one.
10459 * On HSW+ the behaviour of the scanline counter depends on the output
10460 * type. For DP ports it behaves like most other platforms, but on HDMI
10461 * there's an extra 1 line difference. So we need to add two instead of
10462 * one to the value.
10464 if (IS_GEN2(dev
)) {
10465 const struct drm_display_mode
*mode
= &crtc
->config
.adjusted_mode
;
10468 vtotal
= mode
->crtc_vtotal
;
10469 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
10472 crtc
->scanline_offset
= vtotal
- 1;
10473 } else if (HAS_DDI(dev
) &&
10474 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
)) {
10475 crtc
->scanline_offset
= 2;
10477 crtc
->scanline_offset
= 1;
10480 static int __intel_set_mode(struct drm_crtc
*crtc
,
10481 struct drm_display_mode
*mode
,
10482 int x
, int y
, struct drm_framebuffer
*fb
)
10484 struct drm_device
*dev
= crtc
->dev
;
10485 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10486 struct drm_display_mode
*saved_mode
;
10487 struct intel_crtc_config
*pipe_config
= NULL
;
10488 struct intel_crtc
*intel_crtc
;
10489 unsigned disable_pipes
, prepare_pipes
, modeset_pipes
;
10492 saved_mode
= kmalloc(sizeof(*saved_mode
), GFP_KERNEL
);
10496 intel_modeset_affected_pipes(crtc
, &modeset_pipes
,
10497 &prepare_pipes
, &disable_pipes
);
10499 *saved_mode
= crtc
->mode
;
10501 /* Hack: Because we don't (yet) support global modeset on multiple
10502 * crtcs, we don't keep track of the new mode for more than one crtc.
10503 * Hence simply check whether any bit is set in modeset_pipes in all the
10504 * pieces of code that are not yet converted to deal with mutliple crtcs
10505 * changing their mode at the same time. */
10506 if (modeset_pipes
) {
10507 pipe_config
= intel_modeset_pipe_config(crtc
, fb
, mode
);
10508 if (IS_ERR(pipe_config
)) {
10509 ret
= PTR_ERR(pipe_config
);
10510 pipe_config
= NULL
;
10514 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
10516 to_intel_crtc(crtc
)->new_config
= pipe_config
;
10520 * See if the config requires any additional preparation, e.g.
10521 * to adjust global state with pipes off. We need to do this
10522 * here so we can get the modeset_pipe updated config for the new
10523 * mode set on this crtc. For other crtcs we need to use the
10524 * adjusted_mode bits in the crtc directly.
10526 if (IS_VALLEYVIEW(dev
)) {
10527 valleyview_modeset_global_pipes(dev
, &prepare_pipes
);
10529 /* may have added more to prepare_pipes than we should */
10530 prepare_pipes
&= ~disable_pipes
;
10533 for_each_intel_crtc_masked(dev
, disable_pipes
, intel_crtc
)
10534 intel_crtc_disable(&intel_crtc
->base
);
10536 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
10537 if (intel_crtc
->base
.enabled
)
10538 dev_priv
->display
.crtc_disable(&intel_crtc
->base
);
10541 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
10542 * to set it here already despite that we pass it down the callchain.
10544 if (modeset_pipes
) {
10545 crtc
->mode
= *mode
;
10546 /* mode_set/enable/disable functions rely on a correct pipe
10548 to_intel_crtc(crtc
)->config
= *pipe_config
;
10549 to_intel_crtc(crtc
)->new_config
= &to_intel_crtc(crtc
)->config
;
10552 * Calculate and store various constants which
10553 * are later needed by vblank and swap-completion
10554 * timestamping. They are derived from true hwmode.
10556 drm_calc_timestamping_constants(crtc
,
10557 &pipe_config
->adjusted_mode
);
10560 /* Only after disabling all output pipelines that will be changed can we
10561 * update the the output configuration. */
10562 intel_modeset_update_state(dev
, prepare_pipes
);
10564 if (dev_priv
->display
.modeset_global_resources
)
10565 dev_priv
->display
.modeset_global_resources(dev
);
10567 /* Set up the DPLL and any encoders state that needs to adjust or depend
10570 for_each_intel_crtc_masked(dev
, modeset_pipes
, intel_crtc
) {
10571 struct drm_framebuffer
*old_fb
;
10573 mutex_lock(&dev
->struct_mutex
);
10574 ret
= intel_pin_and_fence_fb_obj(dev
,
10575 to_intel_framebuffer(fb
)->obj
,
10578 DRM_ERROR("pin & fence failed\n");
10579 mutex_unlock(&dev
->struct_mutex
);
10582 old_fb
= crtc
->primary
->fb
;
10584 intel_unpin_fb_obj(to_intel_framebuffer(old_fb
)->obj
);
10585 mutex_unlock(&dev
->struct_mutex
);
10587 crtc
->primary
->fb
= fb
;
10591 ret
= dev_priv
->display
.crtc_mode_set(&intel_crtc
->base
,
10597 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
10598 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
10599 update_scanline_offset(intel_crtc
);
10601 dev_priv
->display
.crtc_enable(&intel_crtc
->base
);
10604 /* FIXME: add subpixel order */
10606 if (ret
&& crtc
->enabled
)
10607 crtc
->mode
= *saved_mode
;
10610 kfree(pipe_config
);
10615 static int intel_set_mode(struct drm_crtc
*crtc
,
10616 struct drm_display_mode
*mode
,
10617 int x
, int y
, struct drm_framebuffer
*fb
)
10621 ret
= __intel_set_mode(crtc
, mode
, x
, y
, fb
);
10624 intel_modeset_check_state(crtc
->dev
);
10629 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
10631 intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
, crtc
->primary
->fb
);
10634 #undef for_each_intel_crtc_masked
10636 static void intel_set_config_free(struct intel_set_config
*config
)
10641 kfree(config
->save_connector_encoders
);
10642 kfree(config
->save_encoder_crtcs
);
10643 kfree(config
->save_crtc_enabled
);
10647 static int intel_set_config_save_state(struct drm_device
*dev
,
10648 struct intel_set_config
*config
)
10650 struct drm_crtc
*crtc
;
10651 struct drm_encoder
*encoder
;
10652 struct drm_connector
*connector
;
10655 config
->save_crtc_enabled
=
10656 kcalloc(dev
->mode_config
.num_crtc
,
10657 sizeof(bool), GFP_KERNEL
);
10658 if (!config
->save_crtc_enabled
)
10661 config
->save_encoder_crtcs
=
10662 kcalloc(dev
->mode_config
.num_encoder
,
10663 sizeof(struct drm_crtc
*), GFP_KERNEL
);
10664 if (!config
->save_encoder_crtcs
)
10667 config
->save_connector_encoders
=
10668 kcalloc(dev
->mode_config
.num_connector
,
10669 sizeof(struct drm_encoder
*), GFP_KERNEL
);
10670 if (!config
->save_connector_encoders
)
10673 /* Copy data. Note that driver private data is not affected.
10674 * Should anything bad happen only the expected state is
10675 * restored, not the drivers personal bookkeeping.
10678 for_each_crtc(dev
, crtc
) {
10679 config
->save_crtc_enabled
[count
++] = crtc
->enabled
;
10683 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
10684 config
->save_encoder_crtcs
[count
++] = encoder
->crtc
;
10688 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
10689 config
->save_connector_encoders
[count
++] = connector
->encoder
;
10695 static void intel_set_config_restore_state(struct drm_device
*dev
,
10696 struct intel_set_config
*config
)
10698 struct intel_crtc
*crtc
;
10699 struct intel_encoder
*encoder
;
10700 struct intel_connector
*connector
;
10704 for_each_intel_crtc(dev
, crtc
) {
10705 crtc
->new_enabled
= config
->save_crtc_enabled
[count
++];
10707 if (crtc
->new_enabled
)
10708 crtc
->new_config
= &crtc
->config
;
10710 crtc
->new_config
= NULL
;
10714 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
10715 encoder
->new_crtc
=
10716 to_intel_crtc(config
->save_encoder_crtcs
[count
++]);
10720 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
10721 connector
->new_encoder
=
10722 to_intel_encoder(config
->save_connector_encoders
[count
++]);
10727 is_crtc_connector_off(struct drm_mode_set
*set
)
10731 if (set
->num_connectors
== 0)
10734 if (WARN_ON(set
->connectors
== NULL
))
10737 for (i
= 0; i
< set
->num_connectors
; i
++)
10738 if (set
->connectors
[i
]->encoder
&&
10739 set
->connectors
[i
]->encoder
->crtc
== set
->crtc
&&
10740 set
->connectors
[i
]->dpms
!= DRM_MODE_DPMS_ON
)
10747 intel_set_config_compute_mode_changes(struct drm_mode_set
*set
,
10748 struct intel_set_config
*config
)
10751 /* We should be able to check here if the fb has the same properties
10752 * and then just flip_or_move it */
10753 if (is_crtc_connector_off(set
)) {
10754 config
->mode_changed
= true;
10755 } else if (set
->crtc
->primary
->fb
!= set
->fb
) {
10757 * If we have no fb, we can only flip as long as the crtc is
10758 * active, otherwise we need a full mode set. The crtc may
10759 * be active if we've only disabled the primary plane, or
10760 * in fastboot situations.
10762 if (set
->crtc
->primary
->fb
== NULL
) {
10763 struct intel_crtc
*intel_crtc
=
10764 to_intel_crtc(set
->crtc
);
10766 if (intel_crtc
->active
) {
10767 DRM_DEBUG_KMS("crtc has no fb, will flip\n");
10768 config
->fb_changed
= true;
10770 DRM_DEBUG_KMS("inactive crtc, full mode set\n");
10771 config
->mode_changed
= true;
10773 } else if (set
->fb
== NULL
) {
10774 config
->mode_changed
= true;
10775 } else if (set
->fb
->pixel_format
!=
10776 set
->crtc
->primary
->fb
->pixel_format
) {
10777 config
->mode_changed
= true;
10779 config
->fb_changed
= true;
10783 if (set
->fb
&& (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
))
10784 config
->fb_changed
= true;
10786 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
10787 DRM_DEBUG_KMS("modes are different, full mode set\n");
10788 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
10789 drm_mode_debug_printmodeline(set
->mode
);
10790 config
->mode_changed
= true;
10793 DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
10794 set
->crtc
->base
.id
, config
->mode_changed
, config
->fb_changed
);
10798 intel_modeset_stage_output_state(struct drm_device
*dev
,
10799 struct drm_mode_set
*set
,
10800 struct intel_set_config
*config
)
10802 struct intel_connector
*connector
;
10803 struct intel_encoder
*encoder
;
10804 struct intel_crtc
*crtc
;
10807 /* The upper layers ensure that we either disable a crtc or have a list
10808 * of connectors. For paranoia, double-check this. */
10809 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
10810 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
10812 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10814 /* Otherwise traverse passed in connector list and get encoders
10816 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
10817 if (set
->connectors
[ro
] == &connector
->base
) {
10818 connector
->new_encoder
= connector
->encoder
;
10823 /* If we disable the crtc, disable all its connectors. Also, if
10824 * the connector is on the changing crtc but not on the new
10825 * connector list, disable it. */
10826 if ((!set
->fb
|| ro
== set
->num_connectors
) &&
10827 connector
->base
.encoder
&&
10828 connector
->base
.encoder
->crtc
== set
->crtc
) {
10829 connector
->new_encoder
= NULL
;
10831 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
10832 connector
->base
.base
.id
,
10833 connector
->base
.name
);
10837 if (&connector
->new_encoder
->base
!= connector
->base
.encoder
) {
10838 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
10839 config
->mode_changed
= true;
10842 /* connector->new_encoder is now updated for all connectors. */
10844 /* Update crtc of enabled connectors. */
10845 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10847 struct drm_crtc
*new_crtc
;
10849 if (!connector
->new_encoder
)
10852 new_crtc
= connector
->new_encoder
->base
.crtc
;
10854 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
10855 if (set
->connectors
[ro
] == &connector
->base
)
10856 new_crtc
= set
->crtc
;
10859 /* Make sure the new CRTC will work with the encoder */
10860 if (!drm_encoder_crtc_ok(&connector
->new_encoder
->base
,
10864 connector
->encoder
->new_crtc
= to_intel_crtc(new_crtc
);
10866 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
10867 connector
->base
.base
.id
,
10868 connector
->base
.name
,
10869 new_crtc
->base
.id
);
10872 /* Check for any encoders that needs to be disabled. */
10873 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
10875 int num_connectors
= 0;
10876 list_for_each_entry(connector
,
10877 &dev
->mode_config
.connector_list
,
10879 if (connector
->new_encoder
== encoder
) {
10880 WARN_ON(!connector
->new_encoder
->new_crtc
);
10885 if (num_connectors
== 0)
10886 encoder
->new_crtc
= NULL
;
10887 else if (num_connectors
> 1)
10890 /* Only now check for crtc changes so we don't miss encoders
10891 * that will be disabled. */
10892 if (&encoder
->new_crtc
->base
!= encoder
->base
.crtc
) {
10893 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
10894 config
->mode_changed
= true;
10897 /* Now we've also updated encoder->new_crtc for all encoders. */
10899 for_each_intel_crtc(dev
, crtc
) {
10900 crtc
->new_enabled
= false;
10902 list_for_each_entry(encoder
,
10903 &dev
->mode_config
.encoder_list
,
10905 if (encoder
->new_crtc
== crtc
) {
10906 crtc
->new_enabled
= true;
10911 if (crtc
->new_enabled
!= crtc
->base
.enabled
) {
10912 DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
10913 crtc
->new_enabled
? "en" : "dis");
10914 config
->mode_changed
= true;
10917 if (crtc
->new_enabled
)
10918 crtc
->new_config
= &crtc
->config
;
10920 crtc
->new_config
= NULL
;
10926 static void disable_crtc_nofb(struct intel_crtc
*crtc
)
10928 struct drm_device
*dev
= crtc
->base
.dev
;
10929 struct intel_encoder
*encoder
;
10930 struct intel_connector
*connector
;
10932 DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
10933 pipe_name(crtc
->pipe
));
10935 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
10936 if (connector
->new_encoder
&&
10937 connector
->new_encoder
->new_crtc
== crtc
)
10938 connector
->new_encoder
= NULL
;
10941 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
10942 if (encoder
->new_crtc
== crtc
)
10943 encoder
->new_crtc
= NULL
;
10946 crtc
->new_enabled
= false;
10947 crtc
->new_config
= NULL
;
10950 static int intel_crtc_set_config(struct drm_mode_set
*set
)
10952 struct drm_device
*dev
;
10953 struct drm_mode_set save_set
;
10954 struct intel_set_config
*config
;
10958 BUG_ON(!set
->crtc
);
10959 BUG_ON(!set
->crtc
->helper_private
);
10961 /* Enforce sane interface api - has been abused by the fb helper. */
10962 BUG_ON(!set
->mode
&& set
->fb
);
10963 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
10966 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
10967 set
->crtc
->base
.id
, set
->fb
->base
.id
,
10968 (int)set
->num_connectors
, set
->x
, set
->y
);
10970 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
10973 dev
= set
->crtc
->dev
;
10976 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
10980 ret
= intel_set_config_save_state(dev
, config
);
10984 save_set
.crtc
= set
->crtc
;
10985 save_set
.mode
= &set
->crtc
->mode
;
10986 save_set
.x
= set
->crtc
->x
;
10987 save_set
.y
= set
->crtc
->y
;
10988 save_set
.fb
= set
->crtc
->primary
->fb
;
10990 /* Compute whether we need a full modeset, only an fb base update or no
10991 * change at all. In the future we might also check whether only the
10992 * mode changed, e.g. for LVDS where we only change the panel fitter in
10994 intel_set_config_compute_mode_changes(set
, config
);
10996 ret
= intel_modeset_stage_output_state(dev
, set
, config
);
11000 if (config
->mode_changed
) {
11001 ret
= intel_set_mode(set
->crtc
, set
->mode
,
11002 set
->x
, set
->y
, set
->fb
);
11003 } else if (config
->fb_changed
) {
11004 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11005 struct intel_crtc
*intel_crtc
= to_intel_crtc(set
->crtc
);
11007 intel_crtc_wait_for_pending_flips(set
->crtc
);
11009 ret
= intel_pipe_set_base(set
->crtc
,
11010 set
->x
, set
->y
, set
->fb
);
11013 * We need to make sure the primary plane is re-enabled if it
11014 * has previously been turned off.
11016 if (!intel_crtc
->primary_enabled
&& ret
== 0) {
11017 WARN_ON(!intel_crtc
->active
);
11018 intel_enable_primary_hw_plane(dev_priv
, intel_crtc
->plane
,
11023 * In the fastboot case this may be our only check of the
11024 * state after boot. It would be better to only do it on
11025 * the first update, but we don't have a nice way of doing that
11026 * (and really, set_config isn't used much for high freq page
11027 * flipping, so increasing its cost here shouldn't be a big
11030 if (i915
.fastboot
&& ret
== 0)
11031 intel_modeset_check_state(set
->crtc
->dev
);
11035 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
11036 set
->crtc
->base
.id
, ret
);
11038 intel_set_config_restore_state(dev
, config
);
11041 * HACK: if the pipe was on, but we didn't have a framebuffer,
11042 * force the pipe off to avoid oopsing in the modeset code
11043 * due to fb==NULL. This should only happen during boot since
11044 * we don't yet reconstruct the FB from the hardware state.
11046 if (to_intel_crtc(save_set
.crtc
)->new_enabled
&& !save_set
.fb
)
11047 disable_crtc_nofb(to_intel_crtc(save_set
.crtc
));
11049 /* Try to restore the config */
11050 if (config
->mode_changed
&&
11051 intel_set_mode(save_set
.crtc
, save_set
.mode
,
11052 save_set
.x
, save_set
.y
, save_set
.fb
))
11053 DRM_ERROR("failed to restore config after modeset failure\n");
11057 intel_set_config_free(config
);
11061 static const struct drm_crtc_funcs intel_crtc_funcs
= {
11062 .gamma_set
= intel_crtc_gamma_set
,
11063 .set_config
= intel_crtc_set_config
,
11064 .destroy
= intel_crtc_destroy
,
11065 .page_flip
= intel_crtc_page_flip
,
11068 static void intel_cpu_pll_init(struct drm_device
*dev
)
11071 intel_ddi_pll_init(dev
);
11074 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private
*dev_priv
,
11075 struct intel_shared_dpll
*pll
,
11076 struct intel_dpll_hw_state
*hw_state
)
11080 val
= I915_READ(PCH_DPLL(pll
->id
));
11081 hw_state
->dpll
= val
;
11082 hw_state
->fp0
= I915_READ(PCH_FP0(pll
->id
));
11083 hw_state
->fp1
= I915_READ(PCH_FP1(pll
->id
));
11085 return val
& DPLL_VCO_ENABLE
;
11088 static void ibx_pch_dpll_mode_set(struct drm_i915_private
*dev_priv
,
11089 struct intel_shared_dpll
*pll
)
11091 I915_WRITE(PCH_FP0(pll
->id
), pll
->hw_state
.fp0
);
11092 I915_WRITE(PCH_FP1(pll
->id
), pll
->hw_state
.fp1
);
11095 static void ibx_pch_dpll_enable(struct drm_i915_private
*dev_priv
,
11096 struct intel_shared_dpll
*pll
)
11098 /* PCH refclock must be enabled first */
11099 ibx_assert_pch_refclk_enabled(dev_priv
);
11101 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11103 /* Wait for the clocks to stabilize. */
11104 POSTING_READ(PCH_DPLL(pll
->id
));
11107 /* The pixel multiplier can only be updated once the
11108 * DPLL is enabled and the clocks are stable.
11110 * So write it again.
11112 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11113 POSTING_READ(PCH_DPLL(pll
->id
));
11117 static void ibx_pch_dpll_disable(struct drm_i915_private
*dev_priv
,
11118 struct intel_shared_dpll
*pll
)
11120 struct drm_device
*dev
= dev_priv
->dev
;
11121 struct intel_crtc
*crtc
;
11123 /* Make sure no transcoder isn't still depending on us. */
11124 for_each_intel_crtc(dev
, crtc
) {
11125 if (intel_crtc_to_shared_dpll(crtc
) == pll
)
11126 assert_pch_transcoder_disabled(dev_priv
, crtc
->pipe
);
11129 I915_WRITE(PCH_DPLL(pll
->id
), 0);
11130 POSTING_READ(PCH_DPLL(pll
->id
));
11134 static char *ibx_pch_dpll_names
[] = {
11139 static void ibx_pch_dpll_init(struct drm_device
*dev
)
11141 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11144 dev_priv
->num_shared_dpll
= 2;
11146 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
11147 dev_priv
->shared_dplls
[i
].id
= i
;
11148 dev_priv
->shared_dplls
[i
].name
= ibx_pch_dpll_names
[i
];
11149 dev_priv
->shared_dplls
[i
].mode_set
= ibx_pch_dpll_mode_set
;
11150 dev_priv
->shared_dplls
[i
].enable
= ibx_pch_dpll_enable
;
11151 dev_priv
->shared_dplls
[i
].disable
= ibx_pch_dpll_disable
;
11152 dev_priv
->shared_dplls
[i
].get_hw_state
=
11153 ibx_pch_dpll_get_hw_state
;
11157 static void intel_shared_dpll_init(struct drm_device
*dev
)
11159 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11161 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
11162 ibx_pch_dpll_init(dev
);
11164 dev_priv
->num_shared_dpll
= 0;
11166 BUG_ON(dev_priv
->num_shared_dpll
> I915_NUM_PLLS
);
11170 intel_primary_plane_disable(struct drm_plane
*plane
)
11172 struct drm_device
*dev
= plane
->dev
;
11173 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11174 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11175 struct intel_crtc
*intel_crtc
;
11180 BUG_ON(!plane
->crtc
);
11182 intel_crtc
= to_intel_crtc(plane
->crtc
);
11185 * Even though we checked plane->fb above, it's still possible that
11186 * the primary plane has been implicitly disabled because the crtc
11187 * coordinates given weren't visible, or because we detected
11188 * that it was 100% covered by a sprite plane. Or, the CRTC may be
11189 * off and we've set a fb, but haven't actually turned on the CRTC yet.
11190 * In either case, we need to unpin the FB and let the fb pointer get
11191 * updated, but otherwise we don't need to touch the hardware.
11193 if (!intel_crtc
->primary_enabled
)
11194 goto disable_unpin
;
11196 intel_crtc_wait_for_pending_flips(plane
->crtc
);
11197 intel_disable_primary_hw_plane(dev_priv
, intel_plane
->plane
,
11198 intel_plane
->pipe
);
11201 intel_unpin_fb_obj(to_intel_framebuffer(plane
->fb
)->obj
);
11208 intel_primary_plane_setplane(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11209 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11210 unsigned int crtc_w
, unsigned int crtc_h
,
11211 uint32_t src_x
, uint32_t src_y
,
11212 uint32_t src_w
, uint32_t src_h
)
11214 struct drm_device
*dev
= crtc
->dev
;
11215 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11216 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11217 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11218 struct drm_rect dest
= {
11219 /* integer pixels */
11222 .x2
= crtc_x
+ crtc_w
,
11223 .y2
= crtc_y
+ crtc_h
,
11225 struct drm_rect src
= {
11226 /* 16.16 fixed point */
11229 .x2
= src_x
+ src_w
,
11230 .y2
= src_y
+ src_h
,
11232 const struct drm_rect clip
= {
11233 /* integer pixels */
11234 .x2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_w
: 0,
11235 .y2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_h
: 0,
11240 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
11241 &src
, &dest
, &clip
,
11242 DRM_PLANE_HELPER_NO_SCALING
,
11243 DRM_PLANE_HELPER_NO_SCALING
,
11244 false, true, &visible
);
11250 * If the CRTC isn't enabled, we're just pinning the framebuffer,
11251 * updating the fb pointer, and returning without touching the
11252 * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
11253 * turn on the display with all planes setup as desired.
11255 if (!crtc
->enabled
) {
11257 * If we already called setplane while the crtc was disabled,
11258 * we may have an fb pinned; unpin it.
11261 intel_unpin_fb_obj(to_intel_framebuffer(plane
->fb
)->obj
);
11263 /* Pin and return without programming hardware */
11264 return intel_pin_and_fence_fb_obj(dev
,
11265 to_intel_framebuffer(fb
)->obj
,
11269 intel_crtc_wait_for_pending_flips(crtc
);
11272 * If clipping results in a non-visible primary plane, we'll disable
11273 * the primary plane. Note that this is a bit different than what
11274 * happens if userspace explicitly disables the plane by passing fb=0
11275 * because plane->fb still gets set and pinned.
11279 * Try to pin the new fb first so that we can bail out if we
11282 if (plane
->fb
!= fb
) {
11283 ret
= intel_pin_and_fence_fb_obj(dev
,
11284 to_intel_framebuffer(fb
)->obj
,
11290 if (intel_crtc
->primary_enabled
)
11291 intel_disable_primary_hw_plane(dev_priv
,
11292 intel_plane
->plane
,
11293 intel_plane
->pipe
);
11296 if (plane
->fb
!= fb
)
11298 intel_unpin_fb_obj(to_intel_framebuffer(plane
->fb
)->obj
);
11303 ret
= intel_pipe_set_base(crtc
, src
.x1
, src
.y1
, fb
);
11307 if (!intel_crtc
->primary_enabled
)
11308 intel_enable_primary_hw_plane(dev_priv
, intel_crtc
->plane
,
11314 /* Common destruction function for both primary and cursor planes */
11315 static void intel_plane_destroy(struct drm_plane
*plane
)
11317 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11318 drm_plane_cleanup(plane
);
11319 kfree(intel_plane
);
11322 static const struct drm_plane_funcs intel_primary_plane_funcs
= {
11323 .update_plane
= intel_primary_plane_setplane
,
11324 .disable_plane
= intel_primary_plane_disable
,
11325 .destroy
= intel_plane_destroy
,
11328 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
11331 struct intel_plane
*primary
;
11332 const uint32_t *intel_primary_formats
;
11335 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
11336 if (primary
== NULL
)
11339 primary
->can_scale
= false;
11340 primary
->max_downscale
= 1;
11341 primary
->pipe
= pipe
;
11342 primary
->plane
= pipe
;
11343 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
11344 primary
->plane
= !pipe
;
11346 if (INTEL_INFO(dev
)->gen
<= 3) {
11347 intel_primary_formats
= intel_primary_formats_gen2
;
11348 num_formats
= ARRAY_SIZE(intel_primary_formats_gen2
);
11350 intel_primary_formats
= intel_primary_formats_gen4
;
11351 num_formats
= ARRAY_SIZE(intel_primary_formats_gen4
);
11354 drm_universal_plane_init(dev
, &primary
->base
, 0,
11355 &intel_primary_plane_funcs
,
11356 intel_primary_formats
, num_formats
,
11357 DRM_PLANE_TYPE_PRIMARY
);
11358 return &primary
->base
;
11362 intel_cursor_plane_disable(struct drm_plane
*plane
)
11367 BUG_ON(!plane
->crtc
);
11369 return intel_crtc_cursor_set_obj(plane
->crtc
, NULL
, 0, 0);
11373 intel_cursor_plane_update(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11374 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11375 unsigned int crtc_w
, unsigned int crtc_h
,
11376 uint32_t src_x
, uint32_t src_y
,
11377 uint32_t src_w
, uint32_t src_h
)
11379 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11380 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11381 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11382 struct drm_rect dest
= {
11383 /* integer pixels */
11386 .x2
= crtc_x
+ crtc_w
,
11387 .y2
= crtc_y
+ crtc_h
,
11389 struct drm_rect src
= {
11390 /* 16.16 fixed point */
11393 .x2
= src_x
+ src_w
,
11394 .y2
= src_y
+ src_h
,
11396 const struct drm_rect clip
= {
11397 /* integer pixels */
11398 .x2
= intel_crtc
->config
.pipe_src_w
,
11399 .y2
= intel_crtc
->config
.pipe_src_h
,
11404 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
11405 &src
, &dest
, &clip
,
11406 DRM_PLANE_HELPER_NO_SCALING
,
11407 DRM_PLANE_HELPER_NO_SCALING
,
11408 true, true, &visible
);
11412 crtc
->cursor_x
= crtc_x
;
11413 crtc
->cursor_y
= crtc_y
;
11414 if (fb
!= crtc
->cursor
->fb
) {
11415 return intel_crtc_cursor_set_obj(crtc
, obj
, crtc_w
, crtc_h
);
11417 intel_crtc_update_cursor(crtc
, visible
);
11421 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
11422 .update_plane
= intel_cursor_plane_update
,
11423 .disable_plane
= intel_cursor_plane_disable
,
11424 .destroy
= intel_plane_destroy
,
11427 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
11430 struct intel_plane
*cursor
;
11432 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
11433 if (cursor
== NULL
)
11436 cursor
->can_scale
= false;
11437 cursor
->max_downscale
= 1;
11438 cursor
->pipe
= pipe
;
11439 cursor
->plane
= pipe
;
11441 drm_universal_plane_init(dev
, &cursor
->base
, 0,
11442 &intel_cursor_plane_funcs
,
11443 intel_cursor_formats
,
11444 ARRAY_SIZE(intel_cursor_formats
),
11445 DRM_PLANE_TYPE_CURSOR
);
11446 return &cursor
->base
;
11449 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
11451 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11452 struct intel_crtc
*intel_crtc
;
11453 struct drm_plane
*primary
= NULL
;
11454 struct drm_plane
*cursor
= NULL
;
11457 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
11458 if (intel_crtc
== NULL
)
11461 primary
= intel_primary_plane_create(dev
, pipe
);
11465 cursor
= intel_cursor_plane_create(dev
, pipe
);
11469 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
11470 cursor
, &intel_crtc_funcs
);
11474 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
11475 for (i
= 0; i
< 256; i
++) {
11476 intel_crtc
->lut_r
[i
] = i
;
11477 intel_crtc
->lut_g
[i
] = i
;
11478 intel_crtc
->lut_b
[i
] = i
;
11482 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
11483 * is hooked to pipe B. Hence we want plane A feeding pipe B.
11485 intel_crtc
->pipe
= pipe
;
11486 intel_crtc
->plane
= pipe
;
11487 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
11488 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
11489 intel_crtc
->plane
= !pipe
;
11492 intel_crtc
->cursor_base
= ~0;
11493 intel_crtc
->cursor_cntl
= ~0;
11495 init_waitqueue_head(&intel_crtc
->vbl_wait
);
11497 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
11498 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
11499 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
11500 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
11502 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
11504 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
11509 drm_plane_cleanup(primary
);
11511 drm_plane_cleanup(cursor
);
11515 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
11517 struct drm_encoder
*encoder
= connector
->base
.encoder
;
11518 struct drm_device
*dev
= connector
->base
.dev
;
11520 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
11523 return INVALID_PIPE
;
11525 return to_intel_crtc(encoder
->crtc
)->pipe
;
11528 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
11529 struct drm_file
*file
)
11531 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
11532 struct drm_mode_object
*drmmode_obj
;
11533 struct intel_crtc
*crtc
;
11535 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
11538 drmmode_obj
= drm_mode_object_find(dev
, pipe_from_crtc_id
->crtc_id
,
11539 DRM_MODE_OBJECT_CRTC
);
11541 if (!drmmode_obj
) {
11542 DRM_ERROR("no such CRTC id\n");
11546 crtc
= to_intel_crtc(obj_to_crtc(drmmode_obj
));
11547 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
11552 static int intel_encoder_clones(struct intel_encoder
*encoder
)
11554 struct drm_device
*dev
= encoder
->base
.dev
;
11555 struct intel_encoder
*source_encoder
;
11556 int index_mask
= 0;
11559 list_for_each_entry(source_encoder
,
11560 &dev
->mode_config
.encoder_list
, base
.head
) {
11561 if (encoders_cloneable(encoder
, source_encoder
))
11562 index_mask
|= (1 << entry
);
11570 static bool has_edp_a(struct drm_device
*dev
)
11572 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11574 if (!IS_MOBILE(dev
))
11577 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
11580 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
11586 const char *intel_output_name(int output
)
11588 static const char *names
[] = {
11589 [INTEL_OUTPUT_UNUSED
] = "Unused",
11590 [INTEL_OUTPUT_ANALOG
] = "Analog",
11591 [INTEL_OUTPUT_DVO
] = "DVO",
11592 [INTEL_OUTPUT_SDVO
] = "SDVO",
11593 [INTEL_OUTPUT_LVDS
] = "LVDS",
11594 [INTEL_OUTPUT_TVOUT
] = "TV",
11595 [INTEL_OUTPUT_HDMI
] = "HDMI",
11596 [INTEL_OUTPUT_DISPLAYPORT
] = "DisplayPort",
11597 [INTEL_OUTPUT_EDP
] = "eDP",
11598 [INTEL_OUTPUT_DSI
] = "DSI",
11599 [INTEL_OUTPUT_UNKNOWN
] = "Unknown",
11602 if (output
< 0 || output
>= ARRAY_SIZE(names
) || !names
[output
])
11605 return names
[output
];
11608 static void intel_setup_outputs(struct drm_device
*dev
)
11610 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11611 struct intel_encoder
*encoder
;
11612 bool dpd_is_edp
= false;
11614 intel_lvds_init(dev
);
11616 if (!IS_ULT(dev
) && !IS_CHERRYVIEW(dev
) && dev_priv
->vbt
.int_crt_support
)
11617 intel_crt_init(dev
);
11619 if (HAS_DDI(dev
)) {
11622 /* Haswell uses DDI functions to detect digital outputs */
11623 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
11624 /* DDI A only supports eDP */
11626 intel_ddi_init(dev
, PORT_A
);
11628 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
11630 found
= I915_READ(SFUSE_STRAP
);
11632 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
11633 intel_ddi_init(dev
, PORT_B
);
11634 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
11635 intel_ddi_init(dev
, PORT_C
);
11636 if (found
& SFUSE_STRAP_DDID_DETECTED
)
11637 intel_ddi_init(dev
, PORT_D
);
11638 } else if (HAS_PCH_SPLIT(dev
)) {
11640 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
11642 if (has_edp_a(dev
))
11643 intel_dp_init(dev
, DP_A
, PORT_A
);
11645 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
11646 /* PCH SDVOB multiplex with HDMIB */
11647 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
11649 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
11650 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
11651 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
11654 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
11655 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
11657 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
11658 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
11660 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
11661 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
11663 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
11664 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
11665 } else if (IS_VALLEYVIEW(dev
)) {
11666 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
) {
11667 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
11669 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
)
11670 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
11673 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIC
) & SDVO_DETECTED
) {
11674 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIC
,
11676 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
)
11677 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
11680 if (IS_CHERRYVIEW(dev
)) {
11681 if (I915_READ(VLV_DISPLAY_BASE
+ CHV_HDMID
) & SDVO_DETECTED
) {
11682 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ CHV_HDMID
,
11684 if (I915_READ(VLV_DISPLAY_BASE
+ DP_D
) & DP_DETECTED
)
11685 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_D
, PORT_D
);
11689 intel_dsi_init(dev
);
11690 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
11691 bool found
= false;
11693 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
11694 DRM_DEBUG_KMS("probing SDVOB\n");
11695 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
11696 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
11697 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
11698 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
11701 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
))
11702 intel_dp_init(dev
, DP_B
, PORT_B
);
11705 /* Before G4X SDVOC doesn't have its own detect register */
11707 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
11708 DRM_DEBUG_KMS("probing SDVOC\n");
11709 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
11712 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
11714 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
11715 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
11716 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
11718 if (SUPPORTS_INTEGRATED_DP(dev
))
11719 intel_dp_init(dev
, DP_C
, PORT_C
);
11722 if (SUPPORTS_INTEGRATED_DP(dev
) &&
11723 (I915_READ(DP_D
) & DP_DETECTED
))
11724 intel_dp_init(dev
, DP_D
, PORT_D
);
11725 } else if (IS_GEN2(dev
))
11726 intel_dvo_init(dev
);
11728 if (SUPPORTS_TV(dev
))
11729 intel_tv_init(dev
);
11731 intel_edp_psr_init(dev
);
11733 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
11734 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
11735 encoder
->base
.possible_clones
=
11736 intel_encoder_clones(encoder
);
11739 intel_init_pch_refclk(dev
);
11741 drm_helper_move_panel_connectors_to_head(dev
);
11744 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
11746 struct drm_device
*dev
= fb
->dev
;
11747 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11749 drm_framebuffer_cleanup(fb
);
11750 mutex_lock(&dev
->struct_mutex
);
11751 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
11752 drm_gem_object_unreference(&intel_fb
->obj
->base
);
11753 mutex_unlock(&dev
->struct_mutex
);
11757 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
11758 struct drm_file
*file
,
11759 unsigned int *handle
)
11761 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11762 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11764 return drm_gem_handle_create(file
, &obj
->base
, handle
);
11767 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
11768 .destroy
= intel_user_framebuffer_destroy
,
11769 .create_handle
= intel_user_framebuffer_create_handle
,
11772 static int intel_framebuffer_init(struct drm_device
*dev
,
11773 struct intel_framebuffer
*intel_fb
,
11774 struct drm_mode_fb_cmd2
*mode_cmd
,
11775 struct drm_i915_gem_object
*obj
)
11777 int aligned_height
;
11781 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
11783 if (obj
->tiling_mode
== I915_TILING_Y
) {
11784 DRM_DEBUG("hardware does not support tiling Y\n");
11788 if (mode_cmd
->pitches
[0] & 63) {
11789 DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
11790 mode_cmd
->pitches
[0]);
11794 if (INTEL_INFO(dev
)->gen
>= 5 && !IS_VALLEYVIEW(dev
)) {
11795 pitch_limit
= 32*1024;
11796 } else if (INTEL_INFO(dev
)->gen
>= 4) {
11797 if (obj
->tiling_mode
)
11798 pitch_limit
= 16*1024;
11800 pitch_limit
= 32*1024;
11801 } else if (INTEL_INFO(dev
)->gen
>= 3) {
11802 if (obj
->tiling_mode
)
11803 pitch_limit
= 8*1024;
11805 pitch_limit
= 16*1024;
11807 /* XXX DSPC is limited to 4k tiled */
11808 pitch_limit
= 8*1024;
11810 if (mode_cmd
->pitches
[0] > pitch_limit
) {
11811 DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
11812 obj
->tiling_mode
? "tiled" : "linear",
11813 mode_cmd
->pitches
[0], pitch_limit
);
11817 if (obj
->tiling_mode
!= I915_TILING_NONE
&&
11818 mode_cmd
->pitches
[0] != obj
->stride
) {
11819 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
11820 mode_cmd
->pitches
[0], obj
->stride
);
11824 /* Reject formats not supported by any plane early. */
11825 switch (mode_cmd
->pixel_format
) {
11826 case DRM_FORMAT_C8
:
11827 case DRM_FORMAT_RGB565
:
11828 case DRM_FORMAT_XRGB8888
:
11829 case DRM_FORMAT_ARGB8888
:
11831 case DRM_FORMAT_XRGB1555
:
11832 case DRM_FORMAT_ARGB1555
:
11833 if (INTEL_INFO(dev
)->gen
> 3) {
11834 DRM_DEBUG("unsupported pixel format: %s\n",
11835 drm_get_format_name(mode_cmd
->pixel_format
));
11839 case DRM_FORMAT_XBGR8888
:
11840 case DRM_FORMAT_ABGR8888
:
11841 case DRM_FORMAT_XRGB2101010
:
11842 case DRM_FORMAT_ARGB2101010
:
11843 case DRM_FORMAT_XBGR2101010
:
11844 case DRM_FORMAT_ABGR2101010
:
11845 if (INTEL_INFO(dev
)->gen
< 4) {
11846 DRM_DEBUG("unsupported pixel format: %s\n",
11847 drm_get_format_name(mode_cmd
->pixel_format
));
11851 case DRM_FORMAT_YUYV
:
11852 case DRM_FORMAT_UYVY
:
11853 case DRM_FORMAT_YVYU
:
11854 case DRM_FORMAT_VYUY
:
11855 if (INTEL_INFO(dev
)->gen
< 5) {
11856 DRM_DEBUG("unsupported pixel format: %s\n",
11857 drm_get_format_name(mode_cmd
->pixel_format
));
11862 DRM_DEBUG("unsupported pixel format: %s\n",
11863 drm_get_format_name(mode_cmd
->pixel_format
));
11867 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
11868 if (mode_cmd
->offsets
[0] != 0)
11871 aligned_height
= intel_align_height(dev
, mode_cmd
->height
,
11873 /* FIXME drm helper for size checks (especially planar formats)? */
11874 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
11877 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
11878 intel_fb
->obj
= obj
;
11879 intel_fb
->obj
->framebuffer_references
++;
11881 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
11883 DRM_ERROR("framebuffer init failed %d\n", ret
);
11890 static struct drm_framebuffer
*
11891 intel_user_framebuffer_create(struct drm_device
*dev
,
11892 struct drm_file
*filp
,
11893 struct drm_mode_fb_cmd2
*mode_cmd
)
11895 struct drm_i915_gem_object
*obj
;
11897 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
11898 mode_cmd
->handles
[0]));
11899 if (&obj
->base
== NULL
)
11900 return ERR_PTR(-ENOENT
);
11902 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
11905 #ifndef CONFIG_DRM_I915_FBDEV
11906 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
11911 static const struct drm_mode_config_funcs intel_mode_funcs
= {
11912 .fb_create
= intel_user_framebuffer_create
,
11913 .output_poll_changed
= intel_fbdev_output_poll_changed
,
11916 /* Set up chip specific display functions */
11917 static void intel_init_display(struct drm_device
*dev
)
11919 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11921 if (HAS_PCH_SPLIT(dev
) || IS_G4X(dev
))
11922 dev_priv
->display
.find_dpll
= g4x_find_best_dpll
;
11923 else if (IS_CHERRYVIEW(dev
))
11924 dev_priv
->display
.find_dpll
= chv_find_best_dpll
;
11925 else if (IS_VALLEYVIEW(dev
))
11926 dev_priv
->display
.find_dpll
= vlv_find_best_dpll
;
11927 else if (IS_PINEVIEW(dev
))
11928 dev_priv
->display
.find_dpll
= pnv_find_best_dpll
;
11930 dev_priv
->display
.find_dpll
= i9xx_find_best_dpll
;
11932 if (HAS_DDI(dev
)) {
11933 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
11934 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
11935 dev_priv
->display
.crtc_mode_set
= haswell_crtc_mode_set
;
11936 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
11937 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
11938 dev_priv
->display
.off
= haswell_crtc_off
;
11939 dev_priv
->display
.update_primary_plane
=
11940 ironlake_update_primary_plane
;
11941 } else if (HAS_PCH_SPLIT(dev
)) {
11942 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
11943 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
11944 dev_priv
->display
.crtc_mode_set
= ironlake_crtc_mode_set
;
11945 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
11946 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
11947 dev_priv
->display
.off
= ironlake_crtc_off
;
11948 dev_priv
->display
.update_primary_plane
=
11949 ironlake_update_primary_plane
;
11950 } else if (IS_VALLEYVIEW(dev
)) {
11951 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
11952 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
11953 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
11954 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
11955 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
11956 dev_priv
->display
.off
= i9xx_crtc_off
;
11957 dev_priv
->display
.update_primary_plane
=
11958 i9xx_update_primary_plane
;
11960 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
11961 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
11962 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
11963 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
11964 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
11965 dev_priv
->display
.off
= i9xx_crtc_off
;
11966 dev_priv
->display
.update_primary_plane
=
11967 i9xx_update_primary_plane
;
11970 /* Returns the core display clock speed */
11971 if (IS_VALLEYVIEW(dev
))
11972 dev_priv
->display
.get_display_clock_speed
=
11973 valleyview_get_display_clock_speed
;
11974 else if (IS_I945G(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
11975 dev_priv
->display
.get_display_clock_speed
=
11976 i945_get_display_clock_speed
;
11977 else if (IS_I915G(dev
))
11978 dev_priv
->display
.get_display_clock_speed
=
11979 i915_get_display_clock_speed
;
11980 else if (IS_I945GM(dev
) || IS_845G(dev
))
11981 dev_priv
->display
.get_display_clock_speed
=
11982 i9xx_misc_get_display_clock_speed
;
11983 else if (IS_PINEVIEW(dev
))
11984 dev_priv
->display
.get_display_clock_speed
=
11985 pnv_get_display_clock_speed
;
11986 else if (IS_I915GM(dev
))
11987 dev_priv
->display
.get_display_clock_speed
=
11988 i915gm_get_display_clock_speed
;
11989 else if (IS_I865G(dev
))
11990 dev_priv
->display
.get_display_clock_speed
=
11991 i865_get_display_clock_speed
;
11992 else if (IS_I85X(dev
))
11993 dev_priv
->display
.get_display_clock_speed
=
11994 i855_get_display_clock_speed
;
11995 else /* 852, 830 */
11996 dev_priv
->display
.get_display_clock_speed
=
11997 i830_get_display_clock_speed
;
11999 if (HAS_PCH_SPLIT(dev
)) {
12000 if (IS_GEN5(dev
)) {
12001 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
12002 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12003 } else if (IS_GEN6(dev
)) {
12004 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
12005 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12006 dev_priv
->display
.modeset_global_resources
=
12007 snb_modeset_global_resources
;
12008 } else if (IS_IVYBRIDGE(dev
)) {
12009 /* FIXME: detect B0+ stepping and use auto training */
12010 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
12011 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12012 dev_priv
->display
.modeset_global_resources
=
12013 ivb_modeset_global_resources
;
12014 } else if (IS_HASWELL(dev
) || IS_GEN8(dev
)) {
12015 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
12016 dev_priv
->display
.write_eld
= haswell_write_eld
;
12017 dev_priv
->display
.modeset_global_resources
=
12018 haswell_modeset_global_resources
;
12020 } else if (IS_G4X(dev
)) {
12021 dev_priv
->display
.write_eld
= g4x_write_eld
;
12022 } else if (IS_VALLEYVIEW(dev
)) {
12023 dev_priv
->display
.modeset_global_resources
=
12024 valleyview_modeset_global_resources
;
12025 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12028 /* Default just returns -ENODEV to indicate unsupported */
12029 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
12031 switch (INTEL_INFO(dev
)->gen
) {
12033 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
12037 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
12042 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
12046 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
12049 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
12050 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
12054 intel_panel_init_backlight_funcs(dev
);
12058 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
12059 * resume, or other times. This quirk makes sure that's the case for
12060 * affected systems.
12062 static void quirk_pipea_force(struct drm_device
*dev
)
12064 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12066 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
12067 DRM_INFO("applying pipe a force quirk\n");
12071 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
12073 static void quirk_ssc_force_disable(struct drm_device
*dev
)
12075 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12076 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
12077 DRM_INFO("applying lvds SSC disable quirk\n");
12081 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
12084 static void quirk_invert_brightness(struct drm_device
*dev
)
12086 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12087 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
12088 DRM_INFO("applying inverted panel brightness quirk\n");
12091 struct intel_quirk
{
12093 int subsystem_vendor
;
12094 int subsystem_device
;
12095 void (*hook
)(struct drm_device
*dev
);
12098 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
12099 struct intel_dmi_quirk
{
12100 void (*hook
)(struct drm_device
*dev
);
12101 const struct dmi_system_id (*dmi_id_list
)[];
12104 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
12106 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
12110 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
12112 .dmi_id_list
= &(const struct dmi_system_id
[]) {
12114 .callback
= intel_dmi_reverse_brightness
,
12115 .ident
= "NCR Corporation",
12116 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
12117 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
12120 { } /* terminating entry */
12122 .hook
= quirk_invert_brightness
,
12126 static struct intel_quirk intel_quirks
[] = {
12127 /* HP Mini needs pipe A force quirk (LP: #322104) */
12128 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force
},
12130 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
12131 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
12133 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
12134 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
12136 /* Lenovo U160 cannot use SSC on LVDS */
12137 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
12139 /* Sony Vaio Y cannot use SSC on LVDS */
12140 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
12142 /* Acer Aspire 5734Z must invert backlight brightness */
12143 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
12145 /* Acer/eMachines G725 */
12146 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
12148 /* Acer/eMachines e725 */
12149 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
12151 /* Acer/Packard Bell NCL20 */
12152 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
12154 /* Acer Aspire 4736Z */
12155 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
12157 /* Acer Aspire 5336 */
12158 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
12161 static void intel_init_quirks(struct drm_device
*dev
)
12163 struct pci_dev
*d
= dev
->pdev
;
12166 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
12167 struct intel_quirk
*q
= &intel_quirks
[i
];
12169 if (d
->device
== q
->device
&&
12170 (d
->subsystem_vendor
== q
->subsystem_vendor
||
12171 q
->subsystem_vendor
== PCI_ANY_ID
) &&
12172 (d
->subsystem_device
== q
->subsystem_device
||
12173 q
->subsystem_device
== PCI_ANY_ID
))
12176 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
12177 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
12178 intel_dmi_quirks
[i
].hook(dev
);
12182 /* Disable the VGA plane that we never use */
12183 static void i915_disable_vga(struct drm_device
*dev
)
12185 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12187 u32 vga_reg
= i915_vgacntrl_reg(dev
);
12189 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
12190 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12191 outb(SR01
, VGA_SR_INDEX
);
12192 sr1
= inb(VGA_SR_DATA
);
12193 outb(sr1
| 1<<5, VGA_SR_DATA
);
12194 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12197 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
12198 POSTING_READ(vga_reg
);
12201 void intel_modeset_init_hw(struct drm_device
*dev
)
12203 intel_prepare_ddi(dev
);
12205 intel_init_clock_gating(dev
);
12207 intel_reset_dpio(dev
);
12209 intel_enable_gt_powersave(dev
);
12212 void intel_modeset_suspend_hw(struct drm_device
*dev
)
12214 intel_suspend_hw(dev
);
12217 void intel_modeset_init(struct drm_device
*dev
)
12219 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12222 struct intel_crtc
*crtc
;
12224 drm_mode_config_init(dev
);
12226 dev
->mode_config
.min_width
= 0;
12227 dev
->mode_config
.min_height
= 0;
12229 dev
->mode_config
.preferred_depth
= 24;
12230 dev
->mode_config
.prefer_shadow
= 1;
12232 dev
->mode_config
.funcs
= &intel_mode_funcs
;
12234 intel_init_quirks(dev
);
12236 intel_init_pm(dev
);
12238 if (INTEL_INFO(dev
)->num_pipes
== 0)
12241 intel_init_display(dev
);
12243 if (IS_GEN2(dev
)) {
12244 dev
->mode_config
.max_width
= 2048;
12245 dev
->mode_config
.max_height
= 2048;
12246 } else if (IS_GEN3(dev
)) {
12247 dev
->mode_config
.max_width
= 4096;
12248 dev
->mode_config
.max_height
= 4096;
12250 dev
->mode_config
.max_width
= 8192;
12251 dev
->mode_config
.max_height
= 8192;
12254 if (IS_GEN2(dev
)) {
12255 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
12256 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
12258 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
12259 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
12262 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
12264 DRM_DEBUG_KMS("%d display pipe%s available.\n",
12265 INTEL_INFO(dev
)->num_pipes
,
12266 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
12268 for_each_pipe(pipe
) {
12269 intel_crtc_init(dev
, pipe
);
12270 for_each_sprite(pipe
, sprite
) {
12271 ret
= intel_plane_init(dev
, pipe
, sprite
);
12273 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
12274 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
12278 intel_init_dpio(dev
);
12279 intel_reset_dpio(dev
);
12281 intel_cpu_pll_init(dev
);
12282 intel_shared_dpll_init(dev
);
12284 /* Just disable it once at startup */
12285 i915_disable_vga(dev
);
12286 intel_setup_outputs(dev
);
12288 /* Just in case the BIOS is doing something questionable. */
12289 intel_disable_fbc(dev
);
12291 drm_modeset_lock_all(dev
);
12292 intel_modeset_setup_hw_state(dev
, false);
12293 drm_modeset_unlock_all(dev
);
12295 for_each_intel_crtc(dev
, crtc
) {
12300 * Note that reserving the BIOS fb up front prevents us
12301 * from stuffing other stolen allocations like the ring
12302 * on top. This prevents some ugliness at boot time, and
12303 * can even allow for smooth boot transitions if the BIOS
12304 * fb is large enough for the active pipe configuration.
12306 if (dev_priv
->display
.get_plane_config
) {
12307 dev_priv
->display
.get_plane_config(crtc
,
12308 &crtc
->plane_config
);
12310 * If the fb is shared between multiple heads, we'll
12311 * just get the first one.
12313 intel_find_plane_obj(crtc
, &crtc
->plane_config
);
12318 static void intel_enable_pipe_a(struct drm_device
*dev
)
12320 struct intel_connector
*connector
;
12321 struct drm_connector
*crt
= NULL
;
12322 struct intel_load_detect_pipe load_detect_temp
;
12323 struct drm_modeset_acquire_ctx ctx
;
12325 /* We can't just switch on the pipe A, we need to set things up with a
12326 * proper mode and output configuration. As a gross hack, enable pipe A
12327 * by enabling the load detect pipe once. */
12328 list_for_each_entry(connector
,
12329 &dev
->mode_config
.connector_list
,
12331 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
12332 crt
= &connector
->base
;
12340 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, &ctx
))
12341 intel_release_load_detect_pipe(crt
, &load_detect_temp
, &ctx
);
12347 intel_check_plane_mapping(struct intel_crtc
*crtc
)
12349 struct drm_device
*dev
= crtc
->base
.dev
;
12350 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12353 if (INTEL_INFO(dev
)->num_pipes
== 1)
12356 reg
= DSPCNTR(!crtc
->plane
);
12357 val
= I915_READ(reg
);
12359 if ((val
& DISPLAY_PLANE_ENABLE
) &&
12360 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
12366 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
12368 struct drm_device
*dev
= crtc
->base
.dev
;
12369 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12372 /* Clear any frame start delays used for debugging left by the BIOS */
12373 reg
= PIPECONF(crtc
->config
.cpu_transcoder
);
12374 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
12376 /* restore vblank interrupts to correct state */
12378 drm_vblank_on(dev
, crtc
->pipe
);
12380 drm_vblank_off(dev
, crtc
->pipe
);
12382 /* We need to sanitize the plane -> pipe mapping first because this will
12383 * disable the crtc (and hence change the state) if it is wrong. Note
12384 * that gen4+ has a fixed plane -> pipe mapping. */
12385 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
12386 struct intel_connector
*connector
;
12389 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
12390 crtc
->base
.base
.id
);
12392 /* Pipe has the wrong plane attached and the plane is active.
12393 * Temporarily change the plane mapping and disable everything
12395 plane
= crtc
->plane
;
12396 crtc
->plane
= !plane
;
12397 dev_priv
->display
.crtc_disable(&crtc
->base
);
12398 crtc
->plane
= plane
;
12400 /* ... and break all links. */
12401 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12403 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
12406 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12407 connector
->base
.encoder
= NULL
;
12409 /* multiple connectors may have the same encoder:
12410 * handle them and break crtc link separately */
12411 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12413 if (connector
->encoder
->base
.crtc
== &crtc
->base
) {
12414 connector
->encoder
->base
.crtc
= NULL
;
12415 connector
->encoder
->connectors_active
= false;
12418 WARN_ON(crtc
->active
);
12419 crtc
->base
.enabled
= false;
12422 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
12423 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
12424 /* BIOS forgot to enable pipe A, this mostly happens after
12425 * resume. Force-enable the pipe to fix this, the update_dpms
12426 * call below we restore the pipe to the right state, but leave
12427 * the required bits on. */
12428 intel_enable_pipe_a(dev
);
12431 /* Adjust the state of the output pipe according to whether we
12432 * have active connectors/encoders. */
12433 intel_crtc_update_dpms(&crtc
->base
);
12435 if (crtc
->active
!= crtc
->base
.enabled
) {
12436 struct intel_encoder
*encoder
;
12438 /* This can happen either due to bugs in the get_hw_state
12439 * functions or because the pipe is force-enabled due to the
12441 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
12442 crtc
->base
.base
.id
,
12443 crtc
->base
.enabled
? "enabled" : "disabled",
12444 crtc
->active
? "enabled" : "disabled");
12446 crtc
->base
.enabled
= crtc
->active
;
12448 /* Because we only establish the connector -> encoder ->
12449 * crtc links if something is active, this means the
12450 * crtc is now deactivated. Break the links. connector
12451 * -> encoder links are only establish when things are
12452 * actually up, hence no need to break them. */
12453 WARN_ON(crtc
->active
);
12455 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
12456 WARN_ON(encoder
->connectors_active
);
12457 encoder
->base
.crtc
= NULL
;
12461 if (crtc
->active
|| IS_VALLEYVIEW(dev
) || INTEL_INFO(dev
)->gen
< 5) {
12463 * We start out with underrun reporting disabled to avoid races.
12464 * For correct bookkeeping mark this on active crtcs.
12466 * Also on gmch platforms we dont have any hardware bits to
12467 * disable the underrun reporting. Which means we need to start
12468 * out with underrun reporting disabled also on inactive pipes,
12469 * since otherwise we'll complain about the garbage we read when
12470 * e.g. coming up after runtime pm.
12472 * No protection against concurrent access is required - at
12473 * worst a fifo underrun happens which also sets this to false.
12475 crtc
->cpu_fifo_underrun_disabled
= true;
12476 crtc
->pch_fifo_underrun_disabled
= true;
12478 update_scanline_offset(crtc
);
12482 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
12484 struct intel_connector
*connector
;
12485 struct drm_device
*dev
= encoder
->base
.dev
;
12487 /* We need to check both for a crtc link (meaning that the
12488 * encoder is active and trying to read from a pipe) and the
12489 * pipe itself being active. */
12490 bool has_active_crtc
= encoder
->base
.crtc
&&
12491 to_intel_crtc(encoder
->base
.crtc
)->active
;
12493 if (encoder
->connectors_active
&& !has_active_crtc
) {
12494 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
12495 encoder
->base
.base
.id
,
12496 encoder
->base
.name
);
12498 /* Connector is active, but has no active pipe. This is
12499 * fallout from our resume register restoring. Disable
12500 * the encoder manually again. */
12501 if (encoder
->base
.crtc
) {
12502 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
12503 encoder
->base
.base
.id
,
12504 encoder
->base
.name
);
12505 encoder
->disable(encoder
);
12507 encoder
->base
.crtc
= NULL
;
12508 encoder
->connectors_active
= false;
12510 /* Inconsistent output/port/pipe state happens presumably due to
12511 * a bug in one of the get_hw_state functions. Or someplace else
12512 * in our code, like the register restore mess on resume. Clamp
12513 * things to off as a safer default. */
12514 list_for_each_entry(connector
,
12515 &dev
->mode_config
.connector_list
,
12517 if (connector
->encoder
!= encoder
)
12519 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12520 connector
->base
.encoder
= NULL
;
12523 /* Enabled encoders without active connectors will be fixed in
12524 * the crtc fixup. */
12527 void i915_redisable_vga_power_on(struct drm_device
*dev
)
12529 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12530 u32 vga_reg
= i915_vgacntrl_reg(dev
);
12532 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
12533 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
12534 i915_disable_vga(dev
);
12538 void i915_redisable_vga(struct drm_device
*dev
)
12540 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12542 /* This function can be called both from intel_modeset_setup_hw_state or
12543 * at a very early point in our resume sequence, where the power well
12544 * structures are not yet restored. Since this function is at a very
12545 * paranoid "someone might have enabled VGA while we were not looking"
12546 * level, just check if the power well is enabled instead of trying to
12547 * follow the "don't touch the power well if we don't need it" policy
12548 * the rest of the driver uses. */
12549 if (!intel_display_power_enabled(dev_priv
, POWER_DOMAIN_VGA
))
12552 i915_redisable_vga_power_on(dev
);
12555 static bool primary_get_hw_state(struct intel_crtc
*crtc
)
12557 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
12562 return I915_READ(DSPCNTR(crtc
->plane
)) & DISPLAY_PLANE_ENABLE
;
12565 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
12567 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12569 struct intel_crtc
*crtc
;
12570 struct intel_encoder
*encoder
;
12571 struct intel_connector
*connector
;
12574 for_each_intel_crtc(dev
, crtc
) {
12575 memset(&crtc
->config
, 0, sizeof(crtc
->config
));
12577 crtc
->config
.quirks
|= PIPE_CONFIG_QUIRK_INHERITED_MODE
;
12579 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
12582 crtc
->base
.enabled
= crtc
->active
;
12583 crtc
->primary_enabled
= primary_get_hw_state(crtc
);
12585 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
12586 crtc
->base
.base
.id
,
12587 crtc
->active
? "enabled" : "disabled");
12590 /* FIXME: Smash this into the new shared dpll infrastructure. */
12592 intel_ddi_setup_hw_pll_state(dev
);
12594 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
12595 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
12597 pll
->on
= pll
->get_hw_state(dev_priv
, pll
, &pll
->hw_state
);
12599 for_each_intel_crtc(dev
, crtc
) {
12600 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
12603 pll
->refcount
= pll
->active
;
12605 DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
12606 pll
->name
, pll
->refcount
, pll
->on
);
12609 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
12613 if (encoder
->get_hw_state(encoder
, &pipe
)) {
12614 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
12615 encoder
->base
.crtc
= &crtc
->base
;
12616 encoder
->get_config(encoder
, &crtc
->config
);
12618 encoder
->base
.crtc
= NULL
;
12621 encoder
->connectors_active
= false;
12622 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
12623 encoder
->base
.base
.id
,
12624 encoder
->base
.name
,
12625 encoder
->base
.crtc
? "enabled" : "disabled",
12629 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12631 if (connector
->get_hw_state(connector
)) {
12632 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
12633 connector
->encoder
->connectors_active
= true;
12634 connector
->base
.encoder
= &connector
->encoder
->base
;
12636 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12637 connector
->base
.encoder
= NULL
;
12639 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
12640 connector
->base
.base
.id
,
12641 connector
->base
.name
,
12642 connector
->base
.encoder
? "enabled" : "disabled");
12646 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
12647 * and i915 state tracking structures. */
12648 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
12649 bool force_restore
)
12651 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12653 struct intel_crtc
*crtc
;
12654 struct intel_encoder
*encoder
;
12657 intel_modeset_readout_hw_state(dev
);
12660 * Now that we have the config, copy it to each CRTC struct
12661 * Note that this could go away if we move to using crtc_config
12662 * checking everywhere.
12664 for_each_intel_crtc(dev
, crtc
) {
12665 if (crtc
->active
&& i915
.fastboot
) {
12666 intel_mode_from_pipe_config(&crtc
->base
.mode
, &crtc
->config
);
12667 DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
12668 crtc
->base
.base
.id
);
12669 drm_mode_debug_printmodeline(&crtc
->base
.mode
);
12673 /* HW state is read out, now we need to sanitize this mess. */
12674 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
12676 intel_sanitize_encoder(encoder
);
12679 for_each_pipe(pipe
) {
12680 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
12681 intel_sanitize_crtc(crtc
);
12682 intel_dump_pipe_config(crtc
, &crtc
->config
, "[setup_hw_state]");
12685 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
12686 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
12688 if (!pll
->on
|| pll
->active
)
12691 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
12693 pll
->disable(dev_priv
, pll
);
12697 if (HAS_PCH_SPLIT(dev
))
12698 ilk_wm_get_hw_state(dev
);
12700 if (force_restore
) {
12701 i915_redisable_vga(dev
);
12704 * We need to use raw interfaces for restoring state to avoid
12705 * checking (bogus) intermediate states.
12707 for_each_pipe(pipe
) {
12708 struct drm_crtc
*crtc
=
12709 dev_priv
->pipe_to_crtc_mapping
[pipe
];
12711 __intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
,
12712 crtc
->primary
->fb
);
12715 intel_modeset_update_staged_output_state(dev
);
12718 intel_modeset_check_state(dev
);
12721 void intel_modeset_gem_init(struct drm_device
*dev
)
12723 struct drm_crtc
*c
;
12724 struct intel_framebuffer
*fb
;
12726 mutex_lock(&dev
->struct_mutex
);
12727 intel_init_gt_powersave(dev
);
12728 mutex_unlock(&dev
->struct_mutex
);
12730 intel_modeset_init_hw(dev
);
12732 intel_setup_overlay(dev
);
12735 * Make sure any fbs we allocated at startup are properly
12736 * pinned & fenced. When we do the allocation it's too early
12739 mutex_lock(&dev
->struct_mutex
);
12740 for_each_crtc(dev
, c
) {
12741 if (!c
->primary
->fb
)
12744 fb
= to_intel_framebuffer(c
->primary
->fb
);
12745 if (intel_pin_and_fence_fb_obj(dev
, fb
->obj
, NULL
)) {
12746 DRM_ERROR("failed to pin boot fb on pipe %d\n",
12747 to_intel_crtc(c
)->pipe
);
12748 drm_framebuffer_unreference(c
->primary
->fb
);
12749 c
->primary
->fb
= NULL
;
12752 mutex_unlock(&dev
->struct_mutex
);
12755 void intel_connector_unregister(struct intel_connector
*intel_connector
)
12757 struct drm_connector
*connector
= &intel_connector
->base
;
12759 intel_panel_destroy_backlight(connector
);
12760 drm_sysfs_connector_remove(connector
);
12763 void intel_modeset_cleanup(struct drm_device
*dev
)
12765 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12766 struct drm_crtc
*crtc
;
12767 struct drm_connector
*connector
;
12770 * Interrupts and polling as the first thing to avoid creating havoc.
12771 * Too much stuff here (turning of rps, connectors, ...) would
12772 * experience fancy races otherwise.
12774 drm_irq_uninstall(dev
);
12775 cancel_work_sync(&dev_priv
->hotplug_work
);
12777 * Due to the hpd irq storm handling the hotplug work can re-arm the
12778 * poll handlers. Hence disable polling after hpd handling is shut down.
12780 drm_kms_helper_poll_fini(dev
);
12782 mutex_lock(&dev
->struct_mutex
);
12784 intel_unregister_dsm_handler();
12786 for_each_crtc(dev
, crtc
) {
12787 /* Skip inactive CRTCs */
12788 if (!crtc
->primary
->fb
)
12791 intel_increase_pllclock(crtc
);
12794 intel_disable_fbc(dev
);
12796 intel_disable_gt_powersave(dev
);
12798 ironlake_teardown_rc6(dev
);
12800 mutex_unlock(&dev
->struct_mutex
);
12802 /* flush any delayed tasks or pending work */
12803 flush_scheduled_work();
12805 /* destroy the backlight and sysfs files before encoders/connectors */
12806 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
12807 struct intel_connector
*intel_connector
;
12809 intel_connector
= to_intel_connector(connector
);
12810 intel_connector
->unregister(intel_connector
);
12813 drm_mode_config_cleanup(dev
);
12815 intel_cleanup_overlay(dev
);
12817 mutex_lock(&dev
->struct_mutex
);
12818 intel_cleanup_gt_powersave(dev
);
12819 mutex_unlock(&dev
->struct_mutex
);
12823 * Return which encoder is currently attached for connector.
12825 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
12827 return &intel_attached_encoder(connector
)->base
;
12830 void intel_connector_attach_encoder(struct intel_connector
*connector
,
12831 struct intel_encoder
*encoder
)
12833 connector
->encoder
= encoder
;
12834 drm_mode_connector_attach_encoder(&connector
->base
,
12839 * set vga decode state - true == enable VGA decode
12841 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
12843 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12844 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
12847 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
12848 DRM_ERROR("failed to read control word\n");
12852 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
12856 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
12858 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
12860 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
12861 DRM_ERROR("failed to write control word\n");
12868 struct intel_display_error_state
{
12870 u32 power_well_driver
;
12872 int num_transcoders
;
12874 struct intel_cursor_error_state
{
12879 } cursor
[I915_MAX_PIPES
];
12881 struct intel_pipe_error_state
{
12882 bool power_domain_on
;
12885 } pipe
[I915_MAX_PIPES
];
12887 struct intel_plane_error_state
{
12895 } plane
[I915_MAX_PIPES
];
12897 struct intel_transcoder_error_state
{
12898 bool power_domain_on
;
12899 enum transcoder cpu_transcoder
;
12912 struct intel_display_error_state
*
12913 intel_display_capture_error_state(struct drm_device
*dev
)
12915 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12916 struct intel_display_error_state
*error
;
12917 int transcoders
[] = {
12925 if (INTEL_INFO(dev
)->num_pipes
== 0)
12928 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
12932 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
12933 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
12936 error
->pipe
[i
].power_domain_on
=
12937 intel_display_power_enabled_sw(dev_priv
,
12938 POWER_DOMAIN_PIPE(i
));
12939 if (!error
->pipe
[i
].power_domain_on
)
12942 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
12943 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
12944 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
12946 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
12947 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
12948 if (INTEL_INFO(dev
)->gen
<= 3) {
12949 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
12950 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
12952 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
12953 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
12954 if (INTEL_INFO(dev
)->gen
>= 4) {
12955 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
12956 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
12959 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
12961 if (!HAS_PCH_SPLIT(dev
))
12962 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
12965 error
->num_transcoders
= INTEL_INFO(dev
)->num_pipes
;
12966 if (HAS_DDI(dev_priv
->dev
))
12967 error
->num_transcoders
++; /* Account for eDP. */
12969 for (i
= 0; i
< error
->num_transcoders
; i
++) {
12970 enum transcoder cpu_transcoder
= transcoders
[i
];
12972 error
->transcoder
[i
].power_domain_on
=
12973 intel_display_power_enabled_sw(dev_priv
,
12974 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
12975 if (!error
->transcoder
[i
].power_domain_on
)
12978 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
12980 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
12981 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
12982 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
12983 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
12984 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
12985 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
12986 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
12992 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
12995 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
12996 struct drm_device
*dev
,
12997 struct intel_display_error_state
*error
)
13004 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
13005 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
13006 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
13007 error
->power_well_driver
);
13009 err_printf(m
, "Pipe [%d]:\n", i
);
13010 err_printf(m
, " Power: %s\n",
13011 error
->pipe
[i
].power_domain_on
? "on" : "off");
13012 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
13013 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
13015 err_printf(m
, "Plane [%d]:\n", i
);
13016 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
13017 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
13018 if (INTEL_INFO(dev
)->gen
<= 3) {
13019 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
13020 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
13022 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
13023 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
13024 if (INTEL_INFO(dev
)->gen
>= 4) {
13025 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
13026 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
13029 err_printf(m
, "Cursor [%d]:\n", i
);
13030 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
13031 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
13032 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
13035 for (i
= 0; i
< error
->num_transcoders
; i
++) {
13036 err_printf(m
, "CPU transcoder: %c\n",
13037 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
13038 err_printf(m
, " Power: %s\n",
13039 error
->transcoder
[i
].power_domain_on
? "on" : "off");
13040 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
13041 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
13042 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
13043 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
13044 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
13045 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
13046 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);