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.
27 #include <linux/dmi.h>
28 #include <linux/module.h>
29 #include <linux/input.h>
30 #include <linux/i2c.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/vgaarb.h>
34 #include <drm/drm_edid.h>
36 #include "intel_drv.h"
37 #include <drm/i915_drm.h>
39 #include "i915_trace.h"
40 #include <drm/drm_dp_helper.h>
41 #include <drm/drm_crtc_helper.h>
42 #include <linux/dma_remapping.h>
44 bool intel_pipe_has_type(struct drm_crtc *crtc, int type);
45 static void intel_increase_pllclock(struct drm_crtc *crtc);
46 static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
69 #define INTEL_P2_NUM 2
70 typedef struct intel_limit intel_limit_t;
72 intel_range_t dot, vco, n, m, m1, m2, p, p1;
74 bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
75 int, int, intel_clock_t *, intel_clock_t *);
79 #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
82 intel_pch_rawclk(struct drm_device *dev)
84 struct drm_i915_private *dev_priv = dev->dev_private;
86 WARN_ON(!HAS_PCH_SPLIT(dev));
88 return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
92 intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
93 int target, int refclk, intel_clock_t *match_clock,
94 intel_clock_t *best_clock);
96 intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
97 int target, int refclk, intel_clock_t *match_clock,
98 intel_clock_t *best_clock);
101 intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
102 int target, int refclk, intel_clock_t *match_clock,
103 intel_clock_t *best_clock);
105 intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc,
106 int target, int refclk, intel_clock_t *match_clock,
107 intel_clock_t *best_clock);
110 intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc,
111 int target, int refclk, intel_clock_t *match_clock,
112 intel_clock_t *best_clock);
114 static inline u32 /* units of 100MHz */
115 intel_fdi_link_freq(struct drm_device *dev)
118 struct drm_i915_private *dev_priv = dev->dev_private;
119 return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
124 static const intel_limit_t intel_limits_i8xx_dvo = {
125 .dot = { .min = 25000, .max = 350000 },
126 .vco = { .min = 930000, .max = 1400000 },
127 .n = { .min = 3, .max = 16 },
128 .m = { .min = 96, .max = 140 },
129 .m1 = { .min = 18, .max = 26 },
130 .m2 = { .min = 6, .max = 16 },
131 .p = { .min = 4, .max = 128 },
132 .p1 = { .min = 2, .max = 33 },
133 .p2 = { .dot_limit = 165000,
134 .p2_slow = 4, .p2_fast = 2 },
135 .find_pll = intel_find_best_PLL,
138 static const intel_limit_t intel_limits_i8xx_lvds = {
139 .dot = { .min = 25000, .max = 350000 },
140 .vco = { .min = 930000, .max = 1400000 },
141 .n = { .min = 3, .max = 16 },
142 .m = { .min = 96, .max = 140 },
143 .m1 = { .min = 18, .max = 26 },
144 .m2 = { .min = 6, .max = 16 },
145 .p = { .min = 4, .max = 128 },
146 .p1 = { .min = 1, .max = 6 },
147 .p2 = { .dot_limit = 165000,
148 .p2_slow = 14, .p2_fast = 7 },
149 .find_pll = intel_find_best_PLL,
152 static const intel_limit_t intel_limits_i9xx_sdvo = {
153 .dot = { .min = 20000, .max = 400000 },
154 .vco = { .min = 1400000, .max = 2800000 },
155 .n = { .min = 1, .max = 6 },
156 .m = { .min = 70, .max = 120 },
157 .m1 = { .min = 8, .max = 18 },
158 .m2 = { .min = 3, .max = 7 },
159 .p = { .min = 5, .max = 80 },
160 .p1 = { .min = 1, .max = 8 },
161 .p2 = { .dot_limit = 200000,
162 .p2_slow = 10, .p2_fast = 5 },
163 .find_pll = intel_find_best_PLL,
166 static const intel_limit_t intel_limits_i9xx_lvds = {
167 .dot = { .min = 20000, .max = 400000 },
168 .vco = { .min = 1400000, .max = 2800000 },
169 .n = { .min = 1, .max = 6 },
170 .m = { .min = 70, .max = 120 },
171 .m1 = { .min = 8, .max = 18 },
172 .m2 = { .min = 3, .max = 7 },
173 .p = { .min = 7, .max = 98 },
174 .p1 = { .min = 1, .max = 8 },
175 .p2 = { .dot_limit = 112000,
176 .p2_slow = 14, .p2_fast = 7 },
177 .find_pll = intel_find_best_PLL,
181 static const intel_limit_t intel_limits_g4x_sdvo = {
182 .dot = { .min = 25000, .max = 270000 },
183 .vco = { .min = 1750000, .max = 3500000},
184 .n = { .min = 1, .max = 4 },
185 .m = { .min = 104, .max = 138 },
186 .m1 = { .min = 17, .max = 23 },
187 .m2 = { .min = 5, .max = 11 },
188 .p = { .min = 10, .max = 30 },
189 .p1 = { .min = 1, .max = 3},
190 .p2 = { .dot_limit = 270000,
194 .find_pll = intel_g4x_find_best_PLL,
197 static const intel_limit_t intel_limits_g4x_hdmi = {
198 .dot = { .min = 22000, .max = 400000 },
199 .vco = { .min = 1750000, .max = 3500000},
200 .n = { .min = 1, .max = 4 },
201 .m = { .min = 104, .max = 138 },
202 .m1 = { .min = 16, .max = 23 },
203 .m2 = { .min = 5, .max = 11 },
204 .p = { .min = 5, .max = 80 },
205 .p1 = { .min = 1, .max = 8},
206 .p2 = { .dot_limit = 165000,
207 .p2_slow = 10, .p2_fast = 5 },
208 .find_pll = intel_g4x_find_best_PLL,
211 static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
212 .dot = { .min = 20000, .max = 115000 },
213 .vco = { .min = 1750000, .max = 3500000 },
214 .n = { .min = 1, .max = 3 },
215 .m = { .min = 104, .max = 138 },
216 .m1 = { .min = 17, .max = 23 },
217 .m2 = { .min = 5, .max = 11 },
218 .p = { .min = 28, .max = 112 },
219 .p1 = { .min = 2, .max = 8 },
220 .p2 = { .dot_limit = 0,
221 .p2_slow = 14, .p2_fast = 14
223 .find_pll = intel_g4x_find_best_PLL,
226 static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
227 .dot = { .min = 80000, .max = 224000 },
228 .vco = { .min = 1750000, .max = 3500000 },
229 .n = { .min = 1, .max = 3 },
230 .m = { .min = 104, .max = 138 },
231 .m1 = { .min = 17, .max = 23 },
232 .m2 = { .min = 5, .max = 11 },
233 .p = { .min = 14, .max = 42 },
234 .p1 = { .min = 2, .max = 6 },
235 .p2 = { .dot_limit = 0,
236 .p2_slow = 7, .p2_fast = 7
238 .find_pll = intel_g4x_find_best_PLL,
241 static const intel_limit_t intel_limits_g4x_display_port = {
242 .dot = { .min = 161670, .max = 227000 },
243 .vco = { .min = 1750000, .max = 3500000},
244 .n = { .min = 1, .max = 2 },
245 .m = { .min = 97, .max = 108 },
246 .m1 = { .min = 0x10, .max = 0x12 },
247 .m2 = { .min = 0x05, .max = 0x06 },
248 .p = { .min = 10, .max = 20 },
249 .p1 = { .min = 1, .max = 2},
250 .p2 = { .dot_limit = 0,
251 .p2_slow = 10, .p2_fast = 10 },
252 .find_pll = intel_find_pll_g4x_dp,
255 static const intel_limit_t intel_limits_pineview_sdvo = {
256 .dot = { .min = 20000, .max = 400000},
257 .vco = { .min = 1700000, .max = 3500000 },
258 /* Pineview's Ncounter is a ring counter */
259 .n = { .min = 3, .max = 6 },
260 .m = { .min = 2, .max = 256 },
261 /* Pineview only has one combined m divider, which we treat as m2. */
262 .m1 = { .min = 0, .max = 0 },
263 .m2 = { .min = 0, .max = 254 },
264 .p = { .min = 5, .max = 80 },
265 .p1 = { .min = 1, .max = 8 },
266 .p2 = { .dot_limit = 200000,
267 .p2_slow = 10, .p2_fast = 5 },
268 .find_pll = intel_find_best_PLL,
271 static const intel_limit_t intel_limits_pineview_lvds = {
272 .dot = { .min = 20000, .max = 400000 },
273 .vco = { .min = 1700000, .max = 3500000 },
274 .n = { .min = 3, .max = 6 },
275 .m = { .min = 2, .max = 256 },
276 .m1 = { .min = 0, .max = 0 },
277 .m2 = { .min = 0, .max = 254 },
278 .p = { .min = 7, .max = 112 },
279 .p1 = { .min = 1, .max = 8 },
280 .p2 = { .dot_limit = 112000,
281 .p2_slow = 14, .p2_fast = 14 },
282 .find_pll = intel_find_best_PLL,
285 /* Ironlake / Sandybridge
287 * We calculate clock using (register_value + 2) for N/M1/M2, so here
288 * the range value for them is (actual_value - 2).
290 static const intel_limit_t intel_limits_ironlake_dac = {
291 .dot = { .min = 25000, .max = 350000 },
292 .vco = { .min = 1760000, .max = 3510000 },
293 .n = { .min = 1, .max = 5 },
294 .m = { .min = 79, .max = 127 },
295 .m1 = { .min = 12, .max = 22 },
296 .m2 = { .min = 5, .max = 9 },
297 .p = { .min = 5, .max = 80 },
298 .p1 = { .min = 1, .max = 8 },
299 .p2 = { .dot_limit = 225000,
300 .p2_slow = 10, .p2_fast = 5 },
301 .find_pll = intel_g4x_find_best_PLL,
304 static const intel_limit_t intel_limits_ironlake_single_lvds = {
305 .dot = { .min = 25000, .max = 350000 },
306 .vco = { .min = 1760000, .max = 3510000 },
307 .n = { .min = 1, .max = 3 },
308 .m = { .min = 79, .max = 118 },
309 .m1 = { .min = 12, .max = 22 },
310 .m2 = { .min = 5, .max = 9 },
311 .p = { .min = 28, .max = 112 },
312 .p1 = { .min = 2, .max = 8 },
313 .p2 = { .dot_limit = 225000,
314 .p2_slow = 14, .p2_fast = 14 },
315 .find_pll = intel_g4x_find_best_PLL,
318 static const intel_limit_t intel_limits_ironlake_dual_lvds = {
319 .dot = { .min = 25000, .max = 350000 },
320 .vco = { .min = 1760000, .max = 3510000 },
321 .n = { .min = 1, .max = 3 },
322 .m = { .min = 79, .max = 127 },
323 .m1 = { .min = 12, .max = 22 },
324 .m2 = { .min = 5, .max = 9 },
325 .p = { .min = 14, .max = 56 },
326 .p1 = { .min = 2, .max = 8 },
327 .p2 = { .dot_limit = 225000,
328 .p2_slow = 7, .p2_fast = 7 },
329 .find_pll = intel_g4x_find_best_PLL,
332 /* LVDS 100mhz refclk limits. */
333 static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
334 .dot = { .min = 25000, .max = 350000 },
335 .vco = { .min = 1760000, .max = 3510000 },
336 .n = { .min = 1, .max = 2 },
337 .m = { .min = 79, .max = 126 },
338 .m1 = { .min = 12, .max = 22 },
339 .m2 = { .min = 5, .max = 9 },
340 .p = { .min = 28, .max = 112 },
341 .p1 = { .min = 2, .max = 8 },
342 .p2 = { .dot_limit = 225000,
343 .p2_slow = 14, .p2_fast = 14 },
344 .find_pll = intel_g4x_find_best_PLL,
347 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
348 .dot = { .min = 25000, .max = 350000 },
349 .vco = { .min = 1760000, .max = 3510000 },
350 .n = { .min = 1, .max = 3 },
351 .m = { .min = 79, .max = 126 },
352 .m1 = { .min = 12, .max = 22 },
353 .m2 = { .min = 5, .max = 9 },
354 .p = { .min = 14, .max = 42 },
355 .p1 = { .min = 2, .max = 6 },
356 .p2 = { .dot_limit = 225000,
357 .p2_slow = 7, .p2_fast = 7 },
358 .find_pll = intel_g4x_find_best_PLL,
361 static const intel_limit_t intel_limits_ironlake_display_port = {
362 .dot = { .min = 25000, .max = 350000 },
363 .vco = { .min = 1760000, .max = 3510000},
364 .n = { .min = 1, .max = 2 },
365 .m = { .min = 81, .max = 90 },
366 .m1 = { .min = 12, .max = 22 },
367 .m2 = { .min = 5, .max = 9 },
368 .p = { .min = 10, .max = 20 },
369 .p1 = { .min = 1, .max = 2},
370 .p2 = { .dot_limit = 0,
371 .p2_slow = 10, .p2_fast = 10 },
372 .find_pll = intel_find_pll_ironlake_dp,
375 static const intel_limit_t intel_limits_vlv_dac = {
376 .dot = { .min = 25000, .max = 270000 },
377 .vco = { .min = 4000000, .max = 6000000 },
378 .n = { .min = 1, .max = 7 },
379 .m = { .min = 22, .max = 450 }, /* guess */
380 .m1 = { .min = 2, .max = 3 },
381 .m2 = { .min = 11, .max = 156 },
382 .p = { .min = 10, .max = 30 },
383 .p1 = { .min = 2, .max = 3 },
384 .p2 = { .dot_limit = 270000,
385 .p2_slow = 2, .p2_fast = 20 },
386 .find_pll = intel_vlv_find_best_pll,
389 static const intel_limit_t intel_limits_vlv_hdmi = {
390 .dot = { .min = 20000, .max = 165000 },
391 .vco = { .min = 4000000, .max = 5994000},
392 .n = { .min = 1, .max = 7 },
393 .m = { .min = 60, .max = 300 }, /* guess */
394 .m1 = { .min = 2, .max = 3 },
395 .m2 = { .min = 11, .max = 156 },
396 .p = { .min = 10, .max = 30 },
397 .p1 = { .min = 2, .max = 3 },
398 .p2 = { .dot_limit = 270000,
399 .p2_slow = 2, .p2_fast = 20 },
400 .find_pll = intel_vlv_find_best_pll,
403 static const intel_limit_t intel_limits_vlv_dp = {
404 .dot = { .min = 25000, .max = 270000 },
405 .vco = { .min = 4000000, .max = 6000000 },
406 .n = { .min = 1, .max = 7 },
407 .m = { .min = 22, .max = 450 },
408 .m1 = { .min = 2, .max = 3 },
409 .m2 = { .min = 11, .max = 156 },
410 .p = { .min = 10, .max = 30 },
411 .p1 = { .min = 2, .max = 3 },
412 .p2 = { .dot_limit = 270000,
413 .p2_slow = 2, .p2_fast = 20 },
414 .find_pll = intel_vlv_find_best_pll,
417 u32 intel_dpio_read(struct drm_i915_private *dev_priv, int reg)
419 WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
421 if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
422 DRM_ERROR("DPIO idle wait timed out\n");
426 I915_WRITE(DPIO_REG, reg);
427 I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_READ | DPIO_PORTID |
429 if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
430 DRM_ERROR("DPIO read wait timed out\n");
434 return I915_READ(DPIO_DATA);
437 static void intel_dpio_write(struct drm_i915_private *dev_priv, int reg,
440 WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
442 if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
443 DRM_ERROR("DPIO idle wait timed out\n");
447 I915_WRITE(DPIO_DATA, val);
448 I915_WRITE(DPIO_REG, reg);
449 I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_WRITE | DPIO_PORTID |
451 if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100))
452 DRM_ERROR("DPIO write wait timed out\n");
455 static void vlv_init_dpio(struct drm_device *dev)
457 struct drm_i915_private *dev_priv = dev->dev_private;
459 /* Reset the DPIO config */
460 I915_WRITE(DPIO_CTL, 0);
461 POSTING_READ(DPIO_CTL);
462 I915_WRITE(DPIO_CTL, 1);
463 POSTING_READ(DPIO_CTL);
466 static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
469 struct drm_device *dev = crtc->dev;
470 const intel_limit_t *limit;
472 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
473 if (intel_is_dual_link_lvds(dev)) {
474 /* LVDS dual channel */
475 if (refclk == 100000)
476 limit = &intel_limits_ironlake_dual_lvds_100m;
478 limit = &intel_limits_ironlake_dual_lvds;
480 if (refclk == 100000)
481 limit = &intel_limits_ironlake_single_lvds_100m;
483 limit = &intel_limits_ironlake_single_lvds;
485 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
486 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
487 limit = &intel_limits_ironlake_display_port;
489 limit = &intel_limits_ironlake_dac;
494 static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
496 struct drm_device *dev = crtc->dev;
497 const intel_limit_t *limit;
499 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
500 if (intel_is_dual_link_lvds(dev))
501 /* LVDS with dual channel */
502 limit = &intel_limits_g4x_dual_channel_lvds;
504 /* LVDS with dual channel */
505 limit = &intel_limits_g4x_single_channel_lvds;
506 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
507 intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
508 limit = &intel_limits_g4x_hdmi;
509 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
510 limit = &intel_limits_g4x_sdvo;
511 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
512 limit = &intel_limits_g4x_display_port;
513 } else /* The option is for other outputs */
514 limit = &intel_limits_i9xx_sdvo;
519 static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
521 struct drm_device *dev = crtc->dev;
522 const intel_limit_t *limit;
524 if (HAS_PCH_SPLIT(dev))
525 limit = intel_ironlake_limit(crtc, refclk);
526 else if (IS_G4X(dev)) {
527 limit = intel_g4x_limit(crtc);
528 } else if (IS_PINEVIEW(dev)) {
529 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
530 limit = &intel_limits_pineview_lvds;
532 limit = &intel_limits_pineview_sdvo;
533 } else if (IS_VALLEYVIEW(dev)) {
534 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG))
535 limit = &intel_limits_vlv_dac;
536 else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
537 limit = &intel_limits_vlv_hdmi;
539 limit = &intel_limits_vlv_dp;
540 } else if (!IS_GEN2(dev)) {
541 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
542 limit = &intel_limits_i9xx_lvds;
544 limit = &intel_limits_i9xx_sdvo;
546 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
547 limit = &intel_limits_i8xx_lvds;
549 limit = &intel_limits_i8xx_dvo;
554 /* m1 is reserved as 0 in Pineview, n is a ring counter */
555 static void pineview_clock(int refclk, intel_clock_t *clock)
557 clock->m = clock->m2 + 2;
558 clock->p = clock->p1 * clock->p2;
559 clock->vco = refclk * clock->m / clock->n;
560 clock->dot = clock->vco / clock->p;
563 static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
565 if (IS_PINEVIEW(dev)) {
566 pineview_clock(refclk, clock);
569 clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
570 clock->p = clock->p1 * clock->p2;
571 clock->vco = refclk * clock->m / (clock->n + 2);
572 clock->dot = clock->vco / clock->p;
576 * Returns whether any output on the specified pipe is of the specified type
578 bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
580 struct drm_device *dev = crtc->dev;
581 struct intel_encoder *encoder;
583 for_each_encoder_on_crtc(dev, crtc, encoder)
584 if (encoder->type == type)
590 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
592 * Returns whether the given set of divisors are valid for a given refclk with
593 * the given connectors.
596 static bool intel_PLL_is_valid(struct drm_device *dev,
597 const intel_limit_t *limit,
598 const intel_clock_t *clock)
600 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
601 INTELPllInvalid("p1 out of range\n");
602 if (clock->p < limit->p.min || limit->p.max < clock->p)
603 INTELPllInvalid("p out of range\n");
604 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
605 INTELPllInvalid("m2 out of range\n");
606 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
607 INTELPllInvalid("m1 out of range\n");
608 if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev))
609 INTELPllInvalid("m1 <= m2\n");
610 if (clock->m < limit->m.min || limit->m.max < clock->m)
611 INTELPllInvalid("m out of range\n");
612 if (clock->n < limit->n.min || limit->n.max < clock->n)
613 INTELPllInvalid("n out of range\n");
614 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
615 INTELPllInvalid("vco out of range\n");
616 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
617 * connector, etc., rather than just a single range.
619 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
620 INTELPllInvalid("dot out of range\n");
626 intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
627 int target, int refclk, intel_clock_t *match_clock,
628 intel_clock_t *best_clock)
631 struct drm_device *dev = crtc->dev;
635 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
637 * For LVDS just rely on its current settings for dual-channel.
638 * We haven't figured out how to reliably set up different
639 * single/dual channel state, if we even can.
641 if (intel_is_dual_link_lvds(dev))
642 clock.p2 = limit->p2.p2_fast;
644 clock.p2 = limit->p2.p2_slow;
646 if (target < limit->p2.dot_limit)
647 clock.p2 = limit->p2.p2_slow;
649 clock.p2 = limit->p2.p2_fast;
652 memset(best_clock, 0, sizeof(*best_clock));
654 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
656 for (clock.m2 = limit->m2.min;
657 clock.m2 <= limit->m2.max; clock.m2++) {
658 /* m1 is always 0 in Pineview */
659 if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev))
661 for (clock.n = limit->n.min;
662 clock.n <= limit->n.max; clock.n++) {
663 for (clock.p1 = limit->p1.min;
664 clock.p1 <= limit->p1.max; clock.p1++) {
667 intel_clock(dev, refclk, &clock);
668 if (!intel_PLL_is_valid(dev, limit,
672 clock.p != match_clock->p)
675 this_err = abs(clock.dot - target);
676 if (this_err < err) {
685 return (err != target);
689 intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
690 int target, int refclk, intel_clock_t *match_clock,
691 intel_clock_t *best_clock)
693 struct drm_device *dev = crtc->dev;
697 /* approximately equals target * 0.00585 */
698 int err_most = (target >> 8) + (target >> 9);
701 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
704 if (HAS_PCH_SPLIT(dev))
708 if (intel_is_dual_link_lvds(dev))
709 clock.p2 = limit->p2.p2_fast;
711 clock.p2 = limit->p2.p2_slow;
713 if (target < limit->p2.dot_limit)
714 clock.p2 = limit->p2.p2_slow;
716 clock.p2 = limit->p2.p2_fast;
719 memset(best_clock, 0, sizeof(*best_clock));
720 max_n = limit->n.max;
721 /* based on hardware requirement, prefer smaller n to precision */
722 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
723 /* based on hardware requirement, prefere larger m1,m2 */
724 for (clock.m1 = limit->m1.max;
725 clock.m1 >= limit->m1.min; clock.m1--) {
726 for (clock.m2 = limit->m2.max;
727 clock.m2 >= limit->m2.min; clock.m2--) {
728 for (clock.p1 = limit->p1.max;
729 clock.p1 >= limit->p1.min; clock.p1--) {
732 intel_clock(dev, refclk, &clock);
733 if (!intel_PLL_is_valid(dev, limit,
737 clock.p != match_clock->p)
740 this_err = abs(clock.dot - target);
741 if (this_err < err_most) {
755 intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
756 int target, int refclk, intel_clock_t *match_clock,
757 intel_clock_t *best_clock)
759 struct drm_device *dev = crtc->dev;
762 if (target < 200000) {
775 intel_clock(dev, refclk, &clock);
776 memcpy(best_clock, &clock, sizeof(intel_clock_t));
780 /* DisplayPort has only two frequencies, 162MHz and 270MHz */
782 intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
783 int target, int refclk, intel_clock_t *match_clock,
784 intel_clock_t *best_clock)
787 if (target < 200000) {
800 clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
801 clock.p = (clock.p1 * clock.p2);
802 clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
804 memcpy(best_clock, &clock, sizeof(intel_clock_t));
808 intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc,
809 int target, int refclk, intel_clock_t *match_clock,
810 intel_clock_t *best_clock)
812 u32 p1, p2, m1, m2, vco, bestn, bestm1, bestm2, bestp1, bestp2;
814 u32 updrate, minupdate, fracbits, p;
815 unsigned long bestppm, ppm, absppm;
819 dotclk = target * 1000;
822 fastclk = dotclk / (2*100);
826 n = p = p1 = p2 = m = m1 = m2 = vco = bestn = 0;
827 bestm1 = bestm2 = bestp1 = bestp2 = 0;
829 /* based on hardware requirement, prefer smaller n to precision */
830 for (n = limit->n.min; n <= ((refclk) / minupdate); n++) {
831 updrate = refclk / n;
832 for (p1 = limit->p1.max; p1 > limit->p1.min; p1--) {
833 for (p2 = limit->p2.p2_fast+1; p2 > 0; p2--) {
837 /* based on hardware requirement, prefer bigger m1,m2 values */
838 for (m1 = limit->m1.min; m1 <= limit->m1.max; m1++) {
839 m2 = (((2*(fastclk * p * n / m1 )) +
840 refclk) / (2*refclk));
843 if (vco >= limit->vco.min && vco < limit->vco.max) {
844 ppm = 1000000 * ((vco / p) - fastclk) / fastclk;
845 absppm = (ppm > 0) ? ppm : (-ppm);
846 if (absppm < 100 && ((p1 * p2) > (bestp1 * bestp2))) {
850 if (absppm < bestppm - 10) {
867 best_clock->n = bestn;
868 best_clock->m1 = bestm1;
869 best_clock->m2 = bestm2;
870 best_clock->p1 = bestp1;
871 best_clock->p2 = bestp2;
876 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
879 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
880 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
882 return intel_crtc->cpu_transcoder;
885 static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe)
887 struct drm_i915_private *dev_priv = dev->dev_private;
888 u32 frame, frame_reg = PIPEFRAME(pipe);
890 frame = I915_READ(frame_reg);
892 if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
893 DRM_DEBUG_KMS("vblank wait timed out\n");
897 * intel_wait_for_vblank - wait for vblank on a given pipe
899 * @pipe: pipe to wait for
901 * Wait for vblank to occur on a given pipe. Needed for various bits of
904 void intel_wait_for_vblank(struct drm_device *dev, int pipe)
906 struct drm_i915_private *dev_priv = dev->dev_private;
907 int pipestat_reg = PIPESTAT(pipe);
909 if (INTEL_INFO(dev)->gen >= 5) {
910 ironlake_wait_for_vblank(dev, pipe);
914 /* Clear existing vblank status. Note this will clear any other
915 * sticky status fields as well.
917 * This races with i915_driver_irq_handler() with the result
918 * that either function could miss a vblank event. Here it is not
919 * fatal, as we will either wait upon the next vblank interrupt or
920 * timeout. Generally speaking intel_wait_for_vblank() is only
921 * called during modeset at which time the GPU should be idle and
922 * should *not* be performing page flips and thus not waiting on
924 * Currently, the result of us stealing a vblank from the irq
925 * handler is that a single frame will be skipped during swapbuffers.
927 I915_WRITE(pipestat_reg,
928 I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
930 /* Wait for vblank interrupt bit to set */
931 if (wait_for(I915_READ(pipestat_reg) &
932 PIPE_VBLANK_INTERRUPT_STATUS,
934 DRM_DEBUG_KMS("vblank wait timed out\n");
938 * intel_wait_for_pipe_off - wait for pipe to turn off
940 * @pipe: pipe to wait for
942 * After disabling a pipe, we can't wait for vblank in the usual way,
943 * spinning on the vblank interrupt status bit, since we won't actually
944 * see an interrupt when the pipe is disabled.
947 * wait for the pipe register state bit to turn off
950 * wait for the display line value to settle (it usually
951 * ends up stopping at the start of the next frame).
954 void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
956 struct drm_i915_private *dev_priv = dev->dev_private;
957 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
960 if (INTEL_INFO(dev)->gen >= 4) {
961 int reg = PIPECONF(cpu_transcoder);
963 /* Wait for the Pipe State to go off */
964 if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
966 WARN(1, "pipe_off wait timed out\n");
968 u32 last_line, line_mask;
969 int reg = PIPEDSL(pipe);
970 unsigned long timeout = jiffies + msecs_to_jiffies(100);
973 line_mask = DSL_LINEMASK_GEN2;
975 line_mask = DSL_LINEMASK_GEN3;
977 /* Wait for the display line to settle */
979 last_line = I915_READ(reg) & line_mask;
981 } while (((I915_READ(reg) & line_mask) != last_line) &&
982 time_after(timeout, jiffies));
983 if (time_after(jiffies, timeout))
984 WARN(1, "pipe_off wait timed out\n");
989 * ibx_digital_port_connected - is the specified port connected?
990 * @dev_priv: i915 private structure
991 * @port: the port to test
993 * Returns true if @port is connected, false otherwise.
995 bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
996 struct intel_digital_port *port)
1000 if (HAS_PCH_IBX(dev_priv->dev)) {
1001 switch(port->port) {
1003 bit = SDE_PORTB_HOTPLUG;
1006 bit = SDE_PORTC_HOTPLUG;
1009 bit = SDE_PORTD_HOTPLUG;
1015 switch(port->port) {
1017 bit = SDE_PORTB_HOTPLUG_CPT;
1020 bit = SDE_PORTC_HOTPLUG_CPT;
1023 bit = SDE_PORTD_HOTPLUG_CPT;
1030 return I915_READ(SDEISR) & bit;
1033 static const char *state_string(bool enabled)
1035 return enabled ? "on" : "off";
1038 /* Only for pre-ILK configs */
1039 static void assert_pll(struct drm_i915_private *dev_priv,
1040 enum pipe pipe, bool state)
1047 val = I915_READ(reg);
1048 cur_state = !!(val & DPLL_VCO_ENABLE);
1049 WARN(cur_state != state,
1050 "PLL state assertion failure (expected %s, current %s)\n",
1051 state_string(state), state_string(cur_state));
1053 #define assert_pll_enabled(d, p) assert_pll(d, p, true)
1054 #define assert_pll_disabled(d, p) assert_pll(d, p, false)
1057 static void assert_pch_pll(struct drm_i915_private *dev_priv,
1058 struct intel_pch_pll *pll,
1059 struct intel_crtc *crtc,
1065 if (HAS_PCH_LPT(dev_priv->dev)) {
1066 DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
1071 "asserting PCH PLL %s with no PLL\n", state_string(state)))
1074 val = I915_READ(pll->pll_reg);
1075 cur_state = !!(val & DPLL_VCO_ENABLE);
1076 WARN(cur_state != state,
1077 "PCH PLL state for reg %x assertion failure (expected %s, current %s), val=%08x\n",
1078 pll->pll_reg, state_string(state), state_string(cur_state), val);
1080 /* Make sure the selected PLL is correctly attached to the transcoder */
1081 if (crtc && HAS_PCH_CPT(dev_priv->dev)) {
1084 pch_dpll = I915_READ(PCH_DPLL_SEL);
1085 cur_state = pll->pll_reg == _PCH_DPLL_B;
1086 if (!WARN(((pch_dpll >> (4 * crtc->pipe)) & 1) != cur_state,
1087 "PLL[%d] not attached to this transcoder %d: %08x\n",
1088 cur_state, crtc->pipe, pch_dpll)) {
1089 cur_state = !!(val >> (4*crtc->pipe + 3));
1090 WARN(cur_state != state,
1091 "PLL[%d] not %s on this transcoder %d: %08x\n",
1092 pll->pll_reg == _PCH_DPLL_B,
1093 state_string(state),
1099 #define assert_pch_pll_enabled(d, p, c) assert_pch_pll(d, p, c, true)
1100 #define assert_pch_pll_disabled(d, p, c) assert_pch_pll(d, p, c, false)
1102 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1103 enum pipe pipe, bool state)
1108 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1111 if (HAS_DDI(dev_priv->dev)) {
1112 /* DDI does not have a specific FDI_TX register */
1113 reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
1114 val = I915_READ(reg);
1115 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1117 reg = FDI_TX_CTL(pipe);
1118 val = I915_READ(reg);
1119 cur_state = !!(val & FDI_TX_ENABLE);
1121 WARN(cur_state != state,
1122 "FDI TX state assertion failure (expected %s, current %s)\n",
1123 state_string(state), state_string(cur_state));
1125 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1126 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1128 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1129 enum pipe pipe, bool state)
1135 reg = FDI_RX_CTL(pipe);
1136 val = I915_READ(reg);
1137 cur_state = !!(val & FDI_RX_ENABLE);
1138 WARN(cur_state != state,
1139 "FDI RX state assertion failure (expected %s, current %s)\n",
1140 state_string(state), state_string(cur_state));
1142 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1143 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1145 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1151 /* ILK FDI PLL is always enabled */
1152 if (dev_priv->info->gen == 5)
1155 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1156 if (HAS_DDI(dev_priv->dev))
1159 reg = FDI_TX_CTL(pipe);
1160 val = I915_READ(reg);
1161 WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1164 static void assert_fdi_rx_pll_enabled(struct drm_i915_private *dev_priv,
1170 reg = FDI_RX_CTL(pipe);
1171 val = I915_READ(reg);
1172 WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n");
1175 static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
1178 int pp_reg, lvds_reg;
1180 enum pipe panel_pipe = PIPE_A;
1183 if (HAS_PCH_SPLIT(dev_priv->dev)) {
1184 pp_reg = PCH_PP_CONTROL;
1185 lvds_reg = PCH_LVDS;
1187 pp_reg = PP_CONTROL;
1191 val = I915_READ(pp_reg);
1192 if (!(val & PANEL_POWER_ON) ||
1193 ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
1196 if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
1197 panel_pipe = PIPE_B;
1199 WARN(panel_pipe == pipe && locked,
1200 "panel assertion failure, pipe %c regs locked\n",
1204 void assert_pipe(struct drm_i915_private *dev_priv,
1205 enum pipe pipe, bool state)
1210 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1213 /* if we need the pipe A quirk it must be always on */
1214 if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
1217 if (IS_HASWELL(dev_priv->dev) && cpu_transcoder != TRANSCODER_EDP &&
1218 !(I915_READ(HSW_PWR_WELL_DRIVER) & HSW_PWR_WELL_ENABLE)) {
1221 reg = PIPECONF(cpu_transcoder);
1222 val = I915_READ(reg);
1223 cur_state = !!(val & PIPECONF_ENABLE);
1226 WARN(cur_state != state,
1227 "pipe %c assertion failure (expected %s, current %s)\n",
1228 pipe_name(pipe), state_string(state), state_string(cur_state));
1231 static void assert_plane(struct drm_i915_private *dev_priv,
1232 enum plane plane, bool state)
1238 reg = DSPCNTR(plane);
1239 val = I915_READ(reg);
1240 cur_state = !!(val & DISPLAY_PLANE_ENABLE);
1241 WARN(cur_state != state,
1242 "plane %c assertion failure (expected %s, current %s)\n",
1243 plane_name(plane), state_string(state), state_string(cur_state));
1246 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1247 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1249 static void assert_planes_disabled(struct drm_i915_private *dev_priv,
1256 /* Planes are fixed to pipes on ILK+ */
1257 if (HAS_PCH_SPLIT(dev_priv->dev)) {
1258 reg = DSPCNTR(pipe);
1259 val = I915_READ(reg);
1260 WARN((val & DISPLAY_PLANE_ENABLE),
1261 "plane %c assertion failure, should be disabled but not\n",
1266 /* Need to check both planes against the pipe */
1267 for (i = 0; i < 2; i++) {
1269 val = I915_READ(reg);
1270 cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
1271 DISPPLANE_SEL_PIPE_SHIFT;
1272 WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
1273 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1274 plane_name(i), pipe_name(pipe));
1278 static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
1283 if (HAS_PCH_LPT(dev_priv->dev)) {
1284 DRM_DEBUG_DRIVER("LPT does not has PCH refclk, skipping check\n");
1288 val = I915_READ(PCH_DREF_CONTROL);
1289 enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
1290 DREF_SUPERSPREAD_SOURCE_MASK));
1291 WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
1294 static void assert_transcoder_disabled(struct drm_i915_private *dev_priv,
1301 reg = TRANSCONF(pipe);
1302 val = I915_READ(reg);
1303 enabled = !!(val & TRANS_ENABLE);
1305 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1309 static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
1310 enum pipe pipe, u32 port_sel, u32 val)
1312 if ((val & DP_PORT_EN) == 0)
1315 if (HAS_PCH_CPT(dev_priv->dev)) {
1316 u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
1317 u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
1318 if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
1321 if ((val & DP_PIPE_MASK) != (pipe << 30))
1327 static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
1328 enum pipe pipe, u32 val)
1330 if ((val & PORT_ENABLE) == 0)
1333 if (HAS_PCH_CPT(dev_priv->dev)) {
1334 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1337 if ((val & TRANSCODER_MASK) != TRANSCODER(pipe))
1343 static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
1344 enum pipe pipe, u32 val)
1346 if ((val & LVDS_PORT_EN) == 0)
1349 if (HAS_PCH_CPT(dev_priv->dev)) {
1350 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1353 if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
1359 static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
1360 enum pipe pipe, u32 val)
1362 if ((val & ADPA_DAC_ENABLE) == 0)
1364 if (HAS_PCH_CPT(dev_priv->dev)) {
1365 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1368 if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
1374 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1375 enum pipe pipe, int reg, u32 port_sel)
1377 u32 val = I915_READ(reg);
1378 WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
1379 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1380 reg, pipe_name(pipe));
1382 WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
1383 && (val & DP_PIPEB_SELECT),
1384 "IBX PCH dp port still using transcoder B\n");
1387 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1388 enum pipe pipe, int reg)
1390 u32 val = I915_READ(reg);
1391 WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
1392 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1393 reg, pipe_name(pipe));
1395 WARN(HAS_PCH_IBX(dev_priv->dev) && (val & PORT_ENABLE) == 0
1396 && (val & SDVO_PIPE_B_SELECT),
1397 "IBX PCH hdmi port still using transcoder B\n");
1400 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1406 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
1407 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
1408 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
1411 val = I915_READ(reg);
1412 WARN(adpa_pipe_enabled(dev_priv, pipe, val),
1413 "PCH VGA enabled on transcoder %c, should be disabled\n",
1417 val = I915_READ(reg);
1418 WARN(lvds_pipe_enabled(dev_priv, pipe, val),
1419 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1422 assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB);
1423 assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC);
1424 assert_pch_hdmi_disabled(dev_priv, pipe, HDMID);
1428 * intel_enable_pll - enable a PLL
1429 * @dev_priv: i915 private structure
1430 * @pipe: pipe PLL to enable
1432 * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to
1433 * make sure the PLL reg is writable first though, since the panel write
1434 * protect mechanism may be enabled.
1436 * Note! This is for pre-ILK only.
1438 * Unfortunately needed by dvo_ns2501 since the dvo depends on it running.
1440 static void intel_enable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1445 /* No really, not for ILK+ */
1446 BUG_ON(!IS_VALLEYVIEW(dev_priv->dev) && dev_priv->info->gen >= 5);
1448 /* PLL is protected by panel, make sure we can write it */
1449 if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
1450 assert_panel_unlocked(dev_priv, pipe);
1453 val = I915_READ(reg);
1454 val |= DPLL_VCO_ENABLE;
1456 /* We do this three times for luck */
1457 I915_WRITE(reg, val);
1459 udelay(150); /* wait for warmup */
1460 I915_WRITE(reg, val);
1462 udelay(150); /* wait for warmup */
1463 I915_WRITE(reg, val);
1465 udelay(150); /* wait for warmup */
1469 * intel_disable_pll - disable a PLL
1470 * @dev_priv: i915 private structure
1471 * @pipe: pipe PLL to disable
1473 * Disable the PLL for @pipe, making sure the pipe is off first.
1475 * Note! This is for pre-ILK only.
1477 static void intel_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1482 /* Don't disable pipe A or pipe A PLLs if needed */
1483 if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
1486 /* Make sure the pipe isn't still relying on us */
1487 assert_pipe_disabled(dev_priv, pipe);
1490 val = I915_READ(reg);
1491 val &= ~DPLL_VCO_ENABLE;
1492 I915_WRITE(reg, val);
1498 intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
1499 enum intel_sbi_destination destination)
1503 WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
1505 if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0,
1507 DRM_ERROR("timeout waiting for SBI to become ready\n");
1511 I915_WRITE(SBI_ADDR, (reg << 16));
1512 I915_WRITE(SBI_DATA, value);
1514 if (destination == SBI_ICLK)
1515 tmp = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRWR;
1517 tmp = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IOWR;
1518 I915_WRITE(SBI_CTL_STAT, SBI_BUSY | tmp);
1520 if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0,
1522 DRM_ERROR("timeout waiting for SBI to complete write transaction\n");
1528 intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
1529 enum intel_sbi_destination destination)
1532 WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
1534 if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0,
1536 DRM_ERROR("timeout waiting for SBI to become ready\n");
1540 I915_WRITE(SBI_ADDR, (reg << 16));
1542 if (destination == SBI_ICLK)
1543 value = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRRD;
1545 value = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IORD;
1546 I915_WRITE(SBI_CTL_STAT, value | SBI_BUSY);
1548 if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0,
1550 DRM_ERROR("timeout waiting for SBI to complete read transaction\n");
1554 return I915_READ(SBI_DATA);
1558 * ironlake_enable_pch_pll - enable PCH PLL
1559 * @dev_priv: i915 private structure
1560 * @pipe: pipe PLL to enable
1562 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1563 * drives the transcoder clock.
1565 static void ironlake_enable_pch_pll(struct intel_crtc *intel_crtc)
1567 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
1568 struct intel_pch_pll *pll;
1572 /* PCH PLLs only available on ILK, SNB and IVB */
1573 BUG_ON(dev_priv->info->gen < 5);
1574 pll = intel_crtc->pch_pll;
1578 if (WARN_ON(pll->refcount == 0))
1581 DRM_DEBUG_KMS("enable PCH PLL %x (active %d, on? %d)for crtc %d\n",
1582 pll->pll_reg, pll->active, pll->on,
1583 intel_crtc->base.base.id);
1585 /* PCH refclock must be enabled first */
1586 assert_pch_refclk_enabled(dev_priv);
1588 if (pll->active++ && pll->on) {
1589 assert_pch_pll_enabled(dev_priv, pll, NULL);
1593 DRM_DEBUG_KMS("enabling PCH PLL %x\n", pll->pll_reg);
1596 val = I915_READ(reg);
1597 val |= DPLL_VCO_ENABLE;
1598 I915_WRITE(reg, val);
1605 static void intel_disable_pch_pll(struct intel_crtc *intel_crtc)
1607 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
1608 struct intel_pch_pll *pll = intel_crtc->pch_pll;
1612 /* PCH only available on ILK+ */
1613 BUG_ON(dev_priv->info->gen < 5);
1617 if (WARN_ON(pll->refcount == 0))
1620 DRM_DEBUG_KMS("disable PCH PLL %x (active %d, on? %d) for crtc %d\n",
1621 pll->pll_reg, pll->active, pll->on,
1622 intel_crtc->base.base.id);
1624 if (WARN_ON(pll->active == 0)) {
1625 assert_pch_pll_disabled(dev_priv, pll, NULL);
1629 if (--pll->active) {
1630 assert_pch_pll_enabled(dev_priv, pll, NULL);
1634 DRM_DEBUG_KMS("disabling PCH PLL %x\n", pll->pll_reg);
1636 /* Make sure transcoder isn't still depending on us */
1637 assert_transcoder_disabled(dev_priv, intel_crtc->pipe);
1640 val = I915_READ(reg);
1641 val &= ~DPLL_VCO_ENABLE;
1642 I915_WRITE(reg, val);
1649 static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1652 struct drm_device *dev = dev_priv->dev;
1653 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1654 uint32_t reg, val, pipeconf_val;
1656 /* PCH only available on ILK+ */
1657 BUG_ON(dev_priv->info->gen < 5);
1659 /* Make sure PCH DPLL is enabled */
1660 assert_pch_pll_enabled(dev_priv,
1661 to_intel_crtc(crtc)->pch_pll,
1662 to_intel_crtc(crtc));
1664 /* FDI must be feeding us bits for PCH ports */
1665 assert_fdi_tx_enabled(dev_priv, pipe);
1666 assert_fdi_rx_enabled(dev_priv, pipe);
1668 if (HAS_PCH_CPT(dev)) {
1669 /* Workaround: Set the timing override bit before enabling the
1670 * pch transcoder. */
1671 reg = TRANS_CHICKEN2(pipe);
1672 val = I915_READ(reg);
1673 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1674 I915_WRITE(reg, val);
1677 reg = TRANSCONF(pipe);
1678 val = I915_READ(reg);
1679 pipeconf_val = I915_READ(PIPECONF(pipe));
1681 if (HAS_PCH_IBX(dev_priv->dev)) {
1683 * make the BPC in transcoder be consistent with
1684 * that in pipeconf reg.
1686 val &= ~PIPECONF_BPC_MASK;
1687 val |= pipeconf_val & PIPECONF_BPC_MASK;
1690 val &= ~TRANS_INTERLACE_MASK;
1691 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
1692 if (HAS_PCH_IBX(dev_priv->dev) &&
1693 intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
1694 val |= TRANS_LEGACY_INTERLACED_ILK;
1696 val |= TRANS_INTERLACED;
1698 val |= TRANS_PROGRESSIVE;
1700 I915_WRITE(reg, val | TRANS_ENABLE);
1701 if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
1702 DRM_ERROR("failed to enable transcoder %d\n", pipe);
1705 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1706 enum transcoder cpu_transcoder)
1708 u32 val, pipeconf_val;
1710 /* PCH only available on ILK+ */
1711 BUG_ON(dev_priv->info->gen < 5);
1713 /* FDI must be feeding us bits for PCH ports */
1714 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
1715 assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
1717 /* Workaround: set timing override bit. */
1718 val = I915_READ(_TRANSA_CHICKEN2);
1719 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1720 I915_WRITE(_TRANSA_CHICKEN2, val);
1723 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1725 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1726 PIPECONF_INTERLACED_ILK)
1727 val |= TRANS_INTERLACED;
1729 val |= TRANS_PROGRESSIVE;
1731 I915_WRITE(TRANSCONF(TRANSCODER_A), val);
1732 if (wait_for(I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE, 100))
1733 DRM_ERROR("Failed to enable PCH transcoder\n");
1736 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1739 struct drm_device *dev = dev_priv->dev;
1742 /* FDI relies on the transcoder */
1743 assert_fdi_tx_disabled(dev_priv, pipe);
1744 assert_fdi_rx_disabled(dev_priv, pipe);
1746 /* Ports must be off as well */
1747 assert_pch_ports_disabled(dev_priv, pipe);
1749 reg = TRANSCONF(pipe);
1750 val = I915_READ(reg);
1751 val &= ~TRANS_ENABLE;
1752 I915_WRITE(reg, val);
1753 /* wait for PCH transcoder off, transcoder state */
1754 if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
1755 DRM_ERROR("failed to disable transcoder %d\n", pipe);
1757 if (!HAS_PCH_IBX(dev)) {
1758 /* Workaround: Clear the timing override chicken bit again. */
1759 reg = TRANS_CHICKEN2(pipe);
1760 val = I915_READ(reg);
1761 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1762 I915_WRITE(reg, val);
1766 static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1770 val = I915_READ(_TRANSACONF);
1771 val &= ~TRANS_ENABLE;
1772 I915_WRITE(_TRANSACONF, val);
1773 /* wait for PCH transcoder off, transcoder state */
1774 if (wait_for((I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE) == 0, 50))
1775 DRM_ERROR("Failed to disable PCH transcoder\n");
1777 /* Workaround: clear timing override bit. */
1778 val = I915_READ(_TRANSA_CHICKEN2);
1779 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1780 I915_WRITE(_TRANSA_CHICKEN2, val);
1784 * intel_enable_pipe - enable a pipe, asserting requirements
1785 * @dev_priv: i915 private structure
1786 * @pipe: pipe to enable
1787 * @pch_port: on ILK+, is this pipe driving a PCH port or not
1789 * Enable @pipe, making sure that various hardware specific requirements
1790 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1792 * @pipe should be %PIPE_A or %PIPE_B.
1794 * Will wait until the pipe is actually running (i.e. first vblank) before
1797 static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
1800 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1802 enum pipe pch_transcoder;
1806 if (HAS_PCH_LPT(dev_priv->dev))
1807 pch_transcoder = TRANSCODER_A;
1809 pch_transcoder = pipe;
1812 * A pipe without a PLL won't actually be able to drive bits from
1813 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1816 if (!HAS_PCH_SPLIT(dev_priv->dev))
1817 assert_pll_enabled(dev_priv, pipe);
1820 /* if driving the PCH, we need FDI enabled */
1821 assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
1822 assert_fdi_tx_pll_enabled(dev_priv,
1823 (enum pipe) cpu_transcoder);
1825 /* FIXME: assert CPU port conditions for SNB+ */
1828 reg = PIPECONF(cpu_transcoder);
1829 val = I915_READ(reg);
1830 if (val & PIPECONF_ENABLE)
1833 I915_WRITE(reg, val | PIPECONF_ENABLE);
1834 intel_wait_for_vblank(dev_priv->dev, pipe);
1838 * intel_disable_pipe - disable a pipe, asserting requirements
1839 * @dev_priv: i915 private structure
1840 * @pipe: pipe to disable
1842 * Disable @pipe, making sure that various hardware specific requirements
1843 * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
1845 * @pipe should be %PIPE_A or %PIPE_B.
1847 * Will wait until the pipe has shut down before returning.
1849 static void intel_disable_pipe(struct drm_i915_private *dev_priv,
1852 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1858 * Make sure planes won't keep trying to pump pixels to us,
1859 * or we might hang the display.
1861 assert_planes_disabled(dev_priv, pipe);
1863 /* Don't disable pipe A or pipe A PLLs if needed */
1864 if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
1867 reg = PIPECONF(cpu_transcoder);
1868 val = I915_READ(reg);
1869 if ((val & PIPECONF_ENABLE) == 0)
1872 I915_WRITE(reg, val & ~PIPECONF_ENABLE);
1873 intel_wait_for_pipe_off(dev_priv->dev, pipe);
1877 * Plane regs are double buffered, going from enabled->disabled needs a
1878 * trigger in order to latch. The display address reg provides this.
1880 void intel_flush_display_plane(struct drm_i915_private *dev_priv,
1883 if (dev_priv->info->gen >= 4)
1884 I915_WRITE(DSPSURF(plane), I915_READ(DSPSURF(plane)));
1886 I915_WRITE(DSPADDR(plane), I915_READ(DSPADDR(plane)));
1890 * intel_enable_plane - enable a display plane on a given pipe
1891 * @dev_priv: i915 private structure
1892 * @plane: plane to enable
1893 * @pipe: pipe being fed
1895 * Enable @plane on @pipe, making sure that @pipe is running first.
1897 static void intel_enable_plane(struct drm_i915_private *dev_priv,
1898 enum plane plane, enum pipe pipe)
1903 /* If the pipe isn't enabled, we can't pump pixels and may hang */
1904 assert_pipe_enabled(dev_priv, pipe);
1906 reg = DSPCNTR(plane);
1907 val = I915_READ(reg);
1908 if (val & DISPLAY_PLANE_ENABLE)
1911 I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
1912 intel_flush_display_plane(dev_priv, plane);
1913 intel_wait_for_vblank(dev_priv->dev, pipe);
1917 * intel_disable_plane - disable a display plane
1918 * @dev_priv: i915 private structure
1919 * @plane: plane to disable
1920 * @pipe: pipe consuming the data
1922 * Disable @plane; should be an independent operation.
1924 static void intel_disable_plane(struct drm_i915_private *dev_priv,
1925 enum plane plane, enum pipe pipe)
1930 reg = DSPCNTR(plane);
1931 val = I915_READ(reg);
1932 if ((val & DISPLAY_PLANE_ENABLE) == 0)
1935 I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
1936 intel_flush_display_plane(dev_priv, plane);
1937 intel_wait_for_vblank(dev_priv->dev, pipe);
1941 intel_pin_and_fence_fb_obj(struct drm_device *dev,
1942 struct drm_i915_gem_object *obj,
1943 struct intel_ring_buffer *pipelined)
1945 struct drm_i915_private *dev_priv = dev->dev_private;
1949 switch (obj->tiling_mode) {
1950 case I915_TILING_NONE:
1951 if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
1952 alignment = 128 * 1024;
1953 else if (INTEL_INFO(dev)->gen >= 4)
1954 alignment = 4 * 1024;
1956 alignment = 64 * 1024;
1959 /* pin() will align the object as required by fence */
1963 /* FIXME: Is this true? */
1964 DRM_ERROR("Y tiled not allowed for scan out buffers\n");
1970 dev_priv->mm.interruptible = false;
1971 ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
1973 goto err_interruptible;
1975 /* Install a fence for tiled scan-out. Pre-i965 always needs a
1976 * fence, whereas 965+ only requires a fence if using
1977 * framebuffer compression. For simplicity, we always install
1978 * a fence as the cost is not that onerous.
1980 ret = i915_gem_object_get_fence(obj);
1984 i915_gem_object_pin_fence(obj);
1986 dev_priv->mm.interruptible = true;
1990 i915_gem_object_unpin(obj);
1992 dev_priv->mm.interruptible = true;
1996 void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
1998 i915_gem_object_unpin_fence(obj);
1999 i915_gem_object_unpin(obj);
2002 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2003 * is assumed to be a power-of-two. */
2004 unsigned long intel_gen4_compute_page_offset(int *x, int *y,
2005 unsigned int tiling_mode,
2009 if (tiling_mode != I915_TILING_NONE) {
2010 unsigned int tile_rows, tiles;
2015 tiles = *x / (512/cpp);
2018 return tile_rows * pitch * 8 + tiles * 4096;
2020 unsigned int offset;
2022 offset = *y * pitch + *x * cpp;
2024 *x = (offset & 4095) / cpp;
2025 return offset & -4096;
2029 static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
2032 struct drm_device *dev = crtc->dev;
2033 struct drm_i915_private *dev_priv = dev->dev_private;
2034 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2035 struct intel_framebuffer *intel_fb;
2036 struct drm_i915_gem_object *obj;
2037 int plane = intel_crtc->plane;
2038 unsigned long linear_offset;
2047 DRM_ERROR("Can't update plane %d in SAREA\n", plane);
2051 intel_fb = to_intel_framebuffer(fb);
2052 obj = intel_fb->obj;
2054 reg = DSPCNTR(plane);
2055 dspcntr = I915_READ(reg);
2056 /* Mask out pixel format bits in case we change it */
2057 dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
2058 switch (fb->pixel_format) {
2060 dspcntr |= DISPPLANE_8BPP;
2062 case DRM_FORMAT_XRGB1555:
2063 case DRM_FORMAT_ARGB1555:
2064 dspcntr |= DISPPLANE_BGRX555;
2066 case DRM_FORMAT_RGB565:
2067 dspcntr |= DISPPLANE_BGRX565;
2069 case DRM_FORMAT_XRGB8888:
2070 case DRM_FORMAT_ARGB8888:
2071 dspcntr |= DISPPLANE_BGRX888;
2073 case DRM_FORMAT_XBGR8888:
2074 case DRM_FORMAT_ABGR8888:
2075 dspcntr |= DISPPLANE_RGBX888;
2077 case DRM_FORMAT_XRGB2101010:
2078 case DRM_FORMAT_ARGB2101010:
2079 dspcntr |= DISPPLANE_BGRX101010;
2081 case DRM_FORMAT_XBGR2101010:
2082 case DRM_FORMAT_ABGR2101010:
2083 dspcntr |= DISPPLANE_RGBX101010;
2086 DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
2090 if (INTEL_INFO(dev)->gen >= 4) {
2091 if (obj->tiling_mode != I915_TILING_NONE)
2092 dspcntr |= DISPPLANE_TILED;
2094 dspcntr &= ~DISPPLANE_TILED;
2097 I915_WRITE(reg, dspcntr);
2099 linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
2101 if (INTEL_INFO(dev)->gen >= 4) {
2102 intel_crtc->dspaddr_offset =
2103 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
2104 fb->bits_per_pixel / 8,
2106 linear_offset -= intel_crtc->dspaddr_offset;
2108 intel_crtc->dspaddr_offset = linear_offset;
2111 DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
2112 obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
2113 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
2114 if (INTEL_INFO(dev)->gen >= 4) {
2115 I915_MODIFY_DISPBASE(DSPSURF(plane),
2116 obj->gtt_offset + intel_crtc->dspaddr_offset);
2117 I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
2118 I915_WRITE(DSPLINOFF(plane), linear_offset);
2120 I915_WRITE(DSPADDR(plane), obj->gtt_offset + linear_offset);
2126 static int ironlake_update_plane(struct drm_crtc *crtc,
2127 struct drm_framebuffer *fb, int x, int y)
2129 struct drm_device *dev = crtc->dev;
2130 struct drm_i915_private *dev_priv = dev->dev_private;
2131 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2132 struct intel_framebuffer *intel_fb;
2133 struct drm_i915_gem_object *obj;
2134 int plane = intel_crtc->plane;
2135 unsigned long linear_offset;
2145 DRM_ERROR("Can't update plane %d in SAREA\n", plane);
2149 intel_fb = to_intel_framebuffer(fb);
2150 obj = intel_fb->obj;
2152 reg = DSPCNTR(plane);
2153 dspcntr = I915_READ(reg);
2154 /* Mask out pixel format bits in case we change it */
2155 dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
2156 switch (fb->pixel_format) {
2158 dspcntr |= DISPPLANE_8BPP;
2160 case DRM_FORMAT_RGB565:
2161 dspcntr |= DISPPLANE_BGRX565;
2163 case DRM_FORMAT_XRGB8888:
2164 case DRM_FORMAT_ARGB8888:
2165 dspcntr |= DISPPLANE_BGRX888;
2167 case DRM_FORMAT_XBGR8888:
2168 case DRM_FORMAT_ABGR8888:
2169 dspcntr |= DISPPLANE_RGBX888;
2171 case DRM_FORMAT_XRGB2101010:
2172 case DRM_FORMAT_ARGB2101010:
2173 dspcntr |= DISPPLANE_BGRX101010;
2175 case DRM_FORMAT_XBGR2101010:
2176 case DRM_FORMAT_ABGR2101010:
2177 dspcntr |= DISPPLANE_RGBX101010;
2180 DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
2184 if (obj->tiling_mode != I915_TILING_NONE)
2185 dspcntr |= DISPPLANE_TILED;
2187 dspcntr &= ~DISPPLANE_TILED;
2190 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
2192 I915_WRITE(reg, dspcntr);
2194 linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
2195 intel_crtc->dspaddr_offset =
2196 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
2197 fb->bits_per_pixel / 8,
2199 linear_offset -= intel_crtc->dspaddr_offset;
2201 DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
2202 obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
2203 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
2204 I915_MODIFY_DISPBASE(DSPSURF(plane),
2205 obj->gtt_offset + intel_crtc->dspaddr_offset);
2206 if (IS_HASWELL(dev)) {
2207 I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
2209 I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
2210 I915_WRITE(DSPLINOFF(plane), linear_offset);
2217 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2219 intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
2220 int x, int y, enum mode_set_atomic state)
2222 struct drm_device *dev = crtc->dev;
2223 struct drm_i915_private *dev_priv = dev->dev_private;
2225 if (dev_priv->display.disable_fbc)
2226 dev_priv->display.disable_fbc(dev);
2227 intel_increase_pllclock(crtc);
2229 return dev_priv->display.update_plane(crtc, fb, x, y);
2233 intel_finish_fb(struct drm_framebuffer *old_fb)
2235 struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
2236 struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
2237 bool was_interruptible = dev_priv->mm.interruptible;
2240 /* Big Hammer, we also need to ensure that any pending
2241 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2242 * current scanout is retired before unpinning the old
2245 * This should only fail upon a hung GPU, in which case we
2246 * can safely continue.
2248 dev_priv->mm.interruptible = false;
2249 ret = i915_gem_object_finish_gpu(obj);
2250 dev_priv->mm.interruptible = was_interruptible;
2255 static void intel_crtc_update_sarea_pos(struct drm_crtc *crtc, int x, int y)
2257 struct drm_device *dev = crtc->dev;
2258 struct drm_i915_master_private *master_priv;
2259 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2261 if (!dev->primary->master)
2264 master_priv = dev->primary->master->driver_priv;
2265 if (!master_priv->sarea_priv)
2268 switch (intel_crtc->pipe) {
2270 master_priv->sarea_priv->pipeA_x = x;
2271 master_priv->sarea_priv->pipeA_y = y;
2274 master_priv->sarea_priv->pipeB_x = x;
2275 master_priv->sarea_priv->pipeB_y = y;
2283 intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
2284 struct drm_framebuffer *fb)
2286 struct drm_device *dev = crtc->dev;
2287 struct drm_i915_private *dev_priv = dev->dev_private;
2288 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2289 struct drm_framebuffer *old_fb;
2294 DRM_ERROR("No FB bound\n");
2298 if(intel_crtc->plane > dev_priv->num_pipe) {
2299 DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
2301 dev_priv->num_pipe);
2305 mutex_lock(&dev->struct_mutex);
2306 ret = intel_pin_and_fence_fb_obj(dev,
2307 to_intel_framebuffer(fb)->obj,
2310 mutex_unlock(&dev->struct_mutex);
2311 DRM_ERROR("pin & fence failed\n");
2316 intel_finish_fb(crtc->fb);
2318 ret = dev_priv->display.update_plane(crtc, fb, x, y);
2320 intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj);
2321 mutex_unlock(&dev->struct_mutex);
2322 DRM_ERROR("failed to update base address\n");
2332 intel_wait_for_vblank(dev, intel_crtc->pipe);
2333 intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
2336 intel_update_fbc(dev);
2337 mutex_unlock(&dev->struct_mutex);
2339 intel_crtc_update_sarea_pos(crtc, x, y);
2344 static void intel_fdi_normal_train(struct drm_crtc *crtc)
2346 struct drm_device *dev = crtc->dev;
2347 struct drm_i915_private *dev_priv = dev->dev_private;
2348 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2349 int pipe = intel_crtc->pipe;
2352 /* enable normal train */
2353 reg = FDI_TX_CTL(pipe);
2354 temp = I915_READ(reg);
2355 if (IS_IVYBRIDGE(dev)) {
2356 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
2357 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
2359 temp &= ~FDI_LINK_TRAIN_NONE;
2360 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
2362 I915_WRITE(reg, temp);
2364 reg = FDI_RX_CTL(pipe);
2365 temp = I915_READ(reg);
2366 if (HAS_PCH_CPT(dev)) {
2367 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2368 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
2370 temp &= ~FDI_LINK_TRAIN_NONE;
2371 temp |= FDI_LINK_TRAIN_NONE;
2373 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
2375 /* wait one idle pattern time */
2379 /* IVB wants error correction enabled */
2380 if (IS_IVYBRIDGE(dev))
2381 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
2382 FDI_FE_ERRC_ENABLE);
2385 static void ivb_modeset_global_resources(struct drm_device *dev)
2387 struct drm_i915_private *dev_priv = dev->dev_private;
2388 struct intel_crtc *pipe_B_crtc =
2389 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
2390 struct intel_crtc *pipe_C_crtc =
2391 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
2394 /* When everything is off disable fdi C so that we could enable fdi B
2395 * with all lanes. XXX: This misses the case where a pipe is not using
2396 * any pch resources and so doesn't need any fdi lanes. */
2397 if (!pipe_B_crtc->base.enabled && !pipe_C_crtc->base.enabled) {
2398 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
2399 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
2401 temp = I915_READ(SOUTH_CHICKEN1);
2402 temp &= ~FDI_BC_BIFURCATION_SELECT;
2403 DRM_DEBUG_KMS("disabling fdi C rx\n");
2404 I915_WRITE(SOUTH_CHICKEN1, temp);
2408 /* The FDI link training functions for ILK/Ibexpeak. */
2409 static void ironlake_fdi_link_train(struct drm_crtc *crtc)
2411 struct drm_device *dev = crtc->dev;
2412 struct drm_i915_private *dev_priv = dev->dev_private;
2413 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2414 int pipe = intel_crtc->pipe;
2415 int plane = intel_crtc->plane;
2416 u32 reg, temp, tries;
2418 /* FDI needs bits from pipe & plane first */
2419 assert_pipe_enabled(dev_priv, pipe);
2420 assert_plane_enabled(dev_priv, plane);
2422 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2424 reg = FDI_RX_IMR(pipe);
2425 temp = I915_READ(reg);
2426 temp &= ~FDI_RX_SYMBOL_LOCK;
2427 temp &= ~FDI_RX_BIT_LOCK;
2428 I915_WRITE(reg, temp);
2432 /* enable CPU FDI TX and PCH FDI RX */
2433 reg = FDI_TX_CTL(pipe);
2434 temp = I915_READ(reg);
2436 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2437 temp &= ~FDI_LINK_TRAIN_NONE;
2438 temp |= FDI_LINK_TRAIN_PATTERN_1;
2439 I915_WRITE(reg, temp | FDI_TX_ENABLE);
2441 reg = FDI_RX_CTL(pipe);
2442 temp = I915_READ(reg);
2443 temp &= ~FDI_LINK_TRAIN_NONE;
2444 temp |= FDI_LINK_TRAIN_PATTERN_1;
2445 I915_WRITE(reg, temp | FDI_RX_ENABLE);
2450 /* Ironlake workaround, enable clock pointer after FDI enable*/
2451 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
2452 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
2453 FDI_RX_PHASE_SYNC_POINTER_EN);
2455 reg = FDI_RX_IIR(pipe);
2456 for (tries = 0; tries < 5; tries++) {
2457 temp = I915_READ(reg);
2458 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2460 if ((temp & FDI_RX_BIT_LOCK)) {
2461 DRM_DEBUG_KMS("FDI train 1 done.\n");
2462 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2467 DRM_ERROR("FDI train 1 fail!\n");
2470 reg = FDI_TX_CTL(pipe);
2471 temp = I915_READ(reg);
2472 temp &= ~FDI_LINK_TRAIN_NONE;
2473 temp |= FDI_LINK_TRAIN_PATTERN_2;
2474 I915_WRITE(reg, temp);
2476 reg = FDI_RX_CTL(pipe);
2477 temp = I915_READ(reg);
2478 temp &= ~FDI_LINK_TRAIN_NONE;
2479 temp |= FDI_LINK_TRAIN_PATTERN_2;
2480 I915_WRITE(reg, temp);
2485 reg = FDI_RX_IIR(pipe);
2486 for (tries = 0; tries < 5; tries++) {
2487 temp = I915_READ(reg);
2488 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2490 if (temp & FDI_RX_SYMBOL_LOCK) {
2491 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2492 DRM_DEBUG_KMS("FDI train 2 done.\n");
2497 DRM_ERROR("FDI train 2 fail!\n");
2499 DRM_DEBUG_KMS("FDI train done\n");
2503 static const int snb_b_fdi_train_param[] = {
2504 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
2505 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
2506 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
2507 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
2510 /* The FDI link training functions for SNB/Cougarpoint. */
2511 static void gen6_fdi_link_train(struct drm_crtc *crtc)
2513 struct drm_device *dev = crtc->dev;
2514 struct drm_i915_private *dev_priv = dev->dev_private;
2515 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2516 int pipe = intel_crtc->pipe;
2517 u32 reg, temp, i, retry;
2519 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2521 reg = FDI_RX_IMR(pipe);
2522 temp = I915_READ(reg);
2523 temp &= ~FDI_RX_SYMBOL_LOCK;
2524 temp &= ~FDI_RX_BIT_LOCK;
2525 I915_WRITE(reg, temp);
2530 /* enable CPU FDI TX and PCH FDI RX */
2531 reg = FDI_TX_CTL(pipe);
2532 temp = I915_READ(reg);
2534 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2535 temp &= ~FDI_LINK_TRAIN_NONE;
2536 temp |= FDI_LINK_TRAIN_PATTERN_1;
2537 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2539 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2540 I915_WRITE(reg, temp | FDI_TX_ENABLE);
2542 I915_WRITE(FDI_RX_MISC(pipe),
2543 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
2545 reg = FDI_RX_CTL(pipe);
2546 temp = I915_READ(reg);
2547 if (HAS_PCH_CPT(dev)) {
2548 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2549 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
2551 temp &= ~FDI_LINK_TRAIN_NONE;
2552 temp |= FDI_LINK_TRAIN_PATTERN_1;
2554 I915_WRITE(reg, temp | FDI_RX_ENABLE);
2559 for (i = 0; i < 4; i++) {
2560 reg = FDI_TX_CTL(pipe);
2561 temp = I915_READ(reg);
2562 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2563 temp |= snb_b_fdi_train_param[i];
2564 I915_WRITE(reg, temp);
2569 for (retry = 0; retry < 5; retry++) {
2570 reg = FDI_RX_IIR(pipe);
2571 temp = I915_READ(reg);
2572 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2573 if (temp & FDI_RX_BIT_LOCK) {
2574 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2575 DRM_DEBUG_KMS("FDI train 1 done.\n");
2584 DRM_ERROR("FDI train 1 fail!\n");
2587 reg = FDI_TX_CTL(pipe);
2588 temp = I915_READ(reg);
2589 temp &= ~FDI_LINK_TRAIN_NONE;
2590 temp |= FDI_LINK_TRAIN_PATTERN_2;
2592 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2594 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2596 I915_WRITE(reg, temp);
2598 reg = FDI_RX_CTL(pipe);
2599 temp = I915_READ(reg);
2600 if (HAS_PCH_CPT(dev)) {
2601 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2602 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
2604 temp &= ~FDI_LINK_TRAIN_NONE;
2605 temp |= FDI_LINK_TRAIN_PATTERN_2;
2607 I915_WRITE(reg, temp);
2612 for (i = 0; i < 4; i++) {
2613 reg = FDI_TX_CTL(pipe);
2614 temp = I915_READ(reg);
2615 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2616 temp |= snb_b_fdi_train_param[i];
2617 I915_WRITE(reg, temp);
2622 for (retry = 0; retry < 5; retry++) {
2623 reg = FDI_RX_IIR(pipe);
2624 temp = I915_READ(reg);
2625 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2626 if (temp & FDI_RX_SYMBOL_LOCK) {
2627 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2628 DRM_DEBUG_KMS("FDI train 2 done.\n");
2637 DRM_ERROR("FDI train 2 fail!\n");
2639 DRM_DEBUG_KMS("FDI train done.\n");
2642 /* Manual link training for Ivy Bridge A0 parts */
2643 static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
2645 struct drm_device *dev = crtc->dev;
2646 struct drm_i915_private *dev_priv = dev->dev_private;
2647 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2648 int pipe = intel_crtc->pipe;
2651 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2653 reg = FDI_RX_IMR(pipe);
2654 temp = I915_READ(reg);
2655 temp &= ~FDI_RX_SYMBOL_LOCK;
2656 temp &= ~FDI_RX_BIT_LOCK;
2657 I915_WRITE(reg, temp);
2662 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
2663 I915_READ(FDI_RX_IIR(pipe)));
2665 /* enable CPU FDI TX and PCH FDI RX */
2666 reg = FDI_TX_CTL(pipe);
2667 temp = I915_READ(reg);
2669 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2670 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
2671 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
2672 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2673 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2674 temp |= FDI_COMPOSITE_SYNC;
2675 I915_WRITE(reg, temp | FDI_TX_ENABLE);
2677 I915_WRITE(FDI_RX_MISC(pipe),
2678 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
2680 reg = FDI_RX_CTL(pipe);
2681 temp = I915_READ(reg);
2682 temp &= ~FDI_LINK_TRAIN_AUTO;
2683 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2684 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
2685 temp |= FDI_COMPOSITE_SYNC;
2686 I915_WRITE(reg, temp | FDI_RX_ENABLE);
2691 for (i = 0; i < 4; i++) {
2692 reg = FDI_TX_CTL(pipe);
2693 temp = I915_READ(reg);
2694 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2695 temp |= snb_b_fdi_train_param[i];
2696 I915_WRITE(reg, temp);
2701 reg = FDI_RX_IIR(pipe);
2702 temp = I915_READ(reg);
2703 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2705 if (temp & FDI_RX_BIT_LOCK ||
2706 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
2707 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2708 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i);
2713 DRM_ERROR("FDI train 1 fail!\n");
2716 reg = FDI_TX_CTL(pipe);
2717 temp = I915_READ(reg);
2718 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
2719 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
2720 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2721 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2722 I915_WRITE(reg, temp);
2724 reg = FDI_RX_CTL(pipe);
2725 temp = I915_READ(reg);
2726 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2727 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
2728 I915_WRITE(reg, temp);
2733 for (i = 0; i < 4; i++) {
2734 reg = FDI_TX_CTL(pipe);
2735 temp = I915_READ(reg);
2736 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2737 temp |= snb_b_fdi_train_param[i];
2738 I915_WRITE(reg, temp);
2743 reg = FDI_RX_IIR(pipe);
2744 temp = I915_READ(reg);
2745 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2747 if (temp & FDI_RX_SYMBOL_LOCK) {
2748 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2749 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i);
2754 DRM_ERROR("FDI train 2 fail!\n");
2756 DRM_DEBUG_KMS("FDI train done.\n");
2759 static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
2761 struct drm_device *dev = intel_crtc->base.dev;
2762 struct drm_i915_private *dev_priv = dev->dev_private;
2763 int pipe = intel_crtc->pipe;
2767 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
2768 reg = FDI_RX_CTL(pipe);
2769 temp = I915_READ(reg);
2770 temp &= ~((0x7 << 19) | (0x7 << 16));
2771 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2772 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
2773 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
2778 /* Switch from Rawclk to PCDclk */
2779 temp = I915_READ(reg);
2780 I915_WRITE(reg, temp | FDI_PCDCLK);
2785 /* Enable CPU FDI TX PLL, always on for Ironlake */
2786 reg = FDI_TX_CTL(pipe);
2787 temp = I915_READ(reg);
2788 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
2789 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
2796 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
2798 struct drm_device *dev = intel_crtc->base.dev;
2799 struct drm_i915_private *dev_priv = dev->dev_private;
2800 int pipe = intel_crtc->pipe;
2803 /* Switch from PCDclk to Rawclk */
2804 reg = FDI_RX_CTL(pipe);
2805 temp = I915_READ(reg);
2806 I915_WRITE(reg, temp & ~FDI_PCDCLK);
2808 /* Disable CPU FDI TX PLL */
2809 reg = FDI_TX_CTL(pipe);
2810 temp = I915_READ(reg);
2811 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
2816 reg = FDI_RX_CTL(pipe);
2817 temp = I915_READ(reg);
2818 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
2820 /* Wait for the clocks to turn off. */
2825 static void ironlake_fdi_disable(struct drm_crtc *crtc)
2827 struct drm_device *dev = crtc->dev;
2828 struct drm_i915_private *dev_priv = dev->dev_private;
2829 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2830 int pipe = intel_crtc->pipe;
2833 /* disable CPU FDI tx and PCH FDI rx */
2834 reg = FDI_TX_CTL(pipe);
2835 temp = I915_READ(reg);
2836 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
2839 reg = FDI_RX_CTL(pipe);
2840 temp = I915_READ(reg);
2841 temp &= ~(0x7 << 16);
2842 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
2843 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
2848 /* Ironlake workaround, disable clock pointer after downing FDI */
2849 if (HAS_PCH_IBX(dev)) {
2850 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
2853 /* still set train pattern 1 */
2854 reg = FDI_TX_CTL(pipe);
2855 temp = I915_READ(reg);
2856 temp &= ~FDI_LINK_TRAIN_NONE;
2857 temp |= FDI_LINK_TRAIN_PATTERN_1;
2858 I915_WRITE(reg, temp);
2860 reg = FDI_RX_CTL(pipe);
2861 temp = I915_READ(reg);
2862 if (HAS_PCH_CPT(dev)) {
2863 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2864 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
2866 temp &= ~FDI_LINK_TRAIN_NONE;
2867 temp |= FDI_LINK_TRAIN_PATTERN_1;
2869 /* BPC in FDI rx is consistent with that in PIPECONF */
2870 temp &= ~(0x07 << 16);
2871 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
2872 I915_WRITE(reg, temp);
2878 static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
2880 struct drm_device *dev = crtc->dev;
2881 struct drm_i915_private *dev_priv = dev->dev_private;
2882 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2883 unsigned long flags;
2886 if (i915_reset_in_progress(&dev_priv->gpu_error) ||
2887 intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
2890 spin_lock_irqsave(&dev->event_lock, flags);
2891 pending = to_intel_crtc(crtc)->unpin_work != NULL;
2892 spin_unlock_irqrestore(&dev->event_lock, flags);
2897 static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
2899 struct drm_device *dev = crtc->dev;
2900 struct drm_i915_private *dev_priv = dev->dev_private;
2902 if (crtc->fb == NULL)
2905 WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
2907 wait_event(dev_priv->pending_flip_queue,
2908 !intel_crtc_has_pending_flip(crtc));
2910 mutex_lock(&dev->struct_mutex);
2911 intel_finish_fb(crtc->fb);
2912 mutex_unlock(&dev->struct_mutex);
2915 static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc)
2917 struct drm_device *dev = crtc->dev;
2918 struct intel_encoder *intel_encoder;
2921 * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
2922 * must be driven by its own crtc; no sharing is possible.
2924 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
2925 switch (intel_encoder->type) {
2926 case INTEL_OUTPUT_EDP:
2927 if (!intel_encoder_is_pch_edp(&intel_encoder->base))
2936 static bool haswell_crtc_driving_pch(struct drm_crtc *crtc)
2938 return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG);
2941 /* Program iCLKIP clock to the desired frequency */
2942 static void lpt_program_iclkip(struct drm_crtc *crtc)
2944 struct drm_device *dev = crtc->dev;
2945 struct drm_i915_private *dev_priv = dev->dev_private;
2946 u32 divsel, phaseinc, auxdiv, phasedir = 0;
2949 mutex_lock(&dev_priv->dpio_lock);
2951 /* It is necessary to ungate the pixclk gate prior to programming
2952 * the divisors, and gate it back when it is done.
2954 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
2956 /* Disable SSCCTL */
2957 intel_sbi_write(dev_priv, SBI_SSCCTL6,
2958 intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
2962 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
2963 if (crtc->mode.clock == 20000) {
2968 /* The iCLK virtual clock root frequency is in MHz,
2969 * but the crtc->mode.clock in in KHz. To get the divisors,
2970 * it is necessary to divide one by another, so we
2971 * convert the virtual clock precision to KHz here for higher
2974 u32 iclk_virtual_root_freq = 172800 * 1000;
2975 u32 iclk_pi_range = 64;
2976 u32 desired_divisor, msb_divisor_value, pi_value;
2978 desired_divisor = (iclk_virtual_root_freq / crtc->mode.clock);
2979 msb_divisor_value = desired_divisor / iclk_pi_range;
2980 pi_value = desired_divisor % iclk_pi_range;
2983 divsel = msb_divisor_value - 2;
2984 phaseinc = pi_value;
2987 /* This should not happen with any sane values */
2988 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
2989 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
2990 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
2991 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
2993 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3000 /* Program SSCDIVINTPHASE6 */
3001 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
3002 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
3003 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
3004 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
3005 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
3006 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
3007 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
3008 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
3010 /* Program SSCAUXDIV */
3011 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
3012 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3013 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
3014 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
3016 /* Enable modulator and associated divider */
3017 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
3018 temp &= ~SBI_SSCCTL_DISABLE;
3019 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
3021 /* Wait for initialization time */
3024 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
3026 mutex_unlock(&dev_priv->dpio_lock);
3030 * Enable PCH resources required for PCH ports:
3032 * - FDI training & RX/TX
3033 * - update transcoder timings
3034 * - DP transcoding bits
3037 static void ironlake_pch_enable(struct drm_crtc *crtc)
3039 struct drm_device *dev = crtc->dev;
3040 struct drm_i915_private *dev_priv = dev->dev_private;
3041 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3042 int pipe = intel_crtc->pipe;
3045 assert_transcoder_disabled(dev_priv, pipe);
3047 /* Write the TU size bits before fdi link training, so that error
3048 * detection works. */
3049 I915_WRITE(FDI_RX_TUSIZE1(pipe),
3050 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
3052 /* For PCH output, training FDI link */
3053 dev_priv->display.fdi_link_train(crtc);
3055 /* XXX: pch pll's can be enabled any time before we enable the PCH
3056 * transcoder, and we actually should do this to not upset any PCH
3057 * transcoder that already use the clock when we share it.
3059 * Note that enable_pch_pll tries to do the right thing, but get_pch_pll
3060 * unconditionally resets the pll - we need that to have the right LVDS
3061 * enable sequence. */
3062 ironlake_enable_pch_pll(intel_crtc);
3064 if (HAS_PCH_CPT(dev)) {
3067 temp = I915_READ(PCH_DPLL_SEL);
3071 temp |= TRANSA_DPLL_ENABLE;
3072 sel = TRANSA_DPLLB_SEL;
3075 temp |= TRANSB_DPLL_ENABLE;
3076 sel = TRANSB_DPLLB_SEL;
3079 temp |= TRANSC_DPLL_ENABLE;
3080 sel = TRANSC_DPLLB_SEL;
3083 if (intel_crtc->pch_pll->pll_reg == _PCH_DPLL_B)
3087 I915_WRITE(PCH_DPLL_SEL, temp);
3090 /* set transcoder timing, panel must allow it */
3091 assert_panel_unlocked(dev_priv, pipe);
3092 I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
3093 I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
3094 I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
3096 I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
3097 I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
3098 I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
3099 I915_WRITE(TRANS_VSYNCSHIFT(pipe), I915_READ(VSYNCSHIFT(pipe)));
3101 intel_fdi_normal_train(crtc);
3103 /* For PCH DP, enable TRANS_DP_CTL */
3104 if (HAS_PCH_CPT(dev) &&
3105 (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
3106 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
3107 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
3108 reg = TRANS_DP_CTL(pipe);
3109 temp = I915_READ(reg);
3110 temp &= ~(TRANS_DP_PORT_SEL_MASK |
3111 TRANS_DP_SYNC_MASK |
3113 temp |= (TRANS_DP_OUTPUT_ENABLE |
3114 TRANS_DP_ENH_FRAMING);
3115 temp |= bpc << 9; /* same format but at 11:9 */
3117 if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
3118 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
3119 if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
3120 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
3122 switch (intel_trans_dp_port_sel(crtc)) {
3124 temp |= TRANS_DP_PORT_SEL_B;
3127 temp |= TRANS_DP_PORT_SEL_C;
3130 temp |= TRANS_DP_PORT_SEL_D;
3136 I915_WRITE(reg, temp);
3139 ironlake_enable_pch_transcoder(dev_priv, pipe);
3142 static void lpt_pch_enable(struct drm_crtc *crtc)
3144 struct drm_device *dev = crtc->dev;
3145 struct drm_i915_private *dev_priv = dev->dev_private;
3146 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3147 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
3149 assert_transcoder_disabled(dev_priv, TRANSCODER_A);
3151 lpt_program_iclkip(crtc);
3153 /* Set transcoder timing. */
3154 I915_WRITE(_TRANS_HTOTAL_A, I915_READ(HTOTAL(cpu_transcoder)));
3155 I915_WRITE(_TRANS_HBLANK_A, I915_READ(HBLANK(cpu_transcoder)));
3156 I915_WRITE(_TRANS_HSYNC_A, I915_READ(HSYNC(cpu_transcoder)));
3158 I915_WRITE(_TRANS_VTOTAL_A, I915_READ(VTOTAL(cpu_transcoder)));
3159 I915_WRITE(_TRANS_VBLANK_A, I915_READ(VBLANK(cpu_transcoder)));
3160 I915_WRITE(_TRANS_VSYNC_A, I915_READ(VSYNC(cpu_transcoder)));
3161 I915_WRITE(_TRANS_VSYNCSHIFT_A, I915_READ(VSYNCSHIFT(cpu_transcoder)));
3163 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
3166 static void intel_put_pch_pll(struct intel_crtc *intel_crtc)
3168 struct intel_pch_pll *pll = intel_crtc->pch_pll;
3173 if (pll->refcount == 0) {
3174 WARN(1, "bad PCH PLL refcount\n");
3179 intel_crtc->pch_pll = NULL;
3182 static struct intel_pch_pll *intel_get_pch_pll(struct intel_crtc *intel_crtc, u32 dpll, u32 fp)
3184 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
3185 struct intel_pch_pll *pll;
3188 pll = intel_crtc->pch_pll;
3190 DRM_DEBUG_KMS("CRTC:%d reusing existing PCH PLL %x\n",
3191 intel_crtc->base.base.id, pll->pll_reg);
3195 if (HAS_PCH_IBX(dev_priv->dev)) {
3196 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3197 i = intel_crtc->pipe;
3198 pll = &dev_priv->pch_plls[i];
3200 DRM_DEBUG_KMS("CRTC:%d using pre-allocated PCH PLL %x\n",
3201 intel_crtc->base.base.id, pll->pll_reg);
3206 for (i = 0; i < dev_priv->num_pch_pll; i++) {
3207 pll = &dev_priv->pch_plls[i];
3209 /* Only want to check enabled timings first */
3210 if (pll->refcount == 0)
3213 if (dpll == (I915_READ(pll->pll_reg) & 0x7fffffff) &&
3214 fp == I915_READ(pll->fp0_reg)) {
3215 DRM_DEBUG_KMS("CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n",
3216 intel_crtc->base.base.id,
3217 pll->pll_reg, pll->refcount, pll->active);
3223 /* Ok no matching timings, maybe there's a free one? */
3224 for (i = 0; i < dev_priv->num_pch_pll; i++) {
3225 pll = &dev_priv->pch_plls[i];
3226 if (pll->refcount == 0) {
3227 DRM_DEBUG_KMS("CRTC:%d allocated PCH PLL %x\n",
3228 intel_crtc->base.base.id, pll->pll_reg);
3236 intel_crtc->pch_pll = pll;
3238 DRM_DEBUG_DRIVER("using pll %d for pipe %d\n", i, intel_crtc->pipe);
3239 prepare: /* separate function? */
3240 DRM_DEBUG_DRIVER("switching PLL %x off\n", pll->pll_reg);
3242 /* Wait for the clocks to stabilize before rewriting the regs */
3243 I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
3244 POSTING_READ(pll->pll_reg);
3247 I915_WRITE(pll->fp0_reg, fp);
3248 I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
3253 void intel_cpt_verify_modeset(struct drm_device *dev, int pipe)
3255 struct drm_i915_private *dev_priv = dev->dev_private;
3256 int dslreg = PIPEDSL(pipe);
3259 temp = I915_READ(dslreg);
3261 if (wait_for(I915_READ(dslreg) != temp, 5)) {
3262 if (wait_for(I915_READ(dslreg) != temp, 5))
3263 DRM_ERROR("mode set failed: pipe %d stuck\n", pipe);
3267 static void ironlake_crtc_enable(struct drm_crtc *crtc)
3269 struct drm_device *dev = crtc->dev;
3270 struct drm_i915_private *dev_priv = dev->dev_private;
3271 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3272 struct intel_encoder *encoder;
3273 int pipe = intel_crtc->pipe;
3274 int plane = intel_crtc->plane;
3278 WARN_ON(!crtc->enabled);
3280 if (intel_crtc->active)
3283 intel_crtc->active = true;
3284 intel_update_watermarks(dev);
3286 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
3287 temp = I915_READ(PCH_LVDS);
3288 if ((temp & LVDS_PORT_EN) == 0)
3289 I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
3292 is_pch_port = ironlake_crtc_driving_pch(crtc);
3295 /* Note: FDI PLL enabling _must_ be done before we enable the
3296 * cpu pipes, hence this is separate from all the other fdi/pch
3298 ironlake_fdi_pll_enable(intel_crtc);
3300 assert_fdi_tx_disabled(dev_priv, pipe);
3301 assert_fdi_rx_disabled(dev_priv, pipe);
3304 for_each_encoder_on_crtc(dev, crtc, encoder)
3305 if (encoder->pre_enable)
3306 encoder->pre_enable(encoder);
3308 /* Enable panel fitting for LVDS */
3309 if (dev_priv->pch_pf_size &&
3310 (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
3311 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
3312 /* Force use of hard-coded filter coefficients
3313 * as some pre-programmed values are broken,
3316 if (IS_IVYBRIDGE(dev))
3317 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
3318 PF_PIPE_SEL_IVB(pipe));
3320 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
3321 I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
3322 I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
3326 * On ILK+ LUT must be loaded before the pipe is running but with
3329 intel_crtc_load_lut(crtc);
3331 intel_enable_pipe(dev_priv, pipe, is_pch_port);
3332 intel_enable_plane(dev_priv, plane, pipe);
3335 ironlake_pch_enable(crtc);
3337 mutex_lock(&dev->struct_mutex);
3338 intel_update_fbc(dev);
3339 mutex_unlock(&dev->struct_mutex);
3341 intel_crtc_update_cursor(crtc, true);
3343 for_each_encoder_on_crtc(dev, crtc, encoder)
3344 encoder->enable(encoder);
3346 if (HAS_PCH_CPT(dev))
3347 intel_cpt_verify_modeset(dev, intel_crtc->pipe);
3350 * There seems to be a race in PCH platform hw (at least on some
3351 * outputs) where an enabled pipe still completes any pageflip right
3352 * away (as if the pipe is off) instead of waiting for vblank. As soon
3353 * as the first vblank happend, everything works as expected. Hence just
3354 * wait for one vblank before returning to avoid strange things
3357 intel_wait_for_vblank(dev, intel_crtc->pipe);
3360 static void haswell_crtc_enable(struct drm_crtc *crtc)
3362 struct drm_device *dev = crtc->dev;
3363 struct drm_i915_private *dev_priv = dev->dev_private;
3364 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3365 struct intel_encoder *encoder;
3366 int pipe = intel_crtc->pipe;
3367 int plane = intel_crtc->plane;
3370 WARN_ON(!crtc->enabled);
3372 if (intel_crtc->active)
3375 intel_crtc->active = true;
3376 intel_update_watermarks(dev);
3378 is_pch_port = haswell_crtc_driving_pch(crtc);
3381 dev_priv->display.fdi_link_train(crtc);
3383 for_each_encoder_on_crtc(dev, crtc, encoder)
3384 if (encoder->pre_enable)
3385 encoder->pre_enable(encoder);
3387 intel_ddi_enable_pipe_clock(intel_crtc);
3389 /* Enable panel fitting for eDP */
3390 if (dev_priv->pch_pf_size &&
3391 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
3392 /* Force use of hard-coded filter coefficients
3393 * as some pre-programmed values are broken,
3396 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
3397 PF_PIPE_SEL_IVB(pipe));
3398 I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
3399 I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
3403 * On ILK+ LUT must be loaded before the pipe is running but with
3406 intel_crtc_load_lut(crtc);
3408 intel_ddi_set_pipe_settings(crtc);
3409 intel_ddi_enable_pipe_func(crtc);
3411 intel_enable_pipe(dev_priv, pipe, is_pch_port);
3412 intel_enable_plane(dev_priv, plane, pipe);
3415 lpt_pch_enable(crtc);
3417 mutex_lock(&dev->struct_mutex);
3418 intel_update_fbc(dev);
3419 mutex_unlock(&dev->struct_mutex);
3421 intel_crtc_update_cursor(crtc, true);
3423 for_each_encoder_on_crtc(dev, crtc, encoder)
3424 encoder->enable(encoder);
3427 * There seems to be a race in PCH platform hw (at least on some
3428 * outputs) where an enabled pipe still completes any pageflip right
3429 * away (as if the pipe is off) instead of waiting for vblank. As soon
3430 * as the first vblank happend, everything works as expected. Hence just
3431 * wait for one vblank before returning to avoid strange things
3434 intel_wait_for_vblank(dev, intel_crtc->pipe);
3437 static void ironlake_crtc_disable(struct drm_crtc *crtc)
3439 struct drm_device *dev = crtc->dev;
3440 struct drm_i915_private *dev_priv = dev->dev_private;
3441 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3442 struct intel_encoder *encoder;
3443 int pipe = intel_crtc->pipe;
3444 int plane = intel_crtc->plane;
3448 if (!intel_crtc->active)
3451 for_each_encoder_on_crtc(dev, crtc, encoder)
3452 encoder->disable(encoder);
3454 intel_crtc_wait_for_pending_flips(crtc);
3455 drm_vblank_off(dev, pipe);
3456 intel_crtc_update_cursor(crtc, false);
3458 intel_disable_plane(dev_priv, plane, pipe);
3460 if (dev_priv->cfb_plane == plane)
3461 intel_disable_fbc(dev);
3463 intel_disable_pipe(dev_priv, pipe);
3466 I915_WRITE(PF_CTL(pipe), 0);
3467 I915_WRITE(PF_WIN_SZ(pipe), 0);
3469 for_each_encoder_on_crtc(dev, crtc, encoder)
3470 if (encoder->post_disable)
3471 encoder->post_disable(encoder);
3473 ironlake_fdi_disable(crtc);
3475 ironlake_disable_pch_transcoder(dev_priv, pipe);
3477 if (HAS_PCH_CPT(dev)) {
3478 /* disable TRANS_DP_CTL */
3479 reg = TRANS_DP_CTL(pipe);
3480 temp = I915_READ(reg);
3481 temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
3482 temp |= TRANS_DP_PORT_SEL_NONE;
3483 I915_WRITE(reg, temp);
3485 /* disable DPLL_SEL */
3486 temp = I915_READ(PCH_DPLL_SEL);
3489 temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL);
3492 temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
3495 /* C shares PLL A or B */
3496 temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL);
3501 I915_WRITE(PCH_DPLL_SEL, temp);
3504 /* disable PCH DPLL */
3505 intel_disable_pch_pll(intel_crtc);
3507 ironlake_fdi_pll_disable(intel_crtc);
3509 intel_crtc->active = false;
3510 intel_update_watermarks(dev);
3512 mutex_lock(&dev->struct_mutex);
3513 intel_update_fbc(dev);
3514 mutex_unlock(&dev->struct_mutex);
3517 static void haswell_crtc_disable(struct drm_crtc *crtc)
3519 struct drm_device *dev = crtc->dev;
3520 struct drm_i915_private *dev_priv = dev->dev_private;
3521 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3522 struct intel_encoder *encoder;
3523 int pipe = intel_crtc->pipe;
3524 int plane = intel_crtc->plane;
3525 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
3528 if (!intel_crtc->active)
3531 is_pch_port = haswell_crtc_driving_pch(crtc);
3533 for_each_encoder_on_crtc(dev, crtc, encoder)
3534 encoder->disable(encoder);
3536 intel_crtc_wait_for_pending_flips(crtc);
3537 drm_vblank_off(dev, pipe);
3538 intel_crtc_update_cursor(crtc, false);
3540 intel_disable_plane(dev_priv, plane, pipe);
3542 if (dev_priv->cfb_plane == plane)
3543 intel_disable_fbc(dev);
3545 intel_disable_pipe(dev_priv, pipe);
3547 intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
3550 I915_WRITE(PF_CTL(pipe), 0);
3551 I915_WRITE(PF_WIN_SZ(pipe), 0);
3553 intel_ddi_disable_pipe_clock(intel_crtc);
3555 for_each_encoder_on_crtc(dev, crtc, encoder)
3556 if (encoder->post_disable)
3557 encoder->post_disable(encoder);
3560 lpt_disable_pch_transcoder(dev_priv);
3561 intel_ddi_fdi_disable(crtc);
3564 intel_crtc->active = false;
3565 intel_update_watermarks(dev);
3567 mutex_lock(&dev->struct_mutex);
3568 intel_update_fbc(dev);
3569 mutex_unlock(&dev->struct_mutex);
3572 static void ironlake_crtc_off(struct drm_crtc *crtc)
3574 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3575 intel_put_pch_pll(intel_crtc);
3578 static void haswell_crtc_off(struct drm_crtc *crtc)
3580 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3582 /* Stop saying we're using TRANSCODER_EDP because some other CRTC might
3583 * start using it. */
3584 intel_crtc->cpu_transcoder = (enum transcoder) intel_crtc->pipe;
3586 intel_ddi_put_crtc_pll(crtc);
3589 static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
3591 if (!enable && intel_crtc->overlay) {
3592 struct drm_device *dev = intel_crtc->base.dev;
3593 struct drm_i915_private *dev_priv = dev->dev_private;
3595 mutex_lock(&dev->struct_mutex);
3596 dev_priv->mm.interruptible = false;
3597 (void) intel_overlay_switch_off(intel_crtc->overlay);
3598 dev_priv->mm.interruptible = true;
3599 mutex_unlock(&dev->struct_mutex);
3602 /* Let userspace switch the overlay on again. In most cases userspace
3603 * has to recompute where to put it anyway.
3608 * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
3609 * cursor plane briefly if not already running after enabling the display
3611 * This workaround avoids occasional blank screens when self refresh is
3615 g4x_fixup_plane(struct drm_i915_private *dev_priv, enum pipe pipe)
3617 u32 cntl = I915_READ(CURCNTR(pipe));
3619 if ((cntl & CURSOR_MODE) == 0) {
3620 u32 fw_bcl_self = I915_READ(FW_BLC_SELF);
3622 I915_WRITE(FW_BLC_SELF, fw_bcl_self & ~FW_BLC_SELF_EN);
3623 I915_WRITE(CURCNTR(pipe), CURSOR_MODE_64_ARGB_AX);
3624 intel_wait_for_vblank(dev_priv->dev, pipe);
3625 I915_WRITE(CURCNTR(pipe), cntl);
3626 I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe)));
3627 I915_WRITE(FW_BLC_SELF, fw_bcl_self);
3631 static void i9xx_crtc_enable(struct drm_crtc *crtc)
3633 struct drm_device *dev = crtc->dev;
3634 struct drm_i915_private *dev_priv = dev->dev_private;
3635 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3636 struct intel_encoder *encoder;
3637 int pipe = intel_crtc->pipe;
3638 int plane = intel_crtc->plane;
3640 WARN_ON(!crtc->enabled);
3642 if (intel_crtc->active)
3645 intel_crtc->active = true;
3646 intel_update_watermarks(dev);
3648 intel_enable_pll(dev_priv, pipe);
3650 for_each_encoder_on_crtc(dev, crtc, encoder)
3651 if (encoder->pre_enable)
3652 encoder->pre_enable(encoder);
3654 intel_enable_pipe(dev_priv, pipe, false);
3655 intel_enable_plane(dev_priv, plane, pipe);
3657 g4x_fixup_plane(dev_priv, pipe);
3659 intel_crtc_load_lut(crtc);
3660 intel_update_fbc(dev);
3662 /* Give the overlay scaler a chance to enable if it's on this pipe */
3663 intel_crtc_dpms_overlay(intel_crtc, true);
3664 intel_crtc_update_cursor(crtc, true);
3666 for_each_encoder_on_crtc(dev, crtc, encoder)
3667 encoder->enable(encoder);
3670 static void i9xx_crtc_disable(struct drm_crtc *crtc)
3672 struct drm_device *dev = crtc->dev;
3673 struct drm_i915_private *dev_priv = dev->dev_private;
3674 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3675 struct intel_encoder *encoder;
3676 int pipe = intel_crtc->pipe;
3677 int plane = intel_crtc->plane;
3681 if (!intel_crtc->active)
3684 for_each_encoder_on_crtc(dev, crtc, encoder)
3685 encoder->disable(encoder);
3687 /* Give the overlay scaler a chance to disable if it's on this pipe */
3688 intel_crtc_wait_for_pending_flips(crtc);
3689 drm_vblank_off(dev, pipe);
3690 intel_crtc_dpms_overlay(intel_crtc, false);
3691 intel_crtc_update_cursor(crtc, false);
3693 if (dev_priv->cfb_plane == plane)
3694 intel_disable_fbc(dev);
3696 intel_disable_plane(dev_priv, plane, pipe);
3697 intel_disable_pipe(dev_priv, pipe);
3699 /* Disable pannel fitter if it is on this pipe. */
3700 pctl = I915_READ(PFIT_CONTROL);
3701 if ((pctl & PFIT_ENABLE) &&
3702 ((pctl & PFIT_PIPE_MASK) >> PFIT_PIPE_SHIFT) == pipe)
3703 I915_WRITE(PFIT_CONTROL, 0);
3705 intel_disable_pll(dev_priv, pipe);
3707 intel_crtc->active = false;
3708 intel_update_fbc(dev);
3709 intel_update_watermarks(dev);
3712 static void i9xx_crtc_off(struct drm_crtc *crtc)
3716 static void intel_crtc_update_sarea(struct drm_crtc *crtc,
3719 struct drm_device *dev = crtc->dev;
3720 struct drm_i915_master_private *master_priv;
3721 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3722 int pipe = intel_crtc->pipe;
3724 if (!dev->primary->master)
3727 master_priv = dev->primary->master->driver_priv;
3728 if (!master_priv->sarea_priv)
3733 master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
3734 master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
3737 master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
3738 master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
3741 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
3747 * Sets the power management mode of the pipe and plane.
3749 void intel_crtc_update_dpms(struct drm_crtc *crtc)
3751 struct drm_device *dev = crtc->dev;
3752 struct drm_i915_private *dev_priv = dev->dev_private;
3753 struct intel_encoder *intel_encoder;
3754 bool enable = false;
3756 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
3757 enable |= intel_encoder->connectors_active;
3760 dev_priv->display.crtc_enable(crtc);
3762 dev_priv->display.crtc_disable(crtc);
3764 intel_crtc_update_sarea(crtc, enable);
3767 static void intel_crtc_noop(struct drm_crtc *crtc)
3771 static void intel_crtc_disable(struct drm_crtc *crtc)
3773 struct drm_device *dev = crtc->dev;
3774 struct drm_connector *connector;
3775 struct drm_i915_private *dev_priv = dev->dev_private;
3776 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3778 /* crtc should still be enabled when we disable it. */
3779 WARN_ON(!crtc->enabled);
3781 intel_crtc->eld_vld = false;
3782 dev_priv->display.crtc_disable(crtc);
3783 intel_crtc_update_sarea(crtc, false);
3784 dev_priv->display.off(crtc);
3786 assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
3787 assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe);
3790 mutex_lock(&dev->struct_mutex);
3791 intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
3792 mutex_unlock(&dev->struct_mutex);
3796 /* Update computed state. */
3797 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3798 if (!connector->encoder || !connector->encoder->crtc)
3801 if (connector->encoder->crtc != crtc)
3804 connector->dpms = DRM_MODE_DPMS_OFF;
3805 to_intel_encoder(connector->encoder)->connectors_active = false;
3809 void intel_modeset_disable(struct drm_device *dev)
3811 struct drm_crtc *crtc;
3813 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
3815 intel_crtc_disable(crtc);
3819 void intel_encoder_noop(struct drm_encoder *encoder)
3823 void intel_encoder_destroy(struct drm_encoder *encoder)
3825 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
3827 drm_encoder_cleanup(encoder);
3828 kfree(intel_encoder);
3831 /* Simple dpms helper for encodres with just one connector, no cloning and only
3832 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
3833 * state of the entire output pipe. */
3834 void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
3836 if (mode == DRM_MODE_DPMS_ON) {
3837 encoder->connectors_active = true;
3839 intel_crtc_update_dpms(encoder->base.crtc);
3841 encoder->connectors_active = false;
3843 intel_crtc_update_dpms(encoder->base.crtc);
3847 /* Cross check the actual hw state with our own modeset state tracking (and it's
3848 * internal consistency). */
3849 static void intel_connector_check_state(struct intel_connector *connector)
3851 if (connector->get_hw_state(connector)) {
3852 struct intel_encoder *encoder = connector->encoder;
3853 struct drm_crtc *crtc;
3854 bool encoder_enabled;
3857 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
3858 connector->base.base.id,
3859 drm_get_connector_name(&connector->base));
3861 WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
3862 "wrong connector dpms state\n");
3863 WARN(connector->base.encoder != &encoder->base,
3864 "active connector not linked to encoder\n");
3865 WARN(!encoder->connectors_active,
3866 "encoder->connectors_active not set\n");
3868 encoder_enabled = encoder->get_hw_state(encoder, &pipe);
3869 WARN(!encoder_enabled, "encoder not enabled\n");
3870 if (WARN_ON(!encoder->base.crtc))
3873 crtc = encoder->base.crtc;
3875 WARN(!crtc->enabled, "crtc not enabled\n");
3876 WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
3877 WARN(pipe != to_intel_crtc(crtc)->pipe,
3878 "encoder active on the wrong pipe\n");
3882 /* Even simpler default implementation, if there's really no special case to
3884 void intel_connector_dpms(struct drm_connector *connector, int mode)
3886 struct intel_encoder *encoder = intel_attached_encoder(connector);
3888 /* All the simple cases only support two dpms states. */
3889 if (mode != DRM_MODE_DPMS_ON)
3890 mode = DRM_MODE_DPMS_OFF;
3892 if (mode == connector->dpms)
3895 connector->dpms = mode;
3897 /* Only need to change hw state when actually enabled */
3898 if (encoder->base.crtc)
3899 intel_encoder_dpms(encoder, mode);
3901 WARN_ON(encoder->connectors_active != false);
3903 intel_modeset_check_state(connector->dev);
3906 /* Simple connector->get_hw_state implementation for encoders that support only
3907 * one connector and no cloning and hence the encoder state determines the state
3908 * of the connector. */
3909 bool intel_connector_get_hw_state(struct intel_connector *connector)
3912 struct intel_encoder *encoder = connector->encoder;
3914 return encoder->get_hw_state(encoder, &pipe);
3917 static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
3918 const struct drm_display_mode *mode,
3919 struct drm_display_mode *adjusted_mode)
3921 struct drm_device *dev = crtc->dev;
3923 if (HAS_PCH_SPLIT(dev)) {
3924 /* FDI link clock is fixed at 2.7G */
3925 if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
3929 /* All interlaced capable intel hw wants timings in frames. Note though
3930 * that intel_lvds_mode_fixup does some funny tricks with the crtc
3931 * timings, so we need to be careful not to clobber these.*/
3932 if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
3933 drm_mode_set_crtcinfo(adjusted_mode, 0);
3935 /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
3936 * with a hsync front porch of 0.
3938 if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
3939 adjusted_mode->hsync_start == adjusted_mode->hdisplay)
3945 static int valleyview_get_display_clock_speed(struct drm_device *dev)
3947 return 400000; /* FIXME */
3950 static int i945_get_display_clock_speed(struct drm_device *dev)
3955 static int i915_get_display_clock_speed(struct drm_device *dev)
3960 static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
3965 static int i915gm_get_display_clock_speed(struct drm_device *dev)
3969 pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
3971 if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
3974 switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
3975 case GC_DISPLAY_CLOCK_333_MHZ:
3978 case GC_DISPLAY_CLOCK_190_200_MHZ:
3984 static int i865_get_display_clock_speed(struct drm_device *dev)
3989 static int i855_get_display_clock_speed(struct drm_device *dev)
3992 /* Assume that the hardware is in the high speed state. This
3993 * should be the default.
3995 switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
3996 case GC_CLOCK_133_200:
3997 case GC_CLOCK_100_200:
3999 case GC_CLOCK_166_250:
4001 case GC_CLOCK_100_133:
4005 /* Shouldn't happen */
4009 static int i830_get_display_clock_speed(struct drm_device *dev)
4015 intel_reduce_ratio(uint32_t *num, uint32_t *den)
4017 while (*num > 0xffffff || *den > 0xffffff) {
4024 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
4025 int pixel_clock, int link_clock,
4026 struct intel_link_m_n *m_n)
4029 m_n->gmch_m = bits_per_pixel * pixel_clock;
4030 m_n->gmch_n = link_clock * nlanes * 8;
4031 intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
4032 m_n->link_m = pixel_clock;
4033 m_n->link_n = link_clock;
4034 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
4037 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
4039 if (i915_panel_use_ssc >= 0)
4040 return i915_panel_use_ssc != 0;
4041 return dev_priv->lvds_use_ssc
4042 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
4046 * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
4047 * @crtc: CRTC structure
4048 * @mode: requested mode
4050 * A pipe may be connected to one or more outputs. Based on the depth of the
4051 * attached framebuffer, choose a good color depth to use on the pipe.
4053 * If possible, match the pipe depth to the fb depth. In some cases, this
4054 * isn't ideal, because the connected output supports a lesser or restricted
4055 * set of depths. Resolve that here:
4056 * LVDS typically supports only 6bpc, so clamp down in that case
4057 * HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
4058 * Displays may support a restricted set as well, check EDID and clamp as
4060 * DP may want to dither down to 6bpc to fit larger modes
4063 * Dithering requirement (i.e. false if display bpc and pipe bpc match,
4064 * true if they don't match).
4066 static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
4067 struct drm_framebuffer *fb,
4068 unsigned int *pipe_bpp,
4069 struct drm_display_mode *mode)
4071 struct drm_device *dev = crtc->dev;
4072 struct drm_i915_private *dev_priv = dev->dev_private;
4073 struct drm_connector *connector;
4074 struct intel_encoder *intel_encoder;
4075 unsigned int display_bpc = UINT_MAX, bpc;
4077 /* Walk the encoders & connectors on this crtc, get min bpc */
4078 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
4080 if (intel_encoder->type == INTEL_OUTPUT_LVDS) {
4081 unsigned int lvds_bpc;
4083 if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) ==
4089 if (lvds_bpc < display_bpc) {
4090 DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
4091 display_bpc = lvds_bpc;
4096 /* Not one of the known troublemakers, check the EDID */
4097 list_for_each_entry(connector, &dev->mode_config.connector_list,
4099 if (connector->encoder != &intel_encoder->base)
4102 /* Don't use an invalid EDID bpc value */
4103 if (connector->display_info.bpc &&
4104 connector->display_info.bpc < display_bpc) {
4105 DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
4106 display_bpc = connector->display_info.bpc;
4110 if (intel_encoder->type == INTEL_OUTPUT_EDP) {
4111 /* Use VBT settings if we have an eDP panel */
4112 unsigned int edp_bpc = dev_priv->edp.bpp / 3;
4114 if (edp_bpc && edp_bpc < display_bpc) {
4115 DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
4116 display_bpc = edp_bpc;
4122 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
4123 * through, clamp it down. (Note: >12bpc will be caught below.)
4125 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
4126 if (display_bpc > 8 && display_bpc < 12) {
4127 DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
4130 DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
4136 if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
4137 DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
4142 * We could just drive the pipe at the highest bpc all the time and
4143 * enable dithering as needed, but that costs bandwidth. So choose
4144 * the minimum value that expresses the full color range of the fb but
4145 * also stays within the max display bpc discovered above.
4148 switch (fb->depth) {
4150 bpc = 8; /* since we go through a colormap */
4154 bpc = 6; /* min is 18bpp */
4166 DRM_DEBUG("unsupported depth, assuming 24 bits\n");
4167 bpc = min((unsigned int)8, display_bpc);
4171 display_bpc = min(display_bpc, bpc);
4173 DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
4176 *pipe_bpp = display_bpc * 3;
4178 return display_bpc != bpc;
4181 static int vlv_get_refclk(struct drm_crtc *crtc)
4183 struct drm_device *dev = crtc->dev;
4184 struct drm_i915_private *dev_priv = dev->dev_private;
4185 int refclk = 27000; /* for DP & HDMI */
4187 return 100000; /* only one validated so far */
4189 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
4191 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
4192 if (intel_panel_use_ssc(dev_priv))
4196 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
4203 static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
4205 struct drm_device *dev = crtc->dev;
4206 struct drm_i915_private *dev_priv = dev->dev_private;
4209 if (IS_VALLEYVIEW(dev)) {
4210 refclk = vlv_get_refclk(crtc);
4211 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4212 intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
4213 refclk = dev_priv->lvds_ssc_freq * 1000;
4214 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
4216 } else if (!IS_GEN2(dev)) {
4225 static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode *adjusted_mode,
4226 intel_clock_t *clock)
4228 /* SDVO TV has fixed PLL values depend on its clock range,
4229 this mirrors vbios setting. */
4230 if (adjusted_mode->clock >= 100000
4231 && adjusted_mode->clock < 140500) {
4237 } else if (adjusted_mode->clock >= 140500
4238 && adjusted_mode->clock <= 200000) {
4247 static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
4248 intel_clock_t *clock,
4249 intel_clock_t *reduced_clock)
4251 struct drm_device *dev = crtc->dev;
4252 struct drm_i915_private *dev_priv = dev->dev_private;
4253 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4254 int pipe = intel_crtc->pipe;
4257 if (IS_PINEVIEW(dev)) {
4258 fp = (1 << clock->n) << 16 | clock->m1 << 8 | clock->m2;
4260 fp2 = (1 << reduced_clock->n) << 16 |
4261 reduced_clock->m1 << 8 | reduced_clock->m2;
4263 fp = clock->n << 16 | clock->m1 << 8 | clock->m2;
4265 fp2 = reduced_clock->n << 16 | reduced_clock->m1 << 8 |
4269 I915_WRITE(FP0(pipe), fp);
4271 intel_crtc->lowfreq_avail = false;
4272 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4273 reduced_clock && i915_powersave) {
4274 I915_WRITE(FP1(pipe), fp2);
4275 intel_crtc->lowfreq_avail = true;
4277 I915_WRITE(FP1(pipe), fp);
4281 static void vlv_update_pll(struct drm_crtc *crtc,
4282 struct drm_display_mode *mode,
4283 struct drm_display_mode *adjusted_mode,
4284 intel_clock_t *clock, intel_clock_t *reduced_clock,
4287 struct drm_device *dev = crtc->dev;
4288 struct drm_i915_private *dev_priv = dev->dev_private;
4289 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4290 int pipe = intel_crtc->pipe;
4291 u32 dpll, mdiv, pdiv;
4292 u32 bestn, bestm1, bestm2, bestp1, bestp2;
4296 mutex_lock(&dev_priv->dpio_lock);
4298 is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
4299 intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
4301 dpll = DPLL_VGA_MODE_DIS;
4302 dpll |= DPLL_EXT_BUFFER_ENABLE_VLV;
4303 dpll |= DPLL_REFA_CLK_ENABLE_VLV;
4304 dpll |= DPLL_INTEGRATED_CLOCK_VLV;
4306 I915_WRITE(DPLL(pipe), dpll);
4307 POSTING_READ(DPLL(pipe));
4316 * In Valleyview PLL and program lane counter registers are exposed
4317 * through DPIO interface
4319 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
4320 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
4321 mdiv |= ((bestn << DPIO_N_SHIFT));
4322 mdiv |= (1 << DPIO_POST_DIV_SHIFT);
4323 mdiv |= (1 << DPIO_K_SHIFT);
4324 mdiv |= DPIO_ENABLE_CALIBRATION;
4325 intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv);
4327 intel_dpio_write(dev_priv, DPIO_CORE_CLK(pipe), 0x01000000);
4329 pdiv = (1 << DPIO_REFSEL_OVERRIDE) | (5 << DPIO_PLL_MODESEL_SHIFT) |
4330 (3 << DPIO_BIAS_CURRENT_CTL_SHIFT) | (1<<20) |
4331 (7 << DPIO_PLL_REFCLK_SEL_SHIFT) | (8 << DPIO_DRIVER_CTL_SHIFT) |
4332 (5 << DPIO_CLK_BIAS_CTL_SHIFT);
4333 intel_dpio_write(dev_priv, DPIO_REFSFR(pipe), pdiv);
4335 intel_dpio_write(dev_priv, DPIO_LFP_COEFF(pipe), 0x005f003b);
4337 dpll |= DPLL_VCO_ENABLE;
4338 I915_WRITE(DPLL(pipe), dpll);
4339 POSTING_READ(DPLL(pipe));
4340 if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
4341 DRM_ERROR("DPLL %d failed to lock\n", pipe);
4343 intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620);
4345 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
4346 intel_dp_set_m_n(crtc, mode, adjusted_mode);
4348 I915_WRITE(DPLL(pipe), dpll);
4350 /* Wait for the clocks to stabilize. */
4351 POSTING_READ(DPLL(pipe));
4356 temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4358 temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
4362 I915_WRITE(DPLL_MD(pipe), temp);
4363 POSTING_READ(DPLL_MD(pipe));
4365 /* Now program lane control registers */
4366 if(intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)
4367 || intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
4372 intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp);
4374 if(intel_pipe_has_type(crtc,INTEL_OUTPUT_EDP))
4379 intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL2, temp);
4382 mutex_unlock(&dev_priv->dpio_lock);
4385 static void i9xx_update_pll(struct drm_crtc *crtc,
4386 struct drm_display_mode *mode,
4387 struct drm_display_mode *adjusted_mode,
4388 intel_clock_t *clock, intel_clock_t *reduced_clock,
4391 struct drm_device *dev = crtc->dev;
4392 struct drm_i915_private *dev_priv = dev->dev_private;
4393 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4394 struct intel_encoder *encoder;
4395 int pipe = intel_crtc->pipe;
4399 i9xx_update_pll_dividers(crtc, clock, reduced_clock);
4401 is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
4402 intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
4404 dpll = DPLL_VGA_MODE_DIS;
4406 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
4407 dpll |= DPLLB_MODE_LVDS;
4409 dpll |= DPLLB_MODE_DAC_SERIAL;
4411 int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
4412 if (pixel_multiplier > 1) {
4413 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
4414 dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
4416 dpll |= DPLL_DVO_HIGH_SPEED;
4418 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
4419 dpll |= DPLL_DVO_HIGH_SPEED;
4421 /* compute bitmask from p1 value */
4422 if (IS_PINEVIEW(dev))
4423 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
4425 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4426 if (IS_G4X(dev) && reduced_clock)
4427 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
4429 switch (clock->p2) {
4431 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
4434 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
4437 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
4440 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
4443 if (INTEL_INFO(dev)->gen >= 4)
4444 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
4446 if (is_sdvo && intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4447 dpll |= PLL_REF_INPUT_TVCLKINBC;
4448 else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4449 /* XXX: just matching BIOS for now */
4450 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
4452 else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4453 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4454 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4456 dpll |= PLL_REF_INPUT_DREFCLK;
4458 dpll |= DPLL_VCO_ENABLE;
4459 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
4460 POSTING_READ(DPLL(pipe));
4463 for_each_encoder_on_crtc(dev, crtc, encoder)
4464 if (encoder->pre_pll_enable)
4465 encoder->pre_pll_enable(encoder);
4467 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
4468 intel_dp_set_m_n(crtc, mode, adjusted_mode);
4470 I915_WRITE(DPLL(pipe), dpll);
4472 /* Wait for the clocks to stabilize. */
4473 POSTING_READ(DPLL(pipe));
4476 if (INTEL_INFO(dev)->gen >= 4) {
4479 temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4481 temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
4485 I915_WRITE(DPLL_MD(pipe), temp);
4487 /* The pixel multiplier can only be updated once the
4488 * DPLL is enabled and the clocks are stable.
4490 * So write it again.
4492 I915_WRITE(DPLL(pipe), dpll);
4496 static void i8xx_update_pll(struct drm_crtc *crtc,
4497 struct drm_display_mode *adjusted_mode,
4498 intel_clock_t *clock, intel_clock_t *reduced_clock,
4501 struct drm_device *dev = crtc->dev;
4502 struct drm_i915_private *dev_priv = dev->dev_private;
4503 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4504 struct intel_encoder *encoder;
4505 int pipe = intel_crtc->pipe;
4508 i9xx_update_pll_dividers(crtc, clock, reduced_clock);
4510 dpll = DPLL_VGA_MODE_DIS;
4512 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
4513 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4516 dpll |= PLL_P1_DIVIDE_BY_TWO;
4518 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4520 dpll |= PLL_P2_DIVIDE_BY_4;
4523 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4524 /* XXX: just matching BIOS for now */
4525 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
4527 else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4528 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4529 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4531 dpll |= PLL_REF_INPUT_DREFCLK;
4533 dpll |= DPLL_VCO_ENABLE;
4534 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
4535 POSTING_READ(DPLL(pipe));
4538 for_each_encoder_on_crtc(dev, crtc, encoder)
4539 if (encoder->pre_pll_enable)
4540 encoder->pre_pll_enable(encoder);
4542 I915_WRITE(DPLL(pipe), dpll);
4544 /* Wait for the clocks to stabilize. */
4545 POSTING_READ(DPLL(pipe));
4548 /* The pixel multiplier can only be updated once the
4549 * DPLL is enabled and the clocks are stable.
4551 * So write it again.
4553 I915_WRITE(DPLL(pipe), dpll);
4556 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc,
4557 struct drm_display_mode *mode,
4558 struct drm_display_mode *adjusted_mode)
4560 struct drm_device *dev = intel_crtc->base.dev;
4561 struct drm_i915_private *dev_priv = dev->dev_private;
4562 enum pipe pipe = intel_crtc->pipe;
4563 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
4564 uint32_t vsyncshift;
4566 if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4567 /* the chip adds 2 halflines automatically */
4568 adjusted_mode->crtc_vtotal -= 1;
4569 adjusted_mode->crtc_vblank_end -= 1;
4570 vsyncshift = adjusted_mode->crtc_hsync_start
4571 - adjusted_mode->crtc_htotal / 2;
4576 if (INTEL_INFO(dev)->gen > 3)
4577 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
4579 I915_WRITE(HTOTAL(cpu_transcoder),
4580 (adjusted_mode->crtc_hdisplay - 1) |
4581 ((adjusted_mode->crtc_htotal - 1) << 16));
4582 I915_WRITE(HBLANK(cpu_transcoder),
4583 (adjusted_mode->crtc_hblank_start - 1) |
4584 ((adjusted_mode->crtc_hblank_end - 1) << 16));
4585 I915_WRITE(HSYNC(cpu_transcoder),
4586 (adjusted_mode->crtc_hsync_start - 1) |
4587 ((adjusted_mode->crtc_hsync_end - 1) << 16));
4589 I915_WRITE(VTOTAL(cpu_transcoder),
4590 (adjusted_mode->crtc_vdisplay - 1) |
4591 ((adjusted_mode->crtc_vtotal - 1) << 16));
4592 I915_WRITE(VBLANK(cpu_transcoder),
4593 (adjusted_mode->crtc_vblank_start - 1) |
4594 ((adjusted_mode->crtc_vblank_end - 1) << 16));
4595 I915_WRITE(VSYNC(cpu_transcoder),
4596 (adjusted_mode->crtc_vsync_start - 1) |
4597 ((adjusted_mode->crtc_vsync_end - 1) << 16));
4599 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
4600 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
4601 * documented on the DDI_FUNC_CTL register description, EDP Input Select
4603 if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
4604 (pipe == PIPE_B || pipe == PIPE_C))
4605 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
4607 /* pipesrc controls the size that is scaled from, which should
4608 * always be the user's requested size.
4610 I915_WRITE(PIPESRC(pipe),
4611 ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
4614 static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
4615 struct drm_display_mode *mode,
4616 struct drm_display_mode *adjusted_mode,
4618 struct drm_framebuffer *fb)
4620 struct drm_device *dev = crtc->dev;
4621 struct drm_i915_private *dev_priv = dev->dev_private;
4622 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4623 int pipe = intel_crtc->pipe;
4624 int plane = intel_crtc->plane;
4625 int refclk, num_connectors = 0;
4626 intel_clock_t clock, reduced_clock;
4627 u32 dspcntr, pipeconf;
4628 bool ok, has_reduced_clock = false, is_sdvo = false;
4629 bool is_lvds = false, is_tv = false, is_dp = false;
4630 struct intel_encoder *encoder;
4631 const intel_limit_t *limit;
4634 for_each_encoder_on_crtc(dev, crtc, encoder) {
4635 switch (encoder->type) {
4636 case INTEL_OUTPUT_LVDS:
4639 case INTEL_OUTPUT_SDVO:
4640 case INTEL_OUTPUT_HDMI:
4642 if (encoder->needs_tv_clock)
4645 case INTEL_OUTPUT_TVOUT:
4648 case INTEL_OUTPUT_DISPLAYPORT:
4656 refclk = i9xx_get_refclk(crtc, num_connectors);
4659 * Returns a set of divisors for the desired target clock with the given
4660 * refclk, or FALSE. The returned values represent the clock equation:
4661 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
4663 limit = intel_limit(crtc, refclk);
4664 ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
4667 DRM_ERROR("Couldn't find PLL settings for mode!\n");
4671 /* Ensure that the cursor is valid for the new mode before changing... */
4672 intel_crtc_update_cursor(crtc, true);
4674 if (is_lvds && dev_priv->lvds_downclock_avail) {
4676 * Ensure we match the reduced clock's P to the target clock.
4677 * If the clocks don't match, we can't switch the display clock
4678 * by using the FP0/FP1. In such case we will disable the LVDS
4679 * downclock feature.
4681 has_reduced_clock = limit->find_pll(limit, crtc,
4682 dev_priv->lvds_downclock,
4688 if (is_sdvo && is_tv)
4689 i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
4692 i8xx_update_pll(crtc, adjusted_mode, &clock,
4693 has_reduced_clock ? &reduced_clock : NULL,
4695 else if (IS_VALLEYVIEW(dev))
4696 vlv_update_pll(crtc, mode, adjusted_mode, &clock,
4697 has_reduced_clock ? &reduced_clock : NULL,
4700 i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
4701 has_reduced_clock ? &reduced_clock : NULL,
4704 /* setup pipeconf */
4705 pipeconf = I915_READ(PIPECONF(pipe));
4707 /* Set up the display plane register */
4708 dspcntr = DISPPLANE_GAMMA_ENABLE;
4711 dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
4713 dspcntr |= DISPPLANE_SEL_PIPE_B;
4715 if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
4716 /* Enable pixel doubling when the dot clock is > 90% of the (display)
4719 * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
4723 dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
4724 pipeconf |= PIPECONF_DOUBLE_WIDE;
4726 pipeconf &= ~PIPECONF_DOUBLE_WIDE;
4729 /* default to 8bpc */
4730 pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
4732 if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
4733 pipeconf |= PIPECONF_6BPC |
4734 PIPECONF_DITHER_EN |
4735 PIPECONF_DITHER_TYPE_SP;
4739 if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
4740 if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
4741 pipeconf |= PIPECONF_6BPC |
4743 I965_PIPECONF_ACTIVE;
4747 DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
4748 drm_mode_debug_printmodeline(mode);
4750 if (HAS_PIPE_CXSR(dev)) {
4751 if (intel_crtc->lowfreq_avail) {
4752 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
4753 pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
4755 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
4756 pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
4760 pipeconf &= ~PIPECONF_INTERLACE_MASK;
4761 if (!IS_GEN2(dev) &&
4762 adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
4763 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
4765 pipeconf |= PIPECONF_PROGRESSIVE;
4767 intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
4769 /* pipesrc and dspsize control the size that is scaled from,
4770 * which should always be the user's requested size.
4772 I915_WRITE(DSPSIZE(plane),
4773 ((mode->vdisplay - 1) << 16) |
4774 (mode->hdisplay - 1));
4775 I915_WRITE(DSPPOS(plane), 0);
4777 I915_WRITE(PIPECONF(pipe), pipeconf);
4778 POSTING_READ(PIPECONF(pipe));
4779 intel_enable_pipe(dev_priv, pipe, false);
4781 intel_wait_for_vblank(dev, pipe);
4783 I915_WRITE(DSPCNTR(plane), dspcntr);
4784 POSTING_READ(DSPCNTR(plane));
4786 ret = intel_pipe_set_base(crtc, x, y, fb);
4788 intel_update_watermarks(dev);
4793 static void ironlake_init_pch_refclk(struct drm_device *dev)
4795 struct drm_i915_private *dev_priv = dev->dev_private;
4796 struct drm_mode_config *mode_config = &dev->mode_config;
4797 struct intel_encoder *encoder;
4799 bool has_lvds = false;
4800 bool has_cpu_edp = false;
4801 bool has_pch_edp = false;
4802 bool has_panel = false;
4803 bool has_ck505 = false;
4804 bool can_ssc = false;
4806 /* We need to take the global config into account */
4807 list_for_each_entry(encoder, &mode_config->encoder_list,
4809 switch (encoder->type) {
4810 case INTEL_OUTPUT_LVDS:
4814 case INTEL_OUTPUT_EDP:
4816 if (intel_encoder_is_pch_edp(&encoder->base))
4824 if (HAS_PCH_IBX(dev)) {
4825 has_ck505 = dev_priv->display_clock_mode;
4826 can_ssc = has_ck505;
4832 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n",
4833 has_panel, has_lvds, has_pch_edp, has_cpu_edp,
4836 /* Ironlake: try to setup display ref clock before DPLL
4837 * enabling. This is only under driver's control after
4838 * PCH B stepping, previous chipset stepping should be
4839 * ignoring this setting.
4841 temp = I915_READ(PCH_DREF_CONTROL);
4842 /* Always enable nonspread source */
4843 temp &= ~DREF_NONSPREAD_SOURCE_MASK;
4846 temp |= DREF_NONSPREAD_CK505_ENABLE;
4848 temp |= DREF_NONSPREAD_SOURCE_ENABLE;
4851 temp &= ~DREF_SSC_SOURCE_MASK;
4852 temp |= DREF_SSC_SOURCE_ENABLE;
4854 /* SSC must be turned on before enabling the CPU output */
4855 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4856 DRM_DEBUG_KMS("Using SSC on panel\n");
4857 temp |= DREF_SSC1_ENABLE;
4859 temp &= ~DREF_SSC1_ENABLE;
4861 /* Get SSC going before enabling the outputs */
4862 I915_WRITE(PCH_DREF_CONTROL, temp);
4863 POSTING_READ(PCH_DREF_CONTROL);
4866 temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4868 /* Enable CPU source on CPU attached eDP */
4870 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4871 DRM_DEBUG_KMS("Using SSC on eDP\n");
4872 temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
4875 temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
4877 temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4879 I915_WRITE(PCH_DREF_CONTROL, temp);
4880 POSTING_READ(PCH_DREF_CONTROL);
4883 DRM_DEBUG_KMS("Disabling SSC entirely\n");
4885 temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4887 /* Turn off CPU output */
4888 temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4890 I915_WRITE(PCH_DREF_CONTROL, temp);
4891 POSTING_READ(PCH_DREF_CONTROL);
4894 /* Turn off the SSC source */
4895 temp &= ~DREF_SSC_SOURCE_MASK;
4896 temp |= DREF_SSC_SOURCE_DISABLE;
4899 temp &= ~ DREF_SSC1_ENABLE;
4901 I915_WRITE(PCH_DREF_CONTROL, temp);
4902 POSTING_READ(PCH_DREF_CONTROL);
4907 /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
4908 static void lpt_init_pch_refclk(struct drm_device *dev)
4910 struct drm_i915_private *dev_priv = dev->dev_private;
4911 struct drm_mode_config *mode_config = &dev->mode_config;
4912 struct intel_encoder *encoder;
4913 bool has_vga = false;
4914 bool is_sdv = false;
4917 list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
4918 switch (encoder->type) {
4919 case INTEL_OUTPUT_ANALOG:
4928 mutex_lock(&dev_priv->dpio_lock);
4930 /* XXX: Rip out SDV support once Haswell ships for real. */
4931 if (IS_HASWELL(dev) && (dev->pci_device & 0xFF00) == 0x0C00)
4934 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
4935 tmp &= ~SBI_SSCCTL_DISABLE;
4936 tmp |= SBI_SSCCTL_PATHALT;
4937 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
4941 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
4942 tmp &= ~SBI_SSCCTL_PATHALT;
4943 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
4946 tmp = I915_READ(SOUTH_CHICKEN2);
4947 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
4948 I915_WRITE(SOUTH_CHICKEN2, tmp);
4950 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
4951 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
4952 DRM_ERROR("FDI mPHY reset assert timeout\n");
4954 tmp = I915_READ(SOUTH_CHICKEN2);
4955 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
4956 I915_WRITE(SOUTH_CHICKEN2, tmp);
4958 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
4959 FDI_MPHY_IOSFSB_RESET_STATUS) == 0,
4961 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
4964 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
4965 tmp &= ~(0xFF << 24);
4966 tmp |= (0x12 << 24);
4967 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
4970 tmp = intel_sbi_read(dev_priv, 0x808C, SBI_MPHY);
4972 tmp |= (1 << 6) | (1 << 0);
4973 intel_sbi_write(dev_priv, 0x808C, tmp, SBI_MPHY);
4977 tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY);
4979 intel_sbi_write(dev_priv, 0x800C, tmp, SBI_MPHY);
4982 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
4984 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
4986 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
4988 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
4991 tmp = intel_sbi_read(dev_priv, 0x2038, SBI_MPHY);
4992 tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
4993 intel_sbi_write(dev_priv, 0x2038, tmp, SBI_MPHY);
4995 tmp = intel_sbi_read(dev_priv, 0x2138, SBI_MPHY);
4996 tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
4997 intel_sbi_write(dev_priv, 0x2138, tmp, SBI_MPHY);
4999 tmp = intel_sbi_read(dev_priv, 0x203C, SBI_MPHY);
5001 intel_sbi_write(dev_priv, 0x203C, tmp, SBI_MPHY);
5003 tmp = intel_sbi_read(dev_priv, 0x213C, SBI_MPHY);
5005 intel_sbi_write(dev_priv, 0x213C, tmp, SBI_MPHY);
5008 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
5009 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
5010 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
5012 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
5013 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
5014 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
5017 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
5020 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
5022 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
5025 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
5028 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
5031 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
5033 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
5036 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
5038 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
5039 tmp &= ~(0xFF << 16);
5040 tmp |= (0x1C << 16);
5041 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
5043 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
5044 tmp &= ~(0xFF << 16);
5045 tmp |= (0x1C << 16);
5046 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
5049 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
5051 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
5053 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
5055 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
5057 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
5058 tmp &= ~(0xF << 28);
5060 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
5062 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
5063 tmp &= ~(0xF << 28);
5065 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
5068 /* ULT uses SBI_GEN0, but ULT doesn't have VGA, so we don't care. */
5069 tmp = intel_sbi_read(dev_priv, SBI_DBUFF0, SBI_ICLK);
5070 tmp |= SBI_DBUFF0_ENABLE;
5071 intel_sbi_write(dev_priv, SBI_DBUFF0, tmp, SBI_ICLK);
5073 mutex_unlock(&dev_priv->dpio_lock);
5077 * Initialize reference clocks when the driver loads
5079 void intel_init_pch_refclk(struct drm_device *dev)
5081 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
5082 ironlake_init_pch_refclk(dev);
5083 else if (HAS_PCH_LPT(dev))
5084 lpt_init_pch_refclk(dev);
5087 static int ironlake_get_refclk(struct drm_crtc *crtc)
5089 struct drm_device *dev = crtc->dev;
5090 struct drm_i915_private *dev_priv = dev->dev_private;
5091 struct intel_encoder *encoder;
5092 struct intel_encoder *edp_encoder = NULL;
5093 int num_connectors = 0;
5094 bool is_lvds = false;
5096 for_each_encoder_on_crtc(dev, crtc, encoder) {
5097 switch (encoder->type) {
5098 case INTEL_OUTPUT_LVDS:
5101 case INTEL_OUTPUT_EDP:
5102 edp_encoder = encoder;
5108 if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
5109 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
5110 dev_priv->lvds_ssc_freq);
5111 return dev_priv->lvds_ssc_freq * 1000;
5117 static void ironlake_set_pipeconf(struct drm_crtc *crtc,
5118 struct drm_display_mode *adjusted_mode,
5121 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
5122 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5123 int pipe = intel_crtc->pipe;
5126 val = I915_READ(PIPECONF(pipe));
5128 val &= ~PIPECONF_BPC_MASK;
5129 switch (intel_crtc->bpp) {
5131 val |= PIPECONF_6BPC;
5134 val |= PIPECONF_8BPC;
5137 val |= PIPECONF_10BPC;
5140 val |= PIPECONF_12BPC;
5143 /* Case prevented by intel_choose_pipe_bpp_dither. */
5147 val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
5149 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
5151 val &= ~PIPECONF_INTERLACE_MASK;
5152 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
5153 val |= PIPECONF_INTERLACED_ILK;
5155 val |= PIPECONF_PROGRESSIVE;
5157 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5158 val |= PIPECONF_COLOR_RANGE_SELECT;
5160 val &= ~PIPECONF_COLOR_RANGE_SELECT;
5162 I915_WRITE(PIPECONF(pipe), val);
5163 POSTING_READ(PIPECONF(pipe));
5167 * Set up the pipe CSC unit.
5169 * Currently only full range RGB to limited range RGB conversion
5170 * is supported, but eventually this should handle various
5171 * RGB<->YCbCr scenarios as well.
5173 static void intel_set_pipe_csc(struct drm_crtc *crtc,
5174 const struct drm_display_mode *adjusted_mode)
5176 struct drm_device *dev = crtc->dev;
5177 struct drm_i915_private *dev_priv = dev->dev_private;
5178 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5179 int pipe = intel_crtc->pipe;
5180 uint16_t coeff = 0x7800; /* 1.0 */
5183 * TODO: Check what kind of values actually come out of the pipe
5184 * with these coeff/postoff values and adjust to get the best
5185 * accuracy. Perhaps we even need to take the bpc value into
5189 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5190 coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
5193 * GY/GU and RY/RU should be the other way around according
5194 * to BSpec, but reality doesn't agree. Just set them up in
5195 * a way that results in the correct picture.
5197 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
5198 I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
5200 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
5201 I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
5203 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
5204 I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
5206 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
5207 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
5208 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
5210 if (INTEL_INFO(dev)->gen > 6) {
5211 uint16_t postoff = 0;
5213 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5214 postoff = (16 * (1 << 13) / 255) & 0x1fff;
5216 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
5217 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
5218 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
5220 I915_WRITE(PIPE_CSC_MODE(pipe), 0);
5222 uint32_t mode = CSC_MODE_YUV_TO_RGB;
5224 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5225 mode |= CSC_BLACK_SCREEN_OFFSET;
5227 I915_WRITE(PIPE_CSC_MODE(pipe), mode);
5231 static void haswell_set_pipeconf(struct drm_crtc *crtc,
5232 struct drm_display_mode *adjusted_mode,
5235 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
5236 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5237 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
5240 val = I915_READ(PIPECONF(cpu_transcoder));
5242 val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
5244 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
5246 val &= ~PIPECONF_INTERLACE_MASK_HSW;
5247 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
5248 val |= PIPECONF_INTERLACED_ILK;
5250 val |= PIPECONF_PROGRESSIVE;
5252 I915_WRITE(PIPECONF(cpu_transcoder), val);
5253 POSTING_READ(PIPECONF(cpu_transcoder));
5256 static bool ironlake_compute_clocks(struct drm_crtc *crtc,
5257 struct drm_display_mode *adjusted_mode,
5258 intel_clock_t *clock,
5259 bool *has_reduced_clock,
5260 intel_clock_t *reduced_clock)
5262 struct drm_device *dev = crtc->dev;
5263 struct drm_i915_private *dev_priv = dev->dev_private;
5264 struct intel_encoder *intel_encoder;
5266 const intel_limit_t *limit;
5267 bool ret, is_sdvo = false, is_tv = false, is_lvds = false;
5269 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
5270 switch (intel_encoder->type) {
5271 case INTEL_OUTPUT_LVDS:
5274 case INTEL_OUTPUT_SDVO:
5275 case INTEL_OUTPUT_HDMI:
5277 if (intel_encoder->needs_tv_clock)
5280 case INTEL_OUTPUT_TVOUT:
5286 refclk = ironlake_get_refclk(crtc);
5289 * Returns a set of divisors for the desired target clock with the given
5290 * refclk, or FALSE. The returned values represent the clock equation:
5291 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
5293 limit = intel_limit(crtc, refclk);
5294 ret = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
5299 if (is_lvds && dev_priv->lvds_downclock_avail) {
5301 * Ensure we match the reduced clock's P to the target clock.
5302 * If the clocks don't match, we can't switch the display clock
5303 * by using the FP0/FP1. In such case we will disable the LVDS
5304 * downclock feature.
5306 *has_reduced_clock = limit->find_pll(limit, crtc,
5307 dev_priv->lvds_downclock,
5313 if (is_sdvo && is_tv)
5314 i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
5319 static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
5321 struct drm_i915_private *dev_priv = dev->dev_private;
5324 temp = I915_READ(SOUTH_CHICKEN1);
5325 if (temp & FDI_BC_BIFURCATION_SELECT)
5328 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
5329 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
5331 temp |= FDI_BC_BIFURCATION_SELECT;
5332 DRM_DEBUG_KMS("enabling fdi C rx\n");
5333 I915_WRITE(SOUTH_CHICKEN1, temp);
5334 POSTING_READ(SOUTH_CHICKEN1);
5337 static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
5339 struct drm_device *dev = intel_crtc->base.dev;
5340 struct drm_i915_private *dev_priv = dev->dev_private;
5341 struct intel_crtc *pipe_B_crtc =
5342 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
5344 DRM_DEBUG_KMS("checking fdi config on pipe %i, lanes %i\n",
5345 intel_crtc->pipe, intel_crtc->fdi_lanes);
5346 if (intel_crtc->fdi_lanes > 4) {
5347 DRM_DEBUG_KMS("invalid fdi lane config on pipe %i: %i lanes\n",
5348 intel_crtc->pipe, intel_crtc->fdi_lanes);
5349 /* Clamp lanes to avoid programming the hw with bogus values. */
5350 intel_crtc->fdi_lanes = 4;
5355 if (dev_priv->num_pipe == 2)
5358 switch (intel_crtc->pipe) {
5362 if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
5363 intel_crtc->fdi_lanes > 2) {
5364 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
5365 intel_crtc->pipe, intel_crtc->fdi_lanes);
5366 /* Clamp lanes to avoid programming the hw with bogus values. */
5367 intel_crtc->fdi_lanes = 2;
5372 if (intel_crtc->fdi_lanes > 2)
5373 WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
5375 cpt_enable_fdi_bc_bifurcation(dev);
5379 if (!pipe_B_crtc->base.enabled || pipe_B_crtc->fdi_lanes <= 2) {
5380 if (intel_crtc->fdi_lanes > 2) {
5381 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
5382 intel_crtc->pipe, intel_crtc->fdi_lanes);
5383 /* Clamp lanes to avoid programming the hw with bogus values. */
5384 intel_crtc->fdi_lanes = 2;
5389 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5393 cpt_enable_fdi_bc_bifurcation(dev);
5401 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
5404 * Account for spread spectrum to avoid
5405 * oversubscribing the link. Max center spread
5406 * is 2.5%; use 5% for safety's sake.
5408 u32 bps = target_clock * bpp * 21 / 20;
5409 return bps / (link_bw * 8) + 1;
5412 static void ironlake_set_m_n(struct drm_crtc *crtc,
5413 struct drm_display_mode *mode,
5414 struct drm_display_mode *adjusted_mode)
5416 struct drm_device *dev = crtc->dev;
5417 struct drm_i915_private *dev_priv = dev->dev_private;
5418 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5419 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
5420 struct intel_encoder *intel_encoder, *edp_encoder = NULL;
5421 struct intel_link_m_n m_n = {0};
5422 int target_clock, pixel_multiplier, lane, link_bw;
5423 bool is_dp = false, is_cpu_edp = false;
5425 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
5426 switch (intel_encoder->type) {
5427 case INTEL_OUTPUT_DISPLAYPORT:
5430 case INTEL_OUTPUT_EDP:
5432 if (!intel_encoder_is_pch_edp(&intel_encoder->base))
5434 edp_encoder = intel_encoder;
5440 pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
5442 /* CPU eDP doesn't require FDI link, so just set DP M/N
5443 according to current link config */
5445 intel_edp_link_config(edp_encoder, &lane, &link_bw);
5447 /* FDI is a binary signal running at ~2.7GHz, encoding
5448 * each output octet as 10 bits. The actual frequency
5449 * is stored as a divider into a 100MHz clock, and the
5450 * mode pixel clock is stored in units of 1KHz.
5451 * Hence the bw of each lane in terms of the mode signal
5454 link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
5457 /* [e]DP over FDI requires target mode clock instead of link clock. */
5459 target_clock = intel_edp_target_clock(edp_encoder, mode);
5461 target_clock = mode->clock;
5463 target_clock = adjusted_mode->clock;
5466 lane = ironlake_get_lanes_required(target_clock, link_bw,
5469 intel_crtc->fdi_lanes = lane;
5471 if (pixel_multiplier > 1)
5472 link_bw *= pixel_multiplier;
5473 intel_link_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, &m_n);
5475 I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m);
5476 I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
5477 I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
5478 I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
5481 static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
5482 struct drm_display_mode *adjusted_mode,
5483 intel_clock_t *clock, u32 fp)
5485 struct drm_crtc *crtc = &intel_crtc->base;
5486 struct drm_device *dev = crtc->dev;
5487 struct drm_i915_private *dev_priv = dev->dev_private;
5488 struct intel_encoder *intel_encoder;
5490 int factor, pixel_multiplier, num_connectors = 0;
5491 bool is_lvds = false, is_sdvo = false, is_tv = false;
5492 bool is_dp = false, is_cpu_edp = false;
5494 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
5495 switch (intel_encoder->type) {
5496 case INTEL_OUTPUT_LVDS:
5499 case INTEL_OUTPUT_SDVO:
5500 case INTEL_OUTPUT_HDMI:
5502 if (intel_encoder->needs_tv_clock)
5505 case INTEL_OUTPUT_TVOUT:
5508 case INTEL_OUTPUT_DISPLAYPORT:
5511 case INTEL_OUTPUT_EDP:
5513 if (!intel_encoder_is_pch_edp(&intel_encoder->base))
5521 /* Enable autotuning of the PLL clock (if permissible) */
5524 if ((intel_panel_use_ssc(dev_priv) &&
5525 dev_priv->lvds_ssc_freq == 100) ||
5526 intel_is_dual_link_lvds(dev))
5528 } else if (is_sdvo && is_tv)
5531 if (clock->m < factor * clock->n)
5537 dpll |= DPLLB_MODE_LVDS;
5539 dpll |= DPLLB_MODE_DAC_SERIAL;
5541 pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
5542 if (pixel_multiplier > 1) {
5543 dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
5545 dpll |= DPLL_DVO_HIGH_SPEED;
5547 if (is_dp && !is_cpu_edp)
5548 dpll |= DPLL_DVO_HIGH_SPEED;
5550 /* compute bitmask from p1 value */
5551 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
5553 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
5555 switch (clock->p2) {
5557 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
5560 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
5563 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
5566 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
5570 if (is_sdvo && is_tv)
5571 dpll |= PLL_REF_INPUT_TVCLKINBC;
5573 /* XXX: just matching BIOS for now */
5574 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
5576 else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
5577 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
5579 dpll |= PLL_REF_INPUT_DREFCLK;
5584 static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
5585 struct drm_display_mode *mode,
5586 struct drm_display_mode *adjusted_mode,
5588 struct drm_framebuffer *fb)
5590 struct drm_device *dev = crtc->dev;
5591 struct drm_i915_private *dev_priv = dev->dev_private;
5592 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5593 int pipe = intel_crtc->pipe;
5594 int plane = intel_crtc->plane;
5595 int num_connectors = 0;
5596 intel_clock_t clock, reduced_clock;
5597 u32 dpll, fp = 0, fp2 = 0;
5598 bool ok, has_reduced_clock = false;
5599 bool is_lvds = false, is_dp = false, is_cpu_edp = false;
5600 struct intel_encoder *encoder;
5602 bool dither, fdi_config_ok;
5604 for_each_encoder_on_crtc(dev, crtc, encoder) {
5605 switch (encoder->type) {
5606 case INTEL_OUTPUT_LVDS:
5609 case INTEL_OUTPUT_DISPLAYPORT:
5612 case INTEL_OUTPUT_EDP:
5614 if (!intel_encoder_is_pch_edp(&encoder->base))
5622 WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
5623 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
5625 ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
5626 &has_reduced_clock, &reduced_clock);
5628 DRM_ERROR("Couldn't find PLL settings for mode!\n");
5632 /* Ensure that the cursor is valid for the new mode before changing... */
5633 intel_crtc_update_cursor(crtc, true);
5635 /* determine panel color depth */
5636 dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
5638 if (is_lvds && dev_priv->lvds_dither)
5641 fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
5642 if (has_reduced_clock)
5643 fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
5646 dpll = ironlake_compute_dpll(intel_crtc, adjusted_mode, &clock, fp);
5648 DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
5649 drm_mode_debug_printmodeline(mode);
5651 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
5653 struct intel_pch_pll *pll;
5655 pll = intel_get_pch_pll(intel_crtc, dpll, fp);
5657 DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
5662 intel_put_pch_pll(intel_crtc);
5664 if (is_dp && !is_cpu_edp)
5665 intel_dp_set_m_n(crtc, mode, adjusted_mode);
5667 for_each_encoder_on_crtc(dev, crtc, encoder)
5668 if (encoder->pre_pll_enable)
5669 encoder->pre_pll_enable(encoder);
5671 if (intel_crtc->pch_pll) {
5672 I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
5674 /* Wait for the clocks to stabilize. */
5675 POSTING_READ(intel_crtc->pch_pll->pll_reg);
5678 /* The pixel multiplier can only be updated once the
5679 * DPLL is enabled and the clocks are stable.
5681 * So write it again.
5683 I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
5686 intel_crtc->lowfreq_avail = false;
5687 if (intel_crtc->pch_pll) {
5688 if (is_lvds && has_reduced_clock && i915_powersave) {
5689 I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp2);
5690 intel_crtc->lowfreq_avail = true;
5692 I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp);
5696 intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
5698 /* Note, this also computes intel_crtc->fdi_lanes which is used below in
5699 * ironlake_check_fdi_lanes. */
5700 ironlake_set_m_n(crtc, mode, adjusted_mode);
5702 fdi_config_ok = ironlake_check_fdi_lanes(intel_crtc);
5704 ironlake_set_pipeconf(crtc, adjusted_mode, dither);
5706 intel_wait_for_vblank(dev, pipe);
5708 /* Set up the display plane register */
5709 I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
5710 POSTING_READ(DSPCNTR(plane));
5712 ret = intel_pipe_set_base(crtc, x, y, fb);
5714 intel_update_watermarks(dev);
5716 intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
5718 return fdi_config_ok ? ret : -EINVAL;
5721 static void haswell_modeset_global_resources(struct drm_device *dev)
5723 struct drm_i915_private *dev_priv = dev->dev_private;
5724 bool enable = false;
5725 struct intel_crtc *crtc;
5726 struct intel_encoder *encoder;
5728 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
5729 if (crtc->pipe != PIPE_A && crtc->base.enabled)
5731 /* XXX: Should check for edp transcoder here, but thanks to init
5732 * sequence that's not yet available. Just in case desktop eDP
5733 * on PORT D is possible on haswell, too. */
5736 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
5738 if (encoder->type != INTEL_OUTPUT_EDP &&
5739 encoder->connectors_active)
5743 /* Even the eDP panel fitter is outside the always-on well. */
5744 if (dev_priv->pch_pf_size)
5747 intel_set_power_well(dev, enable);
5750 static int haswell_crtc_mode_set(struct drm_crtc *crtc,
5751 struct drm_display_mode *mode,
5752 struct drm_display_mode *adjusted_mode,
5754 struct drm_framebuffer *fb)
5756 struct drm_device *dev = crtc->dev;
5757 struct drm_i915_private *dev_priv = dev->dev_private;
5758 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5759 int pipe = intel_crtc->pipe;
5760 int plane = intel_crtc->plane;
5761 int num_connectors = 0;
5762 bool is_dp = false, is_cpu_edp = false;
5763 struct intel_encoder *encoder;
5767 for_each_encoder_on_crtc(dev, crtc, encoder) {
5768 switch (encoder->type) {
5769 case INTEL_OUTPUT_DISPLAYPORT:
5772 case INTEL_OUTPUT_EDP:
5774 if (!intel_encoder_is_pch_edp(&encoder->base))
5782 /* We are not sure yet this won't happen. */
5783 WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
5784 INTEL_PCH_TYPE(dev));
5786 WARN(num_connectors != 1, "%d connectors attached to pipe %c\n",
5787 num_connectors, pipe_name(pipe));
5789 WARN_ON(I915_READ(PIPECONF(intel_crtc->cpu_transcoder)) &
5790 (PIPECONF_ENABLE | I965_PIPECONF_ACTIVE));
5792 WARN_ON(I915_READ(DSPCNTR(plane)) & DISPLAY_PLANE_ENABLE);
5794 if (!intel_ddi_pll_mode_set(crtc, adjusted_mode->clock))
5797 /* Ensure that the cursor is valid for the new mode before changing... */
5798 intel_crtc_update_cursor(crtc, true);
5800 /* determine panel color depth */
5801 dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
5804 DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
5805 drm_mode_debug_printmodeline(mode);
5807 if (is_dp && !is_cpu_edp)
5808 intel_dp_set_m_n(crtc, mode, adjusted_mode);
5810 intel_crtc->lowfreq_avail = false;
5812 intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
5814 if (!is_dp || is_cpu_edp)
5815 ironlake_set_m_n(crtc, mode, adjusted_mode);
5817 haswell_set_pipeconf(crtc, adjusted_mode, dither);
5819 intel_set_pipe_csc(crtc, adjusted_mode);
5821 /* Set up the display plane register */
5822 I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE);
5823 POSTING_READ(DSPCNTR(plane));
5825 ret = intel_pipe_set_base(crtc, x, y, fb);
5827 intel_update_watermarks(dev);
5829 intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
5834 static int intel_crtc_mode_set(struct drm_crtc *crtc,
5835 struct drm_display_mode *mode,
5836 struct drm_display_mode *adjusted_mode,
5838 struct drm_framebuffer *fb)
5840 struct drm_device *dev = crtc->dev;
5841 struct drm_i915_private *dev_priv = dev->dev_private;
5842 struct drm_encoder_helper_funcs *encoder_funcs;
5843 struct intel_encoder *encoder;
5844 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5845 int pipe = intel_crtc->pipe;
5848 if (IS_HASWELL(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
5849 intel_crtc->cpu_transcoder = TRANSCODER_EDP;
5851 intel_crtc->cpu_transcoder = pipe;
5853 drm_vblank_pre_modeset(dev, pipe);
5855 ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
5857 drm_vblank_post_modeset(dev, pipe);
5862 for_each_encoder_on_crtc(dev, crtc, encoder) {
5863 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
5864 encoder->base.base.id,
5865 drm_get_encoder_name(&encoder->base),
5866 mode->base.id, mode->name);
5867 encoder_funcs = encoder->base.helper_private;
5868 encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
5874 static bool intel_eld_uptodate(struct drm_connector *connector,
5875 int reg_eldv, uint32_t bits_eldv,
5876 int reg_elda, uint32_t bits_elda,
5879 struct drm_i915_private *dev_priv = connector->dev->dev_private;
5880 uint8_t *eld = connector->eld;
5883 i = I915_READ(reg_eldv);
5892 i = I915_READ(reg_elda);
5894 I915_WRITE(reg_elda, i);
5896 for (i = 0; i < eld[2]; i++)
5897 if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
5903 static void g4x_write_eld(struct drm_connector *connector,
5904 struct drm_crtc *crtc)
5906 struct drm_i915_private *dev_priv = connector->dev->dev_private;
5907 uint8_t *eld = connector->eld;
5912 i = I915_READ(G4X_AUD_VID_DID);
5914 if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
5915 eldv = G4X_ELDV_DEVCL_DEVBLC;
5917 eldv = G4X_ELDV_DEVCTG;
5919 if (intel_eld_uptodate(connector,
5920 G4X_AUD_CNTL_ST, eldv,
5921 G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
5922 G4X_HDMIW_HDMIEDID))
5925 i = I915_READ(G4X_AUD_CNTL_ST);
5926 i &= ~(eldv | G4X_ELD_ADDR);
5927 len = (i >> 9) & 0x1f; /* ELD buffer size */
5928 I915_WRITE(G4X_AUD_CNTL_ST, i);
5933 len = min_t(uint8_t, eld[2], len);
5934 DRM_DEBUG_DRIVER("ELD size %d\n", len);
5935 for (i = 0; i < len; i++)
5936 I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
5938 i = I915_READ(G4X_AUD_CNTL_ST);
5940 I915_WRITE(G4X_AUD_CNTL_ST, i);
5943 static void haswell_write_eld(struct drm_connector *connector,
5944 struct drm_crtc *crtc)
5946 struct drm_i915_private *dev_priv = connector->dev->dev_private;
5947 uint8_t *eld = connector->eld;
5948 struct drm_device *dev = crtc->dev;
5949 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5953 int pipe = to_intel_crtc(crtc)->pipe;
5956 int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
5957 int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
5958 int aud_config = HSW_AUD_CFG(pipe);
5959 int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
5962 DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n");
5964 /* Audio output enable */
5965 DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
5966 tmp = I915_READ(aud_cntrl_st2);
5967 tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
5968 I915_WRITE(aud_cntrl_st2, tmp);
5970 /* Wait for 1 vertical blank */
5971 intel_wait_for_vblank(dev, pipe);
5973 /* Set ELD valid state */
5974 tmp = I915_READ(aud_cntrl_st2);
5975 DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp);
5976 tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
5977 I915_WRITE(aud_cntrl_st2, tmp);
5978 tmp = I915_READ(aud_cntrl_st2);
5979 DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp);
5981 /* Enable HDMI mode */
5982 tmp = I915_READ(aud_config);
5983 DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp);
5984 /* clear N_programing_enable and N_value_index */
5985 tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
5986 I915_WRITE(aud_config, tmp);
5988 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
5990 eldv = AUDIO_ELD_VALID_A << (pipe * 4);
5991 intel_crtc->eld_vld = true;
5993 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
5994 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
5995 eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
5996 I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
5998 I915_WRITE(aud_config, 0);
6000 if (intel_eld_uptodate(connector,
6001 aud_cntrl_st2, eldv,
6002 aud_cntl_st, IBX_ELD_ADDRESS,
6006 i = I915_READ(aud_cntrl_st2);
6008 I915_WRITE(aud_cntrl_st2, i);
6013 i = I915_READ(aud_cntl_st);
6014 i &= ~IBX_ELD_ADDRESS;
6015 I915_WRITE(aud_cntl_st, i);
6016 i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
6017 DRM_DEBUG_DRIVER("port num:%d\n", i);
6019 len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
6020 DRM_DEBUG_DRIVER("ELD size %d\n", len);
6021 for (i = 0; i < len; i++)
6022 I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
6024 i = I915_READ(aud_cntrl_st2);
6026 I915_WRITE(aud_cntrl_st2, i);
6030 static void ironlake_write_eld(struct drm_connector *connector,
6031 struct drm_crtc *crtc)
6033 struct drm_i915_private *dev_priv = connector->dev->dev_private;
6034 uint8_t *eld = connector->eld;
6042 int pipe = to_intel_crtc(crtc)->pipe;
6044 if (HAS_PCH_IBX(connector->dev)) {
6045 hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
6046 aud_config = IBX_AUD_CFG(pipe);
6047 aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
6048 aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
6050 hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
6051 aud_config = CPT_AUD_CFG(pipe);
6052 aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
6053 aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
6056 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
6058 i = I915_READ(aud_cntl_st);
6059 i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
6061 DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
6062 /* operate blindly on all ports */
6063 eldv = IBX_ELD_VALIDB;
6064 eldv |= IBX_ELD_VALIDB << 4;
6065 eldv |= IBX_ELD_VALIDB << 8;
6067 DRM_DEBUG_DRIVER("ELD on port %c\n", 'A' + i);
6068 eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
6071 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
6072 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
6073 eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
6074 I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
6076 I915_WRITE(aud_config, 0);
6078 if (intel_eld_uptodate(connector,
6079 aud_cntrl_st2, eldv,
6080 aud_cntl_st, IBX_ELD_ADDRESS,
6084 i = I915_READ(aud_cntrl_st2);
6086 I915_WRITE(aud_cntrl_st2, i);
6091 i = I915_READ(aud_cntl_st);
6092 i &= ~IBX_ELD_ADDRESS;
6093 I915_WRITE(aud_cntl_st, i);
6095 len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
6096 DRM_DEBUG_DRIVER("ELD size %d\n", len);
6097 for (i = 0; i < len; i++)
6098 I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
6100 i = I915_READ(aud_cntrl_st2);
6102 I915_WRITE(aud_cntrl_st2, i);
6105 void intel_write_eld(struct drm_encoder *encoder,
6106 struct drm_display_mode *mode)
6108 struct drm_crtc *crtc = encoder->crtc;
6109 struct drm_connector *connector;
6110 struct drm_device *dev = encoder->dev;
6111 struct drm_i915_private *dev_priv = dev->dev_private;
6113 connector = drm_select_eld(encoder, mode);
6117 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6119 drm_get_connector_name(connector),
6120 connector->encoder->base.id,
6121 drm_get_encoder_name(connector->encoder));
6123 connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
6125 if (dev_priv->display.write_eld)
6126 dev_priv->display.write_eld(connector, crtc);
6129 /** Loads the palette/gamma unit for the CRTC with the prepared values */
6130 void intel_crtc_load_lut(struct drm_crtc *crtc)
6132 struct drm_device *dev = crtc->dev;
6133 struct drm_i915_private *dev_priv = dev->dev_private;
6134 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6135 int palreg = PALETTE(intel_crtc->pipe);
6138 /* The clocks have to be on to load the palette. */
6139 if (!crtc->enabled || !intel_crtc->active)
6142 /* use legacy palette for Ironlake */
6143 if (HAS_PCH_SPLIT(dev))
6144 palreg = LGC_PALETTE(intel_crtc->pipe);
6146 for (i = 0; i < 256; i++) {
6147 I915_WRITE(palreg + 4 * i,
6148 (intel_crtc->lut_r[i] << 16) |
6149 (intel_crtc->lut_g[i] << 8) |
6150 intel_crtc->lut_b[i]);
6154 static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
6156 struct drm_device *dev = crtc->dev;
6157 struct drm_i915_private *dev_priv = dev->dev_private;
6158 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6159 bool visible = base != 0;
6162 if (intel_crtc->cursor_visible == visible)
6165 cntl = I915_READ(_CURACNTR);
6167 /* On these chipsets we can only modify the base whilst
6168 * the cursor is disabled.
6170 I915_WRITE(_CURABASE, base);
6172 cntl &= ~(CURSOR_FORMAT_MASK);
6173 /* XXX width must be 64, stride 256 => 0x00 << 28 */
6174 cntl |= CURSOR_ENABLE |
6175 CURSOR_GAMMA_ENABLE |
6178 cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
6179 I915_WRITE(_CURACNTR, cntl);
6181 intel_crtc->cursor_visible = visible;
6184 static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
6186 struct drm_device *dev = crtc->dev;
6187 struct drm_i915_private *dev_priv = dev->dev_private;
6188 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6189 int pipe = intel_crtc->pipe;
6190 bool visible = base != 0;
6192 if (intel_crtc->cursor_visible != visible) {
6193 uint32_t cntl = I915_READ(CURCNTR(pipe));
6195 cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
6196 cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
6197 cntl |= pipe << 28; /* Connect to correct pipe */
6199 cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
6200 cntl |= CURSOR_MODE_DISABLE;
6202 I915_WRITE(CURCNTR(pipe), cntl);
6204 intel_crtc->cursor_visible = visible;
6206 /* and commit changes on next vblank */
6207 I915_WRITE(CURBASE(pipe), base);
6210 static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
6212 struct drm_device *dev = crtc->dev;
6213 struct drm_i915_private *dev_priv = dev->dev_private;
6214 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6215 int pipe = intel_crtc->pipe;
6216 bool visible = base != 0;
6218 if (intel_crtc->cursor_visible != visible) {
6219 uint32_t cntl = I915_READ(CURCNTR_IVB(pipe));
6221 cntl &= ~CURSOR_MODE;
6222 cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
6224 cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
6225 cntl |= CURSOR_MODE_DISABLE;
6227 if (IS_HASWELL(dev))
6228 cntl |= CURSOR_PIPE_CSC_ENABLE;
6229 I915_WRITE(CURCNTR_IVB(pipe), cntl);
6231 intel_crtc->cursor_visible = visible;
6233 /* and commit changes on next vblank */
6234 I915_WRITE(CURBASE_IVB(pipe), base);
6237 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
6238 static void intel_crtc_update_cursor(struct drm_crtc *crtc,
6241 struct drm_device *dev = crtc->dev;
6242 struct drm_i915_private *dev_priv = dev->dev_private;
6243 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6244 int pipe = intel_crtc->pipe;
6245 int x = intel_crtc->cursor_x;
6246 int y = intel_crtc->cursor_y;
6252 if (on && crtc->enabled && crtc->fb) {
6253 base = intel_crtc->cursor_addr;
6254 if (x > (int) crtc->fb->width)
6257 if (y > (int) crtc->fb->height)
6263 if (x + intel_crtc->cursor_width < 0)
6266 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
6269 pos |= x << CURSOR_X_SHIFT;
6272 if (y + intel_crtc->cursor_height < 0)
6275 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
6278 pos |= y << CURSOR_Y_SHIFT;
6280 visible = base != 0;
6281 if (!visible && !intel_crtc->cursor_visible)
6284 if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
6285 I915_WRITE(CURPOS_IVB(pipe), pos);
6286 ivb_update_cursor(crtc, base);
6288 I915_WRITE(CURPOS(pipe), pos);
6289 if (IS_845G(dev) || IS_I865G(dev))
6290 i845_update_cursor(crtc, base);
6292 i9xx_update_cursor(crtc, base);
6296 static int intel_crtc_cursor_set(struct drm_crtc *crtc,
6297 struct drm_file *file,
6299 uint32_t width, uint32_t height)
6301 struct drm_device *dev = crtc->dev;
6302 struct drm_i915_private *dev_priv = dev->dev_private;
6303 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6304 struct drm_i915_gem_object *obj;
6308 /* if we want to turn off the cursor ignore width and height */
6310 DRM_DEBUG_KMS("cursor off\n");
6313 mutex_lock(&dev->struct_mutex);
6317 /* Currently we only support 64x64 cursors */
6318 if (width != 64 || height != 64) {
6319 DRM_ERROR("we currently only support 64x64 cursors\n");
6323 obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
6324 if (&obj->base == NULL)
6327 if (obj->base.size < width * height * 4) {
6328 DRM_ERROR("buffer is to small\n");
6333 /* we only need to pin inside GTT if cursor is non-phy */
6334 mutex_lock(&dev->struct_mutex);
6335 if (!dev_priv->info->cursor_needs_physical) {
6336 if (obj->tiling_mode) {
6337 DRM_ERROR("cursor cannot be tiled\n");
6342 ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL);
6344 DRM_ERROR("failed to move cursor bo into the GTT\n");
6348 ret = i915_gem_object_put_fence(obj);
6350 DRM_ERROR("failed to release fence for cursor");
6354 addr = obj->gtt_offset;
6356 int align = IS_I830(dev) ? 16 * 1024 : 256;
6357 ret = i915_gem_attach_phys_object(dev, obj,
6358 (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
6361 DRM_ERROR("failed to attach phys object\n");
6364 addr = obj->phys_obj->handle->busaddr;
6368 I915_WRITE(CURSIZE, (height << 12) | width);
6371 if (intel_crtc->cursor_bo) {
6372 if (dev_priv->info->cursor_needs_physical) {
6373 if (intel_crtc->cursor_bo != obj)
6374 i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
6376 i915_gem_object_unpin(intel_crtc->cursor_bo);
6377 drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
6380 mutex_unlock(&dev->struct_mutex);
6382 intel_crtc->cursor_addr = addr;
6383 intel_crtc->cursor_bo = obj;
6384 intel_crtc->cursor_width = width;
6385 intel_crtc->cursor_height = height;
6387 intel_crtc_update_cursor(crtc, true);
6391 i915_gem_object_unpin(obj);
6393 mutex_unlock(&dev->struct_mutex);
6395 drm_gem_object_unreference_unlocked(&obj->base);
6399 static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
6401 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6403 intel_crtc->cursor_x = x;
6404 intel_crtc->cursor_y = y;
6406 intel_crtc_update_cursor(crtc, true);
6411 /** Sets the color ramps on behalf of RandR */
6412 void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
6413 u16 blue, int regno)
6415 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6417 intel_crtc->lut_r[regno] = red >> 8;
6418 intel_crtc->lut_g[regno] = green >> 8;
6419 intel_crtc->lut_b[regno] = blue >> 8;
6422 void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
6423 u16 *blue, int regno)
6425 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6427 *red = intel_crtc->lut_r[regno] << 8;
6428 *green = intel_crtc->lut_g[regno] << 8;
6429 *blue = intel_crtc->lut_b[regno] << 8;
6432 static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
6433 u16 *blue, uint32_t start, uint32_t size)
6435 int end = (start + size > 256) ? 256 : start + size, i;
6436 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6438 for (i = start; i < end; i++) {
6439 intel_crtc->lut_r[i] = red[i] >> 8;
6440 intel_crtc->lut_g[i] = green[i] >> 8;
6441 intel_crtc->lut_b[i] = blue[i] >> 8;
6444 intel_crtc_load_lut(crtc);
6448 * Get a pipe with a simple mode set on it for doing load-based monitor
6451 * It will be up to the load-detect code to adjust the pipe as appropriate for
6452 * its requirements. The pipe will be connected to no other encoders.
6454 * Currently this code will only succeed if there is a pipe with no encoders
6455 * configured for it. In the future, it could choose to temporarily disable
6456 * some outputs to free up a pipe for its use.
6458 * \return crtc, or NULL if no pipes are available.
6461 /* VESA 640x480x72Hz mode to set on the pipe */
6462 static struct drm_display_mode load_detect_mode = {
6463 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
6464 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
6467 static struct drm_framebuffer *
6468 intel_framebuffer_create(struct drm_device *dev,
6469 struct drm_mode_fb_cmd2 *mode_cmd,
6470 struct drm_i915_gem_object *obj)
6472 struct intel_framebuffer *intel_fb;
6475 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
6477 drm_gem_object_unreference_unlocked(&obj->base);
6478 return ERR_PTR(-ENOMEM);
6481 ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
6483 drm_gem_object_unreference_unlocked(&obj->base);
6485 return ERR_PTR(ret);
6488 return &intel_fb->base;
6492 intel_framebuffer_pitch_for_width(int width, int bpp)
6494 u32 pitch = DIV_ROUND_UP(width * bpp, 8);
6495 return ALIGN(pitch, 64);
6499 intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
6501 u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
6502 return ALIGN(pitch * mode->vdisplay, PAGE_SIZE);
6505 static struct drm_framebuffer *
6506 intel_framebuffer_create_for_mode(struct drm_device *dev,
6507 struct drm_display_mode *mode,
6510 struct drm_i915_gem_object *obj;
6511 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
6513 obj = i915_gem_alloc_object(dev,
6514 intel_framebuffer_size_for_mode(mode, bpp));
6516 return ERR_PTR(-ENOMEM);
6518 mode_cmd.width = mode->hdisplay;
6519 mode_cmd.height = mode->vdisplay;
6520 mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
6522 mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
6524 return intel_framebuffer_create(dev, &mode_cmd, obj);
6527 static struct drm_framebuffer *
6528 mode_fits_in_fbdev(struct drm_device *dev,
6529 struct drm_display_mode *mode)
6531 struct drm_i915_private *dev_priv = dev->dev_private;
6532 struct drm_i915_gem_object *obj;
6533 struct drm_framebuffer *fb;
6535 if (dev_priv->fbdev == NULL)
6538 obj = dev_priv->fbdev->ifb.obj;
6542 fb = &dev_priv->fbdev->ifb.base;
6543 if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
6544 fb->bits_per_pixel))
6547 if (obj->base.size < mode->vdisplay * fb->pitches[0])
6553 bool intel_get_load_detect_pipe(struct drm_connector *connector,
6554 struct drm_display_mode *mode,
6555 struct intel_load_detect_pipe *old)
6557 struct intel_crtc *intel_crtc;
6558 struct intel_encoder *intel_encoder =
6559 intel_attached_encoder(connector);
6560 struct drm_crtc *possible_crtc;
6561 struct drm_encoder *encoder = &intel_encoder->base;
6562 struct drm_crtc *crtc = NULL;
6563 struct drm_device *dev = encoder->dev;
6564 struct drm_framebuffer *fb;
6567 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6568 connector->base.id, drm_get_connector_name(connector),
6569 encoder->base.id, drm_get_encoder_name(encoder));
6572 * Algorithm gets a little messy:
6574 * - if the connector already has an assigned crtc, use it (but make
6575 * sure it's on first)
6577 * - try to find the first unused crtc that can drive this connector,
6578 * and use that if we find one
6581 /* See if we already have a CRTC for this connector */
6582 if (encoder->crtc) {
6583 crtc = encoder->crtc;
6585 mutex_lock(&crtc->mutex);
6587 old->dpms_mode = connector->dpms;
6588 old->load_detect_temp = false;
6590 /* Make sure the crtc and connector are running */
6591 if (connector->dpms != DRM_MODE_DPMS_ON)
6592 connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
6597 /* Find an unused one (if possible) */
6598 list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
6600 if (!(encoder->possible_crtcs & (1 << i)))
6602 if (!possible_crtc->enabled) {
6603 crtc = possible_crtc;
6609 * If we didn't find an unused CRTC, don't use any.
6612 DRM_DEBUG_KMS("no pipe available for load-detect\n");
6616 mutex_lock(&crtc->mutex);
6617 intel_encoder->new_crtc = to_intel_crtc(crtc);
6618 to_intel_connector(connector)->new_encoder = intel_encoder;
6620 intel_crtc = to_intel_crtc(crtc);
6621 old->dpms_mode = connector->dpms;
6622 old->load_detect_temp = true;
6623 old->release_fb = NULL;
6626 mode = &load_detect_mode;
6628 /* We need a framebuffer large enough to accommodate all accesses
6629 * that the plane may generate whilst we perform load detection.
6630 * We can not rely on the fbcon either being present (we get called
6631 * during its initialisation to detect all boot displays, or it may
6632 * not even exist) or that it is large enough to satisfy the
6635 fb = mode_fits_in_fbdev(dev, mode);
6637 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
6638 fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
6639 old->release_fb = fb;
6641 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
6643 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
6644 mutex_unlock(&crtc->mutex);
6648 if (intel_set_mode(crtc, mode, 0, 0, fb)) {
6649 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
6650 if (old->release_fb)
6651 old->release_fb->funcs->destroy(old->release_fb);
6652 mutex_unlock(&crtc->mutex);
6656 /* let the connector get through one full cycle before testing */
6657 intel_wait_for_vblank(dev, intel_crtc->pipe);
6661 void intel_release_load_detect_pipe(struct drm_connector *connector,
6662 struct intel_load_detect_pipe *old)
6664 struct intel_encoder *intel_encoder =
6665 intel_attached_encoder(connector);
6666 struct drm_encoder *encoder = &intel_encoder->base;
6667 struct drm_crtc *crtc = encoder->crtc;
6669 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6670 connector->base.id, drm_get_connector_name(connector),
6671 encoder->base.id, drm_get_encoder_name(encoder));
6673 if (old->load_detect_temp) {
6674 to_intel_connector(connector)->new_encoder = NULL;
6675 intel_encoder->new_crtc = NULL;
6676 intel_set_mode(crtc, NULL, 0, 0, NULL);
6678 if (old->release_fb) {
6679 drm_framebuffer_unregister_private(old->release_fb);
6680 drm_framebuffer_unreference(old->release_fb);
6683 mutex_unlock(&crtc->mutex);
6687 /* Switch crtc and encoder back off if necessary */
6688 if (old->dpms_mode != DRM_MODE_DPMS_ON)
6689 connector->funcs->dpms(connector, old->dpms_mode);
6691 mutex_unlock(&crtc->mutex);
6694 /* Returns the clock of the currently programmed mode of the given pipe. */
6695 static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
6697 struct drm_i915_private *dev_priv = dev->dev_private;
6698 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6699 int pipe = intel_crtc->pipe;
6700 u32 dpll = I915_READ(DPLL(pipe));
6702 intel_clock_t clock;
6704 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
6705 fp = I915_READ(FP0(pipe));
6707 fp = I915_READ(FP1(pipe));
6709 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
6710 if (IS_PINEVIEW(dev)) {
6711 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
6712 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
6714 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
6715 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
6718 if (!IS_GEN2(dev)) {
6719 if (IS_PINEVIEW(dev))
6720 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
6721 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
6723 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
6724 DPLL_FPA01_P1_POST_DIV_SHIFT);
6726 switch (dpll & DPLL_MODE_MASK) {
6727 case DPLLB_MODE_DAC_SERIAL:
6728 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
6731 case DPLLB_MODE_LVDS:
6732 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
6736 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
6737 "mode\n", (int)(dpll & DPLL_MODE_MASK));
6741 /* XXX: Handle the 100Mhz refclk */
6742 intel_clock(dev, 96000, &clock);
6744 bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
6747 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
6748 DPLL_FPA01_P1_POST_DIV_SHIFT);
6751 if ((dpll & PLL_REF_INPUT_MASK) ==
6752 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
6753 /* XXX: might not be 66MHz */
6754 intel_clock(dev, 66000, &clock);
6756 intel_clock(dev, 48000, &clock);
6758 if (dpll & PLL_P1_DIVIDE_BY_TWO)
6761 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
6762 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
6764 if (dpll & PLL_P2_DIVIDE_BY_4)
6769 intel_clock(dev, 48000, &clock);
6773 /* XXX: It would be nice to validate the clocks, but we can't reuse
6774 * i830PllIsValid() because it relies on the xf86_config connector
6775 * configuration being accurate, which it isn't necessarily.
6781 /** Returns the currently programmed mode of the given pipe. */
6782 struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
6783 struct drm_crtc *crtc)
6785 struct drm_i915_private *dev_priv = dev->dev_private;
6786 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6787 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
6788 struct drm_display_mode *mode;
6789 int htot = I915_READ(HTOTAL(cpu_transcoder));
6790 int hsync = I915_READ(HSYNC(cpu_transcoder));
6791 int vtot = I915_READ(VTOTAL(cpu_transcoder));
6792 int vsync = I915_READ(VSYNC(cpu_transcoder));
6794 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
6798 mode->clock = intel_crtc_clock_get(dev, crtc);
6799 mode->hdisplay = (htot & 0xffff) + 1;
6800 mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
6801 mode->hsync_start = (hsync & 0xffff) + 1;
6802 mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
6803 mode->vdisplay = (vtot & 0xffff) + 1;
6804 mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
6805 mode->vsync_start = (vsync & 0xffff) + 1;
6806 mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
6808 drm_mode_set_name(mode);
6813 static void intel_increase_pllclock(struct drm_crtc *crtc)
6815 struct drm_device *dev = crtc->dev;
6816 drm_i915_private_t *dev_priv = dev->dev_private;
6817 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6818 int pipe = intel_crtc->pipe;
6819 int dpll_reg = DPLL(pipe);
6822 if (HAS_PCH_SPLIT(dev))
6825 if (!dev_priv->lvds_downclock_avail)
6828 dpll = I915_READ(dpll_reg);
6829 if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
6830 DRM_DEBUG_DRIVER("upclocking LVDS\n");
6832 assert_panel_unlocked(dev_priv, pipe);
6834 dpll &= ~DISPLAY_RATE_SELECT_FPA1;
6835 I915_WRITE(dpll_reg, dpll);
6836 intel_wait_for_vblank(dev, pipe);
6838 dpll = I915_READ(dpll_reg);
6839 if (dpll & DISPLAY_RATE_SELECT_FPA1)
6840 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
6844 static void intel_decrease_pllclock(struct drm_crtc *crtc)
6846 struct drm_device *dev = crtc->dev;
6847 drm_i915_private_t *dev_priv = dev->dev_private;
6848 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6850 if (HAS_PCH_SPLIT(dev))
6853 if (!dev_priv->lvds_downclock_avail)
6857 * Since this is called by a timer, we should never get here in
6860 if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
6861 int pipe = intel_crtc->pipe;
6862 int dpll_reg = DPLL(pipe);
6865 DRM_DEBUG_DRIVER("downclocking LVDS\n");
6867 assert_panel_unlocked(dev_priv, pipe);
6869 dpll = I915_READ(dpll_reg);
6870 dpll |= DISPLAY_RATE_SELECT_FPA1;
6871 I915_WRITE(dpll_reg, dpll);
6872 intel_wait_for_vblank(dev, pipe);
6873 dpll = I915_READ(dpll_reg);
6874 if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
6875 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
6880 void intel_mark_busy(struct drm_device *dev)
6882 i915_update_gfx_val(dev->dev_private);
6885 void intel_mark_idle(struct drm_device *dev)
6887 struct drm_crtc *crtc;
6889 if (!i915_powersave)
6892 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
6896 intel_decrease_pllclock(crtc);
6900 void intel_mark_fb_busy(struct drm_i915_gem_object *obj)
6902 struct drm_device *dev = obj->base.dev;
6903 struct drm_crtc *crtc;
6905 if (!i915_powersave)
6908 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
6912 if (to_intel_framebuffer(crtc->fb)->obj == obj)
6913 intel_increase_pllclock(crtc);
6917 static void intel_crtc_destroy(struct drm_crtc *crtc)
6919 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6920 struct drm_device *dev = crtc->dev;
6921 struct intel_unpin_work *work;
6922 unsigned long flags;
6924 spin_lock_irqsave(&dev->event_lock, flags);
6925 work = intel_crtc->unpin_work;
6926 intel_crtc->unpin_work = NULL;
6927 spin_unlock_irqrestore(&dev->event_lock, flags);
6930 cancel_work_sync(&work->work);
6934 drm_crtc_cleanup(crtc);
6939 static void intel_unpin_work_fn(struct work_struct *__work)
6941 struct intel_unpin_work *work =
6942 container_of(__work, struct intel_unpin_work, work);
6943 struct drm_device *dev = work->crtc->dev;
6945 mutex_lock(&dev->struct_mutex);
6946 intel_unpin_fb_obj(work->old_fb_obj);
6947 drm_gem_object_unreference(&work->pending_flip_obj->base);
6948 drm_gem_object_unreference(&work->old_fb_obj->base);
6950 intel_update_fbc(dev);
6951 mutex_unlock(&dev->struct_mutex);
6953 BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
6954 atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
6959 static void do_intel_finish_page_flip(struct drm_device *dev,
6960 struct drm_crtc *crtc)
6962 drm_i915_private_t *dev_priv = dev->dev_private;
6963 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6964 struct intel_unpin_work *work;
6965 struct drm_i915_gem_object *obj;
6966 unsigned long flags;
6968 /* Ignore early vblank irqs */
6969 if (intel_crtc == NULL)
6972 spin_lock_irqsave(&dev->event_lock, flags);
6973 work = intel_crtc->unpin_work;
6975 /* Ensure we don't miss a work->pending update ... */
6978 if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
6979 spin_unlock_irqrestore(&dev->event_lock, flags);
6983 /* and that the unpin work is consistent wrt ->pending. */
6986 intel_crtc->unpin_work = NULL;
6989 drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
6991 drm_vblank_put(dev, intel_crtc->pipe);
6993 spin_unlock_irqrestore(&dev->event_lock, flags);
6995 obj = work->old_fb_obj;
6997 wake_up_all(&dev_priv->pending_flip_queue);
6999 queue_work(dev_priv->wq, &work->work);
7001 trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
7004 void intel_finish_page_flip(struct drm_device *dev, int pipe)
7006 drm_i915_private_t *dev_priv = dev->dev_private;
7007 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
7009 do_intel_finish_page_flip(dev, crtc);
7012 void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
7014 drm_i915_private_t *dev_priv = dev->dev_private;
7015 struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
7017 do_intel_finish_page_flip(dev, crtc);
7020 void intel_prepare_page_flip(struct drm_device *dev, int plane)
7022 drm_i915_private_t *dev_priv = dev->dev_private;
7023 struct intel_crtc *intel_crtc =
7024 to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
7025 unsigned long flags;
7027 /* NB: An MMIO update of the plane base pointer will also
7028 * generate a page-flip completion irq, i.e. every modeset
7029 * is also accompanied by a spurious intel_prepare_page_flip().
7031 spin_lock_irqsave(&dev->event_lock, flags);
7032 if (intel_crtc->unpin_work)
7033 atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
7034 spin_unlock_irqrestore(&dev->event_lock, flags);
7037 inline static void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
7039 /* Ensure that the work item is consistent when activating it ... */
7041 atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
7042 /* and that it is marked active as soon as the irq could fire. */
7046 static int intel_gen2_queue_flip(struct drm_device *dev,
7047 struct drm_crtc *crtc,
7048 struct drm_framebuffer *fb,
7049 struct drm_i915_gem_object *obj)
7051 struct drm_i915_private *dev_priv = dev->dev_private;
7052 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7054 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7057 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7061 ret = intel_ring_begin(ring, 6);
7065 /* Can't queue multiple flips, so wait for the previous
7066 * one to finish before executing the next.
7068 if (intel_crtc->plane)
7069 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
7071 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
7072 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
7073 intel_ring_emit(ring, MI_NOOP);
7074 intel_ring_emit(ring, MI_DISPLAY_FLIP |
7075 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7076 intel_ring_emit(ring, fb->pitches[0]);
7077 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7078 intel_ring_emit(ring, 0); /* aux display base address, unused */
7080 intel_mark_page_flip_active(intel_crtc);
7081 intel_ring_advance(ring);
7085 intel_unpin_fb_obj(obj);
7090 static int intel_gen3_queue_flip(struct drm_device *dev,
7091 struct drm_crtc *crtc,
7092 struct drm_framebuffer *fb,
7093 struct drm_i915_gem_object *obj)
7095 struct drm_i915_private *dev_priv = dev->dev_private;
7096 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7098 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7101 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7105 ret = intel_ring_begin(ring, 6);
7109 if (intel_crtc->plane)
7110 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
7112 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
7113 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
7114 intel_ring_emit(ring, MI_NOOP);
7115 intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
7116 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7117 intel_ring_emit(ring, fb->pitches[0]);
7118 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7119 intel_ring_emit(ring, MI_NOOP);
7121 intel_mark_page_flip_active(intel_crtc);
7122 intel_ring_advance(ring);
7126 intel_unpin_fb_obj(obj);
7131 static int intel_gen4_queue_flip(struct drm_device *dev,
7132 struct drm_crtc *crtc,
7133 struct drm_framebuffer *fb,
7134 struct drm_i915_gem_object *obj)
7136 struct drm_i915_private *dev_priv = dev->dev_private;
7137 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7138 uint32_t pf, pipesrc;
7139 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7142 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7146 ret = intel_ring_begin(ring, 4);
7150 /* i965+ uses the linear or tiled offsets from the
7151 * Display Registers (which do not change across a page-flip)
7152 * so we need only reprogram the base address.
7154 intel_ring_emit(ring, MI_DISPLAY_FLIP |
7155 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7156 intel_ring_emit(ring, fb->pitches[0]);
7157 intel_ring_emit(ring,
7158 (obj->gtt_offset + intel_crtc->dspaddr_offset) |
7161 /* XXX Enabling the panel-fitter across page-flip is so far
7162 * untested on non-native modes, so ignore it for now.
7163 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
7166 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
7167 intel_ring_emit(ring, pf | pipesrc);
7169 intel_mark_page_flip_active(intel_crtc);
7170 intel_ring_advance(ring);
7174 intel_unpin_fb_obj(obj);
7179 static int intel_gen6_queue_flip(struct drm_device *dev,
7180 struct drm_crtc *crtc,
7181 struct drm_framebuffer *fb,
7182 struct drm_i915_gem_object *obj)
7184 struct drm_i915_private *dev_priv = dev->dev_private;
7185 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7186 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7187 uint32_t pf, pipesrc;
7190 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7194 ret = intel_ring_begin(ring, 4);
7198 intel_ring_emit(ring, MI_DISPLAY_FLIP |
7199 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7200 intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
7201 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7203 /* Contrary to the suggestions in the documentation,
7204 * "Enable Panel Fitter" does not seem to be required when page
7205 * flipping with a non-native mode, and worse causes a normal
7207 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
7210 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
7211 intel_ring_emit(ring, pf | pipesrc);
7213 intel_mark_page_flip_active(intel_crtc);
7214 intel_ring_advance(ring);
7218 intel_unpin_fb_obj(obj);
7224 * On gen7 we currently use the blit ring because (in early silicon at least)
7225 * the render ring doesn't give us interrpts for page flip completion, which
7226 * means clients will hang after the first flip is queued. Fortunately the
7227 * blit ring generates interrupts properly, so use it instead.
7229 static int intel_gen7_queue_flip(struct drm_device *dev,
7230 struct drm_crtc *crtc,
7231 struct drm_framebuffer *fb,
7232 struct drm_i915_gem_object *obj)
7234 struct drm_i915_private *dev_priv = dev->dev_private;
7235 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7236 struct intel_ring_buffer *ring = &dev_priv->ring[BCS];
7237 uint32_t plane_bit = 0;
7240 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7244 switch(intel_crtc->plane) {
7246 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
7249 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
7252 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
7255 WARN_ONCE(1, "unknown plane in flip command\n");
7260 ret = intel_ring_begin(ring, 4);
7264 intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
7265 intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
7266 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7267 intel_ring_emit(ring, (MI_NOOP));
7269 intel_mark_page_flip_active(intel_crtc);
7270 intel_ring_advance(ring);
7274 intel_unpin_fb_obj(obj);
7279 static int intel_default_queue_flip(struct drm_device *dev,
7280 struct drm_crtc *crtc,
7281 struct drm_framebuffer *fb,
7282 struct drm_i915_gem_object *obj)
7287 static int intel_crtc_page_flip(struct drm_crtc *crtc,
7288 struct drm_framebuffer *fb,
7289 struct drm_pending_vblank_event *event)
7291 struct drm_device *dev = crtc->dev;
7292 struct drm_i915_private *dev_priv = dev->dev_private;
7293 struct drm_framebuffer *old_fb = crtc->fb;
7294 struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
7295 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7296 struct intel_unpin_work *work;
7297 unsigned long flags;
7300 /* Can't change pixel format via MI display flips. */
7301 if (fb->pixel_format != crtc->fb->pixel_format)
7305 * TILEOFF/LINOFF registers can't be changed via MI display flips.
7306 * Note that pitch changes could also affect these register.
7308 if (INTEL_INFO(dev)->gen > 3 &&
7309 (fb->offsets[0] != crtc->fb->offsets[0] ||
7310 fb->pitches[0] != crtc->fb->pitches[0]))
7313 work = kzalloc(sizeof *work, GFP_KERNEL);
7317 work->event = event;
7319 work->old_fb_obj = to_intel_framebuffer(old_fb)->obj;
7320 INIT_WORK(&work->work, intel_unpin_work_fn);
7322 ret = drm_vblank_get(dev, intel_crtc->pipe);
7326 /* We borrow the event spin lock for protecting unpin_work */
7327 spin_lock_irqsave(&dev->event_lock, flags);
7328 if (intel_crtc->unpin_work) {
7329 spin_unlock_irqrestore(&dev->event_lock, flags);
7331 drm_vblank_put(dev, intel_crtc->pipe);
7333 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
7336 intel_crtc->unpin_work = work;
7337 spin_unlock_irqrestore(&dev->event_lock, flags);
7339 if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
7340 flush_workqueue(dev_priv->wq);
7342 ret = i915_mutex_lock_interruptible(dev);
7346 /* Reference the objects for the scheduled work. */
7347 drm_gem_object_reference(&work->old_fb_obj->base);
7348 drm_gem_object_reference(&obj->base);
7352 work->pending_flip_obj = obj;
7354 work->enable_stall_check = true;
7356 atomic_inc(&intel_crtc->unpin_work_count);
7357 intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
7359 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
7361 goto cleanup_pending;
7363 intel_disable_fbc(dev);
7364 intel_mark_fb_busy(obj);
7365 mutex_unlock(&dev->struct_mutex);
7367 trace_i915_flip_request(intel_crtc->plane, obj);
7372 atomic_dec(&intel_crtc->unpin_work_count);
7374 drm_gem_object_unreference(&work->old_fb_obj->base);
7375 drm_gem_object_unreference(&obj->base);
7376 mutex_unlock(&dev->struct_mutex);
7379 spin_lock_irqsave(&dev->event_lock, flags);
7380 intel_crtc->unpin_work = NULL;
7381 spin_unlock_irqrestore(&dev->event_lock, flags);
7383 drm_vblank_put(dev, intel_crtc->pipe);
7390 static struct drm_crtc_helper_funcs intel_helper_funcs = {
7391 .mode_set_base_atomic = intel_pipe_set_base_atomic,
7392 .load_lut = intel_crtc_load_lut,
7393 .disable = intel_crtc_noop,
7396 bool intel_encoder_check_is_cloned(struct intel_encoder *encoder)
7398 struct intel_encoder *other_encoder;
7399 struct drm_crtc *crtc = &encoder->new_crtc->base;
7404 list_for_each_entry(other_encoder,
7405 &crtc->dev->mode_config.encoder_list,
7408 if (&other_encoder->new_crtc->base != crtc ||
7409 encoder == other_encoder)
7418 static bool intel_encoder_crtc_ok(struct drm_encoder *encoder,
7419 struct drm_crtc *crtc)
7421 struct drm_device *dev;
7422 struct drm_crtc *tmp;
7425 WARN(!crtc, "checking null crtc?\n");
7429 list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
7435 if (encoder->possible_crtcs & crtc_mask)
7441 * intel_modeset_update_staged_output_state
7443 * Updates the staged output configuration state, e.g. after we've read out the
7446 static void intel_modeset_update_staged_output_state(struct drm_device *dev)
7448 struct intel_encoder *encoder;
7449 struct intel_connector *connector;
7451 list_for_each_entry(connector, &dev->mode_config.connector_list,
7453 connector->new_encoder =
7454 to_intel_encoder(connector->base.encoder);
7457 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7460 to_intel_crtc(encoder->base.crtc);
7465 * intel_modeset_commit_output_state
7467 * This function copies the stage display pipe configuration to the real one.
7469 static void intel_modeset_commit_output_state(struct drm_device *dev)
7471 struct intel_encoder *encoder;
7472 struct intel_connector *connector;
7474 list_for_each_entry(connector, &dev->mode_config.connector_list,
7476 connector->base.encoder = &connector->new_encoder->base;
7479 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7481 encoder->base.crtc = &encoder->new_crtc->base;
7485 static struct drm_display_mode *
7486 intel_modeset_adjusted_mode(struct drm_crtc *crtc,
7487 struct drm_display_mode *mode)
7489 struct drm_device *dev = crtc->dev;
7490 struct drm_display_mode *adjusted_mode;
7491 struct drm_encoder_helper_funcs *encoder_funcs;
7492 struct intel_encoder *encoder;
7494 adjusted_mode = drm_mode_duplicate(dev, mode);
7496 return ERR_PTR(-ENOMEM);
7498 /* Pass our mode to the connectors and the CRTC to give them a chance to
7499 * adjust it according to limitations or connector properties, and also
7500 * a chance to reject the mode entirely.
7502 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7505 if (&encoder->new_crtc->base != crtc)
7507 encoder_funcs = encoder->base.helper_private;
7508 if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
7510 DRM_DEBUG_KMS("Encoder fixup failed\n");
7515 if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
7516 DRM_DEBUG_KMS("CRTC fixup failed\n");
7519 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
7521 return adjusted_mode;
7523 drm_mode_destroy(dev, adjusted_mode);
7524 return ERR_PTR(-EINVAL);
7527 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
7528 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
7530 intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
7531 unsigned *prepare_pipes, unsigned *disable_pipes)
7533 struct intel_crtc *intel_crtc;
7534 struct drm_device *dev = crtc->dev;
7535 struct intel_encoder *encoder;
7536 struct intel_connector *connector;
7537 struct drm_crtc *tmp_crtc;
7539 *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
7541 /* Check which crtcs have changed outputs connected to them, these need
7542 * to be part of the prepare_pipes mask. We don't (yet) support global
7543 * modeset across multiple crtcs, so modeset_pipes will only have one
7544 * bit set at most. */
7545 list_for_each_entry(connector, &dev->mode_config.connector_list,
7547 if (connector->base.encoder == &connector->new_encoder->base)
7550 if (connector->base.encoder) {
7551 tmp_crtc = connector->base.encoder->crtc;
7553 *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
7556 if (connector->new_encoder)
7558 1 << connector->new_encoder->new_crtc->pipe;
7561 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7563 if (encoder->base.crtc == &encoder->new_crtc->base)
7566 if (encoder->base.crtc) {
7567 tmp_crtc = encoder->base.crtc;
7569 *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
7572 if (encoder->new_crtc)
7573 *prepare_pipes |= 1 << encoder->new_crtc->pipe;
7576 /* Check for any pipes that will be fully disabled ... */
7577 list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
7581 /* Don't try to disable disabled crtcs. */
7582 if (!intel_crtc->base.enabled)
7585 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7587 if (encoder->new_crtc == intel_crtc)
7592 *disable_pipes |= 1 << intel_crtc->pipe;
7596 /* set_mode is also used to update properties on life display pipes. */
7597 intel_crtc = to_intel_crtc(crtc);
7599 *prepare_pipes |= 1 << intel_crtc->pipe;
7601 /* We only support modeset on one single crtc, hence we need to do that
7602 * only for the passed in crtc iff we change anything else than just
7605 * This is actually not true, to be fully compatible with the old crtc
7606 * helper we automatically disable _any_ output (i.e. doesn't need to be
7607 * connected to the crtc we're modesetting on) if it's disconnected.
7608 * Which is a rather nutty api (since changed the output configuration
7609 * without userspace's explicit request can lead to confusion), but
7610 * alas. Hence we currently need to modeset on all pipes we prepare. */
7612 *modeset_pipes = *prepare_pipes;
7614 /* ... and mask these out. */
7615 *modeset_pipes &= ~(*disable_pipes);
7616 *prepare_pipes &= ~(*disable_pipes);
7619 static bool intel_crtc_in_use(struct drm_crtc *crtc)
7621 struct drm_encoder *encoder;
7622 struct drm_device *dev = crtc->dev;
7624 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
7625 if (encoder->crtc == crtc)
7632 intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
7634 struct intel_encoder *intel_encoder;
7635 struct intel_crtc *intel_crtc;
7636 struct drm_connector *connector;
7638 list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
7640 if (!intel_encoder->base.crtc)
7643 intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
7645 if (prepare_pipes & (1 << intel_crtc->pipe))
7646 intel_encoder->connectors_active = false;
7649 intel_modeset_commit_output_state(dev);
7651 /* Update computed state. */
7652 list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
7654 intel_crtc->base.enabled = intel_crtc_in_use(&intel_crtc->base);
7657 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
7658 if (!connector->encoder || !connector->encoder->crtc)
7661 intel_crtc = to_intel_crtc(connector->encoder->crtc);
7663 if (prepare_pipes & (1 << intel_crtc->pipe)) {
7664 struct drm_property *dpms_property =
7665 dev->mode_config.dpms_property;
7667 connector->dpms = DRM_MODE_DPMS_ON;
7668 drm_object_property_set_value(&connector->base,
7672 intel_encoder = to_intel_encoder(connector->encoder);
7673 intel_encoder->connectors_active = true;
7679 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
7680 list_for_each_entry((intel_crtc), \
7681 &(dev)->mode_config.crtc_list, \
7683 if (mask & (1 <<(intel_crtc)->pipe)) \
7686 intel_modeset_check_state(struct drm_device *dev)
7688 struct intel_crtc *crtc;
7689 struct intel_encoder *encoder;
7690 struct intel_connector *connector;
7692 list_for_each_entry(connector, &dev->mode_config.connector_list,
7694 /* This also checks the encoder/connector hw state with the
7695 * ->get_hw_state callbacks. */
7696 intel_connector_check_state(connector);
7698 WARN(&connector->new_encoder->base != connector->base.encoder,
7699 "connector's staged encoder doesn't match current encoder\n");
7702 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7704 bool enabled = false;
7705 bool active = false;
7706 enum pipe pipe, tracked_pipe;
7708 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
7709 encoder->base.base.id,
7710 drm_get_encoder_name(&encoder->base));
7712 WARN(&encoder->new_crtc->base != encoder->base.crtc,
7713 "encoder's stage crtc doesn't match current crtc\n");
7714 WARN(encoder->connectors_active && !encoder->base.crtc,
7715 "encoder's active_connectors set, but no crtc\n");
7717 list_for_each_entry(connector, &dev->mode_config.connector_list,
7719 if (connector->base.encoder != &encoder->base)
7722 if (connector->base.dpms != DRM_MODE_DPMS_OFF)
7725 WARN(!!encoder->base.crtc != enabled,
7726 "encoder's enabled state mismatch "
7727 "(expected %i, found %i)\n",
7728 !!encoder->base.crtc, enabled);
7729 WARN(active && !encoder->base.crtc,
7730 "active encoder with no crtc\n");
7732 WARN(encoder->connectors_active != active,
7733 "encoder's computed active state doesn't match tracked active state "
7734 "(expected %i, found %i)\n", active, encoder->connectors_active);
7736 active = encoder->get_hw_state(encoder, &pipe);
7737 WARN(active != encoder->connectors_active,
7738 "encoder's hw state doesn't match sw tracking "
7739 "(expected %i, found %i)\n",
7740 encoder->connectors_active, active);
7742 if (!encoder->base.crtc)
7745 tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
7746 WARN(active && pipe != tracked_pipe,
7747 "active encoder's pipe doesn't match"
7748 "(expected %i, found %i)\n",
7749 tracked_pipe, pipe);
7753 list_for_each_entry(crtc, &dev->mode_config.crtc_list,
7755 bool enabled = false;
7756 bool active = false;
7758 DRM_DEBUG_KMS("[CRTC:%d]\n",
7759 crtc->base.base.id);
7761 WARN(crtc->active && !crtc->base.enabled,
7762 "active crtc, but not enabled in sw tracking\n");
7764 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7766 if (encoder->base.crtc != &crtc->base)
7769 if (encoder->connectors_active)
7772 WARN(active != crtc->active,
7773 "crtc's computed active state doesn't match tracked active state "
7774 "(expected %i, found %i)\n", active, crtc->active);
7775 WARN(enabled != crtc->base.enabled,
7776 "crtc's computed enabled state doesn't match tracked enabled state "
7777 "(expected %i, found %i)\n", enabled, crtc->base.enabled);
7779 assert_pipe(dev->dev_private, crtc->pipe, crtc->active);
7783 int intel_set_mode(struct drm_crtc *crtc,
7784 struct drm_display_mode *mode,
7785 int x, int y, struct drm_framebuffer *fb)
7787 struct drm_device *dev = crtc->dev;
7788 drm_i915_private_t *dev_priv = dev->dev_private;
7789 struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode;
7790 struct intel_crtc *intel_crtc;
7791 unsigned disable_pipes, prepare_pipes, modeset_pipes;
7794 saved_mode = kmalloc(2 * sizeof(*saved_mode), GFP_KERNEL);
7797 saved_hwmode = saved_mode + 1;
7799 intel_modeset_affected_pipes(crtc, &modeset_pipes,
7800 &prepare_pipes, &disable_pipes);
7802 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
7803 modeset_pipes, prepare_pipes, disable_pipes);
7805 for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
7806 intel_crtc_disable(&intel_crtc->base);
7808 *saved_hwmode = crtc->hwmode;
7809 *saved_mode = crtc->mode;
7811 /* Hack: Because we don't (yet) support global modeset on multiple
7812 * crtcs, we don't keep track of the new mode for more than one crtc.
7813 * Hence simply check whether any bit is set in modeset_pipes in all the
7814 * pieces of code that are not yet converted to deal with mutliple crtcs
7815 * changing their mode at the same time. */
7816 adjusted_mode = NULL;
7817 if (modeset_pipes) {
7818 adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
7819 if (IS_ERR(adjusted_mode)) {
7820 ret = PTR_ERR(adjusted_mode);
7825 for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
7826 if (intel_crtc->base.enabled)
7827 dev_priv->display.crtc_disable(&intel_crtc->base);
7830 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
7831 * to set it here already despite that we pass it down the callchain.
7836 /* Only after disabling all output pipelines that will be changed can we
7837 * update the the output configuration. */
7838 intel_modeset_update_state(dev, prepare_pipes);
7840 if (dev_priv->display.modeset_global_resources)
7841 dev_priv->display.modeset_global_resources(dev);
7843 /* Set up the DPLL and any encoders state that needs to adjust or depend
7846 for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
7847 ret = intel_crtc_mode_set(&intel_crtc->base,
7848 mode, adjusted_mode,
7854 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7855 for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
7856 dev_priv->display.crtc_enable(&intel_crtc->base);
7858 if (modeset_pipes) {
7859 /* Store real post-adjustment hardware mode. */
7860 crtc->hwmode = *adjusted_mode;
7862 /* Calculate and store various constants which
7863 * are later needed by vblank and swap-completion
7864 * timestamping. They are derived from true hwmode.
7866 drm_calc_timestamping_constants(crtc);
7869 /* FIXME: add subpixel order */
7871 drm_mode_destroy(dev, adjusted_mode);
7872 if (ret && crtc->enabled) {
7873 crtc->hwmode = *saved_hwmode;
7874 crtc->mode = *saved_mode;
7876 intel_modeset_check_state(dev);
7884 void intel_crtc_restore_mode(struct drm_crtc *crtc)
7886 intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb);
7889 #undef for_each_intel_crtc_masked
7891 static void intel_set_config_free(struct intel_set_config *config)
7896 kfree(config->save_connector_encoders);
7897 kfree(config->save_encoder_crtcs);
7901 static int intel_set_config_save_state(struct drm_device *dev,
7902 struct intel_set_config *config)
7904 struct drm_encoder *encoder;
7905 struct drm_connector *connector;
7908 config->save_encoder_crtcs =
7909 kcalloc(dev->mode_config.num_encoder,
7910 sizeof(struct drm_crtc *), GFP_KERNEL);
7911 if (!config->save_encoder_crtcs)
7914 config->save_connector_encoders =
7915 kcalloc(dev->mode_config.num_connector,
7916 sizeof(struct drm_encoder *), GFP_KERNEL);
7917 if (!config->save_connector_encoders)
7920 /* Copy data. Note that driver private data is not affected.
7921 * Should anything bad happen only the expected state is
7922 * restored, not the drivers personal bookkeeping.
7925 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
7926 config->save_encoder_crtcs[count++] = encoder->crtc;
7930 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
7931 config->save_connector_encoders[count++] = connector->encoder;
7937 static void intel_set_config_restore_state(struct drm_device *dev,
7938 struct intel_set_config *config)
7940 struct intel_encoder *encoder;
7941 struct intel_connector *connector;
7945 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
7947 to_intel_crtc(config->save_encoder_crtcs[count++]);
7951 list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
7952 connector->new_encoder =
7953 to_intel_encoder(config->save_connector_encoders[count++]);
7958 intel_set_config_compute_mode_changes(struct drm_mode_set *set,
7959 struct intel_set_config *config)
7962 /* We should be able to check here if the fb has the same properties
7963 * and then just flip_or_move it */
7964 if (set->crtc->fb != set->fb) {
7965 /* If we have no fb then treat it as a full mode set */
7966 if (set->crtc->fb == NULL) {
7967 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
7968 config->mode_changed = true;
7969 } else if (set->fb == NULL) {
7970 config->mode_changed = true;
7971 } else if (set->fb->depth != set->crtc->fb->depth) {
7972 config->mode_changed = true;
7973 } else if (set->fb->bits_per_pixel !=
7974 set->crtc->fb->bits_per_pixel) {
7975 config->mode_changed = true;
7977 config->fb_changed = true;
7980 if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
7981 config->fb_changed = true;
7983 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
7984 DRM_DEBUG_KMS("modes are different, full mode set\n");
7985 drm_mode_debug_printmodeline(&set->crtc->mode);
7986 drm_mode_debug_printmodeline(set->mode);
7987 config->mode_changed = true;
7992 intel_modeset_stage_output_state(struct drm_device *dev,
7993 struct drm_mode_set *set,
7994 struct intel_set_config *config)
7996 struct drm_crtc *new_crtc;
7997 struct intel_connector *connector;
7998 struct intel_encoder *encoder;
8001 /* The upper layers ensure that we either disable a crtc or have a list
8002 * of connectors. For paranoia, double-check this. */
8003 WARN_ON(!set->fb && (set->num_connectors != 0));
8004 WARN_ON(set->fb && (set->num_connectors == 0));
8007 list_for_each_entry(connector, &dev->mode_config.connector_list,
8009 /* Otherwise traverse passed in connector list and get encoders
8011 for (ro = 0; ro < set->num_connectors; ro++) {
8012 if (set->connectors[ro] == &connector->base) {
8013 connector->new_encoder = connector->encoder;
8018 /* If we disable the crtc, disable all its connectors. Also, if
8019 * the connector is on the changing crtc but not on the new
8020 * connector list, disable it. */
8021 if ((!set->fb || ro == set->num_connectors) &&
8022 connector->base.encoder &&
8023 connector->base.encoder->crtc == set->crtc) {
8024 connector->new_encoder = NULL;
8026 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
8027 connector->base.base.id,
8028 drm_get_connector_name(&connector->base));
8032 if (&connector->new_encoder->base != connector->base.encoder) {
8033 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
8034 config->mode_changed = true;
8037 /* connector->new_encoder is now updated for all connectors. */
8039 /* Update crtc of enabled connectors. */
8041 list_for_each_entry(connector, &dev->mode_config.connector_list,
8043 if (!connector->new_encoder)
8046 new_crtc = connector->new_encoder->base.crtc;
8048 for (ro = 0; ro < set->num_connectors; ro++) {
8049 if (set->connectors[ro] == &connector->base)
8050 new_crtc = set->crtc;
8053 /* Make sure the new CRTC will work with the encoder */
8054 if (!intel_encoder_crtc_ok(&connector->new_encoder->base,
8058 connector->encoder->new_crtc = to_intel_crtc(new_crtc);
8060 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
8061 connector->base.base.id,
8062 drm_get_connector_name(&connector->base),
8066 /* Check for any encoders that needs to be disabled. */
8067 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
8069 list_for_each_entry(connector,
8070 &dev->mode_config.connector_list,
8072 if (connector->new_encoder == encoder) {
8073 WARN_ON(!connector->new_encoder->new_crtc);
8078 encoder->new_crtc = NULL;
8080 /* Only now check for crtc changes so we don't miss encoders
8081 * that will be disabled. */
8082 if (&encoder->new_crtc->base != encoder->base.crtc) {
8083 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
8084 config->mode_changed = true;
8087 /* Now we've also updated encoder->new_crtc for all encoders. */
8092 static int intel_crtc_set_config(struct drm_mode_set *set)
8094 struct drm_device *dev;
8095 struct drm_mode_set save_set;
8096 struct intel_set_config *config;
8101 BUG_ON(!set->crtc->helper_private);
8106 /* The fb helper likes to play gross jokes with ->mode_set_config.
8107 * Unfortunately the crtc helper doesn't do much at all for this case,
8108 * so we have to cope with this madness until the fb helper is fixed up. */
8109 if (set->fb && set->num_connectors == 0)
8113 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
8114 set->crtc->base.id, set->fb->base.id,
8115 (int)set->num_connectors, set->x, set->y);
8117 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
8120 dev = set->crtc->dev;
8123 config = kzalloc(sizeof(*config), GFP_KERNEL);
8127 ret = intel_set_config_save_state(dev, config);
8131 save_set.crtc = set->crtc;
8132 save_set.mode = &set->crtc->mode;
8133 save_set.x = set->crtc->x;
8134 save_set.y = set->crtc->y;
8135 save_set.fb = set->crtc->fb;
8137 /* Compute whether we need a full modeset, only an fb base update or no
8138 * change at all. In the future we might also check whether only the
8139 * mode changed, e.g. for LVDS where we only change the panel fitter in
8141 intel_set_config_compute_mode_changes(set, config);
8143 ret = intel_modeset_stage_output_state(dev, set, config);
8147 if (config->mode_changed) {
8149 DRM_DEBUG_KMS("attempting to set mode from"
8151 drm_mode_debug_printmodeline(set->mode);
8154 ret = intel_set_mode(set->crtc, set->mode,
8155 set->x, set->y, set->fb);
8157 DRM_ERROR("failed to set mode on [CRTC:%d], err = %d\n",
8158 set->crtc->base.id, ret);
8161 } else if (config->fb_changed) {
8162 ret = intel_pipe_set_base(set->crtc,
8163 set->x, set->y, set->fb);
8166 intel_set_config_free(config);
8171 intel_set_config_restore_state(dev, config);
8173 /* Try to restore the config */
8174 if (config->mode_changed &&
8175 intel_set_mode(save_set.crtc, save_set.mode,
8176 save_set.x, save_set.y, save_set.fb))
8177 DRM_ERROR("failed to restore config after modeset failure\n");
8180 intel_set_config_free(config);
8184 static const struct drm_crtc_funcs intel_crtc_funcs = {
8185 .cursor_set = intel_crtc_cursor_set,
8186 .cursor_move = intel_crtc_cursor_move,
8187 .gamma_set = intel_crtc_gamma_set,
8188 .set_config = intel_crtc_set_config,
8189 .destroy = intel_crtc_destroy,
8190 .page_flip = intel_crtc_page_flip,
8193 static void intel_cpu_pll_init(struct drm_device *dev)
8196 intel_ddi_pll_init(dev);
8199 static void intel_pch_pll_init(struct drm_device *dev)
8201 drm_i915_private_t *dev_priv = dev->dev_private;
8204 if (dev_priv->num_pch_pll == 0) {
8205 DRM_DEBUG_KMS("No PCH PLLs on this hardware, skipping initialisation\n");
8209 for (i = 0; i < dev_priv->num_pch_pll; i++) {
8210 dev_priv->pch_plls[i].pll_reg = _PCH_DPLL(i);
8211 dev_priv->pch_plls[i].fp0_reg = _PCH_FP0(i);
8212 dev_priv->pch_plls[i].fp1_reg = _PCH_FP1(i);
8216 static void intel_crtc_init(struct drm_device *dev, int pipe)
8218 drm_i915_private_t *dev_priv = dev->dev_private;
8219 struct intel_crtc *intel_crtc;
8222 intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
8223 if (intel_crtc == NULL)
8226 drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
8228 drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
8229 for (i = 0; i < 256; i++) {
8230 intel_crtc->lut_r[i] = i;
8231 intel_crtc->lut_g[i] = i;
8232 intel_crtc->lut_b[i] = i;
8235 /* Swap pipes & planes for FBC on pre-965 */
8236 intel_crtc->pipe = pipe;
8237 intel_crtc->plane = pipe;
8238 intel_crtc->cpu_transcoder = pipe;
8239 if (IS_MOBILE(dev) && IS_GEN3(dev)) {
8240 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
8241 intel_crtc->plane = !pipe;
8244 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
8245 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
8246 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
8247 dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
8249 intel_crtc->bpp = 24; /* default for pre-Ironlake */
8251 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
8254 int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
8255 struct drm_file *file)
8257 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
8258 struct drm_mode_object *drmmode_obj;
8259 struct intel_crtc *crtc;
8261 if (!drm_core_check_feature(dev, DRIVER_MODESET))
8264 drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
8265 DRM_MODE_OBJECT_CRTC);
8268 DRM_ERROR("no such CRTC id\n");
8272 crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
8273 pipe_from_crtc_id->pipe = crtc->pipe;
8278 static int intel_encoder_clones(struct intel_encoder *encoder)
8280 struct drm_device *dev = encoder->base.dev;
8281 struct intel_encoder *source_encoder;
8285 list_for_each_entry(source_encoder,
8286 &dev->mode_config.encoder_list, base.head) {
8288 if (encoder == source_encoder)
8289 index_mask |= (1 << entry);
8291 /* Intel hw has only one MUX where enocoders could be cloned. */
8292 if (encoder->cloneable && source_encoder->cloneable)
8293 index_mask |= (1 << entry);
8301 static bool has_edp_a(struct drm_device *dev)
8303 struct drm_i915_private *dev_priv = dev->dev_private;
8305 if (!IS_MOBILE(dev))
8308 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
8312 (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
8318 static void intel_setup_outputs(struct drm_device *dev)
8320 struct drm_i915_private *dev_priv = dev->dev_private;
8321 struct intel_encoder *encoder;
8322 bool dpd_is_edp = false;
8325 has_lvds = intel_lvds_init(dev);
8326 if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
8327 /* disable the panel fitter on everything but LVDS */
8328 I915_WRITE(PFIT_CONTROL, 0);
8331 if (!(HAS_DDI(dev) && (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)))
8332 intel_crt_init(dev);
8337 /* Haswell uses DDI functions to detect digital outputs */
8338 found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
8339 /* DDI A only supports eDP */
8341 intel_ddi_init(dev, PORT_A);
8343 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
8345 found = I915_READ(SFUSE_STRAP);
8347 if (found & SFUSE_STRAP_DDIB_DETECTED)
8348 intel_ddi_init(dev, PORT_B);
8349 if (found & SFUSE_STRAP_DDIC_DETECTED)
8350 intel_ddi_init(dev, PORT_C);
8351 if (found & SFUSE_STRAP_DDID_DETECTED)
8352 intel_ddi_init(dev, PORT_D);
8353 } else if (HAS_PCH_SPLIT(dev)) {
8355 dpd_is_edp = intel_dpd_is_edp(dev);
8358 intel_dp_init(dev, DP_A, PORT_A);
8360 if (I915_READ(HDMIB) & PORT_DETECTED) {
8361 /* PCH SDVOB multiplex with HDMIB */
8362 found = intel_sdvo_init(dev, PCH_SDVOB, true);
8364 intel_hdmi_init(dev, HDMIB, PORT_B);
8365 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
8366 intel_dp_init(dev, PCH_DP_B, PORT_B);
8369 if (I915_READ(HDMIC) & PORT_DETECTED)
8370 intel_hdmi_init(dev, HDMIC, PORT_C);
8372 if (!dpd_is_edp && I915_READ(HDMID) & PORT_DETECTED)
8373 intel_hdmi_init(dev, HDMID, PORT_D);
8375 if (I915_READ(PCH_DP_C) & DP_DETECTED)
8376 intel_dp_init(dev, PCH_DP_C, PORT_C);
8378 if (I915_READ(PCH_DP_D) & DP_DETECTED)
8379 intel_dp_init(dev, PCH_DP_D, PORT_D);
8380 } else if (IS_VALLEYVIEW(dev)) {
8381 /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
8382 if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
8383 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
8385 if (I915_READ(VLV_DISPLAY_BASE + SDVOB) & PORT_DETECTED) {
8386 intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOB, PORT_B);
8387 if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
8388 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
8391 if (I915_READ(VLV_DISPLAY_BASE + SDVOC) & PORT_DETECTED)
8392 intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOC, PORT_C);
8394 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
8397 if (I915_READ(SDVOB) & SDVO_DETECTED) {
8398 DRM_DEBUG_KMS("probing SDVOB\n");
8399 found = intel_sdvo_init(dev, SDVOB, true);
8400 if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
8401 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
8402 intel_hdmi_init(dev, SDVOB, PORT_B);
8405 if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
8406 DRM_DEBUG_KMS("probing DP_B\n");
8407 intel_dp_init(dev, DP_B, PORT_B);
8411 /* Before G4X SDVOC doesn't have its own detect register */
8413 if (I915_READ(SDVOB) & SDVO_DETECTED) {
8414 DRM_DEBUG_KMS("probing SDVOC\n");
8415 found = intel_sdvo_init(dev, SDVOC, false);
8418 if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
8420 if (SUPPORTS_INTEGRATED_HDMI(dev)) {
8421 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
8422 intel_hdmi_init(dev, SDVOC, PORT_C);
8424 if (SUPPORTS_INTEGRATED_DP(dev)) {
8425 DRM_DEBUG_KMS("probing DP_C\n");
8426 intel_dp_init(dev, DP_C, PORT_C);
8430 if (SUPPORTS_INTEGRATED_DP(dev) &&
8431 (I915_READ(DP_D) & DP_DETECTED)) {
8432 DRM_DEBUG_KMS("probing DP_D\n");
8433 intel_dp_init(dev, DP_D, PORT_D);
8435 } else if (IS_GEN2(dev))
8436 intel_dvo_init(dev);
8438 if (SUPPORTS_TV(dev))
8441 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
8442 encoder->base.possible_crtcs = encoder->crtc_mask;
8443 encoder->base.possible_clones =
8444 intel_encoder_clones(encoder);
8447 intel_init_pch_refclk(dev);
8449 drm_helper_move_panel_connectors_to_head(dev);
8452 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
8454 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
8456 drm_framebuffer_cleanup(fb);
8457 drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
8462 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
8463 struct drm_file *file,
8464 unsigned int *handle)
8466 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
8467 struct drm_i915_gem_object *obj = intel_fb->obj;
8469 return drm_gem_handle_create(file, &obj->base, handle);
8472 static const struct drm_framebuffer_funcs intel_fb_funcs = {
8473 .destroy = intel_user_framebuffer_destroy,
8474 .create_handle = intel_user_framebuffer_create_handle,
8477 int intel_framebuffer_init(struct drm_device *dev,
8478 struct intel_framebuffer *intel_fb,
8479 struct drm_mode_fb_cmd2 *mode_cmd,
8480 struct drm_i915_gem_object *obj)
8484 if (obj->tiling_mode == I915_TILING_Y) {
8485 DRM_DEBUG("hardware does not support tiling Y\n");
8489 if (mode_cmd->pitches[0] & 63) {
8490 DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
8491 mode_cmd->pitches[0]);
8495 /* FIXME <= Gen4 stride limits are bit unclear */
8496 if (mode_cmd->pitches[0] > 32768) {
8497 DRM_DEBUG("pitch (%d) must be at less than 32768\n",
8498 mode_cmd->pitches[0]);
8502 if (obj->tiling_mode != I915_TILING_NONE &&
8503 mode_cmd->pitches[0] != obj->stride) {
8504 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
8505 mode_cmd->pitches[0], obj->stride);
8509 /* Reject formats not supported by any plane early. */
8510 switch (mode_cmd->pixel_format) {
8512 case DRM_FORMAT_RGB565:
8513 case DRM_FORMAT_XRGB8888:
8514 case DRM_FORMAT_ARGB8888:
8516 case DRM_FORMAT_XRGB1555:
8517 case DRM_FORMAT_ARGB1555:
8518 if (INTEL_INFO(dev)->gen > 3) {
8519 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
8523 case DRM_FORMAT_XBGR8888:
8524 case DRM_FORMAT_ABGR8888:
8525 case DRM_FORMAT_XRGB2101010:
8526 case DRM_FORMAT_ARGB2101010:
8527 case DRM_FORMAT_XBGR2101010:
8528 case DRM_FORMAT_ABGR2101010:
8529 if (INTEL_INFO(dev)->gen < 4) {
8530 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
8534 case DRM_FORMAT_YUYV:
8535 case DRM_FORMAT_UYVY:
8536 case DRM_FORMAT_YVYU:
8537 case DRM_FORMAT_VYUY:
8538 if (INTEL_INFO(dev)->gen < 5) {
8539 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
8544 DRM_DEBUG("unsupported pixel format 0x%08x\n", mode_cmd->pixel_format);
8548 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
8549 if (mode_cmd->offsets[0] != 0)
8552 drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
8553 intel_fb->obj = obj;
8555 ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
8557 DRM_ERROR("framebuffer init failed %d\n", ret);
8564 static struct drm_framebuffer *
8565 intel_user_framebuffer_create(struct drm_device *dev,
8566 struct drm_file *filp,
8567 struct drm_mode_fb_cmd2 *mode_cmd)
8569 struct drm_i915_gem_object *obj;
8571 obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
8572 mode_cmd->handles[0]));
8573 if (&obj->base == NULL)
8574 return ERR_PTR(-ENOENT);
8576 return intel_framebuffer_create(dev, mode_cmd, obj);
8579 static const struct drm_mode_config_funcs intel_mode_funcs = {
8580 .fb_create = intel_user_framebuffer_create,
8581 .output_poll_changed = intel_fb_output_poll_changed,
8584 /* Set up chip specific display functions */
8585 static void intel_init_display(struct drm_device *dev)
8587 struct drm_i915_private *dev_priv = dev->dev_private;
8589 /* We always want a DPMS function */
8591 dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
8592 dev_priv->display.crtc_enable = haswell_crtc_enable;
8593 dev_priv->display.crtc_disable = haswell_crtc_disable;
8594 dev_priv->display.off = haswell_crtc_off;
8595 dev_priv->display.update_plane = ironlake_update_plane;
8596 } else if (HAS_PCH_SPLIT(dev)) {
8597 dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
8598 dev_priv->display.crtc_enable = ironlake_crtc_enable;
8599 dev_priv->display.crtc_disable = ironlake_crtc_disable;
8600 dev_priv->display.off = ironlake_crtc_off;
8601 dev_priv->display.update_plane = ironlake_update_plane;
8603 dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
8604 dev_priv->display.crtc_enable = i9xx_crtc_enable;
8605 dev_priv->display.crtc_disable = i9xx_crtc_disable;
8606 dev_priv->display.off = i9xx_crtc_off;
8607 dev_priv->display.update_plane = i9xx_update_plane;
8610 /* Returns the core display clock speed */
8611 if (IS_VALLEYVIEW(dev))
8612 dev_priv->display.get_display_clock_speed =
8613 valleyview_get_display_clock_speed;
8614 else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
8615 dev_priv->display.get_display_clock_speed =
8616 i945_get_display_clock_speed;
8617 else if (IS_I915G(dev))
8618 dev_priv->display.get_display_clock_speed =
8619 i915_get_display_clock_speed;
8620 else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
8621 dev_priv->display.get_display_clock_speed =
8622 i9xx_misc_get_display_clock_speed;
8623 else if (IS_I915GM(dev))
8624 dev_priv->display.get_display_clock_speed =
8625 i915gm_get_display_clock_speed;
8626 else if (IS_I865G(dev))
8627 dev_priv->display.get_display_clock_speed =
8628 i865_get_display_clock_speed;
8629 else if (IS_I85X(dev))
8630 dev_priv->display.get_display_clock_speed =
8631 i855_get_display_clock_speed;
8633 dev_priv->display.get_display_clock_speed =
8634 i830_get_display_clock_speed;
8636 if (HAS_PCH_SPLIT(dev)) {
8638 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
8639 dev_priv->display.write_eld = ironlake_write_eld;
8640 } else if (IS_GEN6(dev)) {
8641 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
8642 dev_priv->display.write_eld = ironlake_write_eld;
8643 } else if (IS_IVYBRIDGE(dev)) {
8644 /* FIXME: detect B0+ stepping and use auto training */
8645 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
8646 dev_priv->display.write_eld = ironlake_write_eld;
8647 dev_priv->display.modeset_global_resources =
8648 ivb_modeset_global_resources;
8649 } else if (IS_HASWELL(dev)) {
8650 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
8651 dev_priv->display.write_eld = haswell_write_eld;
8652 dev_priv->display.modeset_global_resources =
8653 haswell_modeset_global_resources;
8655 } else if (IS_G4X(dev)) {
8656 dev_priv->display.write_eld = g4x_write_eld;
8659 /* Default just returns -ENODEV to indicate unsupported */
8660 dev_priv->display.queue_flip = intel_default_queue_flip;
8662 switch (INTEL_INFO(dev)->gen) {
8664 dev_priv->display.queue_flip = intel_gen2_queue_flip;
8668 dev_priv->display.queue_flip = intel_gen3_queue_flip;
8673 dev_priv->display.queue_flip = intel_gen4_queue_flip;
8677 dev_priv->display.queue_flip = intel_gen6_queue_flip;
8680 dev_priv->display.queue_flip = intel_gen7_queue_flip;
8686 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
8687 * resume, or other times. This quirk makes sure that's the case for
8690 static void quirk_pipea_force(struct drm_device *dev)
8692 struct drm_i915_private *dev_priv = dev->dev_private;
8694 dev_priv->quirks |= QUIRK_PIPEA_FORCE;
8695 DRM_INFO("applying pipe a force quirk\n");
8699 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
8701 static void quirk_ssc_force_disable(struct drm_device *dev)
8703 struct drm_i915_private *dev_priv = dev->dev_private;
8704 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
8705 DRM_INFO("applying lvds SSC disable quirk\n");
8709 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
8712 static void quirk_invert_brightness(struct drm_device *dev)
8714 struct drm_i915_private *dev_priv = dev->dev_private;
8715 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
8716 DRM_INFO("applying inverted panel brightness quirk\n");
8719 struct intel_quirk {
8721 int subsystem_vendor;
8722 int subsystem_device;
8723 void (*hook)(struct drm_device *dev);
8726 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
8727 struct intel_dmi_quirk {
8728 void (*hook)(struct drm_device *dev);
8729 const struct dmi_system_id (*dmi_id_list)[];
8732 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
8734 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
8738 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
8740 .dmi_id_list = &(const struct dmi_system_id[]) {
8742 .callback = intel_dmi_reverse_brightness,
8743 .ident = "NCR Corporation",
8744 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
8745 DMI_MATCH(DMI_PRODUCT_NAME, ""),
8748 { } /* terminating entry */
8750 .hook = quirk_invert_brightness,
8754 static struct intel_quirk intel_quirks[] = {
8755 /* HP Mini needs pipe A force quirk (LP: #322104) */
8756 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
8758 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
8759 { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
8761 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
8762 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
8764 /* 830/845 need to leave pipe A & dpll A up */
8765 { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
8766 { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
8768 /* Lenovo U160 cannot use SSC on LVDS */
8769 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
8771 /* Sony Vaio Y cannot use SSC on LVDS */
8772 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
8774 /* Acer Aspire 5734Z must invert backlight brightness */
8775 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
8777 /* Acer/eMachines G725 */
8778 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
8780 /* Acer/eMachines e725 */
8781 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
8783 /* Acer/Packard Bell NCL20 */
8784 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
8786 /* Acer Aspire 4736Z */
8787 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
8790 static void intel_init_quirks(struct drm_device *dev)
8792 struct pci_dev *d = dev->pdev;
8795 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
8796 struct intel_quirk *q = &intel_quirks[i];
8798 if (d->device == q->device &&
8799 (d->subsystem_vendor == q->subsystem_vendor ||
8800 q->subsystem_vendor == PCI_ANY_ID) &&
8801 (d->subsystem_device == q->subsystem_device ||
8802 q->subsystem_device == PCI_ANY_ID))
8805 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
8806 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
8807 intel_dmi_quirks[i].hook(dev);
8811 /* Disable the VGA plane that we never use */
8812 static void i915_disable_vga(struct drm_device *dev)
8814 struct drm_i915_private *dev_priv = dev->dev_private;
8816 u32 vga_reg = i915_vgacntrl_reg(dev);
8818 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
8819 outb(SR01, VGA_SR_INDEX);
8820 sr1 = inb(VGA_SR_DATA);
8821 outb(sr1 | 1<<5, VGA_SR_DATA);
8822 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
8825 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
8826 POSTING_READ(vga_reg);
8829 void intel_modeset_init_hw(struct drm_device *dev)
8831 intel_init_power_well(dev);
8833 intel_prepare_ddi(dev);
8835 intel_init_clock_gating(dev);
8837 mutex_lock(&dev->struct_mutex);
8838 intel_enable_gt_powersave(dev);
8839 mutex_unlock(&dev->struct_mutex);
8842 void intel_modeset_init(struct drm_device *dev)
8844 struct drm_i915_private *dev_priv = dev->dev_private;
8847 drm_mode_config_init(dev);
8849 dev->mode_config.min_width = 0;
8850 dev->mode_config.min_height = 0;
8852 dev->mode_config.preferred_depth = 24;
8853 dev->mode_config.prefer_shadow = 1;
8855 dev->mode_config.funcs = &intel_mode_funcs;
8857 intel_init_quirks(dev);
8861 intel_init_display(dev);
8864 dev->mode_config.max_width = 2048;
8865 dev->mode_config.max_height = 2048;
8866 } else if (IS_GEN3(dev)) {
8867 dev->mode_config.max_width = 4096;
8868 dev->mode_config.max_height = 4096;
8870 dev->mode_config.max_width = 8192;
8871 dev->mode_config.max_height = 8192;
8873 dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
8875 DRM_DEBUG_KMS("%d display pipe%s available.\n",
8876 dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
8878 for (i = 0; i < dev_priv->num_pipe; i++) {
8879 intel_crtc_init(dev, i);
8880 ret = intel_plane_init(dev, i);
8882 DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
8885 intel_cpu_pll_init(dev);
8886 intel_pch_pll_init(dev);
8888 /* Just disable it once at startup */
8889 i915_disable_vga(dev);
8890 intel_setup_outputs(dev);
8892 /* Just in case the BIOS is doing something questionable. */
8893 intel_disable_fbc(dev);
8897 intel_connector_break_all_links(struct intel_connector *connector)
8899 connector->base.dpms = DRM_MODE_DPMS_OFF;
8900 connector->base.encoder = NULL;
8901 connector->encoder->connectors_active = false;
8902 connector->encoder->base.crtc = NULL;
8905 static void intel_enable_pipe_a(struct drm_device *dev)
8907 struct intel_connector *connector;
8908 struct drm_connector *crt = NULL;
8909 struct intel_load_detect_pipe load_detect_temp;
8911 /* We can't just switch on the pipe A, we need to set things up with a
8912 * proper mode and output configuration. As a gross hack, enable pipe A
8913 * by enabling the load detect pipe once. */
8914 list_for_each_entry(connector,
8915 &dev->mode_config.connector_list,
8917 if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
8918 crt = &connector->base;
8926 if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp))
8927 intel_release_load_detect_pipe(crt, &load_detect_temp);
8933 intel_check_plane_mapping(struct intel_crtc *crtc)
8935 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
8938 if (dev_priv->num_pipe == 1)
8941 reg = DSPCNTR(!crtc->plane);
8942 val = I915_READ(reg);
8944 if ((val & DISPLAY_PLANE_ENABLE) &&
8945 (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
8951 static void intel_sanitize_crtc(struct intel_crtc *crtc)
8953 struct drm_device *dev = crtc->base.dev;
8954 struct drm_i915_private *dev_priv = dev->dev_private;
8957 /* Clear any frame start delays used for debugging left by the BIOS */
8958 reg = PIPECONF(crtc->cpu_transcoder);
8959 I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
8961 /* We need to sanitize the plane -> pipe mapping first because this will
8962 * disable the crtc (and hence change the state) if it is wrong. Note
8963 * that gen4+ has a fixed plane -> pipe mapping. */
8964 if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
8965 struct intel_connector *connector;
8968 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
8969 crtc->base.base.id);
8971 /* Pipe has the wrong plane attached and the plane is active.
8972 * Temporarily change the plane mapping and disable everything
8974 plane = crtc->plane;
8975 crtc->plane = !plane;
8976 dev_priv->display.crtc_disable(&crtc->base);
8977 crtc->plane = plane;
8979 /* ... and break all links. */
8980 list_for_each_entry(connector, &dev->mode_config.connector_list,
8982 if (connector->encoder->base.crtc != &crtc->base)
8985 intel_connector_break_all_links(connector);
8988 WARN_ON(crtc->active);
8989 crtc->base.enabled = false;
8992 if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
8993 crtc->pipe == PIPE_A && !crtc->active) {
8994 /* BIOS forgot to enable pipe A, this mostly happens after
8995 * resume. Force-enable the pipe to fix this, the update_dpms
8996 * call below we restore the pipe to the right state, but leave
8997 * the required bits on. */
8998 intel_enable_pipe_a(dev);
9001 /* Adjust the state of the output pipe according to whether we
9002 * have active connectors/encoders. */
9003 intel_crtc_update_dpms(&crtc->base);
9005 if (crtc->active != crtc->base.enabled) {
9006 struct intel_encoder *encoder;
9008 /* This can happen either due to bugs in the get_hw_state
9009 * functions or because the pipe is force-enabled due to the
9011 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
9013 crtc->base.enabled ? "enabled" : "disabled",
9014 crtc->active ? "enabled" : "disabled");
9016 crtc->base.enabled = crtc->active;
9018 /* Because we only establish the connector -> encoder ->
9019 * crtc links if something is active, this means the
9020 * crtc is now deactivated. Break the links. connector
9021 * -> encoder links are only establish when things are
9022 * actually up, hence no need to break them. */
9023 WARN_ON(crtc->active);
9025 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
9026 WARN_ON(encoder->connectors_active);
9027 encoder->base.crtc = NULL;
9032 static void intel_sanitize_encoder(struct intel_encoder *encoder)
9034 struct intel_connector *connector;
9035 struct drm_device *dev = encoder->base.dev;
9037 /* We need to check both for a crtc link (meaning that the
9038 * encoder is active and trying to read from a pipe) and the
9039 * pipe itself being active. */
9040 bool has_active_crtc = encoder->base.crtc &&
9041 to_intel_crtc(encoder->base.crtc)->active;
9043 if (encoder->connectors_active && !has_active_crtc) {
9044 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
9045 encoder->base.base.id,
9046 drm_get_encoder_name(&encoder->base));
9048 /* Connector is active, but has no active pipe. This is
9049 * fallout from our resume register restoring. Disable
9050 * the encoder manually again. */
9051 if (encoder->base.crtc) {
9052 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
9053 encoder->base.base.id,
9054 drm_get_encoder_name(&encoder->base));
9055 encoder->disable(encoder);
9058 /* Inconsistent output/port/pipe state happens presumably due to
9059 * a bug in one of the get_hw_state functions. Or someplace else
9060 * in our code, like the register restore mess on resume. Clamp
9061 * things to off as a safer default. */
9062 list_for_each_entry(connector,
9063 &dev->mode_config.connector_list,
9065 if (connector->encoder != encoder)
9068 intel_connector_break_all_links(connector);
9071 /* Enabled encoders without active connectors will be fixed in
9072 * the crtc fixup. */
9075 void i915_redisable_vga(struct drm_device *dev)
9077 struct drm_i915_private *dev_priv = dev->dev_private;
9078 u32 vga_reg = i915_vgacntrl_reg(dev);
9080 if (I915_READ(vga_reg) != VGA_DISP_DISABLE) {
9081 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
9082 i915_disable_vga(dev);
9086 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
9087 * and i915 state tracking structures. */
9088 void intel_modeset_setup_hw_state(struct drm_device *dev,
9091 struct drm_i915_private *dev_priv = dev->dev_private;
9094 struct intel_crtc *crtc;
9095 struct intel_encoder *encoder;
9096 struct intel_connector *connector;
9099 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9101 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9102 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9103 case TRANS_DDI_EDP_INPUT_A_ON:
9104 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9107 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9110 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9115 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9116 crtc->cpu_transcoder = TRANSCODER_EDP;
9118 DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
9123 for_each_pipe(pipe) {
9124 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9126 tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
9127 if (tmp & PIPECONF_ENABLE)
9128 crtc->active = true;
9130 crtc->active = false;
9132 crtc->base.enabled = crtc->active;
9134 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
9136 crtc->active ? "enabled" : "disabled");
9140 intel_ddi_setup_hw_pll_state(dev);
9142 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
9146 if (encoder->get_hw_state(encoder, &pipe)) {
9147 encoder->base.crtc =
9148 dev_priv->pipe_to_crtc_mapping[pipe];
9150 encoder->base.crtc = NULL;
9153 encoder->connectors_active = false;
9154 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
9155 encoder->base.base.id,
9156 drm_get_encoder_name(&encoder->base),
9157 encoder->base.crtc ? "enabled" : "disabled",
9161 list_for_each_entry(connector, &dev->mode_config.connector_list,
9163 if (connector->get_hw_state(connector)) {
9164 connector->base.dpms = DRM_MODE_DPMS_ON;
9165 connector->encoder->connectors_active = true;
9166 connector->base.encoder = &connector->encoder->base;
9168 connector->base.dpms = DRM_MODE_DPMS_OFF;
9169 connector->base.encoder = NULL;
9171 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
9172 connector->base.base.id,
9173 drm_get_connector_name(&connector->base),
9174 connector->base.encoder ? "enabled" : "disabled");
9177 /* HW state is read out, now we need to sanitize this mess. */
9178 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
9180 intel_sanitize_encoder(encoder);
9183 for_each_pipe(pipe) {
9184 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9185 intel_sanitize_crtc(crtc);
9188 if (force_restore) {
9189 for_each_pipe(pipe) {
9190 intel_crtc_restore_mode(dev_priv->pipe_to_crtc_mapping[pipe]);
9193 i915_redisable_vga(dev);
9195 intel_modeset_update_staged_output_state(dev);
9198 intel_modeset_check_state(dev);
9200 drm_mode_config_reset(dev);
9203 void intel_modeset_gem_init(struct drm_device *dev)
9205 intel_modeset_init_hw(dev);
9207 intel_setup_overlay(dev);
9209 intel_modeset_setup_hw_state(dev, false);
9212 void intel_modeset_cleanup(struct drm_device *dev)
9214 struct drm_i915_private *dev_priv = dev->dev_private;
9215 struct drm_crtc *crtc;
9216 struct intel_crtc *intel_crtc;
9218 drm_kms_helper_poll_fini(dev);
9219 mutex_lock(&dev->struct_mutex);
9221 intel_unregister_dsm_handler();
9224 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
9225 /* Skip inactive CRTCs */
9229 intel_crtc = to_intel_crtc(crtc);
9230 intel_increase_pllclock(crtc);
9233 intel_disable_fbc(dev);
9235 intel_disable_gt_powersave(dev);
9237 ironlake_teardown_rc6(dev);
9239 if (IS_VALLEYVIEW(dev))
9242 mutex_unlock(&dev->struct_mutex);
9244 /* Disable the irq before mode object teardown, for the irq might
9245 * enqueue unpin/hotplug work. */
9246 drm_irq_uninstall(dev);
9247 cancel_work_sync(&dev_priv->hotplug_work);
9248 cancel_work_sync(&dev_priv->rps.work);
9250 /* flush any delayed tasks or pending work */
9251 flush_scheduled_work();
9253 drm_mode_config_cleanup(dev);
9255 intel_cleanup_overlay(dev);
9259 * Return which encoder is currently attached for connector.
9261 struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
9263 return &intel_attached_encoder(connector)->base;
9266 void intel_connector_attach_encoder(struct intel_connector *connector,
9267 struct intel_encoder *encoder)
9269 connector->encoder = encoder;
9270 drm_mode_connector_attach_encoder(&connector->base,
9275 * set vga decode state - true == enable VGA decode
9277 int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
9279 struct drm_i915_private *dev_priv = dev->dev_private;
9282 pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
9284 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
9286 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
9287 pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
9291 #ifdef CONFIG_DEBUG_FS
9292 #include <linux/seq_file.h>
9294 struct intel_display_error_state {
9295 struct intel_cursor_error_state {
9300 } cursor[I915_MAX_PIPES];
9302 struct intel_pipe_error_state {
9312 } pipe[I915_MAX_PIPES];
9314 struct intel_plane_error_state {
9322 } plane[I915_MAX_PIPES];
9325 struct intel_display_error_state *
9326 intel_display_capture_error_state(struct drm_device *dev)
9328 drm_i915_private_t *dev_priv = dev->dev_private;
9329 struct intel_display_error_state *error;
9330 enum transcoder cpu_transcoder;
9333 error = kmalloc(sizeof(*error), GFP_ATOMIC);
9338 cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i);
9340 error->cursor[i].control = I915_READ(CURCNTR(i));
9341 error->cursor[i].position = I915_READ(CURPOS(i));
9342 error->cursor[i].base = I915_READ(CURBASE(i));
9344 error->plane[i].control = I915_READ(DSPCNTR(i));
9345 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
9346 error->plane[i].size = I915_READ(DSPSIZE(i));
9347 error->plane[i].pos = I915_READ(DSPPOS(i));
9348 error->plane[i].addr = I915_READ(DSPADDR(i));
9349 if (INTEL_INFO(dev)->gen >= 4) {
9350 error->plane[i].surface = I915_READ(DSPSURF(i));
9351 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
9354 error->pipe[i].conf = I915_READ(PIPECONF(cpu_transcoder));
9355 error->pipe[i].source = I915_READ(PIPESRC(i));
9356 error->pipe[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
9357 error->pipe[i].hblank = I915_READ(HBLANK(cpu_transcoder));
9358 error->pipe[i].hsync = I915_READ(HSYNC(cpu_transcoder));
9359 error->pipe[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
9360 error->pipe[i].vblank = I915_READ(VBLANK(cpu_transcoder));
9361 error->pipe[i].vsync = I915_READ(VSYNC(cpu_transcoder));
9368 intel_display_print_error_state(struct seq_file *m,
9369 struct drm_device *dev,
9370 struct intel_display_error_state *error)
9372 drm_i915_private_t *dev_priv = dev->dev_private;
9375 seq_printf(m, "Num Pipes: %d\n", dev_priv->num_pipe);
9377 seq_printf(m, "Pipe [%d]:\n", i);
9378 seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
9379 seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
9380 seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
9381 seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
9382 seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
9383 seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
9384 seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
9385 seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
9387 seq_printf(m, "Plane [%d]:\n", i);
9388 seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
9389 seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
9390 seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
9391 seq_printf(m, " POS: %08x\n", error->plane[i].pos);
9392 seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
9393 if (INTEL_INFO(dev)->gen >= 4) {
9394 seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
9395 seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
9398 seq_printf(m, "Cursor [%d]:\n", i);
9399 seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
9400 seq_printf(m, " POS: %08x\n", error->cursor[i].position);
9401 seq_printf(m, " BASE: %08x\n", error->cursor[i].base);