2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/dmi.h>
28 #include <linux/module.h>
29 #include <linux/input.h>
30 #include <linux/i2c.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/vgaarb.h>
34 #include <drm/drm_edid.h>
36 #include "intel_drv.h"
37 #include <drm/i915_drm.h>
39 #include "i915_trace.h"
40 #include <drm/drm_dp_helper.h>
41 #include <drm/drm_crtc_helper.h>
42 #include <drm/drm_plane_helper.h>
43 #include <drm/drm_rect.h>
44 #include <linux/dma_remapping.h>
46 /* Primary plane formats supported by all gen */
47 #define COMMON_PRIMARY_FORMATS \
50 DRM_FORMAT_XRGB8888, \
53 /* Primary plane formats for gen <= 3 */
54 static const uint32_t intel_primary_formats_gen2
[] = {
55 COMMON_PRIMARY_FORMATS
,
60 /* Primary plane formats for gen >= 4 */
61 static const uint32_t intel_primary_formats_gen4
[] = {
62 COMMON_PRIMARY_FORMATS
, \
65 DRM_FORMAT_XRGB2101010
,
66 DRM_FORMAT_ARGB2101010
,
67 DRM_FORMAT_XBGR2101010
,
68 DRM_FORMAT_ABGR2101010
,
72 static const uint32_t intel_cursor_formats
[] = {
76 #define DIV_ROUND_CLOSEST_ULL(ll, d) \
77 ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
79 static void intel_increase_pllclock(struct drm_device
*dev
,
81 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
, bool on
);
83 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
84 struct intel_crtc_config
*pipe_config
);
85 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
86 struct intel_crtc_config
*pipe_config
);
88 static int intel_set_mode(struct drm_crtc
*crtc
, struct drm_display_mode
*mode
,
89 int x
, int y
, struct drm_framebuffer
*old_fb
);
90 static int intel_framebuffer_init(struct drm_device
*dev
,
91 struct intel_framebuffer
*ifb
,
92 struct drm_mode_fb_cmd2
*mode_cmd
,
93 struct drm_i915_gem_object
*obj
);
94 static void 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 struct intel_link_m_n
*m2_n2
);
99 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
);
100 static void haswell_set_pipeconf(struct drm_crtc
*crtc
);
101 static void intel_set_pipe_csc(struct drm_crtc
*crtc
);
102 static void vlv_prepare_pll(struct intel_crtc
*crtc
);
103 static void chv_prepare_pll(struct intel_crtc
*crtc
);
105 static struct intel_encoder
*intel_find_encoder(struct intel_connector
*connector
, int pipe
)
107 if (!connector
->mst_port
)
108 return connector
->encoder
;
110 return &connector
->mst_port
->mst_encoders
[pipe
]->base
;
119 int p2_slow
, p2_fast
;
122 typedef struct intel_limit intel_limit_t
;
124 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
129 intel_pch_rawclk(struct drm_device
*dev
)
131 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
133 WARN_ON(!HAS_PCH_SPLIT(dev
));
135 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
138 static inline u32
/* units of 100MHz */
139 intel_fdi_link_freq(struct drm_device
*dev
)
142 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
143 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
148 static const intel_limit_t intel_limits_i8xx_dac
= {
149 .dot
= { .min
= 25000, .max
= 350000 },
150 .vco
= { .min
= 908000, .max
= 1512000 },
151 .n
= { .min
= 2, .max
= 16 },
152 .m
= { .min
= 96, .max
= 140 },
153 .m1
= { .min
= 18, .max
= 26 },
154 .m2
= { .min
= 6, .max
= 16 },
155 .p
= { .min
= 4, .max
= 128 },
156 .p1
= { .min
= 2, .max
= 33 },
157 .p2
= { .dot_limit
= 165000,
158 .p2_slow
= 4, .p2_fast
= 2 },
161 static const intel_limit_t intel_limits_i8xx_dvo
= {
162 .dot
= { .min
= 25000, .max
= 350000 },
163 .vco
= { .min
= 908000, .max
= 1512000 },
164 .n
= { .min
= 2, .max
= 16 },
165 .m
= { .min
= 96, .max
= 140 },
166 .m1
= { .min
= 18, .max
= 26 },
167 .m2
= { .min
= 6, .max
= 16 },
168 .p
= { .min
= 4, .max
= 128 },
169 .p1
= { .min
= 2, .max
= 33 },
170 .p2
= { .dot_limit
= 165000,
171 .p2_slow
= 4, .p2_fast
= 4 },
174 static const intel_limit_t intel_limits_i8xx_lvds
= {
175 .dot
= { .min
= 25000, .max
= 350000 },
176 .vco
= { .min
= 908000, .max
= 1512000 },
177 .n
= { .min
= 2, .max
= 16 },
178 .m
= { .min
= 96, .max
= 140 },
179 .m1
= { .min
= 18, .max
= 26 },
180 .m2
= { .min
= 6, .max
= 16 },
181 .p
= { .min
= 4, .max
= 128 },
182 .p1
= { .min
= 1, .max
= 6 },
183 .p2
= { .dot_limit
= 165000,
184 .p2_slow
= 14, .p2_fast
= 7 },
187 static const intel_limit_t intel_limits_i9xx_sdvo
= {
188 .dot
= { .min
= 20000, .max
= 400000 },
189 .vco
= { .min
= 1400000, .max
= 2800000 },
190 .n
= { .min
= 1, .max
= 6 },
191 .m
= { .min
= 70, .max
= 120 },
192 .m1
= { .min
= 8, .max
= 18 },
193 .m2
= { .min
= 3, .max
= 7 },
194 .p
= { .min
= 5, .max
= 80 },
195 .p1
= { .min
= 1, .max
= 8 },
196 .p2
= { .dot_limit
= 200000,
197 .p2_slow
= 10, .p2_fast
= 5 },
200 static const intel_limit_t intel_limits_i9xx_lvds
= {
201 .dot
= { .min
= 20000, .max
= 400000 },
202 .vco
= { .min
= 1400000, .max
= 2800000 },
203 .n
= { .min
= 1, .max
= 6 },
204 .m
= { .min
= 70, .max
= 120 },
205 .m1
= { .min
= 8, .max
= 18 },
206 .m2
= { .min
= 3, .max
= 7 },
207 .p
= { .min
= 7, .max
= 98 },
208 .p1
= { .min
= 1, .max
= 8 },
209 .p2
= { .dot_limit
= 112000,
210 .p2_slow
= 14, .p2_fast
= 7 },
214 static const intel_limit_t intel_limits_g4x_sdvo
= {
215 .dot
= { .min
= 25000, .max
= 270000 },
216 .vco
= { .min
= 1750000, .max
= 3500000},
217 .n
= { .min
= 1, .max
= 4 },
218 .m
= { .min
= 104, .max
= 138 },
219 .m1
= { .min
= 17, .max
= 23 },
220 .m2
= { .min
= 5, .max
= 11 },
221 .p
= { .min
= 10, .max
= 30 },
222 .p1
= { .min
= 1, .max
= 3},
223 .p2
= { .dot_limit
= 270000,
229 static const intel_limit_t intel_limits_g4x_hdmi
= {
230 .dot
= { .min
= 22000, .max
= 400000 },
231 .vco
= { .min
= 1750000, .max
= 3500000},
232 .n
= { .min
= 1, .max
= 4 },
233 .m
= { .min
= 104, .max
= 138 },
234 .m1
= { .min
= 16, .max
= 23 },
235 .m2
= { .min
= 5, .max
= 11 },
236 .p
= { .min
= 5, .max
= 80 },
237 .p1
= { .min
= 1, .max
= 8},
238 .p2
= { .dot_limit
= 165000,
239 .p2_slow
= 10, .p2_fast
= 5 },
242 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
243 .dot
= { .min
= 20000, .max
= 115000 },
244 .vco
= { .min
= 1750000, .max
= 3500000 },
245 .n
= { .min
= 1, .max
= 3 },
246 .m
= { .min
= 104, .max
= 138 },
247 .m1
= { .min
= 17, .max
= 23 },
248 .m2
= { .min
= 5, .max
= 11 },
249 .p
= { .min
= 28, .max
= 112 },
250 .p1
= { .min
= 2, .max
= 8 },
251 .p2
= { .dot_limit
= 0,
252 .p2_slow
= 14, .p2_fast
= 14
256 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
257 .dot
= { .min
= 80000, .max
= 224000 },
258 .vco
= { .min
= 1750000, .max
= 3500000 },
259 .n
= { .min
= 1, .max
= 3 },
260 .m
= { .min
= 104, .max
= 138 },
261 .m1
= { .min
= 17, .max
= 23 },
262 .m2
= { .min
= 5, .max
= 11 },
263 .p
= { .min
= 14, .max
= 42 },
264 .p1
= { .min
= 2, .max
= 6 },
265 .p2
= { .dot_limit
= 0,
266 .p2_slow
= 7, .p2_fast
= 7
270 static const intel_limit_t intel_limits_pineview_sdvo
= {
271 .dot
= { .min
= 20000, .max
= 400000},
272 .vco
= { .min
= 1700000, .max
= 3500000 },
273 /* Pineview's Ncounter is a ring counter */
274 .n
= { .min
= 3, .max
= 6 },
275 .m
= { .min
= 2, .max
= 256 },
276 /* Pineview only has one combined m divider, which we treat as m2. */
277 .m1
= { .min
= 0, .max
= 0 },
278 .m2
= { .min
= 0, .max
= 254 },
279 .p
= { .min
= 5, .max
= 80 },
280 .p1
= { .min
= 1, .max
= 8 },
281 .p2
= { .dot_limit
= 200000,
282 .p2_slow
= 10, .p2_fast
= 5 },
285 static const intel_limit_t intel_limits_pineview_lvds
= {
286 .dot
= { .min
= 20000, .max
= 400000 },
287 .vco
= { .min
= 1700000, .max
= 3500000 },
288 .n
= { .min
= 3, .max
= 6 },
289 .m
= { .min
= 2, .max
= 256 },
290 .m1
= { .min
= 0, .max
= 0 },
291 .m2
= { .min
= 0, .max
= 254 },
292 .p
= { .min
= 7, .max
= 112 },
293 .p1
= { .min
= 1, .max
= 8 },
294 .p2
= { .dot_limit
= 112000,
295 .p2_slow
= 14, .p2_fast
= 14 },
298 /* Ironlake / Sandybridge
300 * We calculate clock using (register_value + 2) for N/M1/M2, so here
301 * the range value for them is (actual_value - 2).
303 static const intel_limit_t intel_limits_ironlake_dac
= {
304 .dot
= { .min
= 25000, .max
= 350000 },
305 .vco
= { .min
= 1760000, .max
= 3510000 },
306 .n
= { .min
= 1, .max
= 5 },
307 .m
= { .min
= 79, .max
= 127 },
308 .m1
= { .min
= 12, .max
= 22 },
309 .m2
= { .min
= 5, .max
= 9 },
310 .p
= { .min
= 5, .max
= 80 },
311 .p1
= { .min
= 1, .max
= 8 },
312 .p2
= { .dot_limit
= 225000,
313 .p2_slow
= 10, .p2_fast
= 5 },
316 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
317 .dot
= { .min
= 25000, .max
= 350000 },
318 .vco
= { .min
= 1760000, .max
= 3510000 },
319 .n
= { .min
= 1, .max
= 3 },
320 .m
= { .min
= 79, .max
= 118 },
321 .m1
= { .min
= 12, .max
= 22 },
322 .m2
= { .min
= 5, .max
= 9 },
323 .p
= { .min
= 28, .max
= 112 },
324 .p1
= { .min
= 2, .max
= 8 },
325 .p2
= { .dot_limit
= 225000,
326 .p2_slow
= 14, .p2_fast
= 14 },
329 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
330 .dot
= { .min
= 25000, .max
= 350000 },
331 .vco
= { .min
= 1760000, .max
= 3510000 },
332 .n
= { .min
= 1, .max
= 3 },
333 .m
= { .min
= 79, .max
= 127 },
334 .m1
= { .min
= 12, .max
= 22 },
335 .m2
= { .min
= 5, .max
= 9 },
336 .p
= { .min
= 14, .max
= 56 },
337 .p1
= { .min
= 2, .max
= 8 },
338 .p2
= { .dot_limit
= 225000,
339 .p2_slow
= 7, .p2_fast
= 7 },
342 /* LVDS 100mhz refclk limits. */
343 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
344 .dot
= { .min
= 25000, .max
= 350000 },
345 .vco
= { .min
= 1760000, .max
= 3510000 },
346 .n
= { .min
= 1, .max
= 2 },
347 .m
= { .min
= 79, .max
= 126 },
348 .m1
= { .min
= 12, .max
= 22 },
349 .m2
= { .min
= 5, .max
= 9 },
350 .p
= { .min
= 28, .max
= 112 },
351 .p1
= { .min
= 2, .max
= 8 },
352 .p2
= { .dot_limit
= 225000,
353 .p2_slow
= 14, .p2_fast
= 14 },
356 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
357 .dot
= { .min
= 25000, .max
= 350000 },
358 .vco
= { .min
= 1760000, .max
= 3510000 },
359 .n
= { .min
= 1, .max
= 3 },
360 .m
= { .min
= 79, .max
= 126 },
361 .m1
= { .min
= 12, .max
= 22 },
362 .m2
= { .min
= 5, .max
= 9 },
363 .p
= { .min
= 14, .max
= 42 },
364 .p1
= { .min
= 2, .max
= 6 },
365 .p2
= { .dot_limit
= 225000,
366 .p2_slow
= 7, .p2_fast
= 7 },
369 static const intel_limit_t intel_limits_vlv
= {
371 * These are the data rate limits (measured in fast clocks)
372 * since those are the strictest limits we have. The fast
373 * clock and actual rate limits are more relaxed, so checking
374 * them would make no difference.
376 .dot
= { .min
= 25000 * 5, .max
= 270000 * 5 },
377 .vco
= { .min
= 4000000, .max
= 6000000 },
378 .n
= { .min
= 1, .max
= 7 },
379 .m1
= { .min
= 2, .max
= 3 },
380 .m2
= { .min
= 11, .max
= 156 },
381 .p1
= { .min
= 2, .max
= 3 },
382 .p2
= { .p2_slow
= 2, .p2_fast
= 20 }, /* slow=min, fast=max */
385 static const intel_limit_t intel_limits_chv
= {
387 * These are the data rate limits (measured in fast clocks)
388 * since those are the strictest limits we have. The fast
389 * clock and actual rate limits are more relaxed, so checking
390 * them would make no difference.
392 .dot
= { .min
= 25000 * 5, .max
= 540000 * 5},
393 .vco
= { .min
= 4860000, .max
= 6700000 },
394 .n
= { .min
= 1, .max
= 1 },
395 .m1
= { .min
= 2, .max
= 2 },
396 .m2
= { .min
= 24 << 22, .max
= 175 << 22 },
397 .p1
= { .min
= 2, .max
= 4 },
398 .p2
= { .p2_slow
= 1, .p2_fast
= 14 },
401 static void vlv_clock(int refclk
, intel_clock_t
*clock
)
403 clock
->m
= clock
->m1
* clock
->m2
;
404 clock
->p
= clock
->p1
* clock
->p2
;
405 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
407 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
408 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
412 * Returns whether any output on the specified pipe is of the specified type
414 static bool intel_pipe_has_type(struct drm_crtc
*crtc
, int type
)
416 struct drm_device
*dev
= crtc
->dev
;
417 struct intel_encoder
*encoder
;
419 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
420 if (encoder
->type
== type
)
426 static const intel_limit_t
*intel_ironlake_limit(struct drm_crtc
*crtc
,
429 struct drm_device
*dev
= crtc
->dev
;
430 const intel_limit_t
*limit
;
432 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
433 if (intel_is_dual_link_lvds(dev
)) {
434 if (refclk
== 100000)
435 limit
= &intel_limits_ironlake_dual_lvds_100m
;
437 limit
= &intel_limits_ironlake_dual_lvds
;
439 if (refclk
== 100000)
440 limit
= &intel_limits_ironlake_single_lvds_100m
;
442 limit
= &intel_limits_ironlake_single_lvds
;
445 limit
= &intel_limits_ironlake_dac
;
450 static const intel_limit_t
*intel_g4x_limit(struct drm_crtc
*crtc
)
452 struct drm_device
*dev
= crtc
->dev
;
453 const intel_limit_t
*limit
;
455 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
456 if (intel_is_dual_link_lvds(dev
))
457 limit
= &intel_limits_g4x_dual_channel_lvds
;
459 limit
= &intel_limits_g4x_single_channel_lvds
;
460 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
) ||
461 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
462 limit
= &intel_limits_g4x_hdmi
;
463 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
)) {
464 limit
= &intel_limits_g4x_sdvo
;
465 } else /* The option is for other outputs */
466 limit
= &intel_limits_i9xx_sdvo
;
471 static const intel_limit_t
*intel_limit(struct drm_crtc
*crtc
, int refclk
)
473 struct drm_device
*dev
= crtc
->dev
;
474 const intel_limit_t
*limit
;
476 if (HAS_PCH_SPLIT(dev
))
477 limit
= intel_ironlake_limit(crtc
, refclk
);
478 else if (IS_G4X(dev
)) {
479 limit
= intel_g4x_limit(crtc
);
480 } else if (IS_PINEVIEW(dev
)) {
481 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
482 limit
= &intel_limits_pineview_lvds
;
484 limit
= &intel_limits_pineview_sdvo
;
485 } else if (IS_CHERRYVIEW(dev
)) {
486 limit
= &intel_limits_chv
;
487 } else if (IS_VALLEYVIEW(dev
)) {
488 limit
= &intel_limits_vlv
;
489 } else if (!IS_GEN2(dev
)) {
490 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
491 limit
= &intel_limits_i9xx_lvds
;
493 limit
= &intel_limits_i9xx_sdvo
;
495 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
496 limit
= &intel_limits_i8xx_lvds
;
497 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DVO
))
498 limit
= &intel_limits_i8xx_dvo
;
500 limit
= &intel_limits_i8xx_dac
;
505 /* m1 is reserved as 0 in Pineview, n is a ring counter */
506 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
508 clock
->m
= clock
->m2
+ 2;
509 clock
->p
= clock
->p1
* clock
->p2
;
510 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
512 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
);
513 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
516 static uint32_t i9xx_dpll_compute_m(struct dpll
*dpll
)
518 return 5 * (dpll
->m1
+ 2) + (dpll
->m2
+ 2);
521 static void i9xx_clock(int refclk
, intel_clock_t
*clock
)
523 clock
->m
= i9xx_dpll_compute_m(clock
);
524 clock
->p
= clock
->p1
* clock
->p2
;
525 if (WARN_ON(clock
->n
+ 2 == 0 || clock
->p
== 0))
527 clock
->vco
= DIV_ROUND_CLOSEST(refclk
* clock
->m
, clock
->n
+ 2);
528 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
531 static void chv_clock(int refclk
, intel_clock_t
*clock
)
533 clock
->m
= clock
->m1
* clock
->m2
;
534 clock
->p
= clock
->p1
* clock
->p2
;
535 if (WARN_ON(clock
->n
== 0 || clock
->p
== 0))
537 clock
->vco
= DIV_ROUND_CLOSEST_ULL((uint64_t)refclk
* clock
->m
,
539 clock
->dot
= DIV_ROUND_CLOSEST(clock
->vco
, clock
->p
);
542 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
544 * Returns whether the given set of divisors are valid for a given refclk with
545 * the given connectors.
548 static bool intel_PLL_is_valid(struct drm_device
*dev
,
549 const intel_limit_t
*limit
,
550 const intel_clock_t
*clock
)
552 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
553 INTELPllInvalid("n out of range\n");
554 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
555 INTELPllInvalid("p1 out of range\n");
556 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
557 INTELPllInvalid("m2 out of range\n");
558 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
559 INTELPllInvalid("m1 out of range\n");
561 if (!IS_PINEVIEW(dev
) && !IS_VALLEYVIEW(dev
))
562 if (clock
->m1
<= clock
->m2
)
563 INTELPllInvalid("m1 <= m2\n");
565 if (!IS_VALLEYVIEW(dev
)) {
566 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
567 INTELPllInvalid("p out of range\n");
568 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
569 INTELPllInvalid("m out of range\n");
572 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
573 INTELPllInvalid("vco out of range\n");
574 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
575 * connector, etc., rather than just a single range.
577 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
578 INTELPllInvalid("dot out of range\n");
584 i9xx_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
585 int target
, int refclk
, intel_clock_t
*match_clock
,
586 intel_clock_t
*best_clock
)
588 struct drm_device
*dev
= crtc
->dev
;
592 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
594 * For LVDS just rely on its current settings for dual-channel.
595 * We haven't figured out how to reliably set up different
596 * single/dual channel state, if we even can.
598 if (intel_is_dual_link_lvds(dev
))
599 clock
.p2
= limit
->p2
.p2_fast
;
601 clock
.p2
= limit
->p2
.p2_slow
;
603 if (target
< limit
->p2
.dot_limit
)
604 clock
.p2
= limit
->p2
.p2_slow
;
606 clock
.p2
= limit
->p2
.p2_fast
;
609 memset(best_clock
, 0, sizeof(*best_clock
));
611 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
613 for (clock
.m2
= limit
->m2
.min
;
614 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
615 if (clock
.m2
>= clock
.m1
)
617 for (clock
.n
= limit
->n
.min
;
618 clock
.n
<= limit
->n
.max
; clock
.n
++) {
619 for (clock
.p1
= limit
->p1
.min
;
620 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
623 i9xx_clock(refclk
, &clock
);
624 if (!intel_PLL_is_valid(dev
, limit
,
628 clock
.p
!= match_clock
->p
)
631 this_err
= abs(clock
.dot
- target
);
632 if (this_err
< err
) {
641 return (err
!= target
);
645 pnv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
646 int target
, int refclk
, intel_clock_t
*match_clock
,
647 intel_clock_t
*best_clock
)
649 struct drm_device
*dev
= crtc
->dev
;
653 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
655 * For LVDS just rely on its current settings for dual-channel.
656 * We haven't figured out how to reliably set up different
657 * single/dual channel state, if we even can.
659 if (intel_is_dual_link_lvds(dev
))
660 clock
.p2
= limit
->p2
.p2_fast
;
662 clock
.p2
= limit
->p2
.p2_slow
;
664 if (target
< limit
->p2
.dot_limit
)
665 clock
.p2
= limit
->p2
.p2_slow
;
667 clock
.p2
= limit
->p2
.p2_fast
;
670 memset(best_clock
, 0, sizeof(*best_clock
));
672 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
674 for (clock
.m2
= limit
->m2
.min
;
675 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
676 for (clock
.n
= limit
->n
.min
;
677 clock
.n
<= limit
->n
.max
; clock
.n
++) {
678 for (clock
.p1
= limit
->p1
.min
;
679 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
682 pineview_clock(refclk
, &clock
);
683 if (!intel_PLL_is_valid(dev
, limit
,
687 clock
.p
!= match_clock
->p
)
690 this_err
= abs(clock
.dot
- target
);
691 if (this_err
< err
) {
700 return (err
!= target
);
704 g4x_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
705 int target
, int refclk
, intel_clock_t
*match_clock
,
706 intel_clock_t
*best_clock
)
708 struct drm_device
*dev
= crtc
->dev
;
712 /* approximately equals target * 0.00585 */
713 int err_most
= (target
>> 8) + (target
>> 9);
716 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
717 if (intel_is_dual_link_lvds(dev
))
718 clock
.p2
= limit
->p2
.p2_fast
;
720 clock
.p2
= limit
->p2
.p2_slow
;
722 if (target
< limit
->p2
.dot_limit
)
723 clock
.p2
= limit
->p2
.p2_slow
;
725 clock
.p2
= limit
->p2
.p2_fast
;
728 memset(best_clock
, 0, sizeof(*best_clock
));
729 max_n
= limit
->n
.max
;
730 /* based on hardware requirement, prefer smaller n to precision */
731 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
732 /* based on hardware requirement, prefere larger m1,m2 */
733 for (clock
.m1
= limit
->m1
.max
;
734 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
735 for (clock
.m2
= limit
->m2
.max
;
736 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
737 for (clock
.p1
= limit
->p1
.max
;
738 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
741 i9xx_clock(refclk
, &clock
);
742 if (!intel_PLL_is_valid(dev
, limit
,
746 this_err
= abs(clock
.dot
- target
);
747 if (this_err
< err_most
) {
761 vlv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
762 int target
, int refclk
, intel_clock_t
*match_clock
,
763 intel_clock_t
*best_clock
)
765 struct drm_device
*dev
= crtc
->dev
;
767 unsigned int bestppm
= 1000000;
768 /* min update 19.2 MHz */
769 int max_n
= min(limit
->n
.max
, refclk
/ 19200);
772 target
*= 5; /* fast clock */
774 memset(best_clock
, 0, sizeof(*best_clock
));
776 /* based on hardware requirement, prefer smaller n to precision */
777 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
778 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
779 for (clock
.p2
= limit
->p2
.p2_fast
; clock
.p2
>= limit
->p2
.p2_slow
;
780 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
781 clock
.p
= clock
.p1
* clock
.p2
;
782 /* based on hardware requirement, prefer bigger m1,m2 values */
783 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
; clock
.m1
++) {
784 unsigned int ppm
, diff
;
786 clock
.m2
= DIV_ROUND_CLOSEST(target
* clock
.p
* clock
.n
,
789 vlv_clock(refclk
, &clock
);
791 if (!intel_PLL_is_valid(dev
, limit
,
795 diff
= abs(clock
.dot
- target
);
796 ppm
= div_u64(1000000ULL * diff
, target
);
798 if (ppm
< 100 && clock
.p
> best_clock
->p
) {
804 if (bestppm
>= 10 && ppm
< bestppm
- 10) {
818 chv_find_best_dpll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
819 int target
, int refclk
, intel_clock_t
*match_clock
,
820 intel_clock_t
*best_clock
)
822 struct drm_device
*dev
= crtc
->dev
;
827 memset(best_clock
, 0, sizeof(*best_clock
));
830 * Based on hardware doc, the n always set to 1, and m1 always
831 * set to 2. If requires to support 200Mhz refclk, we need to
832 * revisit this because n may not 1 anymore.
834 clock
.n
= 1, clock
.m1
= 2;
835 target
*= 5; /* fast clock */
837 for (clock
.p1
= limit
->p1
.max
; clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
838 for (clock
.p2
= limit
->p2
.p2_fast
;
839 clock
.p2
>= limit
->p2
.p2_slow
;
840 clock
.p2
-= clock
.p2
> 10 ? 2 : 1) {
842 clock
.p
= clock
.p1
* clock
.p2
;
844 m2
= DIV_ROUND_CLOSEST_ULL(((uint64_t)target
* clock
.p
*
845 clock
.n
) << 22, refclk
* clock
.m1
);
847 if (m2
> INT_MAX
/clock
.m1
)
852 chv_clock(refclk
, &clock
);
854 if (!intel_PLL_is_valid(dev
, limit
, &clock
))
857 /* based on hardware requirement, prefer bigger p
859 if (clock
.p
> best_clock
->p
) {
869 bool intel_crtc_active(struct drm_crtc
*crtc
)
871 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
873 /* Be paranoid as we can arrive here with only partial
874 * state retrieved from the hardware during setup.
876 * We can ditch the adjusted_mode.crtc_clock check as soon
877 * as Haswell has gained clock readout/fastboot support.
879 * We can ditch the crtc->primary->fb check as soon as we can
880 * properly reconstruct framebuffers.
882 return intel_crtc
->active
&& crtc
->primary
->fb
&&
883 intel_crtc
->config
.adjusted_mode
.crtc_clock
;
886 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
889 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
890 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
892 return intel_crtc
->config
.cpu_transcoder
;
895 static void g4x_wait_for_vblank(struct drm_device
*dev
, int pipe
)
897 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
898 u32 frame
, frame_reg
= PIPE_FRMCOUNT_GM45(pipe
);
900 frame
= I915_READ(frame_reg
);
902 if (wait_for(I915_READ_NOTRACE(frame_reg
) != frame
, 50))
903 WARN(1, "vblank wait timed out\n");
907 * intel_wait_for_vblank - wait for vblank on a given pipe
909 * @pipe: pipe to wait for
911 * Wait for vblank to occur on a given pipe. Needed for various bits of
914 void intel_wait_for_vblank(struct drm_device
*dev
, int pipe
)
916 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
917 int pipestat_reg
= PIPESTAT(pipe
);
919 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5) {
920 g4x_wait_for_vblank(dev
, pipe
);
924 /* Clear existing vblank status. Note this will clear any other
925 * sticky status fields as well.
927 * This races with i915_driver_irq_handler() with the result
928 * that either function could miss a vblank event. Here it is not
929 * fatal, as we will either wait upon the next vblank interrupt or
930 * timeout. Generally speaking intel_wait_for_vblank() is only
931 * called during modeset at which time the GPU should be idle and
932 * should *not* be performing page flips and thus not waiting on
934 * Currently, the result of us stealing a vblank from the irq
935 * handler is that a single frame will be skipped during swapbuffers.
937 I915_WRITE(pipestat_reg
,
938 I915_READ(pipestat_reg
) | PIPE_VBLANK_INTERRUPT_STATUS
);
940 /* Wait for vblank interrupt bit to set */
941 if (wait_for(I915_READ(pipestat_reg
) &
942 PIPE_VBLANK_INTERRUPT_STATUS
,
944 DRM_DEBUG_KMS("vblank wait timed out\n");
947 static bool pipe_dsl_stopped(struct drm_device
*dev
, enum pipe pipe
)
949 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
950 u32 reg
= PIPEDSL(pipe
);
955 line_mask
= DSL_LINEMASK_GEN2
;
957 line_mask
= DSL_LINEMASK_GEN3
;
959 line1
= I915_READ(reg
) & line_mask
;
961 line2
= I915_READ(reg
) & line_mask
;
963 return line1
== line2
;
967 * intel_wait_for_pipe_off - wait for pipe to turn off
969 * @pipe: pipe to wait for
971 * After disabling a pipe, we can't wait for vblank in the usual way,
972 * spinning on the vblank interrupt status bit, since we won't actually
973 * see an interrupt when the pipe is disabled.
976 * wait for the pipe register state bit to turn off
979 * wait for the display line value to settle (it usually
980 * ends up stopping at the start of the next frame).
983 void intel_wait_for_pipe_off(struct drm_device
*dev
, int pipe
)
985 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
986 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
989 if (INTEL_INFO(dev
)->gen
>= 4) {
990 int reg
= PIPECONF(cpu_transcoder
);
992 /* Wait for the Pipe State to go off */
993 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
995 WARN(1, "pipe_off wait timed out\n");
997 /* Wait for the display line to settle */
998 if (wait_for(pipe_dsl_stopped(dev
, pipe
), 100))
999 WARN(1, "pipe_off wait timed out\n");
1004 * ibx_digital_port_connected - is the specified port connected?
1005 * @dev_priv: i915 private structure
1006 * @port: the port to test
1008 * Returns true if @port is connected, false otherwise.
1010 bool ibx_digital_port_connected(struct drm_i915_private
*dev_priv
,
1011 struct intel_digital_port
*port
)
1015 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1016 switch (port
->port
) {
1018 bit
= SDE_PORTB_HOTPLUG
;
1021 bit
= SDE_PORTC_HOTPLUG
;
1024 bit
= SDE_PORTD_HOTPLUG
;
1030 switch (port
->port
) {
1032 bit
= SDE_PORTB_HOTPLUG_CPT
;
1035 bit
= SDE_PORTC_HOTPLUG_CPT
;
1038 bit
= SDE_PORTD_HOTPLUG_CPT
;
1045 return I915_READ(SDEISR
) & bit
;
1048 static const char *state_string(bool enabled
)
1050 return enabled
? "on" : "off";
1053 /* Only for pre-ILK configs */
1054 void assert_pll(struct drm_i915_private
*dev_priv
,
1055 enum pipe pipe
, bool state
)
1062 val
= I915_READ(reg
);
1063 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1064 WARN(cur_state
!= state
,
1065 "PLL state assertion failure (expected %s, current %s)\n",
1066 state_string(state
), state_string(cur_state
));
1069 /* XXX: the dsi pll is shared between MIPI DSI ports */
1070 static void assert_dsi_pll(struct drm_i915_private
*dev_priv
, bool state
)
1075 mutex_lock(&dev_priv
->dpio_lock
);
1076 val
= vlv_cck_read(dev_priv
, CCK_REG_DSI_PLL_CONTROL
);
1077 mutex_unlock(&dev_priv
->dpio_lock
);
1079 cur_state
= val
& DSI_PLL_VCO_EN
;
1080 WARN(cur_state
!= state
,
1081 "DSI PLL state assertion failure (expected %s, current %s)\n",
1082 state_string(state
), state_string(cur_state
));
1084 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
1085 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
1087 struct intel_shared_dpll
*
1088 intel_crtc_to_shared_dpll(struct intel_crtc
*crtc
)
1090 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
1092 if (crtc
->config
.shared_dpll
< 0)
1095 return &dev_priv
->shared_dplls
[crtc
->config
.shared_dpll
];
1099 void assert_shared_dpll(struct drm_i915_private
*dev_priv
,
1100 struct intel_shared_dpll
*pll
,
1104 struct intel_dpll_hw_state hw_state
;
1107 "asserting DPLL %s with no DPLL\n", state_string(state
)))
1110 cur_state
= pll
->get_hw_state(dev_priv
, pll
, &hw_state
);
1111 WARN(cur_state
!= state
,
1112 "%s assertion failure (expected %s, current %s)\n",
1113 pll
->name
, state_string(state
), state_string(cur_state
));
1116 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1117 enum pipe pipe
, bool state
)
1122 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1125 if (HAS_DDI(dev_priv
->dev
)) {
1126 /* DDI does not have a specific FDI_TX register */
1127 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1128 val
= I915_READ(reg
);
1129 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1131 reg
= FDI_TX_CTL(pipe
);
1132 val
= I915_READ(reg
);
1133 cur_state
= !!(val
& FDI_TX_ENABLE
);
1135 WARN(cur_state
!= state
,
1136 "FDI TX state assertion failure (expected %s, current %s)\n",
1137 state_string(state
), state_string(cur_state
));
1139 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1140 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1142 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1143 enum pipe pipe
, bool state
)
1149 reg
= FDI_RX_CTL(pipe
);
1150 val
= I915_READ(reg
);
1151 cur_state
= !!(val
& FDI_RX_ENABLE
);
1152 WARN(cur_state
!= state
,
1153 "FDI RX state assertion failure (expected %s, current %s)\n",
1154 state_string(state
), state_string(cur_state
));
1156 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1157 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1159 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1165 /* ILK FDI PLL is always enabled */
1166 if (INTEL_INFO(dev_priv
->dev
)->gen
== 5)
1169 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1170 if (HAS_DDI(dev_priv
->dev
))
1173 reg
= FDI_TX_CTL(pipe
);
1174 val
= I915_READ(reg
);
1175 WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1178 void assert_fdi_rx_pll(struct drm_i915_private
*dev_priv
,
1179 enum pipe pipe
, bool state
)
1185 reg
= FDI_RX_CTL(pipe
);
1186 val
= I915_READ(reg
);
1187 cur_state
= !!(val
& FDI_RX_PLL_ENABLE
);
1188 WARN(cur_state
!= state
,
1189 "FDI RX PLL assertion failure (expected %s, current %s)\n",
1190 state_string(state
), state_string(cur_state
));
1193 static void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1196 int pp_reg
, lvds_reg
;
1198 enum pipe panel_pipe
= PIPE_A
;
1201 if (HAS_PCH_SPLIT(dev_priv
->dev
)) {
1202 pp_reg
= PCH_PP_CONTROL
;
1203 lvds_reg
= PCH_LVDS
;
1205 pp_reg
= PP_CONTROL
;
1209 val
= I915_READ(pp_reg
);
1210 if (!(val
& PANEL_POWER_ON
) ||
1211 ((val
& PANEL_UNLOCK_REGS
) == PANEL_UNLOCK_REGS
))
1214 if (I915_READ(lvds_reg
) & LVDS_PIPEB_SELECT
)
1215 panel_pipe
= PIPE_B
;
1217 WARN(panel_pipe
== pipe
&& locked
,
1218 "panel assertion failure, pipe %c regs locked\n",
1222 static void assert_cursor(struct drm_i915_private
*dev_priv
,
1223 enum pipe pipe
, bool state
)
1225 struct drm_device
*dev
= dev_priv
->dev
;
1228 if (IS_845G(dev
) || IS_I865G(dev
))
1229 cur_state
= I915_READ(_CURACNTR
) & CURSOR_ENABLE
;
1231 cur_state
= I915_READ(CURCNTR(pipe
)) & CURSOR_MODE
;
1233 WARN(cur_state
!= state
,
1234 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
1235 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1237 #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
1238 #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
1240 void assert_pipe(struct drm_i915_private
*dev_priv
,
1241 enum pipe pipe
, bool state
)
1246 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1249 /* if we need the pipe A quirk it must be always on */
1250 if (pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
)
1253 if (!intel_display_power_enabled(dev_priv
,
1254 POWER_DOMAIN_TRANSCODER(cpu_transcoder
))) {
1257 reg
= PIPECONF(cpu_transcoder
);
1258 val
= I915_READ(reg
);
1259 cur_state
= !!(val
& PIPECONF_ENABLE
);
1262 WARN(cur_state
!= state
,
1263 "pipe %c assertion failure (expected %s, current %s)\n",
1264 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1267 static void assert_plane(struct drm_i915_private
*dev_priv
,
1268 enum plane plane
, bool state
)
1274 reg
= DSPCNTR(plane
);
1275 val
= I915_READ(reg
);
1276 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1277 WARN(cur_state
!= state
,
1278 "plane %c assertion failure (expected %s, current %s)\n",
1279 plane_name(plane
), state_string(state
), state_string(cur_state
));
1282 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1283 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1285 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1288 struct drm_device
*dev
= dev_priv
->dev
;
1293 /* Primary planes are fixed to pipes on gen4+ */
1294 if (INTEL_INFO(dev
)->gen
>= 4) {
1295 reg
= DSPCNTR(pipe
);
1296 val
= I915_READ(reg
);
1297 WARN(val
& DISPLAY_PLANE_ENABLE
,
1298 "plane %c assertion failure, should be disabled but not\n",
1303 /* Need to check both planes against the pipe */
1306 val
= I915_READ(reg
);
1307 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1308 DISPPLANE_SEL_PIPE_SHIFT
;
1309 WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1310 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1311 plane_name(i
), pipe_name(pipe
));
1315 static void assert_sprites_disabled(struct drm_i915_private
*dev_priv
,
1318 struct drm_device
*dev
= dev_priv
->dev
;
1322 if (IS_VALLEYVIEW(dev
)) {
1323 for_each_sprite(pipe
, sprite
) {
1324 reg
= SPCNTR(pipe
, sprite
);
1325 val
= I915_READ(reg
);
1326 WARN(val
& SP_ENABLE
,
1327 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1328 sprite_name(pipe
, sprite
), pipe_name(pipe
));
1330 } else if (INTEL_INFO(dev
)->gen
>= 7) {
1332 val
= I915_READ(reg
);
1333 WARN(val
& SPRITE_ENABLE
,
1334 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1335 plane_name(pipe
), pipe_name(pipe
));
1336 } else if (INTEL_INFO(dev
)->gen
>= 5) {
1337 reg
= DVSCNTR(pipe
);
1338 val
= I915_READ(reg
);
1339 WARN(val
& DVS_ENABLE
,
1340 "sprite %c assertion failure, should be off on pipe %c but is still active\n",
1341 plane_name(pipe
), pipe_name(pipe
));
1345 static void assert_vblank_disabled(struct drm_crtc
*crtc
)
1347 if (WARN_ON(drm_crtc_vblank_get(crtc
) == 0))
1348 drm_crtc_vblank_put(crtc
);
1351 static void ibx_assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1356 WARN_ON(!(HAS_PCH_IBX(dev_priv
->dev
) || HAS_PCH_CPT(dev_priv
->dev
)));
1358 val
= I915_READ(PCH_DREF_CONTROL
);
1359 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1360 DREF_SUPERSPREAD_SOURCE_MASK
));
1361 WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1364 static void assert_pch_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1371 reg
= PCH_TRANSCONF(pipe
);
1372 val
= I915_READ(reg
);
1373 enabled
= !!(val
& TRANS_ENABLE
);
1375 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1379 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1380 enum pipe pipe
, u32 port_sel
, u32 val
)
1382 if ((val
& DP_PORT_EN
) == 0)
1385 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1386 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1387 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1388 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1390 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1391 if ((val
& DP_PIPE_MASK_CHV
) != DP_PIPE_SELECT_CHV(pipe
))
1394 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1400 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1401 enum pipe pipe
, u32 val
)
1403 if ((val
& SDVO_ENABLE
) == 0)
1406 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1407 if ((val
& SDVO_PIPE_SEL_MASK_CPT
) != SDVO_PIPE_SEL_CPT(pipe
))
1409 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1410 if ((val
& SDVO_PIPE_SEL_MASK_CHV
) != SDVO_PIPE_SEL_CHV(pipe
))
1413 if ((val
& SDVO_PIPE_SEL_MASK
) != SDVO_PIPE_SEL(pipe
))
1419 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1420 enum pipe pipe
, u32 val
)
1422 if ((val
& LVDS_PORT_EN
) == 0)
1425 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1426 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1429 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1435 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1436 enum pipe pipe
, u32 val
)
1438 if ((val
& ADPA_DAC_ENABLE
) == 0)
1440 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1441 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1444 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1450 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1451 enum pipe pipe
, int reg
, u32 port_sel
)
1453 u32 val
= I915_READ(reg
);
1454 WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1455 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1456 reg
, pipe_name(pipe
));
1458 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1459 && (val
& DP_PIPEB_SELECT
),
1460 "IBX PCH dp port still using transcoder B\n");
1463 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1464 enum pipe pipe
, int reg
)
1466 u32 val
= I915_READ(reg
);
1467 WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1468 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1469 reg
, pipe_name(pipe
));
1471 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& SDVO_ENABLE
) == 0
1472 && (val
& SDVO_PIPE_B_SELECT
),
1473 "IBX PCH hdmi port still using transcoder B\n");
1476 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1482 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1483 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1484 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1487 val
= I915_READ(reg
);
1488 WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1489 "PCH VGA enabled on transcoder %c, should be disabled\n",
1493 val
= I915_READ(reg
);
1494 WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1495 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1498 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIB
);
1499 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMIC
);
1500 assert_pch_hdmi_disabled(dev_priv
, pipe
, PCH_HDMID
);
1503 static void intel_init_dpio(struct drm_device
*dev
)
1505 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1507 if (!IS_VALLEYVIEW(dev
))
1511 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
1512 * CHV x1 PHY (DP/HDMI D)
1513 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
1515 if (IS_CHERRYVIEW(dev
)) {
1516 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO_2
;
1517 DPIO_PHY_IOSF_PORT(DPIO_PHY1
) = IOSF_PORT_DPIO
;
1519 DPIO_PHY_IOSF_PORT(DPIO_PHY0
) = IOSF_PORT_DPIO
;
1523 static void vlv_enable_pll(struct intel_crtc
*crtc
)
1525 struct drm_device
*dev
= crtc
->base
.dev
;
1526 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1527 int reg
= DPLL(crtc
->pipe
);
1528 u32 dpll
= crtc
->config
.dpll_hw_state
.dpll
;
1530 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1532 /* No really, not for ILK+ */
1533 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
));
1535 /* PLL is protected by panel, make sure we can write it */
1536 if (IS_MOBILE(dev_priv
->dev
) && !IS_I830(dev_priv
->dev
))
1537 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1539 I915_WRITE(reg
, dpll
);
1543 if (wait_for(((I915_READ(reg
) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1544 DRM_ERROR("DPLL %d failed to lock\n", crtc
->pipe
);
1546 I915_WRITE(DPLL_MD(crtc
->pipe
), crtc
->config
.dpll_hw_state
.dpll_md
);
1547 POSTING_READ(DPLL_MD(crtc
->pipe
));
1549 /* We do this three times for luck */
1550 I915_WRITE(reg
, dpll
);
1552 udelay(150); /* wait for warmup */
1553 I915_WRITE(reg
, dpll
);
1555 udelay(150); /* wait for warmup */
1556 I915_WRITE(reg
, dpll
);
1558 udelay(150); /* wait for warmup */
1561 static void chv_enable_pll(struct intel_crtc
*crtc
)
1563 struct drm_device
*dev
= crtc
->base
.dev
;
1564 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1565 int pipe
= crtc
->pipe
;
1566 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1569 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1571 BUG_ON(!IS_CHERRYVIEW(dev_priv
->dev
));
1573 mutex_lock(&dev_priv
->dpio_lock
);
1575 /* Enable back the 10bit clock to display controller */
1576 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1577 tmp
|= DPIO_DCLKP_EN
;
1578 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), tmp
);
1581 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1586 I915_WRITE(DPLL(pipe
), crtc
->config
.dpll_hw_state
.dpll
);
1588 /* Check PLL is locked */
1589 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
1590 DRM_ERROR("PLL %d failed to lock\n", pipe
);
1592 /* not sure when this should be written */
1593 I915_WRITE(DPLL_MD(pipe
), crtc
->config
.dpll_hw_state
.dpll_md
);
1594 POSTING_READ(DPLL_MD(pipe
));
1596 mutex_unlock(&dev_priv
->dpio_lock
);
1599 static void i9xx_enable_pll(struct intel_crtc
*crtc
)
1601 struct drm_device
*dev
= crtc
->base
.dev
;
1602 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1603 int reg
= DPLL(crtc
->pipe
);
1604 u32 dpll
= crtc
->config
.dpll_hw_state
.dpll
;
1606 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
1608 /* No really, not for ILK+ */
1609 BUG_ON(INTEL_INFO(dev
)->gen
>= 5);
1611 /* PLL is protected by panel, make sure we can write it */
1612 if (IS_MOBILE(dev
) && !IS_I830(dev
))
1613 assert_panel_unlocked(dev_priv
, crtc
->pipe
);
1615 I915_WRITE(reg
, dpll
);
1617 /* Wait for the clocks to stabilize. */
1621 if (INTEL_INFO(dev
)->gen
>= 4) {
1622 I915_WRITE(DPLL_MD(crtc
->pipe
),
1623 crtc
->config
.dpll_hw_state
.dpll_md
);
1625 /* The pixel multiplier can only be updated once the
1626 * DPLL is enabled and the clocks are stable.
1628 * So write it again.
1630 I915_WRITE(reg
, dpll
);
1633 /* We do this three times for luck */
1634 I915_WRITE(reg
, dpll
);
1636 udelay(150); /* wait for warmup */
1637 I915_WRITE(reg
, dpll
);
1639 udelay(150); /* wait for warmup */
1640 I915_WRITE(reg
, dpll
);
1642 udelay(150); /* wait for warmup */
1646 * i9xx_disable_pll - disable a PLL
1647 * @dev_priv: i915 private structure
1648 * @pipe: pipe PLL to disable
1650 * Disable the PLL for @pipe, making sure the pipe is off first.
1652 * Note! This is for pre-ILK only.
1654 static void i9xx_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1656 /* Don't disable pipe A or pipe A PLLs if needed */
1657 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
1660 /* Make sure the pipe isn't still relying on us */
1661 assert_pipe_disabled(dev_priv
, pipe
);
1663 I915_WRITE(DPLL(pipe
), 0);
1664 POSTING_READ(DPLL(pipe
));
1667 static void vlv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1671 /* Make sure the pipe isn't still relying on us */
1672 assert_pipe_disabled(dev_priv
, pipe
);
1675 * Leave integrated clock source and reference clock enabled for pipe B.
1676 * The latter is needed for VGA hotplug / manual detection.
1679 val
= DPLL_INTEGRATED_CRI_CLK_VLV
| DPLL_REFA_CLK_ENABLE_VLV
;
1680 I915_WRITE(DPLL(pipe
), val
);
1681 POSTING_READ(DPLL(pipe
));
1685 static void chv_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1687 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
1690 /* Make sure the pipe isn't still relying on us */
1691 assert_pipe_disabled(dev_priv
, pipe
);
1693 /* Set PLL en = 0 */
1694 val
= DPLL_SSC_REF_CLOCK_CHV
| DPLL_REFA_CLK_ENABLE_VLV
;
1696 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1697 I915_WRITE(DPLL(pipe
), val
);
1698 POSTING_READ(DPLL(pipe
));
1700 mutex_lock(&dev_priv
->dpio_lock
);
1702 /* Disable 10bit clock to display controller */
1703 val
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
));
1704 val
&= ~DPIO_DCLKP_EN
;
1705 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
), val
);
1707 /* disable left/right clock distribution */
1708 if (pipe
!= PIPE_B
) {
1709 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
);
1710 val
&= ~(CHV_BUFLEFTENA1_MASK
| CHV_BUFRIGHTENA1_MASK
);
1711 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW5_CH0
, val
);
1713 val
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
);
1714 val
&= ~(CHV_BUFLEFTENA2_MASK
| CHV_BUFRIGHTENA2_MASK
);
1715 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW1_CH1
, val
);
1718 mutex_unlock(&dev_priv
->dpio_lock
);
1721 void vlv_wait_port_ready(struct drm_i915_private
*dev_priv
,
1722 struct intel_digital_port
*dport
)
1727 switch (dport
->port
) {
1729 port_mask
= DPLL_PORTB_READY_MASK
;
1733 port_mask
= DPLL_PORTC_READY_MASK
;
1737 port_mask
= DPLL_PORTD_READY_MASK
;
1738 dpll_reg
= DPIO_PHY_STATUS
;
1744 if (wait_for((I915_READ(dpll_reg
) & port_mask
) == 0, 1000))
1745 WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
1746 port_name(dport
->port
), I915_READ(dpll_reg
));
1749 static void intel_prepare_shared_dpll(struct intel_crtc
*crtc
)
1751 struct drm_device
*dev
= crtc
->base
.dev
;
1752 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1753 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1755 if (WARN_ON(pll
== NULL
))
1758 WARN_ON(!pll
->refcount
);
1759 if (pll
->active
== 0) {
1760 DRM_DEBUG_DRIVER("setting up %s\n", pll
->name
);
1762 assert_shared_dpll_disabled(dev_priv
, pll
);
1764 pll
->mode_set(dev_priv
, pll
);
1769 * intel_enable_shared_dpll - enable PCH PLL
1770 * @dev_priv: i915 private structure
1771 * @pipe: pipe PLL to enable
1773 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1774 * drives the transcoder clock.
1776 static void intel_enable_shared_dpll(struct intel_crtc
*crtc
)
1778 struct drm_device
*dev
= crtc
->base
.dev
;
1779 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1780 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1782 if (WARN_ON(pll
== NULL
))
1785 if (WARN_ON(pll
->refcount
== 0))
1788 DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
1789 pll
->name
, pll
->active
, pll
->on
,
1790 crtc
->base
.base
.id
);
1792 if (pll
->active
++) {
1794 assert_shared_dpll_enabled(dev_priv
, pll
);
1799 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
1801 DRM_DEBUG_KMS("enabling %s\n", pll
->name
);
1802 pll
->enable(dev_priv
, pll
);
1806 static void intel_disable_shared_dpll(struct intel_crtc
*crtc
)
1808 struct drm_device
*dev
= crtc
->base
.dev
;
1809 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1810 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
1812 /* PCH only available on ILK+ */
1813 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1814 if (WARN_ON(pll
== NULL
))
1817 if (WARN_ON(pll
->refcount
== 0))
1820 DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
1821 pll
->name
, pll
->active
, pll
->on
,
1822 crtc
->base
.base
.id
);
1824 if (WARN_ON(pll
->active
== 0)) {
1825 assert_shared_dpll_disabled(dev_priv
, pll
);
1829 assert_shared_dpll_enabled(dev_priv
, pll
);
1834 DRM_DEBUG_KMS("disabling %s\n", pll
->name
);
1835 pll
->disable(dev_priv
, pll
);
1838 intel_display_power_put(dev_priv
, POWER_DOMAIN_PLLS
);
1841 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1844 struct drm_device
*dev
= dev_priv
->dev
;
1845 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1846 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1847 uint32_t reg
, val
, pipeconf_val
;
1849 /* PCH only available on ILK+ */
1850 BUG_ON(INTEL_INFO(dev
)->gen
< 5);
1852 /* Make sure PCH DPLL is enabled */
1853 assert_shared_dpll_enabled(dev_priv
,
1854 intel_crtc_to_shared_dpll(intel_crtc
));
1856 /* FDI must be feeding us bits for PCH ports */
1857 assert_fdi_tx_enabled(dev_priv
, pipe
);
1858 assert_fdi_rx_enabled(dev_priv
, pipe
);
1860 if (HAS_PCH_CPT(dev
)) {
1861 /* Workaround: Set the timing override bit before enabling the
1862 * pch transcoder. */
1863 reg
= TRANS_CHICKEN2(pipe
);
1864 val
= I915_READ(reg
);
1865 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1866 I915_WRITE(reg
, val
);
1869 reg
= PCH_TRANSCONF(pipe
);
1870 val
= I915_READ(reg
);
1871 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1873 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1875 * make the BPC in transcoder be consistent with
1876 * that in pipeconf reg.
1878 val
&= ~PIPECONF_BPC_MASK
;
1879 val
|= pipeconf_val
& PIPECONF_BPC_MASK
;
1882 val
&= ~TRANS_INTERLACE_MASK
;
1883 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1884 if (HAS_PCH_IBX(dev_priv
->dev
) &&
1885 intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
))
1886 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1888 val
|= TRANS_INTERLACED
;
1890 val
|= TRANS_PROGRESSIVE
;
1892 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1893 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
1894 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe
));
1897 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1898 enum transcoder cpu_transcoder
)
1900 u32 val
, pipeconf_val
;
1902 /* PCH only available on ILK+ */
1903 BUG_ON(INTEL_INFO(dev_priv
->dev
)->gen
< 5);
1905 /* FDI must be feeding us bits for PCH ports */
1906 assert_fdi_tx_enabled(dev_priv
, (enum pipe
) cpu_transcoder
);
1907 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1909 /* Workaround: set timing override bit. */
1910 val
= I915_READ(_TRANSA_CHICKEN2
);
1911 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1912 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1915 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1917 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1918 PIPECONF_INTERLACED_ILK
)
1919 val
|= TRANS_INTERLACED
;
1921 val
|= TRANS_PROGRESSIVE
;
1923 I915_WRITE(LPT_TRANSCONF
, val
);
1924 if (wait_for(I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
, 100))
1925 DRM_ERROR("Failed to enable PCH transcoder\n");
1928 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1931 struct drm_device
*dev
= dev_priv
->dev
;
1934 /* FDI relies on the transcoder */
1935 assert_fdi_tx_disabled(dev_priv
, pipe
);
1936 assert_fdi_rx_disabled(dev_priv
, pipe
);
1938 /* Ports must be off as well */
1939 assert_pch_ports_disabled(dev_priv
, pipe
);
1941 reg
= PCH_TRANSCONF(pipe
);
1942 val
= I915_READ(reg
);
1943 val
&= ~TRANS_ENABLE
;
1944 I915_WRITE(reg
, val
);
1945 /* wait for PCH transcoder off, transcoder state */
1946 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
1947 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe
));
1949 if (!HAS_PCH_IBX(dev
)) {
1950 /* Workaround: Clear the timing override chicken bit again. */
1951 reg
= TRANS_CHICKEN2(pipe
);
1952 val
= I915_READ(reg
);
1953 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1954 I915_WRITE(reg
, val
);
1958 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1962 val
= I915_READ(LPT_TRANSCONF
);
1963 val
&= ~TRANS_ENABLE
;
1964 I915_WRITE(LPT_TRANSCONF
, val
);
1965 /* wait for PCH transcoder off, transcoder state */
1966 if (wait_for((I915_READ(LPT_TRANSCONF
) & TRANS_STATE_ENABLE
) == 0, 50))
1967 DRM_ERROR("Failed to disable PCH transcoder\n");
1969 /* Workaround: clear timing override bit. */
1970 val
= I915_READ(_TRANSA_CHICKEN2
);
1971 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1972 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1976 * intel_enable_pipe - enable a pipe, asserting requirements
1977 * @crtc: crtc responsible for the pipe
1979 * Enable @crtc's pipe, making sure that various hardware specific requirements
1980 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1982 static void intel_enable_pipe(struct intel_crtc
*crtc
)
1984 struct drm_device
*dev
= crtc
->base
.dev
;
1985 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1986 enum pipe pipe
= crtc
->pipe
;
1987 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1989 enum pipe pch_transcoder
;
1993 assert_planes_disabled(dev_priv
, pipe
);
1994 assert_cursor_disabled(dev_priv
, pipe
);
1995 assert_sprites_disabled(dev_priv
, pipe
);
1997 if (HAS_PCH_LPT(dev_priv
->dev
))
1998 pch_transcoder
= TRANSCODER_A
;
2000 pch_transcoder
= pipe
;
2003 * A pipe without a PLL won't actually be able to drive bits from
2004 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
2007 if (!HAS_PCH_SPLIT(dev_priv
->dev
))
2008 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DSI
))
2009 assert_dsi_pll_enabled(dev_priv
);
2011 assert_pll_enabled(dev_priv
, pipe
);
2013 if (crtc
->config
.has_pch_encoder
) {
2014 /* if driving the PCH, we need FDI enabled */
2015 assert_fdi_rx_pll_enabled(dev_priv
, pch_transcoder
);
2016 assert_fdi_tx_pll_enabled(dev_priv
,
2017 (enum pipe
) cpu_transcoder
);
2019 /* FIXME: assert CPU port conditions for SNB+ */
2022 reg
= PIPECONF(cpu_transcoder
);
2023 val
= I915_READ(reg
);
2024 if (val
& PIPECONF_ENABLE
) {
2025 WARN_ON(!(pipe
== PIPE_A
&&
2026 dev_priv
->quirks
& QUIRK_PIPEA_FORCE
));
2030 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
2035 * intel_disable_pipe - disable a pipe, asserting requirements
2036 * @dev_priv: i915 private structure
2037 * @pipe: pipe to disable
2039 * Disable @pipe, making sure that various hardware specific requirements
2040 * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
2042 * @pipe should be %PIPE_A or %PIPE_B.
2044 * Will wait until the pipe has shut down before returning.
2046 static void intel_disable_pipe(struct drm_i915_private
*dev_priv
,
2049 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
2055 * Make sure planes won't keep trying to pump pixels to us,
2056 * or we might hang the display.
2058 assert_planes_disabled(dev_priv
, pipe
);
2059 assert_cursor_disabled(dev_priv
, pipe
);
2060 assert_sprites_disabled(dev_priv
, pipe
);
2062 /* Don't disable pipe A or pipe A PLLs if needed */
2063 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
2066 reg
= PIPECONF(cpu_transcoder
);
2067 val
= I915_READ(reg
);
2068 if ((val
& PIPECONF_ENABLE
) == 0)
2071 I915_WRITE(reg
, val
& ~PIPECONF_ENABLE
);
2072 intel_wait_for_pipe_off(dev_priv
->dev
, pipe
);
2076 * Plane regs are double buffered, going from enabled->disabled needs a
2077 * trigger in order to latch. The display address reg provides this.
2079 void intel_flush_primary_plane(struct drm_i915_private
*dev_priv
,
2082 struct drm_device
*dev
= dev_priv
->dev
;
2083 u32 reg
= INTEL_INFO(dev
)->gen
>= 4 ? DSPSURF(plane
) : DSPADDR(plane
);
2085 I915_WRITE(reg
, I915_READ(reg
));
2090 * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
2091 * @plane: plane to be enabled
2092 * @crtc: crtc for the plane
2094 * Enable @plane on @crtc, making sure that the pipe is running first.
2096 static void intel_enable_primary_hw_plane(struct drm_plane
*plane
,
2097 struct drm_crtc
*crtc
)
2099 struct drm_device
*dev
= plane
->dev
;
2100 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2101 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2103 /* If the pipe isn't enabled, we can't pump pixels and may hang */
2104 assert_pipe_enabled(dev_priv
, intel_crtc
->pipe
);
2106 if (intel_crtc
->primary_enabled
)
2109 intel_crtc
->primary_enabled
= true;
2111 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
2115 * BDW signals flip done immediately if the plane
2116 * is disabled, even if the plane enable is already
2117 * armed to occur at the next vblank :(
2119 if (IS_BROADWELL(dev
))
2120 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2124 * intel_disable_primary_hw_plane - disable the primary hardware plane
2125 * @plane: plane to be disabled
2126 * @crtc: crtc for the plane
2128 * Disable @plane on @crtc, making sure that the pipe is running first.
2130 static void intel_disable_primary_hw_plane(struct drm_plane
*plane
,
2131 struct drm_crtc
*crtc
)
2133 struct drm_device
*dev
= plane
->dev
;
2134 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2135 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2137 assert_pipe_enabled(dev_priv
, intel_crtc
->pipe
);
2139 if (!intel_crtc
->primary_enabled
)
2142 intel_crtc
->primary_enabled
= false;
2144 dev_priv
->display
.update_primary_plane(crtc
, plane
->fb
,
2148 static bool need_vtd_wa(struct drm_device
*dev
)
2150 #ifdef CONFIG_INTEL_IOMMU
2151 if (INTEL_INFO(dev
)->gen
>= 6 && intel_iommu_gfx_mapped
)
2157 static int intel_align_height(struct drm_device
*dev
, int height
, bool tiled
)
2161 tile_height
= tiled
? (IS_GEN2(dev
) ? 16 : 8) : 1;
2162 return ALIGN(height
, tile_height
);
2166 intel_pin_and_fence_fb_obj(struct drm_device
*dev
,
2167 struct drm_i915_gem_object
*obj
,
2168 struct intel_engine_cs
*pipelined
)
2170 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2174 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
2176 switch (obj
->tiling_mode
) {
2177 case I915_TILING_NONE
:
2178 if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
2179 alignment
= 128 * 1024;
2180 else if (INTEL_INFO(dev
)->gen
>= 4)
2181 alignment
= 4 * 1024;
2183 alignment
= 64 * 1024;
2186 /* pin() will align the object as required by fence */
2190 WARN(1, "Y tiled bo slipped through, driver bug!\n");
2196 /* Note that the w/a also requires 64 PTE of padding following the
2197 * bo. We currently fill all unused PTE with the shadow page and so
2198 * we should always have valid PTE following the scanout preventing
2201 if (need_vtd_wa(dev
) && alignment
< 256 * 1024)
2202 alignment
= 256 * 1024;
2204 dev_priv
->mm
.interruptible
= false;
2205 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
);
2207 goto err_interruptible
;
2209 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2210 * fence, whereas 965+ only requires a fence if using
2211 * framebuffer compression. For simplicity, we always install
2212 * a fence as the cost is not that onerous.
2214 ret
= i915_gem_object_get_fence(obj
);
2218 i915_gem_object_pin_fence(obj
);
2220 dev_priv
->mm
.interruptible
= true;
2224 i915_gem_object_unpin_from_display_plane(obj
);
2226 dev_priv
->mm
.interruptible
= true;
2230 void intel_unpin_fb_obj(struct drm_i915_gem_object
*obj
)
2232 WARN_ON(!mutex_is_locked(&obj
->base
.dev
->struct_mutex
));
2234 i915_gem_object_unpin_fence(obj
);
2235 i915_gem_object_unpin_from_display_plane(obj
);
2238 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2239 * is assumed to be a power-of-two. */
2240 unsigned long intel_gen4_compute_page_offset(int *x
, int *y
,
2241 unsigned int tiling_mode
,
2245 if (tiling_mode
!= I915_TILING_NONE
) {
2246 unsigned int tile_rows
, tiles
;
2251 tiles
= *x
/ (512/cpp
);
2254 return tile_rows
* pitch
* 8 + tiles
* 4096;
2256 unsigned int offset
;
2258 offset
= *y
* pitch
+ *x
* cpp
;
2260 *x
= (offset
& 4095) / cpp
;
2261 return offset
& -4096;
2265 int intel_format_to_fourcc(int format
)
2268 case DISPPLANE_8BPP
:
2269 return DRM_FORMAT_C8
;
2270 case DISPPLANE_BGRX555
:
2271 return DRM_FORMAT_XRGB1555
;
2272 case DISPPLANE_BGRX565
:
2273 return DRM_FORMAT_RGB565
;
2275 case DISPPLANE_BGRX888
:
2276 return DRM_FORMAT_XRGB8888
;
2277 case DISPPLANE_RGBX888
:
2278 return DRM_FORMAT_XBGR8888
;
2279 case DISPPLANE_BGRX101010
:
2280 return DRM_FORMAT_XRGB2101010
;
2281 case DISPPLANE_RGBX101010
:
2282 return DRM_FORMAT_XBGR2101010
;
2286 static bool intel_alloc_plane_obj(struct intel_crtc
*crtc
,
2287 struct intel_plane_config
*plane_config
)
2289 struct drm_device
*dev
= crtc
->base
.dev
;
2290 struct drm_i915_gem_object
*obj
= NULL
;
2291 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
2292 u32 base
= plane_config
->base
;
2294 if (plane_config
->size
== 0)
2297 obj
= i915_gem_object_create_stolen_for_preallocated(dev
, base
, base
,
2298 plane_config
->size
);
2302 if (plane_config
->tiled
) {
2303 obj
->tiling_mode
= I915_TILING_X
;
2304 obj
->stride
= crtc
->base
.primary
->fb
->pitches
[0];
2307 mode_cmd
.pixel_format
= crtc
->base
.primary
->fb
->pixel_format
;
2308 mode_cmd
.width
= crtc
->base
.primary
->fb
->width
;
2309 mode_cmd
.height
= crtc
->base
.primary
->fb
->height
;
2310 mode_cmd
.pitches
[0] = crtc
->base
.primary
->fb
->pitches
[0];
2312 mutex_lock(&dev
->struct_mutex
);
2314 if (intel_framebuffer_init(dev
, to_intel_framebuffer(crtc
->base
.primary
->fb
),
2316 DRM_DEBUG_KMS("intel fb init failed\n");
2320 obj
->frontbuffer_bits
= INTEL_FRONTBUFFER_PRIMARY(crtc
->pipe
);
2321 mutex_unlock(&dev
->struct_mutex
);
2323 DRM_DEBUG_KMS("plane fb obj %p\n", obj
);
2327 drm_gem_object_unreference(&obj
->base
);
2328 mutex_unlock(&dev
->struct_mutex
);
2332 static void intel_find_plane_obj(struct intel_crtc
*intel_crtc
,
2333 struct intel_plane_config
*plane_config
)
2335 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2337 struct intel_crtc
*i
;
2338 struct drm_i915_gem_object
*obj
;
2340 if (!intel_crtc
->base
.primary
->fb
)
2343 if (intel_alloc_plane_obj(intel_crtc
, plane_config
))
2346 kfree(intel_crtc
->base
.primary
->fb
);
2347 intel_crtc
->base
.primary
->fb
= NULL
;
2350 * Failed to alloc the obj, check to see if we should share
2351 * an fb with another CRTC instead
2353 for_each_crtc(dev
, c
) {
2354 i
= to_intel_crtc(c
);
2356 if (c
== &intel_crtc
->base
)
2362 obj
= intel_fb_obj(c
->primary
->fb
);
2366 if (i915_gem_obj_ggtt_offset(obj
) == plane_config
->base
) {
2367 drm_framebuffer_reference(c
->primary
->fb
);
2368 intel_crtc
->base
.primary
->fb
= c
->primary
->fb
;
2369 obj
->frontbuffer_bits
|= INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
);
2375 static void i9xx_update_primary_plane(struct drm_crtc
*crtc
,
2376 struct drm_framebuffer
*fb
,
2379 struct drm_device
*dev
= crtc
->dev
;
2380 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2381 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2382 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2383 int plane
= intel_crtc
->plane
;
2384 unsigned long linear_offset
;
2386 u32 reg
= DSPCNTR(plane
);
2388 if (!intel_crtc
->primary_enabled
) {
2390 if (INTEL_INFO(dev
)->gen
>= 4)
2391 I915_WRITE(DSPSURF(plane
), 0);
2393 I915_WRITE(DSPADDR(plane
), 0);
2398 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2400 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2402 if (INTEL_INFO(dev
)->gen
< 4) {
2403 if (intel_crtc
->pipe
== PIPE_B
)
2404 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
2406 /* pipesrc and dspsize control the size that is scaled from,
2407 * which should always be the user's requested size.
2409 I915_WRITE(DSPSIZE(plane
),
2410 ((intel_crtc
->config
.pipe_src_h
- 1) << 16) |
2411 (intel_crtc
->config
.pipe_src_w
- 1));
2412 I915_WRITE(DSPPOS(plane
), 0);
2415 switch (fb
->pixel_format
) {
2417 dspcntr
|= DISPPLANE_8BPP
;
2419 case DRM_FORMAT_XRGB1555
:
2420 case DRM_FORMAT_ARGB1555
:
2421 dspcntr
|= DISPPLANE_BGRX555
;
2423 case DRM_FORMAT_RGB565
:
2424 dspcntr
|= DISPPLANE_BGRX565
;
2426 case DRM_FORMAT_XRGB8888
:
2427 case DRM_FORMAT_ARGB8888
:
2428 dspcntr
|= DISPPLANE_BGRX888
;
2430 case DRM_FORMAT_XBGR8888
:
2431 case DRM_FORMAT_ABGR8888
:
2432 dspcntr
|= DISPPLANE_RGBX888
;
2434 case DRM_FORMAT_XRGB2101010
:
2435 case DRM_FORMAT_ARGB2101010
:
2436 dspcntr
|= DISPPLANE_BGRX101010
;
2438 case DRM_FORMAT_XBGR2101010
:
2439 case DRM_FORMAT_ABGR2101010
:
2440 dspcntr
|= DISPPLANE_RGBX101010
;
2446 if (INTEL_INFO(dev
)->gen
>= 4 &&
2447 obj
->tiling_mode
!= I915_TILING_NONE
)
2448 dspcntr
|= DISPPLANE_TILED
;
2451 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2453 I915_WRITE(reg
, dspcntr
);
2455 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2457 if (INTEL_INFO(dev
)->gen
>= 4) {
2458 intel_crtc
->dspaddr_offset
=
2459 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2460 fb
->bits_per_pixel
/ 8,
2462 linear_offset
-= intel_crtc
->dspaddr_offset
;
2464 intel_crtc
->dspaddr_offset
= linear_offset
;
2467 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2468 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2470 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2471 if (INTEL_INFO(dev
)->gen
>= 4) {
2472 I915_WRITE(DSPSURF(plane
),
2473 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2474 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2475 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2477 I915_WRITE(DSPADDR(plane
), i915_gem_obj_ggtt_offset(obj
) + linear_offset
);
2481 static void ironlake_update_primary_plane(struct drm_crtc
*crtc
,
2482 struct drm_framebuffer
*fb
,
2485 struct drm_device
*dev
= crtc
->dev
;
2486 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2487 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2488 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2489 int plane
= intel_crtc
->plane
;
2490 unsigned long linear_offset
;
2492 u32 reg
= DSPCNTR(plane
);
2494 if (!intel_crtc
->primary_enabled
) {
2496 I915_WRITE(DSPSURF(plane
), 0);
2501 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
2503 dspcntr
|= DISPLAY_PLANE_ENABLE
;
2505 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2506 dspcntr
|= DISPPLANE_PIPE_CSC_ENABLE
;
2508 switch (fb
->pixel_format
) {
2510 dspcntr
|= DISPPLANE_8BPP
;
2512 case DRM_FORMAT_RGB565
:
2513 dspcntr
|= DISPPLANE_BGRX565
;
2515 case DRM_FORMAT_XRGB8888
:
2516 case DRM_FORMAT_ARGB8888
:
2517 dspcntr
|= DISPPLANE_BGRX888
;
2519 case DRM_FORMAT_XBGR8888
:
2520 case DRM_FORMAT_ABGR8888
:
2521 dspcntr
|= DISPPLANE_RGBX888
;
2523 case DRM_FORMAT_XRGB2101010
:
2524 case DRM_FORMAT_ARGB2101010
:
2525 dspcntr
|= DISPPLANE_BGRX101010
;
2527 case DRM_FORMAT_XBGR2101010
:
2528 case DRM_FORMAT_ABGR2101010
:
2529 dspcntr
|= DISPPLANE_RGBX101010
;
2535 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2536 dspcntr
|= DISPPLANE_TILED
;
2538 if (!IS_HASWELL(dev
) && !IS_BROADWELL(dev
))
2539 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2541 I915_WRITE(reg
, dspcntr
);
2543 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2544 intel_crtc
->dspaddr_offset
=
2545 intel_gen4_compute_page_offset(&x
, &y
, obj
->tiling_mode
,
2546 fb
->bits_per_pixel
/ 8,
2548 linear_offset
-= intel_crtc
->dspaddr_offset
;
2550 DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
2551 i915_gem_obj_ggtt_offset(obj
), linear_offset
, x
, y
,
2553 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2554 I915_WRITE(DSPSURF(plane
),
2555 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
);
2556 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2557 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2559 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2560 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2565 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2567 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
2568 int x
, int y
, enum mode_set_atomic state
)
2570 struct drm_device
*dev
= crtc
->dev
;
2571 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2573 if (dev_priv
->display
.disable_fbc
)
2574 dev_priv
->display
.disable_fbc(dev
);
2575 intel_increase_pllclock(dev
, to_intel_crtc(crtc
)->pipe
);
2577 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2582 void intel_display_handle_reset(struct drm_device
*dev
)
2584 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2585 struct drm_crtc
*crtc
;
2588 * Flips in the rings have been nuked by the reset,
2589 * so complete all pending flips so that user space
2590 * will get its events and not get stuck.
2592 * Also update the base address of all primary
2593 * planes to the the last fb to make sure we're
2594 * showing the correct fb after a reset.
2596 * Need to make two loops over the crtcs so that we
2597 * don't try to grab a crtc mutex before the
2598 * pending_flip_queue really got woken up.
2601 for_each_crtc(dev
, crtc
) {
2602 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2603 enum plane plane
= intel_crtc
->plane
;
2605 intel_prepare_page_flip(dev
, plane
);
2606 intel_finish_page_flip_plane(dev
, plane
);
2609 for_each_crtc(dev
, crtc
) {
2610 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2612 drm_modeset_lock(&crtc
->mutex
, NULL
);
2614 * FIXME: Once we have proper support for primary planes (and
2615 * disabling them without disabling the entire crtc) allow again
2616 * a NULL crtc->primary->fb.
2618 if (intel_crtc
->active
&& crtc
->primary
->fb
)
2619 dev_priv
->display
.update_primary_plane(crtc
,
2623 drm_modeset_unlock(&crtc
->mutex
);
2628 intel_finish_fb(struct drm_framebuffer
*old_fb
)
2630 struct drm_i915_gem_object
*obj
= intel_fb_obj(old_fb
);
2631 struct drm_i915_private
*dev_priv
= obj
->base
.dev
->dev_private
;
2632 bool was_interruptible
= dev_priv
->mm
.interruptible
;
2635 /* Big Hammer, we also need to ensure that any pending
2636 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2637 * current scanout is retired before unpinning the old
2640 * This should only fail upon a hung GPU, in which case we
2641 * can safely continue.
2643 dev_priv
->mm
.interruptible
= false;
2644 ret
= i915_gem_object_finish_gpu(obj
);
2645 dev_priv
->mm
.interruptible
= was_interruptible
;
2650 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
2652 struct drm_device
*dev
= crtc
->dev
;
2653 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2654 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2655 unsigned long flags
;
2658 if (i915_reset_in_progress(&dev_priv
->gpu_error
) ||
2659 intel_crtc
->reset_counter
!= atomic_read(&dev_priv
->gpu_error
.reset_counter
))
2662 spin_lock_irqsave(&dev
->event_lock
, flags
);
2663 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
2664 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2670 intel_pipe_set_base(struct drm_crtc
*crtc
, int x
, int y
,
2671 struct drm_framebuffer
*fb
)
2673 struct drm_device
*dev
= crtc
->dev
;
2674 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2675 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2676 enum pipe pipe
= intel_crtc
->pipe
;
2677 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
2678 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
2679 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(old_fb
);
2682 if (intel_crtc_has_pending_flip(crtc
)) {
2683 DRM_ERROR("pipe is still busy with an old pageflip\n");
2689 DRM_ERROR("No FB bound\n");
2693 if (intel_crtc
->plane
> INTEL_INFO(dev
)->num_pipes
) {
2694 DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
2695 plane_name(intel_crtc
->plane
),
2696 INTEL_INFO(dev
)->num_pipes
);
2700 mutex_lock(&dev
->struct_mutex
);
2701 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
2703 i915_gem_track_fb(old_obj
, obj
,
2704 INTEL_FRONTBUFFER_PRIMARY(pipe
));
2705 mutex_unlock(&dev
->struct_mutex
);
2707 DRM_ERROR("pin & fence failed\n");
2712 * Update pipe size and adjust fitter if needed: the reason for this is
2713 * that in compute_mode_changes we check the native mode (not the pfit
2714 * mode) to see if we can flip rather than do a full mode set. In the
2715 * fastboot case, we'll flip, but if we don't update the pipesrc and
2716 * pfit state, we'll end up with a big fb scanned out into the wrong
2719 * To fix this properly, we need to hoist the checks up into
2720 * compute_mode_changes (or above), check the actual pfit state and
2721 * whether the platform allows pfit disable with pipe active, and only
2722 * then update the pipesrc and pfit state, even on the flip path.
2724 if (i915
.fastboot
) {
2725 const struct drm_display_mode
*adjusted_mode
=
2726 &intel_crtc
->config
.adjusted_mode
;
2728 I915_WRITE(PIPESRC(intel_crtc
->pipe
),
2729 ((adjusted_mode
->crtc_hdisplay
- 1) << 16) |
2730 (adjusted_mode
->crtc_vdisplay
- 1));
2731 if (!intel_crtc
->config
.pch_pfit
.enabled
&&
2732 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
2733 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
2734 I915_WRITE(PF_CTL(intel_crtc
->pipe
), 0);
2735 I915_WRITE(PF_WIN_POS(intel_crtc
->pipe
), 0);
2736 I915_WRITE(PF_WIN_SZ(intel_crtc
->pipe
), 0);
2738 intel_crtc
->config
.pipe_src_w
= adjusted_mode
->crtc_hdisplay
;
2739 intel_crtc
->config
.pipe_src_h
= adjusted_mode
->crtc_vdisplay
;
2742 dev_priv
->display
.update_primary_plane(crtc
, fb
, x
, y
);
2744 if (intel_crtc
->active
)
2745 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
2747 crtc
->primary
->fb
= fb
;
2752 if (intel_crtc
->active
&& old_fb
!= fb
)
2753 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2754 mutex_lock(&dev
->struct_mutex
);
2755 intel_unpin_fb_obj(old_obj
);
2756 mutex_unlock(&dev
->struct_mutex
);
2759 mutex_lock(&dev
->struct_mutex
);
2760 intel_update_fbc(dev
);
2761 mutex_unlock(&dev
->struct_mutex
);
2766 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
2768 struct drm_device
*dev
= crtc
->dev
;
2769 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2770 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2771 int pipe
= intel_crtc
->pipe
;
2774 /* enable normal train */
2775 reg
= FDI_TX_CTL(pipe
);
2776 temp
= I915_READ(reg
);
2777 if (IS_IVYBRIDGE(dev
)) {
2778 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2779 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2781 temp
&= ~FDI_LINK_TRAIN_NONE
;
2782 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2784 I915_WRITE(reg
, temp
);
2786 reg
= FDI_RX_CTL(pipe
);
2787 temp
= I915_READ(reg
);
2788 if (HAS_PCH_CPT(dev
)) {
2789 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2790 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
2792 temp
&= ~FDI_LINK_TRAIN_NONE
;
2793 temp
|= FDI_LINK_TRAIN_NONE
;
2795 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
2797 /* wait one idle pattern time */
2801 /* IVB wants error correction enabled */
2802 if (IS_IVYBRIDGE(dev
))
2803 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
2804 FDI_FE_ERRC_ENABLE
);
2807 static bool pipe_has_enabled_pch(struct intel_crtc
*crtc
)
2809 return crtc
->base
.enabled
&& crtc
->active
&&
2810 crtc
->config
.has_pch_encoder
;
2813 static void ivb_modeset_global_resources(struct drm_device
*dev
)
2815 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2816 struct intel_crtc
*pipe_B_crtc
=
2817 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
2818 struct intel_crtc
*pipe_C_crtc
=
2819 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]);
2823 * When everything is off disable fdi C so that we could enable fdi B
2824 * with all lanes. Note that we don't care about enabled pipes without
2825 * an enabled pch encoder.
2827 if (!pipe_has_enabled_pch(pipe_B_crtc
) &&
2828 !pipe_has_enabled_pch(pipe_C_crtc
)) {
2829 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
2830 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
2832 temp
= I915_READ(SOUTH_CHICKEN1
);
2833 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
2834 DRM_DEBUG_KMS("disabling fdi C rx\n");
2835 I915_WRITE(SOUTH_CHICKEN1
, temp
);
2839 /* The FDI link training functions for ILK/Ibexpeak. */
2840 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
2842 struct drm_device
*dev
= crtc
->dev
;
2843 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2844 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2845 int pipe
= intel_crtc
->pipe
;
2846 u32 reg
, temp
, tries
;
2848 /* FDI needs bits from pipe first */
2849 assert_pipe_enabled(dev_priv
, pipe
);
2851 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2853 reg
= FDI_RX_IMR(pipe
);
2854 temp
= I915_READ(reg
);
2855 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2856 temp
&= ~FDI_RX_BIT_LOCK
;
2857 I915_WRITE(reg
, temp
);
2861 /* enable CPU FDI TX and PCH FDI RX */
2862 reg
= FDI_TX_CTL(pipe
);
2863 temp
= I915_READ(reg
);
2864 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2865 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2866 temp
&= ~FDI_LINK_TRAIN_NONE
;
2867 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2868 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2870 reg
= FDI_RX_CTL(pipe
);
2871 temp
= I915_READ(reg
);
2872 temp
&= ~FDI_LINK_TRAIN_NONE
;
2873 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2874 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2879 /* Ironlake workaround, enable clock pointer after FDI enable*/
2880 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
2881 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
2882 FDI_RX_PHASE_SYNC_POINTER_EN
);
2884 reg
= FDI_RX_IIR(pipe
);
2885 for (tries
= 0; tries
< 5; tries
++) {
2886 temp
= I915_READ(reg
);
2887 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2889 if ((temp
& FDI_RX_BIT_LOCK
)) {
2890 DRM_DEBUG_KMS("FDI train 1 done.\n");
2891 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2896 DRM_ERROR("FDI train 1 fail!\n");
2899 reg
= FDI_TX_CTL(pipe
);
2900 temp
= I915_READ(reg
);
2901 temp
&= ~FDI_LINK_TRAIN_NONE
;
2902 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2903 I915_WRITE(reg
, temp
);
2905 reg
= FDI_RX_CTL(pipe
);
2906 temp
= I915_READ(reg
);
2907 temp
&= ~FDI_LINK_TRAIN_NONE
;
2908 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2909 I915_WRITE(reg
, temp
);
2914 reg
= FDI_RX_IIR(pipe
);
2915 for (tries
= 0; tries
< 5; tries
++) {
2916 temp
= I915_READ(reg
);
2917 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2919 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2920 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2921 DRM_DEBUG_KMS("FDI train 2 done.\n");
2926 DRM_ERROR("FDI train 2 fail!\n");
2928 DRM_DEBUG_KMS("FDI train done\n");
2932 static const int snb_b_fdi_train_param
[] = {
2933 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
2934 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
2935 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
2936 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
2939 /* The FDI link training functions for SNB/Cougarpoint. */
2940 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
2942 struct drm_device
*dev
= crtc
->dev
;
2943 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2944 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2945 int pipe
= intel_crtc
->pipe
;
2946 u32 reg
, temp
, i
, retry
;
2948 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2950 reg
= FDI_RX_IMR(pipe
);
2951 temp
= I915_READ(reg
);
2952 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2953 temp
&= ~FDI_RX_BIT_LOCK
;
2954 I915_WRITE(reg
, temp
);
2959 /* enable CPU FDI TX and PCH FDI RX */
2960 reg
= FDI_TX_CTL(pipe
);
2961 temp
= I915_READ(reg
);
2962 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
2963 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
2964 temp
&= ~FDI_LINK_TRAIN_NONE
;
2965 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2966 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2968 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2969 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2971 I915_WRITE(FDI_RX_MISC(pipe
),
2972 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
2974 reg
= FDI_RX_CTL(pipe
);
2975 temp
= I915_READ(reg
);
2976 if (HAS_PCH_CPT(dev
)) {
2977 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2978 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2980 temp
&= ~FDI_LINK_TRAIN_NONE
;
2981 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2983 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2988 for (i
= 0; i
< 4; i
++) {
2989 reg
= FDI_TX_CTL(pipe
);
2990 temp
= I915_READ(reg
);
2991 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2992 temp
|= snb_b_fdi_train_param
[i
];
2993 I915_WRITE(reg
, temp
);
2998 for (retry
= 0; retry
< 5; retry
++) {
2999 reg
= FDI_RX_IIR(pipe
);
3000 temp
= I915_READ(reg
);
3001 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3002 if (temp
& FDI_RX_BIT_LOCK
) {
3003 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3004 DRM_DEBUG_KMS("FDI train 1 done.\n");
3013 DRM_ERROR("FDI train 1 fail!\n");
3016 reg
= FDI_TX_CTL(pipe
);
3017 temp
= I915_READ(reg
);
3018 temp
&= ~FDI_LINK_TRAIN_NONE
;
3019 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3021 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3023 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
3025 I915_WRITE(reg
, temp
);
3027 reg
= FDI_RX_CTL(pipe
);
3028 temp
= I915_READ(reg
);
3029 if (HAS_PCH_CPT(dev
)) {
3030 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3031 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3033 temp
&= ~FDI_LINK_TRAIN_NONE
;
3034 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
3036 I915_WRITE(reg
, temp
);
3041 for (i
= 0; i
< 4; i
++) {
3042 reg
= FDI_TX_CTL(pipe
);
3043 temp
= I915_READ(reg
);
3044 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3045 temp
|= snb_b_fdi_train_param
[i
];
3046 I915_WRITE(reg
, temp
);
3051 for (retry
= 0; retry
< 5; retry
++) {
3052 reg
= FDI_RX_IIR(pipe
);
3053 temp
= I915_READ(reg
);
3054 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3055 if (temp
& FDI_RX_SYMBOL_LOCK
) {
3056 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3057 DRM_DEBUG_KMS("FDI train 2 done.\n");
3066 DRM_ERROR("FDI train 2 fail!\n");
3068 DRM_DEBUG_KMS("FDI train done.\n");
3071 /* Manual link training for Ivy Bridge A0 parts */
3072 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
3074 struct drm_device
*dev
= crtc
->dev
;
3075 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3076 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3077 int pipe
= intel_crtc
->pipe
;
3078 u32 reg
, temp
, i
, j
;
3080 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3082 reg
= FDI_RX_IMR(pipe
);
3083 temp
= I915_READ(reg
);
3084 temp
&= ~FDI_RX_SYMBOL_LOCK
;
3085 temp
&= ~FDI_RX_BIT_LOCK
;
3086 I915_WRITE(reg
, temp
);
3091 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
3092 I915_READ(FDI_RX_IIR(pipe
)));
3094 /* Try each vswing and preemphasis setting twice before moving on */
3095 for (j
= 0; j
< ARRAY_SIZE(snb_b_fdi_train_param
) * 2; j
++) {
3096 /* disable first in case we need to retry */
3097 reg
= FDI_TX_CTL(pipe
);
3098 temp
= I915_READ(reg
);
3099 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
3100 temp
&= ~FDI_TX_ENABLE
;
3101 I915_WRITE(reg
, temp
);
3103 reg
= FDI_RX_CTL(pipe
);
3104 temp
= I915_READ(reg
);
3105 temp
&= ~FDI_LINK_TRAIN_AUTO
;
3106 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3107 temp
&= ~FDI_RX_ENABLE
;
3108 I915_WRITE(reg
, temp
);
3110 /* enable CPU FDI TX and PCH FDI RX */
3111 reg
= FDI_TX_CTL(pipe
);
3112 temp
= I915_READ(reg
);
3113 temp
&= ~FDI_DP_PORT_WIDTH_MASK
;
3114 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3115 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
3116 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
3117 temp
|= snb_b_fdi_train_param
[j
/2];
3118 temp
|= FDI_COMPOSITE_SYNC
;
3119 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
3121 I915_WRITE(FDI_RX_MISC(pipe
),
3122 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
3124 reg
= FDI_RX_CTL(pipe
);
3125 temp
= I915_READ(reg
);
3126 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3127 temp
|= FDI_COMPOSITE_SYNC
;
3128 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
3131 udelay(1); /* should be 0.5us */
3133 for (i
= 0; i
< 4; i
++) {
3134 reg
= FDI_RX_IIR(pipe
);
3135 temp
= I915_READ(reg
);
3136 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3138 if (temp
& FDI_RX_BIT_LOCK
||
3139 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
3140 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
3141 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
3145 udelay(1); /* should be 0.5us */
3148 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j
/ 2);
3153 reg
= FDI_TX_CTL(pipe
);
3154 temp
= I915_READ(reg
);
3155 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
3156 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
3157 I915_WRITE(reg
, temp
);
3159 reg
= FDI_RX_CTL(pipe
);
3160 temp
= I915_READ(reg
);
3161 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3162 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
3163 I915_WRITE(reg
, temp
);
3166 udelay(2); /* should be 1.5us */
3168 for (i
= 0; i
< 4; i
++) {
3169 reg
= FDI_RX_IIR(pipe
);
3170 temp
= I915_READ(reg
);
3171 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
3173 if (temp
& FDI_RX_SYMBOL_LOCK
||
3174 (I915_READ(reg
) & FDI_RX_SYMBOL_LOCK
)) {
3175 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
3176 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
3180 udelay(2); /* should be 1.5us */
3183 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j
/ 2);
3187 DRM_DEBUG_KMS("FDI train done.\n");
3190 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
3192 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3193 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3194 int pipe
= intel_crtc
->pipe
;
3198 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
3199 reg
= FDI_RX_CTL(pipe
);
3200 temp
= I915_READ(reg
);
3201 temp
&= ~(FDI_DP_PORT_WIDTH_MASK
| (0x7 << 16));
3202 temp
|= FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
3203 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3204 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
3209 /* Switch from Rawclk to PCDclk */
3210 temp
= I915_READ(reg
);
3211 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
3216 /* Enable CPU FDI TX PLL, always on for Ironlake */
3217 reg
= FDI_TX_CTL(pipe
);
3218 temp
= I915_READ(reg
);
3219 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
3220 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
3227 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
3229 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3230 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3231 int pipe
= intel_crtc
->pipe
;
3234 /* Switch from PCDclk to Rawclk */
3235 reg
= FDI_RX_CTL(pipe
);
3236 temp
= I915_READ(reg
);
3237 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
3239 /* Disable CPU FDI TX PLL */
3240 reg
= FDI_TX_CTL(pipe
);
3241 temp
= I915_READ(reg
);
3242 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
3247 reg
= FDI_RX_CTL(pipe
);
3248 temp
= I915_READ(reg
);
3249 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
3251 /* Wait for the clocks to turn off. */
3256 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
3258 struct drm_device
*dev
= crtc
->dev
;
3259 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3260 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3261 int pipe
= intel_crtc
->pipe
;
3264 /* disable CPU FDI tx and PCH FDI rx */
3265 reg
= FDI_TX_CTL(pipe
);
3266 temp
= I915_READ(reg
);
3267 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
3270 reg
= FDI_RX_CTL(pipe
);
3271 temp
= I915_READ(reg
);
3272 temp
&= ~(0x7 << 16);
3273 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3274 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
3279 /* Ironlake workaround, disable clock pointer after downing FDI */
3280 if (HAS_PCH_IBX(dev
))
3281 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
3283 /* still set train pattern 1 */
3284 reg
= FDI_TX_CTL(pipe
);
3285 temp
= I915_READ(reg
);
3286 temp
&= ~FDI_LINK_TRAIN_NONE
;
3287 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3288 I915_WRITE(reg
, temp
);
3290 reg
= FDI_RX_CTL(pipe
);
3291 temp
= I915_READ(reg
);
3292 if (HAS_PCH_CPT(dev
)) {
3293 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
3294 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
3296 temp
&= ~FDI_LINK_TRAIN_NONE
;
3297 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
3299 /* BPC in FDI rx is consistent with that in PIPECONF */
3300 temp
&= ~(0x07 << 16);
3301 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) << 11;
3302 I915_WRITE(reg
, temp
);
3308 bool intel_has_pending_fb_unpin(struct drm_device
*dev
)
3310 struct intel_crtc
*crtc
;
3312 /* Note that we don't need to be called with mode_config.lock here
3313 * as our list of CRTC objects is static for the lifetime of the
3314 * device and so cannot disappear as we iterate. Similarly, we can
3315 * happily treat the predicates as racy, atomic checks as userspace
3316 * cannot claim and pin a new fb without at least acquring the
3317 * struct_mutex and so serialising with us.
3319 for_each_intel_crtc(dev
, crtc
) {
3320 if (atomic_read(&crtc
->unpin_work_count
) == 0)
3323 if (crtc
->unpin_work
)
3324 intel_wait_for_vblank(dev
, crtc
->pipe
);
3332 void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
3334 struct drm_device
*dev
= crtc
->dev
;
3335 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3337 if (crtc
->primary
->fb
== NULL
)
3340 WARN_ON(waitqueue_active(&dev_priv
->pending_flip_queue
));
3342 WARN_ON(wait_event_timeout(dev_priv
->pending_flip_queue
,
3343 !intel_crtc_has_pending_flip(crtc
),
3346 mutex_lock(&dev
->struct_mutex
);
3347 intel_finish_fb(crtc
->primary
->fb
);
3348 mutex_unlock(&dev
->struct_mutex
);
3351 /* Program iCLKIP clock to the desired frequency */
3352 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3354 struct drm_device
*dev
= crtc
->dev
;
3355 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3356 int clock
= to_intel_crtc(crtc
)->config
.adjusted_mode
.crtc_clock
;
3357 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3360 mutex_lock(&dev_priv
->dpio_lock
);
3362 /* It is necessary to ungate the pixclk gate prior to programming
3363 * the divisors, and gate it back when it is done.
3365 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3367 /* Disable SSCCTL */
3368 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
3369 intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
) |
3373 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3374 if (clock
== 20000) {
3379 /* The iCLK virtual clock root frequency is in MHz,
3380 * but the adjusted_mode->crtc_clock in in KHz. To get the
3381 * divisors, it is necessary to divide one by another, so we
3382 * convert the virtual clock precision to KHz here for higher
3385 u32 iclk_virtual_root_freq
= 172800 * 1000;
3386 u32 iclk_pi_range
= 64;
3387 u32 desired_divisor
, msb_divisor_value
, pi_value
;
3389 desired_divisor
= (iclk_virtual_root_freq
/ clock
);
3390 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
3391 pi_value
= desired_divisor
% iclk_pi_range
;
3394 divsel
= msb_divisor_value
- 2;
3395 phaseinc
= pi_value
;
3398 /* This should not happen with any sane values */
3399 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3400 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3401 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3402 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3404 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3411 /* Program SSCDIVINTPHASE6 */
3412 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
, SBI_ICLK
);
3413 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
3414 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
3415 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
3416 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
3417 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
3418 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
3419 intel_sbi_write(dev_priv
, SBI_SSCDIVINTPHASE6
, temp
, SBI_ICLK
);
3421 /* Program SSCAUXDIV */
3422 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
, SBI_ICLK
);
3423 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3424 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
3425 intel_sbi_write(dev_priv
, SBI_SSCAUXDIV6
, temp
, SBI_ICLK
);
3427 /* Enable modulator and associated divider */
3428 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
, SBI_ICLK
);
3429 temp
&= ~SBI_SSCCTL_DISABLE
;
3430 intel_sbi_write(dev_priv
, SBI_SSCCTL6
, temp
, SBI_ICLK
);
3432 /* Wait for initialization time */
3435 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
3437 mutex_unlock(&dev_priv
->dpio_lock
);
3440 static void ironlake_pch_transcoder_set_timings(struct intel_crtc
*crtc
,
3441 enum pipe pch_transcoder
)
3443 struct drm_device
*dev
= crtc
->base
.dev
;
3444 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3445 enum transcoder cpu_transcoder
= crtc
->config
.cpu_transcoder
;
3447 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder
),
3448 I915_READ(HTOTAL(cpu_transcoder
)));
3449 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder
),
3450 I915_READ(HBLANK(cpu_transcoder
)));
3451 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder
),
3452 I915_READ(HSYNC(cpu_transcoder
)));
3454 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder
),
3455 I915_READ(VTOTAL(cpu_transcoder
)));
3456 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder
),
3457 I915_READ(VBLANK(cpu_transcoder
)));
3458 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder
),
3459 I915_READ(VSYNC(cpu_transcoder
)));
3460 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder
),
3461 I915_READ(VSYNCSHIFT(cpu_transcoder
)));
3464 static void cpt_enable_fdi_bc_bifurcation(struct drm_device
*dev
)
3466 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3469 temp
= I915_READ(SOUTH_CHICKEN1
);
3470 if (temp
& FDI_BC_BIFURCATION_SELECT
)
3473 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
3474 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
3476 temp
|= FDI_BC_BIFURCATION_SELECT
;
3477 DRM_DEBUG_KMS("enabling fdi C rx\n");
3478 I915_WRITE(SOUTH_CHICKEN1
, temp
);
3479 POSTING_READ(SOUTH_CHICKEN1
);
3482 static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc
*intel_crtc
)
3484 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3485 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3487 switch (intel_crtc
->pipe
) {
3491 if (intel_crtc
->config
.fdi_lanes
> 2)
3492 WARN_ON(I915_READ(SOUTH_CHICKEN1
) & FDI_BC_BIFURCATION_SELECT
);
3494 cpt_enable_fdi_bc_bifurcation(dev
);
3498 cpt_enable_fdi_bc_bifurcation(dev
);
3507 * Enable PCH resources required for PCH ports:
3509 * - FDI training & RX/TX
3510 * - update transcoder timings
3511 * - DP transcoding bits
3514 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
3516 struct drm_device
*dev
= crtc
->dev
;
3517 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3518 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3519 int pipe
= intel_crtc
->pipe
;
3522 assert_pch_transcoder_disabled(dev_priv
, pipe
);
3524 if (IS_IVYBRIDGE(dev
))
3525 ivybridge_update_fdi_bc_bifurcation(intel_crtc
);
3527 /* Write the TU size bits before fdi link training, so that error
3528 * detection works. */
3529 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
3530 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
3532 /* For PCH output, training FDI link */
3533 dev_priv
->display
.fdi_link_train(crtc
);
3535 /* We need to program the right clock selection before writing the pixel
3536 * mutliplier into the DPLL. */
3537 if (HAS_PCH_CPT(dev
)) {
3540 temp
= I915_READ(PCH_DPLL_SEL
);
3541 temp
|= TRANS_DPLL_ENABLE(pipe
);
3542 sel
= TRANS_DPLLB_SEL(pipe
);
3543 if (intel_crtc
->config
.shared_dpll
== DPLL_ID_PCH_PLL_B
)
3547 I915_WRITE(PCH_DPLL_SEL
, temp
);
3550 /* XXX: pch pll's can be enabled any time before we enable the PCH
3551 * transcoder, and we actually should do this to not upset any PCH
3552 * transcoder that already use the clock when we share it.
3554 * Note that enable_shared_dpll tries to do the right thing, but
3555 * get_shared_dpll unconditionally resets the pll - we need that to have
3556 * the right LVDS enable sequence. */
3557 intel_enable_shared_dpll(intel_crtc
);
3559 /* set transcoder timing, panel must allow it */
3560 assert_panel_unlocked(dev_priv
, pipe
);
3561 ironlake_pch_transcoder_set_timings(intel_crtc
, pipe
);
3563 intel_fdi_normal_train(crtc
);
3565 /* For PCH DP, enable TRANS_DP_CTL */
3566 if (HAS_PCH_CPT(dev
) &&
3567 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
3568 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3569 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPECONF_BPC_MASK
) >> 5;
3570 reg
= TRANS_DP_CTL(pipe
);
3571 temp
= I915_READ(reg
);
3572 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
3573 TRANS_DP_SYNC_MASK
|
3575 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
3576 TRANS_DP_ENH_FRAMING
);
3577 temp
|= bpc
<< 9; /* same format but at 11:9 */
3579 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
3580 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
3581 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
3582 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
3584 switch (intel_trans_dp_port_sel(crtc
)) {
3586 temp
|= TRANS_DP_PORT_SEL_B
;
3589 temp
|= TRANS_DP_PORT_SEL_C
;
3592 temp
|= TRANS_DP_PORT_SEL_D
;
3598 I915_WRITE(reg
, temp
);
3601 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
3604 static void lpt_pch_enable(struct drm_crtc
*crtc
)
3606 struct drm_device
*dev
= crtc
->dev
;
3607 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3608 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3609 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
3611 assert_pch_transcoder_disabled(dev_priv
, TRANSCODER_A
);
3613 lpt_program_iclkip(crtc
);
3615 /* Set transcoder timing. */
3616 ironlake_pch_transcoder_set_timings(intel_crtc
, PIPE_A
);
3618 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
3621 void intel_put_shared_dpll(struct intel_crtc
*crtc
)
3623 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3628 if (pll
->refcount
== 0) {
3629 WARN(1, "bad %s refcount\n", pll
->name
);
3633 if (--pll
->refcount
== 0) {
3635 WARN_ON(pll
->active
);
3638 crtc
->config
.shared_dpll
= DPLL_ID_PRIVATE
;
3641 struct intel_shared_dpll
*intel_get_shared_dpll(struct intel_crtc
*crtc
)
3643 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
3644 struct intel_shared_dpll
*pll
= intel_crtc_to_shared_dpll(crtc
);
3645 enum intel_dpll_id i
;
3648 DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
3649 crtc
->base
.base
.id
, pll
->name
);
3650 intel_put_shared_dpll(crtc
);
3653 if (HAS_PCH_IBX(dev_priv
->dev
)) {
3654 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3655 i
= (enum intel_dpll_id
) crtc
->pipe
;
3656 pll
= &dev_priv
->shared_dplls
[i
];
3658 DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
3659 crtc
->base
.base
.id
, pll
->name
);
3661 WARN_ON(pll
->refcount
);
3666 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3667 pll
= &dev_priv
->shared_dplls
[i
];
3669 /* Only want to check enabled timings first */
3670 if (pll
->refcount
== 0)
3673 if (memcmp(&crtc
->config
.dpll_hw_state
, &pll
->hw_state
,
3674 sizeof(pll
->hw_state
)) == 0) {
3675 DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
3677 pll
->name
, pll
->refcount
, pll
->active
);
3683 /* Ok no matching timings, maybe there's a free one? */
3684 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
3685 pll
= &dev_priv
->shared_dplls
[i
];
3686 if (pll
->refcount
== 0) {
3687 DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
3688 crtc
->base
.base
.id
, pll
->name
);
3696 if (pll
->refcount
== 0)
3697 pll
->hw_state
= crtc
->config
.dpll_hw_state
;
3699 crtc
->config
.shared_dpll
= i
;
3700 DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll
->name
,
3701 pipe_name(crtc
->pipe
));
3708 static void cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
3710 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3711 int dslreg
= PIPEDSL(pipe
);
3714 temp
= I915_READ(dslreg
);
3716 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
3717 if (wait_for(I915_READ(dslreg
) != temp
, 5))
3718 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe
));
3722 static void ironlake_pfit_enable(struct intel_crtc
*crtc
)
3724 struct drm_device
*dev
= crtc
->base
.dev
;
3725 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3726 int pipe
= crtc
->pipe
;
3728 if (crtc
->config
.pch_pfit
.enabled
) {
3729 /* Force use of hard-coded filter coefficients
3730 * as some pre-programmed values are broken,
3733 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
))
3734 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
|
3735 PF_PIPE_SEL_IVB(pipe
));
3737 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
3738 I915_WRITE(PF_WIN_POS(pipe
), crtc
->config
.pch_pfit
.pos
);
3739 I915_WRITE(PF_WIN_SZ(pipe
), crtc
->config
.pch_pfit
.size
);
3743 static void intel_enable_planes(struct drm_crtc
*crtc
)
3745 struct drm_device
*dev
= crtc
->dev
;
3746 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3747 struct drm_plane
*plane
;
3748 struct intel_plane
*intel_plane
;
3750 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3751 intel_plane
= to_intel_plane(plane
);
3752 if (intel_plane
->pipe
== pipe
)
3753 intel_plane_restore(&intel_plane
->base
);
3757 static void intel_disable_planes(struct drm_crtc
*crtc
)
3759 struct drm_device
*dev
= crtc
->dev
;
3760 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
3761 struct drm_plane
*plane
;
3762 struct intel_plane
*intel_plane
;
3764 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
3765 intel_plane
= to_intel_plane(plane
);
3766 if (intel_plane
->pipe
== pipe
)
3767 intel_plane_disable(&intel_plane
->base
);
3771 void hsw_enable_ips(struct intel_crtc
*crtc
)
3773 struct drm_device
*dev
= crtc
->base
.dev
;
3774 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3776 if (!crtc
->config
.ips_enabled
)
3779 /* We can only enable IPS after we enable a plane and wait for a vblank */
3780 intel_wait_for_vblank(dev
, crtc
->pipe
);
3782 assert_plane_enabled(dev_priv
, crtc
->plane
);
3783 if (IS_BROADWELL(dev
)) {
3784 mutex_lock(&dev_priv
->rps
.hw_lock
);
3785 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0xc0000000));
3786 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3787 /* Quoting Art Runyan: "its not safe to expect any particular
3788 * value in IPS_CTL bit 31 after enabling IPS through the
3789 * mailbox." Moreover, the mailbox may return a bogus state,
3790 * so we need to just enable it and continue on.
3793 I915_WRITE(IPS_CTL
, IPS_ENABLE
);
3794 /* The bit only becomes 1 in the next vblank, so this wait here
3795 * is essentially intel_wait_for_vblank. If we don't have this
3796 * and don't wait for vblanks until the end of crtc_enable, then
3797 * the HW state readout code will complain that the expected
3798 * IPS_CTL value is not the one we read. */
3799 if (wait_for(I915_READ_NOTRACE(IPS_CTL
) & IPS_ENABLE
, 50))
3800 DRM_ERROR("Timed out waiting for IPS enable\n");
3804 void hsw_disable_ips(struct intel_crtc
*crtc
)
3806 struct drm_device
*dev
= crtc
->base
.dev
;
3807 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3809 if (!crtc
->config
.ips_enabled
)
3812 assert_plane_enabled(dev_priv
, crtc
->plane
);
3813 if (IS_BROADWELL(dev
)) {
3814 mutex_lock(&dev_priv
->rps
.hw_lock
);
3815 WARN_ON(sandybridge_pcode_write(dev_priv
, DISPLAY_IPS_CONTROL
, 0));
3816 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3817 /* wait for pcode to finish disabling IPS, which may take up to 42ms */
3818 if (wait_for((I915_READ(IPS_CTL
) & IPS_ENABLE
) == 0, 42))
3819 DRM_ERROR("Timed out waiting for IPS disable\n");
3821 I915_WRITE(IPS_CTL
, 0);
3822 POSTING_READ(IPS_CTL
);
3825 /* We need to wait for a vblank before we can disable the plane. */
3826 intel_wait_for_vblank(dev
, crtc
->pipe
);
3829 /** Loads the palette/gamma unit for the CRTC with the prepared values */
3830 static void intel_crtc_load_lut(struct drm_crtc
*crtc
)
3832 struct drm_device
*dev
= crtc
->dev
;
3833 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3834 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3835 enum pipe pipe
= intel_crtc
->pipe
;
3836 int palreg
= PALETTE(pipe
);
3838 bool reenable_ips
= false;
3840 /* The clocks have to be on to load the palette. */
3841 if (!crtc
->enabled
|| !intel_crtc
->active
)
3844 if (!HAS_PCH_SPLIT(dev_priv
->dev
)) {
3845 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
))
3846 assert_dsi_pll_enabled(dev_priv
);
3848 assert_pll_enabled(dev_priv
, pipe
);
3851 /* use legacy palette for Ironlake */
3852 if (!HAS_GMCH_DISPLAY(dev
))
3853 palreg
= LGC_PALETTE(pipe
);
3855 /* Workaround : Do not read or write the pipe palette/gamma data while
3856 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
3858 if (IS_HASWELL(dev
) && intel_crtc
->config
.ips_enabled
&&
3859 ((I915_READ(GAMMA_MODE(pipe
)) & GAMMA_MODE_MODE_MASK
) ==
3860 GAMMA_MODE_MODE_SPLIT
)) {
3861 hsw_disable_ips(intel_crtc
);
3862 reenable_ips
= true;
3865 for (i
= 0; i
< 256; i
++) {
3866 I915_WRITE(palreg
+ 4 * i
,
3867 (intel_crtc
->lut_r
[i
] << 16) |
3868 (intel_crtc
->lut_g
[i
] << 8) |
3869 intel_crtc
->lut_b
[i
]);
3873 hsw_enable_ips(intel_crtc
);
3876 static void intel_crtc_dpms_overlay(struct intel_crtc
*intel_crtc
, bool enable
)
3878 if (!enable
&& intel_crtc
->overlay
) {
3879 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3880 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3882 mutex_lock(&dev
->struct_mutex
);
3883 dev_priv
->mm
.interruptible
= false;
3884 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
3885 dev_priv
->mm
.interruptible
= true;
3886 mutex_unlock(&dev
->struct_mutex
);
3889 /* Let userspace switch the overlay on again. In most cases userspace
3890 * has to recompute where to put it anyway.
3894 static void intel_crtc_enable_planes(struct drm_crtc
*crtc
)
3896 struct drm_device
*dev
= crtc
->dev
;
3897 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3898 int pipe
= intel_crtc
->pipe
;
3900 assert_vblank_disabled(crtc
);
3902 drm_vblank_on(dev
, pipe
);
3904 intel_enable_primary_hw_plane(crtc
->primary
, crtc
);
3905 intel_enable_planes(crtc
);
3906 intel_crtc_update_cursor(crtc
, true);
3907 intel_crtc_dpms_overlay(intel_crtc
, true);
3909 hsw_enable_ips(intel_crtc
);
3911 mutex_lock(&dev
->struct_mutex
);
3912 intel_update_fbc(dev
);
3913 mutex_unlock(&dev
->struct_mutex
);
3916 * FIXME: Once we grow proper nuclear flip support out of this we need
3917 * to compute the mask of flip planes precisely. For the time being
3918 * consider this a flip from a NULL plane.
3920 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
3923 static void intel_crtc_disable_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 intel_crtc_wait_for_pending_flips(crtc
);
3933 if (dev_priv
->fbc
.plane
== plane
)
3934 intel_disable_fbc(dev
);
3936 hsw_disable_ips(intel_crtc
);
3938 intel_crtc_dpms_overlay(intel_crtc
, false);
3939 intel_crtc_update_cursor(crtc
, false);
3940 intel_disable_planes(crtc
);
3941 intel_disable_primary_hw_plane(crtc
->primary
, crtc
);
3944 * FIXME: Once we grow proper nuclear flip support out of this we need
3945 * to compute the mask of flip planes precisely. For the time being
3946 * consider this a flip to a NULL plane.
3948 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_ALL_MASK(pipe
));
3950 drm_vblank_off(dev
, pipe
);
3952 assert_vblank_disabled(crtc
);
3955 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
3957 struct drm_device
*dev
= crtc
->dev
;
3958 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3959 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3960 struct intel_encoder
*encoder
;
3961 int pipe
= intel_crtc
->pipe
;
3963 WARN_ON(!crtc
->enabled
);
3965 if (intel_crtc
->active
)
3968 if (intel_crtc
->config
.has_pch_encoder
)
3969 intel_prepare_shared_dpll(intel_crtc
);
3971 if (intel_crtc
->config
.has_dp_encoder
)
3972 intel_dp_set_m_n(intel_crtc
);
3974 intel_set_pipe_timings(intel_crtc
);
3976 if (intel_crtc
->config
.has_pch_encoder
) {
3977 intel_cpu_transcoder_set_m_n(intel_crtc
,
3978 &intel_crtc
->config
.fdi_m_n
, NULL
);
3981 ironlake_set_pipeconf(crtc
);
3983 intel_crtc
->active
= true;
3985 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
3986 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
3988 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3989 if (encoder
->pre_enable
)
3990 encoder
->pre_enable(encoder
);
3992 if (intel_crtc
->config
.has_pch_encoder
) {
3993 /* Note: FDI PLL enabling _must_ be done before we enable the
3994 * cpu pipes, hence this is separate from all the other fdi/pch
3996 ironlake_fdi_pll_enable(intel_crtc
);
3998 assert_fdi_tx_disabled(dev_priv
, pipe
);
3999 assert_fdi_rx_disabled(dev_priv
, pipe
);
4002 ironlake_pfit_enable(intel_crtc
);
4005 * On ILK+ LUT must be loaded before the pipe is running but with
4008 intel_crtc_load_lut(crtc
);
4010 intel_update_watermarks(crtc
);
4011 intel_enable_pipe(intel_crtc
);
4013 if (intel_crtc
->config
.has_pch_encoder
)
4014 ironlake_pch_enable(crtc
);
4016 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4017 encoder
->enable(encoder
);
4019 if (HAS_PCH_CPT(dev
))
4020 cpt_verify_modeset(dev
, intel_crtc
->pipe
);
4022 intel_crtc_enable_planes(crtc
);
4025 /* IPS only exists on ULT machines and is tied to pipe A. */
4026 static bool hsw_crtc_supports_ips(struct intel_crtc
*crtc
)
4028 return HAS_IPS(crtc
->base
.dev
) && crtc
->pipe
== PIPE_A
;
4032 * This implements the workaround described in the "notes" section of the mode
4033 * set sequence documentation. When going from no pipes or single pipe to
4034 * multiple pipes, and planes are enabled after the pipe, we need to wait at
4035 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
4037 static void haswell_mode_set_planes_workaround(struct intel_crtc
*crtc
)
4039 struct drm_device
*dev
= crtc
->base
.dev
;
4040 struct intel_crtc
*crtc_it
, *other_active_crtc
= NULL
;
4042 /* We want to get the other_active_crtc only if there's only 1 other
4044 for_each_intel_crtc(dev
, crtc_it
) {
4045 if (!crtc_it
->active
|| crtc_it
== crtc
)
4048 if (other_active_crtc
)
4051 other_active_crtc
= crtc_it
;
4053 if (!other_active_crtc
)
4056 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4057 intel_wait_for_vblank(dev
, other_active_crtc
->pipe
);
4060 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
4062 struct drm_device
*dev
= crtc
->dev
;
4063 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4064 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4065 struct intel_encoder
*encoder
;
4066 int pipe
= intel_crtc
->pipe
;
4068 WARN_ON(!crtc
->enabled
);
4070 if (intel_crtc
->active
)
4073 if (intel_crtc_to_shared_dpll(intel_crtc
))
4074 intel_enable_shared_dpll(intel_crtc
);
4076 if (intel_crtc
->config
.has_dp_encoder
)
4077 intel_dp_set_m_n(intel_crtc
);
4079 intel_set_pipe_timings(intel_crtc
);
4081 if (intel_crtc
->config
.has_pch_encoder
) {
4082 intel_cpu_transcoder_set_m_n(intel_crtc
,
4083 &intel_crtc
->config
.fdi_m_n
, NULL
);
4086 haswell_set_pipeconf(crtc
);
4088 intel_set_pipe_csc(crtc
);
4090 intel_crtc
->active
= true;
4092 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4093 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4094 if (encoder
->pre_enable
)
4095 encoder
->pre_enable(encoder
);
4097 if (intel_crtc
->config
.has_pch_encoder
) {
4098 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
4099 dev_priv
->display
.fdi_link_train(crtc
);
4102 intel_ddi_enable_pipe_clock(intel_crtc
);
4104 ironlake_pfit_enable(intel_crtc
);
4107 * On ILK+ LUT must be loaded before the pipe is running but with
4110 intel_crtc_load_lut(crtc
);
4112 intel_ddi_set_pipe_settings(crtc
);
4113 intel_ddi_enable_transcoder_func(crtc
);
4115 intel_update_watermarks(crtc
);
4116 intel_enable_pipe(intel_crtc
);
4118 if (intel_crtc
->config
.has_pch_encoder
)
4119 lpt_pch_enable(crtc
);
4121 if (intel_crtc
->config
.dp_encoder_is_mst
)
4122 intel_ddi_set_vc_payload_alloc(crtc
, true);
4124 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4125 encoder
->enable(encoder
);
4126 intel_opregion_notify_encoder(encoder
, true);
4129 /* If we change the relative order between pipe/planes enabling, we need
4130 * to change the workaround. */
4131 haswell_mode_set_planes_workaround(intel_crtc
);
4132 intel_crtc_enable_planes(crtc
);
4135 static void ironlake_pfit_disable(struct intel_crtc
*crtc
)
4137 struct drm_device
*dev
= crtc
->base
.dev
;
4138 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4139 int pipe
= crtc
->pipe
;
4141 /* To avoid upsetting the power well on haswell only disable the pfit if
4142 * it's in use. The hw state code will make sure we get this right. */
4143 if (crtc
->config
.pch_pfit
.enabled
) {
4144 I915_WRITE(PF_CTL(pipe
), 0);
4145 I915_WRITE(PF_WIN_POS(pipe
), 0);
4146 I915_WRITE(PF_WIN_SZ(pipe
), 0);
4150 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
4152 struct drm_device
*dev
= crtc
->dev
;
4153 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4154 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4155 struct intel_encoder
*encoder
;
4156 int pipe
= intel_crtc
->pipe
;
4159 if (!intel_crtc
->active
)
4162 intel_crtc_disable_planes(crtc
);
4164 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4165 encoder
->disable(encoder
);
4167 if (intel_crtc
->config
.has_pch_encoder
)
4168 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, false);
4170 intel_disable_pipe(dev_priv
, pipe
);
4172 if (intel_crtc
->config
.dp_encoder_is_mst
)
4173 intel_ddi_set_vc_payload_alloc(crtc
, false);
4175 ironlake_pfit_disable(intel_crtc
);
4177 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4178 if (encoder
->post_disable
)
4179 encoder
->post_disable(encoder
);
4181 if (intel_crtc
->config
.has_pch_encoder
) {
4182 ironlake_fdi_disable(crtc
);
4184 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
4185 intel_set_pch_fifo_underrun_reporting(dev
, pipe
, true);
4187 if (HAS_PCH_CPT(dev
)) {
4188 /* disable TRANS_DP_CTL */
4189 reg
= TRANS_DP_CTL(pipe
);
4190 temp
= I915_READ(reg
);
4191 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
|
4192 TRANS_DP_PORT_SEL_MASK
);
4193 temp
|= TRANS_DP_PORT_SEL_NONE
;
4194 I915_WRITE(reg
, temp
);
4196 /* disable DPLL_SEL */
4197 temp
= I915_READ(PCH_DPLL_SEL
);
4198 temp
&= ~(TRANS_DPLL_ENABLE(pipe
) | TRANS_DPLLB_SEL(pipe
));
4199 I915_WRITE(PCH_DPLL_SEL
, temp
);
4202 /* disable PCH DPLL */
4203 intel_disable_shared_dpll(intel_crtc
);
4205 ironlake_fdi_pll_disable(intel_crtc
);
4208 intel_crtc
->active
= false;
4209 intel_update_watermarks(crtc
);
4211 mutex_lock(&dev
->struct_mutex
);
4212 intel_update_fbc(dev
);
4213 mutex_unlock(&dev
->struct_mutex
);
4216 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
4218 struct drm_device
*dev
= crtc
->dev
;
4219 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4220 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4221 struct intel_encoder
*encoder
;
4222 int pipe
= intel_crtc
->pipe
;
4223 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
4225 if (!intel_crtc
->active
)
4228 intel_crtc_disable_planes(crtc
);
4230 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4231 intel_opregion_notify_encoder(encoder
, false);
4232 encoder
->disable(encoder
);
4235 if (intel_crtc
->config
.has_pch_encoder
)
4236 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, false);
4237 intel_disable_pipe(dev_priv
, pipe
);
4239 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
4241 ironlake_pfit_disable(intel_crtc
);
4243 intel_ddi_disable_pipe_clock(intel_crtc
);
4245 if (intel_crtc
->config
.has_pch_encoder
) {
4246 lpt_disable_pch_transcoder(dev_priv
);
4247 intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
, true);
4248 intel_ddi_fdi_disable(crtc
);
4251 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4252 if (encoder
->post_disable
)
4253 encoder
->post_disable(encoder
);
4255 intel_crtc
->active
= false;
4256 intel_update_watermarks(crtc
);
4258 mutex_lock(&dev
->struct_mutex
);
4259 intel_update_fbc(dev
);
4260 mutex_unlock(&dev
->struct_mutex
);
4262 if (intel_crtc_to_shared_dpll(intel_crtc
))
4263 intel_disable_shared_dpll(intel_crtc
);
4266 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
4268 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4269 intel_put_shared_dpll(intel_crtc
);
4273 static void i9xx_pfit_enable(struct intel_crtc
*crtc
)
4275 struct drm_device
*dev
= crtc
->base
.dev
;
4276 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4277 struct intel_crtc_config
*pipe_config
= &crtc
->config
;
4279 if (!crtc
->config
.gmch_pfit
.control
)
4283 * The panel fitter should only be adjusted whilst the pipe is disabled,
4284 * according to register description and PRM.
4286 WARN_ON(I915_READ(PFIT_CONTROL
) & PFIT_ENABLE
);
4287 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4289 I915_WRITE(PFIT_PGM_RATIOS
, pipe_config
->gmch_pfit
.pgm_ratios
);
4290 I915_WRITE(PFIT_CONTROL
, pipe_config
->gmch_pfit
.control
);
4292 /* Border color in case we don't scale up to the full screen. Black by
4293 * default, change to something else for debugging. */
4294 I915_WRITE(BCLRPAT(crtc
->pipe
), 0);
4297 static enum intel_display_power_domain
port_to_power_domain(enum port port
)
4301 return POWER_DOMAIN_PORT_DDI_A_4_LANES
;
4303 return POWER_DOMAIN_PORT_DDI_B_4_LANES
;
4305 return POWER_DOMAIN_PORT_DDI_C_4_LANES
;
4307 return POWER_DOMAIN_PORT_DDI_D_4_LANES
;
4310 return POWER_DOMAIN_PORT_OTHER
;
4314 #define for_each_power_domain(domain, mask) \
4315 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
4316 if ((1 << (domain)) & (mask))
4318 enum intel_display_power_domain
4319 intel_display_port_power_domain(struct intel_encoder
*intel_encoder
)
4321 struct drm_device
*dev
= intel_encoder
->base
.dev
;
4322 struct intel_digital_port
*intel_dig_port
;
4324 switch (intel_encoder
->type
) {
4325 case INTEL_OUTPUT_UNKNOWN
:
4326 /* Only DDI platforms should ever use this output type */
4327 WARN_ON_ONCE(!HAS_DDI(dev
));
4328 case INTEL_OUTPUT_DISPLAYPORT
:
4329 case INTEL_OUTPUT_HDMI
:
4330 case INTEL_OUTPUT_EDP
:
4331 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
4332 return port_to_power_domain(intel_dig_port
->port
);
4333 case INTEL_OUTPUT_DP_MST
:
4334 intel_dig_port
= enc_to_mst(&intel_encoder
->base
)->primary
;
4335 return port_to_power_domain(intel_dig_port
->port
);
4336 case INTEL_OUTPUT_ANALOG
:
4337 return POWER_DOMAIN_PORT_CRT
;
4338 case INTEL_OUTPUT_DSI
:
4339 return POWER_DOMAIN_PORT_DSI
;
4341 return POWER_DOMAIN_PORT_OTHER
;
4345 static unsigned long get_crtc_power_domains(struct drm_crtc
*crtc
)
4347 struct drm_device
*dev
= crtc
->dev
;
4348 struct intel_encoder
*intel_encoder
;
4349 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4350 enum pipe pipe
= intel_crtc
->pipe
;
4352 enum transcoder transcoder
;
4354 transcoder
= intel_pipe_to_cpu_transcoder(dev
->dev_private
, pipe
);
4356 mask
= BIT(POWER_DOMAIN_PIPE(pipe
));
4357 mask
|= BIT(POWER_DOMAIN_TRANSCODER(transcoder
));
4358 if (intel_crtc
->config
.pch_pfit
.enabled
||
4359 intel_crtc
->config
.pch_pfit
.force_thru
)
4360 mask
|= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe
));
4362 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
4363 mask
|= BIT(intel_display_port_power_domain(intel_encoder
));
4368 void intel_display_set_init_power(struct drm_i915_private
*dev_priv
,
4371 if (dev_priv
->power_domains
.init_power_on
== enable
)
4375 intel_display_power_get(dev_priv
, POWER_DOMAIN_INIT
);
4377 intel_display_power_put(dev_priv
, POWER_DOMAIN_INIT
);
4379 dev_priv
->power_domains
.init_power_on
= enable
;
4382 static void modeset_update_crtc_power_domains(struct drm_device
*dev
)
4384 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4385 unsigned long pipe_domains
[I915_MAX_PIPES
] = { 0, };
4386 struct intel_crtc
*crtc
;
4389 * First get all needed power domains, then put all unneeded, to avoid
4390 * any unnecessary toggling of the power wells.
4392 for_each_intel_crtc(dev
, crtc
) {
4393 enum intel_display_power_domain domain
;
4395 if (!crtc
->base
.enabled
)
4398 pipe_domains
[crtc
->pipe
] = get_crtc_power_domains(&crtc
->base
);
4400 for_each_power_domain(domain
, pipe_domains
[crtc
->pipe
])
4401 intel_display_power_get(dev_priv
, domain
);
4404 for_each_intel_crtc(dev
, crtc
) {
4405 enum intel_display_power_domain domain
;
4407 for_each_power_domain(domain
, crtc
->enabled_power_domains
)
4408 intel_display_power_put(dev_priv
, domain
);
4410 crtc
->enabled_power_domains
= pipe_domains
[crtc
->pipe
];
4413 intel_display_set_init_power(dev_priv
, false);
4416 /* returns HPLL frequency in kHz */
4417 static int valleyview_get_vco(struct drm_i915_private
*dev_priv
)
4419 int hpll_freq
, vco_freq
[] = { 800, 1600, 2000, 2400 };
4421 /* Obtain SKU information */
4422 mutex_lock(&dev_priv
->dpio_lock
);
4423 hpll_freq
= vlv_cck_read(dev_priv
, CCK_FUSE_REG
) &
4424 CCK_FUSE_HPLL_FREQ_MASK
;
4425 mutex_unlock(&dev_priv
->dpio_lock
);
4427 return vco_freq
[hpll_freq
] * 1000;
4430 static void vlv_update_cdclk(struct drm_device
*dev
)
4432 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4434 dev_priv
->vlv_cdclk_freq
= dev_priv
->display
.get_display_clock_speed(dev
);
4435 DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz",
4436 dev_priv
->vlv_cdclk_freq
);
4439 * Program the gmbus_freq based on the cdclk frequency.
4440 * BSpec erroneously claims we should aim for 4MHz, but
4441 * in fact 1MHz is the correct frequency.
4443 I915_WRITE(GMBUSFREQ_VLV
, dev_priv
->vlv_cdclk_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(dev_priv
->display
.get_display_clock_speed(dev
) != dev_priv
->vlv_cdclk_freq
);
4454 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
4456 else if (cdclk
== 266667)
4461 mutex_lock(&dev_priv
->rps
.hw_lock
);
4462 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
4463 val
&= ~DSPFREQGUAR_MASK
;
4464 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
4465 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
4466 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
4467 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
4469 DRM_ERROR("timed out waiting for CDclk change\n");
4471 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4473 if (cdclk
== 400000) {
4476 vco
= valleyview_get_vco(dev_priv
);
4477 divider
= DIV_ROUND_CLOSEST(vco
<< 1, cdclk
) - 1;
4479 mutex_lock(&dev_priv
->dpio_lock
);
4480 /* adjust cdclk divider */
4481 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
4482 val
&= ~DISPLAY_FREQUENCY_VALUES
;
4484 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
4486 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
4487 DISPLAY_FREQUENCY_STATUS
) == (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
4489 DRM_ERROR("timed out waiting for CDclk change\n");
4490 mutex_unlock(&dev_priv
->dpio_lock
);
4493 mutex_lock(&dev_priv
->dpio_lock
);
4494 /* adjust self-refresh exit latency value */
4495 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
4499 * For high bandwidth configs, we set a higher latency in the bunit
4500 * so that the core display fetch happens in time to avoid underruns.
4502 if (cdclk
== 400000)
4503 val
|= 4500 / 250; /* 4.5 usec */
4505 val
|= 3000 / 250; /* 3.0 usec */
4506 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
4507 mutex_unlock(&dev_priv
->dpio_lock
);
4509 vlv_update_cdclk(dev
);
4512 static void cherryview_set_cdclk(struct drm_device
*dev
, int cdclk
)
4514 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4517 WARN_ON(dev_priv
->display
.get_display_clock_speed(dev
) != dev_priv
->vlv_cdclk_freq
);
4538 mutex_lock(&dev_priv
->rps
.hw_lock
);
4539 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
4540 val
&= ~DSPFREQGUAR_MASK_CHV
;
4541 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
4542 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
4543 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
4544 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
4546 DRM_ERROR("timed out waiting for CDclk change\n");
4548 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4550 vlv_update_cdclk(dev
);
4553 static int valleyview_calc_cdclk(struct drm_i915_private
*dev_priv
,
4556 int vco
= valleyview_get_vco(dev_priv
);
4557 int freq_320
= (vco
<< 1) % 320000 != 0 ? 333333 : 320000;
4559 /* FIXME: Punit isn't quite ready yet */
4560 if (IS_CHERRYVIEW(dev_priv
->dev
))
4564 * Really only a few cases to deal with, as only 4 CDclks are supported:
4567 * 320/333MHz (depends on HPLL freq)
4569 * So we check to see whether we're above 90% of the lower bin and
4572 * We seem to get an unstable or solid color picture at 200MHz.
4573 * Not sure what's wrong. For now use 200MHz only when all pipes
4576 if (max_pixclk
> freq_320
*9/10)
4578 else if (max_pixclk
> 266667*9/10)
4580 else if (max_pixclk
> 0)
4586 /* compute the max pixel clock for new configuration */
4587 static int intel_mode_max_pixclk(struct drm_i915_private
*dev_priv
)
4589 struct drm_device
*dev
= dev_priv
->dev
;
4590 struct intel_crtc
*intel_crtc
;
4593 for_each_intel_crtc(dev
, intel_crtc
) {
4594 if (intel_crtc
->new_enabled
)
4595 max_pixclk
= max(max_pixclk
,
4596 intel_crtc
->new_config
->adjusted_mode
.crtc_clock
);
4602 static void valleyview_modeset_global_pipes(struct drm_device
*dev
,
4603 unsigned *prepare_pipes
)
4605 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4606 struct intel_crtc
*intel_crtc
;
4607 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4609 if (valleyview_calc_cdclk(dev_priv
, max_pixclk
) ==
4610 dev_priv
->vlv_cdclk_freq
)
4613 /* disable/enable all currently active pipes while we change cdclk */
4614 for_each_intel_crtc(dev
, intel_crtc
)
4615 if (intel_crtc
->base
.enabled
)
4616 *prepare_pipes
|= (1 << intel_crtc
->pipe
);
4619 static void valleyview_modeset_global_resources(struct drm_device
*dev
)
4621 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4622 int max_pixclk
= intel_mode_max_pixclk(dev_priv
);
4623 int req_cdclk
= valleyview_calc_cdclk(dev_priv
, max_pixclk
);
4625 if (req_cdclk
!= dev_priv
->vlv_cdclk_freq
) {
4626 if (IS_CHERRYVIEW(dev
))
4627 cherryview_set_cdclk(dev
, req_cdclk
);
4629 valleyview_set_cdclk(dev
, req_cdclk
);
4632 modeset_update_crtc_power_domains(dev
);
4635 static void valleyview_crtc_enable(struct drm_crtc
*crtc
)
4637 struct drm_device
*dev
= crtc
->dev
;
4638 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4639 struct intel_encoder
*encoder
;
4640 int pipe
= intel_crtc
->pipe
;
4643 WARN_ON(!crtc
->enabled
);
4645 if (intel_crtc
->active
)
4648 is_dsi
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
);
4651 if (IS_CHERRYVIEW(dev
))
4652 chv_prepare_pll(intel_crtc
);
4654 vlv_prepare_pll(intel_crtc
);
4657 if (intel_crtc
->config
.has_dp_encoder
)
4658 intel_dp_set_m_n(intel_crtc
);
4660 intel_set_pipe_timings(intel_crtc
);
4662 i9xx_set_pipeconf(intel_crtc
);
4664 intel_crtc
->active
= true;
4666 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4668 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4669 if (encoder
->pre_pll_enable
)
4670 encoder
->pre_pll_enable(encoder
);
4673 if (IS_CHERRYVIEW(dev
))
4674 chv_enable_pll(intel_crtc
);
4676 vlv_enable_pll(intel_crtc
);
4679 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4680 if (encoder
->pre_enable
)
4681 encoder
->pre_enable(encoder
);
4683 i9xx_pfit_enable(intel_crtc
);
4685 intel_crtc_load_lut(crtc
);
4687 intel_update_watermarks(crtc
);
4688 intel_enable_pipe(intel_crtc
);
4690 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4691 encoder
->enable(encoder
);
4693 intel_crtc_enable_planes(crtc
);
4695 /* Underruns don't raise interrupts, so check manually. */
4696 i9xx_check_fifo_underruns(dev
);
4699 static void i9xx_set_pll_dividers(struct intel_crtc
*crtc
)
4701 struct drm_device
*dev
= crtc
->base
.dev
;
4702 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4704 I915_WRITE(FP0(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp0
);
4705 I915_WRITE(FP1(crtc
->pipe
), crtc
->config
.dpll_hw_state
.fp1
);
4708 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
4710 struct drm_device
*dev
= crtc
->dev
;
4711 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4712 struct intel_encoder
*encoder
;
4713 int pipe
= intel_crtc
->pipe
;
4715 WARN_ON(!crtc
->enabled
);
4717 if (intel_crtc
->active
)
4720 i9xx_set_pll_dividers(intel_crtc
);
4722 if (intel_crtc
->config
.has_dp_encoder
)
4723 intel_dp_set_m_n(intel_crtc
);
4725 intel_set_pipe_timings(intel_crtc
);
4727 i9xx_set_pipeconf(intel_crtc
);
4729 intel_crtc
->active
= true;
4732 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4734 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4735 if (encoder
->pre_enable
)
4736 encoder
->pre_enable(encoder
);
4738 i9xx_enable_pll(intel_crtc
);
4740 i9xx_pfit_enable(intel_crtc
);
4742 intel_crtc_load_lut(crtc
);
4744 intel_update_watermarks(crtc
);
4745 intel_enable_pipe(intel_crtc
);
4747 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4748 encoder
->enable(encoder
);
4750 intel_crtc_enable_planes(crtc
);
4753 * Gen2 reports pipe underruns whenever all planes are disabled.
4754 * So don't enable underrun reporting before at least some planes
4756 * FIXME: Need to fix the logic to work when we turn off all planes
4757 * but leave the pipe running.
4760 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, true);
4762 /* Underruns don't raise interrupts, so check manually. */
4763 i9xx_check_fifo_underruns(dev
);
4766 static void i9xx_pfit_disable(struct intel_crtc
*crtc
)
4768 struct drm_device
*dev
= crtc
->base
.dev
;
4769 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4771 if (!crtc
->config
.gmch_pfit
.control
)
4774 assert_pipe_disabled(dev_priv
, crtc
->pipe
);
4776 DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
4777 I915_READ(PFIT_CONTROL
));
4778 I915_WRITE(PFIT_CONTROL
, 0);
4781 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
4783 struct drm_device
*dev
= crtc
->dev
;
4784 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4785 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4786 struct intel_encoder
*encoder
;
4787 int pipe
= intel_crtc
->pipe
;
4789 if (!intel_crtc
->active
)
4793 * Gen2 reports pipe underruns whenever all planes are disabled.
4794 * So diasble underrun reporting before all the planes get disabled.
4795 * FIXME: Need to fix the logic to work when we turn off all planes
4796 * but leave the pipe running.
4799 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, false);
4802 * Vblank time updates from the shadow to live plane control register
4803 * are blocked if the memory self-refresh mode is active at that
4804 * moment. So to make sure the plane gets truly disabled, disable
4805 * first the self-refresh mode. The self-refresh enable bit in turn
4806 * will be checked/applied by the HW only at the next frame start
4807 * event which is after the vblank start event, so we need to have a
4808 * wait-for-vblank between disabling the plane and the pipe.
4810 intel_set_memory_cxsr(dev_priv
, false);
4811 intel_crtc_disable_planes(crtc
);
4813 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4814 encoder
->disable(encoder
);
4817 * On gen2 planes are double buffered but the pipe isn't, so we must
4818 * wait for planes to fully turn off before disabling the pipe.
4819 * We also need to wait on all gmch platforms because of the
4820 * self-refresh mode constraint explained above.
4822 intel_wait_for_vblank(dev
, pipe
);
4824 intel_disable_pipe(dev_priv
, pipe
);
4826 i9xx_pfit_disable(intel_crtc
);
4828 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
4829 if (encoder
->post_disable
)
4830 encoder
->post_disable(encoder
);
4832 if (!intel_pipe_has_type(crtc
, INTEL_OUTPUT_DSI
)) {
4833 if (IS_CHERRYVIEW(dev
))
4834 chv_disable_pll(dev_priv
, pipe
);
4835 else if (IS_VALLEYVIEW(dev
))
4836 vlv_disable_pll(dev_priv
, pipe
);
4838 i9xx_disable_pll(dev_priv
, pipe
);
4842 intel_set_cpu_fifo_underrun_reporting(dev
, pipe
, false);
4844 intel_crtc
->active
= false;
4845 intel_update_watermarks(crtc
);
4847 mutex_lock(&dev
->struct_mutex
);
4848 intel_update_fbc(dev
);
4849 mutex_unlock(&dev
->struct_mutex
);
4852 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
4856 static void intel_crtc_update_sarea(struct drm_crtc
*crtc
,
4859 struct drm_device
*dev
= crtc
->dev
;
4860 struct drm_i915_master_private
*master_priv
;
4861 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4862 int pipe
= intel_crtc
->pipe
;
4864 if (!dev
->primary
->master
)
4867 master_priv
= dev
->primary
->master
->driver_priv
;
4868 if (!master_priv
->sarea_priv
)
4873 master_priv
->sarea_priv
->pipeA_w
= enabled
? crtc
->mode
.hdisplay
: 0;
4874 master_priv
->sarea_priv
->pipeA_h
= enabled
? crtc
->mode
.vdisplay
: 0;
4877 master_priv
->sarea_priv
->pipeB_w
= enabled
? crtc
->mode
.hdisplay
: 0;
4878 master_priv
->sarea_priv
->pipeB_h
= enabled
? crtc
->mode
.vdisplay
: 0;
4881 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe
));
4886 /* Master function to enable/disable CRTC and corresponding power wells */
4887 void intel_crtc_control(struct drm_crtc
*crtc
, bool enable
)
4889 struct drm_device
*dev
= crtc
->dev
;
4890 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4891 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4892 enum intel_display_power_domain domain
;
4893 unsigned long domains
;
4896 if (!intel_crtc
->active
) {
4897 domains
= get_crtc_power_domains(crtc
);
4898 for_each_power_domain(domain
, domains
)
4899 intel_display_power_get(dev_priv
, domain
);
4900 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 domains
= intel_crtc
->enabled_power_domains
;
4909 for_each_power_domain(domain
, domains
)
4910 intel_display_power_put(dev_priv
, domain
);
4911 intel_crtc
->enabled_power_domains
= 0;
4917 * Sets the power management mode of the pipe and plane.
4919 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
4921 struct drm_device
*dev
= crtc
->dev
;
4922 struct intel_encoder
*intel_encoder
;
4923 bool enable
= false;
4925 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
4926 enable
|= intel_encoder
->connectors_active
;
4928 intel_crtc_control(crtc
, enable
);
4930 intel_crtc_update_sarea(crtc
, enable
);
4933 static void intel_crtc_disable(struct drm_crtc
*crtc
)
4935 struct drm_device
*dev
= crtc
->dev
;
4936 struct drm_connector
*connector
;
4937 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4938 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(crtc
->primary
->fb
);
4939 enum pipe pipe
= to_intel_crtc(crtc
)->pipe
;
4941 /* crtc should still be enabled when we disable it. */
4942 WARN_ON(!crtc
->enabled
);
4944 dev_priv
->display
.crtc_disable(crtc
);
4945 intel_crtc_update_sarea(crtc
, false);
4946 dev_priv
->display
.off(crtc
);
4948 if (crtc
->primary
->fb
) {
4949 mutex_lock(&dev
->struct_mutex
);
4950 intel_unpin_fb_obj(old_obj
);
4951 i915_gem_track_fb(old_obj
, NULL
,
4952 INTEL_FRONTBUFFER_PRIMARY(pipe
));
4953 mutex_unlock(&dev
->struct_mutex
);
4954 crtc
->primary
->fb
= NULL
;
4957 /* Update computed state. */
4958 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
4959 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
4962 if (connector
->encoder
->crtc
!= crtc
)
4965 connector
->dpms
= DRM_MODE_DPMS_OFF
;
4966 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
4970 void intel_encoder_destroy(struct drm_encoder
*encoder
)
4972 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
4974 drm_encoder_cleanup(encoder
);
4975 kfree(intel_encoder
);
4978 /* Simple dpms helper for encoders with just one connector, no cloning and only
4979 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
4980 * state of the entire output pipe. */
4981 static void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
4983 if (mode
== DRM_MODE_DPMS_ON
) {
4984 encoder
->connectors_active
= true;
4986 intel_crtc_update_dpms(encoder
->base
.crtc
);
4988 encoder
->connectors_active
= false;
4990 intel_crtc_update_dpms(encoder
->base
.crtc
);
4994 /* Cross check the actual hw state with our own modeset state tracking (and it's
4995 * internal consistency). */
4996 static void intel_connector_check_state(struct intel_connector
*connector
)
4998 if (connector
->get_hw_state(connector
)) {
4999 struct intel_encoder
*encoder
= connector
->encoder
;
5000 struct drm_crtc
*crtc
;
5001 bool encoder_enabled
;
5004 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5005 connector
->base
.base
.id
,
5006 connector
->base
.name
);
5008 /* there is no real hw state for MST connectors */
5009 if (connector
->mst_port
)
5012 WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
5013 "wrong connector dpms state\n");
5014 WARN(connector
->base
.encoder
!= &encoder
->base
,
5015 "active connector not linked to encoder\n");
5018 WARN(!encoder
->connectors_active
,
5019 "encoder->connectors_active not set\n");
5021 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
5022 WARN(!encoder_enabled
, "encoder not enabled\n");
5023 if (WARN_ON(!encoder
->base
.crtc
))
5026 crtc
= encoder
->base
.crtc
;
5028 WARN(!crtc
->enabled
, "crtc not enabled\n");
5029 WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
5030 WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
5031 "encoder active on the wrong pipe\n");
5036 /* Even simpler default implementation, if there's really no special case to
5038 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
5040 /* All the simple cases only support two dpms states. */
5041 if (mode
!= DRM_MODE_DPMS_ON
)
5042 mode
= DRM_MODE_DPMS_OFF
;
5044 if (mode
== connector
->dpms
)
5047 connector
->dpms
= mode
;
5049 /* Only need to change hw state when actually enabled */
5050 if (connector
->encoder
)
5051 intel_encoder_dpms(to_intel_encoder(connector
->encoder
), mode
);
5053 intel_modeset_check_state(connector
->dev
);
5056 /* Simple connector->get_hw_state implementation for encoders that support only
5057 * one connector and no cloning and hence the encoder state determines the state
5058 * of the connector. */
5059 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
5062 struct intel_encoder
*encoder
= connector
->encoder
;
5064 return encoder
->get_hw_state(encoder
, &pipe
);
5067 static bool ironlake_check_fdi_lanes(struct drm_device
*dev
, enum pipe pipe
,
5068 struct intel_crtc_config
*pipe_config
)
5070 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5071 struct intel_crtc
*pipe_B_crtc
=
5072 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
5074 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
5075 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5076 if (pipe_config
->fdi_lanes
> 4) {
5077 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
5078 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5082 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
5083 if (pipe_config
->fdi_lanes
> 2) {
5084 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
5085 pipe_config
->fdi_lanes
);
5092 if (INTEL_INFO(dev
)->num_pipes
== 2)
5095 /* Ivybridge 3 pipe is really complicated */
5100 if (dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]->enabled
&&
5101 pipe_config
->fdi_lanes
> 2) {
5102 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5103 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5108 if (!pipe_has_enabled_pch(pipe_B_crtc
) ||
5109 pipe_B_crtc
->config
.fdi_lanes
<= 2) {
5110 if (pipe_config
->fdi_lanes
> 2) {
5111 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
5112 pipe_name(pipe
), pipe_config
->fdi_lanes
);
5116 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5126 static int ironlake_fdi_compute_config(struct intel_crtc
*intel_crtc
,
5127 struct intel_crtc_config
*pipe_config
)
5129 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5130 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5131 int lane
, link_bw
, fdi_dotclock
;
5132 bool setup_ok
, needs_recompute
= false;
5135 /* FDI is a binary signal running at ~2.7GHz, encoding
5136 * each output octet as 10 bits. The actual frequency
5137 * is stored as a divider into a 100MHz clock, and the
5138 * mode pixel clock is stored in units of 1KHz.
5139 * Hence the bw of each lane in terms of the mode signal
5142 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
5144 fdi_dotclock
= adjusted_mode
->crtc_clock
;
5146 lane
= ironlake_get_lanes_required(fdi_dotclock
, link_bw
,
5147 pipe_config
->pipe_bpp
);
5149 pipe_config
->fdi_lanes
= lane
;
5151 intel_link_compute_m_n(pipe_config
->pipe_bpp
, lane
, fdi_dotclock
,
5152 link_bw
, &pipe_config
->fdi_m_n
);
5154 setup_ok
= ironlake_check_fdi_lanes(intel_crtc
->base
.dev
,
5155 intel_crtc
->pipe
, pipe_config
);
5156 if (!setup_ok
&& pipe_config
->pipe_bpp
> 6*3) {
5157 pipe_config
->pipe_bpp
-= 2*3;
5158 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
5159 pipe_config
->pipe_bpp
);
5160 needs_recompute
= true;
5161 pipe_config
->bw_constrained
= true;
5166 if (needs_recompute
)
5169 return setup_ok
? 0 : -EINVAL
;
5172 static void hsw_compute_ips_config(struct intel_crtc
*crtc
,
5173 struct intel_crtc_config
*pipe_config
)
5175 pipe_config
->ips_enabled
= i915
.enable_ips
&&
5176 hsw_crtc_supports_ips(crtc
) &&
5177 pipe_config
->pipe_bpp
<= 24;
5180 static int intel_crtc_compute_config(struct intel_crtc
*crtc
,
5181 struct intel_crtc_config
*pipe_config
)
5183 struct drm_device
*dev
= crtc
->base
.dev
;
5184 struct drm_display_mode
*adjusted_mode
= &pipe_config
->adjusted_mode
;
5186 /* FIXME should check pixel clock limits on all platforms */
5187 if (INTEL_INFO(dev
)->gen
< 4) {
5188 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5190 dev_priv
->display
.get_display_clock_speed(dev
);
5193 * Enable pixel doubling when the dot clock
5194 * is > 90% of the (display) core speed.
5196 * GDG double wide on either pipe,
5197 * otherwise pipe A only.
5199 if ((crtc
->pipe
== PIPE_A
|| IS_I915G(dev
)) &&
5200 adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10) {
5202 pipe_config
->double_wide
= true;
5205 if (adjusted_mode
->crtc_clock
> clock_limit
* 9 / 10)
5210 * Pipe horizontal size must be even in:
5212 * - LVDS dual channel mode
5213 * - Double wide pipe
5215 if ((intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5216 intel_is_dual_link_lvds(dev
)) || pipe_config
->double_wide
)
5217 pipe_config
->pipe_src_w
&= ~1;
5219 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
5220 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
5222 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
5223 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
5226 if ((IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) && pipe_config
->pipe_bpp
> 10*3) {
5227 pipe_config
->pipe_bpp
= 10*3; /* 12bpc is gen5+ */
5228 } else if (INTEL_INFO(dev
)->gen
<= 4 && pipe_config
->pipe_bpp
> 8*3) {
5229 /* only a 8bpc pipe, with 6bpc dither through the panel fitter
5231 pipe_config
->pipe_bpp
= 8*3;
5235 hsw_compute_ips_config(crtc
, pipe_config
);
5238 * XXX: PCH/WRPLL clock sharing is done in ->mode_set, so make sure the
5239 * old clock survives for now.
5241 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
) || HAS_DDI(dev
))
5242 pipe_config
->shared_dpll
= crtc
->config
.shared_dpll
;
5244 if (pipe_config
->has_pch_encoder
)
5245 return ironlake_fdi_compute_config(crtc
, pipe_config
);
5250 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
5252 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5253 int vco
= valleyview_get_vco(dev_priv
);
5257 /* FIXME: Punit isn't quite ready yet */
5258 if (IS_CHERRYVIEW(dev
))
5261 mutex_lock(&dev_priv
->dpio_lock
);
5262 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
5263 mutex_unlock(&dev_priv
->dpio_lock
);
5265 divider
= val
& DISPLAY_FREQUENCY_VALUES
;
5267 WARN((val
& DISPLAY_FREQUENCY_STATUS
) !=
5268 (divider
<< DISPLAY_FREQUENCY_STATUS_SHIFT
),
5269 "cdclk change in progress\n");
5271 return DIV_ROUND_CLOSEST(vco
<< 1, divider
+ 1);
5274 static int i945_get_display_clock_speed(struct drm_device
*dev
)
5279 static int i915_get_display_clock_speed(struct drm_device
*dev
)
5284 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
5289 static int pnv_get_display_clock_speed(struct drm_device
*dev
)
5293 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5295 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5296 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
5298 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
5300 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
5302 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
5305 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
5306 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
5308 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
5313 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
5317 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
5319 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
5322 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
5323 case GC_DISPLAY_CLOCK_333_MHZ
:
5326 case GC_DISPLAY_CLOCK_190_200_MHZ
:
5332 static int i865_get_display_clock_speed(struct drm_device
*dev
)
5337 static int i855_get_display_clock_speed(struct drm_device
*dev
)
5340 /* Assume that the hardware is in the high speed state. This
5341 * should be the default.
5343 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
5344 case GC_CLOCK_133_200
:
5345 case GC_CLOCK_100_200
:
5347 case GC_CLOCK_166_250
:
5349 case GC_CLOCK_100_133
:
5353 /* Shouldn't happen */
5357 static int i830_get_display_clock_speed(struct drm_device
*dev
)
5363 intel_reduce_m_n_ratio(uint32_t *num
, uint32_t *den
)
5365 while (*num
> DATA_LINK_M_N_MASK
||
5366 *den
> DATA_LINK_M_N_MASK
) {
5372 static void compute_m_n(unsigned int m
, unsigned int n
,
5373 uint32_t *ret_m
, uint32_t *ret_n
)
5375 *ret_n
= min_t(unsigned int, roundup_pow_of_two(n
), DATA_LINK_N_MAX
);
5376 *ret_m
= div_u64((uint64_t) m
* *ret_n
, n
);
5377 intel_reduce_m_n_ratio(ret_m
, ret_n
);
5381 intel_link_compute_m_n(int bits_per_pixel
, int nlanes
,
5382 int pixel_clock
, int link_clock
,
5383 struct intel_link_m_n
*m_n
)
5387 compute_m_n(bits_per_pixel
* pixel_clock
,
5388 link_clock
* nlanes
* 8,
5389 &m_n
->gmch_m
, &m_n
->gmch_n
);
5391 compute_m_n(pixel_clock
, link_clock
,
5392 &m_n
->link_m
, &m_n
->link_n
);
5395 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
5397 if (i915
.panel_use_ssc
>= 0)
5398 return i915
.panel_use_ssc
!= 0;
5399 return dev_priv
->vbt
.lvds_use_ssc
5400 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
5403 static int i9xx_get_refclk(struct drm_crtc
*crtc
, int num_connectors
)
5405 struct drm_device
*dev
= crtc
->dev
;
5406 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5409 if (IS_VALLEYVIEW(dev
)) {
5411 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
5412 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
5413 refclk
= dev_priv
->vbt
.lvds_ssc_freq
;
5414 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk
);
5415 } else if (!IS_GEN2(dev
)) {
5424 static uint32_t pnv_dpll_compute_fp(struct dpll
*dpll
)
5426 return (1 << dpll
->n
) << 16 | dpll
->m2
;
5429 static uint32_t i9xx_dpll_compute_fp(struct dpll
*dpll
)
5431 return dpll
->n
<< 16 | dpll
->m1
<< 8 | dpll
->m2
;
5434 static void i9xx_update_pll_dividers(struct intel_crtc
*crtc
,
5435 intel_clock_t
*reduced_clock
)
5437 struct drm_device
*dev
= crtc
->base
.dev
;
5440 if (IS_PINEVIEW(dev
)) {
5441 fp
= pnv_dpll_compute_fp(&crtc
->config
.dpll
);
5443 fp2
= pnv_dpll_compute_fp(reduced_clock
);
5445 fp
= i9xx_dpll_compute_fp(&crtc
->config
.dpll
);
5447 fp2
= i9xx_dpll_compute_fp(reduced_clock
);
5450 crtc
->config
.dpll_hw_state
.fp0
= fp
;
5452 crtc
->lowfreq_avail
= false;
5453 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5454 reduced_clock
&& i915
.powersave
) {
5455 crtc
->config
.dpll_hw_state
.fp1
= fp2
;
5456 crtc
->lowfreq_avail
= true;
5458 crtc
->config
.dpll_hw_state
.fp1
= fp
;
5462 static void vlv_pllb_recal_opamp(struct drm_i915_private
*dev_priv
, enum pipe
5468 * PLLB opamp always calibrates to max value of 0x3f, force enable it
5469 * and set it to a reasonable value instead.
5471 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5472 reg_val
&= 0xffffff00;
5473 reg_val
|= 0x00000030;
5474 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5476 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5477 reg_val
&= 0x8cffffff;
5478 reg_val
= 0x8c000000;
5479 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5481 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW9(1));
5482 reg_val
&= 0xffffff00;
5483 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9(1), reg_val
);
5485 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_REF_DW13
);
5486 reg_val
&= 0x00ffffff;
5487 reg_val
|= 0xb0000000;
5488 vlv_dpio_write(dev_priv
, pipe
, VLV_REF_DW13
, reg_val
);
5491 static void intel_pch_transcoder_set_m_n(struct intel_crtc
*crtc
,
5492 struct intel_link_m_n
*m_n
)
5494 struct drm_device
*dev
= crtc
->base
.dev
;
5495 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5496 int pipe
= crtc
->pipe
;
5498 I915_WRITE(PCH_TRANS_DATA_M1(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5499 I915_WRITE(PCH_TRANS_DATA_N1(pipe
), m_n
->gmch_n
);
5500 I915_WRITE(PCH_TRANS_LINK_M1(pipe
), m_n
->link_m
);
5501 I915_WRITE(PCH_TRANS_LINK_N1(pipe
), m_n
->link_n
);
5504 static void intel_cpu_transcoder_set_m_n(struct intel_crtc
*crtc
,
5505 struct intel_link_m_n
*m_n
,
5506 struct intel_link_m_n
*m2_n2
)
5508 struct drm_device
*dev
= crtc
->base
.dev
;
5509 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5510 int pipe
= crtc
->pipe
;
5511 enum transcoder transcoder
= crtc
->config
.cpu_transcoder
;
5513 if (INTEL_INFO(dev
)->gen
>= 5) {
5514 I915_WRITE(PIPE_DATA_M1(transcoder
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5515 I915_WRITE(PIPE_DATA_N1(transcoder
), m_n
->gmch_n
);
5516 I915_WRITE(PIPE_LINK_M1(transcoder
), m_n
->link_m
);
5517 I915_WRITE(PIPE_LINK_N1(transcoder
), m_n
->link_n
);
5518 /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
5519 * for gen < 8) and if DRRS is supported (to make sure the
5520 * registers are not unnecessarily accessed).
5522 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
5523 crtc
->config
.has_drrs
) {
5524 I915_WRITE(PIPE_DATA_M2(transcoder
),
5525 TU_SIZE(m2_n2
->tu
) | m2_n2
->gmch_m
);
5526 I915_WRITE(PIPE_DATA_N2(transcoder
), m2_n2
->gmch_n
);
5527 I915_WRITE(PIPE_LINK_M2(transcoder
), m2_n2
->link_m
);
5528 I915_WRITE(PIPE_LINK_N2(transcoder
), m2_n2
->link_n
);
5531 I915_WRITE(PIPE_DATA_M_G4X(pipe
), TU_SIZE(m_n
->tu
) | m_n
->gmch_m
);
5532 I915_WRITE(PIPE_DATA_N_G4X(pipe
), m_n
->gmch_n
);
5533 I915_WRITE(PIPE_LINK_M_G4X(pipe
), m_n
->link_m
);
5534 I915_WRITE(PIPE_LINK_N_G4X(pipe
), m_n
->link_n
);
5538 void intel_dp_set_m_n(struct intel_crtc
*crtc
)
5540 if (crtc
->config
.has_pch_encoder
)
5541 intel_pch_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
);
5543 intel_cpu_transcoder_set_m_n(crtc
, &crtc
->config
.dp_m_n
,
5544 &crtc
->config
.dp_m2_n2
);
5547 static void vlv_update_pll(struct intel_crtc
*crtc
)
5552 * Enable DPIO clock input. We should never disable the reference
5553 * clock for pipe B, since VGA hotplug / manual detection depends
5556 dpll
= DPLL_EXT_BUFFER_ENABLE_VLV
| DPLL_REFA_CLK_ENABLE_VLV
|
5557 DPLL_VGA_MODE_DIS
| DPLL_INTEGRATED_CLOCK_VLV
;
5558 /* We should never disable this, set it here for state tracking */
5559 if (crtc
->pipe
== PIPE_B
)
5560 dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5561 dpll
|= DPLL_VCO_ENABLE
;
5562 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5564 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
5565 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5566 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
5569 static void vlv_prepare_pll(struct intel_crtc
*crtc
)
5571 struct drm_device
*dev
= crtc
->base
.dev
;
5572 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5573 int pipe
= crtc
->pipe
;
5575 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
5576 u32 coreclk
, reg_val
;
5578 mutex_lock(&dev_priv
->dpio_lock
);
5580 bestn
= crtc
->config
.dpll
.n
;
5581 bestm1
= crtc
->config
.dpll
.m1
;
5582 bestm2
= crtc
->config
.dpll
.m2
;
5583 bestp1
= crtc
->config
.dpll
.p1
;
5584 bestp2
= crtc
->config
.dpll
.p2
;
5586 /* See eDP HDMI DPIO driver vbios notes doc */
5588 /* PLL B needs special handling */
5590 vlv_pllb_recal_opamp(dev_priv
, pipe
);
5592 /* Set up Tx target for periodic Rcomp update */
5593 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW9_BCAST
, 0x0100000f);
5595 /* Disable target IRef on PLL */
5596 reg_val
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW8(pipe
));
5597 reg_val
&= 0x00ffffff;
5598 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW8(pipe
), reg_val
);
5600 /* Disable fast lock */
5601 vlv_dpio_write(dev_priv
, pipe
, VLV_CMN_DW0
, 0x610);
5603 /* Set idtafcrecal before PLL is enabled */
5604 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
5605 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
5606 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
5607 mdiv
|= (1 << DPIO_K_SHIFT
);
5610 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
5611 * but we don't support that).
5612 * Note: don't use the DAC post divider as it seems unstable.
5614 mdiv
|= (DPIO_POST_DIV_HDMIDP
<< DPIO_POST_DIV_SHIFT
);
5615 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5617 mdiv
|= DPIO_ENABLE_CALIBRATION
;
5618 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW3(pipe
), mdiv
);
5620 /* Set HBR and RBR LPF coefficients */
5621 if (crtc
->config
.port_clock
== 162000 ||
5622 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_ANALOG
) ||
5623 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
))
5624 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5627 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW10(pipe
),
5630 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
) ||
5631 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
)) {
5632 /* Use SSC source */
5634 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5637 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5639 } else { /* HDMI or VGA */
5640 /* Use bend source */
5642 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5645 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW5(pipe
),
5649 coreclk
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW7(pipe
));
5650 coreclk
= (coreclk
& 0x0000ff00) | 0x01c00000;
5651 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
) ||
5652 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_EDP
))
5653 coreclk
|= 0x01000000;
5654 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW7(pipe
), coreclk
);
5656 vlv_dpio_write(dev_priv
, pipe
, VLV_PLL_DW11(pipe
), 0x87871000);
5657 mutex_unlock(&dev_priv
->dpio_lock
);
5660 static void chv_update_pll(struct intel_crtc
*crtc
)
5662 crtc
->config
.dpll_hw_state
.dpll
= DPLL_SSC_REF_CLOCK_CHV
|
5663 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
|
5665 if (crtc
->pipe
!= PIPE_A
)
5666 crtc
->config
.dpll_hw_state
.dpll
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
5668 crtc
->config
.dpll_hw_state
.dpll_md
=
5669 (crtc
->config
.pixel_multiplier
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5672 static void chv_prepare_pll(struct intel_crtc
*crtc
)
5674 struct drm_device
*dev
= crtc
->base
.dev
;
5675 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5676 int pipe
= crtc
->pipe
;
5677 int dpll_reg
= DPLL(crtc
->pipe
);
5678 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
5679 u32 loopfilter
, intcoeff
;
5680 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
, bestm2_frac
;
5683 bestn
= crtc
->config
.dpll
.n
;
5684 bestm2_frac
= crtc
->config
.dpll
.m2
& 0x3fffff;
5685 bestm1
= crtc
->config
.dpll
.m1
;
5686 bestm2
= crtc
->config
.dpll
.m2
>> 22;
5687 bestp1
= crtc
->config
.dpll
.p1
;
5688 bestp2
= crtc
->config
.dpll
.p2
;
5691 * Enable Refclk and SSC
5693 I915_WRITE(dpll_reg
,
5694 crtc
->config
.dpll_hw_state
.dpll
& ~DPLL_VCO_ENABLE
);
5696 mutex_lock(&dev_priv
->dpio_lock
);
5698 /* p1 and p2 divider */
5699 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW13(port
),
5700 5 << DPIO_CHV_S1_DIV_SHIFT
|
5701 bestp1
<< DPIO_CHV_P1_DIV_SHIFT
|
5702 bestp2
<< DPIO_CHV_P2_DIV_SHIFT
|
5703 1 << DPIO_CHV_K_DIV_SHIFT
);
5705 /* Feedback post-divider - m2 */
5706 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW0(port
), bestm2
);
5708 /* Feedback refclk divider - n and m1 */
5709 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW1(port
),
5710 DPIO_CHV_M1_DIV_BY_2
|
5711 1 << DPIO_CHV_N_DIV_SHIFT
);
5713 /* M2 fraction division */
5714 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW2(port
), bestm2_frac
);
5716 /* M2 fraction division enable */
5717 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW3(port
),
5718 DPIO_CHV_FRAC_DIV_EN
|
5719 (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT
));
5722 refclk
= i9xx_get_refclk(&crtc
->base
, 0);
5723 loopfilter
= 5 << DPIO_CHV_PROP_COEFF_SHIFT
|
5724 2 << DPIO_CHV_GAIN_CTRL_SHIFT
;
5725 if (refclk
== 100000)
5727 else if (refclk
== 38400)
5731 loopfilter
|= intcoeff
<< DPIO_CHV_INT_COEFF_SHIFT
;
5732 vlv_dpio_write(dev_priv
, pipe
, CHV_PLL_DW6(port
), loopfilter
);
5735 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW14(port
),
5736 vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW14(port
)) |
5739 mutex_unlock(&dev_priv
->dpio_lock
);
5742 static void i9xx_update_pll(struct intel_crtc
*crtc
,
5743 intel_clock_t
*reduced_clock
,
5746 struct drm_device
*dev
= crtc
->base
.dev
;
5747 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5750 struct dpll
*clock
= &crtc
->config
.dpll
;
5752 i9xx_update_pll_dividers(crtc
, reduced_clock
);
5754 is_sdvo
= intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_SDVO
) ||
5755 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
);
5757 dpll
= DPLL_VGA_MODE_DIS
;
5759 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
))
5760 dpll
|= DPLLB_MODE_LVDS
;
5762 dpll
|= DPLLB_MODE_DAC_SERIAL
;
5764 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
5765 dpll
|= (crtc
->config
.pixel_multiplier
- 1)
5766 << SDVO_MULTIPLIER_SHIFT_HIRES
;
5770 dpll
|= DPLL_SDVO_HIGH_SPEED
;
5772 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DISPLAYPORT
))
5773 dpll
|= DPLL_SDVO_HIGH_SPEED
;
5775 /* compute bitmask from p1 value */
5776 if (IS_PINEVIEW(dev
))
5777 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
5779 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5780 if (IS_G4X(dev
) && reduced_clock
)
5781 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
5783 switch (clock
->p2
) {
5785 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
5788 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
5791 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
5794 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
5797 if (INTEL_INFO(dev
)->gen
>= 4)
5798 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
5800 if (crtc
->config
.sdvo_tv_clock
)
5801 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
5802 else if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5803 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5804 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5806 dpll
|= PLL_REF_INPUT_DREFCLK
;
5808 dpll
|= DPLL_VCO_ENABLE
;
5809 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5811 if (INTEL_INFO(dev
)->gen
>= 4) {
5812 u32 dpll_md
= (crtc
->config
.pixel_multiplier
- 1)
5813 << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
5814 crtc
->config
.dpll_hw_state
.dpll_md
= dpll_md
;
5818 static void i8xx_update_pll(struct intel_crtc
*crtc
,
5819 intel_clock_t
*reduced_clock
,
5822 struct drm_device
*dev
= crtc
->base
.dev
;
5823 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5825 struct dpll
*clock
= &crtc
->config
.dpll
;
5827 i9xx_update_pll_dividers(crtc
, reduced_clock
);
5829 dpll
= DPLL_VGA_MODE_DIS
;
5831 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
)) {
5832 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5835 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
5837 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5839 dpll
|= PLL_P2_DIVIDE_BY_4
;
5842 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_DVO
))
5843 dpll
|= DPLL_DVO_2X_MODE
;
5845 if (intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_LVDS
) &&
5846 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5847 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5849 dpll
|= PLL_REF_INPUT_DREFCLK
;
5851 dpll
|= DPLL_VCO_ENABLE
;
5852 crtc
->config
.dpll_hw_state
.dpll
= dpll
;
5855 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
)
5857 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5858 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5859 enum pipe pipe
= intel_crtc
->pipe
;
5860 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
5861 struct drm_display_mode
*adjusted_mode
=
5862 &intel_crtc
->config
.adjusted_mode
;
5863 uint32_t crtc_vtotal
, crtc_vblank_end
;
5866 /* We need to be careful not to changed the adjusted mode, for otherwise
5867 * the hw state checker will get angry at the mismatch. */
5868 crtc_vtotal
= adjusted_mode
->crtc_vtotal
;
5869 crtc_vblank_end
= adjusted_mode
->crtc_vblank_end
;
5871 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
5872 /* the chip adds 2 halflines automatically */
5874 crtc_vblank_end
-= 1;
5876 if (intel_pipe_has_type(&intel_crtc
->base
, INTEL_OUTPUT_SDVO
))
5877 vsyncshift
= (adjusted_mode
->crtc_htotal
- 1) / 2;
5879 vsyncshift
= adjusted_mode
->crtc_hsync_start
-
5880 adjusted_mode
->crtc_htotal
/ 2;
5882 vsyncshift
+= adjusted_mode
->crtc_htotal
;
5885 if (INTEL_INFO(dev
)->gen
> 3)
5886 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
5888 I915_WRITE(HTOTAL(cpu_transcoder
),
5889 (adjusted_mode
->crtc_hdisplay
- 1) |
5890 ((adjusted_mode
->crtc_htotal
- 1) << 16));
5891 I915_WRITE(HBLANK(cpu_transcoder
),
5892 (adjusted_mode
->crtc_hblank_start
- 1) |
5893 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
5894 I915_WRITE(HSYNC(cpu_transcoder
),
5895 (adjusted_mode
->crtc_hsync_start
- 1) |
5896 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
5898 I915_WRITE(VTOTAL(cpu_transcoder
),
5899 (adjusted_mode
->crtc_vdisplay
- 1) |
5900 ((crtc_vtotal
- 1) << 16));
5901 I915_WRITE(VBLANK(cpu_transcoder
),
5902 (adjusted_mode
->crtc_vblank_start
- 1) |
5903 ((crtc_vblank_end
- 1) << 16));
5904 I915_WRITE(VSYNC(cpu_transcoder
),
5905 (adjusted_mode
->crtc_vsync_start
- 1) |
5906 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
5908 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
5909 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
5910 * documented on the DDI_FUNC_CTL register description, EDP Input Select
5912 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
5913 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
5914 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
5916 /* pipesrc controls the size that is scaled from, which should
5917 * always be the user's requested size.
5919 I915_WRITE(PIPESRC(pipe
),
5920 ((intel_crtc
->config
.pipe_src_w
- 1) << 16) |
5921 (intel_crtc
->config
.pipe_src_h
- 1));
5924 static void intel_get_pipe_timings(struct intel_crtc
*crtc
,
5925 struct intel_crtc_config
*pipe_config
)
5927 struct drm_device
*dev
= crtc
->base
.dev
;
5928 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5929 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
5932 tmp
= I915_READ(HTOTAL(cpu_transcoder
));
5933 pipe_config
->adjusted_mode
.crtc_hdisplay
= (tmp
& 0xffff) + 1;
5934 pipe_config
->adjusted_mode
.crtc_htotal
= ((tmp
>> 16) & 0xffff) + 1;
5935 tmp
= I915_READ(HBLANK(cpu_transcoder
));
5936 pipe_config
->adjusted_mode
.crtc_hblank_start
= (tmp
& 0xffff) + 1;
5937 pipe_config
->adjusted_mode
.crtc_hblank_end
= ((tmp
>> 16) & 0xffff) + 1;
5938 tmp
= I915_READ(HSYNC(cpu_transcoder
));
5939 pipe_config
->adjusted_mode
.crtc_hsync_start
= (tmp
& 0xffff) + 1;
5940 pipe_config
->adjusted_mode
.crtc_hsync_end
= ((tmp
>> 16) & 0xffff) + 1;
5942 tmp
= I915_READ(VTOTAL(cpu_transcoder
));
5943 pipe_config
->adjusted_mode
.crtc_vdisplay
= (tmp
& 0xffff) + 1;
5944 pipe_config
->adjusted_mode
.crtc_vtotal
= ((tmp
>> 16) & 0xffff) + 1;
5945 tmp
= I915_READ(VBLANK(cpu_transcoder
));
5946 pipe_config
->adjusted_mode
.crtc_vblank_start
= (tmp
& 0xffff) + 1;
5947 pipe_config
->adjusted_mode
.crtc_vblank_end
= ((tmp
>> 16) & 0xffff) + 1;
5948 tmp
= I915_READ(VSYNC(cpu_transcoder
));
5949 pipe_config
->adjusted_mode
.crtc_vsync_start
= (tmp
& 0xffff) + 1;
5950 pipe_config
->adjusted_mode
.crtc_vsync_end
= ((tmp
>> 16) & 0xffff) + 1;
5952 if (I915_READ(PIPECONF(cpu_transcoder
)) & PIPECONF_INTERLACE_MASK
) {
5953 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_INTERLACE
;
5954 pipe_config
->adjusted_mode
.crtc_vtotal
+= 1;
5955 pipe_config
->adjusted_mode
.crtc_vblank_end
+= 1;
5958 tmp
= I915_READ(PIPESRC(crtc
->pipe
));
5959 pipe_config
->pipe_src_h
= (tmp
& 0xffff) + 1;
5960 pipe_config
->pipe_src_w
= ((tmp
>> 16) & 0xffff) + 1;
5962 pipe_config
->requested_mode
.vdisplay
= pipe_config
->pipe_src_h
;
5963 pipe_config
->requested_mode
.hdisplay
= pipe_config
->pipe_src_w
;
5966 void intel_mode_from_pipe_config(struct drm_display_mode
*mode
,
5967 struct intel_crtc_config
*pipe_config
)
5969 mode
->hdisplay
= pipe_config
->adjusted_mode
.crtc_hdisplay
;
5970 mode
->htotal
= pipe_config
->adjusted_mode
.crtc_htotal
;
5971 mode
->hsync_start
= pipe_config
->adjusted_mode
.crtc_hsync_start
;
5972 mode
->hsync_end
= pipe_config
->adjusted_mode
.crtc_hsync_end
;
5974 mode
->vdisplay
= pipe_config
->adjusted_mode
.crtc_vdisplay
;
5975 mode
->vtotal
= pipe_config
->adjusted_mode
.crtc_vtotal
;
5976 mode
->vsync_start
= pipe_config
->adjusted_mode
.crtc_vsync_start
;
5977 mode
->vsync_end
= pipe_config
->adjusted_mode
.crtc_vsync_end
;
5979 mode
->flags
= pipe_config
->adjusted_mode
.flags
;
5981 mode
->clock
= pipe_config
->adjusted_mode
.crtc_clock
;
5982 mode
->flags
|= pipe_config
->adjusted_mode
.flags
;
5985 static void i9xx_set_pipeconf(struct intel_crtc
*intel_crtc
)
5987 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5988 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5993 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
5994 I915_READ(PIPECONF(intel_crtc
->pipe
)) & PIPECONF_ENABLE
)
5995 pipeconf
|= PIPECONF_ENABLE
;
5997 if (intel_crtc
->config
.double_wide
)
5998 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
6000 /* only g4x and later have fancy bpc/dither controls */
6001 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
6002 /* Bspec claims that we can't use dithering for 30bpp pipes. */
6003 if (intel_crtc
->config
.dither
&& intel_crtc
->config
.pipe_bpp
!= 30)
6004 pipeconf
|= PIPECONF_DITHER_EN
|
6005 PIPECONF_DITHER_TYPE_SP
;
6007 switch (intel_crtc
->config
.pipe_bpp
) {
6009 pipeconf
|= PIPECONF_6BPC
;
6012 pipeconf
|= PIPECONF_8BPC
;
6015 pipeconf
|= PIPECONF_10BPC
;
6018 /* Case prevented by intel_choose_pipe_bpp_dither. */
6023 if (HAS_PIPE_CXSR(dev
)) {
6024 if (intel_crtc
->lowfreq_avail
) {
6025 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
6026 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
6028 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
6032 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
) {
6033 if (INTEL_INFO(dev
)->gen
< 4 ||
6034 intel_pipe_has_type(&intel_crtc
->base
, INTEL_OUTPUT_SDVO
))
6035 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
6037 pipeconf
|= PIPECONF_INTERLACE_W_SYNC_SHIFT
;
6039 pipeconf
|= PIPECONF_PROGRESSIVE
;
6041 if (IS_VALLEYVIEW(dev
) && intel_crtc
->config
.limited_color_range
)
6042 pipeconf
|= PIPECONF_COLOR_RANGE_SELECT
;
6044 I915_WRITE(PIPECONF(intel_crtc
->pipe
), pipeconf
);
6045 POSTING_READ(PIPECONF(intel_crtc
->pipe
));
6048 static int i9xx_crtc_mode_set(struct drm_crtc
*crtc
,
6050 struct drm_framebuffer
*fb
)
6052 struct drm_device
*dev
= crtc
->dev
;
6053 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6054 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6055 int refclk
, num_connectors
= 0;
6056 intel_clock_t clock
, reduced_clock
;
6057 bool ok
, has_reduced_clock
= false;
6058 bool is_lvds
= false, is_dsi
= false;
6059 struct intel_encoder
*encoder
;
6060 const intel_limit_t
*limit
;
6062 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
6063 switch (encoder
->type
) {
6064 case INTEL_OUTPUT_LVDS
:
6067 case INTEL_OUTPUT_DSI
:
6078 if (!intel_crtc
->config
.clock_set
) {
6079 refclk
= i9xx_get_refclk(crtc
, num_connectors
);
6082 * Returns a set of divisors for the desired target clock with
6083 * the given refclk, or FALSE. The returned values represent
6084 * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
6087 limit
= intel_limit(crtc
, refclk
);
6088 ok
= dev_priv
->display
.find_dpll(limit
, crtc
,
6089 intel_crtc
->config
.port_clock
,
6090 refclk
, NULL
, &clock
);
6092 DRM_ERROR("Couldn't find PLL settings for mode!\n");
6096 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
6098 * Ensure we match the reduced clock's P to the target
6099 * clock. If the clocks don't match, we can't switch
6100 * the display clock by using the FP0/FP1. In such case
6101 * we will disable the LVDS downclock feature.
6104 dev_priv
->display
.find_dpll(limit
, crtc
,
6105 dev_priv
->lvds_downclock
,
6109 /* Compat-code for transition, will disappear. */
6110 intel_crtc
->config
.dpll
.n
= clock
.n
;
6111 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
6112 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
6113 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
6114 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
6118 i8xx_update_pll(intel_crtc
,
6119 has_reduced_clock
? &reduced_clock
: NULL
,
6121 } else if (IS_CHERRYVIEW(dev
)) {
6122 chv_update_pll(intel_crtc
);
6123 } else if (IS_VALLEYVIEW(dev
)) {
6124 vlv_update_pll(intel_crtc
);
6126 i9xx_update_pll(intel_crtc
,
6127 has_reduced_clock
? &reduced_clock
: NULL
,
6134 static void i9xx_get_pfit_config(struct intel_crtc
*crtc
,
6135 struct intel_crtc_config
*pipe_config
)
6137 struct drm_device
*dev
= crtc
->base
.dev
;
6138 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6141 if (INTEL_INFO(dev
)->gen
<= 3 && (IS_I830(dev
) || !IS_MOBILE(dev
)))
6144 tmp
= I915_READ(PFIT_CONTROL
);
6145 if (!(tmp
& PFIT_ENABLE
))
6148 /* Check whether the pfit is attached to our pipe. */
6149 if (INTEL_INFO(dev
)->gen
< 4) {
6150 if (crtc
->pipe
!= PIPE_B
)
6153 if ((tmp
& PFIT_PIPE_MASK
) != (crtc
->pipe
<< PFIT_PIPE_SHIFT
))
6157 pipe_config
->gmch_pfit
.control
= tmp
;
6158 pipe_config
->gmch_pfit
.pgm_ratios
= I915_READ(PFIT_PGM_RATIOS
);
6159 if (INTEL_INFO(dev
)->gen
< 5)
6160 pipe_config
->gmch_pfit
.lvds_border_bits
=
6161 I915_READ(LVDS
) & LVDS_BORDER_ENABLE
;
6164 static void vlv_crtc_clock_get(struct intel_crtc
*crtc
,
6165 struct intel_crtc_config
*pipe_config
)
6167 struct drm_device
*dev
= crtc
->base
.dev
;
6168 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6169 int pipe
= pipe_config
->cpu_transcoder
;
6170 intel_clock_t clock
;
6172 int refclk
= 100000;
6174 /* In case of MIPI DPLL will not even be used */
6175 if (!(pipe_config
->dpll_hw_state
.dpll
& DPLL_VCO_ENABLE
))
6178 mutex_lock(&dev_priv
->dpio_lock
);
6179 mdiv
= vlv_dpio_read(dev_priv
, pipe
, VLV_PLL_DW3(pipe
));
6180 mutex_unlock(&dev_priv
->dpio_lock
);
6182 clock
.m1
= (mdiv
>> DPIO_M1DIV_SHIFT
) & 7;
6183 clock
.m2
= mdiv
& DPIO_M2DIV_MASK
;
6184 clock
.n
= (mdiv
>> DPIO_N_SHIFT
) & 0xf;
6185 clock
.p1
= (mdiv
>> DPIO_P1_SHIFT
) & 7;
6186 clock
.p2
= (mdiv
>> DPIO_P2_SHIFT
) & 0x1f;
6188 vlv_clock(refclk
, &clock
);
6190 /* clock.dot is the fast clock */
6191 pipe_config
->port_clock
= clock
.dot
/ 5;
6194 static void i9xx_get_plane_config(struct intel_crtc
*crtc
,
6195 struct intel_plane_config
*plane_config
)
6197 struct drm_device
*dev
= crtc
->base
.dev
;
6198 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6199 u32 val
, base
, offset
;
6200 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
6201 int fourcc
, pixel_format
;
6204 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
6205 if (!crtc
->base
.primary
->fb
) {
6206 DRM_DEBUG_KMS("failed to alloc fb\n");
6210 val
= I915_READ(DSPCNTR(plane
));
6212 if (INTEL_INFO(dev
)->gen
>= 4)
6213 if (val
& DISPPLANE_TILED
)
6214 plane_config
->tiled
= true;
6216 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
6217 fourcc
= intel_format_to_fourcc(pixel_format
);
6218 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
6219 crtc
->base
.primary
->fb
->bits_per_pixel
=
6220 drm_format_plane_cpp(fourcc
, 0) * 8;
6222 if (INTEL_INFO(dev
)->gen
>= 4) {
6223 if (plane_config
->tiled
)
6224 offset
= I915_READ(DSPTILEOFF(plane
));
6226 offset
= I915_READ(DSPLINOFF(plane
));
6227 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
6229 base
= I915_READ(DSPADDR(plane
));
6231 plane_config
->base
= base
;
6233 val
= I915_READ(PIPESRC(pipe
));
6234 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
6235 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
6237 val
= I915_READ(DSPSTRIDE(pipe
));
6238 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffffc0;
6240 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
6241 plane_config
->tiled
);
6243 plane_config
->size
= PAGE_ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
6246 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
6247 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
6248 crtc
->base
.primary
->fb
->height
,
6249 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
6250 crtc
->base
.primary
->fb
->pitches
[0],
6251 plane_config
->size
);
6255 static void chv_crtc_clock_get(struct intel_crtc
*crtc
,
6256 struct intel_crtc_config
*pipe_config
)
6258 struct drm_device
*dev
= crtc
->base
.dev
;
6259 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6260 int pipe
= pipe_config
->cpu_transcoder
;
6261 enum dpio_channel port
= vlv_pipe_to_channel(pipe
);
6262 intel_clock_t clock
;
6263 u32 cmn_dw13
, pll_dw0
, pll_dw1
, pll_dw2
;
6264 int refclk
= 100000;
6266 mutex_lock(&dev_priv
->dpio_lock
);
6267 cmn_dw13
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW13(port
));
6268 pll_dw0
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW0(port
));
6269 pll_dw1
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW1(port
));
6270 pll_dw2
= vlv_dpio_read(dev_priv
, pipe
, CHV_PLL_DW2(port
));
6271 mutex_unlock(&dev_priv
->dpio_lock
);
6273 clock
.m1
= (pll_dw1
& 0x7) == DPIO_CHV_M1_DIV_BY_2
? 2 : 0;
6274 clock
.m2
= ((pll_dw0
& 0xff) << 22) | (pll_dw2
& 0x3fffff);
6275 clock
.n
= (pll_dw1
>> DPIO_CHV_N_DIV_SHIFT
) & 0xf;
6276 clock
.p1
= (cmn_dw13
>> DPIO_CHV_P1_DIV_SHIFT
) & 0x7;
6277 clock
.p2
= (cmn_dw13
>> DPIO_CHV_P2_DIV_SHIFT
) & 0x1f;
6279 chv_clock(refclk
, &clock
);
6281 /* clock.dot is the fast clock */
6282 pipe_config
->port_clock
= clock
.dot
/ 5;
6285 static bool i9xx_get_pipe_config(struct intel_crtc
*crtc
,
6286 struct intel_crtc_config
*pipe_config
)
6288 struct drm_device
*dev
= crtc
->base
.dev
;
6289 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6292 if (!intel_display_power_enabled(dev_priv
,
6293 POWER_DOMAIN_PIPE(crtc
->pipe
)))
6296 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
6297 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
6299 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
6300 if (!(tmp
& PIPECONF_ENABLE
))
6303 if (IS_G4X(dev
) || IS_VALLEYVIEW(dev
)) {
6304 switch (tmp
& PIPECONF_BPC_MASK
) {
6306 pipe_config
->pipe_bpp
= 18;
6309 pipe_config
->pipe_bpp
= 24;
6311 case PIPECONF_10BPC
:
6312 pipe_config
->pipe_bpp
= 30;
6319 if (IS_VALLEYVIEW(dev
) && (tmp
& PIPECONF_COLOR_RANGE_SELECT
))
6320 pipe_config
->limited_color_range
= true;
6322 if (INTEL_INFO(dev
)->gen
< 4)
6323 pipe_config
->double_wide
= tmp
& PIPECONF_DOUBLE_WIDE
;
6325 intel_get_pipe_timings(crtc
, pipe_config
);
6327 i9xx_get_pfit_config(crtc
, pipe_config
);
6329 if (INTEL_INFO(dev
)->gen
>= 4) {
6330 tmp
= I915_READ(DPLL_MD(crtc
->pipe
));
6331 pipe_config
->pixel_multiplier
=
6332 ((tmp
& DPLL_MD_UDI_MULTIPLIER_MASK
)
6333 >> DPLL_MD_UDI_MULTIPLIER_SHIFT
) + 1;
6334 pipe_config
->dpll_hw_state
.dpll_md
= tmp
;
6335 } else if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
)) {
6336 tmp
= I915_READ(DPLL(crtc
->pipe
));
6337 pipe_config
->pixel_multiplier
=
6338 ((tmp
& SDVO_MULTIPLIER_MASK
)
6339 >> SDVO_MULTIPLIER_SHIFT_HIRES
) + 1;
6341 /* Note that on i915G/GM the pixel multiplier is in the sdvo
6342 * port and will be fixed up in the encoder->get_config
6344 pipe_config
->pixel_multiplier
= 1;
6346 pipe_config
->dpll_hw_state
.dpll
= I915_READ(DPLL(crtc
->pipe
));
6347 if (!IS_VALLEYVIEW(dev
)) {
6348 pipe_config
->dpll_hw_state
.fp0
= I915_READ(FP0(crtc
->pipe
));
6349 pipe_config
->dpll_hw_state
.fp1
= I915_READ(FP1(crtc
->pipe
));
6351 /* Mask out read-only status bits. */
6352 pipe_config
->dpll_hw_state
.dpll
&= ~(DPLL_LOCK_VLV
|
6353 DPLL_PORTC_READY_MASK
|
6354 DPLL_PORTB_READY_MASK
);
6357 if (IS_CHERRYVIEW(dev
))
6358 chv_crtc_clock_get(crtc
, pipe_config
);
6359 else if (IS_VALLEYVIEW(dev
))
6360 vlv_crtc_clock_get(crtc
, pipe_config
);
6362 i9xx_crtc_clock_get(crtc
, pipe_config
);
6367 static void ironlake_init_pch_refclk(struct drm_device
*dev
)
6369 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6370 struct intel_encoder
*encoder
;
6372 bool has_lvds
= false;
6373 bool has_cpu_edp
= false;
6374 bool has_panel
= false;
6375 bool has_ck505
= false;
6376 bool can_ssc
= false;
6378 /* We need to take the global config into account */
6379 for_each_intel_encoder(dev
, encoder
) {
6380 switch (encoder
->type
) {
6381 case INTEL_OUTPUT_LVDS
:
6385 case INTEL_OUTPUT_EDP
:
6387 if (enc_to_dig_port(&encoder
->base
)->port
== PORT_A
)
6393 if (HAS_PCH_IBX(dev
)) {
6394 has_ck505
= dev_priv
->vbt
.display_clock_mode
;
6395 can_ssc
= has_ck505
;
6401 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
6402 has_panel
, has_lvds
, has_ck505
);
6404 /* Ironlake: try to setup display ref clock before DPLL
6405 * enabling. This is only under driver's control after
6406 * PCH B stepping, previous chipset stepping should be
6407 * ignoring this setting.
6409 val
= I915_READ(PCH_DREF_CONTROL
);
6411 /* As we must carefully and slowly disable/enable each source in turn,
6412 * compute the final state we want first and check if we need to
6413 * make any changes at all.
6416 final
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6418 final
|= DREF_NONSPREAD_CK505_ENABLE
;
6420 final
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6422 final
&= ~DREF_SSC_SOURCE_MASK
;
6423 final
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6424 final
&= ~DREF_SSC1_ENABLE
;
6427 final
|= DREF_SSC_SOURCE_ENABLE
;
6429 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6430 final
|= DREF_SSC1_ENABLE
;
6433 if (intel_panel_use_ssc(dev_priv
) && can_ssc
)
6434 final
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6436 final
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6438 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6440 final
|= DREF_SSC_SOURCE_DISABLE
;
6441 final
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6447 /* Always enable nonspread source */
6448 val
&= ~DREF_NONSPREAD_SOURCE_MASK
;
6451 val
|= DREF_NONSPREAD_CK505_ENABLE
;
6453 val
|= DREF_NONSPREAD_SOURCE_ENABLE
;
6456 val
&= ~DREF_SSC_SOURCE_MASK
;
6457 val
|= DREF_SSC_SOURCE_ENABLE
;
6459 /* SSC must be turned on before enabling the CPU output */
6460 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6461 DRM_DEBUG_KMS("Using SSC on panel\n");
6462 val
|= DREF_SSC1_ENABLE
;
6464 val
&= ~DREF_SSC1_ENABLE
;
6466 /* Get SSC going before enabling the outputs */
6467 I915_WRITE(PCH_DREF_CONTROL
, val
);
6468 POSTING_READ(PCH_DREF_CONTROL
);
6471 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6473 /* Enable CPU source on CPU attached eDP */
6475 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
6476 DRM_DEBUG_KMS("Using SSC on eDP\n");
6477 val
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
6479 val
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
6481 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6483 I915_WRITE(PCH_DREF_CONTROL
, val
);
6484 POSTING_READ(PCH_DREF_CONTROL
);
6487 DRM_DEBUG_KMS("Disabling SSC entirely\n");
6489 val
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
6491 /* Turn off CPU output */
6492 val
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
6494 I915_WRITE(PCH_DREF_CONTROL
, val
);
6495 POSTING_READ(PCH_DREF_CONTROL
);
6498 /* Turn off the SSC source */
6499 val
&= ~DREF_SSC_SOURCE_MASK
;
6500 val
|= DREF_SSC_SOURCE_DISABLE
;
6503 val
&= ~DREF_SSC1_ENABLE
;
6505 I915_WRITE(PCH_DREF_CONTROL
, val
);
6506 POSTING_READ(PCH_DREF_CONTROL
);
6510 BUG_ON(val
!= final
);
6513 static void lpt_reset_fdi_mphy(struct drm_i915_private
*dev_priv
)
6517 tmp
= I915_READ(SOUTH_CHICKEN2
);
6518 tmp
|= FDI_MPHY_IOSFSB_RESET_CTL
;
6519 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6521 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2
) &
6522 FDI_MPHY_IOSFSB_RESET_STATUS
, 100))
6523 DRM_ERROR("FDI mPHY reset assert timeout\n");
6525 tmp
= I915_READ(SOUTH_CHICKEN2
);
6526 tmp
&= ~FDI_MPHY_IOSFSB_RESET_CTL
;
6527 I915_WRITE(SOUTH_CHICKEN2
, tmp
);
6529 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2
) &
6530 FDI_MPHY_IOSFSB_RESET_STATUS
) == 0, 100))
6531 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
6534 /* WaMPhyProgramming:hsw */
6535 static void lpt_program_fdi_mphy(struct drm_i915_private
*dev_priv
)
6539 tmp
= intel_sbi_read(dev_priv
, 0x8008, SBI_MPHY
);
6540 tmp
&= ~(0xFF << 24);
6541 tmp
|= (0x12 << 24);
6542 intel_sbi_write(dev_priv
, 0x8008, tmp
, SBI_MPHY
);
6544 tmp
= intel_sbi_read(dev_priv
, 0x2008, SBI_MPHY
);
6546 intel_sbi_write(dev_priv
, 0x2008, tmp
, SBI_MPHY
);
6548 tmp
= intel_sbi_read(dev_priv
, 0x2108, SBI_MPHY
);
6550 intel_sbi_write(dev_priv
, 0x2108, tmp
, SBI_MPHY
);
6552 tmp
= intel_sbi_read(dev_priv
, 0x206C, SBI_MPHY
);
6553 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6554 intel_sbi_write(dev_priv
, 0x206C, tmp
, SBI_MPHY
);
6556 tmp
= intel_sbi_read(dev_priv
, 0x216C, SBI_MPHY
);
6557 tmp
|= (1 << 24) | (1 << 21) | (1 << 18);
6558 intel_sbi_write(dev_priv
, 0x216C, tmp
, SBI_MPHY
);
6560 tmp
= intel_sbi_read(dev_priv
, 0x2080, SBI_MPHY
);
6563 intel_sbi_write(dev_priv
, 0x2080, tmp
, SBI_MPHY
);
6565 tmp
= intel_sbi_read(dev_priv
, 0x2180, SBI_MPHY
);
6568 intel_sbi_write(dev_priv
, 0x2180, tmp
, SBI_MPHY
);
6570 tmp
= intel_sbi_read(dev_priv
, 0x208C, SBI_MPHY
);
6573 intel_sbi_write(dev_priv
, 0x208C, tmp
, SBI_MPHY
);
6575 tmp
= intel_sbi_read(dev_priv
, 0x218C, SBI_MPHY
);
6578 intel_sbi_write(dev_priv
, 0x218C, tmp
, SBI_MPHY
);
6580 tmp
= intel_sbi_read(dev_priv
, 0x2098, SBI_MPHY
);
6581 tmp
&= ~(0xFF << 16);
6582 tmp
|= (0x1C << 16);
6583 intel_sbi_write(dev_priv
, 0x2098, tmp
, SBI_MPHY
);
6585 tmp
= intel_sbi_read(dev_priv
, 0x2198, SBI_MPHY
);
6586 tmp
&= ~(0xFF << 16);
6587 tmp
|= (0x1C << 16);
6588 intel_sbi_write(dev_priv
, 0x2198, tmp
, SBI_MPHY
);
6590 tmp
= intel_sbi_read(dev_priv
, 0x20C4, SBI_MPHY
);
6592 intel_sbi_write(dev_priv
, 0x20C4, tmp
, SBI_MPHY
);
6594 tmp
= intel_sbi_read(dev_priv
, 0x21C4, SBI_MPHY
);
6596 intel_sbi_write(dev_priv
, 0x21C4, tmp
, SBI_MPHY
);
6598 tmp
= intel_sbi_read(dev_priv
, 0x20EC, SBI_MPHY
);
6599 tmp
&= ~(0xF << 28);
6601 intel_sbi_write(dev_priv
, 0x20EC, tmp
, SBI_MPHY
);
6603 tmp
= intel_sbi_read(dev_priv
, 0x21EC, SBI_MPHY
);
6604 tmp
&= ~(0xF << 28);
6606 intel_sbi_write(dev_priv
, 0x21EC, tmp
, SBI_MPHY
);
6609 /* Implements 3 different sequences from BSpec chapter "Display iCLK
6610 * Programming" based on the parameters passed:
6611 * - Sequence to enable CLKOUT_DP
6612 * - Sequence to enable CLKOUT_DP without spread
6613 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
6615 static void lpt_enable_clkout_dp(struct drm_device
*dev
, bool with_spread
,
6618 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6621 if (WARN(with_fdi
&& !with_spread
, "FDI requires downspread\n"))
6623 if (WARN(dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
&&
6624 with_fdi
, "LP PCH doesn't have FDI\n"))
6627 mutex_lock(&dev_priv
->dpio_lock
);
6629 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6630 tmp
&= ~SBI_SSCCTL_DISABLE
;
6631 tmp
|= SBI_SSCCTL_PATHALT
;
6632 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6637 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6638 tmp
&= ~SBI_SSCCTL_PATHALT
;
6639 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6642 lpt_reset_fdi_mphy(dev_priv
);
6643 lpt_program_fdi_mphy(dev_priv
);
6647 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6648 SBI_GEN0
: SBI_DBUFF0
;
6649 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6650 tmp
|= SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6651 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6653 mutex_unlock(&dev_priv
->dpio_lock
);
6656 /* Sequence to disable CLKOUT_DP */
6657 static void lpt_disable_clkout_dp(struct drm_device
*dev
)
6659 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6662 mutex_lock(&dev_priv
->dpio_lock
);
6664 reg
= (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) ?
6665 SBI_GEN0
: SBI_DBUFF0
;
6666 tmp
= intel_sbi_read(dev_priv
, reg
, SBI_ICLK
);
6667 tmp
&= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE
;
6668 intel_sbi_write(dev_priv
, reg
, tmp
, SBI_ICLK
);
6670 tmp
= intel_sbi_read(dev_priv
, SBI_SSCCTL
, SBI_ICLK
);
6671 if (!(tmp
& SBI_SSCCTL_DISABLE
)) {
6672 if (!(tmp
& SBI_SSCCTL_PATHALT
)) {
6673 tmp
|= SBI_SSCCTL_PATHALT
;
6674 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6677 tmp
|= SBI_SSCCTL_DISABLE
;
6678 intel_sbi_write(dev_priv
, SBI_SSCCTL
, tmp
, SBI_ICLK
);
6681 mutex_unlock(&dev_priv
->dpio_lock
);
6684 static void lpt_init_pch_refclk(struct drm_device
*dev
)
6686 struct intel_encoder
*encoder
;
6687 bool has_vga
= false;
6689 for_each_intel_encoder(dev
, encoder
) {
6690 switch (encoder
->type
) {
6691 case INTEL_OUTPUT_ANALOG
:
6698 lpt_enable_clkout_dp(dev
, true, true);
6700 lpt_disable_clkout_dp(dev
);
6704 * Initialize reference clocks when the driver loads
6706 void intel_init_pch_refclk(struct drm_device
*dev
)
6708 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
6709 ironlake_init_pch_refclk(dev
);
6710 else if (HAS_PCH_LPT(dev
))
6711 lpt_init_pch_refclk(dev
);
6714 static int ironlake_get_refclk(struct drm_crtc
*crtc
)
6716 struct drm_device
*dev
= crtc
->dev
;
6717 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6718 struct intel_encoder
*encoder
;
6719 int num_connectors
= 0;
6720 bool is_lvds
= false;
6722 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
6723 switch (encoder
->type
) {
6724 case INTEL_OUTPUT_LVDS
:
6731 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
6732 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
6733 dev_priv
->vbt
.lvds_ssc_freq
);
6734 return dev_priv
->vbt
.lvds_ssc_freq
;
6740 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
)
6742 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
6743 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6744 int pipe
= intel_crtc
->pipe
;
6749 switch (intel_crtc
->config
.pipe_bpp
) {
6751 val
|= PIPECONF_6BPC
;
6754 val
|= PIPECONF_8BPC
;
6757 val
|= PIPECONF_10BPC
;
6760 val
|= PIPECONF_12BPC
;
6763 /* Case prevented by intel_choose_pipe_bpp_dither. */
6767 if (intel_crtc
->config
.dither
)
6768 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
6770 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
6771 val
|= PIPECONF_INTERLACED_ILK
;
6773 val
|= PIPECONF_PROGRESSIVE
;
6775 if (intel_crtc
->config
.limited_color_range
)
6776 val
|= PIPECONF_COLOR_RANGE_SELECT
;
6778 I915_WRITE(PIPECONF(pipe
), val
);
6779 POSTING_READ(PIPECONF(pipe
));
6783 * Set up the pipe CSC unit.
6785 * Currently only full range RGB to limited range RGB conversion
6786 * is supported, but eventually this should handle various
6787 * RGB<->YCbCr scenarios as well.
6789 static void intel_set_pipe_csc(struct drm_crtc
*crtc
)
6791 struct drm_device
*dev
= crtc
->dev
;
6792 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6793 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6794 int pipe
= intel_crtc
->pipe
;
6795 uint16_t coeff
= 0x7800; /* 1.0 */
6798 * TODO: Check what kind of values actually come out of the pipe
6799 * with these coeff/postoff values and adjust to get the best
6800 * accuracy. Perhaps we even need to take the bpc value into
6804 if (intel_crtc
->config
.limited_color_range
)
6805 coeff
= ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
6808 * GY/GU and RY/RU should be the other way around according
6809 * to BSpec, but reality doesn't agree. Just set them up in
6810 * a way that results in the correct picture.
6812 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe
), coeff
<< 16);
6813 I915_WRITE(PIPE_CSC_COEFF_BY(pipe
), 0);
6815 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe
), coeff
);
6816 I915_WRITE(PIPE_CSC_COEFF_BU(pipe
), 0);
6818 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe
), 0);
6819 I915_WRITE(PIPE_CSC_COEFF_BV(pipe
), coeff
<< 16);
6821 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe
), 0);
6822 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe
), 0);
6823 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe
), 0);
6825 if (INTEL_INFO(dev
)->gen
> 6) {
6826 uint16_t postoff
= 0;
6828 if (intel_crtc
->config
.limited_color_range
)
6829 postoff
= (16 * (1 << 12) / 255) & 0x1fff;
6831 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe
), postoff
);
6832 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe
), postoff
);
6833 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe
), postoff
);
6835 I915_WRITE(PIPE_CSC_MODE(pipe
), 0);
6837 uint32_t mode
= CSC_MODE_YUV_TO_RGB
;
6839 if (intel_crtc
->config
.limited_color_range
)
6840 mode
|= CSC_BLACK_SCREEN_OFFSET
;
6842 I915_WRITE(PIPE_CSC_MODE(pipe
), mode
);
6846 static void haswell_set_pipeconf(struct drm_crtc
*crtc
)
6848 struct drm_device
*dev
= crtc
->dev
;
6849 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6850 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6851 enum pipe pipe
= intel_crtc
->pipe
;
6852 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
6857 if (IS_HASWELL(dev
) && intel_crtc
->config
.dither
)
6858 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
6860 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_INTERLACE
)
6861 val
|= PIPECONF_INTERLACED_ILK
;
6863 val
|= PIPECONF_PROGRESSIVE
;
6865 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
6866 POSTING_READ(PIPECONF(cpu_transcoder
));
6868 I915_WRITE(GAMMA_MODE(intel_crtc
->pipe
), GAMMA_MODE_MODE_8BIT
);
6869 POSTING_READ(GAMMA_MODE(intel_crtc
->pipe
));
6871 if (IS_BROADWELL(dev
)) {
6874 switch (intel_crtc
->config
.pipe_bpp
) {
6876 val
|= PIPEMISC_DITHER_6_BPC
;
6879 val
|= PIPEMISC_DITHER_8_BPC
;
6882 val
|= PIPEMISC_DITHER_10_BPC
;
6885 val
|= PIPEMISC_DITHER_12_BPC
;
6888 /* Case prevented by pipe_config_set_bpp. */
6892 if (intel_crtc
->config
.dither
)
6893 val
|= PIPEMISC_DITHER_ENABLE
| PIPEMISC_DITHER_TYPE_SP
;
6895 I915_WRITE(PIPEMISC(pipe
), val
);
6899 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
6900 intel_clock_t
*clock
,
6901 bool *has_reduced_clock
,
6902 intel_clock_t
*reduced_clock
)
6904 struct drm_device
*dev
= crtc
->dev
;
6905 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6906 struct intel_encoder
*intel_encoder
;
6908 const intel_limit_t
*limit
;
6909 bool ret
, is_lvds
= false;
6911 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
6912 switch (intel_encoder
->type
) {
6913 case INTEL_OUTPUT_LVDS
:
6919 refclk
= ironlake_get_refclk(crtc
);
6922 * Returns a set of divisors for the desired target clock with the given
6923 * refclk, or FALSE. The returned values represent the clock equation:
6924 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
6926 limit
= intel_limit(crtc
, refclk
);
6927 ret
= dev_priv
->display
.find_dpll(limit
, crtc
,
6928 to_intel_crtc(crtc
)->config
.port_clock
,
6929 refclk
, NULL
, clock
);
6933 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
6935 * Ensure we match the reduced clock's P to the target clock.
6936 * If the clocks don't match, we can't switch the display clock
6937 * by using the FP0/FP1. In such case we will disable the LVDS
6938 * downclock feature.
6940 *has_reduced_clock
=
6941 dev_priv
->display
.find_dpll(limit
, crtc
,
6942 dev_priv
->lvds_downclock
,
6950 int ironlake_get_lanes_required(int target_clock
, int link_bw
, int bpp
)
6953 * Account for spread spectrum to avoid
6954 * oversubscribing the link. Max center spread
6955 * is 2.5%; use 5% for safety's sake.
6957 u32 bps
= target_clock
* bpp
* 21 / 20;
6958 return DIV_ROUND_UP(bps
, link_bw
* 8);
6961 static bool ironlake_needs_fb_cb_tune(struct dpll
*dpll
, int factor
)
6963 return i9xx_dpll_compute_m(dpll
) < factor
* dpll
->n
;
6966 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
6968 intel_clock_t
*reduced_clock
, u32
*fp2
)
6970 struct drm_crtc
*crtc
= &intel_crtc
->base
;
6971 struct drm_device
*dev
= crtc
->dev
;
6972 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6973 struct intel_encoder
*intel_encoder
;
6975 int factor
, num_connectors
= 0;
6976 bool is_lvds
= false, is_sdvo
= false;
6978 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
6979 switch (intel_encoder
->type
) {
6980 case INTEL_OUTPUT_LVDS
:
6983 case INTEL_OUTPUT_SDVO
:
6984 case INTEL_OUTPUT_HDMI
:
6992 /* Enable autotuning of the PLL clock (if permissible) */
6995 if ((intel_panel_use_ssc(dev_priv
) &&
6996 dev_priv
->vbt
.lvds_ssc_freq
== 100000) ||
6997 (HAS_PCH_IBX(dev
) && intel_is_dual_link_lvds(dev
)))
6999 } else if (intel_crtc
->config
.sdvo_tv_clock
)
7002 if (ironlake_needs_fb_cb_tune(&intel_crtc
->config
.dpll
, factor
))
7005 if (fp2
&& (reduced_clock
->m
< factor
* reduced_clock
->n
))
7011 dpll
|= DPLLB_MODE_LVDS
;
7013 dpll
|= DPLLB_MODE_DAC_SERIAL
;
7015 dpll
|= (intel_crtc
->config
.pixel_multiplier
- 1)
7016 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
7019 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7020 if (intel_crtc
->config
.has_dp_encoder
)
7021 dpll
|= DPLL_SDVO_HIGH_SPEED
;
7023 /* compute bitmask from p1 value */
7024 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
7026 dpll
|= (1 << (intel_crtc
->config
.dpll
.p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
7028 switch (intel_crtc
->config
.dpll
.p2
) {
7030 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
7033 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
7036 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
7039 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
7043 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
7044 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
7046 dpll
|= PLL_REF_INPUT_DREFCLK
;
7048 return dpll
| DPLL_VCO_ENABLE
;
7051 static int ironlake_crtc_mode_set(struct drm_crtc
*crtc
,
7053 struct drm_framebuffer
*fb
)
7055 struct drm_device
*dev
= crtc
->dev
;
7056 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7057 int num_connectors
= 0;
7058 intel_clock_t clock
, reduced_clock
;
7059 u32 dpll
= 0, fp
= 0, fp2
= 0;
7060 bool ok
, has_reduced_clock
= false;
7061 bool is_lvds
= false;
7062 struct intel_encoder
*encoder
;
7063 struct intel_shared_dpll
*pll
;
7065 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
7066 switch (encoder
->type
) {
7067 case INTEL_OUTPUT_LVDS
:
7075 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
7076 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
7078 ok
= ironlake_compute_clocks(crtc
, &clock
,
7079 &has_reduced_clock
, &reduced_clock
);
7080 if (!ok
&& !intel_crtc
->config
.clock_set
) {
7081 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7084 /* Compat-code for transition, will disappear. */
7085 if (!intel_crtc
->config
.clock_set
) {
7086 intel_crtc
->config
.dpll
.n
= clock
.n
;
7087 intel_crtc
->config
.dpll
.m1
= clock
.m1
;
7088 intel_crtc
->config
.dpll
.m2
= clock
.m2
;
7089 intel_crtc
->config
.dpll
.p1
= clock
.p1
;
7090 intel_crtc
->config
.dpll
.p2
= clock
.p2
;
7093 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
7094 if (intel_crtc
->config
.has_pch_encoder
) {
7095 fp
= i9xx_dpll_compute_fp(&intel_crtc
->config
.dpll
);
7096 if (has_reduced_clock
)
7097 fp2
= i9xx_dpll_compute_fp(&reduced_clock
);
7099 dpll
= ironlake_compute_dpll(intel_crtc
,
7100 &fp
, &reduced_clock
,
7101 has_reduced_clock
? &fp2
: NULL
);
7103 intel_crtc
->config
.dpll_hw_state
.dpll
= dpll
;
7104 intel_crtc
->config
.dpll_hw_state
.fp0
= fp
;
7105 if (has_reduced_clock
)
7106 intel_crtc
->config
.dpll_hw_state
.fp1
= fp2
;
7108 intel_crtc
->config
.dpll_hw_state
.fp1
= fp
;
7110 pll
= intel_get_shared_dpll(intel_crtc
);
7112 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
7113 pipe_name(intel_crtc
->pipe
));
7117 intel_put_shared_dpll(intel_crtc
);
7119 if (is_lvds
&& has_reduced_clock
&& i915
.powersave
)
7120 intel_crtc
->lowfreq_avail
= true;
7122 intel_crtc
->lowfreq_avail
= false;
7127 static void intel_pch_transcoder_get_m_n(struct intel_crtc
*crtc
,
7128 struct intel_link_m_n
*m_n
)
7130 struct drm_device
*dev
= crtc
->base
.dev
;
7131 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7132 enum pipe pipe
= crtc
->pipe
;
7134 m_n
->link_m
= I915_READ(PCH_TRANS_LINK_M1(pipe
));
7135 m_n
->link_n
= I915_READ(PCH_TRANS_LINK_N1(pipe
));
7136 m_n
->gmch_m
= I915_READ(PCH_TRANS_DATA_M1(pipe
))
7138 m_n
->gmch_n
= I915_READ(PCH_TRANS_DATA_N1(pipe
));
7139 m_n
->tu
= ((I915_READ(PCH_TRANS_DATA_M1(pipe
))
7140 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7143 static void intel_cpu_transcoder_get_m_n(struct intel_crtc
*crtc
,
7144 enum transcoder transcoder
,
7145 struct intel_link_m_n
*m_n
,
7146 struct intel_link_m_n
*m2_n2
)
7148 struct drm_device
*dev
= crtc
->base
.dev
;
7149 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7150 enum pipe pipe
= crtc
->pipe
;
7152 if (INTEL_INFO(dev
)->gen
>= 5) {
7153 m_n
->link_m
= I915_READ(PIPE_LINK_M1(transcoder
));
7154 m_n
->link_n
= I915_READ(PIPE_LINK_N1(transcoder
));
7155 m_n
->gmch_m
= I915_READ(PIPE_DATA_M1(transcoder
))
7157 m_n
->gmch_n
= I915_READ(PIPE_DATA_N1(transcoder
));
7158 m_n
->tu
= ((I915_READ(PIPE_DATA_M1(transcoder
))
7159 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7160 /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
7161 * gen < 8) and if DRRS is supported (to make sure the
7162 * registers are not unnecessarily read).
7164 if (m2_n2
&& INTEL_INFO(dev
)->gen
< 8 &&
7165 crtc
->config
.has_drrs
) {
7166 m2_n2
->link_m
= I915_READ(PIPE_LINK_M2(transcoder
));
7167 m2_n2
->link_n
= I915_READ(PIPE_LINK_N2(transcoder
));
7168 m2_n2
->gmch_m
= I915_READ(PIPE_DATA_M2(transcoder
))
7170 m2_n2
->gmch_n
= I915_READ(PIPE_DATA_N2(transcoder
));
7171 m2_n2
->tu
= ((I915_READ(PIPE_DATA_M2(transcoder
))
7172 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7175 m_n
->link_m
= I915_READ(PIPE_LINK_M_G4X(pipe
));
7176 m_n
->link_n
= I915_READ(PIPE_LINK_N_G4X(pipe
));
7177 m_n
->gmch_m
= I915_READ(PIPE_DATA_M_G4X(pipe
))
7179 m_n
->gmch_n
= I915_READ(PIPE_DATA_N_G4X(pipe
));
7180 m_n
->tu
= ((I915_READ(PIPE_DATA_M_G4X(pipe
))
7181 & TU_SIZE_MASK
) >> TU_SIZE_SHIFT
) + 1;
7185 void intel_dp_get_m_n(struct intel_crtc
*crtc
,
7186 struct intel_crtc_config
*pipe_config
)
7188 if (crtc
->config
.has_pch_encoder
)
7189 intel_pch_transcoder_get_m_n(crtc
, &pipe_config
->dp_m_n
);
7191 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7192 &pipe_config
->dp_m_n
,
7193 &pipe_config
->dp_m2_n2
);
7196 static void ironlake_get_fdi_m_n_config(struct intel_crtc
*crtc
,
7197 struct intel_crtc_config
*pipe_config
)
7199 intel_cpu_transcoder_get_m_n(crtc
, pipe_config
->cpu_transcoder
,
7200 &pipe_config
->fdi_m_n
, NULL
);
7203 static void ironlake_get_pfit_config(struct intel_crtc
*crtc
,
7204 struct intel_crtc_config
*pipe_config
)
7206 struct drm_device
*dev
= crtc
->base
.dev
;
7207 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7210 tmp
= I915_READ(PF_CTL(crtc
->pipe
));
7212 if (tmp
& PF_ENABLE
) {
7213 pipe_config
->pch_pfit
.enabled
= true;
7214 pipe_config
->pch_pfit
.pos
= I915_READ(PF_WIN_POS(crtc
->pipe
));
7215 pipe_config
->pch_pfit
.size
= I915_READ(PF_WIN_SZ(crtc
->pipe
));
7217 /* We currently do not free assignements of panel fitters on
7218 * ivb/hsw (since we don't use the higher upscaling modes which
7219 * differentiates them) so just WARN about this case for now. */
7221 WARN_ON((tmp
& PF_PIPE_SEL_MASK_IVB
) !=
7222 PF_PIPE_SEL_IVB(crtc
->pipe
));
7227 static void ironlake_get_plane_config(struct intel_crtc
*crtc
,
7228 struct intel_plane_config
*plane_config
)
7230 struct drm_device
*dev
= crtc
->base
.dev
;
7231 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7232 u32 val
, base
, offset
;
7233 int pipe
= crtc
->pipe
, plane
= crtc
->plane
;
7234 int fourcc
, pixel_format
;
7237 crtc
->base
.primary
->fb
= kzalloc(sizeof(struct intel_framebuffer
), GFP_KERNEL
);
7238 if (!crtc
->base
.primary
->fb
) {
7239 DRM_DEBUG_KMS("failed to alloc fb\n");
7243 val
= I915_READ(DSPCNTR(plane
));
7245 if (INTEL_INFO(dev
)->gen
>= 4)
7246 if (val
& DISPPLANE_TILED
)
7247 plane_config
->tiled
= true;
7249 pixel_format
= val
& DISPPLANE_PIXFORMAT_MASK
;
7250 fourcc
= intel_format_to_fourcc(pixel_format
);
7251 crtc
->base
.primary
->fb
->pixel_format
= fourcc
;
7252 crtc
->base
.primary
->fb
->bits_per_pixel
=
7253 drm_format_plane_cpp(fourcc
, 0) * 8;
7255 base
= I915_READ(DSPSURF(plane
)) & 0xfffff000;
7256 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
7257 offset
= I915_READ(DSPOFFSET(plane
));
7259 if (plane_config
->tiled
)
7260 offset
= I915_READ(DSPTILEOFF(plane
));
7262 offset
= I915_READ(DSPLINOFF(plane
));
7264 plane_config
->base
= base
;
7266 val
= I915_READ(PIPESRC(pipe
));
7267 crtc
->base
.primary
->fb
->width
= ((val
>> 16) & 0xfff) + 1;
7268 crtc
->base
.primary
->fb
->height
= ((val
>> 0) & 0xfff) + 1;
7270 val
= I915_READ(DSPSTRIDE(pipe
));
7271 crtc
->base
.primary
->fb
->pitches
[0] = val
& 0xffffffc0;
7273 aligned_height
= intel_align_height(dev
, crtc
->base
.primary
->fb
->height
,
7274 plane_config
->tiled
);
7276 plane_config
->size
= PAGE_ALIGN(crtc
->base
.primary
->fb
->pitches
[0] *
7279 DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7280 pipe
, plane
, crtc
->base
.primary
->fb
->width
,
7281 crtc
->base
.primary
->fb
->height
,
7282 crtc
->base
.primary
->fb
->bits_per_pixel
, base
,
7283 crtc
->base
.primary
->fb
->pitches
[0],
7284 plane_config
->size
);
7287 static bool ironlake_get_pipe_config(struct intel_crtc
*crtc
,
7288 struct intel_crtc_config
*pipe_config
)
7290 struct drm_device
*dev
= crtc
->base
.dev
;
7291 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7294 if (!intel_display_power_enabled(dev_priv
,
7295 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7298 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7299 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7301 tmp
= I915_READ(PIPECONF(crtc
->pipe
));
7302 if (!(tmp
& PIPECONF_ENABLE
))
7305 switch (tmp
& PIPECONF_BPC_MASK
) {
7307 pipe_config
->pipe_bpp
= 18;
7310 pipe_config
->pipe_bpp
= 24;
7312 case PIPECONF_10BPC
:
7313 pipe_config
->pipe_bpp
= 30;
7315 case PIPECONF_12BPC
:
7316 pipe_config
->pipe_bpp
= 36;
7322 if (tmp
& PIPECONF_COLOR_RANGE_SELECT
)
7323 pipe_config
->limited_color_range
= true;
7325 if (I915_READ(PCH_TRANSCONF(crtc
->pipe
)) & TRANS_ENABLE
) {
7326 struct intel_shared_dpll
*pll
;
7328 pipe_config
->has_pch_encoder
= true;
7330 tmp
= I915_READ(FDI_RX_CTL(crtc
->pipe
));
7331 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7332 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7334 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7336 if (HAS_PCH_IBX(dev_priv
->dev
)) {
7337 pipe_config
->shared_dpll
=
7338 (enum intel_dpll_id
) crtc
->pipe
;
7340 tmp
= I915_READ(PCH_DPLL_SEL
);
7341 if (tmp
& TRANS_DPLLB_SEL(crtc
->pipe
))
7342 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_B
;
7344 pipe_config
->shared_dpll
= DPLL_ID_PCH_PLL_A
;
7347 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
7349 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
7350 &pipe_config
->dpll_hw_state
));
7352 tmp
= pipe_config
->dpll_hw_state
.dpll
;
7353 pipe_config
->pixel_multiplier
=
7354 ((tmp
& PLL_REF_SDVO_HDMI_MULTIPLIER_MASK
)
7355 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
) + 1;
7357 ironlake_pch_clock_get(crtc
, pipe_config
);
7359 pipe_config
->pixel_multiplier
= 1;
7362 intel_get_pipe_timings(crtc
, pipe_config
);
7364 ironlake_get_pfit_config(crtc
, pipe_config
);
7369 static void assert_can_disable_lcpll(struct drm_i915_private
*dev_priv
)
7371 struct drm_device
*dev
= dev_priv
->dev
;
7372 struct intel_crtc
*crtc
;
7374 for_each_intel_crtc(dev
, crtc
)
7375 WARN(crtc
->active
, "CRTC for pipe %c enabled\n",
7376 pipe_name(crtc
->pipe
));
7378 WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on\n");
7379 WARN(I915_READ(SPLL_CTL
) & SPLL_PLL_ENABLE
, "SPLL enabled\n");
7380 WARN(I915_READ(WRPLL_CTL1
) & WRPLL_PLL_ENABLE
, "WRPLL1 enabled\n");
7381 WARN(I915_READ(WRPLL_CTL2
) & WRPLL_PLL_ENABLE
, "WRPLL2 enabled\n");
7382 WARN(I915_READ(PCH_PP_STATUS
) & PP_ON
, "Panel power on\n");
7383 WARN(I915_READ(BLC_PWM_CPU_CTL2
) & BLM_PWM_ENABLE
,
7384 "CPU PWM1 enabled\n");
7385 if (IS_HASWELL(dev
))
7386 WARN(I915_READ(HSW_BLC_PWM2_CTL
) & BLM_PWM_ENABLE
,
7387 "CPU PWM2 enabled\n");
7388 WARN(I915_READ(BLC_PWM_PCH_CTL1
) & BLM_PCH_PWM_ENABLE
,
7389 "PCH PWM1 enabled\n");
7390 WARN(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
7391 "Utility pin enabled\n");
7392 WARN(I915_READ(PCH_GTC_CTL
) & PCH_GTC_ENABLE
, "PCH GTC enabled\n");
7395 * In theory we can still leave IRQs enabled, as long as only the HPD
7396 * interrupts remain enabled. We used to check for that, but since it's
7397 * gen-specific and since we only disable LCPLL after we fully disable
7398 * the interrupts, the check below should be enough.
7400 WARN(intel_irqs_enabled(dev_priv
), "IRQs enabled\n");
7403 static uint32_t hsw_read_dcomp(struct drm_i915_private
*dev_priv
)
7405 struct drm_device
*dev
= dev_priv
->dev
;
7407 if (IS_HASWELL(dev
))
7408 return I915_READ(D_COMP_HSW
);
7410 return I915_READ(D_COMP_BDW
);
7413 static void hsw_write_dcomp(struct drm_i915_private
*dev_priv
, uint32_t val
)
7415 struct drm_device
*dev
= dev_priv
->dev
;
7417 if (IS_HASWELL(dev
)) {
7418 mutex_lock(&dev_priv
->rps
.hw_lock
);
7419 if (sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_D_COMP
,
7421 DRM_ERROR("Failed to write to D_COMP\n");
7422 mutex_unlock(&dev_priv
->rps
.hw_lock
);
7424 I915_WRITE(D_COMP_BDW
, val
);
7425 POSTING_READ(D_COMP_BDW
);
7430 * This function implements pieces of two sequences from BSpec:
7431 * - Sequence for display software to disable LCPLL
7432 * - Sequence for display software to allow package C8+
7433 * The steps implemented here are just the steps that actually touch the LCPLL
7434 * register. Callers should take care of disabling all the display engine
7435 * functions, doing the mode unset, fixing interrupts, etc.
7437 static void hsw_disable_lcpll(struct drm_i915_private
*dev_priv
,
7438 bool switch_to_fclk
, bool allow_power_down
)
7442 assert_can_disable_lcpll(dev_priv
);
7444 val
= I915_READ(LCPLL_CTL
);
7446 if (switch_to_fclk
) {
7447 val
|= LCPLL_CD_SOURCE_FCLK
;
7448 I915_WRITE(LCPLL_CTL
, val
);
7450 if (wait_for_atomic_us(I915_READ(LCPLL_CTL
) &
7451 LCPLL_CD_SOURCE_FCLK_DONE
, 1))
7452 DRM_ERROR("Switching to FCLK failed\n");
7454 val
= I915_READ(LCPLL_CTL
);
7457 val
|= LCPLL_PLL_DISABLE
;
7458 I915_WRITE(LCPLL_CTL
, val
);
7459 POSTING_READ(LCPLL_CTL
);
7461 if (wait_for((I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
) == 0, 1))
7462 DRM_ERROR("LCPLL still locked\n");
7464 val
= hsw_read_dcomp(dev_priv
);
7465 val
|= D_COMP_COMP_DISABLE
;
7466 hsw_write_dcomp(dev_priv
, val
);
7469 if (wait_for((hsw_read_dcomp(dev_priv
) & D_COMP_RCOMP_IN_PROGRESS
) == 0,
7471 DRM_ERROR("D_COMP RCOMP still in progress\n");
7473 if (allow_power_down
) {
7474 val
= I915_READ(LCPLL_CTL
);
7475 val
|= LCPLL_POWER_DOWN_ALLOW
;
7476 I915_WRITE(LCPLL_CTL
, val
);
7477 POSTING_READ(LCPLL_CTL
);
7482 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
7485 static void hsw_restore_lcpll(struct drm_i915_private
*dev_priv
)
7488 unsigned long irqflags
;
7490 val
= I915_READ(LCPLL_CTL
);
7492 if ((val
& (LCPLL_PLL_LOCK
| LCPLL_PLL_DISABLE
| LCPLL_CD_SOURCE_FCLK
|
7493 LCPLL_POWER_DOWN_ALLOW
)) == LCPLL_PLL_LOCK
)
7497 * Make sure we're not on PC8 state before disabling PC8, otherwise
7498 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
7500 * The other problem is that hsw_restore_lcpll() is called as part of
7501 * the runtime PM resume sequence, so we can't just call
7502 * gen6_gt_force_wake_get() because that function calls
7503 * intel_runtime_pm_get(), and we can't change the runtime PM refcount
7504 * while we are on the resume sequence. So to solve this problem we have
7505 * to call special forcewake code that doesn't touch runtime PM and
7506 * doesn't enable the forcewake delayed work.
7508 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
7509 if (dev_priv
->uncore
.forcewake_count
++ == 0)
7510 dev_priv
->uncore
.funcs
.force_wake_get(dev_priv
, FORCEWAKE_ALL
);
7511 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
7513 if (val
& LCPLL_POWER_DOWN_ALLOW
) {
7514 val
&= ~LCPLL_POWER_DOWN_ALLOW
;
7515 I915_WRITE(LCPLL_CTL
, val
);
7516 POSTING_READ(LCPLL_CTL
);
7519 val
= hsw_read_dcomp(dev_priv
);
7520 val
|= D_COMP_COMP_FORCE
;
7521 val
&= ~D_COMP_COMP_DISABLE
;
7522 hsw_write_dcomp(dev_priv
, val
);
7524 val
= I915_READ(LCPLL_CTL
);
7525 val
&= ~LCPLL_PLL_DISABLE
;
7526 I915_WRITE(LCPLL_CTL
, val
);
7528 if (wait_for(I915_READ(LCPLL_CTL
) & LCPLL_PLL_LOCK
, 5))
7529 DRM_ERROR("LCPLL not locked yet\n");
7531 if (val
& LCPLL_CD_SOURCE_FCLK
) {
7532 val
= I915_READ(LCPLL_CTL
);
7533 val
&= ~LCPLL_CD_SOURCE_FCLK
;
7534 I915_WRITE(LCPLL_CTL
, val
);
7536 if (wait_for_atomic_us((I915_READ(LCPLL_CTL
) &
7537 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
7538 DRM_ERROR("Switching back to LCPLL failed\n");
7541 /* See the big comment above. */
7542 spin_lock_irqsave(&dev_priv
->uncore
.lock
, irqflags
);
7543 if (--dev_priv
->uncore
.forcewake_count
== 0)
7544 dev_priv
->uncore
.funcs
.force_wake_put(dev_priv
, FORCEWAKE_ALL
);
7545 spin_unlock_irqrestore(&dev_priv
->uncore
.lock
, irqflags
);
7549 * Package states C8 and deeper are really deep PC states that can only be
7550 * reached when all the devices on the system allow it, so even if the graphics
7551 * device allows PC8+, it doesn't mean the system will actually get to these
7552 * states. Our driver only allows PC8+ when going into runtime PM.
7554 * The requirements for PC8+ are that all the outputs are disabled, the power
7555 * well is disabled and most interrupts are disabled, and these are also
7556 * requirements for runtime PM. When these conditions are met, we manually do
7557 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
7558 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
7561 * When we really reach PC8 or deeper states (not just when we allow it) we lose
7562 * the state of some registers, so when we come back from PC8+ we need to
7563 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
7564 * need to take care of the registers kept by RC6. Notice that this happens even
7565 * if we don't put the device in PCI D3 state (which is what currently happens
7566 * because of the runtime PM support).
7568 * For more, read "Display Sequences for Package C8" on the hardware
7571 void hsw_enable_pc8(struct drm_i915_private
*dev_priv
)
7573 struct drm_device
*dev
= dev_priv
->dev
;
7576 DRM_DEBUG_KMS("Enabling package C8+\n");
7578 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7579 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7580 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
7581 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7584 lpt_disable_clkout_dp(dev
);
7585 hsw_disable_lcpll(dev_priv
, true, true);
7588 void hsw_disable_pc8(struct drm_i915_private
*dev_priv
)
7590 struct drm_device
*dev
= dev_priv
->dev
;
7593 DRM_DEBUG_KMS("Disabling package C8+\n");
7595 hsw_restore_lcpll(dev_priv
);
7596 lpt_init_pch_refclk(dev
);
7598 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
7599 val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
7600 val
|= PCH_LP_PARTITION_LEVEL_DISABLE
;
7601 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
7604 intel_prepare_ddi(dev
);
7607 static void snb_modeset_global_resources(struct drm_device
*dev
)
7609 modeset_update_crtc_power_domains(dev
);
7612 static void haswell_modeset_global_resources(struct drm_device
*dev
)
7614 modeset_update_crtc_power_domains(dev
);
7617 static int haswell_crtc_mode_set(struct drm_crtc
*crtc
,
7619 struct drm_framebuffer
*fb
)
7621 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7623 if (!intel_ddi_pll_select(intel_crtc
))
7626 intel_crtc
->lowfreq_avail
= false;
7631 static void haswell_get_ddi_pll(struct drm_i915_private
*dev_priv
,
7633 struct intel_crtc_config
*pipe_config
)
7635 pipe_config
->ddi_pll_sel
= I915_READ(PORT_CLK_SEL(port
));
7637 switch (pipe_config
->ddi_pll_sel
) {
7638 case PORT_CLK_SEL_WRPLL1
:
7639 pipe_config
->shared_dpll
= DPLL_ID_WRPLL1
;
7641 case PORT_CLK_SEL_WRPLL2
:
7642 pipe_config
->shared_dpll
= DPLL_ID_WRPLL2
;
7647 static void haswell_get_ddi_port_state(struct intel_crtc
*crtc
,
7648 struct intel_crtc_config
*pipe_config
)
7650 struct drm_device
*dev
= crtc
->base
.dev
;
7651 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7652 struct intel_shared_dpll
*pll
;
7656 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(pipe_config
->cpu_transcoder
));
7658 port
= (tmp
& TRANS_DDI_PORT_MASK
) >> TRANS_DDI_PORT_SHIFT
;
7660 haswell_get_ddi_pll(dev_priv
, port
, pipe_config
);
7662 if (pipe_config
->shared_dpll
>= 0) {
7663 pll
= &dev_priv
->shared_dplls
[pipe_config
->shared_dpll
];
7665 WARN_ON(!pll
->get_hw_state(dev_priv
, pll
,
7666 &pipe_config
->dpll_hw_state
));
7670 * Haswell has only FDI/PCH transcoder A. It is which is connected to
7671 * DDI E. So just check whether this pipe is wired to DDI E and whether
7672 * the PCH transcoder is on.
7674 if ((port
== PORT_E
) && I915_READ(LPT_TRANSCONF
) & TRANS_ENABLE
) {
7675 pipe_config
->has_pch_encoder
= true;
7677 tmp
= I915_READ(FDI_RX_CTL(PIPE_A
));
7678 pipe_config
->fdi_lanes
= ((FDI_DP_PORT_WIDTH_MASK
& tmp
) >>
7679 FDI_DP_PORT_WIDTH_SHIFT
) + 1;
7681 ironlake_get_fdi_m_n_config(crtc
, pipe_config
);
7685 static bool haswell_get_pipe_config(struct intel_crtc
*crtc
,
7686 struct intel_crtc_config
*pipe_config
)
7688 struct drm_device
*dev
= crtc
->base
.dev
;
7689 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7690 enum intel_display_power_domain pfit_domain
;
7693 if (!intel_display_power_enabled(dev_priv
,
7694 POWER_DOMAIN_PIPE(crtc
->pipe
)))
7697 pipe_config
->cpu_transcoder
= (enum transcoder
) crtc
->pipe
;
7698 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
7700 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
7701 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
7702 enum pipe trans_edp_pipe
;
7703 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
7705 WARN(1, "unknown pipe linked to edp transcoder\n");
7706 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
7707 case TRANS_DDI_EDP_INPUT_A_ON
:
7708 trans_edp_pipe
= PIPE_A
;
7710 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
7711 trans_edp_pipe
= PIPE_B
;
7713 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
7714 trans_edp_pipe
= PIPE_C
;
7718 if (trans_edp_pipe
== crtc
->pipe
)
7719 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
7722 if (!intel_display_power_enabled(dev_priv
,
7723 POWER_DOMAIN_TRANSCODER(pipe_config
->cpu_transcoder
)))
7726 tmp
= I915_READ(PIPECONF(pipe_config
->cpu_transcoder
));
7727 if (!(tmp
& PIPECONF_ENABLE
))
7730 haswell_get_ddi_port_state(crtc
, pipe_config
);
7732 intel_get_pipe_timings(crtc
, pipe_config
);
7734 pfit_domain
= POWER_DOMAIN_PIPE_PANEL_FITTER(crtc
->pipe
);
7735 if (intel_display_power_enabled(dev_priv
, pfit_domain
))
7736 ironlake_get_pfit_config(crtc
, pipe_config
);
7738 if (IS_HASWELL(dev
))
7739 pipe_config
->ips_enabled
= hsw_crtc_supports_ips(crtc
) &&
7740 (I915_READ(IPS_CTL
) & IPS_ENABLE
);
7742 pipe_config
->pixel_multiplier
= 1;
7750 } hdmi_audio_clock
[] = {
7751 { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175
},
7752 { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200
}, /* default per bspec */
7753 { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000
},
7754 { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027
},
7755 { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000
},
7756 { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054
},
7757 { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176
},
7758 { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250
},
7759 { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352
},
7760 { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500
},
7763 /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
7764 static u32
audio_config_hdmi_pixel_clock(struct drm_display_mode
*mode
)
7768 for (i
= 0; i
< ARRAY_SIZE(hdmi_audio_clock
); i
++) {
7769 if (mode
->clock
== hdmi_audio_clock
[i
].clock
)
7773 if (i
== ARRAY_SIZE(hdmi_audio_clock
)) {
7774 DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode
->clock
);
7778 DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
7779 hdmi_audio_clock
[i
].clock
,
7780 hdmi_audio_clock
[i
].config
);
7782 return hdmi_audio_clock
[i
].config
;
7785 static bool intel_eld_uptodate(struct drm_connector
*connector
,
7786 int reg_eldv
, uint32_t bits_eldv
,
7787 int reg_elda
, uint32_t bits_elda
,
7790 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7791 uint8_t *eld
= connector
->eld
;
7794 i
= I915_READ(reg_eldv
);
7803 i
= I915_READ(reg_elda
);
7805 I915_WRITE(reg_elda
, i
);
7807 for (i
= 0; i
< eld
[2]; i
++)
7808 if (I915_READ(reg_edid
) != *((uint32_t *)eld
+ i
))
7814 static void g4x_write_eld(struct drm_connector
*connector
,
7815 struct drm_crtc
*crtc
,
7816 struct drm_display_mode
*mode
)
7818 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7819 uint8_t *eld
= connector
->eld
;
7824 i
= I915_READ(G4X_AUD_VID_DID
);
7826 if (i
== INTEL_AUDIO_DEVBLC
|| i
== INTEL_AUDIO_DEVCL
)
7827 eldv
= G4X_ELDV_DEVCL_DEVBLC
;
7829 eldv
= G4X_ELDV_DEVCTG
;
7831 if (intel_eld_uptodate(connector
,
7832 G4X_AUD_CNTL_ST
, eldv
,
7833 G4X_AUD_CNTL_ST
, G4X_ELD_ADDR
,
7834 G4X_HDMIW_HDMIEDID
))
7837 i
= I915_READ(G4X_AUD_CNTL_ST
);
7838 i
&= ~(eldv
| G4X_ELD_ADDR
);
7839 len
= (i
>> 9) & 0x1f; /* ELD buffer size */
7840 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
7845 len
= min_t(uint8_t, eld
[2], len
);
7846 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7847 for (i
= 0; i
< len
; i
++)
7848 I915_WRITE(G4X_HDMIW_HDMIEDID
, *((uint32_t *)eld
+ i
));
7850 i
= I915_READ(G4X_AUD_CNTL_ST
);
7852 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
7855 static void haswell_write_eld(struct drm_connector
*connector
,
7856 struct drm_crtc
*crtc
,
7857 struct drm_display_mode
*mode
)
7859 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7860 uint8_t *eld
= connector
->eld
;
7864 int pipe
= to_intel_crtc(crtc
)->pipe
;
7867 int hdmiw_hdmiedid
= HSW_AUD_EDID_DATA(pipe
);
7868 int aud_cntl_st
= HSW_AUD_DIP_ELD_CTRL(pipe
);
7869 int aud_config
= HSW_AUD_CFG(pipe
);
7870 int aud_cntrl_st2
= HSW_AUD_PIN_ELD_CP_VLD
;
7872 /* Audio output enable */
7873 DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
7874 tmp
= I915_READ(aud_cntrl_st2
);
7875 tmp
|= (AUDIO_OUTPUT_ENABLE_A
<< (pipe
* 4));
7876 I915_WRITE(aud_cntrl_st2
, tmp
);
7877 POSTING_READ(aud_cntrl_st2
);
7879 assert_pipe_disabled(dev_priv
, to_intel_crtc(crtc
)->pipe
);
7881 /* Set ELD valid state */
7882 tmp
= I915_READ(aud_cntrl_st2
);
7883 DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp
);
7884 tmp
|= (AUDIO_ELD_VALID_A
<< (pipe
* 4));
7885 I915_WRITE(aud_cntrl_st2
, tmp
);
7886 tmp
= I915_READ(aud_cntrl_st2
);
7887 DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp
);
7889 /* Enable HDMI mode */
7890 tmp
= I915_READ(aud_config
);
7891 DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp
);
7892 /* clear N_programing_enable and N_value_index */
7893 tmp
&= ~(AUD_CONFIG_N_VALUE_INDEX
| AUD_CONFIG_N_PROG_ENABLE
);
7894 I915_WRITE(aud_config
, tmp
);
7896 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
7898 eldv
= AUDIO_ELD_VALID_A
<< (pipe
* 4);
7900 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
7901 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
7902 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
7903 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
7905 I915_WRITE(aud_config
, audio_config_hdmi_pixel_clock(mode
));
7908 if (intel_eld_uptodate(connector
,
7909 aud_cntrl_st2
, eldv
,
7910 aud_cntl_st
, IBX_ELD_ADDRESS
,
7914 i
= I915_READ(aud_cntrl_st2
);
7916 I915_WRITE(aud_cntrl_st2
, i
);
7921 i
= I915_READ(aud_cntl_st
);
7922 i
&= ~IBX_ELD_ADDRESS
;
7923 I915_WRITE(aud_cntl_st
, i
);
7924 i
= (i
>> 29) & DIP_PORT_SEL_MASK
; /* DIP_Port_Select, 0x1 = PortB */
7925 DRM_DEBUG_DRIVER("port num:%d\n", i
);
7927 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
7928 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
7929 for (i
= 0; i
< len
; i
++)
7930 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
7932 i
= I915_READ(aud_cntrl_st2
);
7934 I915_WRITE(aud_cntrl_st2
, i
);
7938 static void ironlake_write_eld(struct drm_connector
*connector
,
7939 struct drm_crtc
*crtc
,
7940 struct drm_display_mode
*mode
)
7942 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
7943 uint8_t *eld
= connector
->eld
;
7951 int pipe
= to_intel_crtc(crtc
)->pipe
;
7953 if (HAS_PCH_IBX(connector
->dev
)) {
7954 hdmiw_hdmiedid
= IBX_HDMIW_HDMIEDID(pipe
);
7955 aud_config
= IBX_AUD_CFG(pipe
);
7956 aud_cntl_st
= IBX_AUD_CNTL_ST(pipe
);
7957 aud_cntrl_st2
= IBX_AUD_CNTL_ST2
;
7958 } else if (IS_VALLEYVIEW(connector
->dev
)) {
7959 hdmiw_hdmiedid
= VLV_HDMIW_HDMIEDID(pipe
);
7960 aud_config
= VLV_AUD_CFG(pipe
);
7961 aud_cntl_st
= VLV_AUD_CNTL_ST(pipe
);
7962 aud_cntrl_st2
= VLV_AUD_CNTL_ST2
;
7964 hdmiw_hdmiedid
= CPT_HDMIW_HDMIEDID(pipe
);
7965 aud_config
= CPT_AUD_CFG(pipe
);
7966 aud_cntl_st
= CPT_AUD_CNTL_ST(pipe
);
7967 aud_cntrl_st2
= CPT_AUD_CNTRL_ST2
;
7970 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
7972 if (IS_VALLEYVIEW(connector
->dev
)) {
7973 struct intel_encoder
*intel_encoder
;
7974 struct intel_digital_port
*intel_dig_port
;
7976 intel_encoder
= intel_attached_encoder(connector
);
7977 intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
7978 i
= intel_dig_port
->port
;
7980 i
= I915_READ(aud_cntl_st
);
7981 i
= (i
>> 29) & DIP_PORT_SEL_MASK
;
7982 /* DIP_Port_Select, 0x1 = PortB */
7986 DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
7987 /* operate blindly on all ports */
7988 eldv
= IBX_ELD_VALIDB
;
7989 eldv
|= IBX_ELD_VALIDB
<< 4;
7990 eldv
|= IBX_ELD_VALIDB
<< 8;
7992 DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i
));
7993 eldv
= IBX_ELD_VALIDB
<< ((i
- 1) * 4);
7996 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
7997 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
7998 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
7999 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
8001 I915_WRITE(aud_config
, audio_config_hdmi_pixel_clock(mode
));
8004 if (intel_eld_uptodate(connector
,
8005 aud_cntrl_st2
, eldv
,
8006 aud_cntl_st
, IBX_ELD_ADDRESS
,
8010 i
= I915_READ(aud_cntrl_st2
);
8012 I915_WRITE(aud_cntrl_st2
, i
);
8017 i
= I915_READ(aud_cntl_st
);
8018 i
&= ~IBX_ELD_ADDRESS
;
8019 I915_WRITE(aud_cntl_st
, i
);
8021 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
8022 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
8023 for (i
= 0; i
< len
; i
++)
8024 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
8026 i
= I915_READ(aud_cntrl_st2
);
8028 I915_WRITE(aud_cntrl_st2
, i
);
8031 void intel_write_eld(struct drm_encoder
*encoder
,
8032 struct drm_display_mode
*mode
)
8034 struct drm_crtc
*crtc
= encoder
->crtc
;
8035 struct drm_connector
*connector
;
8036 struct drm_device
*dev
= encoder
->dev
;
8037 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8039 connector
= drm_select_eld(encoder
, mode
);
8043 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8046 connector
->encoder
->base
.id
,
8047 connector
->encoder
->name
);
8049 connector
->eld
[6] = drm_av_sync_delay(connector
, mode
) / 2;
8051 if (dev_priv
->display
.write_eld
)
8052 dev_priv
->display
.write_eld(connector
, crtc
, mode
);
8055 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8057 struct drm_device
*dev
= crtc
->dev
;
8058 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8059 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8060 uint32_t cntl
= 0, size
= 0;
8063 unsigned int width
= intel_crtc
->cursor_width
;
8064 unsigned int height
= intel_crtc
->cursor_height
;
8065 unsigned int stride
= roundup_pow_of_two(width
) * 4;
8069 WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
8080 cntl
|= CURSOR_ENABLE
|
8081 CURSOR_GAMMA_ENABLE
|
8082 CURSOR_FORMAT_ARGB
|
8083 CURSOR_STRIDE(stride
);
8085 size
= (height
<< 12) | width
;
8088 if (intel_crtc
->cursor_cntl
!= 0 &&
8089 (intel_crtc
->cursor_base
!= base
||
8090 intel_crtc
->cursor_size
!= size
||
8091 intel_crtc
->cursor_cntl
!= cntl
)) {
8092 /* On these chipsets we can only modify the base/size/stride
8093 * whilst the cursor is disabled.
8095 I915_WRITE(_CURACNTR
, 0);
8096 POSTING_READ(_CURACNTR
);
8097 intel_crtc
->cursor_cntl
= 0;
8100 if (intel_crtc
->cursor_base
!= base
)
8101 I915_WRITE(_CURABASE
, base
);
8103 if (intel_crtc
->cursor_size
!= size
) {
8104 I915_WRITE(CURSIZE
, size
);
8105 intel_crtc
->cursor_size
= size
;
8108 if (intel_crtc
->cursor_cntl
!= cntl
) {
8109 I915_WRITE(_CURACNTR
, cntl
);
8110 POSTING_READ(_CURACNTR
);
8111 intel_crtc
->cursor_cntl
= cntl
;
8115 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
8117 struct drm_device
*dev
= crtc
->dev
;
8118 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8119 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8120 int pipe
= intel_crtc
->pipe
;
8125 cntl
= MCURSOR_GAMMA_ENABLE
;
8126 switch (intel_crtc
->cursor_width
) {
8128 cntl
|= CURSOR_MODE_64_ARGB_AX
;
8131 cntl
|= CURSOR_MODE_128_ARGB_AX
;
8134 cntl
|= CURSOR_MODE_256_ARGB_AX
;
8140 cntl
|= pipe
<< 28; /* Connect to correct pipe */
8142 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
8143 cntl
|= CURSOR_PIPE_CSC_ENABLE
;
8145 if (intel_crtc
->cursor_cntl
!= cntl
) {
8146 I915_WRITE(CURCNTR(pipe
), cntl
);
8147 POSTING_READ(CURCNTR(pipe
));
8148 intel_crtc
->cursor_cntl
= cntl
;
8151 /* and commit changes on next vblank */
8152 I915_WRITE(CURBASE(pipe
), base
);
8153 POSTING_READ(CURBASE(pipe
));
8156 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
8157 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
8160 struct drm_device
*dev
= crtc
->dev
;
8161 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8162 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8163 int pipe
= intel_crtc
->pipe
;
8164 int x
= crtc
->cursor_x
;
8165 int y
= crtc
->cursor_y
;
8166 u32 base
= 0, pos
= 0;
8169 base
= intel_crtc
->cursor_addr
;
8171 if (x
>= intel_crtc
->config
.pipe_src_w
)
8174 if (y
>= intel_crtc
->config
.pipe_src_h
)
8178 if (x
+ intel_crtc
->cursor_width
<= 0)
8181 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
8184 pos
|= x
<< CURSOR_X_SHIFT
;
8187 if (y
+ intel_crtc
->cursor_height
<= 0)
8190 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
8193 pos
|= y
<< CURSOR_Y_SHIFT
;
8195 if (base
== 0 && intel_crtc
->cursor_base
== 0)
8198 I915_WRITE(CURPOS(pipe
), pos
);
8200 if (IS_845G(dev
) || IS_I865G(dev
))
8201 i845_update_cursor(crtc
, base
);
8203 i9xx_update_cursor(crtc
, base
);
8204 intel_crtc
->cursor_base
= base
;
8207 static bool cursor_size_ok(struct drm_device
*dev
,
8208 uint32_t width
, uint32_t height
)
8210 if (width
== 0 || height
== 0)
8214 * 845g/865g are special in that they are only limited by
8215 * the width of their cursors, the height is arbitrary up to
8216 * the precision of the register. Everything else requires
8217 * square cursors, limited to a few power-of-two sizes.
8219 if (IS_845G(dev
) || IS_I865G(dev
)) {
8220 if ((width
& 63) != 0)
8223 if (width
> (IS_845G(dev
) ? 64 : 512))
8229 switch (width
| height
) {
8245 * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
8247 * Note that the object's reference will be consumed if the update fails. If
8248 * the update succeeds, the reference of the old object (if any) will be
8251 static int intel_crtc_cursor_set_obj(struct drm_crtc
*crtc
,
8252 struct drm_i915_gem_object
*obj
,
8253 uint32_t width
, uint32_t height
)
8255 struct drm_device
*dev
= crtc
->dev
;
8256 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8257 enum pipe pipe
= intel_crtc
->pipe
;
8258 unsigned old_width
, stride
;
8262 /* if we want to turn off the cursor ignore width and height */
8264 DRM_DEBUG_KMS("cursor off\n");
8267 mutex_lock(&dev
->struct_mutex
);
8271 /* Check for which cursor types we support */
8272 if (!cursor_size_ok(dev
, width
, height
)) {
8273 DRM_DEBUG("Cursor dimension not supported\n");
8277 stride
= roundup_pow_of_two(width
) * 4;
8278 if (obj
->base
.size
< stride
* height
) {
8279 DRM_DEBUG_KMS("buffer is too small\n");
8284 /* we only need to pin inside GTT if cursor is non-phy */
8285 mutex_lock(&dev
->struct_mutex
);
8286 if (!INTEL_INFO(dev
)->cursor_needs_physical
) {
8289 if (obj
->tiling_mode
) {
8290 DRM_DEBUG_KMS("cursor cannot be tiled\n");
8295 /* Note that the w/a also requires 2 PTE of padding following
8296 * the bo. We currently fill all unused PTE with the shadow
8297 * page and so we should always have valid PTE following the
8298 * cursor preventing the VT-d warning.
8301 if (need_vtd_wa(dev
))
8302 alignment
= 64*1024;
8304 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, NULL
);
8306 DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
8310 ret
= i915_gem_object_put_fence(obj
);
8312 DRM_DEBUG_KMS("failed to release fence for cursor");
8316 addr
= i915_gem_obj_ggtt_offset(obj
);
8318 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
8319 ret
= i915_gem_object_attach_phys(obj
, align
);
8321 DRM_DEBUG_KMS("failed to attach phys object\n");
8324 addr
= obj
->phys_handle
->busaddr
;
8328 if (intel_crtc
->cursor_bo
) {
8329 if (!INTEL_INFO(dev
)->cursor_needs_physical
)
8330 i915_gem_object_unpin_from_display_plane(intel_crtc
->cursor_bo
);
8333 i915_gem_track_fb(intel_crtc
->cursor_bo
, obj
,
8334 INTEL_FRONTBUFFER_CURSOR(pipe
));
8335 mutex_unlock(&dev
->struct_mutex
);
8337 old_width
= intel_crtc
->cursor_width
;
8339 intel_crtc
->cursor_addr
= addr
;
8340 intel_crtc
->cursor_bo
= obj
;
8341 intel_crtc
->cursor_width
= width
;
8342 intel_crtc
->cursor_height
= height
;
8344 if (intel_crtc
->active
) {
8345 if (old_width
!= width
)
8346 intel_update_watermarks(crtc
);
8347 intel_crtc_update_cursor(crtc
, intel_crtc
->cursor_bo
!= NULL
);
8350 intel_frontbuffer_flip(dev
, INTEL_FRONTBUFFER_CURSOR(pipe
));
8354 i915_gem_object_unpin_from_display_plane(obj
);
8356 mutex_unlock(&dev
->struct_mutex
);
8358 drm_gem_object_unreference_unlocked(&obj
->base
);
8362 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
8363 u16
*blue
, uint32_t start
, uint32_t size
)
8365 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
8366 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8368 for (i
= start
; i
< end
; i
++) {
8369 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
8370 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
8371 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
8374 intel_crtc_load_lut(crtc
);
8377 /* VESA 640x480x72Hz mode to set on the pipe */
8378 static struct drm_display_mode load_detect_mode
= {
8379 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
8380 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
8383 struct drm_framebuffer
*
8384 __intel_framebuffer_create(struct drm_device
*dev
,
8385 struct drm_mode_fb_cmd2
*mode_cmd
,
8386 struct drm_i915_gem_object
*obj
)
8388 struct intel_framebuffer
*intel_fb
;
8391 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
8393 drm_gem_object_unreference_unlocked(&obj
->base
);
8394 return ERR_PTR(-ENOMEM
);
8397 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
8401 return &intel_fb
->base
;
8403 drm_gem_object_unreference_unlocked(&obj
->base
);
8406 return ERR_PTR(ret
);
8409 static struct drm_framebuffer
*
8410 intel_framebuffer_create(struct drm_device
*dev
,
8411 struct drm_mode_fb_cmd2
*mode_cmd
,
8412 struct drm_i915_gem_object
*obj
)
8414 struct drm_framebuffer
*fb
;
8417 ret
= i915_mutex_lock_interruptible(dev
);
8419 return ERR_PTR(ret
);
8420 fb
= __intel_framebuffer_create(dev
, mode_cmd
, obj
);
8421 mutex_unlock(&dev
->struct_mutex
);
8427 intel_framebuffer_pitch_for_width(int width
, int bpp
)
8429 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
8430 return ALIGN(pitch
, 64);
8434 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
8436 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
8437 return PAGE_ALIGN(pitch
* mode
->vdisplay
);
8440 static struct drm_framebuffer
*
8441 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
8442 struct drm_display_mode
*mode
,
8445 struct drm_i915_gem_object
*obj
;
8446 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
8448 obj
= i915_gem_alloc_object(dev
,
8449 intel_framebuffer_size_for_mode(mode
, bpp
));
8451 return ERR_PTR(-ENOMEM
);
8453 mode_cmd
.width
= mode
->hdisplay
;
8454 mode_cmd
.height
= mode
->vdisplay
;
8455 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
8457 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
8459 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
8462 static struct drm_framebuffer
*
8463 mode_fits_in_fbdev(struct drm_device
*dev
,
8464 struct drm_display_mode
*mode
)
8466 #ifdef CONFIG_DRM_I915_FBDEV
8467 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8468 struct drm_i915_gem_object
*obj
;
8469 struct drm_framebuffer
*fb
;
8471 if (!dev_priv
->fbdev
)
8474 if (!dev_priv
->fbdev
->fb
)
8477 obj
= dev_priv
->fbdev
->fb
->obj
;
8480 fb
= &dev_priv
->fbdev
->fb
->base
;
8481 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
8482 fb
->bits_per_pixel
))
8485 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
8494 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
8495 struct drm_display_mode
*mode
,
8496 struct intel_load_detect_pipe
*old
,
8497 struct drm_modeset_acquire_ctx
*ctx
)
8499 struct intel_crtc
*intel_crtc
;
8500 struct intel_encoder
*intel_encoder
=
8501 intel_attached_encoder(connector
);
8502 struct drm_crtc
*possible_crtc
;
8503 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8504 struct drm_crtc
*crtc
= NULL
;
8505 struct drm_device
*dev
= encoder
->dev
;
8506 struct drm_framebuffer
*fb
;
8507 struct drm_mode_config
*config
= &dev
->mode_config
;
8510 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8511 connector
->base
.id
, connector
->name
,
8512 encoder
->base
.id
, encoder
->name
);
8515 ret
= drm_modeset_lock(&config
->connection_mutex
, ctx
);
8520 * Algorithm gets a little messy:
8522 * - if the connector already has an assigned crtc, use it (but make
8523 * sure it's on first)
8525 * - try to find the first unused crtc that can drive this connector,
8526 * and use that if we find one
8529 /* See if we already have a CRTC for this connector */
8530 if (encoder
->crtc
) {
8531 crtc
= encoder
->crtc
;
8533 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8537 old
->dpms_mode
= connector
->dpms
;
8538 old
->load_detect_temp
= false;
8540 /* Make sure the crtc and connector are running */
8541 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
8542 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
8547 /* Find an unused one (if possible) */
8548 for_each_crtc(dev
, possible_crtc
) {
8550 if (!(encoder
->possible_crtcs
& (1 << i
)))
8552 if (possible_crtc
->enabled
)
8554 /* This can occur when applying the pipe A quirk on resume. */
8555 if (to_intel_crtc(possible_crtc
)->new_enabled
)
8558 crtc
= possible_crtc
;
8563 * If we didn't find an unused CRTC, don't use any.
8566 DRM_DEBUG_KMS("no pipe available for load-detect\n");
8570 ret
= drm_modeset_lock(&crtc
->mutex
, ctx
);
8573 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
8574 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
8576 intel_crtc
= to_intel_crtc(crtc
);
8577 intel_crtc
->new_enabled
= true;
8578 intel_crtc
->new_config
= &intel_crtc
->config
;
8579 old
->dpms_mode
= connector
->dpms
;
8580 old
->load_detect_temp
= true;
8581 old
->release_fb
= NULL
;
8584 mode
= &load_detect_mode
;
8586 /* We need a framebuffer large enough to accommodate all accesses
8587 * that the plane may generate whilst we perform load detection.
8588 * We can not rely on the fbcon either being present (we get called
8589 * during its initialisation to detect all boot displays, or it may
8590 * not even exist) or that it is large enough to satisfy the
8593 fb
= mode_fits_in_fbdev(dev
, mode
);
8595 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
8596 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
8597 old
->release_fb
= fb
;
8599 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
8601 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
8605 if (intel_set_mode(crtc
, mode
, 0, 0, fb
)) {
8606 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
8607 if (old
->release_fb
)
8608 old
->release_fb
->funcs
->destroy(old
->release_fb
);
8612 /* let the connector get through one full cycle before testing */
8613 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
8617 intel_crtc
->new_enabled
= crtc
->enabled
;
8618 if (intel_crtc
->new_enabled
)
8619 intel_crtc
->new_config
= &intel_crtc
->config
;
8621 intel_crtc
->new_config
= NULL
;
8623 if (ret
== -EDEADLK
) {
8624 drm_modeset_backoff(ctx
);
8631 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
8632 struct intel_load_detect_pipe
*old
)
8634 struct intel_encoder
*intel_encoder
=
8635 intel_attached_encoder(connector
);
8636 struct drm_encoder
*encoder
= &intel_encoder
->base
;
8637 struct drm_crtc
*crtc
= encoder
->crtc
;
8638 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8640 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
8641 connector
->base
.id
, connector
->name
,
8642 encoder
->base
.id
, encoder
->name
);
8644 if (old
->load_detect_temp
) {
8645 to_intel_connector(connector
)->new_encoder
= NULL
;
8646 intel_encoder
->new_crtc
= NULL
;
8647 intel_crtc
->new_enabled
= false;
8648 intel_crtc
->new_config
= NULL
;
8649 intel_set_mode(crtc
, NULL
, 0, 0, NULL
);
8651 if (old
->release_fb
) {
8652 drm_framebuffer_unregister_private(old
->release_fb
);
8653 drm_framebuffer_unreference(old
->release_fb
);
8659 /* Switch crtc and encoder back off if necessary */
8660 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
8661 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
8664 static int i9xx_pll_refclk(struct drm_device
*dev
,
8665 const struct intel_crtc_config
*pipe_config
)
8667 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8668 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8670 if ((dpll
& PLL_REF_INPUT_MASK
) == PLLB_REF_INPUT_SPREADSPECTRUMIN
)
8671 return dev_priv
->vbt
.lvds_ssc_freq
;
8672 else if (HAS_PCH_SPLIT(dev
))
8674 else if (!IS_GEN2(dev
))
8680 /* Returns the clock of the currently programmed mode of the given pipe. */
8681 static void i9xx_crtc_clock_get(struct intel_crtc
*crtc
,
8682 struct intel_crtc_config
*pipe_config
)
8684 struct drm_device
*dev
= crtc
->base
.dev
;
8685 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8686 int pipe
= pipe_config
->cpu_transcoder
;
8687 u32 dpll
= pipe_config
->dpll_hw_state
.dpll
;
8689 intel_clock_t clock
;
8690 int refclk
= i9xx_pll_refclk(dev
, pipe_config
);
8692 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
8693 fp
= pipe_config
->dpll_hw_state
.fp0
;
8695 fp
= pipe_config
->dpll_hw_state
.fp1
;
8697 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
8698 if (IS_PINEVIEW(dev
)) {
8699 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
8700 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8702 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
8703 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
8706 if (!IS_GEN2(dev
)) {
8707 if (IS_PINEVIEW(dev
))
8708 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
8709 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
8711 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
8712 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8714 switch (dpll
& DPLL_MODE_MASK
) {
8715 case DPLLB_MODE_DAC_SERIAL
:
8716 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
8719 case DPLLB_MODE_LVDS
:
8720 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
8724 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
8725 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
8729 if (IS_PINEVIEW(dev
))
8730 pineview_clock(refclk
, &clock
);
8732 i9xx_clock(refclk
, &clock
);
8734 u32 lvds
= IS_I830(dev
) ? 0 : I915_READ(LVDS
);
8735 bool is_lvds
= (pipe
== 1) && (lvds
& LVDS_PORT_EN
);
8738 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
8739 DPLL_FPA01_P1_POST_DIV_SHIFT
);
8741 if (lvds
& LVDS_CLKB_POWER_UP
)
8746 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
8749 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
8750 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
8752 if (dpll
& PLL_P2_DIVIDE_BY_4
)
8758 i9xx_clock(refclk
, &clock
);
8762 * This value includes pixel_multiplier. We will use
8763 * port_clock to compute adjusted_mode.crtc_clock in the
8764 * encoder's get_config() function.
8766 pipe_config
->port_clock
= clock
.dot
;
8769 int intel_dotclock_calculate(int link_freq
,
8770 const struct intel_link_m_n
*m_n
)
8773 * The calculation for the data clock is:
8774 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
8775 * But we want to avoid losing precison if possible, so:
8776 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
8778 * and the link clock is simpler:
8779 * link_clock = (m * link_clock) / n
8785 return div_u64((u64
)m_n
->link_m
* link_freq
, m_n
->link_n
);
8788 static void ironlake_pch_clock_get(struct intel_crtc
*crtc
,
8789 struct intel_crtc_config
*pipe_config
)
8791 struct drm_device
*dev
= crtc
->base
.dev
;
8793 /* read out port_clock from the DPLL */
8794 i9xx_crtc_clock_get(crtc
, pipe_config
);
8797 * This value does not include pixel_multiplier.
8798 * We will check that port_clock and adjusted_mode.crtc_clock
8799 * agree once we know their relationship in the encoder's
8800 * get_config() function.
8802 pipe_config
->adjusted_mode
.crtc_clock
=
8803 intel_dotclock_calculate(intel_fdi_link_freq(dev
) * 10000,
8804 &pipe_config
->fdi_m_n
);
8807 /** Returns the currently programmed mode of the given pipe. */
8808 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
8809 struct drm_crtc
*crtc
)
8811 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8812 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8813 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
8814 struct drm_display_mode
*mode
;
8815 struct intel_crtc_config pipe_config
;
8816 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
8817 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
8818 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
8819 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
8820 enum pipe pipe
= intel_crtc
->pipe
;
8822 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
8827 * Construct a pipe_config sufficient for getting the clock info
8828 * back out of crtc_clock_get.
8830 * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
8831 * to use a real value here instead.
8833 pipe_config
.cpu_transcoder
= (enum transcoder
) pipe
;
8834 pipe_config
.pixel_multiplier
= 1;
8835 pipe_config
.dpll_hw_state
.dpll
= I915_READ(DPLL(pipe
));
8836 pipe_config
.dpll_hw_state
.fp0
= I915_READ(FP0(pipe
));
8837 pipe_config
.dpll_hw_state
.fp1
= I915_READ(FP1(pipe
));
8838 i9xx_crtc_clock_get(intel_crtc
, &pipe_config
);
8840 mode
->clock
= pipe_config
.port_clock
/ pipe_config
.pixel_multiplier
;
8841 mode
->hdisplay
= (htot
& 0xffff) + 1;
8842 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
8843 mode
->hsync_start
= (hsync
& 0xffff) + 1;
8844 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
8845 mode
->vdisplay
= (vtot
& 0xffff) + 1;
8846 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
8847 mode
->vsync_start
= (vsync
& 0xffff) + 1;
8848 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
8850 drm_mode_set_name(mode
);
8855 static void intel_increase_pllclock(struct drm_device
*dev
,
8858 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8859 int dpll_reg
= DPLL(pipe
);
8862 if (!HAS_GMCH_DISPLAY(dev
))
8865 if (!dev_priv
->lvds_downclock_avail
)
8868 dpll
= I915_READ(dpll_reg
);
8869 if (!HAS_PIPE_CXSR(dev
) && (dpll
& DISPLAY_RATE_SELECT_FPA1
)) {
8870 DRM_DEBUG_DRIVER("upclocking LVDS\n");
8872 assert_panel_unlocked(dev_priv
, pipe
);
8874 dpll
&= ~DISPLAY_RATE_SELECT_FPA1
;
8875 I915_WRITE(dpll_reg
, dpll
);
8876 intel_wait_for_vblank(dev
, pipe
);
8878 dpll
= I915_READ(dpll_reg
);
8879 if (dpll
& DISPLAY_RATE_SELECT_FPA1
)
8880 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
8884 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
8886 struct drm_device
*dev
= crtc
->dev
;
8887 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8888 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
8890 if (!HAS_GMCH_DISPLAY(dev
))
8893 if (!dev_priv
->lvds_downclock_avail
)
8897 * Since this is called by a timer, we should never get here in
8900 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
8901 int pipe
= intel_crtc
->pipe
;
8902 int dpll_reg
= DPLL(pipe
);
8905 DRM_DEBUG_DRIVER("downclocking LVDS\n");
8907 assert_panel_unlocked(dev_priv
, pipe
);
8909 dpll
= I915_READ(dpll_reg
);
8910 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
8911 I915_WRITE(dpll_reg
, dpll
);
8912 intel_wait_for_vblank(dev
, pipe
);
8913 dpll
= I915_READ(dpll_reg
);
8914 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
8915 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
8920 void intel_mark_busy(struct drm_device
*dev
)
8922 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8924 if (dev_priv
->mm
.busy
)
8927 intel_runtime_pm_get(dev_priv
);
8928 i915_update_gfx_val(dev_priv
);
8929 dev_priv
->mm
.busy
= true;
8932 void intel_mark_idle(struct drm_device
*dev
)
8934 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8935 struct drm_crtc
*crtc
;
8937 if (!dev_priv
->mm
.busy
)
8940 dev_priv
->mm
.busy
= false;
8942 if (!i915
.powersave
)
8945 for_each_crtc(dev
, crtc
) {
8946 if (!crtc
->primary
->fb
)
8949 intel_decrease_pllclock(crtc
);
8952 if (INTEL_INFO(dev
)->gen
>= 6)
8953 gen6_rps_idle(dev
->dev_private
);
8956 intel_runtime_pm_put(dev_priv
);
8961 * intel_mark_fb_busy - mark given planes as busy
8963 * @frontbuffer_bits: bits for the affected planes
8964 * @ring: optional ring for asynchronous commands
8966 * This function gets called every time the screen contents change. It can be
8967 * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
8969 static void intel_mark_fb_busy(struct drm_device
*dev
,
8970 unsigned frontbuffer_bits
,
8971 struct intel_engine_cs
*ring
)
8975 if (!i915
.powersave
)
8978 for_each_pipe(pipe
) {
8979 if (!(frontbuffer_bits
& INTEL_FRONTBUFFER_ALL_MASK(pipe
)))
8982 intel_increase_pllclock(dev
, pipe
);
8983 if (ring
&& intel_fbc_enabled(dev
))
8984 ring
->fbc_dirty
= true;
8989 * intel_fb_obj_invalidate - invalidate frontbuffer object
8990 * @obj: GEM object to invalidate
8991 * @ring: set for asynchronous rendering
8993 * This function gets called every time rendering on the given object starts and
8994 * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
8995 * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
8996 * until the rendering completes or a flip on this frontbuffer plane is
8999 void intel_fb_obj_invalidate(struct drm_i915_gem_object
*obj
,
9000 struct intel_engine_cs
*ring
)
9002 struct drm_device
*dev
= obj
->base
.dev
;
9003 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9005 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
9007 if (!obj
->frontbuffer_bits
)
9011 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9012 dev_priv
->fb_tracking
.busy_bits
9013 |= obj
->frontbuffer_bits
;
9014 dev_priv
->fb_tracking
.flip_bits
9015 &= ~obj
->frontbuffer_bits
;
9016 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9019 intel_mark_fb_busy(dev
, obj
->frontbuffer_bits
, ring
);
9021 intel_edp_psr_invalidate(dev
, obj
->frontbuffer_bits
);
9025 * intel_frontbuffer_flush - flush frontbuffer
9027 * @frontbuffer_bits: frontbuffer plane tracking bits
9029 * This function gets called every time rendering on the given planes has
9030 * completed and frontbuffer caching can be started again. Flushes will get
9031 * delayed if they're blocked by some oustanding asynchronous rendering.
9033 * Can be called without any locks held.
9035 void intel_frontbuffer_flush(struct drm_device
*dev
,
9036 unsigned frontbuffer_bits
)
9038 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9040 /* Delay flushing when rings are still busy.*/
9041 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9042 frontbuffer_bits
&= ~dev_priv
->fb_tracking
.busy_bits
;
9043 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9045 intel_mark_fb_busy(dev
, frontbuffer_bits
, NULL
);
9047 intel_edp_psr_flush(dev
, frontbuffer_bits
);
9051 * intel_fb_obj_flush - flush frontbuffer object
9052 * @obj: GEM object to flush
9053 * @retire: set when retiring asynchronous rendering
9055 * This function gets called every time rendering on the given object has
9056 * completed and frontbuffer caching can be started again. If @retire is true
9057 * then any delayed flushes will be unblocked.
9059 void intel_fb_obj_flush(struct drm_i915_gem_object
*obj
,
9062 struct drm_device
*dev
= obj
->base
.dev
;
9063 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9064 unsigned frontbuffer_bits
;
9066 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
9068 if (!obj
->frontbuffer_bits
)
9071 frontbuffer_bits
= obj
->frontbuffer_bits
;
9074 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9075 /* Filter out new bits since rendering started. */
9076 frontbuffer_bits
&= dev_priv
->fb_tracking
.busy_bits
;
9078 dev_priv
->fb_tracking
.busy_bits
&= ~frontbuffer_bits
;
9079 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9082 intel_frontbuffer_flush(dev
, frontbuffer_bits
);
9086 * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
9088 * @frontbuffer_bits: frontbuffer plane tracking bits
9090 * This function gets called after scheduling a flip on @obj. The actual
9091 * frontbuffer flushing will be delayed until completion is signalled with
9092 * intel_frontbuffer_flip_complete. If an invalidate happens in between this
9093 * flush will be cancelled.
9095 * Can be called without any locks held.
9097 void intel_frontbuffer_flip_prepare(struct drm_device
*dev
,
9098 unsigned frontbuffer_bits
)
9100 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9102 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9103 dev_priv
->fb_tracking
.flip_bits
9104 |= frontbuffer_bits
;
9105 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9109 * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
9111 * @frontbuffer_bits: frontbuffer plane tracking bits
9113 * This function gets called after the flip has been latched and will complete
9114 * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
9116 * Can be called without any locks held.
9118 void intel_frontbuffer_flip_complete(struct drm_device
*dev
,
9119 unsigned frontbuffer_bits
)
9121 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9123 mutex_lock(&dev_priv
->fb_tracking
.lock
);
9124 /* Mask any cancelled flips. */
9125 frontbuffer_bits
&= dev_priv
->fb_tracking
.flip_bits
;
9126 dev_priv
->fb_tracking
.flip_bits
&= ~frontbuffer_bits
;
9127 mutex_unlock(&dev_priv
->fb_tracking
.lock
);
9129 intel_frontbuffer_flush(dev
, frontbuffer_bits
);
9132 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
9134 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9135 struct drm_device
*dev
= crtc
->dev
;
9136 struct intel_unpin_work
*work
;
9137 unsigned long flags
;
9139 spin_lock_irqsave(&dev
->event_lock
, flags
);
9140 work
= intel_crtc
->unpin_work
;
9141 intel_crtc
->unpin_work
= NULL
;
9142 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9145 cancel_work_sync(&work
->work
);
9149 drm_crtc_cleanup(crtc
);
9154 static void intel_unpin_work_fn(struct work_struct
*__work
)
9156 struct intel_unpin_work
*work
=
9157 container_of(__work
, struct intel_unpin_work
, work
);
9158 struct drm_device
*dev
= work
->crtc
->dev
;
9159 enum pipe pipe
= to_intel_crtc(work
->crtc
)->pipe
;
9161 mutex_lock(&dev
->struct_mutex
);
9162 intel_unpin_fb_obj(work
->old_fb_obj
);
9163 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
9164 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
9166 intel_update_fbc(dev
);
9167 mutex_unlock(&dev
->struct_mutex
);
9169 intel_frontbuffer_flip_complete(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
9171 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
9172 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
9177 static void do_intel_finish_page_flip(struct drm_device
*dev
,
9178 struct drm_crtc
*crtc
)
9180 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9181 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9182 struct intel_unpin_work
*work
;
9183 unsigned long flags
;
9185 /* Ignore early vblank irqs */
9186 if (intel_crtc
== NULL
)
9189 spin_lock_irqsave(&dev
->event_lock
, flags
);
9190 work
= intel_crtc
->unpin_work
;
9192 /* Ensure we don't miss a work->pending update ... */
9195 if (work
== NULL
|| atomic_read(&work
->pending
) < INTEL_FLIP_COMPLETE
) {
9196 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9200 /* and that the unpin work is consistent wrt ->pending. */
9203 intel_crtc
->unpin_work
= NULL
;
9206 drm_send_vblank_event(dev
, intel_crtc
->pipe
, work
->event
);
9208 drm_crtc_vblank_put(crtc
);
9210 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9212 wake_up_all(&dev_priv
->pending_flip_queue
);
9214 queue_work(dev_priv
->wq
, &work
->work
);
9216 trace_i915_flip_complete(intel_crtc
->plane
, work
->pending_flip_obj
);
9219 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
9221 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9222 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
9224 do_intel_finish_page_flip(dev
, crtc
);
9227 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
9229 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9230 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
9232 do_intel_finish_page_flip(dev
, crtc
);
9235 /* Is 'a' after or equal to 'b'? */
9236 static bool g4x_flip_count_after_eq(u32 a
, u32 b
)
9238 return !((a
- b
) & 0x80000000);
9241 static bool page_flip_finished(struct intel_crtc
*crtc
)
9243 struct drm_device
*dev
= crtc
->base
.dev
;
9244 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9247 * The relevant registers doen't exist on pre-ctg.
9248 * As the flip done interrupt doesn't trigger for mmio
9249 * flips on gmch platforms, a flip count check isn't
9250 * really needed there. But since ctg has the registers,
9251 * include it in the check anyway.
9253 if (INTEL_INFO(dev
)->gen
< 5 && !IS_G4X(dev
))
9257 * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
9258 * used the same base address. In that case the mmio flip might
9259 * have completed, but the CS hasn't even executed the flip yet.
9261 * A flip count check isn't enough as the CS might have updated
9262 * the base address just after start of vblank, but before we
9263 * managed to process the interrupt. This means we'd complete the
9266 * Combining both checks should get us a good enough result. It may
9267 * still happen that the CS flip has been executed, but has not
9268 * yet actually completed. But in case the base address is the same
9269 * anyway, we don't really care.
9271 return (I915_READ(DSPSURFLIVE(crtc
->plane
)) & ~0xfff) ==
9272 crtc
->unpin_work
->gtt_offset
&&
9273 g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc
->pipe
)),
9274 crtc
->unpin_work
->flip_count
);
9277 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
9279 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9280 struct intel_crtc
*intel_crtc
=
9281 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
9282 unsigned long flags
;
9284 /* NB: An MMIO update of the plane base pointer will also
9285 * generate a page-flip completion irq, i.e. every modeset
9286 * is also accompanied by a spurious intel_prepare_page_flip().
9288 spin_lock_irqsave(&dev
->event_lock
, flags
);
9289 if (intel_crtc
->unpin_work
&& page_flip_finished(intel_crtc
))
9290 atomic_inc_not_zero(&intel_crtc
->unpin_work
->pending
);
9291 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9294 static inline void intel_mark_page_flip_active(struct intel_crtc
*intel_crtc
)
9296 /* Ensure that the work item is consistent when activating it ... */
9298 atomic_set(&intel_crtc
->unpin_work
->pending
, INTEL_FLIP_PENDING
);
9299 /* and that it is marked active as soon as the irq could fire. */
9303 static int intel_gen2_queue_flip(struct drm_device
*dev
,
9304 struct drm_crtc
*crtc
,
9305 struct drm_framebuffer
*fb
,
9306 struct drm_i915_gem_object
*obj
,
9307 struct intel_engine_cs
*ring
,
9310 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9314 ret
= intel_ring_begin(ring
, 6);
9318 /* Can't queue multiple flips, so wait for the previous
9319 * one to finish before executing the next.
9321 if (intel_crtc
->plane
)
9322 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9324 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9325 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9326 intel_ring_emit(ring
, MI_NOOP
);
9327 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9328 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9329 intel_ring_emit(ring
, fb
->pitches
[0]);
9330 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9331 intel_ring_emit(ring
, 0); /* aux display base address, unused */
9333 intel_mark_page_flip_active(intel_crtc
);
9334 __intel_ring_advance(ring
);
9338 static int intel_gen3_queue_flip(struct drm_device
*dev
,
9339 struct drm_crtc
*crtc
,
9340 struct drm_framebuffer
*fb
,
9341 struct drm_i915_gem_object
*obj
,
9342 struct intel_engine_cs
*ring
,
9345 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9349 ret
= intel_ring_begin(ring
, 6);
9353 if (intel_crtc
->plane
)
9354 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
9356 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
9357 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
9358 intel_ring_emit(ring
, MI_NOOP
);
9359 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
9360 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9361 intel_ring_emit(ring
, fb
->pitches
[0]);
9362 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9363 intel_ring_emit(ring
, MI_NOOP
);
9365 intel_mark_page_flip_active(intel_crtc
);
9366 __intel_ring_advance(ring
);
9370 static int intel_gen4_queue_flip(struct drm_device
*dev
,
9371 struct drm_crtc
*crtc
,
9372 struct drm_framebuffer
*fb
,
9373 struct drm_i915_gem_object
*obj
,
9374 struct intel_engine_cs
*ring
,
9377 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9378 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9379 uint32_t pf
, pipesrc
;
9382 ret
= intel_ring_begin(ring
, 4);
9386 /* i965+ uses the linear or tiled offsets from the
9387 * Display Registers (which do not change across a page-flip)
9388 * so we need only reprogram the base address.
9390 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9391 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9392 intel_ring_emit(ring
, fb
->pitches
[0]);
9393 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
|
9396 /* XXX Enabling the panel-fitter across page-flip is so far
9397 * untested on non-native modes, so ignore it for now.
9398 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
9401 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9402 intel_ring_emit(ring
, pf
| pipesrc
);
9404 intel_mark_page_flip_active(intel_crtc
);
9405 __intel_ring_advance(ring
);
9409 static int intel_gen6_queue_flip(struct drm_device
*dev
,
9410 struct drm_crtc
*crtc
,
9411 struct drm_framebuffer
*fb
,
9412 struct drm_i915_gem_object
*obj
,
9413 struct intel_engine_cs
*ring
,
9416 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9417 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9418 uint32_t pf
, pipesrc
;
9421 ret
= intel_ring_begin(ring
, 4);
9425 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
9426 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
9427 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
9428 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9430 /* Contrary to the suggestions in the documentation,
9431 * "Enable Panel Fitter" does not seem to be required when page
9432 * flipping with a non-native mode, and worse causes a normal
9434 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
9437 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
9438 intel_ring_emit(ring
, pf
| pipesrc
);
9440 intel_mark_page_flip_active(intel_crtc
);
9441 __intel_ring_advance(ring
);
9445 static int intel_gen7_queue_flip(struct drm_device
*dev
,
9446 struct drm_crtc
*crtc
,
9447 struct drm_framebuffer
*fb
,
9448 struct drm_i915_gem_object
*obj
,
9449 struct intel_engine_cs
*ring
,
9452 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9453 uint32_t plane_bit
= 0;
9456 switch (intel_crtc
->plane
) {
9458 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
9461 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
9464 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
9467 WARN_ONCE(1, "unknown plane in flip command\n");
9472 if (ring
->id
== RCS
) {
9475 * On Gen 8, SRM is now taking an extra dword to accommodate
9476 * 48bits addresses, and we need a NOOP for the batch size to
9484 * BSpec MI_DISPLAY_FLIP for IVB:
9485 * "The full packet must be contained within the same cache line."
9487 * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
9488 * cacheline, if we ever start emitting more commands before
9489 * the MI_DISPLAY_FLIP we may need to first emit everything else,
9490 * then do the cacheline alignment, and finally emit the
9493 ret
= intel_ring_cacheline_align(ring
);
9497 ret
= intel_ring_begin(ring
, len
);
9501 /* Unmask the flip-done completion message. Note that the bspec says that
9502 * we should do this for both the BCS and RCS, and that we must not unmask
9503 * more than one flip event at any time (or ensure that one flip message
9504 * can be sent by waiting for flip-done prior to queueing new flips).
9505 * Experimentation says that BCS works despite DERRMR masking all
9506 * flip-done completion events and that unmasking all planes at once
9507 * for the RCS also doesn't appear to drop events. Setting the DERRMR
9508 * to zero does lead to lockups within MI_DISPLAY_FLIP.
9510 if (ring
->id
== RCS
) {
9511 intel_ring_emit(ring
, MI_LOAD_REGISTER_IMM(1));
9512 intel_ring_emit(ring
, DERRMR
);
9513 intel_ring_emit(ring
, ~(DERRMR_PIPEA_PRI_FLIP_DONE
|
9514 DERRMR_PIPEB_PRI_FLIP_DONE
|
9515 DERRMR_PIPEC_PRI_FLIP_DONE
));
9517 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM_GEN8(1) |
9518 MI_SRM_LRM_GLOBAL_GTT
);
9520 intel_ring_emit(ring
, MI_STORE_REGISTER_MEM(1) |
9521 MI_SRM_LRM_GLOBAL_GTT
);
9522 intel_ring_emit(ring
, DERRMR
);
9523 intel_ring_emit(ring
, ring
->scratch
.gtt_offset
+ 256);
9525 intel_ring_emit(ring
, 0);
9526 intel_ring_emit(ring
, MI_NOOP
);
9530 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
9531 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
9532 intel_ring_emit(ring
, intel_crtc
->unpin_work
->gtt_offset
);
9533 intel_ring_emit(ring
, (MI_NOOP
));
9535 intel_mark_page_flip_active(intel_crtc
);
9536 __intel_ring_advance(ring
);
9540 static bool use_mmio_flip(struct intel_engine_cs
*ring
,
9541 struct drm_i915_gem_object
*obj
)
9544 * This is not being used for older platforms, because
9545 * non-availability of flip done interrupt forces us to use
9546 * CS flips. Older platforms derive flip done using some clever
9547 * tricks involving the flip_pending status bits and vblank irqs.
9548 * So using MMIO flips there would disrupt this mechanism.
9554 if (INTEL_INFO(ring
->dev
)->gen
< 5)
9557 if (i915
.use_mmio_flip
< 0)
9559 else if (i915
.use_mmio_flip
> 0)
9561 else if (i915
.enable_execlists
)
9564 return ring
!= obj
->ring
;
9567 static void intel_do_mmio_flip(struct intel_crtc
*intel_crtc
)
9569 struct drm_device
*dev
= intel_crtc
->base
.dev
;
9570 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9571 struct intel_framebuffer
*intel_fb
=
9572 to_intel_framebuffer(intel_crtc
->base
.primary
->fb
);
9573 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
9577 intel_mark_page_flip_active(intel_crtc
);
9579 reg
= DSPCNTR(intel_crtc
->plane
);
9580 dspcntr
= I915_READ(reg
);
9582 if (INTEL_INFO(dev
)->gen
>= 4) {
9583 if (obj
->tiling_mode
!= I915_TILING_NONE
)
9584 dspcntr
|= DISPPLANE_TILED
;
9586 dspcntr
&= ~DISPPLANE_TILED
;
9588 I915_WRITE(reg
, dspcntr
);
9590 I915_WRITE(DSPSURF(intel_crtc
->plane
),
9591 intel_crtc
->unpin_work
->gtt_offset
);
9592 POSTING_READ(DSPSURF(intel_crtc
->plane
));
9595 static int intel_postpone_flip(struct drm_i915_gem_object
*obj
)
9597 struct intel_engine_cs
*ring
;
9600 lockdep_assert_held(&obj
->base
.dev
->struct_mutex
);
9602 if (!obj
->last_write_seqno
)
9607 if (i915_seqno_passed(ring
->get_seqno(ring
, true),
9608 obj
->last_write_seqno
))
9611 ret
= i915_gem_check_olr(ring
, obj
->last_write_seqno
);
9615 if (WARN_ON(!ring
->irq_get(ring
)))
9621 void intel_notify_mmio_flip(struct intel_engine_cs
*ring
)
9623 struct drm_i915_private
*dev_priv
= to_i915(ring
->dev
);
9624 struct intel_crtc
*intel_crtc
;
9625 unsigned long irq_flags
;
9628 seqno
= ring
->get_seqno(ring
, false);
9630 spin_lock_irqsave(&dev_priv
->mmio_flip_lock
, irq_flags
);
9631 for_each_intel_crtc(ring
->dev
, intel_crtc
) {
9632 struct intel_mmio_flip
*mmio_flip
;
9634 mmio_flip
= &intel_crtc
->mmio_flip
;
9635 if (mmio_flip
->seqno
== 0)
9638 if (ring
->id
!= mmio_flip
->ring_id
)
9641 if (i915_seqno_passed(seqno
, mmio_flip
->seqno
)) {
9642 intel_do_mmio_flip(intel_crtc
);
9643 mmio_flip
->seqno
= 0;
9644 ring
->irq_put(ring
);
9647 spin_unlock_irqrestore(&dev_priv
->mmio_flip_lock
, irq_flags
);
9650 static int intel_queue_mmio_flip(struct drm_device
*dev
,
9651 struct drm_crtc
*crtc
,
9652 struct drm_framebuffer
*fb
,
9653 struct drm_i915_gem_object
*obj
,
9654 struct intel_engine_cs
*ring
,
9657 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9658 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9659 unsigned long irq_flags
;
9662 if (WARN_ON(intel_crtc
->mmio_flip
.seqno
))
9665 ret
= intel_postpone_flip(obj
);
9669 intel_do_mmio_flip(intel_crtc
);
9673 spin_lock_irqsave(&dev_priv
->mmio_flip_lock
, irq_flags
);
9674 intel_crtc
->mmio_flip
.seqno
= obj
->last_write_seqno
;
9675 intel_crtc
->mmio_flip
.ring_id
= obj
->ring
->id
;
9676 spin_unlock_irqrestore(&dev_priv
->mmio_flip_lock
, irq_flags
);
9679 * Double check to catch cases where irq fired before
9680 * mmio flip data was ready
9682 intel_notify_mmio_flip(obj
->ring
);
9686 static int intel_default_queue_flip(struct drm_device
*dev
,
9687 struct drm_crtc
*crtc
,
9688 struct drm_framebuffer
*fb
,
9689 struct drm_i915_gem_object
*obj
,
9690 struct intel_engine_cs
*ring
,
9696 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
9697 struct drm_framebuffer
*fb
,
9698 struct drm_pending_vblank_event
*event
,
9699 uint32_t page_flip_flags
)
9701 struct drm_device
*dev
= crtc
->dev
;
9702 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9703 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
9704 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
9705 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
9706 enum pipe pipe
= intel_crtc
->pipe
;
9707 struct intel_unpin_work
*work
;
9708 struct intel_engine_cs
*ring
;
9709 unsigned long flags
;
9713 * drm_mode_page_flip_ioctl() should already catch this, but double
9714 * check to be safe. In the future we may enable pageflipping from
9715 * a disabled primary plane.
9717 if (WARN_ON(intel_fb_obj(old_fb
) == NULL
))
9720 /* Can't change pixel format via MI display flips. */
9721 if (fb
->pixel_format
!= crtc
->primary
->fb
->pixel_format
)
9725 * TILEOFF/LINOFF registers can't be changed via MI display flips.
9726 * Note that pitch changes could also affect these register.
9728 if (INTEL_INFO(dev
)->gen
> 3 &&
9729 (fb
->offsets
[0] != crtc
->primary
->fb
->offsets
[0] ||
9730 fb
->pitches
[0] != crtc
->primary
->fb
->pitches
[0]))
9733 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
9736 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
9740 work
->event
= event
;
9742 work
->old_fb_obj
= intel_fb_obj(old_fb
);
9743 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
9745 ret
= drm_crtc_vblank_get(crtc
);
9749 /* We borrow the event spin lock for protecting unpin_work */
9750 spin_lock_irqsave(&dev
->event_lock
, flags
);
9751 if (intel_crtc
->unpin_work
) {
9752 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9754 drm_crtc_vblank_put(crtc
);
9756 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
9759 intel_crtc
->unpin_work
= work
;
9760 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9762 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
9763 flush_workqueue(dev_priv
->wq
);
9765 ret
= i915_mutex_lock_interruptible(dev
);
9769 /* Reference the objects for the scheduled work. */
9770 drm_gem_object_reference(&work
->old_fb_obj
->base
);
9771 drm_gem_object_reference(&obj
->base
);
9773 crtc
->primary
->fb
= fb
;
9775 work
->pending_flip_obj
= obj
;
9777 work
->enable_stall_check
= true;
9779 atomic_inc(&intel_crtc
->unpin_work_count
);
9780 intel_crtc
->reset_counter
= atomic_read(&dev_priv
->gpu_error
.reset_counter
);
9782 if (INTEL_INFO(dev
)->gen
>= 5 || IS_G4X(dev
))
9783 work
->flip_count
= I915_READ(PIPE_FLIPCOUNT_GM45(pipe
)) + 1;
9785 if (IS_VALLEYVIEW(dev
)) {
9786 ring
= &dev_priv
->ring
[BCS
];
9787 if (obj
->tiling_mode
!= work
->old_fb_obj
->tiling_mode
)
9788 /* vlv: DISPLAY_FLIP fails to change tiling */
9790 } else if (IS_IVYBRIDGE(dev
)) {
9791 ring
= &dev_priv
->ring
[BCS
];
9792 } else if (INTEL_INFO(dev
)->gen
>= 7) {
9794 if (ring
== NULL
|| ring
->id
!= RCS
)
9795 ring
= &dev_priv
->ring
[BCS
];
9797 ring
= &dev_priv
->ring
[RCS
];
9800 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
9802 goto cleanup_pending
;
9805 i915_gem_obj_ggtt_offset(obj
) + intel_crtc
->dspaddr_offset
;
9807 if (use_mmio_flip(ring
, obj
))
9808 ret
= intel_queue_mmio_flip(dev
, crtc
, fb
, obj
, ring
,
9811 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
, ring
,
9816 i915_gem_track_fb(work
->old_fb_obj
, obj
,
9817 INTEL_FRONTBUFFER_PRIMARY(pipe
));
9819 intel_disable_fbc(dev
);
9820 intel_frontbuffer_flip_prepare(dev
, INTEL_FRONTBUFFER_PRIMARY(pipe
));
9821 mutex_unlock(&dev
->struct_mutex
);
9823 trace_i915_flip_request(intel_crtc
->plane
, obj
);
9828 intel_unpin_fb_obj(obj
);
9830 atomic_dec(&intel_crtc
->unpin_work_count
);
9831 crtc
->primary
->fb
= old_fb
;
9832 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
9833 drm_gem_object_unreference(&obj
->base
);
9834 mutex_unlock(&dev
->struct_mutex
);
9837 spin_lock_irqsave(&dev
->event_lock
, flags
);
9838 intel_crtc
->unpin_work
= NULL
;
9839 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
9841 drm_crtc_vblank_put(crtc
);
9847 intel_crtc_wait_for_pending_flips(crtc
);
9848 ret
= intel_pipe_set_base(crtc
, crtc
->x
, crtc
->y
, fb
);
9849 if (ret
== 0 && event
)
9850 drm_send_vblank_event(dev
, pipe
, event
);
9855 static struct drm_crtc_helper_funcs intel_helper_funcs
= {
9856 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
9857 .load_lut
= intel_crtc_load_lut
,
9861 * intel_modeset_update_staged_output_state
9863 * Updates the staged output configuration state, e.g. after we've read out the
9866 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
9868 struct intel_crtc
*crtc
;
9869 struct intel_encoder
*encoder
;
9870 struct intel_connector
*connector
;
9872 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9874 connector
->new_encoder
=
9875 to_intel_encoder(connector
->base
.encoder
);
9878 for_each_intel_encoder(dev
, encoder
) {
9880 to_intel_crtc(encoder
->base
.crtc
);
9883 for_each_intel_crtc(dev
, crtc
) {
9884 crtc
->new_enabled
= crtc
->base
.enabled
;
9886 if (crtc
->new_enabled
)
9887 crtc
->new_config
= &crtc
->config
;
9889 crtc
->new_config
= NULL
;
9894 * intel_modeset_commit_output_state
9896 * This function copies the stage display pipe configuration to the real one.
9898 static void intel_modeset_commit_output_state(struct drm_device
*dev
)
9900 struct intel_crtc
*crtc
;
9901 struct intel_encoder
*encoder
;
9902 struct intel_connector
*connector
;
9904 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9906 connector
->base
.encoder
= &connector
->new_encoder
->base
;
9909 for_each_intel_encoder(dev
, encoder
) {
9910 encoder
->base
.crtc
= &encoder
->new_crtc
->base
;
9913 for_each_intel_crtc(dev
, crtc
) {
9914 crtc
->base
.enabled
= crtc
->new_enabled
;
9919 connected_sink_compute_bpp(struct intel_connector
*connector
,
9920 struct intel_crtc_config
*pipe_config
)
9922 int bpp
= pipe_config
->pipe_bpp
;
9924 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
9925 connector
->base
.base
.id
,
9926 connector
->base
.name
);
9928 /* Don't use an invalid EDID bpc value */
9929 if (connector
->base
.display_info
.bpc
&&
9930 connector
->base
.display_info
.bpc
* 3 < bpp
) {
9931 DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
9932 bpp
, connector
->base
.display_info
.bpc
*3);
9933 pipe_config
->pipe_bpp
= connector
->base
.display_info
.bpc
*3;
9936 /* Clamp bpp to 8 on screens without EDID 1.4 */
9937 if (connector
->base
.display_info
.bpc
== 0 && bpp
> 24) {
9938 DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
9940 pipe_config
->pipe_bpp
= 24;
9945 compute_baseline_pipe_bpp(struct intel_crtc
*crtc
,
9946 struct drm_framebuffer
*fb
,
9947 struct intel_crtc_config
*pipe_config
)
9949 struct drm_device
*dev
= crtc
->base
.dev
;
9950 struct intel_connector
*connector
;
9953 switch (fb
->pixel_format
) {
9955 bpp
= 8*3; /* since we go through a colormap */
9957 case DRM_FORMAT_XRGB1555
:
9958 case DRM_FORMAT_ARGB1555
:
9959 /* checked in intel_framebuffer_init already */
9960 if (WARN_ON(INTEL_INFO(dev
)->gen
> 3))
9962 case DRM_FORMAT_RGB565
:
9963 bpp
= 6*3; /* min is 18bpp */
9965 case DRM_FORMAT_XBGR8888
:
9966 case DRM_FORMAT_ABGR8888
:
9967 /* checked in intel_framebuffer_init already */
9968 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
9970 case DRM_FORMAT_XRGB8888
:
9971 case DRM_FORMAT_ARGB8888
:
9974 case DRM_FORMAT_XRGB2101010
:
9975 case DRM_FORMAT_ARGB2101010
:
9976 case DRM_FORMAT_XBGR2101010
:
9977 case DRM_FORMAT_ABGR2101010
:
9978 /* checked in intel_framebuffer_init already */
9979 if (WARN_ON(INTEL_INFO(dev
)->gen
< 4))
9983 /* TODO: gen4+ supports 16 bpc floating point, too. */
9985 DRM_DEBUG_KMS("unsupported depth\n");
9989 pipe_config
->pipe_bpp
= bpp
;
9991 /* Clamp display bpp to EDID value */
9992 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9994 if (!connector
->new_encoder
||
9995 connector
->new_encoder
->new_crtc
!= crtc
)
9998 connected_sink_compute_bpp(connector
, pipe_config
);
10004 static void intel_dump_crtc_timings(const struct drm_display_mode
*mode
)
10006 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
10007 "type: 0x%x flags: 0x%x\n",
10009 mode
->crtc_hdisplay
, mode
->crtc_hsync_start
,
10010 mode
->crtc_hsync_end
, mode
->crtc_htotal
,
10011 mode
->crtc_vdisplay
, mode
->crtc_vsync_start
,
10012 mode
->crtc_vsync_end
, mode
->crtc_vtotal
, mode
->type
, mode
->flags
);
10015 static void intel_dump_pipe_config(struct intel_crtc
*crtc
,
10016 struct intel_crtc_config
*pipe_config
,
10017 const char *context
)
10019 DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc
->base
.base
.id
,
10020 context
, pipe_name(crtc
->pipe
));
10022 DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config
->cpu_transcoder
));
10023 DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
10024 pipe_config
->pipe_bpp
, pipe_config
->dither
);
10025 DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10026 pipe_config
->has_pch_encoder
,
10027 pipe_config
->fdi_lanes
,
10028 pipe_config
->fdi_m_n
.gmch_m
, pipe_config
->fdi_m_n
.gmch_n
,
10029 pipe_config
->fdi_m_n
.link_m
, pipe_config
->fdi_m_n
.link_n
,
10030 pipe_config
->fdi_m_n
.tu
);
10031 DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10032 pipe_config
->has_dp_encoder
,
10033 pipe_config
->dp_m_n
.gmch_m
, pipe_config
->dp_m_n
.gmch_n
,
10034 pipe_config
->dp_m_n
.link_m
, pipe_config
->dp_m_n
.link_n
,
10035 pipe_config
->dp_m_n
.tu
);
10037 DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
10038 pipe_config
->has_dp_encoder
,
10039 pipe_config
->dp_m2_n2
.gmch_m
,
10040 pipe_config
->dp_m2_n2
.gmch_n
,
10041 pipe_config
->dp_m2_n2
.link_m
,
10042 pipe_config
->dp_m2_n2
.link_n
,
10043 pipe_config
->dp_m2_n2
.tu
);
10045 DRM_DEBUG_KMS("requested mode:\n");
10046 drm_mode_debug_printmodeline(&pipe_config
->requested_mode
);
10047 DRM_DEBUG_KMS("adjusted mode:\n");
10048 drm_mode_debug_printmodeline(&pipe_config
->adjusted_mode
);
10049 intel_dump_crtc_timings(&pipe_config
->adjusted_mode
);
10050 DRM_DEBUG_KMS("port clock: %d\n", pipe_config
->port_clock
);
10051 DRM_DEBUG_KMS("pipe src size: %dx%d\n",
10052 pipe_config
->pipe_src_w
, pipe_config
->pipe_src_h
);
10053 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10054 pipe_config
->gmch_pfit
.control
,
10055 pipe_config
->gmch_pfit
.pgm_ratios
,
10056 pipe_config
->gmch_pfit
.lvds_border_bits
);
10057 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
10058 pipe_config
->pch_pfit
.pos
,
10059 pipe_config
->pch_pfit
.size
,
10060 pipe_config
->pch_pfit
.enabled
? "enabled" : "disabled");
10061 DRM_DEBUG_KMS("ips: %i\n", pipe_config
->ips_enabled
);
10062 DRM_DEBUG_KMS("double wide: %i\n", pipe_config
->double_wide
);
10065 static bool encoders_cloneable(const struct intel_encoder
*a
,
10066 const struct intel_encoder
*b
)
10068 /* masks could be asymmetric, so check both ways */
10069 return a
== b
|| (a
->cloneable
& (1 << b
->type
) &&
10070 b
->cloneable
& (1 << a
->type
));
10073 static bool check_single_encoder_cloning(struct intel_crtc
*crtc
,
10074 struct intel_encoder
*encoder
)
10076 struct drm_device
*dev
= crtc
->base
.dev
;
10077 struct intel_encoder
*source_encoder
;
10079 for_each_intel_encoder(dev
, source_encoder
) {
10080 if (source_encoder
->new_crtc
!= crtc
)
10083 if (!encoders_cloneable(encoder
, source_encoder
))
10090 static bool check_encoder_cloning(struct intel_crtc
*crtc
)
10092 struct drm_device
*dev
= crtc
->base
.dev
;
10093 struct intel_encoder
*encoder
;
10095 for_each_intel_encoder(dev
, encoder
) {
10096 if (encoder
->new_crtc
!= crtc
)
10099 if (!check_single_encoder_cloning(crtc
, encoder
))
10106 static struct intel_crtc_config
*
10107 intel_modeset_pipe_config(struct drm_crtc
*crtc
,
10108 struct drm_framebuffer
*fb
,
10109 struct drm_display_mode
*mode
)
10111 struct drm_device
*dev
= crtc
->dev
;
10112 struct intel_encoder
*encoder
;
10113 struct intel_crtc_config
*pipe_config
;
10114 int plane_bpp
, ret
= -EINVAL
;
10117 if (!check_encoder_cloning(to_intel_crtc(crtc
))) {
10118 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
10119 return ERR_PTR(-EINVAL
);
10122 pipe_config
= kzalloc(sizeof(*pipe_config
), GFP_KERNEL
);
10124 return ERR_PTR(-ENOMEM
);
10126 drm_mode_copy(&pipe_config
->adjusted_mode
, mode
);
10127 drm_mode_copy(&pipe_config
->requested_mode
, mode
);
10129 pipe_config
->cpu_transcoder
=
10130 (enum transcoder
) to_intel_crtc(crtc
)->pipe
;
10131 pipe_config
->shared_dpll
= DPLL_ID_PRIVATE
;
10134 * Sanitize sync polarity flags based on requested ones. If neither
10135 * positive or negative polarity is requested, treat this as meaning
10136 * negative polarity.
10138 if (!(pipe_config
->adjusted_mode
.flags
&
10139 (DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NHSYNC
)))
10140 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NHSYNC
;
10142 if (!(pipe_config
->adjusted_mode
.flags
&
10143 (DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_NVSYNC
)))
10144 pipe_config
->adjusted_mode
.flags
|= DRM_MODE_FLAG_NVSYNC
;
10146 /* Compute a starting value for pipe_config->pipe_bpp taking the source
10147 * plane pixel format and any sink constraints into account. Returns the
10148 * source plane bpp so that dithering can be selected on mismatches
10149 * after encoders and crtc also have had their say. */
10150 plane_bpp
= compute_baseline_pipe_bpp(to_intel_crtc(crtc
),
10156 * Determine the real pipe dimensions. Note that stereo modes can
10157 * increase the actual pipe size due to the frame doubling and
10158 * insertion of additional space for blanks between the frame. This
10159 * is stored in the crtc timings. We use the requested mode to do this
10160 * computation to clearly distinguish it from the adjusted mode, which
10161 * can be changed by the connectors in the below retry loop.
10163 drm_mode_set_crtcinfo(&pipe_config
->requested_mode
, CRTC_STEREO_DOUBLE
);
10164 pipe_config
->pipe_src_w
= pipe_config
->requested_mode
.crtc_hdisplay
;
10165 pipe_config
->pipe_src_h
= pipe_config
->requested_mode
.crtc_vdisplay
;
10168 /* Ensure the port clock defaults are reset when retrying. */
10169 pipe_config
->port_clock
= 0;
10170 pipe_config
->pixel_multiplier
= 1;
10172 /* Fill in default crtc timings, allow encoders to overwrite them. */
10173 drm_mode_set_crtcinfo(&pipe_config
->adjusted_mode
, CRTC_STEREO_DOUBLE
);
10175 /* Pass our mode to the connectors and the CRTC to give them a chance to
10176 * adjust it according to limitations or connector properties, and also
10177 * a chance to reject the mode entirely.
10179 for_each_intel_encoder(dev
, encoder
) {
10181 if (&encoder
->new_crtc
->base
!= crtc
)
10184 if (!(encoder
->compute_config(encoder
, pipe_config
))) {
10185 DRM_DEBUG_KMS("Encoder config failure\n");
10190 /* Set default port clock if not overwritten by the encoder. Needs to be
10191 * done afterwards in case the encoder adjusts the mode. */
10192 if (!pipe_config
->port_clock
)
10193 pipe_config
->port_clock
= pipe_config
->adjusted_mode
.crtc_clock
10194 * pipe_config
->pixel_multiplier
;
10196 ret
= intel_crtc_compute_config(to_intel_crtc(crtc
), pipe_config
);
10198 DRM_DEBUG_KMS("CRTC fixup failed\n");
10202 if (ret
== RETRY
) {
10203 if (WARN(!retry
, "loop in pipe configuration computation\n")) {
10208 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
10210 goto encoder_retry
;
10213 pipe_config
->dither
= pipe_config
->pipe_bpp
!= plane_bpp
;
10214 DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
10215 plane_bpp
, pipe_config
->pipe_bpp
, pipe_config
->dither
);
10217 return pipe_config
;
10219 kfree(pipe_config
);
10220 return ERR_PTR(ret
);
10223 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
10224 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
10226 intel_modeset_affected_pipes(struct drm_crtc
*crtc
, unsigned *modeset_pipes
,
10227 unsigned *prepare_pipes
, unsigned *disable_pipes
)
10229 struct intel_crtc
*intel_crtc
;
10230 struct drm_device
*dev
= crtc
->dev
;
10231 struct intel_encoder
*encoder
;
10232 struct intel_connector
*connector
;
10233 struct drm_crtc
*tmp_crtc
;
10235 *disable_pipes
= *modeset_pipes
= *prepare_pipes
= 0;
10237 /* Check which crtcs have changed outputs connected to them, these need
10238 * to be part of the prepare_pipes mask. We don't (yet) support global
10239 * modeset across multiple crtcs, so modeset_pipes will only have one
10240 * bit set at most. */
10241 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10243 if (connector
->base
.encoder
== &connector
->new_encoder
->base
)
10246 if (connector
->base
.encoder
) {
10247 tmp_crtc
= connector
->base
.encoder
->crtc
;
10249 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
10252 if (connector
->new_encoder
)
10254 1 << connector
->new_encoder
->new_crtc
->pipe
;
10257 for_each_intel_encoder(dev
, encoder
) {
10258 if (encoder
->base
.crtc
== &encoder
->new_crtc
->base
)
10261 if (encoder
->base
.crtc
) {
10262 tmp_crtc
= encoder
->base
.crtc
;
10264 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
10267 if (encoder
->new_crtc
)
10268 *prepare_pipes
|= 1 << encoder
->new_crtc
->pipe
;
10271 /* Check for pipes that will be enabled/disabled ... */
10272 for_each_intel_crtc(dev
, intel_crtc
) {
10273 if (intel_crtc
->base
.enabled
== intel_crtc
->new_enabled
)
10276 if (!intel_crtc
->new_enabled
)
10277 *disable_pipes
|= 1 << intel_crtc
->pipe
;
10279 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
10283 /* set_mode is also used to update properties on life display pipes. */
10284 intel_crtc
= to_intel_crtc(crtc
);
10285 if (intel_crtc
->new_enabled
)
10286 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
10289 * For simplicity do a full modeset on any pipe where the output routing
10290 * changed. We could be more clever, but that would require us to be
10291 * more careful with calling the relevant encoder->mode_set functions.
10293 if (*prepare_pipes
)
10294 *modeset_pipes
= *prepare_pipes
;
10296 /* ... and mask these out. */
10297 *modeset_pipes
&= ~(*disable_pipes
);
10298 *prepare_pipes
&= ~(*disable_pipes
);
10301 * HACK: We don't (yet) fully support global modesets. intel_set_config
10302 * obies this rule, but the modeset restore mode of
10303 * intel_modeset_setup_hw_state does not.
10305 *modeset_pipes
&= 1 << intel_crtc
->pipe
;
10306 *prepare_pipes
&= 1 << intel_crtc
->pipe
;
10308 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
10309 *modeset_pipes
, *prepare_pipes
, *disable_pipes
);
10312 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
10314 struct drm_encoder
*encoder
;
10315 struct drm_device
*dev
= crtc
->dev
;
10317 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
10318 if (encoder
->crtc
== crtc
)
10325 intel_modeset_update_state(struct drm_device
*dev
, unsigned prepare_pipes
)
10327 struct intel_encoder
*intel_encoder
;
10328 struct intel_crtc
*intel_crtc
;
10329 struct drm_connector
*connector
;
10331 for_each_intel_encoder(dev
, intel_encoder
) {
10332 if (!intel_encoder
->base
.crtc
)
10335 intel_crtc
= to_intel_crtc(intel_encoder
->base
.crtc
);
10337 if (prepare_pipes
& (1 << intel_crtc
->pipe
))
10338 intel_encoder
->connectors_active
= false;
10341 intel_modeset_commit_output_state(dev
);
10343 /* Double check state. */
10344 for_each_intel_crtc(dev
, intel_crtc
) {
10345 WARN_ON(intel_crtc
->base
.enabled
!= intel_crtc_in_use(&intel_crtc
->base
));
10346 WARN_ON(intel_crtc
->new_config
&&
10347 intel_crtc
->new_config
!= &intel_crtc
->config
);
10348 WARN_ON(intel_crtc
->base
.enabled
!= !!intel_crtc
->new_config
);
10351 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
10352 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
10355 intel_crtc
= to_intel_crtc(connector
->encoder
->crtc
);
10357 if (prepare_pipes
& (1 << intel_crtc
->pipe
)) {
10358 struct drm_property
*dpms_property
=
10359 dev
->mode_config
.dpms_property
;
10361 connector
->dpms
= DRM_MODE_DPMS_ON
;
10362 drm_object_property_set_value(&connector
->base
,
10366 intel_encoder
= to_intel_encoder(connector
->encoder
);
10367 intel_encoder
->connectors_active
= true;
10373 static bool intel_fuzzy_clock_check(int clock1
, int clock2
)
10377 if (clock1
== clock2
)
10380 if (!clock1
|| !clock2
)
10383 diff
= abs(clock1
- clock2
);
10385 if (((((diff
+ clock1
+ clock2
) * 100)) / (clock1
+ clock2
)) < 105)
10391 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
10392 list_for_each_entry((intel_crtc), \
10393 &(dev)->mode_config.crtc_list, \
10395 if (mask & (1 <<(intel_crtc)->pipe))
10398 intel_pipe_config_compare(struct drm_device
*dev
,
10399 struct intel_crtc_config
*current_config
,
10400 struct intel_crtc_config
*pipe_config
)
10402 #define PIPE_CONF_CHECK_X(name) \
10403 if (current_config->name != pipe_config->name) { \
10404 DRM_ERROR("mismatch in " #name " " \
10405 "(expected 0x%08x, found 0x%08x)\n", \
10406 current_config->name, \
10407 pipe_config->name); \
10411 #define PIPE_CONF_CHECK_I(name) \
10412 if (current_config->name != pipe_config->name) { \
10413 DRM_ERROR("mismatch in " #name " " \
10414 "(expected %i, found %i)\n", \
10415 current_config->name, \
10416 pipe_config->name); \
10420 /* This is required for BDW+ where there is only one set of registers for
10421 * switching between high and low RR.
10422 * This macro can be used whenever a comparison has to be made between one
10423 * hw state and multiple sw state variables.
10425 #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
10426 if ((current_config->name != pipe_config->name) && \
10427 (current_config->alt_name != pipe_config->name)) { \
10428 DRM_ERROR("mismatch in " #name " " \
10429 "(expected %i or %i, found %i)\n", \
10430 current_config->name, \
10431 current_config->alt_name, \
10432 pipe_config->name); \
10436 #define PIPE_CONF_CHECK_FLAGS(name, mask) \
10437 if ((current_config->name ^ pipe_config->name) & (mask)) { \
10438 DRM_ERROR("mismatch in " #name "(" #mask ") " \
10439 "(expected %i, found %i)\n", \
10440 current_config->name & (mask), \
10441 pipe_config->name & (mask)); \
10445 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
10446 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
10447 DRM_ERROR("mismatch in " #name " " \
10448 "(expected %i, found %i)\n", \
10449 current_config->name, \
10450 pipe_config->name); \
10454 #define PIPE_CONF_QUIRK(quirk) \
10455 ((current_config->quirks | pipe_config->quirks) & (quirk))
10457 PIPE_CONF_CHECK_I(cpu_transcoder
);
10459 PIPE_CONF_CHECK_I(has_pch_encoder
);
10460 PIPE_CONF_CHECK_I(fdi_lanes
);
10461 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_m
);
10462 PIPE_CONF_CHECK_I(fdi_m_n
.gmch_n
);
10463 PIPE_CONF_CHECK_I(fdi_m_n
.link_m
);
10464 PIPE_CONF_CHECK_I(fdi_m_n
.link_n
);
10465 PIPE_CONF_CHECK_I(fdi_m_n
.tu
);
10467 PIPE_CONF_CHECK_I(has_dp_encoder
);
10469 if (INTEL_INFO(dev
)->gen
< 8) {
10470 PIPE_CONF_CHECK_I(dp_m_n
.gmch_m
);
10471 PIPE_CONF_CHECK_I(dp_m_n
.gmch_n
);
10472 PIPE_CONF_CHECK_I(dp_m_n
.link_m
);
10473 PIPE_CONF_CHECK_I(dp_m_n
.link_n
);
10474 PIPE_CONF_CHECK_I(dp_m_n
.tu
);
10476 if (current_config
->has_drrs
) {
10477 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_m
);
10478 PIPE_CONF_CHECK_I(dp_m2_n2
.gmch_n
);
10479 PIPE_CONF_CHECK_I(dp_m2_n2
.link_m
);
10480 PIPE_CONF_CHECK_I(dp_m2_n2
.link_n
);
10481 PIPE_CONF_CHECK_I(dp_m2_n2
.tu
);
10484 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_m
, dp_m2_n2
.gmch_m
);
10485 PIPE_CONF_CHECK_I_ALT(dp_m_n
.gmch_n
, dp_m2_n2
.gmch_n
);
10486 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_m
, dp_m2_n2
.link_m
);
10487 PIPE_CONF_CHECK_I_ALT(dp_m_n
.link_n
, dp_m2_n2
.link_n
);
10488 PIPE_CONF_CHECK_I_ALT(dp_m_n
.tu
, dp_m2_n2
.tu
);
10491 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hdisplay
);
10492 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_htotal
);
10493 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_start
);
10494 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hblank_end
);
10495 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_start
);
10496 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_hsync_end
);
10498 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vdisplay
);
10499 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vtotal
);
10500 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_start
);
10501 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vblank_end
);
10502 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_start
);
10503 PIPE_CONF_CHECK_I(adjusted_mode
.crtc_vsync_end
);
10505 PIPE_CONF_CHECK_I(pixel_multiplier
);
10506 PIPE_CONF_CHECK_I(has_hdmi_sink
);
10507 if ((INTEL_INFO(dev
)->gen
< 8 && !IS_HASWELL(dev
)) ||
10508 IS_VALLEYVIEW(dev
))
10509 PIPE_CONF_CHECK_I(limited_color_range
);
10511 PIPE_CONF_CHECK_I(has_audio
);
10513 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10514 DRM_MODE_FLAG_INTERLACE
);
10516 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS
)) {
10517 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10518 DRM_MODE_FLAG_PHSYNC
);
10519 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10520 DRM_MODE_FLAG_NHSYNC
);
10521 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10522 DRM_MODE_FLAG_PVSYNC
);
10523 PIPE_CONF_CHECK_FLAGS(adjusted_mode
.flags
,
10524 DRM_MODE_FLAG_NVSYNC
);
10527 PIPE_CONF_CHECK_I(pipe_src_w
);
10528 PIPE_CONF_CHECK_I(pipe_src_h
);
10531 * FIXME: BIOS likes to set up a cloned config with lvds+external
10532 * screen. Since we don't yet re-compute the pipe config when moving
10533 * just the lvds port away to another pipe the sw tracking won't match.
10535 * Proper atomic modesets with recomputed global state will fix this.
10536 * Until then just don't check gmch state for inherited modes.
10538 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE
)) {
10539 PIPE_CONF_CHECK_I(gmch_pfit
.control
);
10540 /* pfit ratios are autocomputed by the hw on gen4+ */
10541 if (INTEL_INFO(dev
)->gen
< 4)
10542 PIPE_CONF_CHECK_I(gmch_pfit
.pgm_ratios
);
10543 PIPE_CONF_CHECK_I(gmch_pfit
.lvds_border_bits
);
10546 PIPE_CONF_CHECK_I(pch_pfit
.enabled
);
10547 if (current_config
->pch_pfit
.enabled
) {
10548 PIPE_CONF_CHECK_I(pch_pfit
.pos
);
10549 PIPE_CONF_CHECK_I(pch_pfit
.size
);
10552 /* BDW+ don't expose a synchronous way to read the state */
10553 if (IS_HASWELL(dev
))
10554 PIPE_CONF_CHECK_I(ips_enabled
);
10556 PIPE_CONF_CHECK_I(double_wide
);
10558 PIPE_CONF_CHECK_X(ddi_pll_sel
);
10560 PIPE_CONF_CHECK_I(shared_dpll
);
10561 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll
);
10562 PIPE_CONF_CHECK_X(dpll_hw_state
.dpll_md
);
10563 PIPE_CONF_CHECK_X(dpll_hw_state
.fp0
);
10564 PIPE_CONF_CHECK_X(dpll_hw_state
.fp1
);
10565 PIPE_CONF_CHECK_X(dpll_hw_state
.wrpll
);
10567 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5)
10568 PIPE_CONF_CHECK_I(pipe_bpp
);
10570 PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode
.crtc_clock
);
10571 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock
);
10573 #undef PIPE_CONF_CHECK_X
10574 #undef PIPE_CONF_CHECK_I
10575 #undef PIPE_CONF_CHECK_I_ALT
10576 #undef PIPE_CONF_CHECK_FLAGS
10577 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
10578 #undef PIPE_CONF_QUIRK
10584 check_connector_state(struct drm_device
*dev
)
10586 struct intel_connector
*connector
;
10588 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10590 /* This also checks the encoder/connector hw state with the
10591 * ->get_hw_state callbacks. */
10592 intel_connector_check_state(connector
);
10594 WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
10595 "connector's staged encoder doesn't match current encoder\n");
10600 check_encoder_state(struct drm_device
*dev
)
10602 struct intel_encoder
*encoder
;
10603 struct intel_connector
*connector
;
10605 for_each_intel_encoder(dev
, encoder
) {
10606 bool enabled
= false;
10607 bool active
= false;
10608 enum pipe pipe
, tracked_pipe
;
10610 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
10611 encoder
->base
.base
.id
,
10612 encoder
->base
.name
);
10614 WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
10615 "encoder's stage crtc doesn't match current crtc\n");
10616 WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
10617 "encoder's active_connectors set, but no crtc\n");
10619 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
10621 if (connector
->base
.encoder
!= &encoder
->base
)
10624 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
10628 * for MST connectors if we unplug the connector is gone
10629 * away but the encoder is still connected to a crtc
10630 * until a modeset happens in response to the hotplug.
10632 if (!enabled
&& encoder
->base
.encoder_type
== DRM_MODE_ENCODER_DPMST
)
10635 WARN(!!encoder
->base
.crtc
!= enabled
,
10636 "encoder's enabled state mismatch "
10637 "(expected %i, found %i)\n",
10638 !!encoder
->base
.crtc
, enabled
);
10639 WARN(active
&& !encoder
->base
.crtc
,
10640 "active encoder with no crtc\n");
10642 WARN(encoder
->connectors_active
!= active
,
10643 "encoder's computed active state doesn't match tracked active state "
10644 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
10646 active
= encoder
->get_hw_state(encoder
, &pipe
);
10647 WARN(active
!= encoder
->connectors_active
,
10648 "encoder's hw state doesn't match sw tracking "
10649 "(expected %i, found %i)\n",
10650 encoder
->connectors_active
, active
);
10652 if (!encoder
->base
.crtc
)
10655 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
10656 WARN(active
&& pipe
!= tracked_pipe
,
10657 "active encoder's pipe doesn't match"
10658 "(expected %i, found %i)\n",
10659 tracked_pipe
, pipe
);
10665 check_crtc_state(struct drm_device
*dev
)
10667 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10668 struct intel_crtc
*crtc
;
10669 struct intel_encoder
*encoder
;
10670 struct intel_crtc_config pipe_config
;
10672 for_each_intel_crtc(dev
, crtc
) {
10673 bool enabled
= false;
10674 bool active
= false;
10676 memset(&pipe_config
, 0, sizeof(pipe_config
));
10678 DRM_DEBUG_KMS("[CRTC:%d]\n",
10679 crtc
->base
.base
.id
);
10681 WARN(crtc
->active
&& !crtc
->base
.enabled
,
10682 "active crtc, but not enabled in sw tracking\n");
10684 for_each_intel_encoder(dev
, encoder
) {
10685 if (encoder
->base
.crtc
!= &crtc
->base
)
10688 if (encoder
->connectors_active
)
10692 WARN(active
!= crtc
->active
,
10693 "crtc's computed active state doesn't match tracked active state "
10694 "(expected %i, found %i)\n", active
, crtc
->active
);
10695 WARN(enabled
!= crtc
->base
.enabled
,
10696 "crtc's computed enabled state doesn't match tracked enabled state "
10697 "(expected %i, found %i)\n", enabled
, crtc
->base
.enabled
);
10699 active
= dev_priv
->display
.get_pipe_config(crtc
,
10702 /* hw state is inconsistent with the pipe A quirk */
10703 if (crtc
->pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
)
10704 active
= crtc
->active
;
10706 for_each_intel_encoder(dev
, encoder
) {
10708 if (encoder
->base
.crtc
!= &crtc
->base
)
10710 if (encoder
->get_hw_state(encoder
, &pipe
))
10711 encoder
->get_config(encoder
, &pipe_config
);
10714 WARN(crtc
->active
!= active
,
10715 "crtc active state doesn't match with hw state "
10716 "(expected %i, found %i)\n", crtc
->active
, active
);
10719 !intel_pipe_config_compare(dev
, &crtc
->config
, &pipe_config
)) {
10720 WARN(1, "pipe state doesn't match!\n");
10721 intel_dump_pipe_config(crtc
, &pipe_config
,
10723 intel_dump_pipe_config(crtc
, &crtc
->config
,
10730 check_shared_dpll_state(struct drm_device
*dev
)
10732 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10733 struct intel_crtc
*crtc
;
10734 struct intel_dpll_hw_state dpll_hw_state
;
10737 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
10738 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
10739 int enabled_crtcs
= 0, active_crtcs
= 0;
10742 memset(&dpll_hw_state
, 0, sizeof(dpll_hw_state
));
10744 DRM_DEBUG_KMS("%s\n", pll
->name
);
10746 active
= pll
->get_hw_state(dev_priv
, pll
, &dpll_hw_state
);
10748 WARN(pll
->active
> pll
->refcount
,
10749 "more active pll users than references: %i vs %i\n",
10750 pll
->active
, pll
->refcount
);
10751 WARN(pll
->active
&& !pll
->on
,
10752 "pll in active use but not on in sw tracking\n");
10753 WARN(pll
->on
&& !pll
->active
,
10754 "pll in on but not on in use in sw tracking\n");
10755 WARN(pll
->on
!= active
,
10756 "pll on state mismatch (expected %i, found %i)\n",
10759 for_each_intel_crtc(dev
, crtc
) {
10760 if (crtc
->base
.enabled
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10762 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
10765 WARN(pll
->active
!= active_crtcs
,
10766 "pll active crtcs mismatch (expected %i, found %i)\n",
10767 pll
->active
, active_crtcs
);
10768 WARN(pll
->refcount
!= enabled_crtcs
,
10769 "pll enabled crtcs mismatch (expected %i, found %i)\n",
10770 pll
->refcount
, enabled_crtcs
);
10772 WARN(pll
->on
&& memcmp(&pll
->hw_state
, &dpll_hw_state
,
10773 sizeof(dpll_hw_state
)),
10774 "pll hw state mismatch\n");
10779 intel_modeset_check_state(struct drm_device
*dev
)
10781 check_connector_state(dev
);
10782 check_encoder_state(dev
);
10783 check_crtc_state(dev
);
10784 check_shared_dpll_state(dev
);
10787 void ironlake_check_encoder_dotclock(const struct intel_crtc_config
*pipe_config
,
10791 * FDI already provided one idea for the dotclock.
10792 * Yell if the encoder disagrees.
10794 WARN(!intel_fuzzy_clock_check(pipe_config
->adjusted_mode
.crtc_clock
, dotclock
),
10795 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
10796 pipe_config
->adjusted_mode
.crtc_clock
, dotclock
);
10799 static void update_scanline_offset(struct intel_crtc
*crtc
)
10801 struct drm_device
*dev
= crtc
->base
.dev
;
10804 * The scanline counter increments at the leading edge of hsync.
10806 * On most platforms it starts counting from vtotal-1 on the
10807 * first active line. That means the scanline counter value is
10808 * always one less than what we would expect. Ie. just after
10809 * start of vblank, which also occurs at start of hsync (on the
10810 * last active line), the scanline counter will read vblank_start-1.
10812 * On gen2 the scanline counter starts counting from 1 instead
10813 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
10814 * to keep the value positive), instead of adding one.
10816 * On HSW+ the behaviour of the scanline counter depends on the output
10817 * type. For DP ports it behaves like most other platforms, but on HDMI
10818 * there's an extra 1 line difference. So we need to add two instead of
10819 * one to the value.
10821 if (IS_GEN2(dev
)) {
10822 const struct drm_display_mode
*mode
= &crtc
->config
.adjusted_mode
;
10825 vtotal
= mode
->crtc_vtotal
;
10826 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
10829 crtc
->scanline_offset
= vtotal
- 1;
10830 } else if (HAS_DDI(dev
) &&
10831 intel_pipe_has_type(&crtc
->base
, INTEL_OUTPUT_HDMI
)) {
10832 crtc
->scanline_offset
= 2;
10834 crtc
->scanline_offset
= 1;
10837 static int __intel_set_mode(struct drm_crtc
*crtc
,
10838 struct drm_display_mode
*mode
,
10839 int x
, int y
, struct drm_framebuffer
*fb
)
10841 struct drm_device
*dev
= crtc
->dev
;
10842 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
10843 struct drm_display_mode
*saved_mode
;
10844 struct intel_crtc_config
*pipe_config
= NULL
;
10845 struct intel_crtc
*intel_crtc
;
10846 unsigned disable_pipes
, prepare_pipes
, modeset_pipes
;
10849 saved_mode
= kmalloc(sizeof(*saved_mode
), GFP_KERNEL
);
10853 intel_modeset_affected_pipes(crtc
, &modeset_pipes
,
10854 &prepare_pipes
, &disable_pipes
);
10856 *saved_mode
= crtc
->mode
;
10858 /* Hack: Because we don't (yet) support global modeset on multiple
10859 * crtcs, we don't keep track of the new mode for more than one crtc.
10860 * Hence simply check whether any bit is set in modeset_pipes in all the
10861 * pieces of code that are not yet converted to deal with mutliple crtcs
10862 * changing their mode at the same time. */
10863 if (modeset_pipes
) {
10864 pipe_config
= intel_modeset_pipe_config(crtc
, fb
, mode
);
10865 if (IS_ERR(pipe_config
)) {
10866 ret
= PTR_ERR(pipe_config
);
10867 pipe_config
= NULL
;
10871 intel_dump_pipe_config(to_intel_crtc(crtc
), pipe_config
,
10873 to_intel_crtc(crtc
)->new_config
= pipe_config
;
10877 * See if the config requires any additional preparation, e.g.
10878 * to adjust global state with pipes off. We need to do this
10879 * here so we can get the modeset_pipe updated config for the new
10880 * mode set on this crtc. For other crtcs we need to use the
10881 * adjusted_mode bits in the crtc directly.
10883 if (IS_VALLEYVIEW(dev
)) {
10884 valleyview_modeset_global_pipes(dev
, &prepare_pipes
);
10886 /* may have added more to prepare_pipes than we should */
10887 prepare_pipes
&= ~disable_pipes
;
10890 for_each_intel_crtc_masked(dev
, disable_pipes
, intel_crtc
)
10891 intel_crtc_disable(&intel_crtc
->base
);
10893 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
10894 if (intel_crtc
->base
.enabled
)
10895 dev_priv
->display
.crtc_disable(&intel_crtc
->base
);
10898 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
10899 * to set it here already despite that we pass it down the callchain.
10901 if (modeset_pipes
) {
10902 crtc
->mode
= *mode
;
10903 /* mode_set/enable/disable functions rely on a correct pipe
10905 to_intel_crtc(crtc
)->config
= *pipe_config
;
10906 to_intel_crtc(crtc
)->new_config
= &to_intel_crtc(crtc
)->config
;
10909 * Calculate and store various constants which
10910 * are later needed by vblank and swap-completion
10911 * timestamping. They are derived from true hwmode.
10913 drm_calc_timestamping_constants(crtc
,
10914 &pipe_config
->adjusted_mode
);
10917 /* Only after disabling all output pipelines that will be changed can we
10918 * update the the output configuration. */
10919 intel_modeset_update_state(dev
, prepare_pipes
);
10921 if (dev_priv
->display
.modeset_global_resources
)
10922 dev_priv
->display
.modeset_global_resources(dev
);
10924 /* Set up the DPLL and any encoders state that needs to adjust or depend
10927 for_each_intel_crtc_masked(dev
, modeset_pipes
, intel_crtc
) {
10928 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
10929 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(old_fb
);
10930 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
10932 mutex_lock(&dev
->struct_mutex
);
10933 ret
= intel_pin_and_fence_fb_obj(dev
,
10937 DRM_ERROR("pin & fence failed\n");
10938 mutex_unlock(&dev
->struct_mutex
);
10942 intel_unpin_fb_obj(old_obj
);
10943 i915_gem_track_fb(old_obj
, obj
,
10944 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
10945 mutex_unlock(&dev
->struct_mutex
);
10947 crtc
->primary
->fb
= fb
;
10951 ret
= dev_priv
->display
.crtc_mode_set(&intel_crtc
->base
,
10957 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
10958 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
10959 update_scanline_offset(intel_crtc
);
10961 dev_priv
->display
.crtc_enable(&intel_crtc
->base
);
10964 /* FIXME: add subpixel order */
10966 if (ret
&& crtc
->enabled
)
10967 crtc
->mode
= *saved_mode
;
10970 kfree(pipe_config
);
10975 static int intel_set_mode(struct drm_crtc
*crtc
,
10976 struct drm_display_mode
*mode
,
10977 int x
, int y
, struct drm_framebuffer
*fb
)
10981 ret
= __intel_set_mode(crtc
, mode
, x
, y
, fb
);
10984 intel_modeset_check_state(crtc
->dev
);
10989 void intel_crtc_restore_mode(struct drm_crtc
*crtc
)
10991 intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
, crtc
->primary
->fb
);
10994 #undef for_each_intel_crtc_masked
10996 static void intel_set_config_free(struct intel_set_config
*config
)
11001 kfree(config
->save_connector_encoders
);
11002 kfree(config
->save_encoder_crtcs
);
11003 kfree(config
->save_crtc_enabled
);
11007 static int intel_set_config_save_state(struct drm_device
*dev
,
11008 struct intel_set_config
*config
)
11010 struct drm_crtc
*crtc
;
11011 struct drm_encoder
*encoder
;
11012 struct drm_connector
*connector
;
11015 config
->save_crtc_enabled
=
11016 kcalloc(dev
->mode_config
.num_crtc
,
11017 sizeof(bool), GFP_KERNEL
);
11018 if (!config
->save_crtc_enabled
)
11021 config
->save_encoder_crtcs
=
11022 kcalloc(dev
->mode_config
.num_encoder
,
11023 sizeof(struct drm_crtc
*), GFP_KERNEL
);
11024 if (!config
->save_encoder_crtcs
)
11027 config
->save_connector_encoders
=
11028 kcalloc(dev
->mode_config
.num_connector
,
11029 sizeof(struct drm_encoder
*), GFP_KERNEL
);
11030 if (!config
->save_connector_encoders
)
11033 /* Copy data. Note that driver private data is not affected.
11034 * Should anything bad happen only the expected state is
11035 * restored, not the drivers personal bookkeeping.
11038 for_each_crtc(dev
, crtc
) {
11039 config
->save_crtc_enabled
[count
++] = crtc
->enabled
;
11043 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
11044 config
->save_encoder_crtcs
[count
++] = encoder
->crtc
;
11048 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
11049 config
->save_connector_encoders
[count
++] = connector
->encoder
;
11055 static void intel_set_config_restore_state(struct drm_device
*dev
,
11056 struct intel_set_config
*config
)
11058 struct intel_crtc
*crtc
;
11059 struct intel_encoder
*encoder
;
11060 struct intel_connector
*connector
;
11064 for_each_intel_crtc(dev
, crtc
) {
11065 crtc
->new_enabled
= config
->save_crtc_enabled
[count
++];
11067 if (crtc
->new_enabled
)
11068 crtc
->new_config
= &crtc
->config
;
11070 crtc
->new_config
= NULL
;
11074 for_each_intel_encoder(dev
, encoder
) {
11075 encoder
->new_crtc
=
11076 to_intel_crtc(config
->save_encoder_crtcs
[count
++]);
11080 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
11081 connector
->new_encoder
=
11082 to_intel_encoder(config
->save_connector_encoders
[count
++]);
11087 is_crtc_connector_off(struct drm_mode_set
*set
)
11091 if (set
->num_connectors
== 0)
11094 if (WARN_ON(set
->connectors
== NULL
))
11097 for (i
= 0; i
< set
->num_connectors
; i
++)
11098 if (set
->connectors
[i
]->encoder
&&
11099 set
->connectors
[i
]->encoder
->crtc
== set
->crtc
&&
11100 set
->connectors
[i
]->dpms
!= DRM_MODE_DPMS_ON
)
11107 intel_set_config_compute_mode_changes(struct drm_mode_set
*set
,
11108 struct intel_set_config
*config
)
11111 /* We should be able to check here if the fb has the same properties
11112 * and then just flip_or_move it */
11113 if (is_crtc_connector_off(set
)) {
11114 config
->mode_changed
= true;
11115 } else if (set
->crtc
->primary
->fb
!= set
->fb
) {
11117 * If we have no fb, we can only flip as long as the crtc is
11118 * active, otherwise we need a full mode set. The crtc may
11119 * be active if we've only disabled the primary plane, or
11120 * in fastboot situations.
11122 if (set
->crtc
->primary
->fb
== NULL
) {
11123 struct intel_crtc
*intel_crtc
=
11124 to_intel_crtc(set
->crtc
);
11126 if (intel_crtc
->active
) {
11127 DRM_DEBUG_KMS("crtc has no fb, will flip\n");
11128 config
->fb_changed
= true;
11130 DRM_DEBUG_KMS("inactive crtc, full mode set\n");
11131 config
->mode_changed
= true;
11133 } else if (set
->fb
== NULL
) {
11134 config
->mode_changed
= true;
11135 } else if (set
->fb
->pixel_format
!=
11136 set
->crtc
->primary
->fb
->pixel_format
) {
11137 config
->mode_changed
= true;
11139 config
->fb_changed
= true;
11143 if (set
->fb
&& (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
))
11144 config
->fb_changed
= true;
11146 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
11147 DRM_DEBUG_KMS("modes are different, full mode set\n");
11148 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
11149 drm_mode_debug_printmodeline(set
->mode
);
11150 config
->mode_changed
= true;
11153 DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
11154 set
->crtc
->base
.id
, config
->mode_changed
, config
->fb_changed
);
11158 intel_modeset_stage_output_state(struct drm_device
*dev
,
11159 struct drm_mode_set
*set
,
11160 struct intel_set_config
*config
)
11162 struct intel_connector
*connector
;
11163 struct intel_encoder
*encoder
;
11164 struct intel_crtc
*crtc
;
11167 /* The upper layers ensure that we either disable a crtc or have a list
11168 * of connectors. For paranoia, double-check this. */
11169 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
11170 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
11172 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
11174 /* Otherwise traverse passed in connector list and get encoders
11176 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
11177 if (set
->connectors
[ro
] == &connector
->base
) {
11178 connector
->new_encoder
= intel_find_encoder(connector
, to_intel_crtc(set
->crtc
)->pipe
);
11183 /* If we disable the crtc, disable all its connectors. Also, if
11184 * the connector is on the changing crtc but not on the new
11185 * connector list, disable it. */
11186 if ((!set
->fb
|| ro
== set
->num_connectors
) &&
11187 connector
->base
.encoder
&&
11188 connector
->base
.encoder
->crtc
== set
->crtc
) {
11189 connector
->new_encoder
= NULL
;
11191 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
11192 connector
->base
.base
.id
,
11193 connector
->base
.name
);
11197 if (&connector
->new_encoder
->base
!= connector
->base
.encoder
) {
11198 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
11199 config
->mode_changed
= true;
11202 /* connector->new_encoder is now updated for all connectors. */
11204 /* Update crtc of enabled connectors. */
11205 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
11207 struct drm_crtc
*new_crtc
;
11209 if (!connector
->new_encoder
)
11212 new_crtc
= connector
->new_encoder
->base
.crtc
;
11214 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
11215 if (set
->connectors
[ro
] == &connector
->base
)
11216 new_crtc
= set
->crtc
;
11219 /* Make sure the new CRTC will work with the encoder */
11220 if (!drm_encoder_crtc_ok(&connector
->new_encoder
->base
,
11224 connector
->new_encoder
->new_crtc
= to_intel_crtc(new_crtc
);
11226 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
11227 connector
->base
.base
.id
,
11228 connector
->base
.name
,
11229 new_crtc
->base
.id
);
11232 /* Check for any encoders that needs to be disabled. */
11233 for_each_intel_encoder(dev
, encoder
) {
11234 int num_connectors
= 0;
11235 list_for_each_entry(connector
,
11236 &dev
->mode_config
.connector_list
,
11238 if (connector
->new_encoder
== encoder
) {
11239 WARN_ON(!connector
->new_encoder
->new_crtc
);
11244 if (num_connectors
== 0)
11245 encoder
->new_crtc
= NULL
;
11246 else if (num_connectors
> 1)
11249 /* Only now check for crtc changes so we don't miss encoders
11250 * that will be disabled. */
11251 if (&encoder
->new_crtc
->base
!= encoder
->base
.crtc
) {
11252 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
11253 config
->mode_changed
= true;
11256 /* Now we've also updated encoder->new_crtc for all encoders. */
11257 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
11259 if (connector
->new_encoder
)
11260 if (connector
->new_encoder
!= connector
->encoder
)
11261 connector
->encoder
= connector
->new_encoder
;
11263 for_each_intel_crtc(dev
, crtc
) {
11264 crtc
->new_enabled
= false;
11266 for_each_intel_encoder(dev
, encoder
) {
11267 if (encoder
->new_crtc
== crtc
) {
11268 crtc
->new_enabled
= true;
11273 if (crtc
->new_enabled
!= crtc
->base
.enabled
) {
11274 DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
11275 crtc
->new_enabled
? "en" : "dis");
11276 config
->mode_changed
= true;
11279 if (crtc
->new_enabled
)
11280 crtc
->new_config
= &crtc
->config
;
11282 crtc
->new_config
= NULL
;
11288 static void disable_crtc_nofb(struct intel_crtc
*crtc
)
11290 struct drm_device
*dev
= crtc
->base
.dev
;
11291 struct intel_encoder
*encoder
;
11292 struct intel_connector
*connector
;
11294 DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
11295 pipe_name(crtc
->pipe
));
11297 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
11298 if (connector
->new_encoder
&&
11299 connector
->new_encoder
->new_crtc
== crtc
)
11300 connector
->new_encoder
= NULL
;
11303 for_each_intel_encoder(dev
, encoder
) {
11304 if (encoder
->new_crtc
== crtc
)
11305 encoder
->new_crtc
= NULL
;
11308 crtc
->new_enabled
= false;
11309 crtc
->new_config
= NULL
;
11312 static int intel_crtc_set_config(struct drm_mode_set
*set
)
11314 struct drm_device
*dev
;
11315 struct drm_mode_set save_set
;
11316 struct intel_set_config
*config
;
11320 BUG_ON(!set
->crtc
);
11321 BUG_ON(!set
->crtc
->helper_private
);
11323 /* Enforce sane interface api - has been abused by the fb helper. */
11324 BUG_ON(!set
->mode
&& set
->fb
);
11325 BUG_ON(set
->fb
&& set
->num_connectors
== 0);
11328 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
11329 set
->crtc
->base
.id
, set
->fb
->base
.id
,
11330 (int)set
->num_connectors
, set
->x
, set
->y
);
11332 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
11335 dev
= set
->crtc
->dev
;
11338 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
11342 ret
= intel_set_config_save_state(dev
, config
);
11346 save_set
.crtc
= set
->crtc
;
11347 save_set
.mode
= &set
->crtc
->mode
;
11348 save_set
.x
= set
->crtc
->x
;
11349 save_set
.y
= set
->crtc
->y
;
11350 save_set
.fb
= set
->crtc
->primary
->fb
;
11352 /* Compute whether we need a full modeset, only an fb base update or no
11353 * change at all. In the future we might also check whether only the
11354 * mode changed, e.g. for LVDS where we only change the panel fitter in
11356 intel_set_config_compute_mode_changes(set
, config
);
11358 ret
= intel_modeset_stage_output_state(dev
, set
, config
);
11362 if (config
->mode_changed
) {
11363 ret
= intel_set_mode(set
->crtc
, set
->mode
,
11364 set
->x
, set
->y
, set
->fb
);
11365 } else if (config
->fb_changed
) {
11366 struct intel_crtc
*intel_crtc
= to_intel_crtc(set
->crtc
);
11368 intel_crtc_wait_for_pending_flips(set
->crtc
);
11370 ret
= intel_pipe_set_base(set
->crtc
,
11371 set
->x
, set
->y
, set
->fb
);
11374 * We need to make sure the primary plane is re-enabled if it
11375 * has previously been turned off.
11377 if (!intel_crtc
->primary_enabled
&& ret
== 0) {
11378 WARN_ON(!intel_crtc
->active
);
11379 intel_enable_primary_hw_plane(set
->crtc
->primary
, set
->crtc
);
11383 * In the fastboot case this may be our only check of the
11384 * state after boot. It would be better to only do it on
11385 * the first update, but we don't have a nice way of doing that
11386 * (and really, set_config isn't used much for high freq page
11387 * flipping, so increasing its cost here shouldn't be a big
11390 if (i915
.fastboot
&& ret
== 0)
11391 intel_modeset_check_state(set
->crtc
->dev
);
11395 DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
11396 set
->crtc
->base
.id
, ret
);
11398 intel_set_config_restore_state(dev
, config
);
11401 * HACK: if the pipe was on, but we didn't have a framebuffer,
11402 * force the pipe off to avoid oopsing in the modeset code
11403 * due to fb==NULL. This should only happen during boot since
11404 * we don't yet reconstruct the FB from the hardware state.
11406 if (to_intel_crtc(save_set
.crtc
)->new_enabled
&& !save_set
.fb
)
11407 disable_crtc_nofb(to_intel_crtc(save_set
.crtc
));
11409 /* Try to restore the config */
11410 if (config
->mode_changed
&&
11411 intel_set_mode(save_set
.crtc
, save_set
.mode
,
11412 save_set
.x
, save_set
.y
, save_set
.fb
))
11413 DRM_ERROR("failed to restore config after modeset failure\n");
11417 intel_set_config_free(config
);
11421 static const struct drm_crtc_funcs intel_crtc_funcs
= {
11422 .gamma_set
= intel_crtc_gamma_set
,
11423 .set_config
= intel_crtc_set_config
,
11424 .destroy
= intel_crtc_destroy
,
11425 .page_flip
= intel_crtc_page_flip
,
11428 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private
*dev_priv
,
11429 struct intel_shared_dpll
*pll
,
11430 struct intel_dpll_hw_state
*hw_state
)
11434 if (!intel_display_power_enabled(dev_priv
, POWER_DOMAIN_PLLS
))
11437 val
= I915_READ(PCH_DPLL(pll
->id
));
11438 hw_state
->dpll
= val
;
11439 hw_state
->fp0
= I915_READ(PCH_FP0(pll
->id
));
11440 hw_state
->fp1
= I915_READ(PCH_FP1(pll
->id
));
11442 return val
& DPLL_VCO_ENABLE
;
11445 static void ibx_pch_dpll_mode_set(struct drm_i915_private
*dev_priv
,
11446 struct intel_shared_dpll
*pll
)
11448 I915_WRITE(PCH_FP0(pll
->id
), pll
->hw_state
.fp0
);
11449 I915_WRITE(PCH_FP1(pll
->id
), pll
->hw_state
.fp1
);
11452 static void ibx_pch_dpll_enable(struct drm_i915_private
*dev_priv
,
11453 struct intel_shared_dpll
*pll
)
11455 /* PCH refclock must be enabled first */
11456 ibx_assert_pch_refclk_enabled(dev_priv
);
11458 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11460 /* Wait for the clocks to stabilize. */
11461 POSTING_READ(PCH_DPLL(pll
->id
));
11464 /* The pixel multiplier can only be updated once the
11465 * DPLL is enabled and the clocks are stable.
11467 * So write it again.
11469 I915_WRITE(PCH_DPLL(pll
->id
), pll
->hw_state
.dpll
);
11470 POSTING_READ(PCH_DPLL(pll
->id
));
11474 static void ibx_pch_dpll_disable(struct drm_i915_private
*dev_priv
,
11475 struct intel_shared_dpll
*pll
)
11477 struct drm_device
*dev
= dev_priv
->dev
;
11478 struct intel_crtc
*crtc
;
11480 /* Make sure no transcoder isn't still depending on us. */
11481 for_each_intel_crtc(dev
, crtc
) {
11482 if (intel_crtc_to_shared_dpll(crtc
) == pll
)
11483 assert_pch_transcoder_disabled(dev_priv
, crtc
->pipe
);
11486 I915_WRITE(PCH_DPLL(pll
->id
), 0);
11487 POSTING_READ(PCH_DPLL(pll
->id
));
11491 static char *ibx_pch_dpll_names
[] = {
11496 static void ibx_pch_dpll_init(struct drm_device
*dev
)
11498 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11501 dev_priv
->num_shared_dpll
= 2;
11503 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
11504 dev_priv
->shared_dplls
[i
].id
= i
;
11505 dev_priv
->shared_dplls
[i
].name
= ibx_pch_dpll_names
[i
];
11506 dev_priv
->shared_dplls
[i
].mode_set
= ibx_pch_dpll_mode_set
;
11507 dev_priv
->shared_dplls
[i
].enable
= ibx_pch_dpll_enable
;
11508 dev_priv
->shared_dplls
[i
].disable
= ibx_pch_dpll_disable
;
11509 dev_priv
->shared_dplls
[i
].get_hw_state
=
11510 ibx_pch_dpll_get_hw_state
;
11514 static void intel_shared_dpll_init(struct drm_device
*dev
)
11516 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11519 intel_ddi_pll_init(dev
);
11520 else if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
11521 ibx_pch_dpll_init(dev
);
11523 dev_priv
->num_shared_dpll
= 0;
11525 BUG_ON(dev_priv
->num_shared_dpll
> I915_NUM_PLLS
);
11529 intel_primary_plane_disable(struct drm_plane
*plane
)
11531 struct drm_device
*dev
= plane
->dev
;
11532 struct intel_crtc
*intel_crtc
;
11537 BUG_ON(!plane
->crtc
);
11539 intel_crtc
= to_intel_crtc(plane
->crtc
);
11542 * Even though we checked plane->fb above, it's still possible that
11543 * the primary plane has been implicitly disabled because the crtc
11544 * coordinates given weren't visible, or because we detected
11545 * that it was 100% covered by a sprite plane. Or, the CRTC may be
11546 * off and we've set a fb, but haven't actually turned on the CRTC yet.
11547 * In either case, we need to unpin the FB and let the fb pointer get
11548 * updated, but otherwise we don't need to touch the hardware.
11550 if (!intel_crtc
->primary_enabled
)
11551 goto disable_unpin
;
11553 intel_crtc_wait_for_pending_flips(plane
->crtc
);
11554 intel_disable_primary_hw_plane(plane
, plane
->crtc
);
11557 mutex_lock(&dev
->struct_mutex
);
11558 i915_gem_track_fb(intel_fb_obj(plane
->fb
), NULL
,
11559 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11560 intel_unpin_fb_obj(intel_fb_obj(plane
->fb
));
11561 mutex_unlock(&dev
->struct_mutex
);
11568 intel_primary_plane_setplane(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11569 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11570 unsigned int crtc_w
, unsigned int crtc_h
,
11571 uint32_t src_x
, uint32_t src_y
,
11572 uint32_t src_w
, uint32_t src_h
)
11574 struct drm_device
*dev
= crtc
->dev
;
11575 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11576 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
11577 struct drm_i915_gem_object
*old_obj
= intel_fb_obj(plane
->fb
);
11578 struct drm_rect dest
= {
11579 /* integer pixels */
11582 .x2
= crtc_x
+ crtc_w
,
11583 .y2
= crtc_y
+ crtc_h
,
11585 struct drm_rect src
= {
11586 /* 16.16 fixed point */
11589 .x2
= src_x
+ src_w
,
11590 .y2
= src_y
+ src_h
,
11592 const struct drm_rect clip
= {
11593 /* integer pixels */
11594 .x2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_w
: 0,
11595 .y2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_h
: 0,
11600 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
11601 &src
, &dest
, &clip
,
11602 DRM_PLANE_HELPER_NO_SCALING
,
11603 DRM_PLANE_HELPER_NO_SCALING
,
11604 false, true, &visible
);
11610 * If the CRTC isn't enabled, we're just pinning the framebuffer,
11611 * updating the fb pointer, and returning without touching the
11612 * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
11613 * turn on the display with all planes setup as desired.
11615 if (!crtc
->enabled
) {
11616 mutex_lock(&dev
->struct_mutex
);
11619 * If we already called setplane while the crtc was disabled,
11620 * we may have an fb pinned; unpin it.
11623 intel_unpin_fb_obj(old_obj
);
11625 i915_gem_track_fb(old_obj
, obj
,
11626 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11628 /* Pin and return without programming hardware */
11629 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
11630 mutex_unlock(&dev
->struct_mutex
);
11635 intel_crtc_wait_for_pending_flips(crtc
);
11638 * If clipping results in a non-visible primary plane, we'll disable
11639 * the primary plane. Note that this is a bit different than what
11640 * happens if userspace explicitly disables the plane by passing fb=0
11641 * because plane->fb still gets set and pinned.
11644 mutex_lock(&dev
->struct_mutex
);
11647 * Try to pin the new fb first so that we can bail out if we
11650 if (plane
->fb
!= fb
) {
11651 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, NULL
);
11653 mutex_unlock(&dev
->struct_mutex
);
11658 i915_gem_track_fb(old_obj
, obj
,
11659 INTEL_FRONTBUFFER_PRIMARY(intel_crtc
->pipe
));
11661 if (intel_crtc
->primary_enabled
)
11662 intel_disable_primary_hw_plane(plane
, crtc
);
11665 if (plane
->fb
!= fb
)
11667 intel_unpin_fb_obj(old_obj
);
11669 mutex_unlock(&dev
->struct_mutex
);
11674 ret
= intel_pipe_set_base(crtc
, src
.x1
, src
.y1
, fb
);
11678 if (!intel_crtc
->primary_enabled
)
11679 intel_enable_primary_hw_plane(plane
, crtc
);
11684 /* Common destruction function for both primary and cursor planes */
11685 static void intel_plane_destroy(struct drm_plane
*plane
)
11687 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
11688 drm_plane_cleanup(plane
);
11689 kfree(intel_plane
);
11692 static const struct drm_plane_funcs intel_primary_plane_funcs
= {
11693 .update_plane
= intel_primary_plane_setplane
,
11694 .disable_plane
= intel_primary_plane_disable
,
11695 .destroy
= intel_plane_destroy
,
11698 static struct drm_plane
*intel_primary_plane_create(struct drm_device
*dev
,
11701 struct intel_plane
*primary
;
11702 const uint32_t *intel_primary_formats
;
11705 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
11706 if (primary
== NULL
)
11709 primary
->can_scale
= false;
11710 primary
->max_downscale
= 1;
11711 primary
->pipe
= pipe
;
11712 primary
->plane
= pipe
;
11713 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4)
11714 primary
->plane
= !pipe
;
11716 if (INTEL_INFO(dev
)->gen
<= 3) {
11717 intel_primary_formats
= intel_primary_formats_gen2
;
11718 num_formats
= ARRAY_SIZE(intel_primary_formats_gen2
);
11720 intel_primary_formats
= intel_primary_formats_gen4
;
11721 num_formats
= ARRAY_SIZE(intel_primary_formats_gen4
);
11724 drm_universal_plane_init(dev
, &primary
->base
, 0,
11725 &intel_primary_plane_funcs
,
11726 intel_primary_formats
, num_formats
,
11727 DRM_PLANE_TYPE_PRIMARY
);
11728 return &primary
->base
;
11732 intel_cursor_plane_disable(struct drm_plane
*plane
)
11737 BUG_ON(!plane
->crtc
);
11739 return intel_crtc_cursor_set_obj(plane
->crtc
, NULL
, 0, 0);
11743 intel_cursor_plane_update(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
11744 struct drm_framebuffer
*fb
, int crtc_x
, int crtc_y
,
11745 unsigned int crtc_w
, unsigned int crtc_h
,
11746 uint32_t src_x
, uint32_t src_y
,
11747 uint32_t src_w
, uint32_t src_h
)
11749 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
11750 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
11751 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
11752 struct drm_rect dest
= {
11753 /* integer pixels */
11756 .x2
= crtc_x
+ crtc_w
,
11757 .y2
= crtc_y
+ crtc_h
,
11759 struct drm_rect src
= {
11760 /* 16.16 fixed point */
11763 .x2
= src_x
+ src_w
,
11764 .y2
= src_y
+ src_h
,
11766 const struct drm_rect clip
= {
11767 /* integer pixels */
11768 .x2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_w
: 0,
11769 .y2
= intel_crtc
->active
? intel_crtc
->config
.pipe_src_h
: 0,
11774 ret
= drm_plane_helper_check_update(plane
, crtc
, fb
,
11775 &src
, &dest
, &clip
,
11776 DRM_PLANE_HELPER_NO_SCALING
,
11777 DRM_PLANE_HELPER_NO_SCALING
,
11778 true, true, &visible
);
11782 crtc
->cursor_x
= crtc_x
;
11783 crtc
->cursor_y
= crtc_y
;
11784 if (fb
!= crtc
->cursor
->fb
) {
11785 return intel_crtc_cursor_set_obj(crtc
, obj
, crtc_w
, crtc_h
);
11787 intel_crtc_update_cursor(crtc
, visible
);
11789 intel_frontbuffer_flip(crtc
->dev
,
11790 INTEL_FRONTBUFFER_CURSOR(intel_crtc
->pipe
));
11795 static const struct drm_plane_funcs intel_cursor_plane_funcs
= {
11796 .update_plane
= intel_cursor_plane_update
,
11797 .disable_plane
= intel_cursor_plane_disable
,
11798 .destroy
= intel_plane_destroy
,
11801 static struct drm_plane
*intel_cursor_plane_create(struct drm_device
*dev
,
11804 struct intel_plane
*cursor
;
11806 cursor
= kzalloc(sizeof(*cursor
), GFP_KERNEL
);
11807 if (cursor
== NULL
)
11810 cursor
->can_scale
= false;
11811 cursor
->max_downscale
= 1;
11812 cursor
->pipe
= pipe
;
11813 cursor
->plane
= pipe
;
11815 drm_universal_plane_init(dev
, &cursor
->base
, 0,
11816 &intel_cursor_plane_funcs
,
11817 intel_cursor_formats
,
11818 ARRAY_SIZE(intel_cursor_formats
),
11819 DRM_PLANE_TYPE_CURSOR
);
11820 return &cursor
->base
;
11823 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
11825 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11826 struct intel_crtc
*intel_crtc
;
11827 struct drm_plane
*primary
= NULL
;
11828 struct drm_plane
*cursor
= NULL
;
11831 intel_crtc
= kzalloc(sizeof(*intel_crtc
), GFP_KERNEL
);
11832 if (intel_crtc
== NULL
)
11835 primary
= intel_primary_plane_create(dev
, pipe
);
11839 cursor
= intel_cursor_plane_create(dev
, pipe
);
11843 ret
= drm_crtc_init_with_planes(dev
, &intel_crtc
->base
, primary
,
11844 cursor
, &intel_crtc_funcs
);
11848 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
11849 for (i
= 0; i
< 256; i
++) {
11850 intel_crtc
->lut_r
[i
] = i
;
11851 intel_crtc
->lut_g
[i
] = i
;
11852 intel_crtc
->lut_b
[i
] = i
;
11856 * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
11857 * is hooked to pipe B. Hence we want plane A feeding pipe B.
11859 intel_crtc
->pipe
= pipe
;
11860 intel_crtc
->plane
= pipe
;
11861 if (HAS_FBC(dev
) && INTEL_INFO(dev
)->gen
< 4) {
11862 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
11863 intel_crtc
->plane
= !pipe
;
11866 intel_crtc
->cursor_base
= ~0;
11867 intel_crtc
->cursor_cntl
= ~0;
11868 intel_crtc
->cursor_size
= ~0;
11870 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
11871 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
11872 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
11873 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
11875 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
11877 WARN_ON(drm_crtc_index(&intel_crtc
->base
) != intel_crtc
->pipe
);
11882 drm_plane_cleanup(primary
);
11884 drm_plane_cleanup(cursor
);
11888 enum pipe
intel_get_pipe_from_connector(struct intel_connector
*connector
)
11890 struct drm_encoder
*encoder
= connector
->base
.encoder
;
11891 struct drm_device
*dev
= connector
->base
.dev
;
11893 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
11896 return INVALID_PIPE
;
11898 return to_intel_crtc(encoder
->crtc
)->pipe
;
11901 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
11902 struct drm_file
*file
)
11904 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
11905 struct drm_crtc
*drmmode_crtc
;
11906 struct intel_crtc
*crtc
;
11908 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
11911 drmmode_crtc
= drm_crtc_find(dev
, pipe_from_crtc_id
->crtc_id
);
11913 if (!drmmode_crtc
) {
11914 DRM_ERROR("no such CRTC id\n");
11918 crtc
= to_intel_crtc(drmmode_crtc
);
11919 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
11924 static int intel_encoder_clones(struct intel_encoder
*encoder
)
11926 struct drm_device
*dev
= encoder
->base
.dev
;
11927 struct intel_encoder
*source_encoder
;
11928 int index_mask
= 0;
11931 for_each_intel_encoder(dev
, source_encoder
) {
11932 if (encoders_cloneable(encoder
, source_encoder
))
11933 index_mask
|= (1 << entry
);
11941 static bool has_edp_a(struct drm_device
*dev
)
11943 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11945 if (!IS_MOBILE(dev
))
11948 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
11951 if (IS_GEN5(dev
) && (I915_READ(FUSE_STRAP
) & ILK_eDP_A_DISABLE
))
11957 const char *intel_output_name(int output
)
11959 static const char *names
[] = {
11960 [INTEL_OUTPUT_UNUSED
] = "Unused",
11961 [INTEL_OUTPUT_ANALOG
] = "Analog",
11962 [INTEL_OUTPUT_DVO
] = "DVO",
11963 [INTEL_OUTPUT_SDVO
] = "SDVO",
11964 [INTEL_OUTPUT_LVDS
] = "LVDS",
11965 [INTEL_OUTPUT_TVOUT
] = "TV",
11966 [INTEL_OUTPUT_HDMI
] = "HDMI",
11967 [INTEL_OUTPUT_DISPLAYPORT
] = "DisplayPort",
11968 [INTEL_OUTPUT_EDP
] = "eDP",
11969 [INTEL_OUTPUT_DSI
] = "DSI",
11970 [INTEL_OUTPUT_UNKNOWN
] = "Unknown",
11973 if (output
< 0 || output
>= ARRAY_SIZE(names
) || !names
[output
])
11976 return names
[output
];
11979 static bool intel_crt_present(struct drm_device
*dev
)
11981 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11986 if (IS_CHERRYVIEW(dev
))
11989 if (IS_VALLEYVIEW(dev
) && !dev_priv
->vbt
.int_crt_support
)
11995 static void intel_setup_outputs(struct drm_device
*dev
)
11997 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
11998 struct intel_encoder
*encoder
;
11999 bool dpd_is_edp
= false;
12001 intel_lvds_init(dev
);
12003 if (intel_crt_present(dev
))
12004 intel_crt_init(dev
);
12006 if (HAS_DDI(dev
)) {
12009 /* Haswell uses DDI functions to detect digital outputs */
12010 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
12011 /* DDI A only supports eDP */
12013 intel_ddi_init(dev
, PORT_A
);
12015 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
12017 found
= I915_READ(SFUSE_STRAP
);
12019 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
12020 intel_ddi_init(dev
, PORT_B
);
12021 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
12022 intel_ddi_init(dev
, PORT_C
);
12023 if (found
& SFUSE_STRAP_DDID_DETECTED
)
12024 intel_ddi_init(dev
, PORT_D
);
12025 } else if (HAS_PCH_SPLIT(dev
)) {
12027 dpd_is_edp
= intel_dp_is_edp(dev
, PORT_D
);
12029 if (has_edp_a(dev
))
12030 intel_dp_init(dev
, DP_A
, PORT_A
);
12032 if (I915_READ(PCH_HDMIB
) & SDVO_DETECTED
) {
12033 /* PCH SDVOB multiplex with HDMIB */
12034 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
12036 intel_hdmi_init(dev
, PCH_HDMIB
, PORT_B
);
12037 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
12038 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
12041 if (I915_READ(PCH_HDMIC
) & SDVO_DETECTED
)
12042 intel_hdmi_init(dev
, PCH_HDMIC
, PORT_C
);
12044 if (!dpd_is_edp
&& I915_READ(PCH_HDMID
) & SDVO_DETECTED
)
12045 intel_hdmi_init(dev
, PCH_HDMID
, PORT_D
);
12047 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
12048 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
12050 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
12051 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
12052 } else if (IS_VALLEYVIEW(dev
)) {
12053 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIB
) & SDVO_DETECTED
) {
12054 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIB
,
12056 if (I915_READ(VLV_DISPLAY_BASE
+ DP_B
) & DP_DETECTED
)
12057 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_B
, PORT_B
);
12060 if (I915_READ(VLV_DISPLAY_BASE
+ GEN4_HDMIC
) & SDVO_DETECTED
) {
12061 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ GEN4_HDMIC
,
12063 if (I915_READ(VLV_DISPLAY_BASE
+ DP_C
) & DP_DETECTED
)
12064 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_C
, PORT_C
);
12067 if (IS_CHERRYVIEW(dev
)) {
12068 if (I915_READ(VLV_DISPLAY_BASE
+ CHV_HDMID
) & SDVO_DETECTED
) {
12069 intel_hdmi_init(dev
, VLV_DISPLAY_BASE
+ CHV_HDMID
,
12071 if (I915_READ(VLV_DISPLAY_BASE
+ DP_D
) & DP_DETECTED
)
12072 intel_dp_init(dev
, VLV_DISPLAY_BASE
+ DP_D
, PORT_D
);
12076 intel_dsi_init(dev
);
12077 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
12078 bool found
= false;
12080 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
12081 DRM_DEBUG_KMS("probing SDVOB\n");
12082 found
= intel_sdvo_init(dev
, GEN3_SDVOB
, true);
12083 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
12084 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
12085 intel_hdmi_init(dev
, GEN4_HDMIB
, PORT_B
);
12088 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
))
12089 intel_dp_init(dev
, DP_B
, PORT_B
);
12092 /* Before G4X SDVOC doesn't have its own detect register */
12094 if (I915_READ(GEN3_SDVOB
) & SDVO_DETECTED
) {
12095 DRM_DEBUG_KMS("probing SDVOC\n");
12096 found
= intel_sdvo_init(dev
, GEN3_SDVOC
, false);
12099 if (!found
&& (I915_READ(GEN3_SDVOC
) & SDVO_DETECTED
)) {
12101 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
12102 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
12103 intel_hdmi_init(dev
, GEN4_HDMIC
, PORT_C
);
12105 if (SUPPORTS_INTEGRATED_DP(dev
))
12106 intel_dp_init(dev
, DP_C
, PORT_C
);
12109 if (SUPPORTS_INTEGRATED_DP(dev
) &&
12110 (I915_READ(DP_D
) & DP_DETECTED
))
12111 intel_dp_init(dev
, DP_D
, PORT_D
);
12112 } else if (IS_GEN2(dev
))
12113 intel_dvo_init(dev
);
12115 if (SUPPORTS_TV(dev
))
12116 intel_tv_init(dev
);
12118 intel_edp_psr_init(dev
);
12120 for_each_intel_encoder(dev
, encoder
) {
12121 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
12122 encoder
->base
.possible_clones
=
12123 intel_encoder_clones(encoder
);
12126 intel_init_pch_refclk(dev
);
12128 drm_helper_move_panel_connectors_to_head(dev
);
12131 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
12133 struct drm_device
*dev
= fb
->dev
;
12134 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
12136 drm_framebuffer_cleanup(fb
);
12137 mutex_lock(&dev
->struct_mutex
);
12138 WARN_ON(!intel_fb
->obj
->framebuffer_references
--);
12139 drm_gem_object_unreference(&intel_fb
->obj
->base
);
12140 mutex_unlock(&dev
->struct_mutex
);
12144 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
12145 struct drm_file
*file
,
12146 unsigned int *handle
)
12148 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
12149 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
12151 return drm_gem_handle_create(file
, &obj
->base
, handle
);
12154 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
12155 .destroy
= intel_user_framebuffer_destroy
,
12156 .create_handle
= intel_user_framebuffer_create_handle
,
12159 static int intel_framebuffer_init(struct drm_device
*dev
,
12160 struct intel_framebuffer
*intel_fb
,
12161 struct drm_mode_fb_cmd2
*mode_cmd
,
12162 struct drm_i915_gem_object
*obj
)
12164 int aligned_height
;
12168 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
12170 if (obj
->tiling_mode
== I915_TILING_Y
) {
12171 DRM_DEBUG("hardware does not support tiling Y\n");
12175 if (mode_cmd
->pitches
[0] & 63) {
12176 DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
12177 mode_cmd
->pitches
[0]);
12181 if (INTEL_INFO(dev
)->gen
>= 5 && !IS_VALLEYVIEW(dev
)) {
12182 pitch_limit
= 32*1024;
12183 } else if (INTEL_INFO(dev
)->gen
>= 4) {
12184 if (obj
->tiling_mode
)
12185 pitch_limit
= 16*1024;
12187 pitch_limit
= 32*1024;
12188 } else if (INTEL_INFO(dev
)->gen
>= 3) {
12189 if (obj
->tiling_mode
)
12190 pitch_limit
= 8*1024;
12192 pitch_limit
= 16*1024;
12194 /* XXX DSPC is limited to 4k tiled */
12195 pitch_limit
= 8*1024;
12197 if (mode_cmd
->pitches
[0] > pitch_limit
) {
12198 DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
12199 obj
->tiling_mode
? "tiled" : "linear",
12200 mode_cmd
->pitches
[0], pitch_limit
);
12204 if (obj
->tiling_mode
!= I915_TILING_NONE
&&
12205 mode_cmd
->pitches
[0] != obj
->stride
) {
12206 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
12207 mode_cmd
->pitches
[0], obj
->stride
);
12211 /* Reject formats not supported by any plane early. */
12212 switch (mode_cmd
->pixel_format
) {
12213 case DRM_FORMAT_C8
:
12214 case DRM_FORMAT_RGB565
:
12215 case DRM_FORMAT_XRGB8888
:
12216 case DRM_FORMAT_ARGB8888
:
12218 case DRM_FORMAT_XRGB1555
:
12219 case DRM_FORMAT_ARGB1555
:
12220 if (INTEL_INFO(dev
)->gen
> 3) {
12221 DRM_DEBUG("unsupported pixel format: %s\n",
12222 drm_get_format_name(mode_cmd
->pixel_format
));
12226 case DRM_FORMAT_XBGR8888
:
12227 case DRM_FORMAT_ABGR8888
:
12228 case DRM_FORMAT_XRGB2101010
:
12229 case DRM_FORMAT_ARGB2101010
:
12230 case DRM_FORMAT_XBGR2101010
:
12231 case DRM_FORMAT_ABGR2101010
:
12232 if (INTEL_INFO(dev
)->gen
< 4) {
12233 DRM_DEBUG("unsupported pixel format: %s\n",
12234 drm_get_format_name(mode_cmd
->pixel_format
));
12238 case DRM_FORMAT_YUYV
:
12239 case DRM_FORMAT_UYVY
:
12240 case DRM_FORMAT_YVYU
:
12241 case DRM_FORMAT_VYUY
:
12242 if (INTEL_INFO(dev
)->gen
< 5) {
12243 DRM_DEBUG("unsupported pixel format: %s\n",
12244 drm_get_format_name(mode_cmd
->pixel_format
));
12249 DRM_DEBUG("unsupported pixel format: %s\n",
12250 drm_get_format_name(mode_cmd
->pixel_format
));
12254 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
12255 if (mode_cmd
->offsets
[0] != 0)
12258 aligned_height
= intel_align_height(dev
, mode_cmd
->height
,
12260 /* FIXME drm helper for size checks (especially planar formats)? */
12261 if (obj
->base
.size
< aligned_height
* mode_cmd
->pitches
[0])
12264 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
12265 intel_fb
->obj
= obj
;
12266 intel_fb
->obj
->framebuffer_references
++;
12268 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
12270 DRM_ERROR("framebuffer init failed %d\n", ret
);
12277 static struct drm_framebuffer
*
12278 intel_user_framebuffer_create(struct drm_device
*dev
,
12279 struct drm_file
*filp
,
12280 struct drm_mode_fb_cmd2
*mode_cmd
)
12282 struct drm_i915_gem_object
*obj
;
12284 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
12285 mode_cmd
->handles
[0]));
12286 if (&obj
->base
== NULL
)
12287 return ERR_PTR(-ENOENT
);
12289 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
12292 #ifndef CONFIG_DRM_I915_FBDEV
12293 static inline void intel_fbdev_output_poll_changed(struct drm_device
*dev
)
12298 static const struct drm_mode_config_funcs intel_mode_funcs
= {
12299 .fb_create
= intel_user_framebuffer_create
,
12300 .output_poll_changed
= intel_fbdev_output_poll_changed
,
12303 /* Set up chip specific display functions */
12304 static void intel_init_display(struct drm_device
*dev
)
12306 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12308 if (HAS_PCH_SPLIT(dev
) || IS_G4X(dev
))
12309 dev_priv
->display
.find_dpll
= g4x_find_best_dpll
;
12310 else if (IS_CHERRYVIEW(dev
))
12311 dev_priv
->display
.find_dpll
= chv_find_best_dpll
;
12312 else if (IS_VALLEYVIEW(dev
))
12313 dev_priv
->display
.find_dpll
= vlv_find_best_dpll
;
12314 else if (IS_PINEVIEW(dev
))
12315 dev_priv
->display
.find_dpll
= pnv_find_best_dpll
;
12317 dev_priv
->display
.find_dpll
= i9xx_find_best_dpll
;
12319 if (HAS_DDI(dev
)) {
12320 dev_priv
->display
.get_pipe_config
= haswell_get_pipe_config
;
12321 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
12322 dev_priv
->display
.crtc_mode_set
= haswell_crtc_mode_set
;
12323 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
12324 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
12325 dev_priv
->display
.off
= ironlake_crtc_off
;
12326 dev_priv
->display
.update_primary_plane
=
12327 ironlake_update_primary_plane
;
12328 } else if (HAS_PCH_SPLIT(dev
)) {
12329 dev_priv
->display
.get_pipe_config
= ironlake_get_pipe_config
;
12330 dev_priv
->display
.get_plane_config
= ironlake_get_plane_config
;
12331 dev_priv
->display
.crtc_mode_set
= ironlake_crtc_mode_set
;
12332 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
12333 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
12334 dev_priv
->display
.off
= ironlake_crtc_off
;
12335 dev_priv
->display
.update_primary_plane
=
12336 ironlake_update_primary_plane
;
12337 } else if (IS_VALLEYVIEW(dev
)) {
12338 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
12339 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
12340 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
12341 dev_priv
->display
.crtc_enable
= valleyview_crtc_enable
;
12342 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
12343 dev_priv
->display
.off
= i9xx_crtc_off
;
12344 dev_priv
->display
.update_primary_plane
=
12345 i9xx_update_primary_plane
;
12347 dev_priv
->display
.get_pipe_config
= i9xx_get_pipe_config
;
12348 dev_priv
->display
.get_plane_config
= i9xx_get_plane_config
;
12349 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
12350 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
12351 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
12352 dev_priv
->display
.off
= i9xx_crtc_off
;
12353 dev_priv
->display
.update_primary_plane
=
12354 i9xx_update_primary_plane
;
12357 /* Returns the core display clock speed */
12358 if (IS_VALLEYVIEW(dev
))
12359 dev_priv
->display
.get_display_clock_speed
=
12360 valleyview_get_display_clock_speed
;
12361 else if (IS_I945G(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
12362 dev_priv
->display
.get_display_clock_speed
=
12363 i945_get_display_clock_speed
;
12364 else if (IS_I915G(dev
))
12365 dev_priv
->display
.get_display_clock_speed
=
12366 i915_get_display_clock_speed
;
12367 else if (IS_I945GM(dev
) || IS_845G(dev
))
12368 dev_priv
->display
.get_display_clock_speed
=
12369 i9xx_misc_get_display_clock_speed
;
12370 else if (IS_PINEVIEW(dev
))
12371 dev_priv
->display
.get_display_clock_speed
=
12372 pnv_get_display_clock_speed
;
12373 else if (IS_I915GM(dev
))
12374 dev_priv
->display
.get_display_clock_speed
=
12375 i915gm_get_display_clock_speed
;
12376 else if (IS_I865G(dev
))
12377 dev_priv
->display
.get_display_clock_speed
=
12378 i865_get_display_clock_speed
;
12379 else if (IS_I85X(dev
))
12380 dev_priv
->display
.get_display_clock_speed
=
12381 i855_get_display_clock_speed
;
12382 else /* 852, 830 */
12383 dev_priv
->display
.get_display_clock_speed
=
12384 i830_get_display_clock_speed
;
12387 dev_priv
->display
.write_eld
= g4x_write_eld
;
12388 } else if (IS_GEN5(dev
)) {
12389 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
12390 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12391 } else if (IS_GEN6(dev
)) {
12392 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
12393 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12394 dev_priv
->display
.modeset_global_resources
=
12395 snb_modeset_global_resources
;
12396 } else if (IS_IVYBRIDGE(dev
)) {
12397 /* FIXME: detect B0+ stepping and use auto training */
12398 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
12399 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12400 dev_priv
->display
.modeset_global_resources
=
12401 ivb_modeset_global_resources
;
12402 } else if (IS_HASWELL(dev
) || IS_GEN8(dev
)) {
12403 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
12404 dev_priv
->display
.write_eld
= haswell_write_eld
;
12405 dev_priv
->display
.modeset_global_resources
=
12406 haswell_modeset_global_resources
;
12407 } else if (IS_VALLEYVIEW(dev
)) {
12408 dev_priv
->display
.modeset_global_resources
=
12409 valleyview_modeset_global_resources
;
12410 dev_priv
->display
.write_eld
= ironlake_write_eld
;
12413 /* Default just returns -ENODEV to indicate unsupported */
12414 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
12416 switch (INTEL_INFO(dev
)->gen
) {
12418 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
12422 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
12427 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
12431 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
12434 case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
12435 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
12439 intel_panel_init_backlight_funcs(dev
);
12443 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
12444 * resume, or other times. This quirk makes sure that's the case for
12445 * affected systems.
12447 static void quirk_pipea_force(struct drm_device
*dev
)
12449 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12451 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
12452 DRM_INFO("applying pipe a force quirk\n");
12456 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
12458 static void quirk_ssc_force_disable(struct drm_device
*dev
)
12460 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12461 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
12462 DRM_INFO("applying lvds SSC disable quirk\n");
12466 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
12469 static void quirk_invert_brightness(struct drm_device
*dev
)
12471 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12472 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
12473 DRM_INFO("applying inverted panel brightness quirk\n");
12476 /* Some VBT's incorrectly indicate no backlight is present */
12477 static void quirk_backlight_present(struct drm_device
*dev
)
12479 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12480 dev_priv
->quirks
|= QUIRK_BACKLIGHT_PRESENT
;
12481 DRM_INFO("applying backlight present quirk\n");
12484 struct intel_quirk
{
12486 int subsystem_vendor
;
12487 int subsystem_device
;
12488 void (*hook
)(struct drm_device
*dev
);
12491 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
12492 struct intel_dmi_quirk
{
12493 void (*hook
)(struct drm_device
*dev
);
12494 const struct dmi_system_id (*dmi_id_list
)[];
12497 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
12499 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
12503 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
12505 .dmi_id_list
= &(const struct dmi_system_id
[]) {
12507 .callback
= intel_dmi_reverse_brightness
,
12508 .ident
= "NCR Corporation",
12509 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
12510 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
12513 { } /* terminating entry */
12515 .hook
= quirk_invert_brightness
,
12519 static struct intel_quirk intel_quirks
[] = {
12520 /* HP Mini needs pipe A force quirk (LP: #322104) */
12521 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force
},
12523 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
12524 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
12526 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
12527 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
12529 /* Lenovo U160 cannot use SSC on LVDS */
12530 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
12532 /* Sony Vaio Y cannot use SSC on LVDS */
12533 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
12535 /* Acer Aspire 5734Z must invert backlight brightness */
12536 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
12538 /* Acer/eMachines G725 */
12539 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness
},
12541 /* Acer/eMachines e725 */
12542 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness
},
12544 /* Acer/Packard Bell NCL20 */
12545 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness
},
12547 /* Acer Aspire 4736Z */
12548 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness
},
12550 /* Acer Aspire 5336 */
12551 { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness
},
12553 /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
12554 { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present
},
12556 /* Toshiba CB35 Chromebook (Celeron 2955U) */
12557 { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present
},
12559 /* HP Chromebook 14 (Celeron 2955U) */
12560 { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present
},
12563 static void intel_init_quirks(struct drm_device
*dev
)
12565 struct pci_dev
*d
= dev
->pdev
;
12568 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
12569 struct intel_quirk
*q
= &intel_quirks
[i
];
12571 if (d
->device
== q
->device
&&
12572 (d
->subsystem_vendor
== q
->subsystem_vendor
||
12573 q
->subsystem_vendor
== PCI_ANY_ID
) &&
12574 (d
->subsystem_device
== q
->subsystem_device
||
12575 q
->subsystem_device
== PCI_ANY_ID
))
12578 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
12579 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
12580 intel_dmi_quirks
[i
].hook(dev
);
12584 /* Disable the VGA plane that we never use */
12585 static void i915_disable_vga(struct drm_device
*dev
)
12587 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12589 u32 vga_reg
= i915_vgacntrl_reg(dev
);
12591 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
12592 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12593 outb(SR01
, VGA_SR_INDEX
);
12594 sr1
= inb(VGA_SR_DATA
);
12595 outb(sr1
| 1<<5, VGA_SR_DATA
);
12596 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
12599 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
12600 POSTING_READ(vga_reg
);
12603 void intel_modeset_init_hw(struct drm_device
*dev
)
12605 intel_prepare_ddi(dev
);
12607 if (IS_VALLEYVIEW(dev
))
12608 vlv_update_cdclk(dev
);
12610 intel_init_clock_gating(dev
);
12612 intel_enable_gt_powersave(dev
);
12615 void intel_modeset_suspend_hw(struct drm_device
*dev
)
12617 intel_suspend_hw(dev
);
12620 void intel_modeset_init(struct drm_device
*dev
)
12622 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12625 struct intel_crtc
*crtc
;
12627 drm_mode_config_init(dev
);
12629 dev
->mode_config
.min_width
= 0;
12630 dev
->mode_config
.min_height
= 0;
12632 dev
->mode_config
.preferred_depth
= 24;
12633 dev
->mode_config
.prefer_shadow
= 1;
12635 dev
->mode_config
.funcs
= &intel_mode_funcs
;
12637 intel_init_quirks(dev
);
12639 intel_init_pm(dev
);
12641 if (INTEL_INFO(dev
)->num_pipes
== 0)
12644 intel_init_display(dev
);
12646 if (IS_GEN2(dev
)) {
12647 dev
->mode_config
.max_width
= 2048;
12648 dev
->mode_config
.max_height
= 2048;
12649 } else if (IS_GEN3(dev
)) {
12650 dev
->mode_config
.max_width
= 4096;
12651 dev
->mode_config
.max_height
= 4096;
12653 dev
->mode_config
.max_width
= 8192;
12654 dev
->mode_config
.max_height
= 8192;
12657 if (IS_845G(dev
) || IS_I865G(dev
)) {
12658 dev
->mode_config
.cursor_width
= IS_845G(dev
) ? 64 : 512;
12659 dev
->mode_config
.cursor_height
= 1023;
12660 } else if (IS_GEN2(dev
)) {
12661 dev
->mode_config
.cursor_width
= GEN2_CURSOR_WIDTH
;
12662 dev
->mode_config
.cursor_height
= GEN2_CURSOR_HEIGHT
;
12664 dev
->mode_config
.cursor_width
= MAX_CURSOR_WIDTH
;
12665 dev
->mode_config
.cursor_height
= MAX_CURSOR_HEIGHT
;
12668 dev
->mode_config
.fb_base
= dev_priv
->gtt
.mappable_base
;
12670 DRM_DEBUG_KMS("%d display pipe%s available.\n",
12671 INTEL_INFO(dev
)->num_pipes
,
12672 INTEL_INFO(dev
)->num_pipes
> 1 ? "s" : "");
12674 for_each_pipe(pipe
) {
12675 intel_crtc_init(dev
, pipe
);
12676 for_each_sprite(pipe
, sprite
) {
12677 ret
= intel_plane_init(dev
, pipe
, sprite
);
12679 DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
12680 pipe_name(pipe
), sprite_name(pipe
, sprite
), ret
);
12684 intel_init_dpio(dev
);
12686 intel_shared_dpll_init(dev
);
12688 /* Just disable it once at startup */
12689 i915_disable_vga(dev
);
12690 intel_setup_outputs(dev
);
12692 /* Just in case the BIOS is doing something questionable. */
12693 intel_disable_fbc(dev
);
12695 drm_modeset_lock_all(dev
);
12696 intel_modeset_setup_hw_state(dev
, false);
12697 drm_modeset_unlock_all(dev
);
12699 for_each_intel_crtc(dev
, crtc
) {
12704 * Note that reserving the BIOS fb up front prevents us
12705 * from stuffing other stolen allocations like the ring
12706 * on top. This prevents some ugliness at boot time, and
12707 * can even allow for smooth boot transitions if the BIOS
12708 * fb is large enough for the active pipe configuration.
12710 if (dev_priv
->display
.get_plane_config
) {
12711 dev_priv
->display
.get_plane_config(crtc
,
12712 &crtc
->plane_config
);
12714 * If the fb is shared between multiple heads, we'll
12715 * just get the first one.
12717 intel_find_plane_obj(crtc
, &crtc
->plane_config
);
12722 static void intel_enable_pipe_a(struct drm_device
*dev
)
12724 struct intel_connector
*connector
;
12725 struct drm_connector
*crt
= NULL
;
12726 struct intel_load_detect_pipe load_detect_temp
;
12727 struct drm_modeset_acquire_ctx
*ctx
= dev
->mode_config
.acquire_ctx
;
12729 /* We can't just switch on the pipe A, we need to set things up with a
12730 * proper mode and output configuration. As a gross hack, enable pipe A
12731 * by enabling the load detect pipe once. */
12732 list_for_each_entry(connector
,
12733 &dev
->mode_config
.connector_list
,
12735 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
12736 crt
= &connector
->base
;
12744 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
, ctx
))
12745 intel_release_load_detect_pipe(crt
, &load_detect_temp
);
12749 intel_check_plane_mapping(struct intel_crtc
*crtc
)
12751 struct drm_device
*dev
= crtc
->base
.dev
;
12752 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12755 if (INTEL_INFO(dev
)->num_pipes
== 1)
12758 reg
= DSPCNTR(!crtc
->plane
);
12759 val
= I915_READ(reg
);
12761 if ((val
& DISPLAY_PLANE_ENABLE
) &&
12762 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
12768 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
12770 struct drm_device
*dev
= crtc
->base
.dev
;
12771 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12774 /* Clear any frame start delays used for debugging left by the BIOS */
12775 reg
= PIPECONF(crtc
->config
.cpu_transcoder
);
12776 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
12778 /* restore vblank interrupts to correct state */
12779 if (crtc
->active
) {
12780 update_scanline_offset(crtc
);
12781 drm_vblank_on(dev
, crtc
->pipe
);
12783 drm_vblank_off(dev
, crtc
->pipe
);
12785 /* We need to sanitize the plane -> pipe mapping first because this will
12786 * disable the crtc (and hence change the state) if it is wrong. Note
12787 * that gen4+ has a fixed plane -> pipe mapping. */
12788 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
12789 struct intel_connector
*connector
;
12792 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
12793 crtc
->base
.base
.id
);
12795 /* Pipe has the wrong plane attached and the plane is active.
12796 * Temporarily change the plane mapping and disable everything
12798 plane
= crtc
->plane
;
12799 crtc
->plane
= !plane
;
12800 crtc
->primary_enabled
= true;
12801 dev_priv
->display
.crtc_disable(&crtc
->base
);
12802 crtc
->plane
= plane
;
12804 /* ... and break all links. */
12805 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12807 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
12810 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12811 connector
->base
.encoder
= NULL
;
12813 /* multiple connectors may have the same encoder:
12814 * handle them and break crtc link separately */
12815 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
12817 if (connector
->encoder
->base
.crtc
== &crtc
->base
) {
12818 connector
->encoder
->base
.crtc
= NULL
;
12819 connector
->encoder
->connectors_active
= false;
12822 WARN_ON(crtc
->active
);
12823 crtc
->base
.enabled
= false;
12826 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
12827 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
12828 /* BIOS forgot to enable pipe A, this mostly happens after
12829 * resume. Force-enable the pipe to fix this, the update_dpms
12830 * call below we restore the pipe to the right state, but leave
12831 * the required bits on. */
12832 intel_enable_pipe_a(dev
);
12835 /* Adjust the state of the output pipe according to whether we
12836 * have active connectors/encoders. */
12837 intel_crtc_update_dpms(&crtc
->base
);
12839 if (crtc
->active
!= crtc
->base
.enabled
) {
12840 struct intel_encoder
*encoder
;
12842 /* This can happen either due to bugs in the get_hw_state
12843 * functions or because the pipe is force-enabled due to the
12845 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
12846 crtc
->base
.base
.id
,
12847 crtc
->base
.enabled
? "enabled" : "disabled",
12848 crtc
->active
? "enabled" : "disabled");
12850 crtc
->base
.enabled
= crtc
->active
;
12852 /* Because we only establish the connector -> encoder ->
12853 * crtc links if something is active, this means the
12854 * crtc is now deactivated. Break the links. connector
12855 * -> encoder links are only establish when things are
12856 * actually up, hence no need to break them. */
12857 WARN_ON(crtc
->active
);
12859 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
12860 WARN_ON(encoder
->connectors_active
);
12861 encoder
->base
.crtc
= NULL
;
12865 if (crtc
->active
|| IS_VALLEYVIEW(dev
) || INTEL_INFO(dev
)->gen
< 5) {
12867 * We start out with underrun reporting disabled to avoid races.
12868 * For correct bookkeeping mark this on active crtcs.
12870 * Also on gmch platforms we dont have any hardware bits to
12871 * disable the underrun reporting. Which means we need to start
12872 * out with underrun reporting disabled also on inactive pipes,
12873 * since otherwise we'll complain about the garbage we read when
12874 * e.g. coming up after runtime pm.
12876 * No protection against concurrent access is required - at
12877 * worst a fifo underrun happens which also sets this to false.
12879 crtc
->cpu_fifo_underrun_disabled
= true;
12880 crtc
->pch_fifo_underrun_disabled
= true;
12884 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
12886 struct intel_connector
*connector
;
12887 struct drm_device
*dev
= encoder
->base
.dev
;
12889 /* We need to check both for a crtc link (meaning that the
12890 * encoder is active and trying to read from a pipe) and the
12891 * pipe itself being active. */
12892 bool has_active_crtc
= encoder
->base
.crtc
&&
12893 to_intel_crtc(encoder
->base
.crtc
)->active
;
12895 if (encoder
->connectors_active
&& !has_active_crtc
) {
12896 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
12897 encoder
->base
.base
.id
,
12898 encoder
->base
.name
);
12900 /* Connector is active, but has no active pipe. This is
12901 * fallout from our resume register restoring. Disable
12902 * the encoder manually again. */
12903 if (encoder
->base
.crtc
) {
12904 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
12905 encoder
->base
.base
.id
,
12906 encoder
->base
.name
);
12907 encoder
->disable(encoder
);
12908 if (encoder
->post_disable
)
12909 encoder
->post_disable(encoder
);
12911 encoder
->base
.crtc
= NULL
;
12912 encoder
->connectors_active
= false;
12914 /* Inconsistent output/port/pipe state happens presumably due to
12915 * a bug in one of the get_hw_state functions. Or someplace else
12916 * in our code, like the register restore mess on resume. Clamp
12917 * things to off as a safer default. */
12918 list_for_each_entry(connector
,
12919 &dev
->mode_config
.connector_list
,
12921 if (connector
->encoder
!= encoder
)
12923 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
12924 connector
->base
.encoder
= NULL
;
12927 /* Enabled encoders without active connectors will be fixed in
12928 * the crtc fixup. */
12931 void i915_redisable_vga_power_on(struct drm_device
*dev
)
12933 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12934 u32 vga_reg
= i915_vgacntrl_reg(dev
);
12936 if (!(I915_READ(vga_reg
) & VGA_DISP_DISABLE
)) {
12937 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
12938 i915_disable_vga(dev
);
12942 void i915_redisable_vga(struct drm_device
*dev
)
12944 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12946 /* This function can be called both from intel_modeset_setup_hw_state or
12947 * at a very early point in our resume sequence, where the power well
12948 * structures are not yet restored. Since this function is at a very
12949 * paranoid "someone might have enabled VGA while we were not looking"
12950 * level, just check if the power well is enabled instead of trying to
12951 * follow the "don't touch the power well if we don't need it" policy
12952 * the rest of the driver uses. */
12953 if (!intel_display_power_enabled(dev_priv
, POWER_DOMAIN_VGA
))
12956 i915_redisable_vga_power_on(dev
);
12959 static bool primary_get_hw_state(struct intel_crtc
*crtc
)
12961 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
12966 return I915_READ(DSPCNTR(crtc
->plane
)) & DISPLAY_PLANE_ENABLE
;
12969 static void intel_modeset_readout_hw_state(struct drm_device
*dev
)
12971 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
12973 struct intel_crtc
*crtc
;
12974 struct intel_encoder
*encoder
;
12975 struct intel_connector
*connector
;
12978 for_each_intel_crtc(dev
, crtc
) {
12979 memset(&crtc
->config
, 0, sizeof(crtc
->config
));
12981 crtc
->config
.quirks
|= PIPE_CONFIG_QUIRK_INHERITED_MODE
;
12983 crtc
->active
= dev_priv
->display
.get_pipe_config(crtc
,
12986 crtc
->base
.enabled
= crtc
->active
;
12987 crtc
->primary_enabled
= primary_get_hw_state(crtc
);
12989 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
12990 crtc
->base
.base
.id
,
12991 crtc
->active
? "enabled" : "disabled");
12994 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
12995 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
12997 pll
->on
= pll
->get_hw_state(dev_priv
, pll
, &pll
->hw_state
);
12999 for_each_intel_crtc(dev
, crtc
) {
13000 if (crtc
->active
&& intel_crtc_to_shared_dpll(crtc
) == pll
)
13003 pll
->refcount
= pll
->active
;
13005 DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
13006 pll
->name
, pll
->refcount
, pll
->on
);
13009 intel_display_power_get(dev_priv
, POWER_DOMAIN_PLLS
);
13012 for_each_intel_encoder(dev
, encoder
) {
13015 if (encoder
->get_hw_state(encoder
, &pipe
)) {
13016 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
13017 encoder
->base
.crtc
= &crtc
->base
;
13018 encoder
->get_config(encoder
, &crtc
->config
);
13020 encoder
->base
.crtc
= NULL
;
13023 encoder
->connectors_active
= false;
13024 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
13025 encoder
->base
.base
.id
,
13026 encoder
->base
.name
,
13027 encoder
->base
.crtc
? "enabled" : "disabled",
13031 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
13033 if (connector
->get_hw_state(connector
)) {
13034 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
13035 connector
->encoder
->connectors_active
= true;
13036 connector
->base
.encoder
= &connector
->encoder
->base
;
13038 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
13039 connector
->base
.encoder
= NULL
;
13041 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
13042 connector
->base
.base
.id
,
13043 connector
->base
.name
,
13044 connector
->base
.encoder
? "enabled" : "disabled");
13048 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
13049 * and i915 state tracking structures. */
13050 void intel_modeset_setup_hw_state(struct drm_device
*dev
,
13051 bool force_restore
)
13053 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13055 struct intel_crtc
*crtc
;
13056 struct intel_encoder
*encoder
;
13059 intel_modeset_readout_hw_state(dev
);
13062 * Now that we have the config, copy it to each CRTC struct
13063 * Note that this could go away if we move to using crtc_config
13064 * checking everywhere.
13066 for_each_intel_crtc(dev
, crtc
) {
13067 if (crtc
->active
&& i915
.fastboot
) {
13068 intel_mode_from_pipe_config(&crtc
->base
.mode
, &crtc
->config
);
13069 DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
13070 crtc
->base
.base
.id
);
13071 drm_mode_debug_printmodeline(&crtc
->base
.mode
);
13075 /* HW state is read out, now we need to sanitize this mess. */
13076 for_each_intel_encoder(dev
, encoder
) {
13077 intel_sanitize_encoder(encoder
);
13080 for_each_pipe(pipe
) {
13081 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
13082 intel_sanitize_crtc(crtc
);
13083 intel_dump_pipe_config(crtc
, &crtc
->config
, "[setup_hw_state]");
13086 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
13087 struct intel_shared_dpll
*pll
= &dev_priv
->shared_dplls
[i
];
13089 if (!pll
->on
|| pll
->active
)
13092 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll
->name
);
13094 pll
->disable(dev_priv
, pll
);
13098 if (HAS_PCH_SPLIT(dev
))
13099 ilk_wm_get_hw_state(dev
);
13101 if (force_restore
) {
13102 i915_redisable_vga(dev
);
13105 * We need to use raw interfaces for restoring state to avoid
13106 * checking (bogus) intermediate states.
13108 for_each_pipe(pipe
) {
13109 struct drm_crtc
*crtc
=
13110 dev_priv
->pipe_to_crtc_mapping
[pipe
];
13112 __intel_set_mode(crtc
, &crtc
->mode
, crtc
->x
, crtc
->y
,
13113 crtc
->primary
->fb
);
13116 intel_modeset_update_staged_output_state(dev
);
13119 intel_modeset_check_state(dev
);
13122 void intel_modeset_gem_init(struct drm_device
*dev
)
13124 struct drm_crtc
*c
;
13125 struct drm_i915_gem_object
*obj
;
13127 mutex_lock(&dev
->struct_mutex
);
13128 intel_init_gt_powersave(dev
);
13129 mutex_unlock(&dev
->struct_mutex
);
13131 intel_modeset_init_hw(dev
);
13133 intel_setup_overlay(dev
);
13136 * Make sure any fbs we allocated at startup are properly
13137 * pinned & fenced. When we do the allocation it's too early
13140 mutex_lock(&dev
->struct_mutex
);
13141 for_each_crtc(dev
, c
) {
13142 obj
= intel_fb_obj(c
->primary
->fb
);
13146 if (intel_pin_and_fence_fb_obj(dev
, obj
, NULL
)) {
13147 DRM_ERROR("failed to pin boot fb on pipe %d\n",
13148 to_intel_crtc(c
)->pipe
);
13149 drm_framebuffer_unreference(c
->primary
->fb
);
13150 c
->primary
->fb
= NULL
;
13153 mutex_unlock(&dev
->struct_mutex
);
13156 void intel_connector_unregister(struct intel_connector
*intel_connector
)
13158 struct drm_connector
*connector
= &intel_connector
->base
;
13160 intel_panel_destroy_backlight(connector
);
13161 drm_connector_unregister(connector
);
13164 void intel_modeset_cleanup(struct drm_device
*dev
)
13166 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13167 struct drm_connector
*connector
;
13170 * Interrupts and polling as the first thing to avoid creating havoc.
13171 * Too much stuff here (turning of rps, connectors, ...) would
13172 * experience fancy races otherwise.
13174 drm_irq_uninstall(dev
);
13175 intel_hpd_cancel_work(dev_priv
);
13176 dev_priv
->pm
._irqs_disabled
= true;
13179 * Due to the hpd irq storm handling the hotplug work can re-arm the
13180 * poll handlers. Hence disable polling after hpd handling is shut down.
13182 drm_kms_helper_poll_fini(dev
);
13184 mutex_lock(&dev
->struct_mutex
);
13186 intel_unregister_dsm_handler();
13188 intel_disable_fbc(dev
);
13190 intel_disable_gt_powersave(dev
);
13192 ironlake_teardown_rc6(dev
);
13194 mutex_unlock(&dev
->struct_mutex
);
13196 /* flush any delayed tasks or pending work */
13197 flush_scheduled_work();
13199 /* destroy the backlight and sysfs files before encoders/connectors */
13200 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
13201 struct intel_connector
*intel_connector
;
13203 intel_connector
= to_intel_connector(connector
);
13204 intel_connector
->unregister(intel_connector
);
13207 drm_mode_config_cleanup(dev
);
13209 intel_cleanup_overlay(dev
);
13211 mutex_lock(&dev
->struct_mutex
);
13212 intel_cleanup_gt_powersave(dev
);
13213 mutex_unlock(&dev
->struct_mutex
);
13217 * Return which encoder is currently attached for connector.
13219 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
13221 return &intel_attached_encoder(connector
)->base
;
13224 void intel_connector_attach_encoder(struct intel_connector
*connector
,
13225 struct intel_encoder
*encoder
)
13227 connector
->encoder
= encoder
;
13228 drm_mode_connector_attach_encoder(&connector
->base
,
13233 * set vga decode state - true == enable VGA decode
13235 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
13237 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13238 unsigned reg
= INTEL_INFO(dev
)->gen
>= 6 ? SNB_GMCH_CTRL
: INTEL_GMCH_CTRL
;
13241 if (pci_read_config_word(dev_priv
->bridge_dev
, reg
, &gmch_ctrl
)) {
13242 DRM_ERROR("failed to read control word\n");
13246 if (!!(gmch_ctrl
& INTEL_GMCH_VGA_DISABLE
) == !state
)
13250 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
13252 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
13254 if (pci_write_config_word(dev_priv
->bridge_dev
, reg
, gmch_ctrl
)) {
13255 DRM_ERROR("failed to write control word\n");
13262 struct intel_display_error_state
{
13264 u32 power_well_driver
;
13266 int num_transcoders
;
13268 struct intel_cursor_error_state
{
13273 } cursor
[I915_MAX_PIPES
];
13275 struct intel_pipe_error_state
{
13276 bool power_domain_on
;
13279 } pipe
[I915_MAX_PIPES
];
13281 struct intel_plane_error_state
{
13289 } plane
[I915_MAX_PIPES
];
13291 struct intel_transcoder_error_state
{
13292 bool power_domain_on
;
13293 enum transcoder cpu_transcoder
;
13306 struct intel_display_error_state
*
13307 intel_display_capture_error_state(struct drm_device
*dev
)
13309 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
13310 struct intel_display_error_state
*error
;
13311 int transcoders
[] = {
13319 if (INTEL_INFO(dev
)->num_pipes
== 0)
13322 error
= kzalloc(sizeof(*error
), GFP_ATOMIC
);
13326 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
13327 error
->power_well_driver
= I915_READ(HSW_PWR_WELL_DRIVER
);
13330 error
->pipe
[i
].power_domain_on
=
13331 intel_display_power_enabled_unlocked(dev_priv
,
13332 POWER_DOMAIN_PIPE(i
));
13333 if (!error
->pipe
[i
].power_domain_on
)
13336 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
13337 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
13338 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
13340 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
13341 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
13342 if (INTEL_INFO(dev
)->gen
<= 3) {
13343 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
13344 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
13346 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
13347 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
13348 if (INTEL_INFO(dev
)->gen
>= 4) {
13349 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
13350 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
13353 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
13355 if (HAS_GMCH_DISPLAY(dev
))
13356 error
->pipe
[i
].stat
= I915_READ(PIPESTAT(i
));
13359 error
->num_transcoders
= INTEL_INFO(dev
)->num_pipes
;
13360 if (HAS_DDI(dev_priv
->dev
))
13361 error
->num_transcoders
++; /* Account for eDP. */
13363 for (i
= 0; i
< error
->num_transcoders
; i
++) {
13364 enum transcoder cpu_transcoder
= transcoders
[i
];
13366 error
->transcoder
[i
].power_domain_on
=
13367 intel_display_power_enabled_unlocked(dev_priv
,
13368 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
13369 if (!error
->transcoder
[i
].power_domain_on
)
13372 error
->transcoder
[i
].cpu_transcoder
= cpu_transcoder
;
13374 error
->transcoder
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
13375 error
->transcoder
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
13376 error
->transcoder
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
13377 error
->transcoder
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
13378 error
->transcoder
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
13379 error
->transcoder
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
13380 error
->transcoder
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
13386 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
13389 intel_display_print_error_state(struct drm_i915_error_state_buf
*m
,
13390 struct drm_device
*dev
,
13391 struct intel_display_error_state
*error
)
13398 err_printf(m
, "Num Pipes: %d\n", INTEL_INFO(dev
)->num_pipes
);
13399 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
13400 err_printf(m
, "PWR_WELL_CTL2: %08x\n",
13401 error
->power_well_driver
);
13403 err_printf(m
, "Pipe [%d]:\n", i
);
13404 err_printf(m
, " Power: %s\n",
13405 error
->pipe
[i
].power_domain_on
? "on" : "off");
13406 err_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
13407 err_printf(m
, " STAT: %08x\n", error
->pipe
[i
].stat
);
13409 err_printf(m
, "Plane [%d]:\n", i
);
13410 err_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
13411 err_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
13412 if (INTEL_INFO(dev
)->gen
<= 3) {
13413 err_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
13414 err_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
13416 if (INTEL_INFO(dev
)->gen
<= 7 && !IS_HASWELL(dev
))
13417 err_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
13418 if (INTEL_INFO(dev
)->gen
>= 4) {
13419 err_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
13420 err_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
13423 err_printf(m
, "Cursor [%d]:\n", i
);
13424 err_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
13425 err_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
13426 err_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);
13429 for (i
= 0; i
< error
->num_transcoders
; i
++) {
13430 err_printf(m
, "CPU transcoder: %c\n",
13431 transcoder_name(error
->transcoder
[i
].cpu_transcoder
));
13432 err_printf(m
, " Power: %s\n",
13433 error
->transcoder
[i
].power_domain_on
? "on" : "off");
13434 err_printf(m
, " CONF: %08x\n", error
->transcoder
[i
].conf
);
13435 err_printf(m
, " HTOTAL: %08x\n", error
->transcoder
[i
].htotal
);
13436 err_printf(m
, " HBLANK: %08x\n", error
->transcoder
[i
].hblank
);
13437 err_printf(m
, " HSYNC: %08x\n", error
->transcoder
[i
].hsync
);
13438 err_printf(m
, " VTOTAL: %08x\n", error
->transcoder
[i
].vtotal
);
13439 err_printf(m
, " VBLANK: %08x\n", error
->transcoder
[i
].vblank
);
13440 err_printf(m
, " VSYNC: %08x\n", error
->transcoder
[i
].vsync
);
13444 void intel_modeset_preclose(struct drm_device
*dev
, struct drm_file
*file
)
13446 struct intel_crtc
*crtc
;
13448 for_each_intel_crtc(dev
, crtc
) {
13449 struct intel_unpin_work
*work
;
13450 unsigned long irqflags
;
13452 spin_lock_irqsave(&dev
->event_lock
, irqflags
);
13454 work
= crtc
->unpin_work
;
13456 if (work
&& work
->event
&&
13457 work
->event
->base
.file_priv
== file
) {
13458 kfree(work
->event
);
13459 work
->event
= NULL
;
13462 spin_unlock_irqrestore(&dev
->event_lock
, irqflags
);