2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
28 #include <sys/limits.h>
31 #include <drm/drm_edid.h>
32 #include "intel_drv.h"
33 #include <drm/i915_drm.h>
35 #include <drm/drm_dp_helper.h>
36 #include <drm/drm_crtc_helper.h>
38 #include <linux/err.h>
40 bool intel_pipe_has_type(struct drm_crtc *crtc, int type);
41 static void intel_increase_pllclock(struct drm_crtc *crtc);
42 static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
65 #define INTEL_P2_NUM 2
66 typedef struct intel_limit intel_limit_t;
68 intel_range_t dot, vco, n, m, m1, m2, p, p1;
70 bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
71 int, int, intel_clock_t *, intel_clock_t *);
75 #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
78 intel_pch_rawclk(struct drm_device *dev)
80 struct drm_i915_private *dev_priv = dev->dev_private;
82 WARN_ON(!HAS_PCH_SPLIT(dev));
84 return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
88 intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
89 int target, int refclk, intel_clock_t *match_clock,
90 intel_clock_t *best_clock);
92 intel_g4x_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);
97 intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
98 int target, int refclk, intel_clock_t *match_clock,
99 intel_clock_t *best_clock);
101 intel_find_pll_ironlake_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);
106 intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc,
107 int target, int refclk, intel_clock_t *match_clock,
108 intel_clock_t *best_clock);
110 static inline u32 /* units of 100MHz */
111 intel_fdi_link_freq(struct drm_device *dev)
114 struct drm_i915_private *dev_priv = dev->dev_private;
115 return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
120 static const intel_limit_t intel_limits_i8xx_dvo = {
121 .dot = { .min = 25000, .max = 350000 },
122 .vco = { .min = 930000, .max = 1400000 },
123 .n = { .min = 3, .max = 16 },
124 .m = { .min = 96, .max = 140 },
125 .m1 = { .min = 18, .max = 26 },
126 .m2 = { .min = 6, .max = 16 },
127 .p = { .min = 4, .max = 128 },
128 .p1 = { .min = 2, .max = 33 },
129 .p2 = { .dot_limit = 165000,
130 .p2_slow = 4, .p2_fast = 2 },
131 .find_pll = intel_find_best_PLL,
134 static const intel_limit_t intel_limits_i8xx_lvds = {
135 .dot = { .min = 25000, .max = 350000 },
136 .vco = { .min = 930000, .max = 1400000 },
137 .n = { .min = 3, .max = 16 },
138 .m = { .min = 96, .max = 140 },
139 .m1 = { .min = 18, .max = 26 },
140 .m2 = { .min = 6, .max = 16 },
141 .p = { .min = 4, .max = 128 },
142 .p1 = { .min = 1, .max = 6 },
143 .p2 = { .dot_limit = 165000,
144 .p2_slow = 14, .p2_fast = 7 },
145 .find_pll = intel_find_best_PLL,
148 static const intel_limit_t intel_limits_i9xx_sdvo = {
149 .dot = { .min = 20000, .max = 400000 },
150 .vco = { .min = 1400000, .max = 2800000 },
151 .n = { .min = 1, .max = 6 },
152 .m = { .min = 70, .max = 120 },
153 .m1 = { .min = 8, .max = 18 },
154 .m2 = { .min = 3, .max = 7 },
155 .p = { .min = 5, .max = 80 },
156 .p1 = { .min = 1, .max = 8 },
157 .p2 = { .dot_limit = 200000,
158 .p2_slow = 10, .p2_fast = 5 },
159 .find_pll = intel_find_best_PLL,
162 static const intel_limit_t intel_limits_i9xx_lvds = {
163 .dot = { .min = 20000, .max = 400000 },
164 .vco = { .min = 1400000, .max = 2800000 },
165 .n = { .min = 1, .max = 6 },
166 .m = { .min = 70, .max = 120 },
167 .m1 = { .min = 8, .max = 18 },
168 .m2 = { .min = 3, .max = 7 },
169 .p = { .min = 7, .max = 98 },
170 .p1 = { .min = 1, .max = 8 },
171 .p2 = { .dot_limit = 112000,
172 .p2_slow = 14, .p2_fast = 7 },
173 .find_pll = intel_find_best_PLL,
177 static const intel_limit_t intel_limits_g4x_sdvo = {
178 .dot = { .min = 25000, .max = 270000 },
179 .vco = { .min = 1750000, .max = 3500000},
180 .n = { .min = 1, .max = 4 },
181 .m = { .min = 104, .max = 138 },
182 .m1 = { .min = 17, .max = 23 },
183 .m2 = { .min = 5, .max = 11 },
184 .p = { .min = 10, .max = 30 },
185 .p1 = { .min = 1, .max = 3},
186 .p2 = { .dot_limit = 270000,
190 .find_pll = intel_g4x_find_best_PLL,
193 static const intel_limit_t intel_limits_g4x_hdmi = {
194 .dot = { .min = 22000, .max = 400000 },
195 .vco = { .min = 1750000, .max = 3500000},
196 .n = { .min = 1, .max = 4 },
197 .m = { .min = 104, .max = 138 },
198 .m1 = { .min = 16, .max = 23 },
199 .m2 = { .min = 5, .max = 11 },
200 .p = { .min = 5, .max = 80 },
201 .p1 = { .min = 1, .max = 8},
202 .p2 = { .dot_limit = 165000,
203 .p2_slow = 10, .p2_fast = 5 },
204 .find_pll = intel_g4x_find_best_PLL,
207 static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
208 .dot = { .min = 20000, .max = 115000 },
209 .vco = { .min = 1750000, .max = 3500000 },
210 .n = { .min = 1, .max = 3 },
211 .m = { .min = 104, .max = 138 },
212 .m1 = { .min = 17, .max = 23 },
213 .m2 = { .min = 5, .max = 11 },
214 .p = { .min = 28, .max = 112 },
215 .p1 = { .min = 2, .max = 8 },
216 .p2 = { .dot_limit = 0,
217 .p2_slow = 14, .p2_fast = 14
219 .find_pll = intel_g4x_find_best_PLL,
222 static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
223 .dot = { .min = 80000, .max = 224000 },
224 .vco = { .min = 1750000, .max = 3500000 },
225 .n = { .min = 1, .max = 3 },
226 .m = { .min = 104, .max = 138 },
227 .m1 = { .min = 17, .max = 23 },
228 .m2 = { .min = 5, .max = 11 },
229 .p = { .min = 14, .max = 42 },
230 .p1 = { .min = 2, .max = 6 },
231 .p2 = { .dot_limit = 0,
232 .p2_slow = 7, .p2_fast = 7
234 .find_pll = intel_g4x_find_best_PLL,
237 static const intel_limit_t intel_limits_g4x_display_port = {
238 .dot = { .min = 161670, .max = 227000 },
239 .vco = { .min = 1750000, .max = 3500000},
240 .n = { .min = 1, .max = 2 },
241 .m = { .min = 97, .max = 108 },
242 .m1 = { .min = 0x10, .max = 0x12 },
243 .m2 = { .min = 0x05, .max = 0x06 },
244 .p = { .min = 10, .max = 20 },
245 .p1 = { .min = 1, .max = 2},
246 .p2 = { .dot_limit = 0,
247 .p2_slow = 10, .p2_fast = 10 },
248 .find_pll = intel_find_pll_g4x_dp,
251 static const intel_limit_t intel_limits_pineview_sdvo = {
252 .dot = { .min = 20000, .max = 400000},
253 .vco = { .min = 1700000, .max = 3500000 },
254 /* Pineview's Ncounter is a ring counter */
255 .n = { .min = 3, .max = 6 },
256 .m = { .min = 2, .max = 256 },
257 /* Pineview only has one combined m divider, which we treat as m2. */
258 .m1 = { .min = 0, .max = 0 },
259 .m2 = { .min = 0, .max = 254 },
260 .p = { .min = 5, .max = 80 },
261 .p1 = { .min = 1, .max = 8 },
262 .p2 = { .dot_limit = 200000,
263 .p2_slow = 10, .p2_fast = 5 },
264 .find_pll = intel_find_best_PLL,
267 static const intel_limit_t intel_limits_pineview_lvds = {
268 .dot = { .min = 20000, .max = 400000 },
269 .vco = { .min = 1700000, .max = 3500000 },
270 .n = { .min = 3, .max = 6 },
271 .m = { .min = 2, .max = 256 },
272 .m1 = { .min = 0, .max = 0 },
273 .m2 = { .min = 0, .max = 254 },
274 .p = { .min = 7, .max = 112 },
275 .p1 = { .min = 1, .max = 8 },
276 .p2 = { .dot_limit = 112000,
277 .p2_slow = 14, .p2_fast = 14 },
278 .find_pll = intel_find_best_PLL,
281 /* Ironlake / Sandybridge
283 * We calculate clock using (register_value + 2) for N/M1/M2, so here
284 * the range value for them is (actual_value - 2).
286 static const intel_limit_t intel_limits_ironlake_dac = {
287 .dot = { .min = 25000, .max = 350000 },
288 .vco = { .min = 1760000, .max = 3510000 },
289 .n = { .min = 1, .max = 5 },
290 .m = { .min = 79, .max = 127 },
291 .m1 = { .min = 12, .max = 22 },
292 .m2 = { .min = 5, .max = 9 },
293 .p = { .min = 5, .max = 80 },
294 .p1 = { .min = 1, .max = 8 },
295 .p2 = { .dot_limit = 225000,
296 .p2_slow = 10, .p2_fast = 5 },
297 .find_pll = intel_g4x_find_best_PLL,
300 static const intel_limit_t intel_limits_ironlake_single_lvds = {
301 .dot = { .min = 25000, .max = 350000 },
302 .vco = { .min = 1760000, .max = 3510000 },
303 .n = { .min = 1, .max = 3 },
304 .m = { .min = 79, .max = 118 },
305 .m1 = { .min = 12, .max = 22 },
306 .m2 = { .min = 5, .max = 9 },
307 .p = { .min = 28, .max = 112 },
308 .p1 = { .min = 2, .max = 8 },
309 .p2 = { .dot_limit = 225000,
310 .p2_slow = 14, .p2_fast = 14 },
311 .find_pll = intel_g4x_find_best_PLL,
314 static const intel_limit_t intel_limits_ironlake_dual_lvds = {
315 .dot = { .min = 25000, .max = 350000 },
316 .vco = { .min = 1760000, .max = 3510000 },
317 .n = { .min = 1, .max = 3 },
318 .m = { .min = 79, .max = 127 },
319 .m1 = { .min = 12, .max = 22 },
320 .m2 = { .min = 5, .max = 9 },
321 .p = { .min = 14, .max = 56 },
322 .p1 = { .min = 2, .max = 8 },
323 .p2 = { .dot_limit = 225000,
324 .p2_slow = 7, .p2_fast = 7 },
325 .find_pll = intel_g4x_find_best_PLL,
328 /* LVDS 100mhz refclk limits. */
329 static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
330 .dot = { .min = 25000, .max = 350000 },
331 .vco = { .min = 1760000, .max = 3510000 },
332 .n = { .min = 1, .max = 2 },
333 .m = { .min = 79, .max = 126 },
334 .m1 = { .min = 12, .max = 22 },
335 .m2 = { .min = 5, .max = 9 },
336 .p = { .min = 28, .max = 112 },
337 .p1 = { .min = 2, .max = 8 },
338 .p2 = { .dot_limit = 225000,
339 .p2_slow = 14, .p2_fast = 14 },
340 .find_pll = intel_g4x_find_best_PLL,
343 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
344 .dot = { .min = 25000, .max = 350000 },
345 .vco = { .min = 1760000, .max = 3510000 },
346 .n = { .min = 1, .max = 3 },
347 .m = { .min = 79, .max = 126 },
348 .m1 = { .min = 12, .max = 22 },
349 .m2 = { .min = 5, .max = 9 },
350 .p = { .min = 14, .max = 42 },
351 .p1 = { .min = 2, .max = 6 },
352 .p2 = { .dot_limit = 225000,
353 .p2_slow = 7, .p2_fast = 7 },
354 .find_pll = intel_g4x_find_best_PLL,
357 static const intel_limit_t intel_limits_ironlake_display_port = {
358 .dot = { .min = 25000, .max = 350000 },
359 .vco = { .min = 1760000, .max = 3510000},
360 .n = { .min = 1, .max = 2 },
361 .m = { .min = 81, .max = 90 },
362 .m1 = { .min = 12, .max = 22 },
363 .m2 = { .min = 5, .max = 9 },
364 .p = { .min = 10, .max = 20 },
365 .p1 = { .min = 1, .max = 2},
366 .p2 = { .dot_limit = 0,
367 .p2_slow = 10, .p2_fast = 10 },
368 .find_pll = intel_find_pll_ironlake_dp,
371 static const intel_limit_t intel_limits_vlv_dac = {
372 .dot = { .min = 25000, .max = 270000 },
373 .vco = { .min = 4000000, .max = 6000000 },
374 .n = { .min = 1, .max = 7 },
375 .m = { .min = 22, .max = 450 }, /* guess */
376 .m1 = { .min = 2, .max = 3 },
377 .m2 = { .min = 11, .max = 156 },
378 .p = { .min = 10, .max = 30 },
379 .p1 = { .min = 2, .max = 3 },
380 .p2 = { .dot_limit = 270000,
381 .p2_slow = 2, .p2_fast = 20 },
382 .find_pll = intel_vlv_find_best_pll,
385 static const intel_limit_t intel_limits_vlv_hdmi = {
386 .dot = { .min = 20000, .max = 165000 },
387 .vco = { .min = 4000000, .max = 5994000},
388 .n = { .min = 1, .max = 7 },
389 .m = { .min = 60, .max = 300 }, /* guess */
390 .m1 = { .min = 2, .max = 3 },
391 .m2 = { .min = 11, .max = 156 },
392 .p = { .min = 10, .max = 30 },
393 .p1 = { .min = 2, .max = 3 },
394 .p2 = { .dot_limit = 270000,
395 .p2_slow = 2, .p2_fast = 20 },
396 .find_pll = intel_vlv_find_best_pll,
399 static const intel_limit_t intel_limits_vlv_dp = {
400 .dot = { .min = 25000, .max = 270000 },
401 .vco = { .min = 4000000, .max = 6000000 },
402 .n = { .min = 1, .max = 7 },
403 .m = { .min = 22, .max = 450 },
404 .m1 = { .min = 2, .max = 3 },
405 .m2 = { .min = 11, .max = 156 },
406 .p = { .min = 10, .max = 30 },
407 .p1 = { .min = 2, .max = 3 },
408 .p2 = { .dot_limit = 270000,
409 .p2_slow = 2, .p2_fast = 20 },
410 .find_pll = intel_vlv_find_best_pll,
413 u32 intel_dpio_read(struct drm_i915_private *dev_priv, int reg)
415 WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
417 if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
418 DRM_ERROR("DPIO idle wait timed out\n");
422 I915_WRITE(DPIO_REG, reg);
423 I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_READ | DPIO_PORTID |
425 if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
426 DRM_ERROR("DPIO read wait timed out\n");
430 return I915_READ(DPIO_DATA);
433 static void intel_dpio_write(struct drm_i915_private *dev_priv, int reg,
436 WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
438 if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
439 DRM_ERROR("DPIO idle wait timed out\n");
443 I915_WRITE(DPIO_DATA, val);
444 I915_WRITE(DPIO_REG, reg);
445 I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_WRITE | DPIO_PORTID |
447 if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100))
448 DRM_ERROR("DPIO write wait timed out\n");
451 static void vlv_init_dpio(struct drm_device *dev)
453 struct drm_i915_private *dev_priv = dev->dev_private;
455 /* Reset the DPIO config */
456 I915_WRITE(DPIO_CTL, 0);
457 POSTING_READ(DPIO_CTL);
458 I915_WRITE(DPIO_CTL, 1);
459 POSTING_READ(DPIO_CTL);
462 static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
465 struct drm_device *dev = crtc->dev;
466 const intel_limit_t *limit;
468 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
469 if (intel_is_dual_link_lvds(dev)) {
470 /* LVDS dual channel */
471 if (refclk == 100000)
472 limit = &intel_limits_ironlake_dual_lvds_100m;
474 limit = &intel_limits_ironlake_dual_lvds;
476 if (refclk == 100000)
477 limit = &intel_limits_ironlake_single_lvds_100m;
479 limit = &intel_limits_ironlake_single_lvds;
481 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
482 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
483 limit = &intel_limits_ironlake_display_port;
485 limit = &intel_limits_ironlake_dac;
490 static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
492 struct drm_device *dev = crtc->dev;
493 const intel_limit_t *limit;
495 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
496 if (intel_is_dual_link_lvds(dev))
497 /* LVDS with dual channel */
498 limit = &intel_limits_g4x_dual_channel_lvds;
500 /* LVDS with dual channel */
501 limit = &intel_limits_g4x_single_channel_lvds;
502 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
503 intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
504 limit = &intel_limits_g4x_hdmi;
505 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
506 limit = &intel_limits_g4x_sdvo;
507 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
508 limit = &intel_limits_g4x_display_port;
509 } else /* The option is for other outputs */
510 limit = &intel_limits_i9xx_sdvo;
515 static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
517 struct drm_device *dev = crtc->dev;
518 const intel_limit_t *limit;
520 if (HAS_PCH_SPLIT(dev))
521 limit = intel_ironlake_limit(crtc, refclk);
522 else if (IS_G4X(dev)) {
523 limit = intel_g4x_limit(crtc);
524 } else if (IS_PINEVIEW(dev)) {
525 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
526 limit = &intel_limits_pineview_lvds;
528 limit = &intel_limits_pineview_sdvo;
529 } else if (IS_VALLEYVIEW(dev)) {
530 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG))
531 limit = &intel_limits_vlv_dac;
532 else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
533 limit = &intel_limits_vlv_hdmi;
535 limit = &intel_limits_vlv_dp;
536 } else if (!IS_GEN2(dev)) {
537 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
538 limit = &intel_limits_i9xx_lvds;
540 limit = &intel_limits_i9xx_sdvo;
542 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
543 limit = &intel_limits_i8xx_lvds;
545 limit = &intel_limits_i8xx_dvo;
550 /* m1 is reserved as 0 in Pineview, n is a ring counter */
551 static void pineview_clock(int refclk, intel_clock_t *clock)
553 clock->m = clock->m2 + 2;
554 clock->p = clock->p1 * clock->p2;
555 clock->vco = refclk * clock->m / clock->n;
556 clock->dot = clock->vco / clock->p;
559 static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
561 if (IS_PINEVIEW(dev)) {
562 pineview_clock(refclk, clock);
565 clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
566 clock->p = clock->p1 * clock->p2;
567 clock->vco = refclk * clock->m / (clock->n + 2);
568 clock->dot = clock->vco / clock->p;
572 * Returns whether any output on the specified pipe is of the specified type
574 bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
576 struct drm_device *dev = crtc->dev;
577 struct intel_encoder *encoder;
579 for_each_encoder_on_crtc(dev, crtc, encoder)
580 if (encoder->type == type)
586 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
588 * Returns whether the given set of divisors are valid for a given refclk with
589 * the given connectors.
592 static bool intel_PLL_is_valid(struct drm_device *dev,
593 const intel_limit_t *limit,
594 const intel_clock_t *clock)
596 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
597 INTELPllInvalid("p1 out of range\n");
598 if (clock->p < limit->p.min || limit->p.max < clock->p)
599 INTELPllInvalid("p out of range\n");
600 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
601 INTELPllInvalid("m2 out of range\n");
602 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
603 INTELPllInvalid("m1 out of range\n");
604 if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev))
605 INTELPllInvalid("m1 <= m2\n");
606 if (clock->m < limit->m.min || limit->m.max < clock->m)
607 INTELPllInvalid("m out of range\n");
608 if (clock->n < limit->n.min || limit->n.max < clock->n)
609 INTELPllInvalid("n out of range\n");
610 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
611 INTELPllInvalid("vco out of range\n");
612 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
613 * connector, etc., rather than just a single range.
615 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
616 INTELPllInvalid("dot out of range\n");
622 intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
623 int target, int refclk, intel_clock_t *match_clock,
624 intel_clock_t *best_clock)
627 struct drm_device *dev = crtc->dev;
631 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
633 * For LVDS just rely on its current settings for dual-channel.
634 * We haven't figured out how to reliably set up different
635 * single/dual channel state, if we even can.
637 if (intel_is_dual_link_lvds(dev))
638 clock.p2 = limit->p2.p2_fast;
640 clock.p2 = limit->p2.p2_slow;
642 if (target < limit->p2.dot_limit)
643 clock.p2 = limit->p2.p2_slow;
645 clock.p2 = limit->p2.p2_fast;
648 memset(best_clock, 0, sizeof(*best_clock));
650 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
652 for (clock.m2 = limit->m2.min;
653 clock.m2 <= limit->m2.max; clock.m2++) {
654 /* m1 is always 0 in Pineview */
655 if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev))
657 for (clock.n = limit->n.min;
658 clock.n <= limit->n.max; clock.n++) {
659 for (clock.p1 = limit->p1.min;
660 clock.p1 <= limit->p1.max; clock.p1++) {
663 intel_clock(dev, refclk, &clock);
664 if (!intel_PLL_is_valid(dev, limit,
668 clock.p != match_clock->p)
671 this_err = abs(clock.dot - target);
672 if (this_err < err) {
681 return (err != target);
685 intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
686 int target, int refclk, intel_clock_t *match_clock,
687 intel_clock_t *best_clock)
689 struct drm_device *dev = crtc->dev;
693 /* approximately equals target * 0.00585 */
694 int err_most = (target >> 8) + (target >> 9);
697 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
700 if (HAS_PCH_SPLIT(dev))
704 if (intel_is_dual_link_lvds(dev))
705 clock.p2 = limit->p2.p2_fast;
707 clock.p2 = limit->p2.p2_slow;
709 if (target < limit->p2.dot_limit)
710 clock.p2 = limit->p2.p2_slow;
712 clock.p2 = limit->p2.p2_fast;
715 memset(best_clock, 0, sizeof(*best_clock));
716 max_n = limit->n.max;
717 /* based on hardware requirement, prefer smaller n to precision */
718 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
719 /* based on hardware requirement, prefere larger m1,m2 */
720 for (clock.m1 = limit->m1.max;
721 clock.m1 >= limit->m1.min; clock.m1--) {
722 for (clock.m2 = limit->m2.max;
723 clock.m2 >= limit->m2.min; clock.m2--) {
724 for (clock.p1 = limit->p1.max;
725 clock.p1 >= limit->p1.min; clock.p1--) {
728 intel_clock(dev, refclk, &clock);
729 if (!intel_PLL_is_valid(dev, limit,
733 clock.p != match_clock->p)
736 this_err = abs(clock.dot - target);
737 if (this_err < err_most) {
751 intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
752 int target, int refclk, intel_clock_t *match_clock,
753 intel_clock_t *best_clock)
755 struct drm_device *dev = crtc->dev;
758 if (target < 200000) {
771 intel_clock(dev, refclk, &clock);
772 memcpy(best_clock, &clock, sizeof(intel_clock_t));
776 /* DisplayPort has only two frequencies, 162MHz and 270MHz */
778 intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
779 int target, int refclk, intel_clock_t *match_clock,
780 intel_clock_t *best_clock)
783 if (target < 200000) {
796 clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
797 clock.p = (clock.p1 * clock.p2);
798 clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
800 memcpy(best_clock, &clock, sizeof(intel_clock_t));
805 intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc,
806 int target, int refclk, intel_clock_t *match_clock,
807 intel_clock_t *best_clock)
809 u32 p1, p2, m1, m2, vco, bestn, bestm1, bestm2, bestp1, bestp2;
811 u32 updrate, minupdate, fracbits, p;
812 unsigned long bestppm, ppm, absppm;
816 dotclk = target * 1000;
819 fastclk = dotclk / (2*100);
823 n = p = p1 = p2 = m = m1 = m2 = vco = bestn = 0;
824 bestm1 = bestm2 = bestp1 = bestp2 = 0;
826 /* based on hardware requirement, prefer smaller n to precision */
827 for (n = limit->n.min; n <= ((refclk) / minupdate); n++) {
828 updrate = refclk / n;
829 for (p1 = limit->p1.max; p1 > limit->p1.min; p1--) {
830 for (p2 = limit->p2.p2_fast+1; p2 > 0; p2--) {
834 /* based on hardware requirement, prefer bigger m1,m2 values */
835 for (m1 = limit->m1.min; m1 <= limit->m1.max; m1++) {
836 m2 = (((2*(fastclk * p * n / m1 )) +
837 refclk) / (2*refclk));
840 if (vco >= limit->vco.min && vco < limit->vco.max) {
841 ppm = 1000000 * ((vco / p) - fastclk) / fastclk;
842 absppm = (ppm > 0) ? ppm : (-ppm);
843 if (absppm < 100 && ((p1 * p2) > (bestp1 * bestp2))) {
847 if (absppm < bestppm - 10) {
864 best_clock->n = bestn;
865 best_clock->m1 = bestm1;
866 best_clock->m2 = bestm2;
867 best_clock->p1 = bestp1;
868 best_clock->p2 = bestp2;
873 enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
876 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
877 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
879 return intel_crtc->cpu_transcoder;
882 static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe)
884 struct drm_i915_private *dev_priv = dev->dev_private;
885 u32 frame, frame_reg = PIPEFRAME(pipe);
887 frame = I915_READ(frame_reg);
889 if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
890 DRM_DEBUG_KMS("vblank wait timed out\n");
894 * intel_wait_for_vblank - wait for vblank on a given pipe
896 * @pipe: pipe to wait for
898 * Wait for vblank to occur on a given pipe. Needed for various bits of
901 void intel_wait_for_vblank(struct drm_device *dev, int pipe)
903 struct drm_i915_private *dev_priv = dev->dev_private;
904 int pipestat_reg = PIPESTAT(pipe);
906 if (INTEL_INFO(dev)->gen >= 5) {
907 ironlake_wait_for_vblank(dev, pipe);
911 /* Clear existing vblank status. Note this will clear any other
912 * sticky status fields as well.
914 * This races with i915_driver_irq_handler() with the result
915 * that either function could miss a vblank event. Here it is not
916 * fatal, as we will either wait upon the next vblank interrupt or
917 * timeout. Generally speaking intel_wait_for_vblank() is only
918 * called during modeset at which time the GPU should be idle and
919 * should *not* be performing page flips and thus not waiting on
921 * Currently, the result of us stealing a vblank from the irq
922 * handler is that a single frame will be skipped during swapbuffers.
924 I915_WRITE(pipestat_reg,
925 I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
927 /* Wait for vblank interrupt bit to set */
928 if (wait_for(I915_READ(pipestat_reg) &
929 PIPE_VBLANK_INTERRUPT_STATUS,
931 DRM_DEBUG_KMS("vblank wait timed out\n");
935 * intel_wait_for_pipe_off - wait for pipe to turn off
937 * @pipe: pipe to wait for
939 * After disabling a pipe, we can't wait for vblank in the usual way,
940 * spinning on the vblank interrupt status bit, since we won't actually
941 * see an interrupt when the pipe is disabled.
944 * wait for the pipe register state bit to turn off
947 * wait for the display line value to settle (it usually
948 * ends up stopping at the start of the next frame).
951 void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
953 struct drm_i915_private *dev_priv = dev->dev_private;
954 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
957 if (INTEL_INFO(dev)->gen >= 4) {
958 int reg = PIPECONF(cpu_transcoder);
960 /* Wait for the Pipe State to go off */
961 if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
963 WARN(1, "pipe_off wait timed out\n");
965 u32 last_line, line_mask;
966 int reg = PIPEDSL(pipe);
967 unsigned long timeout = jiffies + msecs_to_jiffies(100);
970 line_mask = DSL_LINEMASK_GEN2;
972 line_mask = DSL_LINEMASK_GEN3;
974 /* Wait for the display line to settle */
976 last_line = I915_READ(reg) & line_mask;
978 } while (((I915_READ(reg) & line_mask) != last_line) &&
979 time_after(timeout, jiffies));
980 if (time_after(jiffies, timeout))
981 WARN(1, "pipe_off wait timed out\n");
986 * ibx_digital_port_connected - is the specified port connected?
987 * @dev_priv: i915 private structure
988 * @port: the port to test
990 * Returns true if @port is connected, false otherwise.
992 bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
993 struct intel_digital_port *port)
997 if (HAS_PCH_IBX(dev_priv->dev)) {
1000 bit = SDE_PORTB_HOTPLUG;
1003 bit = SDE_PORTC_HOTPLUG;
1006 bit = SDE_PORTD_HOTPLUG;
1012 switch(port->port) {
1014 bit = SDE_PORTB_HOTPLUG_CPT;
1017 bit = SDE_PORTC_HOTPLUG_CPT;
1020 bit = SDE_PORTD_HOTPLUG_CPT;
1027 return I915_READ(SDEISR) & bit;
1030 static const char *state_string(bool enabled)
1032 return enabled ? "on" : "off";
1035 /* Only for pre-ILK configs */
1036 static void assert_pll(struct drm_i915_private *dev_priv,
1037 enum i915_pipe pipe, bool state)
1044 val = I915_READ(reg);
1045 cur_state = !!(val & DPLL_VCO_ENABLE);
1046 WARN(cur_state != state,
1047 "PLL state assertion failure (expected %s, current %s)\n",
1048 state_string(state), state_string(cur_state));
1050 #define assert_pll_enabled(d, p) assert_pll(d, p, true)
1051 #define assert_pll_disabled(d, p) assert_pll(d, p, false)
1054 static void assert_pch_pll(struct drm_i915_private *dev_priv,
1055 struct intel_pch_pll *pll,
1056 struct intel_crtc *crtc,
1062 if (HAS_PCH_LPT(dev_priv->dev)) {
1063 DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
1068 "asserting PCH PLL %s with no PLL\n", state_string(state)))
1071 val = I915_READ(pll->pll_reg);
1072 cur_state = !!(val & DPLL_VCO_ENABLE);
1073 WARN(cur_state != state,
1074 "PCH PLL state for reg %x assertion failure (expected %s, current %s), val=%08x\n",
1075 pll->pll_reg, state_string(state), state_string(cur_state), val);
1077 /* Make sure the selected PLL is correctly attached to the transcoder */
1078 if (crtc && HAS_PCH_CPT(dev_priv->dev)) {
1081 pch_dpll = I915_READ(PCH_DPLL_SEL);
1082 cur_state = pll->pll_reg == _PCH_DPLL_B;
1083 if (!WARN(((pch_dpll >> (4 * crtc->pipe)) & 1) != cur_state,
1084 "PLL[%d] not attached to this transcoder %d: %08x\n",
1085 cur_state, crtc->pipe, pch_dpll)) {
1086 cur_state = !!(val >> (4*crtc->pipe + 3));
1087 WARN(cur_state != state,
1088 "PLL[%d] not %s on this transcoder %d: %08x\n",
1089 pll->pll_reg == _PCH_DPLL_B,
1090 state_string(state),
1096 #define assert_pch_pll_enabled(d, p, c) assert_pch_pll(d, p, c, true)
1097 #define assert_pch_pll_disabled(d, p, c) assert_pch_pll(d, p, c, false)
1099 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1100 enum i915_pipe pipe, bool state)
1105 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1108 if (HAS_DDI(dev_priv->dev)) {
1109 /* DDI does not have a specific FDI_TX register */
1110 reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
1111 val = I915_READ(reg);
1112 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1114 reg = FDI_TX_CTL(pipe);
1115 val = I915_READ(reg);
1116 cur_state = !!(val & FDI_TX_ENABLE);
1118 WARN(cur_state != state,
1119 "FDI TX state assertion failure (expected %s, current %s)\n",
1120 state_string(state), state_string(cur_state));
1122 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1123 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1125 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1126 enum i915_pipe pipe, bool state)
1132 reg = FDI_RX_CTL(pipe);
1133 val = I915_READ(reg);
1134 cur_state = !!(val & FDI_RX_ENABLE);
1135 WARN(cur_state != state,
1136 "FDI RX state assertion failure (expected %s, current %s)\n",
1137 state_string(state), state_string(cur_state));
1139 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1140 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1142 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1143 enum i915_pipe pipe)
1148 /* ILK FDI PLL is always enabled */
1149 if (dev_priv->info->gen == 5)
1152 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1153 if (HAS_DDI(dev_priv->dev))
1156 reg = FDI_TX_CTL(pipe);
1157 val = I915_READ(reg);
1158 WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
1161 static void assert_fdi_rx_pll_enabled(struct drm_i915_private *dev_priv,
1162 enum i915_pipe pipe)
1167 reg = FDI_RX_CTL(pipe);
1168 val = I915_READ(reg);
1169 WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n");
1172 static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
1173 enum i915_pipe pipe)
1175 int pp_reg, lvds_reg;
1177 enum i915_pipe panel_pipe = PIPE_A;
1180 if (HAS_PCH_SPLIT(dev_priv->dev)) {
1181 pp_reg = PCH_PP_CONTROL;
1182 lvds_reg = PCH_LVDS;
1184 pp_reg = PP_CONTROL;
1188 val = I915_READ(pp_reg);
1189 if (!(val & PANEL_POWER_ON) ||
1190 ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
1193 if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
1194 panel_pipe = PIPE_B;
1196 WARN(panel_pipe == pipe && locked,
1197 "panel assertion failure, pipe %c regs locked\n",
1201 void assert_pipe(struct drm_i915_private *dev_priv,
1202 enum i915_pipe pipe, bool state)
1207 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1210 /* if we need the pipe A quirk it must be always on */
1211 if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
1214 if (IS_HASWELL(dev_priv->dev) && cpu_transcoder != TRANSCODER_EDP &&
1215 !(I915_READ(HSW_PWR_WELL_DRIVER) & HSW_PWR_WELL_ENABLE)) {
1218 reg = PIPECONF(cpu_transcoder);
1219 val = I915_READ(reg);
1220 cur_state = !!(val & PIPECONF_ENABLE);
1223 WARN(cur_state != state,
1224 "pipe %c assertion failure (expected %s, current %s)\n",
1225 pipe_name(pipe), state_string(state), state_string(cur_state));
1228 static void assert_plane(struct drm_i915_private *dev_priv,
1229 enum plane plane, bool state)
1235 reg = DSPCNTR(plane);
1236 val = I915_READ(reg);
1237 cur_state = !!(val & DISPLAY_PLANE_ENABLE);
1238 WARN(cur_state != state,
1239 "plane %c assertion failure (expected %s, current %s)\n",
1240 plane_name(plane), state_string(state), state_string(cur_state));
1243 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1244 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1246 static void assert_planes_disabled(struct drm_i915_private *dev_priv,
1247 enum i915_pipe pipe)
1253 /* Planes are fixed to pipes on ILK+ */
1254 if (HAS_PCH_SPLIT(dev_priv->dev)) {
1255 reg = DSPCNTR(pipe);
1256 val = I915_READ(reg);
1257 WARN((val & DISPLAY_PLANE_ENABLE),
1258 "plane %c assertion failure, should be disabled but not\n",
1263 /* Need to check both planes against the pipe */
1264 for (i = 0; i < 2; i++) {
1266 val = I915_READ(reg);
1267 cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
1268 DISPPLANE_SEL_PIPE_SHIFT;
1269 WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
1270 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1271 plane_name(i), pipe_name(pipe));
1275 static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
1280 if (HAS_PCH_LPT(dev_priv->dev)) {
1281 DRM_DEBUG_DRIVER("LPT does not has PCH refclk, skipping check\n");
1285 val = I915_READ(PCH_DREF_CONTROL);
1286 enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
1287 DREF_SUPERSPREAD_SOURCE_MASK));
1288 WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
1291 static void assert_transcoder_disabled(struct drm_i915_private *dev_priv,
1292 enum i915_pipe pipe)
1298 reg = TRANSCONF(pipe);
1299 val = I915_READ(reg);
1300 enabled = !!(val & TRANS_ENABLE);
1302 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1306 static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
1307 enum i915_pipe pipe, u32 port_sel, u32 val)
1309 if ((val & DP_PORT_EN) == 0)
1312 if (HAS_PCH_CPT(dev_priv->dev)) {
1313 u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
1314 u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
1315 if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
1318 if ((val & DP_PIPE_MASK) != (pipe << 30))
1324 static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
1325 enum i915_pipe pipe, u32 val)
1327 if ((val & PORT_ENABLE) == 0)
1330 if (HAS_PCH_CPT(dev_priv->dev)) {
1331 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1334 if ((val & TRANSCODER_MASK) != TRANSCODER(pipe))
1340 static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
1341 enum i915_pipe pipe, u32 val)
1343 if ((val & LVDS_PORT_EN) == 0)
1346 if (HAS_PCH_CPT(dev_priv->dev)) {
1347 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1350 if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
1356 static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
1357 enum i915_pipe pipe, u32 val)
1359 if ((val & ADPA_DAC_ENABLE) == 0)
1361 if (HAS_PCH_CPT(dev_priv->dev)) {
1362 if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
1365 if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
1371 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
1372 enum i915_pipe pipe, int reg, u32 port_sel)
1374 u32 val = I915_READ(reg);
1375 WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
1376 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1377 reg, pipe_name(pipe));
1379 WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
1380 && (val & DP_PIPEB_SELECT),
1381 "IBX PCH dp port still using transcoder B\n");
1384 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
1385 enum i915_pipe pipe, int reg)
1387 u32 val = I915_READ(reg);
1388 WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
1389 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1390 reg, pipe_name(pipe));
1392 WARN(HAS_PCH_IBX(dev_priv->dev) && (val & PORT_ENABLE) == 0
1393 && (val & SDVO_PIPE_B_SELECT),
1394 "IBX PCH hdmi port still using transcoder B\n");
1397 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1398 enum i915_pipe pipe)
1403 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
1404 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
1405 assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
1408 val = I915_READ(reg);
1409 WARN(adpa_pipe_enabled(dev_priv, pipe, val),
1410 "PCH VGA enabled on transcoder %c, should be disabled\n",
1414 val = I915_READ(reg);
1415 WARN(lvds_pipe_enabled(dev_priv, pipe, val),
1416 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1419 assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB);
1420 assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC);
1421 assert_pch_hdmi_disabled(dev_priv, pipe, HDMID);
1425 * intel_enable_pll - enable a PLL
1426 * @dev_priv: i915 private structure
1427 * @pipe: pipe PLL to enable
1429 * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to
1430 * make sure the PLL reg is writable first though, since the panel write
1431 * protect mechanism may be enabled.
1433 * Note! This is for pre-ILK only.
1435 * Unfortunately needed by dvo_ns2501 since the dvo depends on it running.
1437 static void intel_enable_pll(struct drm_i915_private *dev_priv, enum i915_pipe pipe)
1442 /* No really, not for ILK+ */
1443 BUG_ON(!IS_VALLEYVIEW(dev_priv->dev) && dev_priv->info->gen >= 5);
1445 /* PLL is protected by panel, make sure we can write it */
1446 if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
1447 assert_panel_unlocked(dev_priv, pipe);
1450 val = I915_READ(reg);
1451 val |= DPLL_VCO_ENABLE;
1453 /* We do this three times for luck */
1454 I915_WRITE(reg, val);
1456 udelay(150); /* wait for warmup */
1457 I915_WRITE(reg, val);
1459 udelay(150); /* wait for warmup */
1460 I915_WRITE(reg, val);
1462 udelay(150); /* wait for warmup */
1466 * intel_disable_pll - disable a PLL
1467 * @dev_priv: i915 private structure
1468 * @pipe: pipe PLL to disable
1470 * Disable the PLL for @pipe, making sure the pipe is off first.
1472 * Note! This is for pre-ILK only.
1474 static void intel_disable_pll(struct drm_i915_private *dev_priv, enum i915_pipe pipe)
1479 /* Don't disable pipe A or pipe A PLLs if needed */
1480 if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
1483 /* Make sure the pipe isn't still relying on us */
1484 assert_pipe_disabled(dev_priv, pipe);
1487 val = I915_READ(reg);
1488 val &= ~DPLL_VCO_ENABLE;
1489 I915_WRITE(reg, val);
1495 intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
1496 enum intel_sbi_destination destination)
1500 WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
1502 if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0, 100)) {
1503 DRM_ERROR("timeout waiting for SBI to become ready\n");
1507 I915_WRITE(SBI_ADDR, (reg << 16));
1508 I915_WRITE(SBI_DATA, value);
1510 if (destination == SBI_ICLK)
1511 tmp = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRWR;
1513 tmp = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IOWR;
1514 I915_WRITE(SBI_CTL_STAT, SBI_BUSY | tmp);
1516 if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0,
1518 DRM_ERROR("timeout waiting for SBI to complete write transaction\n");
1524 intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
1525 enum intel_sbi_destination destination)
1529 WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
1531 if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0, 100)) {
1532 DRM_ERROR("timeout waiting for SBI to become ready\n");
1536 I915_WRITE(SBI_ADDR, (reg << 16));
1538 if (destination == SBI_ICLK)
1539 value = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRRD;
1541 value = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IORD;
1542 I915_WRITE(SBI_CTL_STAT, value | SBI_BUSY);
1544 if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0,
1546 DRM_ERROR("timeout waiting for SBI to complete read transaction\n");
1550 return I915_READ(SBI_DATA);
1554 * ironlake_enable_pch_pll - enable PCH PLL
1555 * @dev_priv: i915 private structure
1556 * @pipe: pipe PLL to enable
1558 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1559 * drives the transcoder clock.
1561 static void ironlake_enable_pch_pll(struct intel_crtc *intel_crtc)
1563 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
1564 struct intel_pch_pll *pll;
1568 /* PCH PLLs only available on ILK, SNB and IVB */
1569 BUG_ON(dev_priv->info->gen < 5);
1570 pll = intel_crtc->pch_pll;
1574 if (WARN_ON(pll->refcount == 0))
1577 DRM_DEBUG_KMS("enable PCH PLL %x (active %d, on? %d)for crtc %d\n",
1578 pll->pll_reg, pll->active, pll->on,
1579 intel_crtc->base.base.id);
1581 /* PCH refclock must be enabled first */
1582 assert_pch_refclk_enabled(dev_priv);
1584 if (pll->active++ && pll->on) {
1585 assert_pch_pll_enabled(dev_priv, pll, NULL);
1589 DRM_DEBUG_KMS("enabling PCH PLL %x\n", pll->pll_reg);
1592 val = I915_READ(reg);
1593 val |= DPLL_VCO_ENABLE;
1594 I915_WRITE(reg, val);
1601 static void intel_disable_pch_pll(struct intel_crtc *intel_crtc)
1603 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
1604 struct intel_pch_pll *pll = intel_crtc->pch_pll;
1608 /* PCH only available on ILK+ */
1609 BUG_ON(dev_priv->info->gen < 5);
1613 if (WARN_ON(pll->refcount == 0))
1616 DRM_DEBUG_KMS("disable PCH PLL %x (active %d, on? %d) for crtc %d\n",
1617 pll->pll_reg, pll->active, pll->on,
1618 intel_crtc->base.base.id);
1620 if (WARN_ON(pll->active == 0)) {
1621 assert_pch_pll_disabled(dev_priv, pll, NULL);
1625 if (--pll->active) {
1626 assert_pch_pll_enabled(dev_priv, pll, NULL);
1630 DRM_DEBUG_KMS("disabling PCH PLL %x\n", pll->pll_reg);
1632 /* Make sure transcoder isn't still depending on us */
1633 assert_transcoder_disabled(dev_priv, intel_crtc->pipe);
1636 val = I915_READ(reg);
1637 val &= ~DPLL_VCO_ENABLE;
1638 I915_WRITE(reg, val);
1645 static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1646 enum i915_pipe pipe)
1648 struct drm_device *dev = dev_priv->dev;
1649 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1650 uint32_t reg, val, pipeconf_val;
1652 /* PCH only available on ILK+ */
1653 BUG_ON(dev_priv->info->gen < 5);
1655 /* Make sure PCH DPLL is enabled */
1656 assert_pch_pll_enabled(dev_priv,
1657 to_intel_crtc(crtc)->pch_pll,
1658 to_intel_crtc(crtc));
1660 /* FDI must be feeding us bits for PCH ports */
1661 assert_fdi_tx_enabled(dev_priv, pipe);
1662 assert_fdi_rx_enabled(dev_priv, pipe);
1664 if (HAS_PCH_CPT(dev)) {
1665 /* Workaround: Set the timing override bit before enabling the
1666 * pch transcoder. */
1667 reg = TRANS_CHICKEN2(pipe);
1668 val = I915_READ(reg);
1669 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1670 I915_WRITE(reg, val);
1673 reg = TRANSCONF(pipe);
1674 val = I915_READ(reg);
1675 pipeconf_val = I915_READ(PIPECONF(pipe));
1677 if (HAS_PCH_IBX(dev_priv->dev)) {
1679 * make the BPC in transcoder be consistent with
1680 * that in pipeconf reg.
1682 val &= ~PIPECONF_BPC_MASK;
1683 val |= pipeconf_val & PIPECONF_BPC_MASK;
1686 val &= ~TRANS_INTERLACE_MASK;
1687 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
1688 if (HAS_PCH_IBX(dev_priv->dev) &&
1689 intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
1690 val |= TRANS_LEGACY_INTERLACED_ILK;
1692 val |= TRANS_INTERLACED;
1694 val |= TRANS_PROGRESSIVE;
1696 I915_WRITE(reg, val | TRANS_ENABLE);
1697 if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
1698 DRM_ERROR("failed to enable transcoder %d\n", pipe);
1701 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1702 enum transcoder cpu_transcoder)
1704 u32 val, pipeconf_val;
1706 /* PCH only available on ILK+ */
1707 BUG_ON(dev_priv->info->gen < 5);
1709 /* FDI must be feeding us bits for PCH ports */
1710 assert_fdi_tx_enabled(dev_priv, (enum i915_pipe) cpu_transcoder);
1711 assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
1713 /* Workaround: set timing override bit. */
1714 val = I915_READ(_TRANSA_CHICKEN2);
1715 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1716 I915_WRITE(_TRANSA_CHICKEN2, val);
1719 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
1721 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1722 PIPECONF_INTERLACED_ILK)
1723 val |= TRANS_INTERLACED;
1725 val |= TRANS_PROGRESSIVE;
1727 I915_WRITE(TRANSCONF(TRANSCODER_A), val);
1728 if (wait_for(I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE, 100))
1729 DRM_ERROR("Failed to enable PCH transcoder\n");
1732 static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1733 enum i915_pipe pipe)
1735 struct drm_device *dev = dev_priv->dev;
1738 /* FDI relies on the transcoder */
1739 assert_fdi_tx_disabled(dev_priv, pipe);
1740 assert_fdi_rx_disabled(dev_priv, pipe);
1742 /* Ports must be off as well */
1743 assert_pch_ports_disabled(dev_priv, pipe);
1745 reg = TRANSCONF(pipe);
1746 val = I915_READ(reg);
1747 val &= ~TRANS_ENABLE;
1748 I915_WRITE(reg, val);
1749 /* wait for PCH transcoder off, transcoder state */
1750 if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
1751 DRM_ERROR("failed to disable transcoder %d\n", pipe);
1753 if (!HAS_PCH_IBX(dev)) {
1754 /* Workaround: Clear the timing override chicken bit again. */
1755 reg = TRANS_CHICKEN2(pipe);
1756 val = I915_READ(reg);
1757 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1758 I915_WRITE(reg, val);
1762 static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
1766 val = I915_READ(_TRANSACONF);
1767 val &= ~TRANS_ENABLE;
1768 I915_WRITE(_TRANSACONF, val);
1769 /* wait for PCH transcoder off, transcoder state */
1770 if (wait_for((I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE) == 0, 50))
1771 DRM_ERROR("Failed to disable PCH transcoder\n");
1773 /* Workaround: clear timing override bit. */
1774 val = I915_READ(_TRANSA_CHICKEN2);
1775 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1776 I915_WRITE(_TRANSA_CHICKEN2, val);
1780 * intel_enable_pipe - enable a pipe, asserting requirements
1781 * @dev_priv: i915 private structure
1782 * @pipe: pipe to enable
1783 * @pch_port: on ILK+, is this pipe driving a PCH port or not
1785 * Enable @pipe, making sure that various hardware specific requirements
1786 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1788 * @pipe should be %PIPE_A or %PIPE_B.
1790 * Will wait until the pipe is actually running (i.e. first vblank) before
1793 static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum i915_pipe pipe,
1796 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1798 enum i915_pipe pch_transcoder;
1802 if (HAS_PCH_LPT(dev_priv->dev))
1803 pch_transcoder = TRANSCODER_A;
1805 pch_transcoder = pipe;
1808 * A pipe without a PLL won't actually be able to drive bits from
1809 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1812 if (!HAS_PCH_SPLIT(dev_priv->dev))
1813 assert_pll_enabled(dev_priv, pipe);
1816 /* if driving the PCH, we need FDI enabled */
1817 assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
1818 assert_fdi_tx_pll_enabled(dev_priv,
1819 (enum i915_pipe) cpu_transcoder);
1821 /* FIXME: assert CPU port conditions for SNB+ */
1824 reg = PIPECONF(cpu_transcoder);
1825 val = I915_READ(reg);
1826 if (val & PIPECONF_ENABLE)
1829 I915_WRITE(reg, val | PIPECONF_ENABLE);
1830 intel_wait_for_vblank(dev_priv->dev, pipe);
1834 * intel_disable_pipe - disable a pipe, asserting requirements
1835 * @dev_priv: i915 private structure
1836 * @pipe: pipe to disable
1838 * Disable @pipe, making sure that various hardware specific requirements
1839 * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
1841 * @pipe should be %PIPE_A or %PIPE_B.
1843 * Will wait until the pipe has shut down before returning.
1845 static void intel_disable_pipe(struct drm_i915_private *dev_priv,
1846 enum i915_pipe pipe)
1848 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1854 * Make sure planes won't keep trying to pump pixels to us,
1855 * or we might hang the display.
1857 assert_planes_disabled(dev_priv, pipe);
1859 /* Don't disable pipe A or pipe A PLLs if needed */
1860 if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
1863 reg = PIPECONF(cpu_transcoder);
1864 val = I915_READ(reg);
1865 if ((val & PIPECONF_ENABLE) == 0)
1868 I915_WRITE(reg, val & ~PIPECONF_ENABLE);
1869 intel_wait_for_pipe_off(dev_priv->dev, pipe);
1873 * Plane regs are double buffered, going from enabled->disabled needs a
1874 * trigger in order to latch. The display address reg provides this.
1876 void intel_flush_display_plane(struct drm_i915_private *dev_priv,
1879 if (dev_priv->info->gen >= 4)
1880 I915_WRITE(DSPSURF(plane), I915_READ(DSPSURF(plane)));
1882 I915_WRITE(DSPADDR(plane), I915_READ(DSPADDR(plane)));
1886 * intel_enable_plane - enable a display plane on a given pipe
1887 * @dev_priv: i915 private structure
1888 * @plane: plane to enable
1889 * @pipe: pipe being fed
1891 * Enable @plane on @pipe, making sure that @pipe is running first.
1893 static void intel_enable_plane(struct drm_i915_private *dev_priv,
1894 enum plane plane, enum i915_pipe pipe)
1899 /* If the pipe isn't enabled, we can't pump pixels and may hang */
1900 assert_pipe_enabled(dev_priv, pipe);
1902 reg = DSPCNTR(plane);
1903 val = I915_READ(reg);
1904 if (val & DISPLAY_PLANE_ENABLE)
1907 I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
1908 intel_flush_display_plane(dev_priv, plane);
1909 intel_wait_for_vblank(dev_priv->dev, pipe);
1913 * intel_disable_plane - disable a display plane
1914 * @dev_priv: i915 private structure
1915 * @plane: plane to disable
1916 * @pipe: pipe consuming the data
1918 * Disable @plane; should be an independent operation.
1920 static void intel_disable_plane(struct drm_i915_private *dev_priv,
1921 enum plane plane, enum i915_pipe pipe)
1926 reg = DSPCNTR(plane);
1927 val = I915_READ(reg);
1928 if ((val & DISPLAY_PLANE_ENABLE) == 0)
1931 I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
1932 intel_flush_display_plane(dev_priv, plane);
1933 intel_wait_for_vblank(dev_priv->dev, pipe);
1937 intel_pin_and_fence_fb_obj(struct drm_device *dev,
1938 struct drm_i915_gem_object *obj,
1939 struct intel_ring_buffer *pipelined)
1941 struct drm_i915_private *dev_priv = dev->dev_private;
1945 switch (obj->tiling_mode) {
1946 case I915_TILING_NONE:
1947 if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
1948 alignment = 128 * 1024;
1949 else if (INTEL_INFO(dev)->gen >= 4)
1950 alignment = 4 * 1024;
1952 alignment = 64 * 1024;
1955 /* pin() will align the object as required by fence */
1959 /* FIXME: Is this true? */
1960 DRM_ERROR("Y tiled not allowed for scan out buffers\n");
1966 dev_priv->mm.interruptible = false;
1967 ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
1969 goto err_interruptible;
1971 /* Install a fence for tiled scan-out. Pre-i965 always needs a
1972 * fence, whereas 965+ only requires a fence if using
1973 * framebuffer compression. For simplicity, we always install
1974 * a fence as the cost is not that onerous.
1976 ret = i915_gem_object_get_fence(obj);
1980 i915_gem_object_pin_fence(obj);
1982 dev_priv->mm.interruptible = true;
1986 i915_gem_object_unpin(obj);
1988 dev_priv->mm.interruptible = true;
1992 void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
1994 i915_gem_object_unpin_fence(obj);
1995 i915_gem_object_unpin(obj);
1998 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
1999 * is assumed to be a power-of-two. */
2000 unsigned long intel_gen4_compute_page_offset(int *x, int *y,
2001 unsigned int tiling_mode,
2005 if (tiling_mode != I915_TILING_NONE) {
2006 unsigned int tile_rows, tiles;
2011 tiles = *x / (512/cpp);
2014 return tile_rows * pitch * 8 + tiles * 4096;
2016 unsigned int offset;
2018 offset = *y * pitch + *x * cpp;
2020 *x = (offset & 4095) / cpp;
2021 return offset & -4096;
2025 static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
2028 struct drm_device *dev = crtc->dev;
2029 struct drm_i915_private *dev_priv = dev->dev_private;
2030 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2031 struct intel_framebuffer *intel_fb;
2032 struct drm_i915_gem_object *obj;
2033 int plane = intel_crtc->plane;
2034 unsigned long linear_offset;
2043 DRM_ERROR("Can't update plane %d in SAREA\n", plane);
2047 intel_fb = to_intel_framebuffer(fb);
2048 obj = intel_fb->obj;
2050 reg = DSPCNTR(plane);
2051 dspcntr = I915_READ(reg);
2052 /* Mask out pixel format bits in case we change it */
2053 dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
2054 switch (fb->pixel_format) {
2056 dspcntr |= DISPPLANE_8BPP;
2058 case DRM_FORMAT_XRGB1555:
2059 case DRM_FORMAT_ARGB1555:
2060 dspcntr |= DISPPLANE_BGRX555;
2062 case DRM_FORMAT_RGB565:
2063 dspcntr |= DISPPLANE_BGRX565;
2065 case DRM_FORMAT_XRGB8888:
2066 case DRM_FORMAT_ARGB8888:
2067 dspcntr |= DISPPLANE_BGRX888;
2069 case DRM_FORMAT_XBGR8888:
2070 case DRM_FORMAT_ABGR8888:
2071 dspcntr |= DISPPLANE_RGBX888;
2073 case DRM_FORMAT_XRGB2101010:
2074 case DRM_FORMAT_ARGB2101010:
2075 dspcntr |= DISPPLANE_BGRX101010;
2077 case DRM_FORMAT_XBGR2101010:
2078 case DRM_FORMAT_ABGR2101010:
2079 dspcntr |= DISPPLANE_RGBX101010;
2082 DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
2086 if (INTEL_INFO(dev)->gen >= 4) {
2087 if (obj->tiling_mode != I915_TILING_NONE)
2088 dspcntr |= DISPPLANE_TILED;
2090 dspcntr &= ~DISPPLANE_TILED;
2093 I915_WRITE(reg, dspcntr);
2095 linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
2097 if (INTEL_INFO(dev)->gen >= 4) {
2098 intel_crtc->dspaddr_offset =
2099 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
2100 fb->bits_per_pixel / 8,
2102 linear_offset -= intel_crtc->dspaddr_offset;
2104 intel_crtc->dspaddr_offset = linear_offset;
2107 DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
2108 obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
2109 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
2110 if (INTEL_INFO(dev)->gen >= 4) {
2111 I915_MODIFY_DISPBASE(DSPSURF(plane),
2112 obj->gtt_offset + intel_crtc->dspaddr_offset);
2113 I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
2114 I915_WRITE(DSPLINOFF(plane), linear_offset);
2116 I915_WRITE(DSPADDR(plane), obj->gtt_offset + linear_offset);
2122 static int ironlake_update_plane(struct drm_crtc *crtc,
2123 struct drm_framebuffer *fb, int x, int y)
2125 struct drm_device *dev = crtc->dev;
2126 struct drm_i915_private *dev_priv = dev->dev_private;
2127 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2128 struct intel_framebuffer *intel_fb;
2129 struct drm_i915_gem_object *obj;
2130 int plane = intel_crtc->plane;
2131 unsigned long linear_offset;
2141 DRM_ERROR("Can't update plane %d in SAREA\n", plane);
2145 intel_fb = to_intel_framebuffer(fb);
2146 obj = intel_fb->obj;
2148 reg = DSPCNTR(plane);
2149 dspcntr = I915_READ(reg);
2150 /* Mask out pixel format bits in case we change it */
2151 dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
2152 switch (fb->pixel_format) {
2154 dspcntr |= DISPPLANE_8BPP;
2156 case DRM_FORMAT_RGB565:
2157 dspcntr |= DISPPLANE_BGRX565;
2159 case DRM_FORMAT_XRGB8888:
2160 case DRM_FORMAT_ARGB8888:
2161 dspcntr |= DISPPLANE_BGRX888;
2163 case DRM_FORMAT_XBGR8888:
2164 case DRM_FORMAT_ABGR8888:
2165 dspcntr |= DISPPLANE_RGBX888;
2167 case DRM_FORMAT_XRGB2101010:
2168 case DRM_FORMAT_ARGB2101010:
2169 dspcntr |= DISPPLANE_BGRX101010;
2171 case DRM_FORMAT_XBGR2101010:
2172 case DRM_FORMAT_ABGR2101010:
2173 dspcntr |= DISPPLANE_RGBX101010;
2176 DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
2180 if (obj->tiling_mode != I915_TILING_NONE)
2181 dspcntr |= DISPPLANE_TILED;
2183 dspcntr &= ~DISPPLANE_TILED;
2186 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
2188 I915_WRITE(reg, dspcntr);
2190 linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
2191 intel_crtc->dspaddr_offset =
2192 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
2193 fb->bits_per_pixel / 8,
2195 linear_offset -= intel_crtc->dspaddr_offset;
2197 DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
2198 obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
2199 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
2200 I915_MODIFY_DISPBASE(DSPSURF(plane),
2201 obj->gtt_offset + intel_crtc->dspaddr_offset);
2202 if (IS_HASWELL(dev)) {
2203 I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
2205 I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
2206 I915_WRITE(DSPLINOFF(plane), linear_offset);
2213 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2215 intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
2216 int x, int y, enum mode_set_atomic state)
2218 struct drm_device *dev = crtc->dev;
2219 struct drm_i915_private *dev_priv = dev->dev_private;
2221 if (dev_priv->display.disable_fbc)
2222 dev_priv->display.disable_fbc(dev);
2223 intel_increase_pllclock(crtc);
2225 return dev_priv->display.update_plane(crtc, fb, x, y);
2229 intel_finish_fb(struct drm_framebuffer *old_fb)
2231 struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
2232 struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
2233 bool was_interruptible = dev_priv->mm.interruptible;
2236 /* Big Hammer, we also need to ensure that any pending
2237 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2238 * current scanout is retired before unpinning the old
2241 * This should only fail upon a hung GPU, in which case we
2242 * can safely continue.
2244 dev_priv->mm.interruptible = false;
2245 ret = i915_gem_object_finish_gpu(obj);
2246 dev_priv->mm.interruptible = was_interruptible;
2251 static void intel_crtc_update_sarea_pos(struct drm_crtc *crtc, int x, int y)
2253 struct drm_device *dev = crtc->dev;
2255 struct drm_i915_master_private *master_priv;
2257 drm_i915_private_t *dev_priv = dev->dev_private;
2259 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2262 if (!dev->primary->master)
2265 master_priv = dev->primary->master->driver_priv;
2266 if (!master_priv->sarea_priv)
2269 if (!dev_priv->sarea_priv)
2273 switch (intel_crtc->pipe) {
2276 master_priv->sarea_priv->pipeA_x = x;
2277 master_priv->sarea_priv->pipeA_y = y;
2279 dev_priv->sarea_priv->planeA_x = x;
2280 dev_priv->sarea_priv->planeA_y = y;
2285 master_priv->sarea_priv->pipeB_x = x;
2286 master_priv->sarea_priv->pipeB_y = y;
2288 dev_priv->sarea_priv->planeB_x = x;
2289 dev_priv->sarea_priv->planeB_y = y;
2298 intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
2299 struct drm_framebuffer *fb)
2301 struct drm_device *dev = crtc->dev;
2302 struct drm_i915_private *dev_priv = dev->dev_private;
2303 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2304 struct drm_framebuffer *old_fb;
2309 DRM_ERROR("No FB bound\n");
2313 if(intel_crtc->plane > dev_priv->num_pipe) {
2314 DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
2316 dev_priv->num_pipe);
2320 mutex_lock(&dev->struct_mutex);
2321 ret = intel_pin_and_fence_fb_obj(dev,
2322 to_intel_framebuffer(fb)->obj,
2325 mutex_unlock(&dev->struct_mutex);
2326 DRM_ERROR("pin & fence failed\n");
2331 intel_finish_fb(crtc->fb);
2333 ret = dev_priv->display.update_plane(crtc, fb, x, y);
2335 intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj);
2336 mutex_unlock(&dev->struct_mutex);
2337 DRM_ERROR("failed to update base address\n");
2347 intel_wait_for_vblank(dev, intel_crtc->pipe);
2348 intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
2351 intel_update_fbc(dev);
2352 mutex_unlock(&dev->struct_mutex);
2354 intel_crtc_update_sarea_pos(crtc, x, y);
2359 static void intel_fdi_normal_train(struct drm_crtc *crtc)
2361 struct drm_device *dev = crtc->dev;
2362 struct drm_i915_private *dev_priv = dev->dev_private;
2363 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2364 int pipe = intel_crtc->pipe;
2367 /* enable normal train */
2368 reg = FDI_TX_CTL(pipe);
2369 temp = I915_READ(reg);
2370 if (IS_IVYBRIDGE(dev)) {
2371 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
2372 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
2374 temp &= ~FDI_LINK_TRAIN_NONE;
2375 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
2377 I915_WRITE(reg, temp);
2379 reg = FDI_RX_CTL(pipe);
2380 temp = I915_READ(reg);
2381 if (HAS_PCH_CPT(dev)) {
2382 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2383 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
2385 temp &= ~FDI_LINK_TRAIN_NONE;
2386 temp |= FDI_LINK_TRAIN_NONE;
2388 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
2390 /* wait one idle pattern time */
2394 /* IVB wants error correction enabled */
2395 if (IS_IVYBRIDGE(dev))
2396 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
2397 FDI_FE_ERRC_ENABLE);
2400 static void ivb_modeset_global_resources(struct drm_device *dev)
2402 struct drm_i915_private *dev_priv = dev->dev_private;
2403 struct intel_crtc *pipe_B_crtc =
2404 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
2405 struct intel_crtc *pipe_C_crtc =
2406 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
2409 /* When everything is off disable fdi C so that we could enable fdi B
2410 * with all lanes. XXX: This misses the case where a pipe is not using
2411 * any pch resources and so doesn't need any fdi lanes. */
2412 if (!pipe_B_crtc->base.enabled && !pipe_C_crtc->base.enabled) {
2413 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
2414 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
2416 temp = I915_READ(SOUTH_CHICKEN1);
2417 temp &= ~FDI_BC_BIFURCATION_SELECT;
2418 DRM_DEBUG_KMS("disabling fdi C rx\n");
2419 I915_WRITE(SOUTH_CHICKEN1, temp);
2423 /* The FDI link training functions for ILK/Ibexpeak. */
2424 static void ironlake_fdi_link_train(struct drm_crtc *crtc)
2426 struct drm_device *dev = crtc->dev;
2427 struct drm_i915_private *dev_priv = dev->dev_private;
2428 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2429 int pipe = intel_crtc->pipe;
2430 int plane = intel_crtc->plane;
2431 u32 reg, temp, tries;
2433 /* FDI needs bits from pipe & plane first */
2434 assert_pipe_enabled(dev_priv, pipe);
2435 assert_plane_enabled(dev_priv, plane);
2437 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2439 reg = FDI_RX_IMR(pipe);
2440 temp = I915_READ(reg);
2441 temp &= ~FDI_RX_SYMBOL_LOCK;
2442 temp &= ~FDI_RX_BIT_LOCK;
2443 I915_WRITE(reg, temp);
2447 /* enable CPU FDI TX and PCH FDI RX */
2448 reg = FDI_TX_CTL(pipe);
2449 temp = I915_READ(reg);
2451 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2452 temp &= ~FDI_LINK_TRAIN_NONE;
2453 temp |= FDI_LINK_TRAIN_PATTERN_1;
2454 I915_WRITE(reg, temp | FDI_TX_ENABLE);
2456 reg = FDI_RX_CTL(pipe);
2457 temp = I915_READ(reg);
2458 temp &= ~FDI_LINK_TRAIN_NONE;
2459 temp |= FDI_LINK_TRAIN_PATTERN_1;
2460 I915_WRITE(reg, temp | FDI_RX_ENABLE);
2465 /* Ironlake workaround, enable clock pointer after FDI enable*/
2466 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
2467 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
2468 FDI_RX_PHASE_SYNC_POINTER_EN);
2470 reg = FDI_RX_IIR(pipe);
2471 for (tries = 0; tries < 5; tries++) {
2472 temp = I915_READ(reg);
2473 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2475 if ((temp & FDI_RX_BIT_LOCK)) {
2476 DRM_DEBUG_KMS("FDI train 1 done.\n");
2477 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2482 DRM_ERROR("FDI train 1 fail!\n");
2485 reg = FDI_TX_CTL(pipe);
2486 temp = I915_READ(reg);
2487 temp &= ~FDI_LINK_TRAIN_NONE;
2488 temp |= FDI_LINK_TRAIN_PATTERN_2;
2489 I915_WRITE(reg, temp);
2491 reg = FDI_RX_CTL(pipe);
2492 temp = I915_READ(reg);
2493 temp &= ~FDI_LINK_TRAIN_NONE;
2494 temp |= FDI_LINK_TRAIN_PATTERN_2;
2495 I915_WRITE(reg, temp);
2500 reg = FDI_RX_IIR(pipe);
2501 for (tries = 0; tries < 5; tries++) {
2502 temp = I915_READ(reg);
2503 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2505 if (temp & FDI_RX_SYMBOL_LOCK) {
2506 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2507 DRM_DEBUG_KMS("FDI train 2 done.\n");
2512 DRM_ERROR("FDI train 2 fail!\n");
2514 DRM_DEBUG_KMS("FDI train done\n");
2518 static const int snb_b_fdi_train_param[] = {
2519 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
2520 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
2521 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
2522 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
2525 /* The FDI link training functions for SNB/Cougarpoint. */
2526 static void gen6_fdi_link_train(struct drm_crtc *crtc)
2528 struct drm_device *dev = crtc->dev;
2529 struct drm_i915_private *dev_priv = dev->dev_private;
2530 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2531 int pipe = intel_crtc->pipe;
2532 u32 reg, temp, i, retry;
2534 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2536 reg = FDI_RX_IMR(pipe);
2537 temp = I915_READ(reg);
2538 temp &= ~FDI_RX_SYMBOL_LOCK;
2539 temp &= ~FDI_RX_BIT_LOCK;
2540 I915_WRITE(reg, temp);
2545 /* enable CPU FDI TX and PCH FDI RX */
2546 reg = FDI_TX_CTL(pipe);
2547 temp = I915_READ(reg);
2549 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2550 temp &= ~FDI_LINK_TRAIN_NONE;
2551 temp |= FDI_LINK_TRAIN_PATTERN_1;
2552 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2554 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2555 I915_WRITE(reg, temp | FDI_TX_ENABLE);
2557 I915_WRITE(FDI_RX_MISC(pipe),
2558 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
2560 reg = FDI_RX_CTL(pipe);
2561 temp = I915_READ(reg);
2562 if (HAS_PCH_CPT(dev)) {
2563 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2564 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
2566 temp &= ~FDI_LINK_TRAIN_NONE;
2567 temp |= FDI_LINK_TRAIN_PATTERN_1;
2569 I915_WRITE(reg, temp | FDI_RX_ENABLE);
2574 for (i = 0; i < 4; i++) {
2575 reg = FDI_TX_CTL(pipe);
2576 temp = I915_READ(reg);
2577 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2578 temp |= snb_b_fdi_train_param[i];
2579 I915_WRITE(reg, temp);
2584 for (retry = 0; retry < 5; retry++) {
2585 reg = FDI_RX_IIR(pipe);
2586 temp = I915_READ(reg);
2587 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2588 if (temp & FDI_RX_BIT_LOCK) {
2589 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2590 DRM_DEBUG_KMS("FDI train 1 done.\n");
2599 DRM_ERROR("FDI train 1 fail!\n");
2602 reg = FDI_TX_CTL(pipe);
2603 temp = I915_READ(reg);
2604 temp &= ~FDI_LINK_TRAIN_NONE;
2605 temp |= FDI_LINK_TRAIN_PATTERN_2;
2607 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2609 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2611 I915_WRITE(reg, temp);
2613 reg = FDI_RX_CTL(pipe);
2614 temp = I915_READ(reg);
2615 if (HAS_PCH_CPT(dev)) {
2616 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2617 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
2619 temp &= ~FDI_LINK_TRAIN_NONE;
2620 temp |= FDI_LINK_TRAIN_PATTERN_2;
2622 I915_WRITE(reg, temp);
2627 for (i = 0; i < 4; i++) {
2628 reg = FDI_TX_CTL(pipe);
2629 temp = I915_READ(reg);
2630 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2631 temp |= snb_b_fdi_train_param[i];
2632 I915_WRITE(reg, temp);
2637 for (retry = 0; retry < 5; retry++) {
2638 reg = FDI_RX_IIR(pipe);
2639 temp = I915_READ(reg);
2640 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2641 if (temp & FDI_RX_SYMBOL_LOCK) {
2642 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2643 DRM_DEBUG_KMS("FDI train 2 done.\n");
2652 DRM_ERROR("FDI train 2 fail!\n");
2654 DRM_DEBUG_KMS("FDI train done.\n");
2657 /* Manual link training for Ivy Bridge A0 parts */
2658 static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
2660 struct drm_device *dev = crtc->dev;
2661 struct drm_i915_private *dev_priv = dev->dev_private;
2662 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2663 int pipe = intel_crtc->pipe;
2666 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2668 reg = FDI_RX_IMR(pipe);
2669 temp = I915_READ(reg);
2670 temp &= ~FDI_RX_SYMBOL_LOCK;
2671 temp &= ~FDI_RX_BIT_LOCK;
2672 I915_WRITE(reg, temp);
2677 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
2678 I915_READ(FDI_RX_IIR(pipe)));
2680 /* enable CPU FDI TX and PCH FDI RX */
2681 reg = FDI_TX_CTL(pipe);
2682 temp = I915_READ(reg);
2684 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2685 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
2686 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
2687 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2688 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2689 temp |= FDI_COMPOSITE_SYNC;
2690 I915_WRITE(reg, temp | FDI_TX_ENABLE);
2692 I915_WRITE(FDI_RX_MISC(pipe),
2693 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
2695 reg = FDI_RX_CTL(pipe);
2696 temp = I915_READ(reg);
2697 temp &= ~FDI_LINK_TRAIN_AUTO;
2698 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2699 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
2700 temp |= FDI_COMPOSITE_SYNC;
2701 I915_WRITE(reg, temp | FDI_RX_ENABLE);
2706 for (i = 0; i < 4; i++) {
2707 reg = FDI_TX_CTL(pipe);
2708 temp = I915_READ(reg);
2709 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2710 temp |= snb_b_fdi_train_param[i];
2711 I915_WRITE(reg, temp);
2716 reg = FDI_RX_IIR(pipe);
2717 temp = I915_READ(reg);
2718 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2720 if (temp & FDI_RX_BIT_LOCK ||
2721 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
2722 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2723 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i);
2728 DRM_ERROR("FDI train 1 fail!\n");
2731 reg = FDI_TX_CTL(pipe);
2732 temp = I915_READ(reg);
2733 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
2734 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
2735 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2736 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2737 I915_WRITE(reg, temp);
2739 reg = FDI_RX_CTL(pipe);
2740 temp = I915_READ(reg);
2741 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2742 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
2743 I915_WRITE(reg, temp);
2748 for (i = 0; i < 4; i++) {
2749 reg = FDI_TX_CTL(pipe);
2750 temp = I915_READ(reg);
2751 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2752 temp |= snb_b_fdi_train_param[i];
2753 I915_WRITE(reg, temp);
2758 reg = FDI_RX_IIR(pipe);
2759 temp = I915_READ(reg);
2760 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2762 if (temp & FDI_RX_SYMBOL_LOCK) {
2763 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2764 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i);
2769 DRM_ERROR("FDI train 2 fail!\n");
2771 DRM_DEBUG_KMS("FDI train done.\n");
2774 static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
2776 struct drm_device *dev = intel_crtc->base.dev;
2777 struct drm_i915_private *dev_priv = dev->dev_private;
2778 int pipe = intel_crtc->pipe;
2782 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
2783 reg = FDI_RX_CTL(pipe);
2784 temp = I915_READ(reg);
2785 temp &= ~((0x7 << 19) | (0x7 << 16));
2786 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2787 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
2788 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
2793 /* Switch from Rawclk to PCDclk */
2794 temp = I915_READ(reg);
2795 I915_WRITE(reg, temp | FDI_PCDCLK);
2800 /* Enable CPU FDI TX PLL, always on for Ironlake */
2801 reg = FDI_TX_CTL(pipe);
2802 temp = I915_READ(reg);
2803 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
2804 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
2811 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
2813 struct drm_device *dev = intel_crtc->base.dev;
2814 struct drm_i915_private *dev_priv = dev->dev_private;
2815 int pipe = intel_crtc->pipe;
2818 /* Switch from PCDclk to Rawclk */
2819 reg = FDI_RX_CTL(pipe);
2820 temp = I915_READ(reg);
2821 I915_WRITE(reg, temp & ~FDI_PCDCLK);
2823 /* Disable CPU FDI TX PLL */
2824 reg = FDI_TX_CTL(pipe);
2825 temp = I915_READ(reg);
2826 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
2831 reg = FDI_RX_CTL(pipe);
2832 temp = I915_READ(reg);
2833 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
2835 /* Wait for the clocks to turn off. */
2840 static void ironlake_fdi_disable(struct drm_crtc *crtc)
2842 struct drm_device *dev = crtc->dev;
2843 struct drm_i915_private *dev_priv = dev->dev_private;
2844 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2845 int pipe = intel_crtc->pipe;
2848 /* disable CPU FDI tx and PCH FDI rx */
2849 reg = FDI_TX_CTL(pipe);
2850 temp = I915_READ(reg);
2851 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
2854 reg = FDI_RX_CTL(pipe);
2855 temp = I915_READ(reg);
2856 temp &= ~(0x7 << 16);
2857 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
2858 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
2863 /* Ironlake workaround, disable clock pointer after downing FDI */
2864 if (HAS_PCH_IBX(dev)) {
2865 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
2868 /* still set train pattern 1 */
2869 reg = FDI_TX_CTL(pipe);
2870 temp = I915_READ(reg);
2871 temp &= ~FDI_LINK_TRAIN_NONE;
2872 temp |= FDI_LINK_TRAIN_PATTERN_1;
2873 I915_WRITE(reg, temp);
2875 reg = FDI_RX_CTL(pipe);
2876 temp = I915_READ(reg);
2877 if (HAS_PCH_CPT(dev)) {
2878 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2879 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
2881 temp &= ~FDI_LINK_TRAIN_NONE;
2882 temp |= FDI_LINK_TRAIN_PATTERN_1;
2884 /* BPC in FDI rx is consistent with that in PIPECONF */
2885 temp &= ~(0x07 << 16);
2886 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
2887 I915_WRITE(reg, temp);
2893 static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
2895 struct drm_device *dev = crtc->dev;
2896 struct drm_i915_private *dev_priv = dev->dev_private;
2897 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2900 if (i915_reset_in_progress(&dev_priv->gpu_error) ||
2901 intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
2904 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
2905 pending = to_intel_crtc(crtc)->unpin_work != NULL;
2906 lockmgr(&dev->event_lock, LK_RELEASE);
2911 static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
2913 struct drm_device *dev = crtc->dev;
2914 struct drm_i915_private *dev_priv = dev->dev_private;
2916 if (crtc->fb == NULL)
2919 WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
2921 wait_event(dev_priv->pending_flip_queue,
2922 !intel_crtc_has_pending_flip(crtc));
2924 mutex_lock(&dev->struct_mutex);
2925 intel_finish_fb(crtc->fb);
2926 mutex_unlock(&dev->struct_mutex);
2929 static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc)
2931 struct drm_device *dev = crtc->dev;
2932 struct intel_encoder *intel_encoder;
2935 * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
2936 * must be driven by its own crtc; no sharing is possible.
2938 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
2939 switch (intel_encoder->type) {
2940 case INTEL_OUTPUT_EDP:
2941 if (!intel_encoder_is_pch_edp(&intel_encoder->base))
2950 static bool haswell_crtc_driving_pch(struct drm_crtc *crtc)
2952 return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG);
2955 /* Program iCLKIP clock to the desired frequency */
2956 static void lpt_program_iclkip(struct drm_crtc *crtc)
2958 struct drm_device *dev = crtc->dev;
2959 struct drm_i915_private *dev_priv = dev->dev_private;
2960 u32 divsel, phaseinc, auxdiv, phasedir = 0;
2963 mutex_lock(&dev_priv->dpio_lock);
2965 /* It is necessary to ungate the pixclk gate prior to programming
2966 * the divisors, and gate it back when it is done.
2968 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
2970 /* Disable SSCCTL */
2971 intel_sbi_write(dev_priv, SBI_SSCCTL6,
2972 intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
2976 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
2977 if (crtc->mode.clock == 20000) {
2982 /* The iCLK virtual clock root frequency is in MHz,
2983 * but the crtc->mode.clock in in KHz. To get the divisors,
2984 * it is necessary to divide one by another, so we
2985 * convert the virtual clock precision to KHz here for higher
2988 u32 iclk_virtual_root_freq = 172800 * 1000;
2989 u32 iclk_pi_range = 64;
2990 u32 desired_divisor, msb_divisor_value, pi_value;
2992 desired_divisor = (iclk_virtual_root_freq / crtc->mode.clock);
2993 msb_divisor_value = desired_divisor / iclk_pi_range;
2994 pi_value = desired_divisor % iclk_pi_range;
2997 divsel = msb_divisor_value - 2;
2998 phaseinc = pi_value;
3001 /* This should not happen with any sane values */
3002 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
3003 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
3004 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
3005 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
3007 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3014 /* Program SSCDIVINTPHASE6 */
3015 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
3016 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
3017 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
3018 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
3019 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
3020 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
3021 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
3022 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
3024 /* Program SSCAUXDIV */
3025 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
3026 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3027 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
3028 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
3030 /* Enable modulator and associated divider */
3031 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
3032 temp &= ~SBI_SSCCTL_DISABLE;
3033 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
3035 /* Wait for initialization time */
3038 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
3040 mutex_unlock(&dev_priv->dpio_lock);
3044 * Enable PCH resources required for PCH ports:
3046 * - FDI training & RX/TX
3047 * - update transcoder timings
3048 * - DP transcoding bits
3051 static void ironlake_pch_enable(struct drm_crtc *crtc)
3053 struct drm_device *dev = crtc->dev;
3054 struct drm_i915_private *dev_priv = dev->dev_private;
3055 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3056 int pipe = intel_crtc->pipe;
3059 assert_transcoder_disabled(dev_priv, pipe);
3061 /* Write the TU size bits before fdi link training, so that error
3062 * detection works. */
3063 I915_WRITE(FDI_RX_TUSIZE1(pipe),
3064 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
3066 /* For PCH output, training FDI link */
3067 dev_priv->display.fdi_link_train(crtc);
3069 /* XXX: pch pll's can be enabled any time before we enable the PCH
3070 * transcoder, and we actually should do this to not upset any PCH
3071 * transcoder that already use the clock when we share it.
3073 * Note that enable_pch_pll tries to do the right thing, but get_pch_pll
3074 * unconditionally resets the pll - we need that to have the right LVDS
3075 * enable sequence. */
3076 ironlake_enable_pch_pll(intel_crtc);
3078 if (HAS_PCH_CPT(dev)) {
3081 temp = I915_READ(PCH_DPLL_SEL);
3085 temp |= TRANSA_DPLL_ENABLE;
3086 sel = TRANSA_DPLLB_SEL;
3089 temp |= TRANSB_DPLL_ENABLE;
3090 sel = TRANSB_DPLLB_SEL;
3093 temp |= TRANSC_DPLL_ENABLE;
3094 sel = TRANSC_DPLLB_SEL;
3097 if (intel_crtc->pch_pll->pll_reg == _PCH_DPLL_B)
3101 I915_WRITE(PCH_DPLL_SEL, temp);
3104 /* set transcoder timing, panel must allow it */
3105 assert_panel_unlocked(dev_priv, pipe);
3106 I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
3107 I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
3108 I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
3110 I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
3111 I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
3112 I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
3113 I915_WRITE(TRANS_VSYNCSHIFT(pipe), I915_READ(VSYNCSHIFT(pipe)));
3115 intel_fdi_normal_train(crtc);
3117 /* For PCH DP, enable TRANS_DP_CTL */
3118 if (HAS_PCH_CPT(dev) &&
3119 (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
3120 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
3121 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
3122 reg = TRANS_DP_CTL(pipe);
3123 temp = I915_READ(reg);
3124 temp &= ~(TRANS_DP_PORT_SEL_MASK |
3125 TRANS_DP_SYNC_MASK |
3127 temp |= (TRANS_DP_OUTPUT_ENABLE |
3128 TRANS_DP_ENH_FRAMING);
3129 temp |= bpc << 9; /* same format but at 11:9 */
3131 if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
3132 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
3133 if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
3134 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
3136 switch (intel_trans_dp_port_sel(crtc)) {
3138 temp |= TRANS_DP_PORT_SEL_B;
3141 temp |= TRANS_DP_PORT_SEL_C;
3144 temp |= TRANS_DP_PORT_SEL_D;
3150 I915_WRITE(reg, temp);
3153 ironlake_enable_pch_transcoder(dev_priv, pipe);
3156 static void lpt_pch_enable(struct drm_crtc *crtc)
3158 struct drm_device *dev = crtc->dev;
3159 struct drm_i915_private *dev_priv = dev->dev_private;
3160 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3161 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
3163 assert_transcoder_disabled(dev_priv, TRANSCODER_A);
3165 lpt_program_iclkip(crtc);
3167 /* Set transcoder timing. */
3168 I915_WRITE(_TRANS_HTOTAL_A, I915_READ(HTOTAL(cpu_transcoder)));
3169 I915_WRITE(_TRANS_HBLANK_A, I915_READ(HBLANK(cpu_transcoder)));
3170 I915_WRITE(_TRANS_HSYNC_A, I915_READ(HSYNC(cpu_transcoder)));
3172 I915_WRITE(_TRANS_VTOTAL_A, I915_READ(VTOTAL(cpu_transcoder)));
3173 I915_WRITE(_TRANS_VBLANK_A, I915_READ(VBLANK(cpu_transcoder)));
3174 I915_WRITE(_TRANS_VSYNC_A, I915_READ(VSYNC(cpu_transcoder)));
3175 I915_WRITE(_TRANS_VSYNCSHIFT_A, I915_READ(VSYNCSHIFT(cpu_transcoder)));
3177 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
3180 static void intel_put_pch_pll(struct intel_crtc *intel_crtc)
3182 struct intel_pch_pll *pll = intel_crtc->pch_pll;
3187 if (pll->refcount == 0) {
3188 WARN(1, "bad PCH PLL refcount\n");
3193 intel_crtc->pch_pll = NULL;
3196 static struct intel_pch_pll *intel_get_pch_pll(struct intel_crtc *intel_crtc, u32 dpll, u32 fp)
3198 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
3199 struct intel_pch_pll *pll;
3202 pll = intel_crtc->pch_pll;
3204 DRM_DEBUG_KMS("CRTC:%d reusing existing PCH PLL %x\n",
3205 intel_crtc->base.base.id, pll->pll_reg);
3209 if (HAS_PCH_IBX(dev_priv->dev)) {
3210 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3211 i = intel_crtc->pipe;
3212 pll = &dev_priv->pch_plls[i];
3214 DRM_DEBUG_KMS("CRTC:%d using pre-allocated PCH PLL %x\n",
3215 intel_crtc->base.base.id, pll->pll_reg);
3220 for (i = 0; i < dev_priv->num_pch_pll; i++) {
3221 pll = &dev_priv->pch_plls[i];
3223 /* Only want to check enabled timings first */
3224 if (pll->refcount == 0)
3227 if (dpll == (I915_READ(pll->pll_reg) & 0x7fffffff) &&
3228 fp == I915_READ(pll->fp0_reg)) {
3229 DRM_DEBUG_KMS("CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n",
3230 intel_crtc->base.base.id,
3231 pll->pll_reg, pll->refcount, pll->active);
3237 /* Ok no matching timings, maybe there's a free one? */
3238 for (i = 0; i < dev_priv->num_pch_pll; i++) {
3239 pll = &dev_priv->pch_plls[i];
3240 if (pll->refcount == 0) {
3241 DRM_DEBUG_KMS("CRTC:%d allocated PCH PLL %x\n",
3242 intel_crtc->base.base.id, pll->pll_reg);
3250 intel_crtc->pch_pll = pll;
3252 DRM_DEBUG_DRIVER("using pll %d for pipe %d\n", i, intel_crtc->pipe);
3253 prepare: /* separate function? */
3254 DRM_DEBUG_DRIVER("switching PLL %x off\n", pll->pll_reg);
3256 /* Wait for the clocks to stabilize before rewriting the regs */
3257 I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
3258 POSTING_READ(pll->pll_reg);
3261 I915_WRITE(pll->fp0_reg, fp);
3262 I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
3267 void intel_cpt_verify_modeset(struct drm_device *dev, int pipe)
3269 struct drm_i915_private *dev_priv = dev->dev_private;
3270 int dslreg = PIPEDSL(pipe);
3273 temp = I915_READ(dslreg);
3275 if (wait_for(I915_READ(dslreg) != temp, 5)) {
3276 if (wait_for(I915_READ(dslreg) != temp, 5))
3277 DRM_ERROR("mode set failed: pipe %d stuck\n", pipe);
3281 static void ironlake_crtc_enable(struct drm_crtc *crtc)
3283 struct drm_device *dev = crtc->dev;
3284 struct drm_i915_private *dev_priv = dev->dev_private;
3285 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3286 struct intel_encoder *encoder;
3287 int pipe = intel_crtc->pipe;
3288 int plane = intel_crtc->plane;
3292 WARN_ON(!crtc->enabled);
3294 if (intel_crtc->active)
3297 intel_crtc->active = true;
3298 intel_update_watermarks(dev);
3300 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
3301 temp = I915_READ(PCH_LVDS);
3302 if ((temp & LVDS_PORT_EN) == 0)
3303 I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
3306 is_pch_port = ironlake_crtc_driving_pch(crtc);
3309 /* Note: FDI PLL enabling _must_ be done before we enable the
3310 * cpu pipes, hence this is separate from all the other fdi/pch
3312 ironlake_fdi_pll_enable(intel_crtc);
3314 assert_fdi_tx_disabled(dev_priv, pipe);
3315 assert_fdi_rx_disabled(dev_priv, pipe);
3318 for_each_encoder_on_crtc(dev, crtc, encoder)
3319 if (encoder->pre_enable)
3320 encoder->pre_enable(encoder);
3322 /* Enable panel fitting for LVDS */
3323 if (dev_priv->pch_pf_size &&
3324 (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
3325 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
3326 /* Force use of hard-coded filter coefficients
3327 * as some pre-programmed values are broken,
3330 if (IS_IVYBRIDGE(dev))
3331 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
3332 PF_PIPE_SEL_IVB(pipe));
3334 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
3335 I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
3336 I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
3340 * On ILK+ LUT must be loaded before the pipe is running but with
3343 intel_crtc_load_lut(crtc);
3345 intel_enable_pipe(dev_priv, pipe, is_pch_port);
3346 intel_enable_plane(dev_priv, plane, pipe);
3349 ironlake_pch_enable(crtc);
3351 mutex_lock(&dev->struct_mutex);
3352 intel_update_fbc(dev);
3353 mutex_unlock(&dev->struct_mutex);
3355 intel_crtc_update_cursor(crtc, true);
3357 for_each_encoder_on_crtc(dev, crtc, encoder)
3358 encoder->enable(encoder);
3360 if (HAS_PCH_CPT(dev))
3361 intel_cpt_verify_modeset(dev, intel_crtc->pipe);
3364 * There seems to be a race in PCH platform hw (at least on some
3365 * outputs) where an enabled pipe still completes any pageflip right
3366 * away (as if the pipe is off) instead of waiting for vblank. As soon
3367 * as the first vblank happend, everything works as expected. Hence just
3368 * wait for one vblank before returning to avoid strange things
3371 intel_wait_for_vblank(dev, intel_crtc->pipe);
3374 static void haswell_crtc_enable(struct drm_crtc *crtc)
3376 struct drm_device *dev = crtc->dev;
3377 struct drm_i915_private *dev_priv = dev->dev_private;
3378 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3379 struct intel_encoder *encoder;
3380 int pipe = intel_crtc->pipe;
3381 int plane = intel_crtc->plane;
3384 WARN_ON(!crtc->enabled);
3386 if (intel_crtc->active)
3389 intel_crtc->active = true;
3390 intel_update_watermarks(dev);
3392 is_pch_port = haswell_crtc_driving_pch(crtc);
3395 dev_priv->display.fdi_link_train(crtc);
3397 for_each_encoder_on_crtc(dev, crtc, encoder)
3398 if (encoder->pre_enable)
3399 encoder->pre_enable(encoder);
3401 intel_ddi_enable_pipe_clock(intel_crtc);
3403 /* Enable panel fitting for eDP */
3404 if (dev_priv->pch_pf_size &&
3405 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
3406 /* Force use of hard-coded filter coefficients
3407 * as some pre-programmed values are broken,
3410 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
3411 PF_PIPE_SEL_IVB(pipe));
3412 I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
3413 I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
3417 * On ILK+ LUT must be loaded before the pipe is running but with
3420 intel_crtc_load_lut(crtc);
3422 intel_ddi_set_pipe_settings(crtc);
3423 intel_ddi_enable_pipe_func(crtc);
3425 intel_enable_pipe(dev_priv, pipe, is_pch_port);
3426 intel_enable_plane(dev_priv, plane, pipe);
3429 lpt_pch_enable(crtc);
3431 mutex_lock(&dev->struct_mutex);
3432 intel_update_fbc(dev);
3433 mutex_unlock(&dev->struct_mutex);
3435 intel_crtc_update_cursor(crtc, true);
3437 for_each_encoder_on_crtc(dev, crtc, encoder)
3438 encoder->enable(encoder);
3441 * There seems to be a race in PCH platform hw (at least on some
3442 * outputs) where an enabled pipe still completes any pageflip right
3443 * away (as if the pipe is off) instead of waiting for vblank. As soon
3444 * as the first vblank happend, everything works as expected. Hence just
3445 * wait for one vblank before returning to avoid strange things
3448 intel_wait_for_vblank(dev, intel_crtc->pipe);
3451 static void ironlake_crtc_disable(struct drm_crtc *crtc)
3453 struct drm_device *dev = crtc->dev;
3454 struct drm_i915_private *dev_priv = dev->dev_private;
3455 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3456 struct intel_encoder *encoder;
3457 int pipe = intel_crtc->pipe;
3458 int plane = intel_crtc->plane;
3462 if (!intel_crtc->active)
3465 for_each_encoder_on_crtc(dev, crtc, encoder)
3466 encoder->disable(encoder);
3468 intel_crtc_wait_for_pending_flips(crtc);
3469 drm_vblank_off(dev, pipe);
3470 intel_crtc_update_cursor(crtc, false);
3472 intel_disable_plane(dev_priv, plane, pipe);
3474 if (dev_priv->cfb_plane == plane)
3475 intel_disable_fbc(dev);
3477 intel_disable_pipe(dev_priv, pipe);
3480 I915_WRITE(PF_CTL(pipe), 0);
3481 I915_WRITE(PF_WIN_SZ(pipe), 0);
3483 for_each_encoder_on_crtc(dev, crtc, encoder)
3484 if (encoder->post_disable)
3485 encoder->post_disable(encoder);
3487 ironlake_fdi_disable(crtc);
3489 ironlake_disable_pch_transcoder(dev_priv, pipe);
3491 if (HAS_PCH_CPT(dev)) {
3492 /* disable TRANS_DP_CTL */
3493 reg = TRANS_DP_CTL(pipe);
3494 temp = I915_READ(reg);
3495 temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
3496 temp |= TRANS_DP_PORT_SEL_NONE;
3497 I915_WRITE(reg, temp);
3499 /* disable DPLL_SEL */
3500 temp = I915_READ(PCH_DPLL_SEL);
3503 temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL);
3506 temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
3509 /* C shares PLL A or B */
3510 temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL);
3515 I915_WRITE(PCH_DPLL_SEL, temp);
3518 /* disable PCH DPLL */
3519 intel_disable_pch_pll(intel_crtc);
3521 ironlake_fdi_pll_disable(intel_crtc);
3523 intel_crtc->active = false;
3524 intel_update_watermarks(dev);
3526 mutex_lock(&dev->struct_mutex);
3527 intel_update_fbc(dev);
3528 mutex_unlock(&dev->struct_mutex);
3531 static void haswell_crtc_disable(struct drm_crtc *crtc)
3533 struct drm_device *dev = crtc->dev;
3534 struct drm_i915_private *dev_priv = dev->dev_private;
3535 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3536 struct intel_encoder *encoder;
3537 int pipe = intel_crtc->pipe;
3538 int plane = intel_crtc->plane;
3539 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
3542 if (!intel_crtc->active)
3545 is_pch_port = haswell_crtc_driving_pch(crtc);
3547 for_each_encoder_on_crtc(dev, crtc, encoder)
3548 encoder->disable(encoder);
3550 intel_crtc_wait_for_pending_flips(crtc);
3551 drm_vblank_off(dev, pipe);
3552 intel_crtc_update_cursor(crtc, false);
3554 intel_disable_plane(dev_priv, plane, pipe);
3556 if (dev_priv->cfb_plane == plane)
3557 intel_disable_fbc(dev);
3559 intel_disable_pipe(dev_priv, pipe);
3561 intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
3564 I915_WRITE(PF_CTL(pipe), 0);
3565 I915_WRITE(PF_WIN_SZ(pipe), 0);
3567 intel_ddi_disable_pipe_clock(intel_crtc);
3569 for_each_encoder_on_crtc(dev, crtc, encoder)
3570 if (encoder->post_disable)
3571 encoder->post_disable(encoder);
3574 lpt_disable_pch_transcoder(dev_priv);
3575 intel_ddi_fdi_disable(crtc);
3578 intel_crtc->active = false;
3579 intel_update_watermarks(dev);
3581 mutex_lock(&dev->struct_mutex);
3582 intel_update_fbc(dev);
3583 mutex_unlock(&dev->struct_mutex);
3586 static void ironlake_crtc_off(struct drm_crtc *crtc)
3588 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3589 intel_put_pch_pll(intel_crtc);
3592 static void haswell_crtc_off(struct drm_crtc *crtc)
3594 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3596 /* Stop saying we're using TRANSCODER_EDP because some other CRTC might
3597 * start using it. */
3598 intel_crtc->cpu_transcoder = (enum transcoder) intel_crtc->pipe;
3600 intel_ddi_put_crtc_pll(crtc);
3603 static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
3605 if (!enable && intel_crtc->overlay) {
3606 struct drm_device *dev = intel_crtc->base.dev;
3607 struct drm_i915_private *dev_priv = dev->dev_private;
3609 mutex_lock(&dev->struct_mutex);
3610 dev_priv->mm.interruptible = false;
3611 (void) intel_overlay_switch_off(intel_crtc->overlay);
3612 dev_priv->mm.interruptible = true;
3613 mutex_unlock(&dev->struct_mutex);
3616 /* Let userspace switch the overlay on again. In most cases userspace
3617 * has to recompute where to put it anyway.
3622 * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
3623 * cursor plane briefly if not already running after enabling the display
3625 * This workaround avoids occasional blank screens when self refresh is
3629 g4x_fixup_plane(struct drm_i915_private *dev_priv, enum i915_pipe pipe)
3631 u32 cntl = I915_READ(CURCNTR(pipe));
3633 if ((cntl & CURSOR_MODE) == 0) {
3634 u32 fw_bcl_self = I915_READ(FW_BLC_SELF);
3636 I915_WRITE(FW_BLC_SELF, fw_bcl_self & ~FW_BLC_SELF_EN);
3637 I915_WRITE(CURCNTR(pipe), CURSOR_MODE_64_ARGB_AX);
3638 intel_wait_for_vblank(dev_priv->dev, pipe);
3639 I915_WRITE(CURCNTR(pipe), cntl);
3640 I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe)));
3641 I915_WRITE(FW_BLC_SELF, fw_bcl_self);
3645 static void i9xx_crtc_enable(struct drm_crtc *crtc)
3647 struct drm_device *dev = crtc->dev;
3648 struct drm_i915_private *dev_priv = dev->dev_private;
3649 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3650 struct intel_encoder *encoder;
3651 int pipe = intel_crtc->pipe;
3652 int plane = intel_crtc->plane;
3654 WARN_ON(!crtc->enabled);
3656 if (intel_crtc->active)
3659 intel_crtc->active = true;
3660 intel_update_watermarks(dev);
3662 intel_enable_pll(dev_priv, pipe);
3664 for_each_encoder_on_crtc(dev, crtc, encoder)
3665 if (encoder->pre_enable)
3666 encoder->pre_enable(encoder);
3668 intel_enable_pipe(dev_priv, pipe, false);
3669 intel_enable_plane(dev_priv, plane, pipe);
3671 g4x_fixup_plane(dev_priv, pipe);
3673 intel_crtc_load_lut(crtc);
3674 intel_update_fbc(dev);
3676 /* Give the overlay scaler a chance to enable if it's on this pipe */
3677 intel_crtc_dpms_overlay(intel_crtc, true);
3678 intel_crtc_update_cursor(crtc, true);
3680 for_each_encoder_on_crtc(dev, crtc, encoder)
3681 encoder->enable(encoder);
3684 static void i9xx_crtc_disable(struct drm_crtc *crtc)
3686 struct drm_device *dev = crtc->dev;
3687 struct drm_i915_private *dev_priv = dev->dev_private;
3688 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3689 struct intel_encoder *encoder;
3690 int pipe = intel_crtc->pipe;
3691 int plane = intel_crtc->plane;
3695 if (!intel_crtc->active)
3698 for_each_encoder_on_crtc(dev, crtc, encoder)
3699 encoder->disable(encoder);
3701 /* Give the overlay scaler a chance to disable if it's on this pipe */
3702 intel_crtc_wait_for_pending_flips(crtc);
3703 drm_vblank_off(dev, pipe);
3704 intel_crtc_dpms_overlay(intel_crtc, false);
3705 intel_crtc_update_cursor(crtc, false);
3707 if (dev_priv->cfb_plane == plane)
3708 intel_disable_fbc(dev);
3710 intel_disable_plane(dev_priv, plane, pipe);
3711 intel_disable_pipe(dev_priv, pipe);
3713 /* Disable pannel fitter if it is on this pipe. */
3714 pctl = I915_READ(PFIT_CONTROL);
3715 if ((pctl & PFIT_ENABLE) &&
3716 ((pctl & PFIT_PIPE_MASK) >> PFIT_PIPE_SHIFT) == pipe)
3717 I915_WRITE(PFIT_CONTROL, 0);
3719 intel_disable_pll(dev_priv, pipe);
3721 intel_crtc->active = false;
3722 intel_update_fbc(dev);
3723 intel_update_watermarks(dev);
3726 static void i9xx_crtc_off(struct drm_crtc *crtc)
3730 static void intel_crtc_update_sarea(struct drm_crtc *crtc,
3733 struct drm_device *dev = crtc->dev;
3734 struct drm_i915_private *dev_priv = dev->dev_private;
3736 struct drm_i915_master_private *master_priv;
3738 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3739 int pipe = intel_crtc->pipe;
3742 if (!dev->primary->master)
3745 master_priv = dev->primary->master->driver_priv;
3746 if (!master_priv->sarea_priv)
3749 if (!dev_priv->sarea_priv)
3756 master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
3757 master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
3759 dev_priv->sarea_priv->planeA_w = enabled ? crtc->mode.hdisplay : 0;
3760 dev_priv->sarea_priv->planeA_h = enabled ? crtc->mode.vdisplay : 0;
3765 master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
3766 master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
3768 dev_priv->sarea_priv->planeB_w = enabled ? crtc->mode.hdisplay : 0;
3769 dev_priv->sarea_priv->planeB_h = enabled ? crtc->mode.vdisplay : 0;
3773 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
3779 * Sets the power management mode of the pipe and plane.
3781 void intel_crtc_update_dpms(struct drm_crtc *crtc)
3783 struct drm_device *dev = crtc->dev;
3784 struct drm_i915_private *dev_priv = dev->dev_private;
3785 struct intel_encoder *intel_encoder;
3786 bool enable = false;
3788 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
3789 enable |= intel_encoder->connectors_active;
3792 dev_priv->display.crtc_enable(crtc);
3794 dev_priv->display.crtc_disable(crtc);
3796 intel_crtc_update_sarea(crtc, enable);
3799 static void intel_crtc_noop(struct drm_crtc *crtc)
3803 static void intel_crtc_disable(struct drm_crtc *crtc)
3805 struct drm_device *dev = crtc->dev;
3806 struct drm_connector *connector;
3807 struct drm_i915_private *dev_priv = dev->dev_private;
3808 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3810 /* crtc should still be enabled when we disable it. */
3811 WARN_ON(!crtc->enabled);
3813 intel_crtc->eld_vld = false;
3814 dev_priv->display.crtc_disable(crtc);
3815 intel_crtc_update_sarea(crtc, false);
3816 dev_priv->display.off(crtc);
3818 assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
3819 assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe);
3822 mutex_lock(&dev->struct_mutex);
3823 intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
3824 mutex_unlock(&dev->struct_mutex);
3828 /* Update computed state. */
3829 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3830 if (!connector->encoder || !connector->encoder->crtc)
3833 if (connector->encoder->crtc != crtc)
3836 connector->dpms = DRM_MODE_DPMS_OFF;
3837 to_intel_encoder(connector->encoder)->connectors_active = false;
3841 void intel_modeset_disable(struct drm_device *dev)
3843 struct drm_crtc *crtc;
3845 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
3847 intel_crtc_disable(crtc);
3851 void intel_encoder_noop(struct drm_encoder *encoder)
3855 void intel_encoder_destroy(struct drm_encoder *encoder)
3857 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
3859 drm_encoder_cleanup(encoder);
3860 drm_free(intel_encoder, M_DRM);
3863 /* Simple dpms helper for encodres with just one connector, no cloning and only
3864 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
3865 * state of the entire output pipe. */
3866 void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
3868 if (mode == DRM_MODE_DPMS_ON) {
3869 encoder->connectors_active = true;
3871 intel_crtc_update_dpms(encoder->base.crtc);
3873 encoder->connectors_active = false;
3875 intel_crtc_update_dpms(encoder->base.crtc);
3879 /* Cross check the actual hw state with our own modeset state tracking (and it's
3880 * internal consistency). */
3881 static void intel_connector_check_state(struct intel_connector *connector)
3883 if (connector->get_hw_state(connector)) {
3884 struct intel_encoder *encoder = connector->encoder;
3885 struct drm_crtc *crtc;
3886 bool encoder_enabled;
3887 enum i915_pipe pipe;
3889 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
3890 connector->base.base.id,
3891 drm_get_connector_name(&connector->base));
3893 WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
3894 "wrong connector dpms state\n");
3895 WARN(connector->base.encoder != &encoder->base,
3896 "active connector not linked to encoder\n");
3897 WARN(!encoder->connectors_active,
3898 "encoder->connectors_active not set\n");
3900 encoder_enabled = encoder->get_hw_state(encoder, &pipe);
3901 WARN(!encoder_enabled, "encoder not enabled\n");
3902 if (WARN_ON(!encoder->base.crtc))
3905 crtc = encoder->base.crtc;
3907 WARN(!crtc->enabled, "crtc not enabled\n");
3908 WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
3909 WARN(pipe != to_intel_crtc(crtc)->pipe,
3910 "encoder active on the wrong pipe\n");
3914 /* Even simpler default implementation, if there's really no special case to
3916 void intel_connector_dpms(struct drm_connector *connector, int mode)
3918 struct intel_encoder *encoder = intel_attached_encoder(connector);
3920 /* All the simple cases only support two dpms states. */
3921 if (mode != DRM_MODE_DPMS_ON)
3922 mode = DRM_MODE_DPMS_OFF;
3924 if (mode == connector->dpms)
3927 connector->dpms = mode;
3929 /* Only need to change hw state when actually enabled */
3930 if (encoder->base.crtc)
3931 intel_encoder_dpms(encoder, mode);
3933 WARN_ON(encoder->connectors_active != false);
3935 intel_modeset_check_state(connector->dev);
3938 /* Simple connector->get_hw_state implementation for encoders that support only
3939 * one connector and no cloning and hence the encoder state determines the state
3940 * of the connector. */
3941 bool intel_connector_get_hw_state(struct intel_connector *connector)
3943 enum i915_pipe pipe = 0;
3944 struct intel_encoder *encoder = connector->encoder;
3946 return encoder->get_hw_state(encoder, &pipe);
3949 static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
3950 const struct drm_display_mode *mode,
3951 struct drm_display_mode *adjusted_mode)
3953 struct drm_device *dev = crtc->dev;
3955 if (HAS_PCH_SPLIT(dev)) {
3956 /* FDI link clock is fixed at 2.7G */
3957 if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
3961 /* All interlaced capable intel hw wants timings in frames. Note though
3962 * that intel_lvds_mode_fixup does some funny tricks with the crtc
3963 * timings, so we need to be careful not to clobber these.*/
3964 if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
3965 drm_mode_set_crtcinfo(adjusted_mode, 0);
3967 /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
3968 * with a hsync front porch of 0.
3970 if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
3971 adjusted_mode->hsync_start == adjusted_mode->hdisplay)
3977 static int valleyview_get_display_clock_speed(struct drm_device *dev)
3979 return 400000; /* FIXME */
3982 static int i945_get_display_clock_speed(struct drm_device *dev)
3987 static int i915_get_display_clock_speed(struct drm_device *dev)
3992 static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
3997 static int i915gm_get_display_clock_speed(struct drm_device *dev)
4001 pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
4003 if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
4006 switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
4007 case GC_DISPLAY_CLOCK_333_MHZ:
4010 case GC_DISPLAY_CLOCK_190_200_MHZ:
4016 static int i865_get_display_clock_speed(struct drm_device *dev)
4021 static int i855_get_display_clock_speed(struct drm_device *dev)
4024 /* Assume that the hardware is in the high speed state. This
4025 * should be the default.
4027 switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
4028 case GC_CLOCK_133_200:
4029 case GC_CLOCK_100_200:
4031 case GC_CLOCK_166_250:
4033 case GC_CLOCK_100_133:
4037 /* Shouldn't happen */
4041 static int i830_get_display_clock_speed(struct drm_device *dev)
4047 intel_reduce_ratio(uint32_t *num, uint32_t *den)
4049 while (*num > 0xffffff || *den > 0xffffff) {
4056 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
4057 int pixel_clock, int link_clock,
4058 struct intel_link_m_n *m_n)
4061 m_n->gmch_m = bits_per_pixel * pixel_clock;
4062 m_n->gmch_n = link_clock * nlanes * 8;
4063 intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
4064 m_n->link_m = pixel_clock;
4065 m_n->link_n = link_clock;
4066 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
4069 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
4071 if (i915_panel_use_ssc >= 0)
4072 return i915_panel_use_ssc != 0;
4073 return dev_priv->lvds_use_ssc
4074 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
4078 * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
4079 * @crtc: CRTC structure
4080 * @mode: requested mode
4082 * A pipe may be connected to one or more outputs. Based on the depth of the
4083 * attached framebuffer, choose a good color depth to use on the pipe.
4085 * If possible, match the pipe depth to the fb depth. In some cases, this
4086 * isn't ideal, because the connected output supports a lesser or restricted
4087 * set of depths. Resolve that here:
4088 * LVDS typically supports only 6bpc, so clamp down in that case
4089 * HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
4090 * Displays may support a restricted set as well, check EDID and clamp as
4092 * DP may want to dither down to 6bpc to fit larger modes
4095 * Dithering requirement (i.e. false if display bpc and pipe bpc match,
4096 * true if they don't match).
4098 static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
4099 struct drm_framebuffer *fb,
4100 unsigned int *pipe_bpp,
4101 struct drm_display_mode *mode)
4103 struct drm_device *dev = crtc->dev;
4104 struct drm_i915_private *dev_priv = dev->dev_private;
4105 struct drm_connector *connector;
4106 struct intel_encoder *intel_encoder;
4107 unsigned int display_bpc = UINT_MAX, bpc;
4109 /* Walk the encoders & connectors on this crtc, get min bpc */
4110 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
4112 if (intel_encoder->type == INTEL_OUTPUT_LVDS) {
4113 unsigned int lvds_bpc;
4115 if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) ==
4121 if (lvds_bpc < display_bpc) {
4122 DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
4123 display_bpc = lvds_bpc;
4128 /* Not one of the known troublemakers, check the EDID */
4129 list_for_each_entry(connector, &dev->mode_config.connector_list,
4131 if (connector->encoder != &intel_encoder->base)
4134 /* Don't use an invalid EDID bpc value */
4135 if (connector->display_info.bpc &&
4136 connector->display_info.bpc < display_bpc) {
4137 DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
4138 display_bpc = connector->display_info.bpc;
4142 if (intel_encoder->type == INTEL_OUTPUT_EDP) {
4143 /* Use VBT settings if we have an eDP panel */
4144 unsigned int edp_bpc = dev_priv->edp.bpp / 3;
4146 if (edp_bpc && edp_bpc < display_bpc) {
4147 DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
4148 display_bpc = edp_bpc;
4154 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
4155 * through, clamp it down. (Note: >12bpc will be caught below.)
4157 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
4158 if (display_bpc > 8 && display_bpc < 12) {
4159 DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
4162 DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
4168 if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
4169 DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
4174 * We could just drive the pipe at the highest bpc all the time and
4175 * enable dithering as needed, but that costs bandwidth. So choose
4176 * the minimum value that expresses the full color range of the fb but
4177 * also stays within the max display bpc discovered above.
4180 switch (fb->depth) {
4182 bpc = 8; /* since we go through a colormap */
4186 bpc = 6; /* min is 18bpp */
4198 DRM_DEBUG("unsupported depth, assuming 24 bits\n");
4199 bpc = min((unsigned int)8, display_bpc);
4203 display_bpc = min(display_bpc, bpc);
4205 DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
4208 *pipe_bpp = display_bpc * 3;
4210 return display_bpc != bpc;
4213 static int vlv_get_refclk(struct drm_crtc *crtc)
4215 struct drm_device *dev = crtc->dev;
4216 struct drm_i915_private *dev_priv = dev->dev_private;
4217 int refclk = 27000; /* for DP & HDMI */
4219 return 100000; /* only one validated so far */
4221 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
4223 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
4224 if (intel_panel_use_ssc(dev_priv))
4228 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
4235 static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
4237 struct drm_device *dev = crtc->dev;
4238 struct drm_i915_private *dev_priv = dev->dev_private;
4241 if (IS_VALLEYVIEW(dev)) {
4242 refclk = vlv_get_refclk(crtc);
4243 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4244 intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
4245 refclk = dev_priv->lvds_ssc_freq * 1000;
4246 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
4248 } else if (!IS_GEN2(dev)) {
4257 static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode *adjusted_mode,
4258 intel_clock_t *clock)
4260 /* SDVO TV has fixed PLL values depend on its clock range,
4261 this mirrors vbios setting. */
4262 if (adjusted_mode->clock >= 100000
4263 && adjusted_mode->clock < 140500) {
4269 } else if (adjusted_mode->clock >= 140500
4270 && adjusted_mode->clock <= 200000) {
4279 static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
4280 intel_clock_t *clock,
4281 intel_clock_t *reduced_clock)
4283 struct drm_device *dev = crtc->dev;
4284 struct drm_i915_private *dev_priv = dev->dev_private;
4285 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4286 int pipe = intel_crtc->pipe;
4289 if (IS_PINEVIEW(dev)) {
4290 fp = (1 << clock->n) << 16 | clock->m1 << 8 | clock->m2;
4292 fp2 = (1 << reduced_clock->n) << 16 |
4293 reduced_clock->m1 << 8 | reduced_clock->m2;
4295 fp = clock->n << 16 | clock->m1 << 8 | clock->m2;
4297 fp2 = reduced_clock->n << 16 | reduced_clock->m1 << 8 |
4301 I915_WRITE(FP0(pipe), fp);
4303 intel_crtc->lowfreq_avail = false;
4304 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4305 reduced_clock && i915_powersave) {
4306 I915_WRITE(FP1(pipe), fp2);
4307 intel_crtc->lowfreq_avail = true;
4309 I915_WRITE(FP1(pipe), fp);
4313 static void vlv_update_pll(struct drm_crtc *crtc,
4314 struct drm_display_mode *mode,
4315 struct drm_display_mode *adjusted_mode,
4316 intel_clock_t *clock, intel_clock_t *reduced_clock,
4319 struct drm_device *dev = crtc->dev;
4320 struct drm_i915_private *dev_priv = dev->dev_private;
4321 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4322 int pipe = intel_crtc->pipe;
4323 u32 dpll, mdiv, pdiv;
4324 u32 bestn, bestm1, bestm2, bestp1, bestp2;
4328 lockmgr(&dev_priv->dpio_lock, LK_EXCLUSIVE);
4330 is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
4331 intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
4333 dpll = DPLL_VGA_MODE_DIS;
4334 dpll |= DPLL_EXT_BUFFER_ENABLE_VLV;
4335 dpll |= DPLL_REFA_CLK_ENABLE_VLV;
4336 dpll |= DPLL_INTEGRATED_CLOCK_VLV;
4338 I915_WRITE(DPLL(pipe), dpll);
4339 POSTING_READ(DPLL(pipe));
4348 * In Valleyview PLL and program lane counter registers are exposed
4349 * through DPIO interface
4351 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
4352 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
4353 mdiv |= ((bestn << DPIO_N_SHIFT));
4354 mdiv |= (1 << DPIO_POST_DIV_SHIFT);
4355 mdiv |= (1 << DPIO_K_SHIFT);
4356 mdiv |= DPIO_ENABLE_CALIBRATION;
4357 intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv);
4359 intel_dpio_write(dev_priv, DPIO_CORE_CLK(pipe), 0x01000000);
4361 pdiv = (1 << DPIO_REFSEL_OVERRIDE) | (5 << DPIO_PLL_MODESEL_SHIFT) |
4362 (3 << DPIO_BIAS_CURRENT_CTL_SHIFT) | (1<<20) |
4363 (7 << DPIO_PLL_REFCLK_SEL_SHIFT) | (8 << DPIO_DRIVER_CTL_SHIFT) |
4364 (5 << DPIO_CLK_BIAS_CTL_SHIFT);
4365 intel_dpio_write(dev_priv, DPIO_REFSFR(pipe), pdiv);
4367 intel_dpio_write(dev_priv, DPIO_LFP_COEFF(pipe), 0x005f003b);
4369 dpll |= DPLL_VCO_ENABLE;
4370 I915_WRITE(DPLL(pipe), dpll);
4371 POSTING_READ(DPLL(pipe));
4372 if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
4373 DRM_ERROR("DPLL %d failed to lock\n", pipe);
4375 intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620);
4377 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
4378 intel_dp_set_m_n(crtc, mode, adjusted_mode);
4380 I915_WRITE(DPLL(pipe), dpll);
4382 /* Wait for the clocks to stabilize. */
4383 POSTING_READ(DPLL(pipe));
4388 temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4390 temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
4394 I915_WRITE(DPLL_MD(pipe), temp);
4395 POSTING_READ(DPLL_MD(pipe));
4397 /* Now program lane control registers */
4398 if(intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)
4399 || intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
4404 intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp);
4406 if(intel_pipe_has_type(crtc,INTEL_OUTPUT_EDP))
4411 intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL2, temp);
4414 lockmgr(&dev_priv->dpio_lock, LK_RELEASE);
4417 static void i9xx_update_pll(struct drm_crtc *crtc,
4418 struct drm_display_mode *mode,
4419 struct drm_display_mode *adjusted_mode,
4420 intel_clock_t *clock, intel_clock_t *reduced_clock,
4423 struct drm_device *dev = crtc->dev;
4424 struct drm_i915_private *dev_priv = dev->dev_private;
4425 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4426 struct intel_encoder *encoder;
4427 int pipe = intel_crtc->pipe;
4431 i9xx_update_pll_dividers(crtc, clock, reduced_clock);
4433 is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
4434 intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
4436 dpll = DPLL_VGA_MODE_DIS;
4438 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
4439 dpll |= DPLLB_MODE_LVDS;
4441 dpll |= DPLLB_MODE_DAC_SERIAL;
4443 int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
4444 if (pixel_multiplier > 1) {
4445 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
4446 dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
4448 dpll |= DPLL_DVO_HIGH_SPEED;
4450 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
4451 dpll |= DPLL_DVO_HIGH_SPEED;
4453 /* compute bitmask from p1 value */
4454 if (IS_PINEVIEW(dev))
4455 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
4457 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4458 if (IS_G4X(dev) && reduced_clock)
4459 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
4461 switch (clock->p2) {
4463 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
4466 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
4469 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
4472 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
4475 if (INTEL_INFO(dev)->gen >= 4)
4476 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
4478 if (is_sdvo && intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4479 dpll |= PLL_REF_INPUT_TVCLKINBC;
4480 else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4481 /* XXX: just matching BIOS for now */
4482 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
4484 else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4485 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4486 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4488 dpll |= PLL_REF_INPUT_DREFCLK;
4490 dpll |= DPLL_VCO_ENABLE;
4491 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
4492 POSTING_READ(DPLL(pipe));
4495 for_each_encoder_on_crtc(dev, crtc, encoder)
4496 if (encoder->pre_pll_enable)
4497 encoder->pre_pll_enable(encoder);
4499 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
4500 intel_dp_set_m_n(crtc, mode, adjusted_mode);
4502 I915_WRITE(DPLL(pipe), dpll);
4504 /* Wait for the clocks to stabilize. */
4505 POSTING_READ(DPLL(pipe));
4508 if (INTEL_INFO(dev)->gen >= 4) {
4511 temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4513 temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
4517 I915_WRITE(DPLL_MD(pipe), temp);
4519 /* The pixel multiplier can only be updated once the
4520 * DPLL is enabled and the clocks are stable.
4522 * So write it again.
4524 I915_WRITE(DPLL(pipe), dpll);
4528 static void i8xx_update_pll(struct drm_crtc *crtc,
4529 struct drm_display_mode *adjusted_mode,
4530 intel_clock_t *clock, intel_clock_t *reduced_clock,
4533 struct drm_device *dev = crtc->dev;
4534 struct drm_i915_private *dev_priv = dev->dev_private;
4535 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4536 struct intel_encoder *encoder;
4537 int pipe = intel_crtc->pipe;
4540 i9xx_update_pll_dividers(crtc, clock, reduced_clock);
4542 dpll = DPLL_VGA_MODE_DIS;
4544 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
4545 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4548 dpll |= PLL_P1_DIVIDE_BY_TWO;
4550 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4552 dpll |= PLL_P2_DIVIDE_BY_4;
4555 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4556 /* XXX: just matching BIOS for now */
4557 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
4559 else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4560 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4561 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4563 dpll |= PLL_REF_INPUT_DREFCLK;
4565 dpll |= DPLL_VCO_ENABLE;
4566 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
4567 POSTING_READ(DPLL(pipe));
4570 for_each_encoder_on_crtc(dev, crtc, encoder)
4571 if (encoder->pre_pll_enable)
4572 encoder->pre_pll_enable(encoder);
4574 I915_WRITE(DPLL(pipe), dpll);
4576 /* Wait for the clocks to stabilize. */
4577 POSTING_READ(DPLL(pipe));
4580 /* The pixel multiplier can only be updated once the
4581 * DPLL is enabled and the clocks are stable.
4583 * So write it again.
4585 I915_WRITE(DPLL(pipe), dpll);
4588 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc,
4589 struct drm_display_mode *mode,
4590 struct drm_display_mode *adjusted_mode)
4592 struct drm_device *dev = intel_crtc->base.dev;
4593 struct drm_i915_private *dev_priv = dev->dev_private;
4594 enum i915_pipe pipe = intel_crtc->pipe;
4595 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
4596 uint32_t vsyncshift;
4598 if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4599 /* the chip adds 2 halflines automatically */
4600 adjusted_mode->crtc_vtotal -= 1;
4601 adjusted_mode->crtc_vblank_end -= 1;
4602 vsyncshift = adjusted_mode->crtc_hsync_start
4603 - adjusted_mode->crtc_htotal / 2;
4608 if (INTEL_INFO(dev)->gen > 3)
4609 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
4611 I915_WRITE(HTOTAL(cpu_transcoder),
4612 (adjusted_mode->crtc_hdisplay - 1) |
4613 ((adjusted_mode->crtc_htotal - 1) << 16));
4614 I915_WRITE(HBLANK(cpu_transcoder),
4615 (adjusted_mode->crtc_hblank_start - 1) |
4616 ((adjusted_mode->crtc_hblank_end - 1) << 16));
4617 I915_WRITE(HSYNC(cpu_transcoder),
4618 (adjusted_mode->crtc_hsync_start - 1) |
4619 ((adjusted_mode->crtc_hsync_end - 1) << 16));
4621 I915_WRITE(VTOTAL(cpu_transcoder),
4622 (adjusted_mode->crtc_vdisplay - 1) |
4623 ((adjusted_mode->crtc_vtotal - 1) << 16));
4624 I915_WRITE(VBLANK(cpu_transcoder),
4625 (adjusted_mode->crtc_vblank_start - 1) |
4626 ((adjusted_mode->crtc_vblank_end - 1) << 16));
4627 I915_WRITE(VSYNC(cpu_transcoder),
4628 (adjusted_mode->crtc_vsync_start - 1) |
4629 ((adjusted_mode->crtc_vsync_end - 1) << 16));
4631 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
4632 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
4633 * documented on the DDI_FUNC_CTL register description, EDP Input Select
4635 if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
4636 (pipe == PIPE_B || pipe == PIPE_C))
4637 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
4639 /* pipesrc controls the size that is scaled from, which should
4640 * always be the user's requested size.
4642 I915_WRITE(PIPESRC(pipe),
4643 ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
4646 static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
4647 struct drm_display_mode *mode,
4648 struct drm_display_mode *adjusted_mode,
4650 struct drm_framebuffer *fb)
4652 struct drm_device *dev = crtc->dev;
4653 struct drm_i915_private *dev_priv = dev->dev_private;
4654 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4655 int pipe = intel_crtc->pipe;
4656 int plane = intel_crtc->plane;
4657 int refclk, num_connectors = 0;
4658 intel_clock_t clock, reduced_clock;
4659 u32 dspcntr, pipeconf;
4660 bool ok, has_reduced_clock = false, is_sdvo = false;
4661 bool is_lvds = false, is_tv = false, is_dp = false;
4662 struct intel_encoder *encoder;
4663 const intel_limit_t *limit;
4666 for_each_encoder_on_crtc(dev, crtc, encoder) {
4667 switch (encoder->type) {
4668 case INTEL_OUTPUT_LVDS:
4671 case INTEL_OUTPUT_SDVO:
4672 case INTEL_OUTPUT_HDMI:
4674 if (encoder->needs_tv_clock)
4677 case INTEL_OUTPUT_TVOUT:
4680 case INTEL_OUTPUT_DISPLAYPORT:
4688 refclk = i9xx_get_refclk(crtc, num_connectors);
4691 * Returns a set of divisors for the desired target clock with the given
4692 * refclk, or FALSE. The returned values represent the clock equation:
4693 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
4695 limit = intel_limit(crtc, refclk);
4696 ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
4699 DRM_ERROR("Couldn't find PLL settings for mode!\n");
4703 /* Ensure that the cursor is valid for the new mode before changing... */
4704 intel_crtc_update_cursor(crtc, true);
4706 if (is_lvds && dev_priv->lvds_downclock_avail) {
4708 * Ensure we match the reduced clock's P to the target clock.
4709 * If the clocks don't match, we can't switch the display clock
4710 * by using the FP0/FP1. In such case we will disable the LVDS
4711 * downclock feature.
4713 has_reduced_clock = limit->find_pll(limit, crtc,
4714 dev_priv->lvds_downclock,
4720 if (is_sdvo && is_tv)
4721 i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
4724 i8xx_update_pll(crtc, adjusted_mode, &clock,
4725 has_reduced_clock ? &reduced_clock : NULL,
4727 else if (IS_VALLEYVIEW(dev))
4728 vlv_update_pll(crtc, mode, adjusted_mode, &clock,
4729 has_reduced_clock ? &reduced_clock : NULL,
4732 i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
4733 has_reduced_clock ? &reduced_clock : NULL,
4736 /* setup pipeconf */
4737 pipeconf = I915_READ(PIPECONF(pipe));
4739 /* Set up the display plane register */
4740 dspcntr = DISPPLANE_GAMMA_ENABLE;
4743 dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
4745 dspcntr |= DISPPLANE_SEL_PIPE_B;
4747 if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
4748 /* Enable pixel doubling when the dot clock is > 90% of the (display)
4751 * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
4755 dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
4756 pipeconf |= PIPECONF_DOUBLE_WIDE;
4758 pipeconf &= ~PIPECONF_DOUBLE_WIDE;
4761 /* default to 8bpc */
4762 pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
4764 if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
4765 pipeconf |= PIPECONF_6BPC |
4766 PIPECONF_DITHER_EN |
4767 PIPECONF_DITHER_TYPE_SP;
4771 if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
4772 if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
4773 pipeconf |= PIPECONF_6BPC |
4775 I965_PIPECONF_ACTIVE;
4779 DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
4780 drm_mode_debug_printmodeline(mode);
4782 if (HAS_PIPE_CXSR(dev)) {
4783 if (intel_crtc->lowfreq_avail) {
4784 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
4785 pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
4787 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
4788 pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
4792 pipeconf &= ~PIPECONF_INTERLACE_MASK;
4793 if (!IS_GEN2(dev) &&
4794 adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
4795 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
4797 pipeconf |= PIPECONF_PROGRESSIVE;
4799 intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
4801 /* pipesrc and dspsize control the size that is scaled from,
4802 * which should always be the user's requested size.
4804 I915_WRITE(DSPSIZE(plane),
4805 ((mode->vdisplay - 1) << 16) |
4806 (mode->hdisplay - 1));
4807 I915_WRITE(DSPPOS(plane), 0);
4809 I915_WRITE(PIPECONF(pipe), pipeconf);
4810 POSTING_READ(PIPECONF(pipe));
4811 intel_enable_pipe(dev_priv, pipe, false);
4813 intel_wait_for_vblank(dev, pipe);
4815 I915_WRITE(DSPCNTR(plane), dspcntr);
4816 POSTING_READ(DSPCNTR(plane));
4818 ret = intel_pipe_set_base(crtc, x, y, fb);
4820 intel_update_watermarks(dev);
4825 static void ironlake_init_pch_refclk(struct drm_device *dev)
4827 struct drm_i915_private *dev_priv = dev->dev_private;
4828 struct drm_mode_config *mode_config = &dev->mode_config;
4829 struct intel_encoder *encoder;
4831 bool has_lvds = false;
4832 bool has_cpu_edp = false;
4833 bool has_pch_edp = false;
4834 bool has_panel = false;
4835 bool has_ck505 = false;
4836 bool can_ssc = false;
4838 /* We need to take the global config into account */
4839 list_for_each_entry(encoder, &mode_config->encoder_list,
4841 switch (encoder->type) {
4842 case INTEL_OUTPUT_LVDS:
4846 case INTEL_OUTPUT_EDP:
4848 if (intel_encoder_is_pch_edp(&encoder->base))
4856 if (HAS_PCH_IBX(dev)) {
4857 has_ck505 = dev_priv->display_clock_mode;
4858 can_ssc = has_ck505;
4864 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n",
4865 has_panel, has_lvds, has_pch_edp, has_cpu_edp,
4868 /* Ironlake: try to setup display ref clock before DPLL
4869 * enabling. This is only under driver's control after
4870 * PCH B stepping, previous chipset stepping should be
4871 * ignoring this setting.
4873 temp = I915_READ(PCH_DREF_CONTROL);
4874 /* Always enable nonspread source */
4875 temp &= ~DREF_NONSPREAD_SOURCE_MASK;
4878 temp |= DREF_NONSPREAD_CK505_ENABLE;
4880 temp |= DREF_NONSPREAD_SOURCE_ENABLE;
4883 temp &= ~DREF_SSC_SOURCE_MASK;
4884 temp |= DREF_SSC_SOURCE_ENABLE;
4886 /* SSC must be turned on before enabling the CPU output */
4887 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4888 DRM_DEBUG_KMS("Using SSC on panel\n");
4889 temp |= DREF_SSC1_ENABLE;
4891 temp &= ~DREF_SSC1_ENABLE;
4893 /* Get SSC going before enabling the outputs */
4894 I915_WRITE(PCH_DREF_CONTROL, temp);
4895 POSTING_READ(PCH_DREF_CONTROL);
4898 temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4900 /* Enable CPU source on CPU attached eDP */
4902 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4903 DRM_DEBUG_KMS("Using SSC on eDP\n");
4904 temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
4907 temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
4909 temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4911 I915_WRITE(PCH_DREF_CONTROL, temp);
4912 POSTING_READ(PCH_DREF_CONTROL);
4915 DRM_DEBUG_KMS("Disabling SSC entirely\n");
4917 temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4919 /* Turn off CPU output */
4920 temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4922 I915_WRITE(PCH_DREF_CONTROL, temp);
4923 POSTING_READ(PCH_DREF_CONTROL);
4926 /* Turn off the SSC source */
4927 temp &= ~DREF_SSC_SOURCE_MASK;
4928 temp |= DREF_SSC_SOURCE_DISABLE;
4931 temp &= ~ DREF_SSC1_ENABLE;
4933 I915_WRITE(PCH_DREF_CONTROL, temp);
4934 POSTING_READ(PCH_DREF_CONTROL);
4939 /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
4940 static void lpt_init_pch_refclk(struct drm_device *dev)
4942 struct drm_i915_private *dev_priv = dev->dev_private;
4943 struct drm_mode_config *mode_config = &dev->mode_config;
4944 struct intel_encoder *encoder;
4945 bool has_vga = false;
4946 bool is_sdv = false;
4949 list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
4950 switch (encoder->type) {
4951 case INTEL_OUTPUT_ANALOG:
4960 mutex_lock(&dev_priv->dpio_lock);
4962 /* XXX: Rip out SDV support once Haswell ships for real. */
4963 if (IS_HASWELL(dev) && (dev->pci_device & 0xFF00) == 0x0C00)
4966 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
4967 tmp &= ~SBI_SSCCTL_DISABLE;
4968 tmp |= SBI_SSCCTL_PATHALT;
4969 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
4973 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
4974 tmp &= ~SBI_SSCCTL_PATHALT;
4975 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
4978 tmp = I915_READ(SOUTH_CHICKEN2);
4979 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
4980 I915_WRITE(SOUTH_CHICKEN2, tmp);
4982 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
4983 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
4984 DRM_ERROR("FDI mPHY reset assert timeout\n");
4986 tmp = I915_READ(SOUTH_CHICKEN2);
4987 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
4988 I915_WRITE(SOUTH_CHICKEN2, tmp);
4990 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
4991 FDI_MPHY_IOSFSB_RESET_STATUS) == 0,
4993 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
4996 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
4997 tmp &= ~(0xFF << 24);
4998 tmp |= (0x12 << 24);
4999 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
5002 tmp = intel_sbi_read(dev_priv, 0x808C, SBI_MPHY);
5004 tmp |= (1 << 6) | (1 << 0);
5005 intel_sbi_write(dev_priv, 0x808C, tmp, SBI_MPHY);
5009 tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY);
5011 intel_sbi_write(dev_priv, 0x800C, tmp, SBI_MPHY);
5014 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
5016 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
5018 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
5020 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
5023 tmp = intel_sbi_read(dev_priv, 0x2038, SBI_MPHY);
5024 tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
5025 intel_sbi_write(dev_priv, 0x2038, tmp, SBI_MPHY);
5027 tmp = intel_sbi_read(dev_priv, 0x2138, SBI_MPHY);
5028 tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
5029 intel_sbi_write(dev_priv, 0x2138, tmp, SBI_MPHY);
5031 tmp = intel_sbi_read(dev_priv, 0x203C, SBI_MPHY);
5033 intel_sbi_write(dev_priv, 0x203C, tmp, SBI_MPHY);
5035 tmp = intel_sbi_read(dev_priv, 0x213C, SBI_MPHY);
5037 intel_sbi_write(dev_priv, 0x213C, tmp, SBI_MPHY);
5040 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
5041 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
5042 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
5044 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
5045 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
5046 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
5049 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
5052 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
5054 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
5057 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
5060 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
5063 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
5065 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
5068 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
5070 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
5071 tmp &= ~(0xFF << 16);
5072 tmp |= (0x1C << 16);
5073 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
5075 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
5076 tmp &= ~(0xFF << 16);
5077 tmp |= (0x1C << 16);
5078 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
5081 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
5083 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
5085 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
5087 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
5089 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
5090 tmp &= ~(0xF << 28);
5092 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
5094 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
5095 tmp &= ~(0xF << 28);
5097 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
5100 /* ULT uses SBI_GEN0, but ULT doesn't have VGA, so we don't care. */
5101 tmp = intel_sbi_read(dev_priv, SBI_DBUFF0, SBI_ICLK);
5102 tmp |= SBI_DBUFF0_ENABLE;
5103 intel_sbi_write(dev_priv, SBI_DBUFF0, tmp, SBI_ICLK);
5105 mutex_unlock(&dev_priv->dpio_lock);
5109 * Initialize reference clocks when the driver loads
5111 void intel_init_pch_refclk(struct drm_device *dev)
5113 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
5114 ironlake_init_pch_refclk(dev);
5115 else if (HAS_PCH_LPT(dev))
5116 lpt_init_pch_refclk(dev);
5119 static int ironlake_get_refclk(struct drm_crtc *crtc)
5121 struct drm_device *dev = crtc->dev;
5122 struct drm_i915_private *dev_priv = dev->dev_private;
5123 struct intel_encoder *encoder;
5124 struct intel_encoder *edp_encoder = NULL;
5125 int num_connectors = 0;
5126 bool is_lvds = false;
5128 for_each_encoder_on_crtc(dev, crtc, encoder) {
5129 switch (encoder->type) {
5130 case INTEL_OUTPUT_LVDS:
5133 case INTEL_OUTPUT_EDP:
5134 edp_encoder = encoder;
5140 if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
5141 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
5142 dev_priv->lvds_ssc_freq);
5143 return dev_priv->lvds_ssc_freq * 1000;
5149 static void ironlake_set_pipeconf(struct drm_crtc *crtc,
5150 struct drm_display_mode *adjusted_mode,
5153 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
5154 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5155 int pipe = intel_crtc->pipe;
5158 val = I915_READ(PIPECONF(pipe));
5160 val &= ~PIPECONF_BPC_MASK;
5161 switch (intel_crtc->bpp) {
5163 val |= PIPECONF_6BPC;
5166 val |= PIPECONF_8BPC;
5169 val |= PIPECONF_10BPC;
5172 val |= PIPECONF_12BPC;
5175 /* Case prevented by intel_choose_pipe_bpp_dither. */
5179 val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
5181 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
5183 val &= ~PIPECONF_INTERLACE_MASK;
5184 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
5185 val |= PIPECONF_INTERLACED_ILK;
5187 val |= PIPECONF_PROGRESSIVE;
5189 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5190 val |= PIPECONF_COLOR_RANGE_SELECT;
5192 val &= ~PIPECONF_COLOR_RANGE_SELECT;
5194 I915_WRITE(PIPECONF(pipe), val);
5195 POSTING_READ(PIPECONF(pipe));
5199 * Set up the pipe CSC unit.
5201 * Currently only full range RGB to limited range RGB conversion
5202 * is supported, but eventually this should handle various
5203 * RGB<->YCbCr scenarios as well.
5205 static void intel_set_pipe_csc(struct drm_crtc *crtc,
5206 const struct drm_display_mode *adjusted_mode)
5208 struct drm_device *dev = crtc->dev;
5209 struct drm_i915_private *dev_priv = dev->dev_private;
5210 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5211 int pipe = intel_crtc->pipe;
5212 uint16_t coeff = 0x7800; /* 1.0 */
5215 * TODO: Check what kind of values actually come out of the pipe
5216 * with these coeff/postoff values and adjust to get the best
5217 * accuracy. Perhaps we even need to take the bpc value into
5221 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5222 coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
5225 * GY/GU and RY/RU should be the other way around according
5226 * to BSpec, but reality doesn't agree. Just set them up in
5227 * a way that results in the correct picture.
5229 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
5230 I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
5232 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
5233 I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
5235 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
5236 I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
5238 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
5239 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
5240 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
5242 if (INTEL_INFO(dev)->gen > 6) {
5243 uint16_t postoff = 0;
5245 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5246 postoff = (16 * (1 << 13) / 255) & 0x1fff;
5248 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
5249 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
5250 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
5252 I915_WRITE(PIPE_CSC_MODE(pipe), 0);
5254 uint32_t mode = CSC_MODE_YUV_TO_RGB;
5256 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5257 mode |= CSC_BLACK_SCREEN_OFFSET;
5259 I915_WRITE(PIPE_CSC_MODE(pipe), mode);
5263 static void haswell_set_pipeconf(struct drm_crtc *crtc,
5264 struct drm_display_mode *adjusted_mode,
5267 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
5268 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5269 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
5272 val = I915_READ(PIPECONF(cpu_transcoder));
5274 val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
5276 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
5278 val &= ~PIPECONF_INTERLACE_MASK_HSW;
5279 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
5280 val |= PIPECONF_INTERLACED_ILK;
5282 val |= PIPECONF_PROGRESSIVE;
5284 I915_WRITE(PIPECONF(cpu_transcoder), val);
5285 POSTING_READ(PIPECONF(cpu_transcoder));
5288 static bool ironlake_compute_clocks(struct drm_crtc *crtc,
5289 struct drm_display_mode *adjusted_mode,
5290 intel_clock_t *clock,
5291 bool *has_reduced_clock,
5292 intel_clock_t *reduced_clock)
5294 struct drm_device *dev = crtc->dev;
5295 struct drm_i915_private *dev_priv = dev->dev_private;
5296 struct intel_encoder *intel_encoder;
5298 const intel_limit_t *limit;
5299 bool ret, is_sdvo = false, is_tv = false, is_lvds = false;
5301 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
5302 switch (intel_encoder->type) {
5303 case INTEL_OUTPUT_LVDS:
5306 case INTEL_OUTPUT_SDVO:
5307 case INTEL_OUTPUT_HDMI:
5309 if (intel_encoder->needs_tv_clock)
5312 case INTEL_OUTPUT_TVOUT:
5318 refclk = ironlake_get_refclk(crtc);
5321 * Returns a set of divisors for the desired target clock with the given
5322 * refclk, or FALSE. The returned values represent the clock equation:
5323 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
5325 limit = intel_limit(crtc, refclk);
5326 ret = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
5331 if (is_lvds && dev_priv->lvds_downclock_avail) {
5333 * Ensure we match the reduced clock's P to the target clock.
5334 * If the clocks don't match, we can't switch the display clock
5335 * by using the FP0/FP1. In such case we will disable the LVDS
5336 * downclock feature.
5338 *has_reduced_clock = limit->find_pll(limit, crtc,
5339 dev_priv->lvds_downclock,
5345 if (is_sdvo && is_tv)
5346 i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
5351 static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
5353 struct drm_i915_private *dev_priv = dev->dev_private;
5356 temp = I915_READ(SOUTH_CHICKEN1);
5357 if (temp & FDI_BC_BIFURCATION_SELECT)
5360 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
5361 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
5363 temp |= FDI_BC_BIFURCATION_SELECT;
5364 DRM_DEBUG_KMS("enabling fdi C rx\n");
5365 I915_WRITE(SOUTH_CHICKEN1, temp);
5366 POSTING_READ(SOUTH_CHICKEN1);
5369 static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
5371 struct drm_device *dev = intel_crtc->base.dev;
5372 struct drm_i915_private *dev_priv = dev->dev_private;
5373 struct intel_crtc *pipe_B_crtc =
5374 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
5376 DRM_DEBUG_KMS("checking fdi config on pipe %i, lanes %i\n",
5377 intel_crtc->pipe, intel_crtc->fdi_lanes);
5378 if (intel_crtc->fdi_lanes > 4) {
5379 DRM_DEBUG_KMS("invalid fdi lane config on pipe %i: %i lanes\n",
5380 intel_crtc->pipe, intel_crtc->fdi_lanes);
5381 /* Clamp lanes to avoid programming the hw with bogus values. */
5382 intel_crtc->fdi_lanes = 4;
5387 if (dev_priv->num_pipe == 2)
5390 switch (intel_crtc->pipe) {
5394 if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
5395 intel_crtc->fdi_lanes > 2) {
5396 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
5397 intel_crtc->pipe, intel_crtc->fdi_lanes);
5398 /* Clamp lanes to avoid programming the hw with bogus values. */
5399 intel_crtc->fdi_lanes = 2;
5404 if (intel_crtc->fdi_lanes > 2)
5405 WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
5407 cpt_enable_fdi_bc_bifurcation(dev);
5411 if (!pipe_B_crtc->base.enabled || pipe_B_crtc->fdi_lanes <= 2) {
5412 if (intel_crtc->fdi_lanes > 2) {
5413 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
5414 intel_crtc->pipe, intel_crtc->fdi_lanes);
5415 /* Clamp lanes to avoid programming the hw with bogus values. */
5416 intel_crtc->fdi_lanes = 2;
5421 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5425 cpt_enable_fdi_bc_bifurcation(dev);
5433 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
5436 * Account for spread spectrum to avoid
5437 * oversubscribing the link. Max center spread
5438 * is 2.5%; use 5% for safety's sake.
5440 u32 bps = target_clock * bpp * 21 / 20;
5441 return bps / (link_bw * 8) + 1;
5444 static void ironlake_set_m_n(struct drm_crtc *crtc,
5445 struct drm_display_mode *mode,
5446 struct drm_display_mode *adjusted_mode)
5448 struct drm_device *dev = crtc->dev;
5449 struct drm_i915_private *dev_priv = dev->dev_private;
5450 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5451 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
5452 struct intel_encoder *intel_encoder, *edp_encoder = NULL;
5453 struct intel_link_m_n m_n = {0};
5454 int target_clock, pixel_multiplier, lane, link_bw;
5455 bool is_dp = false, is_cpu_edp = false;
5457 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
5458 switch (intel_encoder->type) {
5459 case INTEL_OUTPUT_DISPLAYPORT:
5462 case INTEL_OUTPUT_EDP:
5464 if (!intel_encoder_is_pch_edp(&intel_encoder->base))
5466 edp_encoder = intel_encoder;
5472 pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
5474 /* CPU eDP doesn't require FDI link, so just set DP M/N
5475 according to current link config */
5477 intel_edp_link_config(edp_encoder, &lane, &link_bw);
5479 /* FDI is a binary signal running at ~2.7GHz, encoding
5480 * each output octet as 10 bits. The actual frequency
5481 * is stored as a divider into a 100MHz clock, and the
5482 * mode pixel clock is stored in units of 1KHz.
5483 * Hence the bw of each lane in terms of the mode signal
5486 link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
5489 /* [e]DP over FDI requires target mode clock instead of link clock. */
5491 target_clock = intel_edp_target_clock(edp_encoder, mode);
5493 target_clock = mode->clock;
5495 target_clock = adjusted_mode->clock;
5498 lane = ironlake_get_lanes_required(target_clock, link_bw,
5501 intel_crtc->fdi_lanes = lane;
5503 if (pixel_multiplier > 1)
5504 link_bw *= pixel_multiplier;
5505 intel_link_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, &m_n);
5507 I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m);
5508 I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
5509 I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
5510 I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
5513 static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
5514 struct drm_display_mode *adjusted_mode,
5515 intel_clock_t *clock, u32 fp)
5517 struct drm_crtc *crtc = &intel_crtc->base;
5518 struct drm_device *dev = crtc->dev;
5519 struct drm_i915_private *dev_priv = dev->dev_private;
5520 struct intel_encoder *intel_encoder;
5522 int factor, pixel_multiplier, num_connectors = 0;
5523 bool is_lvds = false, is_sdvo = false, is_tv = false;
5524 bool is_dp = false, is_cpu_edp = false;
5526 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
5527 switch (intel_encoder->type) {
5528 case INTEL_OUTPUT_LVDS:
5531 case INTEL_OUTPUT_SDVO:
5532 case INTEL_OUTPUT_HDMI:
5534 if (intel_encoder->needs_tv_clock)
5537 case INTEL_OUTPUT_TVOUT:
5540 case INTEL_OUTPUT_DISPLAYPORT:
5543 case INTEL_OUTPUT_EDP:
5545 if (!intel_encoder_is_pch_edp(&intel_encoder->base))
5553 /* Enable autotuning of the PLL clock (if permissible) */
5556 if ((intel_panel_use_ssc(dev_priv) &&
5557 dev_priv->lvds_ssc_freq == 100) ||
5558 intel_is_dual_link_lvds(dev))
5560 } else if (is_sdvo && is_tv)
5563 if (clock->m < factor * clock->n)
5569 dpll |= DPLLB_MODE_LVDS;
5571 dpll |= DPLLB_MODE_DAC_SERIAL;
5573 pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
5574 if (pixel_multiplier > 1) {
5575 dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
5577 dpll |= DPLL_DVO_HIGH_SPEED;
5579 if (is_dp && !is_cpu_edp)
5580 dpll |= DPLL_DVO_HIGH_SPEED;
5582 /* compute bitmask from p1 value */
5583 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
5585 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
5587 switch (clock->p2) {
5589 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
5592 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
5595 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
5598 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
5602 if (is_sdvo && is_tv)
5603 dpll |= PLL_REF_INPUT_TVCLKINBC;
5605 /* XXX: just matching BIOS for now */
5606 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
5608 else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
5609 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
5611 dpll |= PLL_REF_INPUT_DREFCLK;
5616 static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
5617 struct drm_display_mode *mode,
5618 struct drm_display_mode *adjusted_mode,
5620 struct drm_framebuffer *fb)
5622 struct drm_device *dev = crtc->dev;
5623 struct drm_i915_private *dev_priv = dev->dev_private;
5624 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5625 int pipe = intel_crtc->pipe;
5626 int plane = intel_crtc->plane;
5627 int num_connectors = 0;
5628 intel_clock_t clock, reduced_clock;
5629 u32 dpll, fp = 0, fp2 = 0;
5630 bool ok, has_reduced_clock = false;
5631 bool is_lvds = false, is_dp = false, is_cpu_edp = false;
5632 struct intel_encoder *encoder;
5634 bool dither, fdi_config_ok;
5636 for_each_encoder_on_crtc(dev, crtc, encoder) {
5637 switch (encoder->type) {
5638 case INTEL_OUTPUT_LVDS:
5641 case INTEL_OUTPUT_DISPLAYPORT:
5644 case INTEL_OUTPUT_EDP:
5646 if (!intel_encoder_is_pch_edp(&encoder->base))
5654 WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
5655 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
5657 ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
5658 &has_reduced_clock, &reduced_clock);
5660 DRM_ERROR("Couldn't find PLL settings for mode!\n");
5664 /* Ensure that the cursor is valid for the new mode before changing... */
5665 intel_crtc_update_cursor(crtc, true);
5667 /* determine panel color depth */
5668 dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
5670 if (is_lvds && dev_priv->lvds_dither)
5673 fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
5674 if (has_reduced_clock)
5675 fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
5678 dpll = ironlake_compute_dpll(intel_crtc, adjusted_mode, &clock, fp);
5680 DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
5681 drm_mode_debug_printmodeline(mode);
5683 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
5685 struct intel_pch_pll *pll;
5687 pll = intel_get_pch_pll(intel_crtc, dpll, fp);
5689 DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
5694 intel_put_pch_pll(intel_crtc);
5696 if (is_dp && !is_cpu_edp)
5697 intel_dp_set_m_n(crtc, mode, adjusted_mode);
5699 for_each_encoder_on_crtc(dev, crtc, encoder)
5700 if (encoder->pre_pll_enable)
5701 encoder->pre_pll_enable(encoder);
5703 if (intel_crtc->pch_pll) {
5704 I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
5706 /* Wait for the clocks to stabilize. */
5707 POSTING_READ(intel_crtc->pch_pll->pll_reg);
5710 /* The pixel multiplier can only be updated once the
5711 * DPLL is enabled and the clocks are stable.
5713 * So write it again.
5715 I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
5718 intel_crtc->lowfreq_avail = false;
5719 if (intel_crtc->pch_pll) {
5720 if (is_lvds && has_reduced_clock && i915_powersave) {
5721 I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp2);
5722 intel_crtc->lowfreq_avail = true;
5724 I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp);
5728 intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
5730 /* Note, this also computes intel_crtc->fdi_lanes which is used below in
5731 * ironlake_check_fdi_lanes. */
5733 ironlake_set_m_n(crtc, mode, adjusted_mode);
5735 fdi_config_ok = ironlake_check_fdi_lanes(intel_crtc);
5737 ironlake_set_pipeconf(crtc, adjusted_mode, dither);
5739 intel_wait_for_vblank(dev, pipe);
5741 /* Set up the display plane register */
5742 I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
5743 POSTING_READ(DSPCNTR(plane));
5745 ret = intel_pipe_set_base(crtc, x, y, fb);
5747 intel_update_watermarks(dev);
5749 intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
5751 return fdi_config_ok ? ret : -EINVAL;
5754 static void haswell_modeset_global_resources(struct drm_device *dev)
5756 struct drm_i915_private *dev_priv = dev->dev_private;
5757 bool enable = false;
5758 struct intel_crtc *crtc;
5759 struct intel_encoder *encoder;
5761 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
5762 if (crtc->pipe != PIPE_A && crtc->base.enabled)
5764 /* XXX: Should check for edp transcoder here, but thanks to init
5765 * sequence that's not yet available. Just in case desktop eDP
5766 * on PORT D is possible on haswell, too. */
5769 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
5771 if (encoder->type != INTEL_OUTPUT_EDP &&
5772 encoder->connectors_active)
5776 /* Even the eDP panel fitter is outside the always-on well. */
5777 if (dev_priv->pch_pf_size)
5780 intel_set_power_well(dev, enable);
5783 static int haswell_crtc_mode_set(struct drm_crtc *crtc,
5784 struct drm_display_mode *mode,
5785 struct drm_display_mode *adjusted_mode,
5787 struct drm_framebuffer *fb)
5789 struct drm_device *dev = crtc->dev;
5790 struct drm_i915_private *dev_priv = dev->dev_private;
5791 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5792 int pipe = intel_crtc->pipe;
5793 int plane = intel_crtc->plane;
5794 int num_connectors = 0;
5795 bool is_dp = false, is_cpu_edp = false;
5796 struct intel_encoder *encoder;
5800 for_each_encoder_on_crtc(dev, crtc, encoder) {
5801 switch (encoder->type) {
5802 case INTEL_OUTPUT_DISPLAYPORT:
5805 case INTEL_OUTPUT_EDP:
5807 if (!intel_encoder_is_pch_edp(&encoder->base))
5816 intel_crtc->cpu_transcoder = TRANSCODER_EDP;
5818 intel_crtc->cpu_transcoder = pipe;
5820 /* We are not sure yet this won't happen. */
5821 WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
5822 INTEL_PCH_TYPE(dev));
5824 WARN(num_connectors != 1, "%d connectors attached to pipe %c\n",
5825 num_connectors, pipe_name(pipe));
5827 WARN_ON(I915_READ(PIPECONF(intel_crtc->cpu_transcoder)) &
5828 (PIPECONF_ENABLE | I965_PIPECONF_ACTIVE));
5830 WARN_ON(I915_READ(DSPCNTR(plane)) & DISPLAY_PLANE_ENABLE);
5832 if (!intel_ddi_pll_mode_set(crtc, adjusted_mode->clock))
5835 /* Ensure that the cursor is valid for the new mode before changing... */
5836 intel_crtc_update_cursor(crtc, true);
5838 /* determine panel color depth */
5839 dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
5842 DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
5843 drm_mode_debug_printmodeline(mode);
5845 if (is_dp && !is_cpu_edp)
5846 intel_dp_set_m_n(crtc, mode, adjusted_mode);
5848 intel_crtc->lowfreq_avail = false;
5850 intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
5852 if (!is_dp || is_cpu_edp)
5853 ironlake_set_m_n(crtc, mode, adjusted_mode);
5855 haswell_set_pipeconf(crtc, adjusted_mode, dither);
5857 intel_set_pipe_csc(crtc, adjusted_mode);
5859 /* Set up the display plane register */
5860 I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE);
5861 POSTING_READ(DSPCNTR(plane));
5863 ret = intel_pipe_set_base(crtc, x, y, fb);
5865 intel_update_watermarks(dev);
5867 intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
5872 static int intel_crtc_mode_set(struct drm_crtc *crtc,
5873 struct drm_display_mode *mode,
5874 struct drm_display_mode *adjusted_mode,
5876 struct drm_framebuffer *fb)
5878 struct drm_device *dev = crtc->dev;
5879 struct drm_i915_private *dev_priv = dev->dev_private;
5880 struct drm_encoder_helper_funcs *encoder_funcs;
5881 struct intel_encoder *encoder;
5882 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5883 int pipe = intel_crtc->pipe;
5886 drm_vblank_pre_modeset(dev, pipe);
5888 ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
5890 drm_vblank_post_modeset(dev, pipe);
5895 for_each_encoder_on_crtc(dev, crtc, encoder) {
5896 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
5897 encoder->base.base.id,
5898 drm_get_encoder_name(&encoder->base),
5899 mode->base.id, mode->name);
5900 encoder_funcs = encoder->base.helper_private;
5901 encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
5907 static bool intel_eld_uptodate(struct drm_connector *connector,
5908 int reg_eldv, uint32_t bits_eldv,
5909 int reg_elda, uint32_t bits_elda,
5912 struct drm_i915_private *dev_priv = connector->dev->dev_private;
5913 uint8_t *eld = connector->eld;
5916 i = I915_READ(reg_eldv);
5925 i = I915_READ(reg_elda);
5927 I915_WRITE(reg_elda, i);
5929 for (i = 0; i < eld[2]; i++)
5930 if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
5936 static void g4x_write_eld(struct drm_connector *connector,
5937 struct drm_crtc *crtc)
5939 struct drm_i915_private *dev_priv = connector->dev->dev_private;
5940 uint8_t *eld = connector->eld;
5945 i = I915_READ(G4X_AUD_VID_DID);
5947 if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
5948 eldv = G4X_ELDV_DEVCL_DEVBLC;
5950 eldv = G4X_ELDV_DEVCTG;
5952 if (intel_eld_uptodate(connector,
5953 G4X_AUD_CNTL_ST, eldv,
5954 G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
5955 G4X_HDMIW_HDMIEDID))
5958 i = I915_READ(G4X_AUD_CNTL_ST);
5959 i &= ~(eldv | G4X_ELD_ADDR);
5960 len = (i >> 9) & 0x1f; /* ELD buffer size */
5961 I915_WRITE(G4X_AUD_CNTL_ST, i);
5966 len = min_t(uint8_t, eld[2], len);
5967 DRM_DEBUG_DRIVER("ELD size %d\n", len);
5968 for (i = 0; i < len; i++)
5969 I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
5971 i = I915_READ(G4X_AUD_CNTL_ST);
5973 I915_WRITE(G4X_AUD_CNTL_ST, i);
5976 static void haswell_write_eld(struct drm_connector *connector,
5977 struct drm_crtc *crtc)
5979 struct drm_i915_private *dev_priv = connector->dev->dev_private;
5980 uint8_t *eld = connector->eld;
5981 struct drm_device *dev = crtc->dev;
5982 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5986 int pipe = to_intel_crtc(crtc)->pipe;
5989 int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
5990 int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
5991 int aud_config = HSW_AUD_CFG(pipe);
5992 int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
5995 DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n");
5997 /* Audio output enable */
5998 DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
5999 tmp = I915_READ(aud_cntrl_st2);
6000 tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
6001 I915_WRITE(aud_cntrl_st2, tmp);
6003 /* Wait for 1 vertical blank */
6004 intel_wait_for_vblank(dev, pipe);
6006 /* Set ELD valid state */
6007 tmp = I915_READ(aud_cntrl_st2);
6008 DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp);
6009 tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
6010 I915_WRITE(aud_cntrl_st2, tmp);
6011 tmp = I915_READ(aud_cntrl_st2);
6012 DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp);
6014 /* Enable HDMI mode */
6015 tmp = I915_READ(aud_config);
6016 DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp);
6017 /* clear N_programing_enable and N_value_index */
6018 tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
6019 I915_WRITE(aud_config, tmp);
6021 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
6023 eldv = AUDIO_ELD_VALID_A << (pipe * 4);
6024 intel_crtc->eld_vld = true;
6026 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
6027 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
6028 eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
6029 I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
6031 I915_WRITE(aud_config, 0);
6033 if (intel_eld_uptodate(connector,
6034 aud_cntrl_st2, eldv,
6035 aud_cntl_st, IBX_ELD_ADDRESS,
6039 i = I915_READ(aud_cntrl_st2);
6041 I915_WRITE(aud_cntrl_st2, i);
6046 i = I915_READ(aud_cntl_st);
6047 i &= ~IBX_ELD_ADDRESS;
6048 I915_WRITE(aud_cntl_st, i);
6049 i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
6050 DRM_DEBUG_DRIVER("port num:%d\n", i);
6052 len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
6053 DRM_DEBUG_DRIVER("ELD size %d\n", len);
6054 for (i = 0; i < len; i++)
6055 I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
6057 i = I915_READ(aud_cntrl_st2);
6059 I915_WRITE(aud_cntrl_st2, i);
6063 static void ironlake_write_eld(struct drm_connector *connector,
6064 struct drm_crtc *crtc)
6066 struct drm_i915_private *dev_priv = connector->dev->dev_private;
6067 uint8_t *eld = connector->eld;
6075 int pipe = to_intel_crtc(crtc)->pipe;
6077 if (HAS_PCH_IBX(connector->dev)) {
6078 hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
6079 aud_config = IBX_AUD_CFG(pipe);
6080 aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
6081 aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
6083 hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
6084 aud_config = CPT_AUD_CFG(pipe);
6085 aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
6086 aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
6089 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
6091 i = I915_READ(aud_cntl_st);
6092 i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
6094 DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
6095 /* operate blindly on all ports */
6096 eldv = IBX_ELD_VALIDB;
6097 eldv |= IBX_ELD_VALIDB << 4;
6098 eldv |= IBX_ELD_VALIDB << 8;
6100 DRM_DEBUG_DRIVER("ELD on port %c\n", 'A' + i);
6101 eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
6104 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
6105 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
6106 eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
6107 I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
6109 I915_WRITE(aud_config, 0);
6111 if (intel_eld_uptodate(connector,
6112 aud_cntrl_st2, eldv,
6113 aud_cntl_st, IBX_ELD_ADDRESS,
6117 i = I915_READ(aud_cntrl_st2);
6119 I915_WRITE(aud_cntrl_st2, i);
6124 i = I915_READ(aud_cntl_st);
6125 i &= ~IBX_ELD_ADDRESS;
6126 I915_WRITE(aud_cntl_st, i);
6128 len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
6129 DRM_DEBUG_DRIVER("ELD size %d\n", len);
6130 for (i = 0; i < len; i++)
6131 I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
6133 i = I915_READ(aud_cntrl_st2);
6135 I915_WRITE(aud_cntrl_st2, i);
6138 void intel_write_eld(struct drm_encoder *encoder,
6139 struct drm_display_mode *mode)
6141 struct drm_crtc *crtc = encoder->crtc;
6142 struct drm_connector *connector;
6143 struct drm_device *dev = encoder->dev;
6144 struct drm_i915_private *dev_priv = dev->dev_private;
6146 connector = drm_select_eld(encoder, mode);
6150 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6152 drm_get_connector_name(connector),
6153 connector->encoder->base.id,
6154 drm_get_encoder_name(connector->encoder));
6156 connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
6158 if (dev_priv->display.write_eld)
6159 dev_priv->display.write_eld(connector, crtc);
6162 /** Loads the palette/gamma unit for the CRTC with the prepared values */
6163 void intel_crtc_load_lut(struct drm_crtc *crtc)
6165 struct drm_device *dev = crtc->dev;
6166 struct drm_i915_private *dev_priv = dev->dev_private;
6167 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6168 int palreg = PALETTE(intel_crtc->pipe);
6171 /* The clocks have to be on to load the palette. */
6172 if (!crtc->enabled || !intel_crtc->active)
6175 /* use legacy palette for Ironlake */
6176 if (HAS_PCH_SPLIT(dev))
6177 palreg = LGC_PALETTE(intel_crtc->pipe);
6179 for (i = 0; i < 256; i++) {
6180 I915_WRITE(palreg + 4 * i,
6181 (intel_crtc->lut_r[i] << 16) |
6182 (intel_crtc->lut_g[i] << 8) |
6183 intel_crtc->lut_b[i]);
6187 static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
6189 struct drm_device *dev = crtc->dev;
6190 struct drm_i915_private *dev_priv = dev->dev_private;
6191 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6192 bool visible = base != 0;
6195 if (intel_crtc->cursor_visible == visible)
6198 cntl = I915_READ(_CURACNTR);
6200 /* On these chipsets we can only modify the base whilst
6201 * the cursor is disabled.
6203 I915_WRITE(_CURABASE, base);
6205 cntl &= ~(CURSOR_FORMAT_MASK);
6206 /* XXX width must be 64, stride 256 => 0x00 << 28 */
6207 cntl |= CURSOR_ENABLE |
6208 CURSOR_GAMMA_ENABLE |
6211 cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
6212 I915_WRITE(_CURACNTR, cntl);
6214 intel_crtc->cursor_visible = visible;
6217 static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
6219 struct drm_device *dev = crtc->dev;
6220 struct drm_i915_private *dev_priv = dev->dev_private;
6221 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6222 int pipe = intel_crtc->pipe;
6223 bool visible = base != 0;
6225 if (intel_crtc->cursor_visible != visible) {
6226 uint32_t cntl = I915_READ(CURCNTR(pipe));
6228 cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
6229 cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
6230 cntl |= pipe << 28; /* Connect to correct pipe */
6232 cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
6233 cntl |= CURSOR_MODE_DISABLE;
6235 I915_WRITE(CURCNTR(pipe), cntl);
6237 intel_crtc->cursor_visible = visible;
6239 /* and commit changes on next vblank */
6240 I915_WRITE(CURBASE(pipe), base);
6243 static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
6245 struct drm_device *dev = crtc->dev;
6246 struct drm_i915_private *dev_priv = dev->dev_private;
6247 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6248 int pipe = intel_crtc->pipe;
6249 bool visible = base != 0;
6251 if (intel_crtc->cursor_visible != visible) {
6252 uint32_t cntl = I915_READ(CURCNTR_IVB(pipe));
6254 cntl &= ~CURSOR_MODE;
6255 cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
6257 cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
6258 cntl |= CURSOR_MODE_DISABLE;
6260 if (IS_HASWELL(dev))
6261 cntl |= CURSOR_PIPE_CSC_ENABLE;
6262 I915_WRITE(CURCNTR_IVB(pipe), cntl);
6264 intel_crtc->cursor_visible = visible;
6266 /* and commit changes on next vblank */
6267 I915_WRITE(CURBASE_IVB(pipe), base);
6270 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
6271 static void intel_crtc_update_cursor(struct drm_crtc *crtc,
6274 struct drm_device *dev = crtc->dev;
6275 struct drm_i915_private *dev_priv = dev->dev_private;
6276 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6277 int pipe = intel_crtc->pipe;
6278 int x = intel_crtc->cursor_x;
6279 int y = intel_crtc->cursor_y;
6285 if (on && crtc->enabled && crtc->fb) {
6286 base = intel_crtc->cursor_addr;
6287 if (x > (int) crtc->fb->width)
6290 if (y > (int) crtc->fb->height)
6296 if (x + intel_crtc->cursor_width < 0)
6299 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
6302 pos |= x << CURSOR_X_SHIFT;
6305 if (y + intel_crtc->cursor_height < 0)
6308 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
6311 pos |= y << CURSOR_Y_SHIFT;
6313 visible = base != 0;
6314 if (!visible && !intel_crtc->cursor_visible)
6317 if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
6318 I915_WRITE(CURPOS_IVB(pipe), pos);
6319 ivb_update_cursor(crtc, base);
6321 I915_WRITE(CURPOS(pipe), pos);
6322 if (IS_845G(dev) || IS_I865G(dev))
6323 i845_update_cursor(crtc, base);
6325 i9xx_update_cursor(crtc, base);
6329 static int intel_crtc_cursor_set(struct drm_crtc *crtc,
6330 struct drm_file *file,
6332 uint32_t width, uint32_t height)
6334 struct drm_device *dev = crtc->dev;
6335 struct drm_i915_private *dev_priv = dev->dev_private;
6336 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6337 struct drm_i915_gem_object *obj;
6341 /* if we want to turn off the cursor ignore width and height */
6343 DRM_DEBUG_KMS("cursor off\n");
6346 mutex_lock(&dev->struct_mutex);
6350 /* Currently we only support 64x64 cursors */
6351 if (width != 64 || height != 64) {
6352 DRM_ERROR("we currently only support 64x64 cursors\n");
6356 obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
6357 if (&obj->base == NULL)
6360 if (obj->base.size < width * height * 4) {
6361 DRM_ERROR("buffer is to small\n");
6366 /* we only need to pin inside GTT if cursor is non-phy */
6367 mutex_lock(&dev->struct_mutex);
6368 if (!dev_priv->info->cursor_needs_physical) {
6369 if (obj->tiling_mode) {
6370 DRM_ERROR("cursor cannot be tiled\n");
6375 ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL);
6377 DRM_ERROR("failed to move cursor bo into the GTT\n");
6381 ret = i915_gem_object_put_fence(obj);
6383 DRM_ERROR("failed to release fence for cursor");
6387 addr = obj->gtt_offset;
6389 int align = IS_I830(dev) ? 16 * 1024 : 256;
6390 ret = i915_gem_attach_phys_object(dev, obj,
6391 (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
6394 DRM_ERROR("failed to attach phys object\n");
6397 addr = obj->phys_obj->handle->busaddr;
6401 I915_WRITE(CURSIZE, (height << 12) | width);
6404 if (intel_crtc->cursor_bo) {
6405 if (dev_priv->info->cursor_needs_physical) {
6406 if (intel_crtc->cursor_bo != obj)
6407 i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
6409 i915_gem_object_unpin(intel_crtc->cursor_bo);
6410 drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
6413 mutex_unlock(&dev->struct_mutex);
6415 intel_crtc->cursor_addr = addr;
6416 intel_crtc->cursor_bo = obj;
6417 intel_crtc->cursor_width = width;
6418 intel_crtc->cursor_height = height;
6420 intel_crtc_update_cursor(crtc, true);
6424 i915_gem_object_unpin(obj);
6426 mutex_unlock(&dev->struct_mutex);
6428 drm_gem_object_unreference_unlocked(&obj->base);
6432 static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
6434 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6436 intel_crtc->cursor_x = x;
6437 intel_crtc->cursor_y = y;
6439 intel_crtc_update_cursor(crtc, true);
6444 /** Sets the color ramps on behalf of RandR */
6445 void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
6446 u16 blue, int regno)
6448 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6450 intel_crtc->lut_r[regno] = red >> 8;
6451 intel_crtc->lut_g[regno] = green >> 8;
6452 intel_crtc->lut_b[regno] = blue >> 8;
6455 void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
6456 u16 *blue, int regno)
6458 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6460 *red = intel_crtc->lut_r[regno] << 8;
6461 *green = intel_crtc->lut_g[regno] << 8;
6462 *blue = intel_crtc->lut_b[regno] << 8;
6465 static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
6466 u16 *blue, uint32_t start, uint32_t size)
6468 int end = (start + size > 256) ? 256 : start + size, i;
6469 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6471 for (i = start; i < end; i++) {
6472 intel_crtc->lut_r[i] = red[i] >> 8;
6473 intel_crtc->lut_g[i] = green[i] >> 8;
6474 intel_crtc->lut_b[i] = blue[i] >> 8;
6477 intel_crtc_load_lut(crtc);
6481 * Get a pipe with a simple mode set on it for doing load-based monitor
6484 * It will be up to the load-detect code to adjust the pipe as appropriate for
6485 * its requirements. The pipe will be connected to no other encoders.
6487 * Currently this code will only succeed if there is a pipe with no encoders
6488 * configured for it. In the future, it could choose to temporarily disable
6489 * some outputs to free up a pipe for its use.
6491 * \return crtc, or NULL if no pipes are available.
6494 /* VESA 640x480x72Hz mode to set on the pipe */
6495 static struct drm_display_mode load_detect_mode = {
6496 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
6497 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
6500 static struct drm_framebuffer *
6501 intel_framebuffer_create(struct drm_device *dev,
6502 struct drm_mode_fb_cmd2 *mode_cmd,
6503 struct drm_i915_gem_object *obj)
6505 struct intel_framebuffer *intel_fb;
6508 intel_fb = kmalloc(sizeof(*intel_fb), M_DRM, M_WAITOK | M_ZERO);
6510 drm_gem_object_unreference_unlocked(&obj->base);
6511 return ERR_PTR(-ENOMEM);
6514 ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
6516 drm_gem_object_unreference_unlocked(&obj->base);
6517 kfree(intel_fb, M_DRM);
6518 return ERR_PTR(ret);
6521 return &intel_fb->base;
6525 intel_framebuffer_pitch_for_width(int width, int bpp)
6527 u32 pitch = DIV_ROUND_UP(width * bpp, 8);
6528 return ALIGN(pitch, 64);
6532 intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
6534 u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
6535 return ALIGN(pitch * mode->vdisplay, PAGE_SIZE);
6538 static struct drm_framebuffer *
6539 intel_framebuffer_create_for_mode(struct drm_device *dev,
6540 struct drm_display_mode *mode,
6543 struct drm_i915_gem_object *obj;
6544 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
6546 obj = i915_gem_alloc_object(dev,
6547 intel_framebuffer_size_for_mode(mode, bpp));
6549 return ERR_PTR(-ENOMEM);
6551 mode_cmd.width = mode->hdisplay;
6552 mode_cmd.height = mode->vdisplay;
6553 mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
6555 mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
6557 return intel_framebuffer_create(dev, &mode_cmd, obj);
6560 static struct drm_framebuffer *
6561 mode_fits_in_fbdev(struct drm_device *dev,
6562 struct drm_display_mode *mode)
6564 struct drm_i915_private *dev_priv = dev->dev_private;
6565 struct drm_i915_gem_object *obj;
6566 struct drm_framebuffer *fb;
6568 if (dev_priv->fbdev == NULL)
6571 obj = dev_priv->fbdev->ifb.obj;
6575 fb = &dev_priv->fbdev->ifb.base;
6576 if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
6577 fb->bits_per_pixel))
6580 if (obj->base.size < mode->vdisplay * fb->pitches[0])
6586 bool intel_get_load_detect_pipe(struct drm_connector *connector,
6587 struct drm_display_mode *mode,
6588 struct intel_load_detect_pipe *old)
6590 struct intel_crtc *intel_crtc;
6591 struct intel_encoder *intel_encoder =
6592 intel_attached_encoder(connector);
6593 struct drm_crtc *possible_crtc;
6594 struct drm_encoder *encoder = &intel_encoder->base;
6595 struct drm_crtc *crtc = NULL;
6596 struct drm_device *dev = encoder->dev;
6597 struct drm_framebuffer *fb;
6600 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6601 connector->base.id, drm_get_connector_name(connector),
6602 encoder->base.id, drm_get_encoder_name(encoder));
6605 * Algorithm gets a little messy:
6607 * - if the connector already has an assigned crtc, use it (but make
6608 * sure it's on first)
6610 * - try to find the first unused crtc that can drive this connector,
6611 * and use that if we find one
6614 /* See if we already have a CRTC for this connector */
6615 if (encoder->crtc) {
6616 crtc = encoder->crtc;
6618 mutex_lock(&crtc->mutex);
6620 old->dpms_mode = connector->dpms;
6621 old->load_detect_temp = false;
6623 /* Make sure the crtc and connector are running */
6624 if (connector->dpms != DRM_MODE_DPMS_ON)
6625 connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
6630 /* Find an unused one (if possible) */
6631 list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
6633 if (!(encoder->possible_crtcs & (1 << i)))
6635 if (!possible_crtc->enabled) {
6636 crtc = possible_crtc;
6642 * If we didn't find an unused CRTC, don't use any.
6645 DRM_DEBUG_KMS("no pipe available for load-detect\n");
6649 mutex_lock(&crtc->mutex);
6650 intel_encoder->new_crtc = to_intel_crtc(crtc);
6651 to_intel_connector(connector)->new_encoder = intel_encoder;
6653 intel_crtc = to_intel_crtc(crtc);
6654 old->dpms_mode = connector->dpms;
6655 old->load_detect_temp = true;
6656 old->release_fb = NULL;
6659 mode = &load_detect_mode;
6661 /* We need a framebuffer large enough to accommodate all accesses
6662 * that the plane may generate whilst we perform load detection.
6663 * We can not rely on the fbcon either being present (we get called
6664 * during its initialisation to detect all boot displays, or it may
6665 * not even exist) or that it is large enough to satisfy the
6668 fb = mode_fits_in_fbdev(dev, mode);
6670 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
6671 fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
6672 old->release_fb = fb;
6674 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
6676 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
6677 mutex_unlock(&crtc->mutex);
6681 if (intel_set_mode(crtc, mode, 0, 0, fb)) {
6682 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
6683 if (old->release_fb)
6684 old->release_fb->funcs->destroy(old->release_fb);
6685 mutex_unlock(&crtc->mutex);
6689 /* let the connector get through one full cycle before testing */
6690 intel_wait_for_vblank(dev, intel_crtc->pipe);
6694 void intel_release_load_detect_pipe(struct drm_connector *connector,
6695 struct intel_load_detect_pipe *old)
6697 struct intel_encoder *intel_encoder =
6698 intel_attached_encoder(connector);
6699 struct drm_encoder *encoder = &intel_encoder->base;
6700 struct drm_crtc *crtc = encoder->crtc;
6702 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6703 connector->base.id, drm_get_connector_name(connector),
6704 encoder->base.id, drm_get_encoder_name(encoder));
6706 if (old->load_detect_temp) {
6707 to_intel_connector(connector)->new_encoder = NULL;
6708 intel_encoder->new_crtc = NULL;
6709 intel_set_mode(crtc, NULL, 0, 0, NULL);
6711 if (old->release_fb) {
6712 drm_framebuffer_unregister_private(old->release_fb);
6713 drm_framebuffer_unreference(old->release_fb);
6716 mutex_unlock(&crtc->mutex);
6720 /* Switch crtc and encoder back off if necessary */
6721 if (old->dpms_mode != DRM_MODE_DPMS_ON)
6722 connector->funcs->dpms(connector, old->dpms_mode);
6724 mutex_unlock(&crtc->mutex);
6727 /* Returns the clock of the currently programmed mode of the given pipe. */
6728 static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
6730 struct drm_i915_private *dev_priv = dev->dev_private;
6731 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6732 int pipe = intel_crtc->pipe;
6733 u32 dpll = I915_READ(DPLL(pipe));
6735 intel_clock_t clock;
6737 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
6738 fp = I915_READ(FP0(pipe));
6740 fp = I915_READ(FP1(pipe));
6742 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
6743 if (IS_PINEVIEW(dev)) {
6744 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
6745 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
6747 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
6748 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
6751 if (!IS_GEN2(dev)) {
6752 if (IS_PINEVIEW(dev))
6753 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
6754 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
6756 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
6757 DPLL_FPA01_P1_POST_DIV_SHIFT);
6759 switch (dpll & DPLL_MODE_MASK) {
6760 case DPLLB_MODE_DAC_SERIAL:
6761 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
6764 case DPLLB_MODE_LVDS:
6765 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
6769 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
6770 "mode\n", (int)(dpll & DPLL_MODE_MASK));
6774 /* XXX: Handle the 100Mhz refclk */
6775 intel_clock(dev, 96000, &clock);
6777 bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
6780 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
6781 DPLL_FPA01_P1_POST_DIV_SHIFT);
6784 if ((dpll & PLL_REF_INPUT_MASK) ==
6785 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
6786 /* XXX: might not be 66MHz */
6787 intel_clock(dev, 66000, &clock);
6789 intel_clock(dev, 48000, &clock);
6791 if (dpll & PLL_P1_DIVIDE_BY_TWO)
6794 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
6795 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
6797 if (dpll & PLL_P2_DIVIDE_BY_4)
6802 intel_clock(dev, 48000, &clock);
6806 /* XXX: It would be nice to validate the clocks, but we can't reuse
6807 * i830PllIsValid() because it relies on the xf86_config connector
6808 * configuration being accurate, which it isn't necessarily.
6814 /** Returns the currently programmed mode of the given pipe. */
6815 struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
6816 struct drm_crtc *crtc)
6818 struct drm_i915_private *dev_priv = dev->dev_private;
6819 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6820 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
6821 struct drm_display_mode *mode;
6822 int htot = I915_READ(HTOTAL(cpu_transcoder));
6823 int hsync = I915_READ(HSYNC(cpu_transcoder));
6824 int vtot = I915_READ(VTOTAL(cpu_transcoder));
6825 int vsync = I915_READ(VSYNC(cpu_transcoder));
6827 mode = kmalloc(sizeof(*mode), M_DRM, M_WAITOK | M_ZERO);
6831 mode->clock = intel_crtc_clock_get(dev, crtc);
6832 mode->hdisplay = (htot & 0xffff) + 1;
6833 mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
6834 mode->hsync_start = (hsync & 0xffff) + 1;
6835 mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
6836 mode->vdisplay = (vtot & 0xffff) + 1;
6837 mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
6838 mode->vsync_start = (vsync & 0xffff) + 1;
6839 mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
6841 drm_mode_set_name(mode);
6846 static void intel_increase_pllclock(struct drm_crtc *crtc)
6848 struct drm_device *dev = crtc->dev;
6849 drm_i915_private_t *dev_priv = dev->dev_private;
6850 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6851 int pipe = intel_crtc->pipe;
6852 int dpll_reg = DPLL(pipe);
6855 if (HAS_PCH_SPLIT(dev))
6858 if (!dev_priv->lvds_downclock_avail)
6861 dpll = I915_READ(dpll_reg);
6862 if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
6863 DRM_DEBUG_DRIVER("upclocking LVDS\n");
6865 assert_panel_unlocked(dev_priv, pipe);
6867 dpll &= ~DISPLAY_RATE_SELECT_FPA1;
6868 I915_WRITE(dpll_reg, dpll);
6869 intel_wait_for_vblank(dev, pipe);
6871 dpll = I915_READ(dpll_reg);
6872 if (dpll & DISPLAY_RATE_SELECT_FPA1)
6873 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
6877 static void intel_decrease_pllclock(struct drm_crtc *crtc)
6879 struct drm_device *dev = crtc->dev;
6880 drm_i915_private_t *dev_priv = dev->dev_private;
6881 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6883 if (HAS_PCH_SPLIT(dev))
6886 if (!dev_priv->lvds_downclock_avail)
6890 * Since this is called by a timer, we should never get here in
6893 if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
6894 int pipe = intel_crtc->pipe;
6895 int dpll_reg = DPLL(pipe);
6898 DRM_DEBUG_DRIVER("downclocking LVDS\n");
6900 assert_panel_unlocked(dev_priv, pipe);
6902 dpll = I915_READ(dpll_reg);
6903 dpll |= DISPLAY_RATE_SELECT_FPA1;
6904 I915_WRITE(dpll_reg, dpll);
6905 intel_wait_for_vblank(dev, pipe);
6906 dpll = I915_READ(dpll_reg);
6907 if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
6908 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
6912 void intel_mark_busy(struct drm_device *dev)
6914 i915_update_gfx_val(dev->dev_private);
6917 void intel_mark_idle(struct drm_device *dev)
6919 struct drm_crtc *crtc;
6921 if (!i915_powersave)
6924 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
6928 intel_decrease_pllclock(crtc);
6932 void intel_mark_fb_busy(struct drm_i915_gem_object *obj)
6934 struct drm_device *dev = obj->base.dev;
6935 struct drm_crtc *crtc;
6937 if (!i915_powersave)
6940 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
6944 if (to_intel_framebuffer(crtc->fb)->obj == obj)
6945 intel_increase_pllclock(crtc);
6949 static void intel_crtc_destroy(struct drm_crtc *crtc)
6951 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6952 struct drm_device *dev = crtc->dev;
6953 struct intel_unpin_work *work;
6955 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
6956 work = intel_crtc->unpin_work;
6957 intel_crtc->unpin_work = NULL;
6958 lockmgr(&dev->event_lock, LK_RELEASE);
6961 cancel_work_sync(&work->work);
6965 drm_crtc_cleanup(crtc);
6967 drm_free(intel_crtc, M_DRM);
6970 static void intel_unpin_work_fn(struct work_struct *__work)
6972 struct intel_unpin_work *work =
6973 container_of(__work, struct intel_unpin_work, work);
6974 struct drm_device *dev = work->crtc->dev;
6976 mutex_lock(&dev->struct_mutex);
6977 intel_unpin_fb_obj(work->old_fb_obj);
6978 drm_gem_object_unreference(&work->pending_flip_obj->base);
6979 drm_gem_object_unreference(&work->old_fb_obj->base);
6981 intel_update_fbc(dev);
6982 mutex_unlock(&dev->struct_mutex);
6984 BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
6985 atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
6987 drm_free(work, M_DRM);
6990 static void do_intel_finish_page_flip(struct drm_device *dev,
6991 struct drm_crtc *crtc)
6993 drm_i915_private_t *dev_priv = dev->dev_private;
6994 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6995 struct intel_unpin_work *work;
6996 struct drm_i915_gem_object *obj;
6998 /* Ignore early vblank irqs */
6999 if (intel_crtc == NULL)
7002 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
7003 work = intel_crtc->unpin_work;
7005 /* Ensure we don't miss a work->pending update ... */
7008 if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
7009 lockmgr(&dev->event_lock, LK_RELEASE);
7013 /* and that the unpin work is consistent wrt ->pending. */
7016 intel_crtc->unpin_work = NULL;
7019 drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
7021 drm_vblank_put(dev, intel_crtc->pipe);
7023 lockmgr(&dev->event_lock, LK_RELEASE);
7025 obj = work->old_fb_obj;
7027 wake_up_all(&dev_priv->pending_flip_queue);
7029 queue_work(dev_priv->wq, &work->work);
7032 void intel_finish_page_flip(struct drm_device *dev, int pipe)
7034 drm_i915_private_t *dev_priv = dev->dev_private;
7035 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
7037 do_intel_finish_page_flip(dev, crtc);
7040 void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
7042 drm_i915_private_t *dev_priv = dev->dev_private;
7043 struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
7045 do_intel_finish_page_flip(dev, crtc);
7048 void intel_prepare_page_flip(struct drm_device *dev, int plane)
7050 drm_i915_private_t *dev_priv = dev->dev_private;
7051 struct intel_crtc *intel_crtc =
7052 to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
7054 /* NB: An MMIO update of the plane base pointer will also
7055 * generate a page-flip completion irq, i.e. every modeset
7056 * is also accompanied by a spurious intel_prepare_page_flip().
7058 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
7059 if (intel_crtc->unpin_work)
7060 atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
7061 lockmgr(&dev->event_lock, LK_RELEASE);
7064 inline static void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
7066 /* Ensure that the work item is consistent when activating it ... */
7068 atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
7069 /* and that it is marked active as soon as the irq could fire. */
7073 static int intel_gen2_queue_flip(struct drm_device *dev,
7074 struct drm_crtc *crtc,
7075 struct drm_framebuffer *fb,
7076 struct drm_i915_gem_object *obj)
7078 struct drm_i915_private *dev_priv = dev->dev_private;
7079 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7081 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7084 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7088 ret = intel_ring_begin(ring, 6);
7092 /* Can't queue multiple flips, so wait for the previous
7093 * one to finish before executing the next.
7095 if (intel_crtc->plane)
7096 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
7098 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
7099 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
7100 intel_ring_emit(ring, MI_NOOP);
7101 intel_ring_emit(ring, MI_DISPLAY_FLIP |
7102 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7103 intel_ring_emit(ring, fb->pitches[0]);
7104 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7105 intel_ring_emit(ring, 0); /* aux display base address, unused */
7107 intel_mark_page_flip_active(intel_crtc);
7108 intel_ring_advance(ring);
7112 intel_unpin_fb_obj(obj);
7117 static int intel_gen3_queue_flip(struct drm_device *dev,
7118 struct drm_crtc *crtc,
7119 struct drm_framebuffer *fb,
7120 struct drm_i915_gem_object *obj)
7122 struct drm_i915_private *dev_priv = dev->dev_private;
7123 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7125 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7128 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7132 ret = intel_ring_begin(ring, 6);
7136 if (intel_crtc->plane)
7137 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
7139 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
7140 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
7141 intel_ring_emit(ring, MI_NOOP);
7142 intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
7143 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7144 intel_ring_emit(ring, fb->pitches[0]);
7145 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7146 intel_ring_emit(ring, MI_NOOP);
7148 intel_mark_page_flip_active(intel_crtc);
7149 intel_ring_advance(ring);
7153 intel_unpin_fb_obj(obj);
7158 static int intel_gen4_queue_flip(struct drm_device *dev,
7159 struct drm_crtc *crtc,
7160 struct drm_framebuffer *fb,
7161 struct drm_i915_gem_object *obj)
7163 struct drm_i915_private *dev_priv = dev->dev_private;
7164 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7165 uint32_t pf, pipesrc;
7166 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7169 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7173 ret = intel_ring_begin(ring, 4);
7177 /* i965+ uses the linear or tiled offsets from the
7178 * Display Registers (which do not change across a page-flip)
7179 * so we need only reprogram the base address.
7181 intel_ring_emit(ring, MI_DISPLAY_FLIP |
7182 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7183 intel_ring_emit(ring, fb->pitches[0]);
7184 intel_ring_emit(ring,
7185 (obj->gtt_offset + intel_crtc->dspaddr_offset) |
7188 /* XXX Enabling the panel-fitter across page-flip is so far
7189 * untested on non-native modes, so ignore it for now.
7190 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
7193 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
7194 intel_ring_emit(ring, pf | pipesrc);
7196 intel_mark_page_flip_active(intel_crtc);
7197 intel_ring_advance(ring);
7201 intel_unpin_fb_obj(obj);
7206 static int intel_gen6_queue_flip(struct drm_device *dev,
7207 struct drm_crtc *crtc,
7208 struct drm_framebuffer *fb,
7209 struct drm_i915_gem_object *obj)
7211 struct drm_i915_private *dev_priv = dev->dev_private;
7212 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7213 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7214 uint32_t pf, pipesrc;
7217 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7221 ret = intel_ring_begin(ring, 4);
7225 intel_ring_emit(ring, MI_DISPLAY_FLIP |
7226 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7227 intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
7228 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7230 /* Contrary to the suggestions in the documentation,
7231 * "Enable Panel Fitter" does not seem to be required when page
7232 * flipping with a non-native mode, and worse causes a normal
7234 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
7237 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
7238 intel_ring_emit(ring, pf | pipesrc);
7240 intel_mark_page_flip_active(intel_crtc);
7241 intel_ring_advance(ring);
7245 intel_unpin_fb_obj(obj);
7251 * On gen7 we currently use the blit ring because (in early silicon at least)
7252 * the render ring doesn't give us interrpts for page flip completion, which
7253 * means clients will hang after the first flip is queued. Fortunately the
7254 * blit ring generates interrupts properly, so use it instead.
7256 static int intel_gen7_queue_flip(struct drm_device *dev,
7257 struct drm_crtc *crtc,
7258 struct drm_framebuffer *fb,
7259 struct drm_i915_gem_object *obj)
7261 struct drm_i915_private *dev_priv = dev->dev_private;
7262 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7263 struct intel_ring_buffer *ring = &dev_priv->ring[BCS];
7264 uint32_t plane_bit = 0;
7267 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7271 switch(intel_crtc->plane) {
7273 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
7276 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
7279 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
7282 WARN_ONCE(1, "unknown plane in flip command\n");
7287 ret = intel_ring_begin(ring, 4);
7291 intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
7292 intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
7293 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7294 intel_ring_emit(ring, (MI_NOOP));
7296 intel_mark_page_flip_active(intel_crtc);
7297 intel_ring_advance(ring);
7301 intel_unpin_fb_obj(obj);
7306 static int intel_default_queue_flip(struct drm_device *dev,
7307 struct drm_crtc *crtc,
7308 struct drm_framebuffer *fb,
7309 struct drm_i915_gem_object *obj)
7314 static int intel_crtc_page_flip(struct drm_crtc *crtc,
7315 struct drm_framebuffer *fb,
7316 struct drm_pending_vblank_event *event)
7318 struct drm_device *dev = crtc->dev;
7319 struct drm_i915_private *dev_priv = dev->dev_private;
7320 struct drm_framebuffer *old_fb = crtc->fb;
7321 struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
7322 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7323 struct intel_unpin_work *work;
7326 /* Can't change pixel format via MI display flips. */
7327 if (fb->pixel_format != crtc->fb->pixel_format)
7331 * TILEOFF/LINOFF registers can't be changed via MI display flips.
7332 * Note that pitch changes could also affect these register.
7334 if (INTEL_INFO(dev)->gen > 3 &&
7335 (fb->offsets[0] != crtc->fb->offsets[0] ||
7336 fb->pitches[0] != crtc->fb->pitches[0]))
7339 work = kmalloc(sizeof *work, M_DRM, M_WAITOK | M_ZERO);
7343 work->event = event;
7345 work->old_fb_obj = to_intel_framebuffer(old_fb)->obj;
7346 INIT_WORK(&work->work, intel_unpin_work_fn);
7348 ret = drm_vblank_get(dev, intel_crtc->pipe);
7352 /* We borrow the event spin lock for protecting unpin_work */
7353 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
7354 if (intel_crtc->unpin_work) {
7355 lockmgr(&dev->event_lock, LK_RELEASE);
7356 drm_free(work, M_DRM);
7357 drm_vblank_put(dev, intel_crtc->pipe);
7359 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
7362 intel_crtc->unpin_work = work;
7363 lockmgr(&dev->event_lock, LK_RELEASE);
7365 if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
7366 flush_workqueue(dev_priv->wq);
7368 ret = i915_mutex_lock_interruptible(dev);
7372 /* Reference the objects for the scheduled work. */
7373 drm_gem_object_reference(&work->old_fb_obj->base);
7374 drm_gem_object_reference(&obj->base);
7378 work->pending_flip_obj = obj;
7380 work->enable_stall_check = true;
7382 atomic_inc(&intel_crtc->unpin_work_count);
7383 intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
7385 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
7387 goto cleanup_pending;
7389 intel_disable_fbc(dev);
7390 intel_mark_fb_busy(obj);
7391 mutex_unlock(&dev->struct_mutex);
7396 atomic_dec(&intel_crtc->unpin_work_count);
7398 drm_gem_object_unreference(&work->old_fb_obj->base);
7399 drm_gem_object_unreference(&obj->base);
7400 mutex_unlock(&dev->struct_mutex);
7403 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
7404 intel_crtc->unpin_work = NULL;
7405 lockmgr(&dev->event_lock, LK_RELEASE);
7407 drm_vblank_put(dev, intel_crtc->pipe);
7409 drm_free(work, M_DRM);
7414 static struct drm_crtc_helper_funcs intel_helper_funcs = {
7415 .mode_set_base_atomic = intel_pipe_set_base_atomic,
7416 .load_lut = intel_crtc_load_lut,
7417 .disable = intel_crtc_noop,
7420 bool intel_encoder_check_is_cloned(struct intel_encoder *encoder)
7422 struct intel_encoder *other_encoder;
7423 struct drm_crtc *crtc = &encoder->new_crtc->base;
7428 list_for_each_entry(other_encoder,
7429 &crtc->dev->mode_config.encoder_list,
7432 if (&other_encoder->new_crtc->base != crtc ||
7433 encoder == other_encoder)
7442 static bool intel_encoder_crtc_ok(struct drm_encoder *encoder,
7443 struct drm_crtc *crtc)
7445 struct drm_device *dev;
7446 struct drm_crtc *tmp;
7449 WARN(!crtc, "checking null crtc?\n");
7450 /* profmakx: this is to prevent the kernel from panicing */
7457 list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
7463 if (encoder->possible_crtcs & crtc_mask)
7469 * intel_modeset_update_staged_output_state
7471 * Updates the staged output configuration state, e.g. after we've read out the
7474 static void intel_modeset_update_staged_output_state(struct drm_device *dev)
7476 struct intel_encoder *encoder;
7477 struct intel_connector *connector;
7479 list_for_each_entry(connector, &dev->mode_config.connector_list,
7481 connector->new_encoder =
7482 to_intel_encoder(connector->base.encoder);
7485 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7488 to_intel_crtc(encoder->base.crtc);
7493 * intel_modeset_commit_output_state
7495 * This function copies the stage display pipe configuration to the real one.
7497 static void intel_modeset_commit_output_state(struct drm_device *dev)
7499 struct intel_encoder *encoder;
7500 struct intel_connector *connector;
7502 list_for_each_entry(connector, &dev->mode_config.connector_list,
7504 connector->base.encoder = &connector->new_encoder->base;
7507 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7509 encoder->base.crtc = &encoder->new_crtc->base;
7513 static struct drm_display_mode *
7514 intel_modeset_adjusted_mode(struct drm_crtc *crtc,
7515 struct drm_display_mode *mode)
7517 struct drm_device *dev = crtc->dev;
7518 struct drm_display_mode *adjusted_mode;
7519 struct drm_encoder_helper_funcs *encoder_funcs;
7520 struct intel_encoder *encoder;
7522 adjusted_mode = drm_mode_duplicate(dev, mode);
7524 return ERR_PTR(-ENOMEM);
7526 /* Pass our mode to the connectors and the CRTC to give them a chance to
7527 * adjust it according to limitations or connector properties, and also
7528 * a chance to reject the mode entirely.
7530 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7533 if (&encoder->new_crtc->base != crtc)
7535 encoder_funcs = encoder->base.helper_private;
7536 if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
7538 DRM_DEBUG_KMS("Encoder fixup failed\n");
7543 if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
7544 DRM_DEBUG_KMS("CRTC fixup failed\n");
7547 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
7549 return adjusted_mode;
7551 drm_mode_destroy(dev, adjusted_mode);
7552 return ERR_PTR(-EINVAL);
7555 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
7556 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
7558 intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
7559 unsigned *prepare_pipes, unsigned *disable_pipes)
7561 struct intel_crtc *intel_crtc;
7562 struct drm_device *dev = crtc->dev;
7563 struct intel_encoder *encoder;
7564 struct intel_connector *connector;
7565 struct drm_crtc *tmp_crtc;
7567 *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
7569 /* Check which crtcs have changed outputs connected to them, these need
7570 * to be part of the prepare_pipes mask. We don't (yet) support global
7571 * modeset across multiple crtcs, so modeset_pipes will only have one
7572 * bit set at most. */
7573 list_for_each_entry(connector, &dev->mode_config.connector_list,
7575 if (connector->base.encoder == &connector->new_encoder->base)
7578 if (connector->base.encoder) {
7579 tmp_crtc = connector->base.encoder->crtc;
7581 *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
7584 if (connector->new_encoder)
7586 1 << connector->new_encoder->new_crtc->pipe;
7589 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7591 if (encoder->base.crtc == &encoder->new_crtc->base)
7594 if (encoder->base.crtc) {
7595 tmp_crtc = encoder->base.crtc;
7597 *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
7600 if (encoder->new_crtc)
7601 *prepare_pipes |= 1 << encoder->new_crtc->pipe;
7604 /* Check for any pipes that will be fully disabled ... */
7605 list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
7609 /* Don't try to disable disabled crtcs. */
7610 if (!intel_crtc->base.enabled)
7613 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7615 if (encoder->new_crtc == intel_crtc)
7620 *disable_pipes |= 1 << intel_crtc->pipe;
7624 /* set_mode is also used to update properties on life display pipes. */
7625 intel_crtc = to_intel_crtc(crtc);
7627 *prepare_pipes |= 1 << intel_crtc->pipe;
7630 * For simplicity do a full modeset on any pipe where the output routing
7631 * changed. We could be more clever, but that would require us to be
7632 * more careful with calling the relevant encoder->mode_set functions.
7635 *modeset_pipes = *prepare_pipes;
7637 /* ... and mask these out. */
7638 *modeset_pipes &= ~(*disable_pipes);
7639 *prepare_pipes &= ~(*disable_pipes);
7642 * HACK: We don't (yet) fully support global modesets. intel_set_config
7643 * obies this rule, but the modeset restore mode of
7644 * intel_modeset_setup_hw_state does not.
7646 *modeset_pipes &= 1 << intel_crtc->pipe;
7647 *prepare_pipes &= 1 << intel_crtc->pipe;
7650 static bool intel_crtc_in_use(struct drm_crtc *crtc)
7652 struct drm_encoder *encoder;
7653 struct drm_device *dev = crtc->dev;
7655 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
7656 if (encoder->crtc == crtc)
7663 intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
7665 struct intel_encoder *intel_encoder;
7666 struct intel_crtc *intel_crtc;
7667 struct drm_connector *connector;
7669 list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
7671 if (!intel_encoder->base.crtc)
7674 intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
7676 if (prepare_pipes & (1 << intel_crtc->pipe))
7677 intel_encoder->connectors_active = false;
7680 intel_modeset_commit_output_state(dev);
7682 /* Update computed state. */
7683 list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
7685 intel_crtc->base.enabled = intel_crtc_in_use(&intel_crtc->base);
7688 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
7689 if (!connector->encoder || !connector->encoder->crtc)
7692 intel_crtc = to_intel_crtc(connector->encoder->crtc);
7694 if (prepare_pipes & (1 << intel_crtc->pipe)) {
7695 struct drm_property *dpms_property =
7696 dev->mode_config.dpms_property;
7698 connector->dpms = DRM_MODE_DPMS_ON;
7699 drm_object_property_set_value(&connector->base,
7703 intel_encoder = to_intel_encoder(connector->encoder);
7704 intel_encoder->connectors_active = true;
7710 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
7711 list_for_each_entry((intel_crtc), \
7712 &(dev)->mode_config.crtc_list, \
7714 if (mask & (1 <<(intel_crtc)->pipe)) \
7717 intel_modeset_check_state(struct drm_device *dev)
7719 struct intel_crtc *crtc;
7720 struct intel_encoder *encoder;
7721 struct intel_connector *connector;
7723 list_for_each_entry(connector, &dev->mode_config.connector_list,
7725 /* This also checks the encoder/connector hw state with the
7726 * ->get_hw_state callbacks. */
7727 intel_connector_check_state(connector);
7729 WARN(&connector->new_encoder->base != connector->base.encoder,
7730 "connector's staged encoder doesn't match current encoder\n");
7733 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7735 bool enabled = false;
7736 bool active = false;
7737 enum i915_pipe pipe, tracked_pipe;
7739 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
7740 encoder->base.base.id,
7741 drm_get_encoder_name(&encoder->base));
7743 WARN(&encoder->new_crtc->base != encoder->base.crtc,
7744 "encoder's stage crtc doesn't match current crtc\n");
7745 WARN(encoder->connectors_active && !encoder->base.crtc,
7746 "encoder's active_connectors set, but no crtc\n");
7748 list_for_each_entry(connector, &dev->mode_config.connector_list,
7750 if (connector->base.encoder != &encoder->base)
7753 if (connector->base.dpms != DRM_MODE_DPMS_OFF)
7756 WARN(!!encoder->base.crtc != enabled,
7757 "encoder's enabled state mismatch "
7758 "(expected %i, found %i)\n",
7759 !!encoder->base.crtc, enabled);
7760 WARN(active && !encoder->base.crtc,
7761 "active encoder with no crtc\n");
7763 WARN(encoder->connectors_active != active,
7764 "encoder's computed active state doesn't match tracked active state "
7765 "(expected %i, found %i)\n", active, encoder->connectors_active);
7767 active = encoder->get_hw_state(encoder, &pipe);
7768 WARN(active != encoder->connectors_active,
7769 "encoder's hw state doesn't match sw tracking "
7770 "(expected %i, found %i)\n",
7771 encoder->connectors_active, active);
7773 if (!encoder->base.crtc)
7776 tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
7777 WARN(active && pipe != tracked_pipe,
7778 "active encoder's pipe doesn't match"
7779 "(expected %i, found %i)\n",
7780 tracked_pipe, pipe);
7784 list_for_each_entry(crtc, &dev->mode_config.crtc_list,
7786 bool enabled = false;
7787 bool active = false;
7789 DRM_DEBUG_KMS("[CRTC:%d]\n",
7790 crtc->base.base.id);
7792 WARN(crtc->active && !crtc->base.enabled,
7793 "active crtc, but not enabled in sw tracking\n");
7795 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7797 if (encoder->base.crtc != &crtc->base)
7800 if (encoder->connectors_active)
7803 WARN(active != crtc->active,
7804 "crtc's computed active state doesn't match tracked active state "
7805 "(expected %i, found %i)\n", active, crtc->active);
7806 WARN(enabled != crtc->base.enabled,
7807 "crtc's computed enabled state doesn't match tracked enabled state "
7808 "(expected %i, found %i)\n", enabled, crtc->base.enabled);
7810 assert_pipe(dev->dev_private, crtc->pipe, crtc->active);
7814 static int __intel_set_mode(struct drm_crtc *crtc,
7815 struct drm_display_mode *mode,
7816 int x, int y, struct drm_framebuffer *fb)
7818 struct drm_device *dev = crtc->dev;
7819 drm_i915_private_t *dev_priv = dev->dev_private;
7820 struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode;
7821 struct intel_crtc *intel_crtc;
7822 unsigned disable_pipes, prepare_pipes, modeset_pipes;
7825 saved_mode = kmalloc(2 * sizeof(*saved_mode), M_DRM, M_WAITOK);
7828 saved_hwmode = saved_mode + 1;
7830 intel_modeset_affected_pipes(crtc, &modeset_pipes,
7831 &prepare_pipes, &disable_pipes);
7833 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
7834 modeset_pipes, prepare_pipes, disable_pipes);
7836 for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
7837 intel_crtc_disable(&intel_crtc->base);
7839 *saved_hwmode = crtc->hwmode;
7840 *saved_mode = crtc->mode;
7842 /* Hack: Because we don't (yet) support global modeset on multiple
7843 * crtcs, we don't keep track of the new mode for more than one crtc.
7844 * Hence simply check whether any bit is set in modeset_pipes in all the
7845 * pieces of code that are not yet converted to deal with mutliple crtcs
7846 * changing their mode at the same time. */
7847 adjusted_mode = NULL;
7848 if (modeset_pipes) {
7849 adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
7850 if (IS_ERR(adjusted_mode)) {
7851 ret = PTR_ERR(adjusted_mode);
7856 for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
7857 if (intel_crtc->base.enabled)
7858 dev_priv->display.crtc_disable(&intel_crtc->base);
7861 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
7862 * to set it here already despite that we pass it down the callchain.
7867 /* Only after disabling all output pipelines that will be changed can we
7868 * update the the output configuration. */
7869 intel_modeset_update_state(dev, prepare_pipes);
7871 if (dev_priv->display.modeset_global_resources)
7872 dev_priv->display.modeset_global_resources(dev);
7874 /* Set up the DPLL and any encoders state that needs to adjust or depend
7877 for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
7878 ret = intel_crtc_mode_set(&intel_crtc->base,
7879 mode, adjusted_mode,
7885 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7886 for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
7887 dev_priv->display.crtc_enable(&intel_crtc->base);
7889 if (modeset_pipes) {
7890 /* Store real post-adjustment hardware mode. */
7891 crtc->hwmode = *adjusted_mode;
7893 /* Calculate and store various constants which
7894 * are later needed by vblank and swap-completion
7895 * timestamping. They are derived from true hwmode.
7897 drm_calc_timestamping_constants(crtc);
7900 /* FIXME: add subpixel order */
7902 drm_mode_destroy(dev, adjusted_mode);
7903 if (ret && crtc->enabled) {
7904 crtc->hwmode = *saved_hwmode;
7905 crtc->mode = *saved_mode;
7909 kfree(saved_mode, M_DRM);
7913 int intel_set_mode(struct drm_crtc *crtc,
7914 struct drm_display_mode *mode,
7915 int x, int y, struct drm_framebuffer *fb)
7919 ret = __intel_set_mode(crtc, mode, x, y, fb);
7922 intel_modeset_check_state(crtc->dev);
7927 void intel_crtc_restore_mode(struct drm_crtc *crtc)
7929 intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb);
7932 #undef for_each_intel_crtc_masked
7934 static void intel_set_config_free(struct intel_set_config *config)
7939 drm_free(config->save_connector_encoders, M_DRM);
7940 drm_free(config->save_encoder_crtcs, M_DRM);
7941 drm_free(config, M_DRM);
7944 static int intel_set_config_save_state(struct drm_device *dev,
7945 struct intel_set_config *config)
7947 struct drm_encoder *encoder;
7948 struct drm_connector *connector;
7951 config->save_encoder_crtcs =
7952 kmalloc(dev->mode_config.num_encoder *
7953 sizeof(struct drm_crtc *), M_DRM, M_WAITOK | M_ZERO );
7954 if (!config->save_encoder_crtcs)
7957 config->save_connector_encoders =
7958 kmalloc(dev->mode_config.num_connector *
7959 sizeof(struct drm_encoder *), M_DRM, M_WAITOK | M_ZERO );
7960 if (!config->save_connector_encoders)
7963 /* Copy data. Note that driver private data is not affected.
7964 * Should anything bad happen only the expected state is
7965 * restored, not the drivers personal bookkeeping.
7968 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
7969 config->save_encoder_crtcs[count++] = encoder->crtc;
7973 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
7974 config->save_connector_encoders[count++] = connector->encoder;
7980 static void intel_set_config_restore_state(struct drm_device *dev,
7981 struct intel_set_config *config)
7983 struct intel_encoder *encoder;
7984 struct intel_connector *connector;
7988 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
7990 to_intel_crtc(config->save_encoder_crtcs[count++]);
7994 list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
7995 connector->new_encoder =
7996 to_intel_encoder(config->save_connector_encoders[count++]);
8001 is_crtc_connector_off(struct drm_crtc *crtc, struct drm_connector *connectors,
8006 for (i = 0; i < num_connectors; i++)
8007 if (connectors[i].encoder &&
8008 connectors[i].encoder->crtc == crtc &&
8009 connectors[i].dpms != DRM_MODE_DPMS_ON)
8016 intel_set_config_compute_mode_changes(struct drm_mode_set *set,
8017 struct intel_set_config *config)
8020 /* We should be able to check here if the fb has the same properties
8021 * and then just flip_or_move it */
8022 if (set->connectors != NULL &&
8023 is_crtc_connector_off(set->crtc, *set->connectors,
8024 set->num_connectors)) {
8025 config->mode_changed = true;
8026 } else if (set->crtc->fb != set->fb) {
8027 /* If we have no fb then treat it as a full mode set */
8028 if (set->crtc->fb == NULL) {
8029 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
8030 config->mode_changed = true;
8031 } else if (set->fb == NULL) {
8032 config->mode_changed = true;
8033 } else if (set->fb->depth != set->crtc->fb->depth) {
8034 config->mode_changed = true;
8035 } else if (set->fb->bits_per_pixel !=
8036 set->crtc->fb->bits_per_pixel) {
8037 config->mode_changed = true;
8039 config->fb_changed = true;
8043 if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
8044 config->fb_changed = true;
8046 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
8047 DRM_DEBUG_KMS("modes are different, full mode set\n");
8048 drm_mode_debug_printmodeline(&set->crtc->mode);
8049 drm_mode_debug_printmodeline(set->mode);
8050 config->mode_changed = true;
8055 intel_modeset_stage_output_state(struct drm_device *dev,
8056 struct drm_mode_set *set,
8057 struct intel_set_config *config)
8059 struct drm_crtc *new_crtc;
8060 struct intel_connector *connector;
8061 struct intel_encoder *encoder;
8064 /* The upper layers ensure that we either disable a crtc or have a list
8065 * of connectors. For paranoia, double-check this. */
8066 WARN_ON(!set->fb && (set->num_connectors != 0));
8067 WARN_ON(set->fb && (set->num_connectors == 0));
8070 list_for_each_entry(connector, &dev->mode_config.connector_list,
8072 /* Otherwise traverse passed in connector list and get encoders
8074 for (ro = 0; ro < set->num_connectors; ro++) {
8075 if (set->connectors[ro] == &connector->base) {
8076 connector->new_encoder = connector->encoder;
8081 /* If we disable the crtc, disable all its connectors. Also, if
8082 * the connector is on the changing crtc but not on the new
8083 * connector list, disable it. */
8084 if ((!set->fb || ro == set->num_connectors) &&
8085 connector->base.encoder &&
8086 connector->base.encoder->crtc == set->crtc) {
8087 connector->new_encoder = NULL;
8089 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
8090 connector->base.base.id,
8091 drm_get_connector_name(&connector->base));
8095 if (&connector->new_encoder->base != connector->base.encoder) {
8096 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
8097 config->mode_changed = true;
8100 /* connector->new_encoder is now updated for all connectors. */
8102 /* Update crtc of enabled connectors. */
8104 list_for_each_entry(connector, &dev->mode_config.connector_list,
8106 if (!connector->new_encoder)
8109 new_crtc = connector->new_encoder->base.crtc;
8111 for (ro = 0; ro < set->num_connectors; ro++) {
8112 if (set->connectors[ro] == &connector->base)
8113 new_crtc = set->crtc;
8116 /* Make sure the new CRTC will work with the encoder */
8117 if (!intel_encoder_crtc_ok(&connector->new_encoder->base,
8121 connector->encoder->new_crtc = to_intel_crtc(new_crtc);
8123 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
8124 connector->base.base.id,
8125 drm_get_connector_name(&connector->base),
8129 /* Check for any encoders that needs to be disabled. */
8130 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
8132 list_for_each_entry(connector,
8133 &dev->mode_config.connector_list,
8135 if (connector->new_encoder == encoder) {
8136 WARN_ON(!connector->new_encoder->new_crtc);
8141 encoder->new_crtc = NULL;
8143 /* Only now check for crtc changes so we don't miss encoders
8144 * that will be disabled. */
8145 if (&encoder->new_crtc->base != encoder->base.crtc) {
8146 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
8147 config->mode_changed = true;
8150 /* Now we've also updated encoder->new_crtc for all encoders. */
8155 static int intel_crtc_set_config(struct drm_mode_set *set)
8157 struct drm_device *dev;
8158 struct drm_mode_set save_set;
8159 struct intel_set_config *config;
8164 BUG_ON(!set->crtc->helper_private);
8166 /* Enforce sane interface api - has been abused by the fb helper. */
8167 BUG_ON(!set->mode && set->fb);
8168 BUG_ON(set->fb && set->num_connectors == 0);
8171 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
8172 set->crtc->base.id, set->fb->base.id,
8173 (int)set->num_connectors, set->x, set->y);
8175 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
8178 dev = set->crtc->dev;
8181 config = kmalloc(sizeof(*config), M_DRM, M_WAITOK | M_ZERO);
8185 ret = intel_set_config_save_state(dev, config);
8189 save_set.crtc = set->crtc;
8190 save_set.mode = &set->crtc->mode;
8191 save_set.x = set->crtc->x;
8192 save_set.y = set->crtc->y;
8193 save_set.fb = set->crtc->fb;
8195 /* Compute whether we need a full modeset, only an fb base update or no
8196 * change at all. In the future we might also check whether only the
8197 * mode changed, e.g. for LVDS where we only change the panel fitter in
8199 intel_set_config_compute_mode_changes(set, config);
8201 ret = intel_modeset_stage_output_state(dev, set, config);
8205 if (config->mode_changed) {
8207 DRM_DEBUG_KMS("attempting to set mode from"
8209 drm_mode_debug_printmodeline(set->mode);
8212 ret = intel_set_mode(set->crtc, set->mode,
8213 set->x, set->y, set->fb);
8215 DRM_ERROR("failed to set mode on [CRTC:%d], err = %d\n",
8216 set->crtc->base.id, ret);
8219 } else if (config->fb_changed) {
8220 ret = intel_pipe_set_base(set->crtc,
8221 set->x, set->y, set->fb);
8224 intel_set_config_free(config);
8229 intel_set_config_restore_state(dev, config);
8231 /* Try to restore the config */
8232 if (config->mode_changed &&
8233 intel_set_mode(save_set.crtc, save_set.mode,
8234 save_set.x, save_set.y, save_set.fb))
8235 DRM_ERROR("failed to restore config after modeset failure\n");
8238 intel_set_config_free(config);
8242 static const struct drm_crtc_funcs intel_crtc_funcs = {
8243 .cursor_set = intel_crtc_cursor_set,
8244 .cursor_move = intel_crtc_cursor_move,
8245 .gamma_set = intel_crtc_gamma_set,
8246 .set_config = intel_crtc_set_config,
8247 .destroy = intel_crtc_destroy,
8248 .page_flip = intel_crtc_page_flip,
8251 static void intel_cpu_pll_init(struct drm_device *dev)
8254 intel_ddi_pll_init(dev);
8257 static void intel_pch_pll_init(struct drm_device *dev)
8259 drm_i915_private_t *dev_priv = dev->dev_private;
8262 if (dev_priv->num_pch_pll == 0) {
8263 DRM_DEBUG_KMS("No PCH PLLs on this hardware, skipping initialisation\n");
8267 for (i = 0; i < dev_priv->num_pch_pll; i++) {
8268 dev_priv->pch_plls[i].pll_reg = _PCH_DPLL(i);
8269 dev_priv->pch_plls[i].fp0_reg = _PCH_FP0(i);
8270 dev_priv->pch_plls[i].fp1_reg = _PCH_FP1(i);
8274 static void intel_crtc_init(struct drm_device *dev, int pipe)
8276 drm_i915_private_t *dev_priv = dev->dev_private;
8277 struct intel_crtc *intel_crtc;
8280 intel_crtc = kmalloc(sizeof(struct intel_crtc) +
8281 (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)),
8282 M_DRM, M_WAITOK | M_ZERO);
8283 if (intel_crtc == NULL)
8286 drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
8288 drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
8289 for (i = 0; i < 256; i++) {
8290 intel_crtc->lut_r[i] = i;
8291 intel_crtc->lut_g[i] = i;
8292 intel_crtc->lut_b[i] = i;
8295 /* Swap pipes & planes for FBC on pre-965 */
8296 intel_crtc->pipe = pipe;
8297 intel_crtc->plane = pipe;
8298 intel_crtc->cpu_transcoder = pipe;
8299 if (IS_MOBILE(dev) && IS_GEN3(dev)) {
8300 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
8301 intel_crtc->plane = !pipe;
8304 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
8305 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
8306 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
8307 dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
8309 intel_crtc->bpp = 24; /* default for pre-Ironlake */
8311 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
8314 int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
8315 struct drm_file *file)
8317 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
8318 struct drm_mode_object *drmmode_obj;
8319 struct intel_crtc *crtc;
8321 if (!drm_core_check_feature(dev, DRIVER_MODESET))
8324 drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
8325 DRM_MODE_OBJECT_CRTC);
8328 DRM_ERROR("no such CRTC id\n");
8332 crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
8333 pipe_from_crtc_id->pipe = crtc->pipe;
8338 static int intel_encoder_clones(struct intel_encoder *encoder)
8340 struct drm_device *dev = encoder->base.dev;
8341 struct intel_encoder *source_encoder;
8345 list_for_each_entry(source_encoder,
8346 &dev->mode_config.encoder_list, base.head) {
8348 if (encoder == source_encoder)
8349 index_mask |= (1 << entry);
8351 /* Intel hw has only one MUX where enocoders could be cloned. */
8352 if (encoder->cloneable && source_encoder->cloneable)
8353 index_mask |= (1 << entry);
8361 static bool has_edp_a(struct drm_device *dev)
8363 struct drm_i915_private *dev_priv = dev->dev_private;
8365 if (!IS_MOBILE(dev))
8368 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
8372 (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
8378 static void intel_setup_outputs(struct drm_device *dev)
8380 struct drm_i915_private *dev_priv = dev->dev_private;
8381 struct intel_encoder *encoder;
8382 bool dpd_is_edp = false;
8385 has_lvds = intel_lvds_init(dev);
8386 if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
8387 /* disable the panel fitter on everything but LVDS */
8388 I915_WRITE(PFIT_CONTROL, 0);
8392 intel_crt_init(dev);
8397 /* Haswell uses DDI functions to detect digital outputs */
8398 found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
8399 /* DDI A only supports eDP */
8401 intel_ddi_init(dev, PORT_A);
8403 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
8405 found = I915_READ(SFUSE_STRAP);
8407 if (found & SFUSE_STRAP_DDIB_DETECTED)
8408 intel_ddi_init(dev, PORT_B);
8409 if (found & SFUSE_STRAP_DDIC_DETECTED)
8410 intel_ddi_init(dev, PORT_C);
8411 if (found & SFUSE_STRAP_DDID_DETECTED)
8412 intel_ddi_init(dev, PORT_D);
8413 } else if (HAS_PCH_SPLIT(dev)) {
8415 dpd_is_edp = intel_dpd_is_edp(dev);
8418 intel_dp_init(dev, DP_A, PORT_A);
8420 if (I915_READ(HDMIB) & PORT_DETECTED) {
8421 /* PCH SDVOB multiplex with HDMIB */
8422 found = intel_sdvo_init(dev, PCH_SDVOB, true);
8424 intel_hdmi_init(dev, HDMIB, PORT_B);
8425 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
8426 intel_dp_init(dev, PCH_DP_B, PORT_B);
8429 if (I915_READ(HDMIC) & PORT_DETECTED)
8430 intel_hdmi_init(dev, HDMIC, PORT_C);
8432 if (!dpd_is_edp && I915_READ(HDMID) & PORT_DETECTED)
8433 intel_hdmi_init(dev, HDMID, PORT_D);
8435 if (I915_READ(PCH_DP_C) & DP_DETECTED)
8436 intel_dp_init(dev, PCH_DP_C, PORT_C);
8438 if (I915_READ(PCH_DP_D) & DP_DETECTED)
8439 intel_dp_init(dev, PCH_DP_D, PORT_D);
8440 } else if (IS_VALLEYVIEW(dev)) {
8441 /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
8442 if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
8443 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
8445 if (I915_READ(VLV_DISPLAY_BASE + SDVOB) & PORT_DETECTED) {
8446 intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOB, PORT_B);
8447 if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
8448 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
8451 if (I915_READ(VLV_DISPLAY_BASE + SDVOC) & PORT_DETECTED)
8452 intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOC, PORT_C);
8454 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
8457 if (I915_READ(SDVOB) & SDVO_DETECTED) {
8458 DRM_DEBUG_KMS("probing SDVOB\n");
8459 found = intel_sdvo_init(dev, SDVOB, true);
8460 if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
8461 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
8462 intel_hdmi_init(dev, SDVOB, PORT_B);
8465 if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
8466 DRM_DEBUG_KMS("probing DP_B\n");
8467 intel_dp_init(dev, DP_B, PORT_B);
8471 /* Before G4X SDVOC doesn't have its own detect register */
8473 if (I915_READ(SDVOB) & SDVO_DETECTED) {
8474 DRM_DEBUG_KMS("probing SDVOC\n");
8475 found = intel_sdvo_init(dev, SDVOC, false);
8478 if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
8480 if (SUPPORTS_INTEGRATED_HDMI(dev)) {
8481 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
8482 intel_hdmi_init(dev, SDVOC, PORT_C);
8484 if (SUPPORTS_INTEGRATED_DP(dev)) {
8485 DRM_DEBUG_KMS("probing DP_C\n");
8486 intel_dp_init(dev, DP_C, PORT_C);
8490 if (SUPPORTS_INTEGRATED_DP(dev) &&
8491 (I915_READ(DP_D) & DP_DETECTED)) {
8492 DRM_DEBUG_KMS("probing DP_D\n");
8493 intel_dp_init(dev, DP_D, PORT_D);
8495 } else if (IS_GEN2(dev)) {
8497 intel_dvo_init(dev);
8501 if (SUPPORTS_TV(dev))
8504 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
8505 encoder->base.possible_crtcs = encoder->crtc_mask;
8506 encoder->base.possible_clones =
8507 intel_encoder_clones(encoder);
8510 intel_init_pch_refclk(dev);
8512 drm_helper_move_panel_connectors_to_head(dev);
8515 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
8517 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
8519 drm_framebuffer_cleanup(fb);
8520 drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
8522 drm_free(intel_fb, M_DRM);
8525 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
8526 struct drm_file *file,
8527 unsigned int *handle)
8529 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
8530 struct drm_i915_gem_object *obj = intel_fb->obj;
8532 return drm_gem_handle_create(file, &obj->base, handle);
8535 static const struct drm_framebuffer_funcs intel_fb_funcs = {
8536 .destroy = intel_user_framebuffer_destroy,
8537 .create_handle = intel_user_framebuffer_create_handle,
8540 int intel_framebuffer_init(struct drm_device *dev,
8541 struct intel_framebuffer *intel_fb,
8542 struct drm_mode_fb_cmd2 *mode_cmd,
8543 struct drm_i915_gem_object *obj)
8547 if (obj->tiling_mode == I915_TILING_Y) {
8548 DRM_DEBUG("hardware does not support tiling Y\n");
8552 if (mode_cmd->pitches[0] & 63) {
8553 DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
8554 mode_cmd->pitches[0]);
8558 /* FIXME <= Gen4 stride limits are bit unclear */
8559 if (mode_cmd->pitches[0] > 32768) {
8560 DRM_DEBUG("pitch (%d) must be at less than 32768\n",
8561 mode_cmd->pitches[0]);
8565 if (obj->tiling_mode != I915_TILING_NONE &&
8566 mode_cmd->pitches[0] != obj->stride) {
8567 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
8568 mode_cmd->pitches[0], obj->stride);
8572 /* Reject formats not supported by any plane early. */
8573 switch (mode_cmd->pixel_format) {
8575 case DRM_FORMAT_RGB565:
8576 case DRM_FORMAT_XRGB8888:
8577 case DRM_FORMAT_ARGB8888:
8579 case DRM_FORMAT_XRGB1555:
8580 case DRM_FORMAT_ARGB1555:
8581 if (INTEL_INFO(dev)->gen > 3) {
8582 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
8586 case DRM_FORMAT_XBGR8888:
8587 case DRM_FORMAT_ABGR8888:
8588 case DRM_FORMAT_XRGB2101010:
8589 case DRM_FORMAT_ARGB2101010:
8590 case DRM_FORMAT_XBGR2101010:
8591 case DRM_FORMAT_ABGR2101010:
8592 if (INTEL_INFO(dev)->gen < 4) {
8593 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
8597 case DRM_FORMAT_YUYV:
8598 case DRM_FORMAT_UYVY:
8599 case DRM_FORMAT_YVYU:
8600 case DRM_FORMAT_VYUY:
8601 if (INTEL_INFO(dev)->gen < 5) {
8602 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
8607 DRM_DEBUG("unsupported pixel format 0x%08x\n", mode_cmd->pixel_format);
8611 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
8612 if (mode_cmd->offsets[0] != 0)
8615 drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
8616 intel_fb->obj = obj;
8618 ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
8620 DRM_ERROR("framebuffer init failed %d\n", ret);
8627 static struct drm_framebuffer *
8628 intel_user_framebuffer_create(struct drm_device *dev,
8629 struct drm_file *filp,
8630 struct drm_mode_fb_cmd2 *mode_cmd)
8632 struct drm_i915_gem_object *obj;
8634 obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
8635 mode_cmd->handles[0]));
8636 if (&obj->base == NULL)
8637 return ERR_PTR(-ENOENT);
8639 return intel_framebuffer_create(dev, mode_cmd, obj);
8642 static const struct drm_mode_config_funcs intel_mode_funcs = {
8643 .fb_create = intel_user_framebuffer_create,
8644 .output_poll_changed = intel_fb_output_poll_changed,
8647 /* Set up chip specific display functions */
8648 static void intel_init_display(struct drm_device *dev)
8650 struct drm_i915_private *dev_priv = dev->dev_private;
8652 /* We always want a DPMS function */
8654 dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
8655 dev_priv->display.crtc_enable = haswell_crtc_enable;
8656 dev_priv->display.crtc_disable = haswell_crtc_disable;
8657 dev_priv->display.off = haswell_crtc_off;
8658 dev_priv->display.update_plane = ironlake_update_plane;
8659 } else if (HAS_PCH_SPLIT(dev)) {
8660 dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
8661 dev_priv->display.crtc_enable = ironlake_crtc_enable;
8662 dev_priv->display.crtc_disable = ironlake_crtc_disable;
8663 dev_priv->display.off = ironlake_crtc_off;
8664 dev_priv->display.update_plane = ironlake_update_plane;
8666 dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
8667 dev_priv->display.crtc_enable = i9xx_crtc_enable;
8668 dev_priv->display.crtc_disable = i9xx_crtc_disable;
8669 dev_priv->display.off = i9xx_crtc_off;
8670 dev_priv->display.update_plane = i9xx_update_plane;
8673 /* Returns the core display clock speed */
8674 if (IS_VALLEYVIEW(dev))
8675 dev_priv->display.get_display_clock_speed =
8676 valleyview_get_display_clock_speed;
8677 else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
8678 dev_priv->display.get_display_clock_speed =
8679 i945_get_display_clock_speed;
8680 else if (IS_I915G(dev))
8681 dev_priv->display.get_display_clock_speed =
8682 i915_get_display_clock_speed;
8683 else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
8684 dev_priv->display.get_display_clock_speed =
8685 i9xx_misc_get_display_clock_speed;
8686 else if (IS_I915GM(dev))
8687 dev_priv->display.get_display_clock_speed =
8688 i915gm_get_display_clock_speed;
8689 else if (IS_I865G(dev))
8690 dev_priv->display.get_display_clock_speed =
8691 i865_get_display_clock_speed;
8692 else if (IS_I85X(dev))
8693 dev_priv->display.get_display_clock_speed =
8694 i855_get_display_clock_speed;
8696 dev_priv->display.get_display_clock_speed =
8697 i830_get_display_clock_speed;
8699 if (HAS_PCH_SPLIT(dev)) {
8701 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
8702 dev_priv->display.write_eld = ironlake_write_eld;
8703 } else if (IS_GEN6(dev)) {
8704 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
8705 dev_priv->display.write_eld = ironlake_write_eld;
8706 } else if (IS_IVYBRIDGE(dev)) {
8707 /* FIXME: detect B0+ stepping and use auto training */
8708 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
8709 dev_priv->display.write_eld = ironlake_write_eld;
8710 dev_priv->display.modeset_global_resources =
8711 ivb_modeset_global_resources;
8712 } else if (IS_HASWELL(dev)) {
8713 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
8714 dev_priv->display.write_eld = haswell_write_eld;
8715 dev_priv->display.modeset_global_resources =
8716 haswell_modeset_global_resources;
8718 } else if (IS_G4X(dev)) {
8719 dev_priv->display.write_eld = g4x_write_eld;
8722 /* Default just returns -ENODEV to indicate unsupported */
8723 dev_priv->display.queue_flip = intel_default_queue_flip;
8725 switch (INTEL_INFO(dev)->gen) {
8727 dev_priv->display.queue_flip = intel_gen2_queue_flip;
8731 dev_priv->display.queue_flip = intel_gen3_queue_flip;
8736 dev_priv->display.queue_flip = intel_gen4_queue_flip;
8740 dev_priv->display.queue_flip = intel_gen6_queue_flip;
8743 dev_priv->display.queue_flip = intel_gen7_queue_flip;
8749 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
8750 * resume, or other times. This quirk makes sure that's the case for
8753 static void quirk_pipea_force(struct drm_device *dev)
8755 struct drm_i915_private *dev_priv = dev->dev_private;
8757 dev_priv->quirks |= QUIRK_PIPEA_FORCE;
8758 DRM_INFO("applying pipe a force quirk\n");
8762 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
8764 static void quirk_ssc_force_disable(struct drm_device *dev)
8766 struct drm_i915_private *dev_priv = dev->dev_private;
8767 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
8768 DRM_INFO("applying lvds SSC disable quirk\n");
8772 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
8775 static void quirk_invert_brightness(struct drm_device *dev)
8777 struct drm_i915_private *dev_priv = dev->dev_private;
8778 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
8779 DRM_INFO("applying inverted panel brightness quirk\n");
8782 struct intel_quirk {
8784 int subsystem_vendor;
8785 int subsystem_device;
8786 void (*hook)(struct drm_device *dev);
8789 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
8790 struct intel_dmi_quirk {
8791 void (*hook)(struct drm_device *dev);
8792 const struct dmi_system_id (*dmi_id_list)[];
8795 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
8797 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
8801 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
8803 .dmi_id_list = &(const struct dmi_system_id[]) {
8805 .callback = intel_dmi_reverse_brightness,
8806 .ident = "NCR Corporation",
8807 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
8808 DMI_MATCH(DMI_PRODUCT_NAME, ""),
8811 { } /* terminating entry */
8813 .hook = quirk_invert_brightness,
8817 static struct intel_quirk intel_quirks[] = {
8818 /* HP Mini needs pipe A force quirk (LP: #322104) */
8819 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
8821 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
8822 { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
8824 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
8825 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
8827 /* 830/845 need to leave pipe A & dpll A up */
8828 { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
8829 { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
8831 /* Lenovo U160 cannot use SSC on LVDS */
8832 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
8834 /* Sony Vaio Y cannot use SSC on LVDS */
8835 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
8837 /* Acer Aspire 5734Z must invert backlight brightness */
8838 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
8840 /* Acer/eMachines G725 */
8841 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
8843 /* Acer/eMachines e725 */
8844 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
8846 /* Acer/Packard Bell NCL20 */
8847 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
8849 /* Acer Aspire 4736Z */
8850 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
8853 static void intel_init_quirks(struct drm_device *dev)
8859 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
8860 struct intel_quirk *q = &intel_quirks[i];
8861 if (pci_get_device(d) == q->device &&
8862 (pci_get_subvendor(d) == q->subsystem_vendor ||
8863 q->subsystem_vendor == PCI_ANY_ID) &&
8864 (pci_get_subdevice(d) == q->subsystem_device ||
8865 q->subsystem_device == PCI_ANY_ID))
8868 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
8869 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
8870 intel_dmi_quirks[i].hook(dev);
8874 /* Disable the VGA plane that we never use */
8875 static void i915_disable_vga(struct drm_device *dev)
8877 struct drm_i915_private *dev_priv = dev->dev_private;
8879 u32 vga_reg = i915_vgacntrl_reg(dev);
8882 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
8884 outb(VGA_SR_INDEX, 1);
8885 sr1 = inb(VGA_SR_DATA);
8886 outb(VGA_SR_DATA, sr1 | 1 << 5);
8888 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
8892 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
8893 POSTING_READ(vga_reg);
8896 void intel_modeset_init_hw(struct drm_device *dev)
8898 intel_init_power_well(dev);
8900 intel_prepare_ddi(dev);
8902 intel_init_clock_gating(dev);
8904 mutex_lock(&dev->struct_mutex);
8905 intel_enable_gt_powersave(dev);
8906 mutex_unlock(&dev->struct_mutex);
8909 void intel_modeset_init(struct drm_device *dev)
8911 struct drm_i915_private *dev_priv = dev->dev_private;
8914 drm_mode_config_init(dev);
8916 dev->mode_config.min_width = 0;
8917 dev->mode_config.min_height = 0;
8919 dev->mode_config.preferred_depth = 24;
8920 dev->mode_config.prefer_shadow = 1;
8922 dev->mode_config.funcs = &intel_mode_funcs;
8924 intel_init_quirks(dev);
8928 intel_init_display(dev);
8931 dev->mode_config.max_width = 2048;
8932 dev->mode_config.max_height = 2048;
8933 } else if (IS_GEN3(dev)) {
8934 dev->mode_config.max_width = 4096;
8935 dev->mode_config.max_height = 4096;
8937 dev->mode_config.max_width = 8192;
8938 dev->mode_config.max_height = 8192;
8940 dev->mode_config.fb_base = dev->agp->base;
8942 DRM_DEBUG_KMS("%d display pipe%s available.\n",
8943 dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
8945 for (i = 0; i < dev_priv->num_pipe; i++) {
8946 intel_crtc_init(dev, i);
8947 ret = intel_plane_init(dev, i);
8949 DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
8952 intel_cpu_pll_init(dev);
8953 intel_pch_pll_init(dev);
8955 /* Just disable it once at startup */
8956 i915_disable_vga(dev);
8957 intel_setup_outputs(dev);
8959 /* Just in case the BIOS is doing something questionable. */
8960 intel_disable_fbc(dev);
8964 intel_connector_break_all_links(struct intel_connector *connector)
8966 connector->base.dpms = DRM_MODE_DPMS_OFF;
8967 connector->base.encoder = NULL;
8968 connector->encoder->connectors_active = false;
8969 connector->encoder->base.crtc = NULL;
8972 static void intel_enable_pipe_a(struct drm_device *dev)
8974 struct intel_connector *connector;
8975 struct drm_connector *crt = NULL;
8976 struct intel_load_detect_pipe load_detect_temp;
8978 /* We can't just switch on the pipe A, we need to set things up with a
8979 * proper mode and output configuration. As a gross hack, enable pipe A
8980 * by enabling the load detect pipe once. */
8981 list_for_each_entry(connector,
8982 &dev->mode_config.connector_list,
8984 if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
8985 crt = &connector->base;
8993 if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp))
8994 intel_release_load_detect_pipe(crt, &load_detect_temp);
9000 intel_check_plane_mapping(struct intel_crtc *crtc)
9002 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
9005 if (dev_priv->num_pipe == 1)
9008 reg = DSPCNTR(!crtc->plane);
9009 val = I915_READ(reg);
9011 if ((val & DISPLAY_PLANE_ENABLE) &&
9012 (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
9018 static void intel_sanitize_crtc(struct intel_crtc *crtc)
9020 struct drm_device *dev = crtc->base.dev;
9021 struct drm_i915_private *dev_priv = dev->dev_private;
9024 /* Clear any frame start delays used for debugging left by the BIOS */
9025 reg = PIPECONF(crtc->cpu_transcoder);
9026 I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
9028 /* We need to sanitize the plane -> pipe mapping first because this will
9029 * disable the crtc (and hence change the state) if it is wrong. Note
9030 * that gen4+ has a fixed plane -> pipe mapping. */
9031 if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
9032 struct intel_connector *connector;
9035 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
9036 crtc->base.base.id);
9038 /* Pipe has the wrong plane attached and the plane is active.
9039 * Temporarily change the plane mapping and disable everything
9041 plane = crtc->plane;
9042 crtc->plane = !plane;
9043 dev_priv->display.crtc_disable(&crtc->base);
9044 crtc->plane = plane;
9046 /* ... and break all links. */
9047 list_for_each_entry(connector, &dev->mode_config.connector_list,
9049 if (connector->encoder->base.crtc != &crtc->base)
9052 intel_connector_break_all_links(connector);
9055 WARN_ON(crtc->active);
9056 crtc->base.enabled = false;
9059 if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
9060 crtc->pipe == PIPE_A && !crtc->active) {
9061 /* BIOS forgot to enable pipe A, this mostly happens after
9062 * resume. Force-enable the pipe to fix this, the update_dpms
9063 * call below we restore the pipe to the right state, but leave
9064 * the required bits on. */
9065 intel_enable_pipe_a(dev);
9068 /* Adjust the state of the output pipe according to whether we
9069 * have active connectors/encoders. */
9070 intel_crtc_update_dpms(&crtc->base);
9072 if (crtc->active != crtc->base.enabled) {
9073 struct intel_encoder *encoder;
9075 /* This can happen either due to bugs in the get_hw_state
9076 * functions or because the pipe is force-enabled due to the
9078 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
9080 crtc->base.enabled ? "enabled" : "disabled",
9081 crtc->active ? "enabled" : "disabled");
9083 crtc->base.enabled = crtc->active;
9085 /* Because we only establish the connector -> encoder ->
9086 * crtc links if something is active, this means the
9087 * crtc is now deactivated. Break the links. connector
9088 * -> encoder links are only establish when things are
9089 * actually up, hence no need to break them. */
9090 WARN_ON(crtc->active);
9092 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
9093 WARN_ON(encoder->connectors_active);
9094 encoder->base.crtc = NULL;
9099 static void intel_sanitize_encoder(struct intel_encoder *encoder)
9101 struct intel_connector *connector;
9102 struct drm_device *dev = encoder->base.dev;
9104 /* We need to check both for a crtc link (meaning that the
9105 * encoder is active and trying to read from a pipe) and the
9106 * pipe itself being active. */
9107 bool has_active_crtc = encoder->base.crtc &&
9108 to_intel_crtc(encoder->base.crtc)->active;
9110 if (encoder->connectors_active && !has_active_crtc) {
9111 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
9112 encoder->base.base.id,
9113 drm_get_encoder_name(&encoder->base));
9115 /* Connector is active, but has no active pipe. This is
9116 * fallout from our resume register restoring. Disable
9117 * the encoder manually again. */
9118 if (encoder->base.crtc) {
9119 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
9120 encoder->base.base.id,
9121 drm_get_encoder_name(&encoder->base));
9122 encoder->disable(encoder);
9125 /* Inconsistent output/port/pipe state happens presumably due to
9126 * a bug in one of the get_hw_state functions. Or someplace else
9127 * in our code, like the register restore mess on resume. Clamp
9128 * things to off as a safer default. */
9129 list_for_each_entry(connector,
9130 &dev->mode_config.connector_list,
9132 if (connector->encoder != encoder)
9135 intel_connector_break_all_links(connector);
9138 /* Enabled encoders without active connectors will be fixed in
9139 * the crtc fixup. */
9142 void i915_redisable_vga(struct drm_device *dev)
9144 struct drm_i915_private *dev_priv = dev->dev_private;
9145 u32 vga_reg = i915_vgacntrl_reg(dev);
9147 if (I915_READ(vga_reg) != VGA_DISP_DISABLE) {
9148 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
9149 i915_disable_vga(dev);
9153 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
9154 * and i915 state tracking structures. */
9155 void intel_modeset_setup_hw_state(struct drm_device *dev,
9158 struct drm_i915_private *dev_priv = dev->dev_private;
9159 enum i915_pipe pipe;
9161 struct intel_crtc *crtc;
9162 struct intel_encoder *encoder;
9163 struct intel_connector *connector;
9166 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9168 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9169 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9170 case TRANS_DDI_EDP_INPUT_A_ON:
9171 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9174 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9177 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9182 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9183 crtc->cpu_transcoder = TRANSCODER_EDP;
9185 DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
9190 for_each_pipe(pipe) {
9191 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9193 tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
9194 if (tmp & PIPECONF_ENABLE)
9195 crtc->active = true;
9197 crtc->active = false;
9199 crtc->base.enabled = crtc->active;
9201 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
9203 crtc->active ? "enabled" : "disabled");
9207 intel_ddi_setup_hw_pll_state(dev);
9209 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
9213 if (encoder->get_hw_state(encoder, &pipe)) {
9214 encoder->base.crtc =
9215 dev_priv->pipe_to_crtc_mapping[pipe];
9217 encoder->base.crtc = NULL;
9220 encoder->connectors_active = false;
9221 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
9222 encoder->base.base.id,
9223 drm_get_encoder_name(&encoder->base),
9224 encoder->base.crtc ? "enabled" : "disabled",
9228 list_for_each_entry(connector, &dev->mode_config.connector_list,
9230 if (connector->get_hw_state(connector)) {
9231 connector->base.dpms = DRM_MODE_DPMS_ON;
9232 connector->encoder->connectors_active = true;
9233 connector->base.encoder = &connector->encoder->base;
9235 connector->base.dpms = DRM_MODE_DPMS_OFF;
9236 connector->base.encoder = NULL;
9238 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
9239 connector->base.base.id,
9240 drm_get_connector_name(&connector->base),
9241 connector->base.encoder ? "enabled" : "disabled");
9244 /* HW state is read out, now we need to sanitize this mess. */
9245 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
9247 intel_sanitize_encoder(encoder);
9250 for_each_pipe(pipe) {
9251 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9252 intel_sanitize_crtc(crtc);
9255 if (force_restore) {
9257 * We need to use raw interfaces for restoring state to avoid
9258 * checking (bogus) intermediate states.
9260 for_each_pipe(pipe) {
9261 struct drm_crtc *crtc =
9262 dev_priv->pipe_to_crtc_mapping[pipe];
9264 __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
9268 i915_redisable_vga(dev);
9270 intel_modeset_update_staged_output_state(dev);
9273 intel_modeset_check_state(dev);
9275 drm_mode_config_reset(dev);
9278 void intel_modeset_gem_init(struct drm_device *dev)
9280 intel_modeset_init_hw(dev);
9282 intel_setup_overlay(dev);
9284 intel_modeset_setup_hw_state(dev, false);
9287 void intel_modeset_cleanup(struct drm_device *dev)
9289 struct drm_i915_private *dev_priv = dev->dev_private;
9290 struct drm_crtc *crtc;
9291 struct intel_crtc *intel_crtc;
9293 drm_kms_helper_poll_fini(dev);
9294 mutex_lock(&dev->struct_mutex);
9297 intel_unregister_dsm_handler();
9300 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
9301 /* Skip inactive CRTCs */
9305 intel_crtc = to_intel_crtc(crtc);
9306 intel_increase_pllclock(crtc);
9309 intel_disable_fbc(dev);
9311 intel_disable_gt_powersave(dev);
9313 ironlake_teardown_rc6(dev);
9315 if (IS_VALLEYVIEW(dev))
9318 mutex_unlock(&dev->struct_mutex);
9320 /* Disable the irq before mode object teardown, for the irq might
9321 * enqueue unpin/hotplug work. */
9322 drm_irq_uninstall(dev);
9323 cancel_work_sync(&dev_priv->hotplug_work);
9324 cancel_work_sync(&dev_priv->rps.work);
9326 /* flush any delayed tasks or pending work */
9327 flush_scheduled_work();
9329 /* destroy backlight, if any, before the connectors */
9330 intel_panel_destroy_backlight(dev);
9332 drm_mode_config_cleanup(dev);
9334 intel_cleanup_overlay(dev);
9338 * Return which encoder is currently attached for connector.
9340 struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
9342 return &intel_attached_encoder(connector)->base;
9345 void intel_connector_attach_encoder(struct intel_connector *connector,
9346 struct intel_encoder *encoder)
9348 connector->encoder = encoder;
9349 drm_mode_connector_attach_encoder(&connector->base,
9354 * set vga decode state - true == enable VGA decode
9356 int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
9358 struct drm_i915_private *dev_priv = dev->dev_private;
9361 pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
9363 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
9365 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
9366 pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
9370 #ifdef CONFIG_DEBUG_FS
9371 #include <linux/seq_file.h>
9373 struct intel_display_error_state {
9374 struct intel_cursor_error_state {
9379 } cursor[I915_MAX_PIPES];
9381 struct intel_pipe_error_state {
9391 } pipe[I915_MAX_PIPES];
9393 struct intel_plane_error_state {
9401 } plane[I915_MAX_PIPES];
9404 struct intel_display_error_state *
9405 intel_display_capture_error_state(struct drm_device *dev)
9407 drm_i915_private_t *dev_priv = dev->dev_private;
9408 struct intel_display_error_state *error;
9409 enum transcoder cpu_transcoder;
9412 error = kmalloc(sizeof(*error), M_DRM, M_WAITOK | M_NULLOK);
9417 cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i);
9419 error->cursor[i].control = I915_READ(CURCNTR(i));
9420 error->cursor[i].position = I915_READ(CURPOS(i));
9421 error->cursor[i].base = I915_READ(CURBASE(i));
9423 error->plane[i].control = I915_READ(DSPCNTR(i));
9424 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
9425 error->plane[i].size = I915_READ(DSPSIZE(i));
9426 error->plane[i].pos = I915_READ(DSPPOS(i));
9427 error->plane[i].addr = I915_READ(DSPADDR(i));
9428 if (INTEL_INFO(dev)->gen >= 4) {
9429 error->plane[i].surface = I915_READ(DSPSURF(i));
9430 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
9433 error->pipe[i].conf = I915_READ(PIPECONF(cpu_transcoder));
9434 error->pipe[i].source = I915_READ(PIPESRC(i));
9435 error->pipe[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
9436 error->pipe[i].hblank = I915_READ(HBLANK(cpu_transcoder));
9437 error->pipe[i].hsync = I915_READ(HSYNC(cpu_transcoder));
9438 error->pipe[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
9439 error->pipe[i].vblank = I915_READ(VBLANK(cpu_transcoder));
9440 error->pipe[i].vsync = I915_READ(VSYNC(cpu_transcoder));
9447 intel_display_print_error_state(struct seq_file *m,
9448 struct drm_device *dev,
9449 struct intel_display_error_state *error)
9451 drm_i915_private_t *dev_priv = dev->dev_private;
9454 seq_printf(m, "Num Pipes: %d\n", dev_priv->num_pipe);
9456 seq_printf(m, "Pipe [%d]:\n", i);
9457 seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
9458 seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
9459 seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
9460 seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
9461 seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
9462 seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
9463 seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
9464 seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
9466 seq_printf(m, "Plane [%d]:\n", i);
9467 seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
9468 seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
9469 seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
9470 seq_printf(m, " POS: %08x\n", error->plane[i].pos);
9471 seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
9472 if (INTEL_INFO(dev)->gen >= 4) {
9473 seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
9474 seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
9477 seq_printf(m, "Cursor [%d]:\n", i);
9478 seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
9479 seq_printf(m, " POS: %08x\n", error->cursor[i].position);
9480 seq_printf(m, " BASE: %08x\n", error->cursor[i].base);