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;
2254 struct drm_i915_master_private *master_priv;
2255 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2257 if (!dev->primary->master)
2260 master_priv = dev->primary->master->driver_priv;
2261 if (!master_priv->sarea_priv)
2264 switch (intel_crtc->pipe) {
2266 master_priv->sarea_priv->pipeA_x = x;
2267 master_priv->sarea_priv->pipeA_y = y;
2270 master_priv->sarea_priv->pipeB_x = x;
2271 master_priv->sarea_priv->pipeB_y = y;
2279 intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
2280 struct drm_framebuffer *fb)
2282 struct drm_device *dev = crtc->dev;
2283 struct drm_i915_private *dev_priv = dev->dev_private;
2284 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2285 struct drm_framebuffer *old_fb;
2290 DRM_ERROR("No FB bound\n");
2294 if(intel_crtc->plane > dev_priv->num_pipe) {
2295 DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
2297 dev_priv->num_pipe);
2301 mutex_lock(&dev->struct_mutex);
2302 ret = intel_pin_and_fence_fb_obj(dev,
2303 to_intel_framebuffer(fb)->obj,
2306 mutex_unlock(&dev->struct_mutex);
2307 DRM_ERROR("pin & fence failed\n");
2312 intel_finish_fb(crtc->fb);
2314 ret = dev_priv->display.update_plane(crtc, fb, x, y);
2316 intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj);
2317 mutex_unlock(&dev->struct_mutex);
2318 DRM_ERROR("failed to update base address\n");
2328 intel_wait_for_vblank(dev, intel_crtc->pipe);
2329 intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
2332 intel_update_fbc(dev);
2333 mutex_unlock(&dev->struct_mutex);
2335 intel_crtc_update_sarea_pos(crtc, x, y);
2340 static void intel_fdi_normal_train(struct drm_crtc *crtc)
2342 struct drm_device *dev = crtc->dev;
2343 struct drm_i915_private *dev_priv = dev->dev_private;
2344 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2345 int pipe = intel_crtc->pipe;
2348 /* enable normal train */
2349 reg = FDI_TX_CTL(pipe);
2350 temp = I915_READ(reg);
2351 if (IS_IVYBRIDGE(dev)) {
2352 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
2353 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
2355 temp &= ~FDI_LINK_TRAIN_NONE;
2356 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
2358 I915_WRITE(reg, temp);
2360 reg = FDI_RX_CTL(pipe);
2361 temp = I915_READ(reg);
2362 if (HAS_PCH_CPT(dev)) {
2363 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2364 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
2366 temp &= ~FDI_LINK_TRAIN_NONE;
2367 temp |= FDI_LINK_TRAIN_NONE;
2369 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
2371 /* wait one idle pattern time */
2375 /* IVB wants error correction enabled */
2376 if (IS_IVYBRIDGE(dev))
2377 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
2378 FDI_FE_ERRC_ENABLE);
2381 static void ivb_modeset_global_resources(struct drm_device *dev)
2383 struct drm_i915_private *dev_priv = dev->dev_private;
2384 struct intel_crtc *pipe_B_crtc =
2385 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
2386 struct intel_crtc *pipe_C_crtc =
2387 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
2390 /* When everything is off disable fdi C so that we could enable fdi B
2391 * with all lanes. XXX: This misses the case where a pipe is not using
2392 * any pch resources and so doesn't need any fdi lanes. */
2393 if (!pipe_B_crtc->base.enabled && !pipe_C_crtc->base.enabled) {
2394 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
2395 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
2397 temp = I915_READ(SOUTH_CHICKEN1);
2398 temp &= ~FDI_BC_BIFURCATION_SELECT;
2399 DRM_DEBUG_KMS("disabling fdi C rx\n");
2400 I915_WRITE(SOUTH_CHICKEN1, temp);
2404 /* The FDI link training functions for ILK/Ibexpeak. */
2405 static void ironlake_fdi_link_train(struct drm_crtc *crtc)
2407 struct drm_device *dev = crtc->dev;
2408 struct drm_i915_private *dev_priv = dev->dev_private;
2409 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2410 int pipe = intel_crtc->pipe;
2411 int plane = intel_crtc->plane;
2412 u32 reg, temp, tries;
2414 /* FDI needs bits from pipe & plane first */
2415 assert_pipe_enabled(dev_priv, pipe);
2416 assert_plane_enabled(dev_priv, plane);
2418 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2420 reg = FDI_RX_IMR(pipe);
2421 temp = I915_READ(reg);
2422 temp &= ~FDI_RX_SYMBOL_LOCK;
2423 temp &= ~FDI_RX_BIT_LOCK;
2424 I915_WRITE(reg, temp);
2428 /* enable CPU FDI TX and PCH FDI RX */
2429 reg = FDI_TX_CTL(pipe);
2430 temp = I915_READ(reg);
2432 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2433 temp &= ~FDI_LINK_TRAIN_NONE;
2434 temp |= FDI_LINK_TRAIN_PATTERN_1;
2435 I915_WRITE(reg, temp | FDI_TX_ENABLE);
2437 reg = FDI_RX_CTL(pipe);
2438 temp = I915_READ(reg);
2439 temp &= ~FDI_LINK_TRAIN_NONE;
2440 temp |= FDI_LINK_TRAIN_PATTERN_1;
2441 I915_WRITE(reg, temp | FDI_RX_ENABLE);
2446 /* Ironlake workaround, enable clock pointer after FDI enable*/
2447 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
2448 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
2449 FDI_RX_PHASE_SYNC_POINTER_EN);
2451 reg = FDI_RX_IIR(pipe);
2452 for (tries = 0; tries < 5; tries++) {
2453 temp = I915_READ(reg);
2454 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2456 if ((temp & FDI_RX_BIT_LOCK)) {
2457 DRM_DEBUG_KMS("FDI train 1 done.\n");
2458 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2463 DRM_ERROR("FDI train 1 fail!\n");
2466 reg = FDI_TX_CTL(pipe);
2467 temp = I915_READ(reg);
2468 temp &= ~FDI_LINK_TRAIN_NONE;
2469 temp |= FDI_LINK_TRAIN_PATTERN_2;
2470 I915_WRITE(reg, temp);
2472 reg = FDI_RX_CTL(pipe);
2473 temp = I915_READ(reg);
2474 temp &= ~FDI_LINK_TRAIN_NONE;
2475 temp |= FDI_LINK_TRAIN_PATTERN_2;
2476 I915_WRITE(reg, temp);
2481 reg = FDI_RX_IIR(pipe);
2482 for (tries = 0; tries < 5; tries++) {
2483 temp = I915_READ(reg);
2484 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2486 if (temp & FDI_RX_SYMBOL_LOCK) {
2487 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2488 DRM_DEBUG_KMS("FDI train 2 done.\n");
2493 DRM_ERROR("FDI train 2 fail!\n");
2495 DRM_DEBUG_KMS("FDI train done\n");
2499 static const int snb_b_fdi_train_param[] = {
2500 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
2501 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
2502 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
2503 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
2506 /* The FDI link training functions for SNB/Cougarpoint. */
2507 static void gen6_fdi_link_train(struct drm_crtc *crtc)
2509 struct drm_device *dev = crtc->dev;
2510 struct drm_i915_private *dev_priv = dev->dev_private;
2511 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2512 int pipe = intel_crtc->pipe;
2513 u32 reg, temp, i, retry;
2515 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2517 reg = FDI_RX_IMR(pipe);
2518 temp = I915_READ(reg);
2519 temp &= ~FDI_RX_SYMBOL_LOCK;
2520 temp &= ~FDI_RX_BIT_LOCK;
2521 I915_WRITE(reg, temp);
2526 /* enable CPU FDI TX and PCH FDI RX */
2527 reg = FDI_TX_CTL(pipe);
2528 temp = I915_READ(reg);
2530 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2531 temp &= ~FDI_LINK_TRAIN_NONE;
2532 temp |= FDI_LINK_TRAIN_PATTERN_1;
2533 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2535 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2536 I915_WRITE(reg, temp | FDI_TX_ENABLE);
2538 I915_WRITE(FDI_RX_MISC(pipe),
2539 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
2541 reg = FDI_RX_CTL(pipe);
2542 temp = I915_READ(reg);
2543 if (HAS_PCH_CPT(dev)) {
2544 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2545 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
2547 temp &= ~FDI_LINK_TRAIN_NONE;
2548 temp |= FDI_LINK_TRAIN_PATTERN_1;
2550 I915_WRITE(reg, temp | FDI_RX_ENABLE);
2555 for (i = 0; i < 4; i++) {
2556 reg = FDI_TX_CTL(pipe);
2557 temp = I915_READ(reg);
2558 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2559 temp |= snb_b_fdi_train_param[i];
2560 I915_WRITE(reg, temp);
2565 for (retry = 0; retry < 5; retry++) {
2566 reg = FDI_RX_IIR(pipe);
2567 temp = I915_READ(reg);
2568 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2569 if (temp & FDI_RX_BIT_LOCK) {
2570 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2571 DRM_DEBUG_KMS("FDI train 1 done.\n");
2580 DRM_ERROR("FDI train 1 fail!\n");
2583 reg = FDI_TX_CTL(pipe);
2584 temp = I915_READ(reg);
2585 temp &= ~FDI_LINK_TRAIN_NONE;
2586 temp |= FDI_LINK_TRAIN_PATTERN_2;
2588 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2590 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2592 I915_WRITE(reg, temp);
2594 reg = FDI_RX_CTL(pipe);
2595 temp = I915_READ(reg);
2596 if (HAS_PCH_CPT(dev)) {
2597 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2598 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
2600 temp &= ~FDI_LINK_TRAIN_NONE;
2601 temp |= FDI_LINK_TRAIN_PATTERN_2;
2603 I915_WRITE(reg, temp);
2608 for (i = 0; i < 4; i++) {
2609 reg = FDI_TX_CTL(pipe);
2610 temp = I915_READ(reg);
2611 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2612 temp |= snb_b_fdi_train_param[i];
2613 I915_WRITE(reg, temp);
2618 for (retry = 0; retry < 5; retry++) {
2619 reg = FDI_RX_IIR(pipe);
2620 temp = I915_READ(reg);
2621 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2622 if (temp & FDI_RX_SYMBOL_LOCK) {
2623 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2624 DRM_DEBUG_KMS("FDI train 2 done.\n");
2633 DRM_ERROR("FDI train 2 fail!\n");
2635 DRM_DEBUG_KMS("FDI train done.\n");
2638 /* Manual link training for Ivy Bridge A0 parts */
2639 static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
2641 struct drm_device *dev = crtc->dev;
2642 struct drm_i915_private *dev_priv = dev->dev_private;
2643 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2644 int pipe = intel_crtc->pipe;
2647 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2649 reg = FDI_RX_IMR(pipe);
2650 temp = I915_READ(reg);
2651 temp &= ~FDI_RX_SYMBOL_LOCK;
2652 temp &= ~FDI_RX_BIT_LOCK;
2653 I915_WRITE(reg, temp);
2658 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
2659 I915_READ(FDI_RX_IIR(pipe)));
2661 /* enable CPU FDI TX and PCH FDI RX */
2662 reg = FDI_TX_CTL(pipe);
2663 temp = I915_READ(reg);
2665 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2666 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
2667 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
2668 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2669 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2670 temp |= FDI_COMPOSITE_SYNC;
2671 I915_WRITE(reg, temp | FDI_TX_ENABLE);
2673 I915_WRITE(FDI_RX_MISC(pipe),
2674 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
2676 reg = FDI_RX_CTL(pipe);
2677 temp = I915_READ(reg);
2678 temp &= ~FDI_LINK_TRAIN_AUTO;
2679 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2680 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
2681 temp |= FDI_COMPOSITE_SYNC;
2682 I915_WRITE(reg, temp | FDI_RX_ENABLE);
2687 for (i = 0; i < 4; i++) {
2688 reg = FDI_TX_CTL(pipe);
2689 temp = I915_READ(reg);
2690 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2691 temp |= snb_b_fdi_train_param[i];
2692 I915_WRITE(reg, temp);
2697 reg = FDI_RX_IIR(pipe);
2698 temp = I915_READ(reg);
2699 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2701 if (temp & FDI_RX_BIT_LOCK ||
2702 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
2703 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2704 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i);
2709 DRM_ERROR("FDI train 1 fail!\n");
2712 reg = FDI_TX_CTL(pipe);
2713 temp = I915_READ(reg);
2714 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
2715 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
2716 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2717 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2718 I915_WRITE(reg, temp);
2720 reg = FDI_RX_CTL(pipe);
2721 temp = I915_READ(reg);
2722 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2723 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
2724 I915_WRITE(reg, temp);
2729 for (i = 0; i < 4; i++) {
2730 reg = FDI_TX_CTL(pipe);
2731 temp = I915_READ(reg);
2732 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2733 temp |= snb_b_fdi_train_param[i];
2734 I915_WRITE(reg, temp);
2739 reg = FDI_RX_IIR(pipe);
2740 temp = I915_READ(reg);
2741 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2743 if (temp & FDI_RX_SYMBOL_LOCK) {
2744 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2745 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i);
2750 DRM_ERROR("FDI train 2 fail!\n");
2752 DRM_DEBUG_KMS("FDI train done.\n");
2755 static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
2757 struct drm_device *dev = intel_crtc->base.dev;
2758 struct drm_i915_private *dev_priv = dev->dev_private;
2759 int pipe = intel_crtc->pipe;
2763 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
2764 reg = FDI_RX_CTL(pipe);
2765 temp = I915_READ(reg);
2766 temp &= ~((0x7 << 19) | (0x7 << 16));
2767 temp |= (intel_crtc->fdi_lanes - 1) << 19;
2768 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
2769 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
2774 /* Switch from Rawclk to PCDclk */
2775 temp = I915_READ(reg);
2776 I915_WRITE(reg, temp | FDI_PCDCLK);
2781 /* Enable CPU FDI TX PLL, always on for Ironlake */
2782 reg = FDI_TX_CTL(pipe);
2783 temp = I915_READ(reg);
2784 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
2785 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
2792 static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
2794 struct drm_device *dev = intel_crtc->base.dev;
2795 struct drm_i915_private *dev_priv = dev->dev_private;
2796 int pipe = intel_crtc->pipe;
2799 /* Switch from PCDclk to Rawclk */
2800 reg = FDI_RX_CTL(pipe);
2801 temp = I915_READ(reg);
2802 I915_WRITE(reg, temp & ~FDI_PCDCLK);
2804 /* Disable CPU FDI TX PLL */
2805 reg = FDI_TX_CTL(pipe);
2806 temp = I915_READ(reg);
2807 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
2812 reg = FDI_RX_CTL(pipe);
2813 temp = I915_READ(reg);
2814 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
2816 /* Wait for the clocks to turn off. */
2821 static void ironlake_fdi_disable(struct drm_crtc *crtc)
2823 struct drm_device *dev = crtc->dev;
2824 struct drm_i915_private *dev_priv = dev->dev_private;
2825 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2826 int pipe = intel_crtc->pipe;
2829 /* disable CPU FDI tx and PCH FDI rx */
2830 reg = FDI_TX_CTL(pipe);
2831 temp = I915_READ(reg);
2832 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
2835 reg = FDI_RX_CTL(pipe);
2836 temp = I915_READ(reg);
2837 temp &= ~(0x7 << 16);
2838 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
2839 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
2844 /* Ironlake workaround, disable clock pointer after downing FDI */
2845 if (HAS_PCH_IBX(dev)) {
2846 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
2849 /* still set train pattern 1 */
2850 reg = FDI_TX_CTL(pipe);
2851 temp = I915_READ(reg);
2852 temp &= ~FDI_LINK_TRAIN_NONE;
2853 temp |= FDI_LINK_TRAIN_PATTERN_1;
2854 I915_WRITE(reg, temp);
2856 reg = FDI_RX_CTL(pipe);
2857 temp = I915_READ(reg);
2858 if (HAS_PCH_CPT(dev)) {
2859 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2860 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
2862 temp &= ~FDI_LINK_TRAIN_NONE;
2863 temp |= FDI_LINK_TRAIN_PATTERN_1;
2865 /* BPC in FDI rx is consistent with that in PIPECONF */
2866 temp &= ~(0x07 << 16);
2867 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
2868 I915_WRITE(reg, temp);
2874 static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
2876 struct drm_device *dev = crtc->dev;
2877 struct drm_i915_private *dev_priv = dev->dev_private;
2878 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2881 if (i915_reset_in_progress(&dev_priv->gpu_error) ||
2882 intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
2885 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
2886 pending = to_intel_crtc(crtc)->unpin_work != NULL;
2887 lockmgr(&dev->event_lock, LK_RELEASE);
2892 static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
2894 struct drm_device *dev = crtc->dev;
2895 struct drm_i915_private *dev_priv = dev->dev_private;
2897 if (crtc->fb == NULL)
2900 WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
2902 wait_event(dev_priv->pending_flip_queue,
2903 !intel_crtc_has_pending_flip(crtc));
2905 mutex_lock(&dev->struct_mutex);
2906 intel_finish_fb(crtc->fb);
2907 mutex_unlock(&dev->struct_mutex);
2910 static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc)
2912 struct drm_device *dev = crtc->dev;
2913 struct intel_encoder *intel_encoder;
2916 * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
2917 * must be driven by its own crtc; no sharing is possible.
2919 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
2920 switch (intel_encoder->type) {
2921 case INTEL_OUTPUT_EDP:
2922 if (!intel_encoder_is_pch_edp(&intel_encoder->base))
2931 static bool haswell_crtc_driving_pch(struct drm_crtc *crtc)
2933 return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG);
2936 /* Program iCLKIP clock to the desired frequency */
2937 static void lpt_program_iclkip(struct drm_crtc *crtc)
2939 struct drm_device *dev = crtc->dev;
2940 struct drm_i915_private *dev_priv = dev->dev_private;
2941 u32 divsel, phaseinc, auxdiv, phasedir = 0;
2944 mutex_lock(&dev_priv->dpio_lock);
2946 /* It is necessary to ungate the pixclk gate prior to programming
2947 * the divisors, and gate it back when it is done.
2949 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
2951 /* Disable SSCCTL */
2952 intel_sbi_write(dev_priv, SBI_SSCCTL6,
2953 intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
2957 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
2958 if (crtc->mode.clock == 20000) {
2963 /* The iCLK virtual clock root frequency is in MHz,
2964 * but the crtc->mode.clock in in KHz. To get the divisors,
2965 * it is necessary to divide one by another, so we
2966 * convert the virtual clock precision to KHz here for higher
2969 u32 iclk_virtual_root_freq = 172800 * 1000;
2970 u32 iclk_pi_range = 64;
2971 u32 desired_divisor, msb_divisor_value, pi_value;
2973 desired_divisor = (iclk_virtual_root_freq / crtc->mode.clock);
2974 msb_divisor_value = desired_divisor / iclk_pi_range;
2975 pi_value = desired_divisor % iclk_pi_range;
2978 divsel = msb_divisor_value - 2;
2979 phaseinc = pi_value;
2982 /* This should not happen with any sane values */
2983 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
2984 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
2985 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
2986 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
2988 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
2995 /* Program SSCDIVINTPHASE6 */
2996 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
2997 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
2998 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
2999 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
3000 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
3001 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
3002 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
3003 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
3005 /* Program SSCAUXDIV */
3006 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
3007 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3008 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
3009 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
3011 /* Enable modulator and associated divider */
3012 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
3013 temp &= ~SBI_SSCCTL_DISABLE;
3014 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
3016 /* Wait for initialization time */
3019 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
3021 mutex_unlock(&dev_priv->dpio_lock);
3025 * Enable PCH resources required for PCH ports:
3027 * - FDI training & RX/TX
3028 * - update transcoder timings
3029 * - DP transcoding bits
3032 static void ironlake_pch_enable(struct drm_crtc *crtc)
3034 struct drm_device *dev = crtc->dev;
3035 struct drm_i915_private *dev_priv = dev->dev_private;
3036 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3037 int pipe = intel_crtc->pipe;
3040 assert_transcoder_disabled(dev_priv, pipe);
3042 /* Write the TU size bits before fdi link training, so that error
3043 * detection works. */
3044 I915_WRITE(FDI_RX_TUSIZE1(pipe),
3045 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
3047 /* For PCH output, training FDI link */
3048 dev_priv->display.fdi_link_train(crtc);
3050 /* XXX: pch pll's can be enabled any time before we enable the PCH
3051 * transcoder, and we actually should do this to not upset any PCH
3052 * transcoder that already use the clock when we share it.
3054 * Note that enable_pch_pll tries to do the right thing, but get_pch_pll
3055 * unconditionally resets the pll - we need that to have the right LVDS
3056 * enable sequence. */
3057 ironlake_enable_pch_pll(intel_crtc);
3059 if (HAS_PCH_CPT(dev)) {
3062 temp = I915_READ(PCH_DPLL_SEL);
3066 temp |= TRANSA_DPLL_ENABLE;
3067 sel = TRANSA_DPLLB_SEL;
3070 temp |= TRANSB_DPLL_ENABLE;
3071 sel = TRANSB_DPLLB_SEL;
3074 temp |= TRANSC_DPLL_ENABLE;
3075 sel = TRANSC_DPLLB_SEL;
3078 if (intel_crtc->pch_pll->pll_reg == _PCH_DPLL_B)
3082 I915_WRITE(PCH_DPLL_SEL, temp);
3085 /* set transcoder timing, panel must allow it */
3086 assert_panel_unlocked(dev_priv, pipe);
3087 I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
3088 I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
3089 I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
3091 I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
3092 I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
3093 I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
3094 I915_WRITE(TRANS_VSYNCSHIFT(pipe), I915_READ(VSYNCSHIFT(pipe)));
3096 intel_fdi_normal_train(crtc);
3098 /* For PCH DP, enable TRANS_DP_CTL */
3099 if (HAS_PCH_CPT(dev) &&
3100 (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
3101 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
3102 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
3103 reg = TRANS_DP_CTL(pipe);
3104 temp = I915_READ(reg);
3105 temp &= ~(TRANS_DP_PORT_SEL_MASK |
3106 TRANS_DP_SYNC_MASK |
3108 temp |= (TRANS_DP_OUTPUT_ENABLE |
3109 TRANS_DP_ENH_FRAMING);
3110 temp |= bpc << 9; /* same format but at 11:9 */
3112 if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
3113 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
3114 if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
3115 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
3117 switch (intel_trans_dp_port_sel(crtc)) {
3119 temp |= TRANS_DP_PORT_SEL_B;
3122 temp |= TRANS_DP_PORT_SEL_C;
3125 temp |= TRANS_DP_PORT_SEL_D;
3131 I915_WRITE(reg, temp);
3134 ironlake_enable_pch_transcoder(dev_priv, pipe);
3137 static void lpt_pch_enable(struct drm_crtc *crtc)
3139 struct drm_device *dev = crtc->dev;
3140 struct drm_i915_private *dev_priv = dev->dev_private;
3141 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3142 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
3144 assert_transcoder_disabled(dev_priv, TRANSCODER_A);
3146 lpt_program_iclkip(crtc);
3148 /* Set transcoder timing. */
3149 I915_WRITE(_TRANS_HTOTAL_A, I915_READ(HTOTAL(cpu_transcoder)));
3150 I915_WRITE(_TRANS_HBLANK_A, I915_READ(HBLANK(cpu_transcoder)));
3151 I915_WRITE(_TRANS_HSYNC_A, I915_READ(HSYNC(cpu_transcoder)));
3153 I915_WRITE(_TRANS_VTOTAL_A, I915_READ(VTOTAL(cpu_transcoder)));
3154 I915_WRITE(_TRANS_VBLANK_A, I915_READ(VBLANK(cpu_transcoder)));
3155 I915_WRITE(_TRANS_VSYNC_A, I915_READ(VSYNC(cpu_transcoder)));
3156 I915_WRITE(_TRANS_VSYNCSHIFT_A, I915_READ(VSYNCSHIFT(cpu_transcoder)));
3158 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
3161 static void intel_put_pch_pll(struct intel_crtc *intel_crtc)
3163 struct intel_pch_pll *pll = intel_crtc->pch_pll;
3168 if (pll->refcount == 0) {
3169 WARN(1, "bad PCH PLL refcount\n");
3174 intel_crtc->pch_pll = NULL;
3177 static struct intel_pch_pll *intel_get_pch_pll(struct intel_crtc *intel_crtc, u32 dpll, u32 fp)
3179 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
3180 struct intel_pch_pll *pll;
3183 pll = intel_crtc->pch_pll;
3185 DRM_DEBUG_KMS("CRTC:%d reusing existing PCH PLL %x\n",
3186 intel_crtc->base.base.id, pll->pll_reg);
3190 if (HAS_PCH_IBX(dev_priv->dev)) {
3191 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3192 i = intel_crtc->pipe;
3193 pll = &dev_priv->pch_plls[i];
3195 DRM_DEBUG_KMS("CRTC:%d using pre-allocated PCH PLL %x\n",
3196 intel_crtc->base.base.id, pll->pll_reg);
3201 for (i = 0; i < dev_priv->num_pch_pll; i++) {
3202 pll = &dev_priv->pch_plls[i];
3204 /* Only want to check enabled timings first */
3205 if (pll->refcount == 0)
3208 if (dpll == (I915_READ(pll->pll_reg) & 0x7fffffff) &&
3209 fp == I915_READ(pll->fp0_reg)) {
3210 DRM_DEBUG_KMS("CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n",
3211 intel_crtc->base.base.id,
3212 pll->pll_reg, pll->refcount, pll->active);
3218 /* Ok no matching timings, maybe there's a free one? */
3219 for (i = 0; i < dev_priv->num_pch_pll; i++) {
3220 pll = &dev_priv->pch_plls[i];
3221 if (pll->refcount == 0) {
3222 DRM_DEBUG_KMS("CRTC:%d allocated PCH PLL %x\n",
3223 intel_crtc->base.base.id, pll->pll_reg);
3231 intel_crtc->pch_pll = pll;
3233 DRM_DEBUG_DRIVER("using pll %d for pipe %d\n", i, intel_crtc->pipe);
3234 prepare: /* separate function? */
3235 DRM_DEBUG_DRIVER("switching PLL %x off\n", pll->pll_reg);
3237 /* Wait for the clocks to stabilize before rewriting the regs */
3238 I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
3239 POSTING_READ(pll->pll_reg);
3242 I915_WRITE(pll->fp0_reg, fp);
3243 I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
3248 void intel_cpt_verify_modeset(struct drm_device *dev, int pipe)
3250 struct drm_i915_private *dev_priv = dev->dev_private;
3251 int dslreg = PIPEDSL(pipe);
3254 temp = I915_READ(dslreg);
3256 if (wait_for(I915_READ(dslreg) != temp, 5)) {
3257 if (wait_for(I915_READ(dslreg) != temp, 5))
3258 DRM_ERROR("mode set failed: pipe %d stuck\n", pipe);
3262 static void ironlake_crtc_enable(struct drm_crtc *crtc)
3264 struct drm_device *dev = crtc->dev;
3265 struct drm_i915_private *dev_priv = dev->dev_private;
3266 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3267 struct intel_encoder *encoder;
3268 int pipe = intel_crtc->pipe;
3269 int plane = intel_crtc->plane;
3273 WARN_ON(!crtc->enabled);
3275 if (intel_crtc->active)
3278 intel_crtc->active = true;
3279 intel_update_watermarks(dev);
3281 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
3282 temp = I915_READ(PCH_LVDS);
3283 if ((temp & LVDS_PORT_EN) == 0)
3284 I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
3287 is_pch_port = ironlake_crtc_driving_pch(crtc);
3290 /* Note: FDI PLL enabling _must_ be done before we enable the
3291 * cpu pipes, hence this is separate from all the other fdi/pch
3293 ironlake_fdi_pll_enable(intel_crtc);
3295 assert_fdi_tx_disabled(dev_priv, pipe);
3296 assert_fdi_rx_disabled(dev_priv, pipe);
3299 for_each_encoder_on_crtc(dev, crtc, encoder)
3300 if (encoder->pre_enable)
3301 encoder->pre_enable(encoder);
3303 /* Enable panel fitting for LVDS */
3304 if (dev_priv->pch_pf_size &&
3305 (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
3306 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
3307 /* Force use of hard-coded filter coefficients
3308 * as some pre-programmed values are broken,
3311 if (IS_IVYBRIDGE(dev))
3312 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
3313 PF_PIPE_SEL_IVB(pipe));
3315 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
3316 I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
3317 I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
3321 * On ILK+ LUT must be loaded before the pipe is running but with
3324 intel_crtc_load_lut(crtc);
3326 intel_enable_pipe(dev_priv, pipe, is_pch_port);
3327 intel_enable_plane(dev_priv, plane, pipe);
3330 ironlake_pch_enable(crtc);
3332 mutex_lock(&dev->struct_mutex);
3333 intel_update_fbc(dev);
3334 mutex_unlock(&dev->struct_mutex);
3336 intel_crtc_update_cursor(crtc, true);
3338 for_each_encoder_on_crtc(dev, crtc, encoder)
3339 encoder->enable(encoder);
3341 if (HAS_PCH_CPT(dev))
3342 intel_cpt_verify_modeset(dev, intel_crtc->pipe);
3345 * There seems to be a race in PCH platform hw (at least on some
3346 * outputs) where an enabled pipe still completes any pageflip right
3347 * away (as if the pipe is off) instead of waiting for vblank. As soon
3348 * as the first vblank happend, everything works as expected. Hence just
3349 * wait for one vblank before returning to avoid strange things
3352 intel_wait_for_vblank(dev, intel_crtc->pipe);
3355 static void haswell_crtc_enable(struct drm_crtc *crtc)
3357 struct drm_device *dev = crtc->dev;
3358 struct drm_i915_private *dev_priv = dev->dev_private;
3359 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3360 struct intel_encoder *encoder;
3361 int pipe = intel_crtc->pipe;
3362 int plane = intel_crtc->plane;
3365 WARN_ON(!crtc->enabled);
3367 if (intel_crtc->active)
3370 intel_crtc->active = true;
3371 intel_update_watermarks(dev);
3373 is_pch_port = haswell_crtc_driving_pch(crtc);
3376 dev_priv->display.fdi_link_train(crtc);
3378 for_each_encoder_on_crtc(dev, crtc, encoder)
3379 if (encoder->pre_enable)
3380 encoder->pre_enable(encoder);
3382 intel_ddi_enable_pipe_clock(intel_crtc);
3384 /* Enable panel fitting for eDP */
3385 if (dev_priv->pch_pf_size &&
3386 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
3387 /* Force use of hard-coded filter coefficients
3388 * as some pre-programmed values are broken,
3391 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
3392 PF_PIPE_SEL_IVB(pipe));
3393 I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
3394 I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
3398 * On ILK+ LUT must be loaded before the pipe is running but with
3401 intel_crtc_load_lut(crtc);
3403 intel_ddi_set_pipe_settings(crtc);
3404 intel_ddi_enable_pipe_func(crtc);
3406 intel_enable_pipe(dev_priv, pipe, is_pch_port);
3407 intel_enable_plane(dev_priv, plane, pipe);
3410 lpt_pch_enable(crtc);
3412 mutex_lock(&dev->struct_mutex);
3413 intel_update_fbc(dev);
3414 mutex_unlock(&dev->struct_mutex);
3416 intel_crtc_update_cursor(crtc, true);
3418 for_each_encoder_on_crtc(dev, crtc, encoder)
3419 encoder->enable(encoder);
3422 * There seems to be a race in PCH platform hw (at least on some
3423 * outputs) where an enabled pipe still completes any pageflip right
3424 * away (as if the pipe is off) instead of waiting for vblank. As soon
3425 * as the first vblank happend, everything works as expected. Hence just
3426 * wait for one vblank before returning to avoid strange things
3429 intel_wait_for_vblank(dev, intel_crtc->pipe);
3432 static void ironlake_crtc_disable(struct drm_crtc *crtc)
3434 struct drm_device *dev = crtc->dev;
3435 struct drm_i915_private *dev_priv = dev->dev_private;
3436 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3437 struct intel_encoder *encoder;
3438 int pipe = intel_crtc->pipe;
3439 int plane = intel_crtc->plane;
3443 if (!intel_crtc->active)
3446 for_each_encoder_on_crtc(dev, crtc, encoder)
3447 encoder->disable(encoder);
3449 intel_crtc_wait_for_pending_flips(crtc);
3450 drm_vblank_off(dev, pipe);
3451 intel_crtc_update_cursor(crtc, false);
3453 intel_disable_plane(dev_priv, plane, pipe);
3455 if (dev_priv->cfb_plane == plane)
3456 intel_disable_fbc(dev);
3458 intel_disable_pipe(dev_priv, pipe);
3461 I915_WRITE(PF_CTL(pipe), 0);
3462 I915_WRITE(PF_WIN_SZ(pipe), 0);
3464 for_each_encoder_on_crtc(dev, crtc, encoder)
3465 if (encoder->post_disable)
3466 encoder->post_disable(encoder);
3468 ironlake_fdi_disable(crtc);
3470 ironlake_disable_pch_transcoder(dev_priv, pipe);
3472 if (HAS_PCH_CPT(dev)) {
3473 /* disable TRANS_DP_CTL */
3474 reg = TRANS_DP_CTL(pipe);
3475 temp = I915_READ(reg);
3476 temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
3477 temp |= TRANS_DP_PORT_SEL_NONE;
3478 I915_WRITE(reg, temp);
3480 /* disable DPLL_SEL */
3481 temp = I915_READ(PCH_DPLL_SEL);
3484 temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL);
3487 temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
3490 /* C shares PLL A or B */
3491 temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL);
3496 I915_WRITE(PCH_DPLL_SEL, temp);
3499 /* disable PCH DPLL */
3500 intel_disable_pch_pll(intel_crtc);
3502 ironlake_fdi_pll_disable(intel_crtc);
3504 intel_crtc->active = false;
3505 intel_update_watermarks(dev);
3507 mutex_lock(&dev->struct_mutex);
3508 intel_update_fbc(dev);
3509 mutex_unlock(&dev->struct_mutex);
3512 static void haswell_crtc_disable(struct drm_crtc *crtc)
3514 struct drm_device *dev = crtc->dev;
3515 struct drm_i915_private *dev_priv = dev->dev_private;
3516 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3517 struct intel_encoder *encoder;
3518 int pipe = intel_crtc->pipe;
3519 int plane = intel_crtc->plane;
3520 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
3523 if (!intel_crtc->active)
3526 is_pch_port = haswell_crtc_driving_pch(crtc);
3528 for_each_encoder_on_crtc(dev, crtc, encoder)
3529 encoder->disable(encoder);
3531 intel_crtc_wait_for_pending_flips(crtc);
3532 drm_vblank_off(dev, pipe);
3533 intel_crtc_update_cursor(crtc, false);
3535 intel_disable_plane(dev_priv, plane, pipe);
3537 if (dev_priv->cfb_plane == plane)
3538 intel_disable_fbc(dev);
3540 intel_disable_pipe(dev_priv, pipe);
3542 intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
3545 I915_WRITE(PF_CTL(pipe), 0);
3546 I915_WRITE(PF_WIN_SZ(pipe), 0);
3548 intel_ddi_disable_pipe_clock(intel_crtc);
3550 for_each_encoder_on_crtc(dev, crtc, encoder)
3551 if (encoder->post_disable)
3552 encoder->post_disable(encoder);
3555 lpt_disable_pch_transcoder(dev_priv);
3556 intel_ddi_fdi_disable(crtc);
3559 intel_crtc->active = false;
3560 intel_update_watermarks(dev);
3562 mutex_lock(&dev->struct_mutex);
3563 intel_update_fbc(dev);
3564 mutex_unlock(&dev->struct_mutex);
3567 static void ironlake_crtc_off(struct drm_crtc *crtc)
3569 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3570 intel_put_pch_pll(intel_crtc);
3573 static void haswell_crtc_off(struct drm_crtc *crtc)
3575 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3577 /* Stop saying we're using TRANSCODER_EDP because some other CRTC might
3578 * start using it. */
3579 intel_crtc->cpu_transcoder = (enum transcoder) intel_crtc->pipe;
3581 intel_ddi_put_crtc_pll(crtc);
3584 static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
3586 if (!enable && intel_crtc->overlay) {
3587 struct drm_device *dev = intel_crtc->base.dev;
3588 struct drm_i915_private *dev_priv = dev->dev_private;
3590 mutex_lock(&dev->struct_mutex);
3591 dev_priv->mm.interruptible = false;
3592 (void) intel_overlay_switch_off(intel_crtc->overlay);
3593 dev_priv->mm.interruptible = true;
3594 mutex_unlock(&dev->struct_mutex);
3597 /* Let userspace switch the overlay on again. In most cases userspace
3598 * has to recompute where to put it anyway.
3603 * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
3604 * cursor plane briefly if not already running after enabling the display
3606 * This workaround avoids occasional blank screens when self refresh is
3610 g4x_fixup_plane(struct drm_i915_private *dev_priv, enum i915_pipe pipe)
3612 u32 cntl = I915_READ(CURCNTR(pipe));
3614 if ((cntl & CURSOR_MODE) == 0) {
3615 u32 fw_bcl_self = I915_READ(FW_BLC_SELF);
3617 I915_WRITE(FW_BLC_SELF, fw_bcl_self & ~FW_BLC_SELF_EN);
3618 I915_WRITE(CURCNTR(pipe), CURSOR_MODE_64_ARGB_AX);
3619 intel_wait_for_vblank(dev_priv->dev, pipe);
3620 I915_WRITE(CURCNTR(pipe), cntl);
3621 I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe)));
3622 I915_WRITE(FW_BLC_SELF, fw_bcl_self);
3626 static void i9xx_crtc_enable(struct drm_crtc *crtc)
3628 struct drm_device *dev = crtc->dev;
3629 struct drm_i915_private *dev_priv = dev->dev_private;
3630 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3631 struct intel_encoder *encoder;
3632 int pipe = intel_crtc->pipe;
3633 int plane = intel_crtc->plane;
3635 WARN_ON(!crtc->enabled);
3637 if (intel_crtc->active)
3640 intel_crtc->active = true;
3641 intel_update_watermarks(dev);
3643 intel_enable_pll(dev_priv, pipe);
3645 for_each_encoder_on_crtc(dev, crtc, encoder)
3646 if (encoder->pre_enable)
3647 encoder->pre_enable(encoder);
3649 intel_enable_pipe(dev_priv, pipe, false);
3650 intel_enable_plane(dev_priv, plane, pipe);
3652 g4x_fixup_plane(dev_priv, pipe);
3654 intel_crtc_load_lut(crtc);
3655 intel_update_fbc(dev);
3657 /* Give the overlay scaler a chance to enable if it's on this pipe */
3658 intel_crtc_dpms_overlay(intel_crtc, true);
3659 intel_crtc_update_cursor(crtc, true);
3661 for_each_encoder_on_crtc(dev, crtc, encoder)
3662 encoder->enable(encoder);
3665 static void i9xx_crtc_disable(struct drm_crtc *crtc)
3667 struct drm_device *dev = crtc->dev;
3668 struct drm_i915_private *dev_priv = dev->dev_private;
3669 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3670 struct intel_encoder *encoder;
3671 int pipe = intel_crtc->pipe;
3672 int plane = intel_crtc->plane;
3676 if (!intel_crtc->active)
3679 for_each_encoder_on_crtc(dev, crtc, encoder)
3680 encoder->disable(encoder);
3682 /* Give the overlay scaler a chance to disable if it's on this pipe */
3683 intel_crtc_wait_for_pending_flips(crtc);
3684 drm_vblank_off(dev, pipe);
3685 intel_crtc_dpms_overlay(intel_crtc, false);
3686 intel_crtc_update_cursor(crtc, false);
3688 if (dev_priv->cfb_plane == plane)
3689 intel_disable_fbc(dev);
3691 intel_disable_plane(dev_priv, plane, pipe);
3692 intel_disable_pipe(dev_priv, pipe);
3694 /* Disable pannel fitter if it is on this pipe. */
3695 pctl = I915_READ(PFIT_CONTROL);
3696 if ((pctl & PFIT_ENABLE) &&
3697 ((pctl & PFIT_PIPE_MASK) >> PFIT_PIPE_SHIFT) == pipe)
3698 I915_WRITE(PFIT_CONTROL, 0);
3700 intel_disable_pll(dev_priv, pipe);
3702 intel_crtc->active = false;
3703 intel_update_fbc(dev);
3704 intel_update_watermarks(dev);
3707 static void i9xx_crtc_off(struct drm_crtc *crtc)
3711 static void intel_crtc_update_sarea(struct drm_crtc *crtc,
3714 struct drm_device *dev = crtc->dev;
3715 struct drm_i915_master_private *master_priv;
3716 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3717 int pipe = intel_crtc->pipe;
3719 if (!dev->primary->master)
3722 master_priv = dev->primary->master->driver_priv;
3723 if (!master_priv->sarea_priv)
3728 master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
3729 master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
3732 master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
3733 master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
3736 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
3742 * Sets the power management mode of the pipe and plane.
3744 void intel_crtc_update_dpms(struct drm_crtc *crtc)
3746 struct drm_device *dev = crtc->dev;
3747 struct drm_i915_private *dev_priv = dev->dev_private;
3748 struct intel_encoder *intel_encoder;
3749 bool enable = false;
3751 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
3752 enable |= intel_encoder->connectors_active;
3755 dev_priv->display.crtc_enable(crtc);
3757 dev_priv->display.crtc_disable(crtc);
3759 intel_crtc_update_sarea(crtc, enable);
3762 static void intel_crtc_noop(struct drm_crtc *crtc)
3766 static void intel_crtc_disable(struct drm_crtc *crtc)
3768 struct drm_device *dev = crtc->dev;
3769 struct drm_connector *connector;
3770 struct drm_i915_private *dev_priv = dev->dev_private;
3771 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3773 /* crtc should still be enabled when we disable it. */
3774 WARN_ON(!crtc->enabled);
3776 intel_crtc->eld_vld = false;
3777 dev_priv->display.crtc_disable(crtc);
3778 intel_crtc_update_sarea(crtc, false);
3779 dev_priv->display.off(crtc);
3781 assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
3782 assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe);
3785 mutex_lock(&dev->struct_mutex);
3786 intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
3787 mutex_unlock(&dev->struct_mutex);
3791 /* Update computed state. */
3792 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3793 if (!connector->encoder || !connector->encoder->crtc)
3796 if (connector->encoder->crtc != crtc)
3799 connector->dpms = DRM_MODE_DPMS_OFF;
3800 to_intel_encoder(connector->encoder)->connectors_active = false;
3804 void intel_modeset_disable(struct drm_device *dev)
3806 struct drm_crtc *crtc;
3808 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
3810 intel_crtc_disable(crtc);
3814 void intel_encoder_noop(struct drm_encoder *encoder)
3818 void intel_encoder_destroy(struct drm_encoder *encoder)
3820 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
3822 drm_encoder_cleanup(encoder);
3823 drm_free(intel_encoder, M_DRM);
3826 /* Simple dpms helper for encodres with just one connector, no cloning and only
3827 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
3828 * state of the entire output pipe. */
3829 void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
3831 if (mode == DRM_MODE_DPMS_ON) {
3832 encoder->connectors_active = true;
3834 intel_crtc_update_dpms(encoder->base.crtc);
3836 encoder->connectors_active = false;
3838 intel_crtc_update_dpms(encoder->base.crtc);
3842 /* Cross check the actual hw state with our own modeset state tracking (and it's
3843 * internal consistency). */
3844 static void intel_connector_check_state(struct intel_connector *connector)
3846 if (connector->get_hw_state(connector)) {
3847 struct intel_encoder *encoder = connector->encoder;
3848 struct drm_crtc *crtc;
3849 bool encoder_enabled;
3850 enum i915_pipe pipe;
3852 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
3853 connector->base.base.id,
3854 drm_get_connector_name(&connector->base));
3856 WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
3857 "wrong connector dpms state\n");
3858 WARN(connector->base.encoder != &encoder->base,
3859 "active connector not linked to encoder\n");
3860 WARN(!encoder->connectors_active,
3861 "encoder->connectors_active not set\n");
3863 encoder_enabled = encoder->get_hw_state(encoder, &pipe);
3864 WARN(!encoder_enabled, "encoder not enabled\n");
3865 if (WARN_ON(!encoder->base.crtc))
3868 crtc = encoder->base.crtc;
3870 WARN(!crtc->enabled, "crtc not enabled\n");
3871 WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
3872 WARN(pipe != to_intel_crtc(crtc)->pipe,
3873 "encoder active on the wrong pipe\n");
3877 /* Even simpler default implementation, if there's really no special case to
3879 void intel_connector_dpms(struct drm_connector *connector, int mode)
3881 struct intel_encoder *encoder = intel_attached_encoder(connector);
3883 /* All the simple cases only support two dpms states. */
3884 if (mode != DRM_MODE_DPMS_ON)
3885 mode = DRM_MODE_DPMS_OFF;
3887 if (mode == connector->dpms)
3890 connector->dpms = mode;
3892 /* Only need to change hw state when actually enabled */
3893 if (encoder->base.crtc)
3894 intel_encoder_dpms(encoder, mode);
3896 WARN_ON(encoder->connectors_active != false);
3898 intel_modeset_check_state(connector->dev);
3901 /* Simple connector->get_hw_state implementation for encoders that support only
3902 * one connector and no cloning and hence the encoder state determines the state
3903 * of the connector. */
3904 bool intel_connector_get_hw_state(struct intel_connector *connector)
3906 enum i915_pipe pipe = 0;
3907 struct intel_encoder *encoder = connector->encoder;
3909 return encoder->get_hw_state(encoder, &pipe);
3912 static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
3913 const struct drm_display_mode *mode,
3914 struct drm_display_mode *adjusted_mode)
3916 struct drm_device *dev = crtc->dev;
3918 if (HAS_PCH_SPLIT(dev)) {
3919 /* FDI link clock is fixed at 2.7G */
3920 if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
3924 /* All interlaced capable intel hw wants timings in frames. Note though
3925 * that intel_lvds_mode_fixup does some funny tricks with the crtc
3926 * timings, so we need to be careful not to clobber these.*/
3927 if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
3928 drm_mode_set_crtcinfo(adjusted_mode, 0);
3930 /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
3931 * with a hsync front porch of 0.
3933 if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
3934 adjusted_mode->hsync_start == adjusted_mode->hdisplay)
3940 static int valleyview_get_display_clock_speed(struct drm_device *dev)
3942 return 400000; /* FIXME */
3945 static int i945_get_display_clock_speed(struct drm_device *dev)
3950 static int i915_get_display_clock_speed(struct drm_device *dev)
3955 static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
3960 static int i915gm_get_display_clock_speed(struct drm_device *dev)
3964 pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
3966 if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
3969 switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
3970 case GC_DISPLAY_CLOCK_333_MHZ:
3973 case GC_DISPLAY_CLOCK_190_200_MHZ:
3979 static int i865_get_display_clock_speed(struct drm_device *dev)
3984 static int i855_get_display_clock_speed(struct drm_device *dev)
3987 /* Assume that the hardware is in the high speed state. This
3988 * should be the default.
3990 switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
3991 case GC_CLOCK_133_200:
3992 case GC_CLOCK_100_200:
3994 case GC_CLOCK_166_250:
3996 case GC_CLOCK_100_133:
4000 /* Shouldn't happen */
4004 static int i830_get_display_clock_speed(struct drm_device *dev)
4010 intel_reduce_ratio(uint32_t *num, uint32_t *den)
4012 while (*num > 0xffffff || *den > 0xffffff) {
4019 intel_link_compute_m_n(int bits_per_pixel, int nlanes,
4020 int pixel_clock, int link_clock,
4021 struct intel_link_m_n *m_n)
4024 m_n->gmch_m = bits_per_pixel * pixel_clock;
4025 m_n->gmch_n = link_clock * nlanes * 8;
4026 intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
4027 m_n->link_m = pixel_clock;
4028 m_n->link_n = link_clock;
4029 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
4032 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
4034 if (i915_panel_use_ssc >= 0)
4035 return i915_panel_use_ssc != 0;
4036 return dev_priv->lvds_use_ssc
4037 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
4041 * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
4042 * @crtc: CRTC structure
4043 * @mode: requested mode
4045 * A pipe may be connected to one or more outputs. Based on the depth of the
4046 * attached framebuffer, choose a good color depth to use on the pipe.
4048 * If possible, match the pipe depth to the fb depth. In some cases, this
4049 * isn't ideal, because the connected output supports a lesser or restricted
4050 * set of depths. Resolve that here:
4051 * LVDS typically supports only 6bpc, so clamp down in that case
4052 * HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
4053 * Displays may support a restricted set as well, check EDID and clamp as
4055 * DP may want to dither down to 6bpc to fit larger modes
4058 * Dithering requirement (i.e. false if display bpc and pipe bpc match,
4059 * true if they don't match).
4061 static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
4062 struct drm_framebuffer *fb,
4063 unsigned int *pipe_bpp,
4064 struct drm_display_mode *mode)
4066 struct drm_device *dev = crtc->dev;
4067 struct drm_i915_private *dev_priv = dev->dev_private;
4068 struct drm_connector *connector;
4069 struct intel_encoder *intel_encoder;
4070 unsigned int display_bpc = UINT_MAX, bpc;
4072 /* Walk the encoders & connectors on this crtc, get min bpc */
4073 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
4075 if (intel_encoder->type == INTEL_OUTPUT_LVDS) {
4076 unsigned int lvds_bpc;
4078 if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) ==
4084 if (lvds_bpc < display_bpc) {
4085 DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
4086 display_bpc = lvds_bpc;
4091 /* Not one of the known troublemakers, check the EDID */
4092 list_for_each_entry(connector, &dev->mode_config.connector_list,
4094 if (connector->encoder != &intel_encoder->base)
4097 /* Don't use an invalid EDID bpc value */
4098 if (connector->display_info.bpc &&
4099 connector->display_info.bpc < display_bpc) {
4100 DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
4101 display_bpc = connector->display_info.bpc;
4105 if (intel_encoder->type == INTEL_OUTPUT_EDP) {
4106 /* Use VBT settings if we have an eDP panel */
4107 unsigned int edp_bpc = dev_priv->edp.bpp / 3;
4109 if (edp_bpc && edp_bpc < display_bpc) {
4110 DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
4111 display_bpc = edp_bpc;
4117 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
4118 * through, clamp it down. (Note: >12bpc will be caught below.)
4120 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
4121 if (display_bpc > 8 && display_bpc < 12) {
4122 DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
4125 DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
4131 if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
4132 DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
4137 * We could just drive the pipe at the highest bpc all the time and
4138 * enable dithering as needed, but that costs bandwidth. So choose
4139 * the minimum value that expresses the full color range of the fb but
4140 * also stays within the max display bpc discovered above.
4143 switch (fb->depth) {
4145 bpc = 8; /* since we go through a colormap */
4149 bpc = 6; /* min is 18bpp */
4161 DRM_DEBUG("unsupported depth, assuming 24 bits\n");
4162 bpc = min((unsigned int)8, display_bpc);
4166 display_bpc = min(display_bpc, bpc);
4168 DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
4171 *pipe_bpp = display_bpc * 3;
4173 return display_bpc != bpc;
4176 static int vlv_get_refclk(struct drm_crtc *crtc)
4178 struct drm_device *dev = crtc->dev;
4179 struct drm_i915_private *dev_priv = dev->dev_private;
4180 int refclk = 27000; /* for DP & HDMI */
4182 return 100000; /* only one validated so far */
4184 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
4186 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
4187 if (intel_panel_use_ssc(dev_priv))
4191 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
4198 static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
4200 struct drm_device *dev = crtc->dev;
4201 struct drm_i915_private *dev_priv = dev->dev_private;
4204 if (IS_VALLEYVIEW(dev)) {
4205 refclk = vlv_get_refclk(crtc);
4206 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4207 intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
4208 refclk = dev_priv->lvds_ssc_freq * 1000;
4209 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
4211 } else if (!IS_GEN2(dev)) {
4220 static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode *adjusted_mode,
4221 intel_clock_t *clock)
4223 /* SDVO TV has fixed PLL values depend on its clock range,
4224 this mirrors vbios setting. */
4225 if (adjusted_mode->clock >= 100000
4226 && adjusted_mode->clock < 140500) {
4232 } else if (adjusted_mode->clock >= 140500
4233 && adjusted_mode->clock <= 200000) {
4242 static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
4243 intel_clock_t *clock,
4244 intel_clock_t *reduced_clock)
4246 struct drm_device *dev = crtc->dev;
4247 struct drm_i915_private *dev_priv = dev->dev_private;
4248 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4249 int pipe = intel_crtc->pipe;
4252 if (IS_PINEVIEW(dev)) {
4253 fp = (1 << clock->n) << 16 | clock->m1 << 8 | clock->m2;
4255 fp2 = (1 << reduced_clock->n) << 16 |
4256 reduced_clock->m1 << 8 | reduced_clock->m2;
4258 fp = clock->n << 16 | clock->m1 << 8 | clock->m2;
4260 fp2 = reduced_clock->n << 16 | reduced_clock->m1 << 8 |
4264 I915_WRITE(FP0(pipe), fp);
4266 intel_crtc->lowfreq_avail = false;
4267 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4268 reduced_clock && i915_powersave) {
4269 I915_WRITE(FP1(pipe), fp2);
4270 intel_crtc->lowfreq_avail = true;
4272 I915_WRITE(FP1(pipe), fp);
4276 static void vlv_update_pll(struct drm_crtc *crtc,
4277 struct drm_display_mode *mode,
4278 struct drm_display_mode *adjusted_mode,
4279 intel_clock_t *clock, intel_clock_t *reduced_clock,
4282 struct drm_device *dev = crtc->dev;
4283 struct drm_i915_private *dev_priv = dev->dev_private;
4284 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4285 int pipe = intel_crtc->pipe;
4286 u32 dpll, mdiv, pdiv;
4287 u32 bestn, bestm1, bestm2, bestp1, bestp2;
4291 lockmgr(&dev_priv->dpio_lock, LK_EXCLUSIVE);
4293 is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
4294 intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
4296 dpll = DPLL_VGA_MODE_DIS;
4297 dpll |= DPLL_EXT_BUFFER_ENABLE_VLV;
4298 dpll |= DPLL_REFA_CLK_ENABLE_VLV;
4299 dpll |= DPLL_INTEGRATED_CLOCK_VLV;
4301 I915_WRITE(DPLL(pipe), dpll);
4302 POSTING_READ(DPLL(pipe));
4311 * In Valleyview PLL and program lane counter registers are exposed
4312 * through DPIO interface
4314 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
4315 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
4316 mdiv |= ((bestn << DPIO_N_SHIFT));
4317 mdiv |= (1 << DPIO_POST_DIV_SHIFT);
4318 mdiv |= (1 << DPIO_K_SHIFT);
4319 mdiv |= DPIO_ENABLE_CALIBRATION;
4320 intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv);
4322 intel_dpio_write(dev_priv, DPIO_CORE_CLK(pipe), 0x01000000);
4324 pdiv = (1 << DPIO_REFSEL_OVERRIDE) | (5 << DPIO_PLL_MODESEL_SHIFT) |
4325 (3 << DPIO_BIAS_CURRENT_CTL_SHIFT) | (1<<20) |
4326 (7 << DPIO_PLL_REFCLK_SEL_SHIFT) | (8 << DPIO_DRIVER_CTL_SHIFT) |
4327 (5 << DPIO_CLK_BIAS_CTL_SHIFT);
4328 intel_dpio_write(dev_priv, DPIO_REFSFR(pipe), pdiv);
4330 intel_dpio_write(dev_priv, DPIO_LFP_COEFF(pipe), 0x005f003b);
4332 dpll |= DPLL_VCO_ENABLE;
4333 I915_WRITE(DPLL(pipe), dpll);
4334 POSTING_READ(DPLL(pipe));
4335 if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
4336 DRM_ERROR("DPLL %d failed to lock\n", pipe);
4338 intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620);
4340 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
4341 intel_dp_set_m_n(crtc, mode, adjusted_mode);
4343 I915_WRITE(DPLL(pipe), dpll);
4345 /* Wait for the clocks to stabilize. */
4346 POSTING_READ(DPLL(pipe));
4351 temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4353 temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
4357 I915_WRITE(DPLL_MD(pipe), temp);
4358 POSTING_READ(DPLL_MD(pipe));
4360 /* Now program lane control registers */
4361 if(intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)
4362 || intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
4367 intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp);
4369 if(intel_pipe_has_type(crtc,INTEL_OUTPUT_EDP))
4374 intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL2, temp);
4377 lockmgr(&dev_priv->dpio_lock, LK_RELEASE);
4380 static void i9xx_update_pll(struct drm_crtc *crtc,
4381 struct drm_display_mode *mode,
4382 struct drm_display_mode *adjusted_mode,
4383 intel_clock_t *clock, intel_clock_t *reduced_clock,
4386 struct drm_device *dev = crtc->dev;
4387 struct drm_i915_private *dev_priv = dev->dev_private;
4388 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4389 struct intel_encoder *encoder;
4390 int pipe = intel_crtc->pipe;
4394 i9xx_update_pll_dividers(crtc, clock, reduced_clock);
4396 is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
4397 intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
4399 dpll = DPLL_VGA_MODE_DIS;
4401 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
4402 dpll |= DPLLB_MODE_LVDS;
4404 dpll |= DPLLB_MODE_DAC_SERIAL;
4406 int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
4407 if (pixel_multiplier > 1) {
4408 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
4409 dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
4411 dpll |= DPLL_DVO_HIGH_SPEED;
4413 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
4414 dpll |= DPLL_DVO_HIGH_SPEED;
4416 /* compute bitmask from p1 value */
4417 if (IS_PINEVIEW(dev))
4418 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
4420 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4421 if (IS_G4X(dev) && reduced_clock)
4422 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
4424 switch (clock->p2) {
4426 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
4429 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
4432 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
4435 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
4438 if (INTEL_INFO(dev)->gen >= 4)
4439 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
4441 if (is_sdvo && intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4442 dpll |= PLL_REF_INPUT_TVCLKINBC;
4443 else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4444 /* XXX: just matching BIOS for now */
4445 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
4447 else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4448 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4449 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4451 dpll |= PLL_REF_INPUT_DREFCLK;
4453 dpll |= DPLL_VCO_ENABLE;
4454 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
4455 POSTING_READ(DPLL(pipe));
4458 for_each_encoder_on_crtc(dev, crtc, encoder)
4459 if (encoder->pre_pll_enable)
4460 encoder->pre_pll_enable(encoder);
4462 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
4463 intel_dp_set_m_n(crtc, mode, adjusted_mode);
4465 I915_WRITE(DPLL(pipe), dpll);
4467 /* Wait for the clocks to stabilize. */
4468 POSTING_READ(DPLL(pipe));
4471 if (INTEL_INFO(dev)->gen >= 4) {
4474 temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4476 temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
4480 I915_WRITE(DPLL_MD(pipe), temp);
4482 /* The pixel multiplier can only be updated once the
4483 * DPLL is enabled and the clocks are stable.
4485 * So write it again.
4487 I915_WRITE(DPLL(pipe), dpll);
4491 static void i8xx_update_pll(struct drm_crtc *crtc,
4492 struct drm_display_mode *adjusted_mode,
4493 intel_clock_t *clock, intel_clock_t *reduced_clock,
4496 struct drm_device *dev = crtc->dev;
4497 struct drm_i915_private *dev_priv = dev->dev_private;
4498 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4499 struct intel_encoder *encoder;
4500 int pipe = intel_crtc->pipe;
4503 i9xx_update_pll_dividers(crtc, clock, reduced_clock);
4505 dpll = DPLL_VGA_MODE_DIS;
4507 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
4508 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4511 dpll |= PLL_P1_DIVIDE_BY_TWO;
4513 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4515 dpll |= PLL_P2_DIVIDE_BY_4;
4518 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
4519 /* XXX: just matching BIOS for now */
4520 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
4522 else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
4523 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4524 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4526 dpll |= PLL_REF_INPUT_DREFCLK;
4528 dpll |= DPLL_VCO_ENABLE;
4529 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
4530 POSTING_READ(DPLL(pipe));
4533 for_each_encoder_on_crtc(dev, crtc, encoder)
4534 if (encoder->pre_pll_enable)
4535 encoder->pre_pll_enable(encoder);
4537 I915_WRITE(DPLL(pipe), dpll);
4539 /* Wait for the clocks to stabilize. */
4540 POSTING_READ(DPLL(pipe));
4543 /* The pixel multiplier can only be updated once the
4544 * DPLL is enabled and the clocks are stable.
4546 * So write it again.
4548 I915_WRITE(DPLL(pipe), dpll);
4551 static void intel_set_pipe_timings(struct intel_crtc *intel_crtc,
4552 struct drm_display_mode *mode,
4553 struct drm_display_mode *adjusted_mode)
4555 struct drm_device *dev = intel_crtc->base.dev;
4556 struct drm_i915_private *dev_priv = dev->dev_private;
4557 enum i915_pipe pipe = intel_crtc->pipe;
4558 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
4559 uint32_t vsyncshift;
4561 if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4562 /* the chip adds 2 halflines automatically */
4563 adjusted_mode->crtc_vtotal -= 1;
4564 adjusted_mode->crtc_vblank_end -= 1;
4565 vsyncshift = adjusted_mode->crtc_hsync_start
4566 - adjusted_mode->crtc_htotal / 2;
4571 if (INTEL_INFO(dev)->gen > 3)
4572 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
4574 I915_WRITE(HTOTAL(cpu_transcoder),
4575 (adjusted_mode->crtc_hdisplay - 1) |
4576 ((adjusted_mode->crtc_htotal - 1) << 16));
4577 I915_WRITE(HBLANK(cpu_transcoder),
4578 (adjusted_mode->crtc_hblank_start - 1) |
4579 ((adjusted_mode->crtc_hblank_end - 1) << 16));
4580 I915_WRITE(HSYNC(cpu_transcoder),
4581 (adjusted_mode->crtc_hsync_start - 1) |
4582 ((adjusted_mode->crtc_hsync_end - 1) << 16));
4584 I915_WRITE(VTOTAL(cpu_transcoder),
4585 (adjusted_mode->crtc_vdisplay - 1) |
4586 ((adjusted_mode->crtc_vtotal - 1) << 16));
4587 I915_WRITE(VBLANK(cpu_transcoder),
4588 (adjusted_mode->crtc_vblank_start - 1) |
4589 ((adjusted_mode->crtc_vblank_end - 1) << 16));
4590 I915_WRITE(VSYNC(cpu_transcoder),
4591 (adjusted_mode->crtc_vsync_start - 1) |
4592 ((adjusted_mode->crtc_vsync_end - 1) << 16));
4594 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
4595 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
4596 * documented on the DDI_FUNC_CTL register description, EDP Input Select
4598 if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
4599 (pipe == PIPE_B || pipe == PIPE_C))
4600 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
4602 /* pipesrc controls the size that is scaled from, which should
4603 * always be the user's requested size.
4605 I915_WRITE(PIPESRC(pipe),
4606 ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
4609 static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
4610 struct drm_display_mode *mode,
4611 struct drm_display_mode *adjusted_mode,
4613 struct drm_framebuffer *fb)
4615 struct drm_device *dev = crtc->dev;
4616 struct drm_i915_private *dev_priv = dev->dev_private;
4617 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4618 int pipe = intel_crtc->pipe;
4619 int plane = intel_crtc->plane;
4620 int refclk, num_connectors = 0;
4621 intel_clock_t clock, reduced_clock;
4622 u32 dspcntr, pipeconf;
4623 bool ok, has_reduced_clock = false, is_sdvo = false;
4624 bool is_lvds = false, is_tv = false, is_dp = false;
4625 struct intel_encoder *encoder;
4626 const intel_limit_t *limit;
4629 for_each_encoder_on_crtc(dev, crtc, encoder) {
4630 switch (encoder->type) {
4631 case INTEL_OUTPUT_LVDS:
4634 case INTEL_OUTPUT_SDVO:
4635 case INTEL_OUTPUT_HDMI:
4637 if (encoder->needs_tv_clock)
4640 case INTEL_OUTPUT_TVOUT:
4643 case INTEL_OUTPUT_DISPLAYPORT:
4651 refclk = i9xx_get_refclk(crtc, num_connectors);
4654 * Returns a set of divisors for the desired target clock with the given
4655 * refclk, or FALSE. The returned values represent the clock equation:
4656 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
4658 limit = intel_limit(crtc, refclk);
4659 ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
4662 DRM_ERROR("Couldn't find PLL settings for mode!\n");
4666 /* Ensure that the cursor is valid for the new mode before changing... */
4667 intel_crtc_update_cursor(crtc, true);
4669 if (is_lvds && dev_priv->lvds_downclock_avail) {
4671 * Ensure we match the reduced clock's P to the target clock.
4672 * If the clocks don't match, we can't switch the display clock
4673 * by using the FP0/FP1. In such case we will disable the LVDS
4674 * downclock feature.
4676 has_reduced_clock = limit->find_pll(limit, crtc,
4677 dev_priv->lvds_downclock,
4683 if (is_sdvo && is_tv)
4684 i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
4687 i8xx_update_pll(crtc, adjusted_mode, &clock,
4688 has_reduced_clock ? &reduced_clock : NULL,
4690 else if (IS_VALLEYVIEW(dev))
4691 vlv_update_pll(crtc, mode, adjusted_mode, &clock,
4692 has_reduced_clock ? &reduced_clock : NULL,
4695 i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
4696 has_reduced_clock ? &reduced_clock : NULL,
4699 /* setup pipeconf */
4700 pipeconf = I915_READ(PIPECONF(pipe));
4702 /* Set up the display plane register */
4703 dspcntr = DISPPLANE_GAMMA_ENABLE;
4706 dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
4708 dspcntr |= DISPPLANE_SEL_PIPE_B;
4710 if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
4711 /* Enable pixel doubling when the dot clock is > 90% of the (display)
4714 * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
4718 dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
4719 pipeconf |= PIPECONF_DOUBLE_WIDE;
4721 pipeconf &= ~PIPECONF_DOUBLE_WIDE;
4724 /* default to 8bpc */
4725 pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
4727 if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
4728 pipeconf |= PIPECONF_6BPC |
4729 PIPECONF_DITHER_EN |
4730 PIPECONF_DITHER_TYPE_SP;
4734 if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
4735 if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
4736 pipeconf |= PIPECONF_6BPC |
4738 I965_PIPECONF_ACTIVE;
4742 DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
4743 drm_mode_debug_printmodeline(mode);
4745 if (HAS_PIPE_CXSR(dev)) {
4746 if (intel_crtc->lowfreq_avail) {
4747 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
4748 pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
4750 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
4751 pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
4755 pipeconf &= ~PIPECONF_INTERLACE_MASK;
4756 if (!IS_GEN2(dev) &&
4757 adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
4758 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
4760 pipeconf |= PIPECONF_PROGRESSIVE;
4762 intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
4764 /* pipesrc and dspsize control the size that is scaled from,
4765 * which should always be the user's requested size.
4767 I915_WRITE(DSPSIZE(plane),
4768 ((mode->vdisplay - 1) << 16) |
4769 (mode->hdisplay - 1));
4770 I915_WRITE(DSPPOS(plane), 0);
4772 I915_WRITE(PIPECONF(pipe), pipeconf);
4773 POSTING_READ(PIPECONF(pipe));
4774 intel_enable_pipe(dev_priv, pipe, false);
4776 intel_wait_for_vblank(dev, pipe);
4778 I915_WRITE(DSPCNTR(plane), dspcntr);
4779 POSTING_READ(DSPCNTR(plane));
4781 ret = intel_pipe_set_base(crtc, x, y, fb);
4783 intel_update_watermarks(dev);
4788 static void ironlake_init_pch_refclk(struct drm_device *dev)
4790 struct drm_i915_private *dev_priv = dev->dev_private;
4791 struct drm_mode_config *mode_config = &dev->mode_config;
4792 struct intel_encoder *encoder;
4794 bool has_lvds = false;
4795 bool has_cpu_edp = false;
4796 bool has_pch_edp = false;
4797 bool has_panel = false;
4798 bool has_ck505 = false;
4799 bool can_ssc = false;
4801 /* We need to take the global config into account */
4802 list_for_each_entry(encoder, &mode_config->encoder_list,
4804 switch (encoder->type) {
4805 case INTEL_OUTPUT_LVDS:
4809 case INTEL_OUTPUT_EDP:
4811 if (intel_encoder_is_pch_edp(&encoder->base))
4819 if (HAS_PCH_IBX(dev)) {
4820 has_ck505 = dev_priv->display_clock_mode;
4821 can_ssc = has_ck505;
4827 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n",
4828 has_panel, has_lvds, has_pch_edp, has_cpu_edp,
4831 /* Ironlake: try to setup display ref clock before DPLL
4832 * enabling. This is only under driver's control after
4833 * PCH B stepping, previous chipset stepping should be
4834 * ignoring this setting.
4836 temp = I915_READ(PCH_DREF_CONTROL);
4837 /* Always enable nonspread source */
4838 temp &= ~DREF_NONSPREAD_SOURCE_MASK;
4841 temp |= DREF_NONSPREAD_CK505_ENABLE;
4843 temp |= DREF_NONSPREAD_SOURCE_ENABLE;
4846 temp &= ~DREF_SSC_SOURCE_MASK;
4847 temp |= DREF_SSC_SOURCE_ENABLE;
4849 /* SSC must be turned on before enabling the CPU output */
4850 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4851 DRM_DEBUG_KMS("Using SSC on panel\n");
4852 temp |= DREF_SSC1_ENABLE;
4854 temp &= ~DREF_SSC1_ENABLE;
4856 /* Get SSC going before enabling the outputs */
4857 I915_WRITE(PCH_DREF_CONTROL, temp);
4858 POSTING_READ(PCH_DREF_CONTROL);
4861 temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4863 /* Enable CPU source on CPU attached eDP */
4865 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4866 DRM_DEBUG_KMS("Using SSC on eDP\n");
4867 temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
4870 temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
4872 temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4874 I915_WRITE(PCH_DREF_CONTROL, temp);
4875 POSTING_READ(PCH_DREF_CONTROL);
4878 DRM_DEBUG_KMS("Disabling SSC entirely\n");
4880 temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4882 /* Turn off CPU output */
4883 temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4885 I915_WRITE(PCH_DREF_CONTROL, temp);
4886 POSTING_READ(PCH_DREF_CONTROL);
4889 /* Turn off the SSC source */
4890 temp &= ~DREF_SSC_SOURCE_MASK;
4891 temp |= DREF_SSC_SOURCE_DISABLE;
4894 temp &= ~ DREF_SSC1_ENABLE;
4896 I915_WRITE(PCH_DREF_CONTROL, temp);
4897 POSTING_READ(PCH_DREF_CONTROL);
4902 /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
4903 static void lpt_init_pch_refclk(struct drm_device *dev)
4905 struct drm_i915_private *dev_priv = dev->dev_private;
4906 struct drm_mode_config *mode_config = &dev->mode_config;
4907 struct intel_encoder *encoder;
4908 bool has_vga = false;
4909 bool is_sdv = false;
4912 list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
4913 switch (encoder->type) {
4914 case INTEL_OUTPUT_ANALOG:
4923 mutex_lock(&dev_priv->dpio_lock);
4925 /* XXX: Rip out SDV support once Haswell ships for real. */
4926 if (IS_HASWELL(dev) && (dev->pci_device & 0xFF00) == 0x0C00)
4929 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
4930 tmp &= ~SBI_SSCCTL_DISABLE;
4931 tmp |= SBI_SSCCTL_PATHALT;
4932 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
4936 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
4937 tmp &= ~SBI_SSCCTL_PATHALT;
4938 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
4941 tmp = I915_READ(SOUTH_CHICKEN2);
4942 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
4943 I915_WRITE(SOUTH_CHICKEN2, tmp);
4945 if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
4946 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
4947 DRM_ERROR("FDI mPHY reset assert timeout\n");
4949 tmp = I915_READ(SOUTH_CHICKEN2);
4950 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
4951 I915_WRITE(SOUTH_CHICKEN2, tmp);
4953 if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
4954 FDI_MPHY_IOSFSB_RESET_STATUS) == 0,
4956 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
4959 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
4960 tmp &= ~(0xFF << 24);
4961 tmp |= (0x12 << 24);
4962 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
4965 tmp = intel_sbi_read(dev_priv, 0x808C, SBI_MPHY);
4967 tmp |= (1 << 6) | (1 << 0);
4968 intel_sbi_write(dev_priv, 0x808C, tmp, SBI_MPHY);
4972 tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY);
4974 intel_sbi_write(dev_priv, 0x800C, tmp, SBI_MPHY);
4977 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
4979 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
4981 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
4983 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
4986 tmp = intel_sbi_read(dev_priv, 0x2038, SBI_MPHY);
4987 tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
4988 intel_sbi_write(dev_priv, 0x2038, tmp, SBI_MPHY);
4990 tmp = intel_sbi_read(dev_priv, 0x2138, SBI_MPHY);
4991 tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
4992 intel_sbi_write(dev_priv, 0x2138, tmp, SBI_MPHY);
4994 tmp = intel_sbi_read(dev_priv, 0x203C, SBI_MPHY);
4996 intel_sbi_write(dev_priv, 0x203C, tmp, SBI_MPHY);
4998 tmp = intel_sbi_read(dev_priv, 0x213C, SBI_MPHY);
5000 intel_sbi_write(dev_priv, 0x213C, tmp, SBI_MPHY);
5003 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
5004 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
5005 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
5007 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
5008 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
5009 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
5012 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
5015 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
5017 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
5020 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
5023 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
5026 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
5028 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
5031 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
5033 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
5034 tmp &= ~(0xFF << 16);
5035 tmp |= (0x1C << 16);
5036 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
5038 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
5039 tmp &= ~(0xFF << 16);
5040 tmp |= (0x1C << 16);
5041 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
5044 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
5046 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
5048 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
5050 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
5052 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
5053 tmp &= ~(0xF << 28);
5055 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
5057 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
5058 tmp &= ~(0xF << 28);
5060 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
5063 /* ULT uses SBI_GEN0, but ULT doesn't have VGA, so we don't care. */
5064 tmp = intel_sbi_read(dev_priv, SBI_DBUFF0, SBI_ICLK);
5065 tmp |= SBI_DBUFF0_ENABLE;
5066 intel_sbi_write(dev_priv, SBI_DBUFF0, tmp, SBI_ICLK);
5068 mutex_unlock(&dev_priv->dpio_lock);
5072 * Initialize reference clocks when the driver loads
5074 void intel_init_pch_refclk(struct drm_device *dev)
5076 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
5077 ironlake_init_pch_refclk(dev);
5078 else if (HAS_PCH_LPT(dev))
5079 lpt_init_pch_refclk(dev);
5082 static int ironlake_get_refclk(struct drm_crtc *crtc)
5084 struct drm_device *dev = crtc->dev;
5085 struct drm_i915_private *dev_priv = dev->dev_private;
5086 struct intel_encoder *encoder;
5087 struct intel_encoder *edp_encoder = NULL;
5088 int num_connectors = 0;
5089 bool is_lvds = false;
5091 for_each_encoder_on_crtc(dev, crtc, encoder) {
5092 switch (encoder->type) {
5093 case INTEL_OUTPUT_LVDS:
5096 case INTEL_OUTPUT_EDP:
5097 edp_encoder = encoder;
5103 if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
5104 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
5105 dev_priv->lvds_ssc_freq);
5106 return dev_priv->lvds_ssc_freq * 1000;
5112 static void ironlake_set_pipeconf(struct drm_crtc *crtc,
5113 struct drm_display_mode *adjusted_mode,
5116 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
5117 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5118 int pipe = intel_crtc->pipe;
5121 val = I915_READ(PIPECONF(pipe));
5123 val &= ~PIPECONF_BPC_MASK;
5124 switch (intel_crtc->bpp) {
5126 val |= PIPECONF_6BPC;
5129 val |= PIPECONF_8BPC;
5132 val |= PIPECONF_10BPC;
5135 val |= PIPECONF_12BPC;
5138 /* Case prevented by intel_choose_pipe_bpp_dither. */
5142 val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
5144 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
5146 val &= ~PIPECONF_INTERLACE_MASK;
5147 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
5148 val |= PIPECONF_INTERLACED_ILK;
5150 val |= PIPECONF_PROGRESSIVE;
5152 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5153 val |= PIPECONF_COLOR_RANGE_SELECT;
5155 val &= ~PIPECONF_COLOR_RANGE_SELECT;
5157 I915_WRITE(PIPECONF(pipe), val);
5158 POSTING_READ(PIPECONF(pipe));
5162 * Set up the pipe CSC unit.
5164 * Currently only full range RGB to limited range RGB conversion
5165 * is supported, but eventually this should handle various
5166 * RGB<->YCbCr scenarios as well.
5168 static void intel_set_pipe_csc(struct drm_crtc *crtc,
5169 const struct drm_display_mode *adjusted_mode)
5171 struct drm_device *dev = crtc->dev;
5172 struct drm_i915_private *dev_priv = dev->dev_private;
5173 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5174 int pipe = intel_crtc->pipe;
5175 uint16_t coeff = 0x7800; /* 1.0 */
5178 * TODO: Check what kind of values actually come out of the pipe
5179 * with these coeff/postoff values and adjust to get the best
5180 * accuracy. Perhaps we even need to take the bpc value into
5184 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5185 coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
5188 * GY/GU and RY/RU should be the other way around according
5189 * to BSpec, but reality doesn't agree. Just set them up in
5190 * a way that results in the correct picture.
5192 I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
5193 I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
5195 I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
5196 I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
5198 I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
5199 I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
5201 I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
5202 I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
5203 I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
5205 if (INTEL_INFO(dev)->gen > 6) {
5206 uint16_t postoff = 0;
5208 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5209 postoff = (16 * (1 << 13) / 255) & 0x1fff;
5211 I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
5212 I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
5213 I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
5215 I915_WRITE(PIPE_CSC_MODE(pipe), 0);
5217 uint32_t mode = CSC_MODE_YUV_TO_RGB;
5219 if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
5220 mode |= CSC_BLACK_SCREEN_OFFSET;
5222 I915_WRITE(PIPE_CSC_MODE(pipe), mode);
5226 static void haswell_set_pipeconf(struct drm_crtc *crtc,
5227 struct drm_display_mode *adjusted_mode,
5230 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
5231 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5232 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
5235 val = I915_READ(PIPECONF(cpu_transcoder));
5237 val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
5239 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
5241 val &= ~PIPECONF_INTERLACE_MASK_HSW;
5242 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
5243 val |= PIPECONF_INTERLACED_ILK;
5245 val |= PIPECONF_PROGRESSIVE;
5247 I915_WRITE(PIPECONF(cpu_transcoder), val);
5248 POSTING_READ(PIPECONF(cpu_transcoder));
5251 static bool ironlake_compute_clocks(struct drm_crtc *crtc,
5252 struct drm_display_mode *adjusted_mode,
5253 intel_clock_t *clock,
5254 bool *has_reduced_clock,
5255 intel_clock_t *reduced_clock)
5257 struct drm_device *dev = crtc->dev;
5258 struct drm_i915_private *dev_priv = dev->dev_private;
5259 struct intel_encoder *intel_encoder;
5261 const intel_limit_t *limit;
5262 bool ret, is_sdvo = false, is_tv = false, is_lvds = false;
5264 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
5265 switch (intel_encoder->type) {
5266 case INTEL_OUTPUT_LVDS:
5269 case INTEL_OUTPUT_SDVO:
5270 case INTEL_OUTPUT_HDMI:
5272 if (intel_encoder->needs_tv_clock)
5275 case INTEL_OUTPUT_TVOUT:
5281 refclk = ironlake_get_refclk(crtc);
5284 * Returns a set of divisors for the desired target clock with the given
5285 * refclk, or FALSE. The returned values represent the clock equation:
5286 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
5288 limit = intel_limit(crtc, refclk);
5289 ret = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
5294 if (is_lvds && dev_priv->lvds_downclock_avail) {
5296 * Ensure we match the reduced clock's P to the target clock.
5297 * If the clocks don't match, we can't switch the display clock
5298 * by using the FP0/FP1. In such case we will disable the LVDS
5299 * downclock feature.
5301 *has_reduced_clock = limit->find_pll(limit, crtc,
5302 dev_priv->lvds_downclock,
5308 if (is_sdvo && is_tv)
5309 i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
5314 static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
5316 struct drm_i915_private *dev_priv = dev->dev_private;
5319 temp = I915_READ(SOUTH_CHICKEN1);
5320 if (temp & FDI_BC_BIFURCATION_SELECT)
5323 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
5324 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
5326 temp |= FDI_BC_BIFURCATION_SELECT;
5327 DRM_DEBUG_KMS("enabling fdi C rx\n");
5328 I915_WRITE(SOUTH_CHICKEN1, temp);
5329 POSTING_READ(SOUTH_CHICKEN1);
5332 static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
5334 struct drm_device *dev = intel_crtc->base.dev;
5335 struct drm_i915_private *dev_priv = dev->dev_private;
5336 struct intel_crtc *pipe_B_crtc =
5337 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
5339 DRM_DEBUG_KMS("checking fdi config on pipe %i, lanes %i\n",
5340 intel_crtc->pipe, intel_crtc->fdi_lanes);
5341 if (intel_crtc->fdi_lanes > 4) {
5342 DRM_DEBUG_KMS("invalid fdi lane config on pipe %i: %i lanes\n",
5343 intel_crtc->pipe, intel_crtc->fdi_lanes);
5344 /* Clamp lanes to avoid programming the hw with bogus values. */
5345 intel_crtc->fdi_lanes = 4;
5350 if (dev_priv->num_pipe == 2)
5353 switch (intel_crtc->pipe) {
5357 if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
5358 intel_crtc->fdi_lanes > 2) {
5359 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
5360 intel_crtc->pipe, intel_crtc->fdi_lanes);
5361 /* Clamp lanes to avoid programming the hw with bogus values. */
5362 intel_crtc->fdi_lanes = 2;
5367 if (intel_crtc->fdi_lanes > 2)
5368 WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
5370 cpt_enable_fdi_bc_bifurcation(dev);
5374 if (!pipe_B_crtc->base.enabled || pipe_B_crtc->fdi_lanes <= 2) {
5375 if (intel_crtc->fdi_lanes > 2) {
5376 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
5377 intel_crtc->pipe, intel_crtc->fdi_lanes);
5378 /* Clamp lanes to avoid programming the hw with bogus values. */
5379 intel_crtc->fdi_lanes = 2;
5384 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5388 cpt_enable_fdi_bc_bifurcation(dev);
5396 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
5399 * Account for spread spectrum to avoid
5400 * oversubscribing the link. Max center spread
5401 * is 2.5%; use 5% for safety's sake.
5403 u32 bps = target_clock * bpp * 21 / 20;
5404 return bps / (link_bw * 8) + 1;
5407 static void ironlake_set_m_n(struct drm_crtc *crtc,
5408 struct drm_display_mode *mode,
5409 struct drm_display_mode *adjusted_mode)
5411 struct drm_device *dev = crtc->dev;
5412 struct drm_i915_private *dev_priv = dev->dev_private;
5413 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5414 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
5415 struct intel_encoder *intel_encoder, *edp_encoder = NULL;
5416 struct intel_link_m_n m_n = {0};
5417 int target_clock, pixel_multiplier, lane, link_bw;
5418 bool is_dp = false, is_cpu_edp = false;
5420 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
5421 switch (intel_encoder->type) {
5422 case INTEL_OUTPUT_DISPLAYPORT:
5425 case INTEL_OUTPUT_EDP:
5427 if (!intel_encoder_is_pch_edp(&intel_encoder->base))
5429 edp_encoder = intel_encoder;
5435 pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
5437 /* CPU eDP doesn't require FDI link, so just set DP M/N
5438 according to current link config */
5440 intel_edp_link_config(edp_encoder, &lane, &link_bw);
5442 /* FDI is a binary signal running at ~2.7GHz, encoding
5443 * each output octet as 10 bits. The actual frequency
5444 * is stored as a divider into a 100MHz clock, and the
5445 * mode pixel clock is stored in units of 1KHz.
5446 * Hence the bw of each lane in terms of the mode signal
5449 link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
5452 /* [e]DP over FDI requires target mode clock instead of link clock. */
5454 target_clock = intel_edp_target_clock(edp_encoder, mode);
5456 target_clock = mode->clock;
5458 target_clock = adjusted_mode->clock;
5461 lane = ironlake_get_lanes_required(target_clock, link_bw,
5464 intel_crtc->fdi_lanes = lane;
5466 if (pixel_multiplier > 1)
5467 link_bw *= pixel_multiplier;
5468 intel_link_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, &m_n);
5470 I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m);
5471 I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
5472 I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
5473 I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
5476 static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
5477 struct drm_display_mode *adjusted_mode,
5478 intel_clock_t *clock, u32 fp)
5480 struct drm_crtc *crtc = &intel_crtc->base;
5481 struct drm_device *dev = crtc->dev;
5482 struct drm_i915_private *dev_priv = dev->dev_private;
5483 struct intel_encoder *intel_encoder;
5485 int factor, pixel_multiplier, num_connectors = 0;
5486 bool is_lvds = false, is_sdvo = false, is_tv = false;
5487 bool is_dp = false, is_cpu_edp = false;
5489 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
5490 switch (intel_encoder->type) {
5491 case INTEL_OUTPUT_LVDS:
5494 case INTEL_OUTPUT_SDVO:
5495 case INTEL_OUTPUT_HDMI:
5497 if (intel_encoder->needs_tv_clock)
5500 case INTEL_OUTPUT_TVOUT:
5503 case INTEL_OUTPUT_DISPLAYPORT:
5506 case INTEL_OUTPUT_EDP:
5508 if (!intel_encoder_is_pch_edp(&intel_encoder->base))
5516 /* Enable autotuning of the PLL clock (if permissible) */
5519 if ((intel_panel_use_ssc(dev_priv) &&
5520 dev_priv->lvds_ssc_freq == 100) ||
5521 intel_is_dual_link_lvds(dev))
5523 } else if (is_sdvo && is_tv)
5526 if (clock->m < factor * clock->n)
5532 dpll |= DPLLB_MODE_LVDS;
5534 dpll |= DPLLB_MODE_DAC_SERIAL;
5536 pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
5537 if (pixel_multiplier > 1) {
5538 dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
5540 dpll |= DPLL_DVO_HIGH_SPEED;
5542 if (is_dp && !is_cpu_edp)
5543 dpll |= DPLL_DVO_HIGH_SPEED;
5545 /* compute bitmask from p1 value */
5546 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
5548 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
5550 switch (clock->p2) {
5552 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
5555 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
5558 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
5561 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
5565 if (is_sdvo && is_tv)
5566 dpll |= PLL_REF_INPUT_TVCLKINBC;
5568 /* XXX: just matching BIOS for now */
5569 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
5571 else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
5572 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
5574 dpll |= PLL_REF_INPUT_DREFCLK;
5579 static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
5580 struct drm_display_mode *mode,
5581 struct drm_display_mode *adjusted_mode,
5583 struct drm_framebuffer *fb)
5585 struct drm_device *dev = crtc->dev;
5586 struct drm_i915_private *dev_priv = dev->dev_private;
5587 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5588 int pipe = intel_crtc->pipe;
5589 int plane = intel_crtc->plane;
5590 int num_connectors = 0;
5591 intel_clock_t clock, reduced_clock;
5592 u32 dpll, fp = 0, fp2 = 0;
5593 bool ok, has_reduced_clock = false;
5594 bool is_lvds = false, is_dp = false, is_cpu_edp = false;
5595 struct intel_encoder *encoder;
5597 bool dither, fdi_config_ok;
5599 for_each_encoder_on_crtc(dev, crtc, encoder) {
5600 switch (encoder->type) {
5601 case INTEL_OUTPUT_LVDS:
5604 case INTEL_OUTPUT_DISPLAYPORT:
5607 case INTEL_OUTPUT_EDP:
5609 if (!intel_encoder_is_pch_edp(&encoder->base))
5617 WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
5618 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
5620 ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
5621 &has_reduced_clock, &reduced_clock);
5623 DRM_ERROR("Couldn't find PLL settings for mode!\n");
5627 /* Ensure that the cursor is valid for the new mode before changing... */
5628 intel_crtc_update_cursor(crtc, true);
5630 /* determine panel color depth */
5631 dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
5633 if (is_lvds && dev_priv->lvds_dither)
5636 fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
5637 if (has_reduced_clock)
5638 fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
5641 dpll = ironlake_compute_dpll(intel_crtc, adjusted_mode, &clock, fp);
5643 DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
5644 drm_mode_debug_printmodeline(mode);
5646 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
5648 struct intel_pch_pll *pll;
5650 pll = intel_get_pch_pll(intel_crtc, dpll, fp);
5652 DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
5657 intel_put_pch_pll(intel_crtc);
5659 if (is_dp && !is_cpu_edp)
5660 intel_dp_set_m_n(crtc, mode, adjusted_mode);
5662 for_each_encoder_on_crtc(dev, crtc, encoder)
5663 if (encoder->pre_pll_enable)
5664 encoder->pre_pll_enable(encoder);
5666 if (intel_crtc->pch_pll) {
5667 I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
5669 /* Wait for the clocks to stabilize. */
5670 POSTING_READ(intel_crtc->pch_pll->pll_reg);
5673 /* The pixel multiplier can only be updated once the
5674 * DPLL is enabled and the clocks are stable.
5676 * So write it again.
5678 I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
5681 intel_crtc->lowfreq_avail = false;
5682 if (intel_crtc->pch_pll) {
5683 if (is_lvds && has_reduced_clock && i915_powersave) {
5684 I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp2);
5685 intel_crtc->lowfreq_avail = true;
5687 I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp);
5691 intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
5693 /* Note, this also computes intel_crtc->fdi_lanes which is used below in
5694 * ironlake_check_fdi_lanes. */
5696 ironlake_set_m_n(crtc, mode, adjusted_mode);
5698 fdi_config_ok = ironlake_check_fdi_lanes(intel_crtc);
5700 ironlake_set_pipeconf(crtc, adjusted_mode, dither);
5702 intel_wait_for_vblank(dev, pipe);
5704 /* Set up the display plane register */
5705 I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
5706 POSTING_READ(DSPCNTR(plane));
5708 ret = intel_pipe_set_base(crtc, x, y, fb);
5710 intel_update_watermarks(dev);
5712 intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
5714 return fdi_config_ok ? ret : -EINVAL;
5717 static void haswell_modeset_global_resources(struct drm_device *dev)
5719 struct drm_i915_private *dev_priv = dev->dev_private;
5720 bool enable = false;
5721 struct intel_crtc *crtc;
5722 struct intel_encoder *encoder;
5724 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
5725 if (crtc->pipe != PIPE_A && crtc->base.enabled)
5727 /* XXX: Should check for edp transcoder here, but thanks to init
5728 * sequence that's not yet available. Just in case desktop eDP
5729 * on PORT D is possible on haswell, too. */
5732 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
5734 if (encoder->type != INTEL_OUTPUT_EDP &&
5735 encoder->connectors_active)
5739 /* Even the eDP panel fitter is outside the always-on well. */
5740 if (dev_priv->pch_pf_size)
5743 intel_set_power_well(dev, enable);
5746 static int haswell_crtc_mode_set(struct drm_crtc *crtc,
5747 struct drm_display_mode *mode,
5748 struct drm_display_mode *adjusted_mode,
5750 struct drm_framebuffer *fb)
5752 struct drm_device *dev = crtc->dev;
5753 struct drm_i915_private *dev_priv = dev->dev_private;
5754 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5755 int pipe = intel_crtc->pipe;
5756 int plane = intel_crtc->plane;
5757 int num_connectors = 0;
5758 bool is_dp = false, is_cpu_edp = false;
5759 struct intel_encoder *encoder;
5763 for_each_encoder_on_crtc(dev, crtc, encoder) {
5764 switch (encoder->type) {
5765 case INTEL_OUTPUT_DISPLAYPORT:
5768 case INTEL_OUTPUT_EDP:
5770 if (!intel_encoder_is_pch_edp(&encoder->base))
5779 intel_crtc->cpu_transcoder = TRANSCODER_EDP;
5781 intel_crtc->cpu_transcoder = pipe;
5783 /* We are not sure yet this won't happen. */
5784 WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
5785 INTEL_PCH_TYPE(dev));
5787 WARN(num_connectors != 1, "%d connectors attached to pipe %c\n",
5788 num_connectors, pipe_name(pipe));
5790 WARN_ON(I915_READ(PIPECONF(intel_crtc->cpu_transcoder)) &
5791 (PIPECONF_ENABLE | I965_PIPECONF_ACTIVE));
5793 WARN_ON(I915_READ(DSPCNTR(plane)) & DISPLAY_PLANE_ENABLE);
5795 if (!intel_ddi_pll_mode_set(crtc, adjusted_mode->clock))
5798 /* Ensure that the cursor is valid for the new mode before changing... */
5799 intel_crtc_update_cursor(crtc, true);
5801 /* determine panel color depth */
5802 dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
5805 DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
5806 drm_mode_debug_printmodeline(mode);
5808 if (is_dp && !is_cpu_edp)
5809 intel_dp_set_m_n(crtc, mode, adjusted_mode);
5811 intel_crtc->lowfreq_avail = false;
5813 intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
5815 if (!is_dp || is_cpu_edp)
5816 ironlake_set_m_n(crtc, mode, adjusted_mode);
5818 haswell_set_pipeconf(crtc, adjusted_mode, dither);
5820 intel_set_pipe_csc(crtc, adjusted_mode);
5822 /* Set up the display plane register */
5823 I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE);
5824 POSTING_READ(DSPCNTR(plane));
5826 ret = intel_pipe_set_base(crtc, x, y, fb);
5828 intel_update_watermarks(dev);
5830 intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
5835 static int intel_crtc_mode_set(struct drm_crtc *crtc,
5836 struct drm_display_mode *mode,
5837 struct drm_display_mode *adjusted_mode,
5839 struct drm_framebuffer *fb)
5841 struct drm_device *dev = crtc->dev;
5842 struct drm_i915_private *dev_priv = dev->dev_private;
5843 struct drm_encoder_helper_funcs *encoder_funcs;
5844 struct intel_encoder *encoder;
5845 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5846 int pipe = intel_crtc->pipe;
5849 drm_vblank_pre_modeset(dev, pipe);
5851 ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
5853 drm_vblank_post_modeset(dev, pipe);
5858 for_each_encoder_on_crtc(dev, crtc, encoder) {
5859 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
5860 encoder->base.base.id,
5861 drm_get_encoder_name(&encoder->base),
5862 mode->base.id, mode->name);
5863 encoder_funcs = encoder->base.helper_private;
5864 encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
5870 static bool intel_eld_uptodate(struct drm_connector *connector,
5871 int reg_eldv, uint32_t bits_eldv,
5872 int reg_elda, uint32_t bits_elda,
5875 struct drm_i915_private *dev_priv = connector->dev->dev_private;
5876 uint8_t *eld = connector->eld;
5879 i = I915_READ(reg_eldv);
5888 i = I915_READ(reg_elda);
5890 I915_WRITE(reg_elda, i);
5892 for (i = 0; i < eld[2]; i++)
5893 if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
5899 static void g4x_write_eld(struct drm_connector *connector,
5900 struct drm_crtc *crtc)
5902 struct drm_i915_private *dev_priv = connector->dev->dev_private;
5903 uint8_t *eld = connector->eld;
5908 i = I915_READ(G4X_AUD_VID_DID);
5910 if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
5911 eldv = G4X_ELDV_DEVCL_DEVBLC;
5913 eldv = G4X_ELDV_DEVCTG;
5915 if (intel_eld_uptodate(connector,
5916 G4X_AUD_CNTL_ST, eldv,
5917 G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
5918 G4X_HDMIW_HDMIEDID))
5921 i = I915_READ(G4X_AUD_CNTL_ST);
5922 i &= ~(eldv | G4X_ELD_ADDR);
5923 len = (i >> 9) & 0x1f; /* ELD buffer size */
5924 I915_WRITE(G4X_AUD_CNTL_ST, i);
5929 len = min_t(uint8_t, eld[2], len);
5930 DRM_DEBUG_DRIVER("ELD size %d\n", len);
5931 for (i = 0; i < len; i++)
5932 I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
5934 i = I915_READ(G4X_AUD_CNTL_ST);
5936 I915_WRITE(G4X_AUD_CNTL_ST, i);
5939 static void haswell_write_eld(struct drm_connector *connector,
5940 struct drm_crtc *crtc)
5942 struct drm_i915_private *dev_priv = connector->dev->dev_private;
5943 uint8_t *eld = connector->eld;
5944 struct drm_device *dev = crtc->dev;
5945 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5949 int pipe = to_intel_crtc(crtc)->pipe;
5952 int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
5953 int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
5954 int aud_config = HSW_AUD_CFG(pipe);
5955 int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
5958 DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n");
5960 /* Audio output enable */
5961 DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
5962 tmp = I915_READ(aud_cntrl_st2);
5963 tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
5964 I915_WRITE(aud_cntrl_st2, tmp);
5966 /* Wait for 1 vertical blank */
5967 intel_wait_for_vblank(dev, pipe);
5969 /* Set ELD valid state */
5970 tmp = I915_READ(aud_cntrl_st2);
5971 DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp);
5972 tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
5973 I915_WRITE(aud_cntrl_st2, tmp);
5974 tmp = I915_READ(aud_cntrl_st2);
5975 DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp);
5977 /* Enable HDMI mode */
5978 tmp = I915_READ(aud_config);
5979 DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp);
5980 /* clear N_programing_enable and N_value_index */
5981 tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
5982 I915_WRITE(aud_config, tmp);
5984 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
5986 eldv = AUDIO_ELD_VALID_A << (pipe * 4);
5987 intel_crtc->eld_vld = true;
5989 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
5990 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
5991 eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
5992 I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
5994 I915_WRITE(aud_config, 0);
5996 if (intel_eld_uptodate(connector,
5997 aud_cntrl_st2, eldv,
5998 aud_cntl_st, IBX_ELD_ADDRESS,
6002 i = I915_READ(aud_cntrl_st2);
6004 I915_WRITE(aud_cntrl_st2, i);
6009 i = I915_READ(aud_cntl_st);
6010 i &= ~IBX_ELD_ADDRESS;
6011 I915_WRITE(aud_cntl_st, i);
6012 i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
6013 DRM_DEBUG_DRIVER("port num:%d\n", i);
6015 len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
6016 DRM_DEBUG_DRIVER("ELD size %d\n", len);
6017 for (i = 0; i < len; i++)
6018 I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
6020 i = I915_READ(aud_cntrl_st2);
6022 I915_WRITE(aud_cntrl_st2, i);
6026 static void ironlake_write_eld(struct drm_connector *connector,
6027 struct drm_crtc *crtc)
6029 struct drm_i915_private *dev_priv = connector->dev->dev_private;
6030 uint8_t *eld = connector->eld;
6038 int pipe = to_intel_crtc(crtc)->pipe;
6040 if (HAS_PCH_IBX(connector->dev)) {
6041 hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
6042 aud_config = IBX_AUD_CFG(pipe);
6043 aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
6044 aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
6046 hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
6047 aud_config = CPT_AUD_CFG(pipe);
6048 aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
6049 aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
6052 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
6054 i = I915_READ(aud_cntl_st);
6055 i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
6057 DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
6058 /* operate blindly on all ports */
6059 eldv = IBX_ELD_VALIDB;
6060 eldv |= IBX_ELD_VALIDB << 4;
6061 eldv |= IBX_ELD_VALIDB << 8;
6063 DRM_DEBUG_DRIVER("ELD on port %c\n", 'A' + i);
6064 eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
6067 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
6068 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
6069 eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
6070 I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
6072 I915_WRITE(aud_config, 0);
6074 if (intel_eld_uptodate(connector,
6075 aud_cntrl_st2, eldv,
6076 aud_cntl_st, IBX_ELD_ADDRESS,
6080 i = I915_READ(aud_cntrl_st2);
6082 I915_WRITE(aud_cntrl_st2, i);
6087 i = I915_READ(aud_cntl_st);
6088 i &= ~IBX_ELD_ADDRESS;
6089 I915_WRITE(aud_cntl_st, i);
6091 len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
6092 DRM_DEBUG_DRIVER("ELD size %d\n", len);
6093 for (i = 0; i < len; i++)
6094 I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
6096 i = I915_READ(aud_cntrl_st2);
6098 I915_WRITE(aud_cntrl_st2, i);
6101 void intel_write_eld(struct drm_encoder *encoder,
6102 struct drm_display_mode *mode)
6104 struct drm_crtc *crtc = encoder->crtc;
6105 struct drm_connector *connector;
6106 struct drm_device *dev = encoder->dev;
6107 struct drm_i915_private *dev_priv = dev->dev_private;
6109 connector = drm_select_eld(encoder, mode);
6113 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6115 drm_get_connector_name(connector),
6116 connector->encoder->base.id,
6117 drm_get_encoder_name(connector->encoder));
6119 connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
6121 if (dev_priv->display.write_eld)
6122 dev_priv->display.write_eld(connector, crtc);
6125 /** Loads the palette/gamma unit for the CRTC with the prepared values */
6126 void intel_crtc_load_lut(struct drm_crtc *crtc)
6128 struct drm_device *dev = crtc->dev;
6129 struct drm_i915_private *dev_priv = dev->dev_private;
6130 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6131 int palreg = PALETTE(intel_crtc->pipe);
6134 /* The clocks have to be on to load the palette. */
6135 if (!crtc->enabled || !intel_crtc->active)
6138 /* use legacy palette for Ironlake */
6139 if (HAS_PCH_SPLIT(dev))
6140 palreg = LGC_PALETTE(intel_crtc->pipe);
6142 for (i = 0; i < 256; i++) {
6143 I915_WRITE(palreg + 4 * i,
6144 (intel_crtc->lut_r[i] << 16) |
6145 (intel_crtc->lut_g[i] << 8) |
6146 intel_crtc->lut_b[i]);
6150 static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
6152 struct drm_device *dev = crtc->dev;
6153 struct drm_i915_private *dev_priv = dev->dev_private;
6154 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6155 bool visible = base != 0;
6158 if (intel_crtc->cursor_visible == visible)
6161 cntl = I915_READ(_CURACNTR);
6163 /* On these chipsets we can only modify the base whilst
6164 * the cursor is disabled.
6166 I915_WRITE(_CURABASE, base);
6168 cntl &= ~(CURSOR_FORMAT_MASK);
6169 /* XXX width must be 64, stride 256 => 0x00 << 28 */
6170 cntl |= CURSOR_ENABLE |
6171 CURSOR_GAMMA_ENABLE |
6174 cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
6175 I915_WRITE(_CURACNTR, cntl);
6177 intel_crtc->cursor_visible = visible;
6180 static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
6182 struct drm_device *dev = crtc->dev;
6183 struct drm_i915_private *dev_priv = dev->dev_private;
6184 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6185 int pipe = intel_crtc->pipe;
6186 bool visible = base != 0;
6188 if (intel_crtc->cursor_visible != visible) {
6189 uint32_t cntl = I915_READ(CURCNTR(pipe));
6191 cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
6192 cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
6193 cntl |= pipe << 28; /* Connect to correct pipe */
6195 cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
6196 cntl |= CURSOR_MODE_DISABLE;
6198 I915_WRITE(CURCNTR(pipe), cntl);
6200 intel_crtc->cursor_visible = visible;
6202 /* and commit changes on next vblank */
6203 I915_WRITE(CURBASE(pipe), base);
6206 static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
6208 struct drm_device *dev = crtc->dev;
6209 struct drm_i915_private *dev_priv = dev->dev_private;
6210 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6211 int pipe = intel_crtc->pipe;
6212 bool visible = base != 0;
6214 if (intel_crtc->cursor_visible != visible) {
6215 uint32_t cntl = I915_READ(CURCNTR_IVB(pipe));
6217 cntl &= ~CURSOR_MODE;
6218 cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
6220 cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
6221 cntl |= CURSOR_MODE_DISABLE;
6223 if (IS_HASWELL(dev))
6224 cntl |= CURSOR_PIPE_CSC_ENABLE;
6225 I915_WRITE(CURCNTR_IVB(pipe), cntl);
6227 intel_crtc->cursor_visible = visible;
6229 /* and commit changes on next vblank */
6230 I915_WRITE(CURBASE_IVB(pipe), base);
6233 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
6234 static void intel_crtc_update_cursor(struct drm_crtc *crtc,
6237 struct drm_device *dev = crtc->dev;
6238 struct drm_i915_private *dev_priv = dev->dev_private;
6239 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6240 int pipe = intel_crtc->pipe;
6241 int x = intel_crtc->cursor_x;
6242 int y = intel_crtc->cursor_y;
6248 if (on && crtc->enabled && crtc->fb) {
6249 base = intel_crtc->cursor_addr;
6250 if (x > (int) crtc->fb->width)
6253 if (y > (int) crtc->fb->height)
6259 if (x + intel_crtc->cursor_width < 0)
6262 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
6265 pos |= x << CURSOR_X_SHIFT;
6268 if (y + intel_crtc->cursor_height < 0)
6271 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
6274 pos |= y << CURSOR_Y_SHIFT;
6276 visible = base != 0;
6277 if (!visible && !intel_crtc->cursor_visible)
6280 if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
6281 I915_WRITE(CURPOS_IVB(pipe), pos);
6282 ivb_update_cursor(crtc, base);
6284 I915_WRITE(CURPOS(pipe), pos);
6285 if (IS_845G(dev) || IS_I865G(dev))
6286 i845_update_cursor(crtc, base);
6288 i9xx_update_cursor(crtc, base);
6292 static int intel_crtc_cursor_set(struct drm_crtc *crtc,
6293 struct drm_file *file,
6295 uint32_t width, uint32_t height)
6297 struct drm_device *dev = crtc->dev;
6298 struct drm_i915_private *dev_priv = dev->dev_private;
6299 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6300 struct drm_i915_gem_object *obj;
6304 /* if we want to turn off the cursor ignore width and height */
6306 DRM_DEBUG_KMS("cursor off\n");
6309 mutex_lock(&dev->struct_mutex);
6313 /* Currently we only support 64x64 cursors */
6314 if (width != 64 || height != 64) {
6315 DRM_ERROR("we currently only support 64x64 cursors\n");
6319 obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
6320 if (&obj->base == NULL)
6323 if (obj->base.size < width * height * 4) {
6324 DRM_ERROR("buffer is to small\n");
6329 /* we only need to pin inside GTT if cursor is non-phy */
6330 mutex_lock(&dev->struct_mutex);
6331 if (!dev_priv->info->cursor_needs_physical) {
6332 if (obj->tiling_mode) {
6333 DRM_ERROR("cursor cannot be tiled\n");
6338 ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL);
6340 DRM_ERROR("failed to move cursor bo into the GTT\n");
6344 ret = i915_gem_object_put_fence(obj);
6346 DRM_ERROR("failed to release fence for cursor");
6350 addr = obj->gtt_offset;
6352 int align = IS_I830(dev) ? 16 * 1024 : 256;
6353 ret = i915_gem_attach_phys_object(dev, obj,
6354 (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
6357 DRM_ERROR("failed to attach phys object\n");
6360 addr = obj->phys_obj->handle->busaddr;
6364 I915_WRITE(CURSIZE, (height << 12) | width);
6367 if (intel_crtc->cursor_bo) {
6368 if (dev_priv->info->cursor_needs_physical) {
6369 if (intel_crtc->cursor_bo != obj)
6370 i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
6372 i915_gem_object_unpin(intel_crtc->cursor_bo);
6373 drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
6376 mutex_unlock(&dev->struct_mutex);
6378 intel_crtc->cursor_addr = addr;
6379 intel_crtc->cursor_bo = obj;
6380 intel_crtc->cursor_width = width;
6381 intel_crtc->cursor_height = height;
6383 intel_crtc_update_cursor(crtc, true);
6387 i915_gem_object_unpin(obj);
6389 mutex_unlock(&dev->struct_mutex);
6391 drm_gem_object_unreference_unlocked(&obj->base);
6395 static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
6397 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6399 intel_crtc->cursor_x = x;
6400 intel_crtc->cursor_y = y;
6402 intel_crtc_update_cursor(crtc, true);
6407 /** Sets the color ramps on behalf of RandR */
6408 void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
6409 u16 blue, int regno)
6411 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6413 intel_crtc->lut_r[regno] = red >> 8;
6414 intel_crtc->lut_g[regno] = green >> 8;
6415 intel_crtc->lut_b[regno] = blue >> 8;
6418 void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
6419 u16 *blue, int regno)
6421 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6423 *red = intel_crtc->lut_r[regno] << 8;
6424 *green = intel_crtc->lut_g[regno] << 8;
6425 *blue = intel_crtc->lut_b[regno] << 8;
6428 static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
6429 u16 *blue, uint32_t start, uint32_t size)
6431 int end = (start + size > 256) ? 256 : start + size, i;
6432 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6434 for (i = start; i < end; i++) {
6435 intel_crtc->lut_r[i] = red[i] >> 8;
6436 intel_crtc->lut_g[i] = green[i] >> 8;
6437 intel_crtc->lut_b[i] = blue[i] >> 8;
6440 intel_crtc_load_lut(crtc);
6444 * Get a pipe with a simple mode set on it for doing load-based monitor
6447 * It will be up to the load-detect code to adjust the pipe as appropriate for
6448 * its requirements. The pipe will be connected to no other encoders.
6450 * Currently this code will only succeed if there is a pipe with no encoders
6451 * configured for it. In the future, it could choose to temporarily disable
6452 * some outputs to free up a pipe for its use.
6454 * \return crtc, or NULL if no pipes are available.
6457 /* VESA 640x480x72Hz mode to set on the pipe */
6458 static struct drm_display_mode load_detect_mode = {
6459 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
6460 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
6463 static struct drm_framebuffer *
6464 intel_framebuffer_create(struct drm_device *dev,
6465 struct drm_mode_fb_cmd2 *mode_cmd,
6466 struct drm_i915_gem_object *obj)
6468 struct intel_framebuffer *intel_fb;
6471 intel_fb = kmalloc(sizeof(*intel_fb), M_DRM, M_WAITOK | M_ZERO);
6473 drm_gem_object_unreference_unlocked(&obj->base);
6474 return ERR_PTR(-ENOMEM);
6477 ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
6479 drm_gem_object_unreference_unlocked(&obj->base);
6480 kfree(intel_fb, M_DRM);
6481 return ERR_PTR(ret);
6484 return &intel_fb->base;
6488 intel_framebuffer_pitch_for_width(int width, int bpp)
6490 u32 pitch = DIV_ROUND_UP(width * bpp, 8);
6491 return ALIGN(pitch, 64);
6495 intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
6497 u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
6498 return ALIGN(pitch * mode->vdisplay, PAGE_SIZE);
6501 static struct drm_framebuffer *
6502 intel_framebuffer_create_for_mode(struct drm_device *dev,
6503 struct drm_display_mode *mode,
6506 struct drm_i915_gem_object *obj;
6507 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
6509 obj = i915_gem_alloc_object(dev,
6510 intel_framebuffer_size_for_mode(mode, bpp));
6512 return ERR_PTR(-ENOMEM);
6514 mode_cmd.width = mode->hdisplay;
6515 mode_cmd.height = mode->vdisplay;
6516 mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
6518 mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
6520 return intel_framebuffer_create(dev, &mode_cmd, obj);
6523 static struct drm_framebuffer *
6524 mode_fits_in_fbdev(struct drm_device *dev,
6525 struct drm_display_mode *mode)
6527 struct drm_i915_private *dev_priv = dev->dev_private;
6528 struct drm_i915_gem_object *obj;
6529 struct drm_framebuffer *fb;
6531 if (dev_priv->fbdev == NULL)
6534 obj = dev_priv->fbdev->ifb.obj;
6538 fb = &dev_priv->fbdev->ifb.base;
6539 if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
6540 fb->bits_per_pixel))
6543 if (obj->base.size < mode->vdisplay * fb->pitches[0])
6549 bool intel_get_load_detect_pipe(struct drm_connector *connector,
6550 struct drm_display_mode *mode,
6551 struct intel_load_detect_pipe *old)
6553 struct intel_crtc *intel_crtc;
6554 struct intel_encoder *intel_encoder =
6555 intel_attached_encoder(connector);
6556 struct drm_crtc *possible_crtc;
6557 struct drm_encoder *encoder = &intel_encoder->base;
6558 struct drm_crtc *crtc = NULL;
6559 struct drm_device *dev = encoder->dev;
6560 struct drm_framebuffer *fb;
6563 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6564 connector->base.id, drm_get_connector_name(connector),
6565 encoder->base.id, drm_get_encoder_name(encoder));
6568 * Algorithm gets a little messy:
6570 * - if the connector already has an assigned crtc, use it (but make
6571 * sure it's on first)
6573 * - try to find the first unused crtc that can drive this connector,
6574 * and use that if we find one
6577 /* See if we already have a CRTC for this connector */
6578 if (encoder->crtc) {
6579 crtc = encoder->crtc;
6581 mutex_lock(&crtc->mutex);
6583 old->dpms_mode = connector->dpms;
6584 old->load_detect_temp = false;
6586 /* Make sure the crtc and connector are running */
6587 if (connector->dpms != DRM_MODE_DPMS_ON)
6588 connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
6593 /* Find an unused one (if possible) */
6594 list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
6596 if (!(encoder->possible_crtcs & (1 << i)))
6598 if (!possible_crtc->enabled) {
6599 crtc = possible_crtc;
6605 * If we didn't find an unused CRTC, don't use any.
6608 DRM_DEBUG_KMS("no pipe available for load-detect\n");
6612 mutex_lock(&crtc->mutex);
6613 intel_encoder->new_crtc = to_intel_crtc(crtc);
6614 to_intel_connector(connector)->new_encoder = intel_encoder;
6616 intel_crtc = to_intel_crtc(crtc);
6617 old->dpms_mode = connector->dpms;
6618 old->load_detect_temp = true;
6619 old->release_fb = NULL;
6622 mode = &load_detect_mode;
6624 /* We need a framebuffer large enough to accommodate all accesses
6625 * that the plane may generate whilst we perform load detection.
6626 * We can not rely on the fbcon either being present (we get called
6627 * during its initialisation to detect all boot displays, or it may
6628 * not even exist) or that it is large enough to satisfy the
6631 fb = mode_fits_in_fbdev(dev, mode);
6633 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
6634 fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
6635 old->release_fb = fb;
6637 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
6639 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
6640 mutex_unlock(&crtc->mutex);
6644 if (intel_set_mode(crtc, mode, 0, 0, fb)) {
6645 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
6646 if (old->release_fb)
6647 old->release_fb->funcs->destroy(old->release_fb);
6648 mutex_unlock(&crtc->mutex);
6652 /* let the connector get through one full cycle before testing */
6653 intel_wait_for_vblank(dev, intel_crtc->pipe);
6657 void intel_release_load_detect_pipe(struct drm_connector *connector,
6658 struct intel_load_detect_pipe *old)
6660 struct intel_encoder *intel_encoder =
6661 intel_attached_encoder(connector);
6662 struct drm_encoder *encoder = &intel_encoder->base;
6663 struct drm_crtc *crtc = encoder->crtc;
6665 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6666 connector->base.id, drm_get_connector_name(connector),
6667 encoder->base.id, drm_get_encoder_name(encoder));
6669 if (old->load_detect_temp) {
6670 to_intel_connector(connector)->new_encoder = NULL;
6671 intel_encoder->new_crtc = NULL;
6672 intel_set_mode(crtc, NULL, 0, 0, NULL);
6674 if (old->release_fb) {
6675 drm_framebuffer_unregister_private(old->release_fb);
6676 drm_framebuffer_unreference(old->release_fb);
6679 mutex_unlock(&crtc->mutex);
6683 /* Switch crtc and encoder back off if necessary */
6684 if (old->dpms_mode != DRM_MODE_DPMS_ON)
6685 connector->funcs->dpms(connector, old->dpms_mode);
6687 mutex_unlock(&crtc->mutex);
6690 /* Returns the clock of the currently programmed mode of the given pipe. */
6691 static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
6693 struct drm_i915_private *dev_priv = dev->dev_private;
6694 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6695 int pipe = intel_crtc->pipe;
6696 u32 dpll = I915_READ(DPLL(pipe));
6698 intel_clock_t clock;
6700 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
6701 fp = I915_READ(FP0(pipe));
6703 fp = I915_READ(FP1(pipe));
6705 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
6706 if (IS_PINEVIEW(dev)) {
6707 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
6708 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
6710 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
6711 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
6714 if (!IS_GEN2(dev)) {
6715 if (IS_PINEVIEW(dev))
6716 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
6717 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
6719 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
6720 DPLL_FPA01_P1_POST_DIV_SHIFT);
6722 switch (dpll & DPLL_MODE_MASK) {
6723 case DPLLB_MODE_DAC_SERIAL:
6724 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
6727 case DPLLB_MODE_LVDS:
6728 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
6732 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
6733 "mode\n", (int)(dpll & DPLL_MODE_MASK));
6737 /* XXX: Handle the 100Mhz refclk */
6738 intel_clock(dev, 96000, &clock);
6740 bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
6743 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
6744 DPLL_FPA01_P1_POST_DIV_SHIFT);
6747 if ((dpll & PLL_REF_INPUT_MASK) ==
6748 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
6749 /* XXX: might not be 66MHz */
6750 intel_clock(dev, 66000, &clock);
6752 intel_clock(dev, 48000, &clock);
6754 if (dpll & PLL_P1_DIVIDE_BY_TWO)
6757 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
6758 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
6760 if (dpll & PLL_P2_DIVIDE_BY_4)
6765 intel_clock(dev, 48000, &clock);
6769 /* XXX: It would be nice to validate the clocks, but we can't reuse
6770 * i830PllIsValid() because it relies on the xf86_config connector
6771 * configuration being accurate, which it isn't necessarily.
6777 /** Returns the currently programmed mode of the given pipe. */
6778 struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
6779 struct drm_crtc *crtc)
6781 struct drm_i915_private *dev_priv = dev->dev_private;
6782 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6783 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
6784 struct drm_display_mode *mode;
6785 int htot = I915_READ(HTOTAL(cpu_transcoder));
6786 int hsync = I915_READ(HSYNC(cpu_transcoder));
6787 int vtot = I915_READ(VTOTAL(cpu_transcoder));
6788 int vsync = I915_READ(VSYNC(cpu_transcoder));
6790 mode = kmalloc(sizeof(*mode), M_DRM, M_WAITOK | M_ZERO);
6794 mode->clock = intel_crtc_clock_get(dev, crtc);
6795 mode->hdisplay = (htot & 0xffff) + 1;
6796 mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
6797 mode->hsync_start = (hsync & 0xffff) + 1;
6798 mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
6799 mode->vdisplay = (vtot & 0xffff) + 1;
6800 mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
6801 mode->vsync_start = (vsync & 0xffff) + 1;
6802 mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
6804 drm_mode_set_name(mode);
6809 static void intel_increase_pllclock(struct drm_crtc *crtc)
6811 struct drm_device *dev = crtc->dev;
6812 drm_i915_private_t *dev_priv = dev->dev_private;
6813 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6814 int pipe = intel_crtc->pipe;
6815 int dpll_reg = DPLL(pipe);
6818 if (HAS_PCH_SPLIT(dev))
6821 if (!dev_priv->lvds_downclock_avail)
6824 dpll = I915_READ(dpll_reg);
6825 if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
6826 DRM_DEBUG_DRIVER("upclocking LVDS\n");
6828 assert_panel_unlocked(dev_priv, pipe);
6830 dpll &= ~DISPLAY_RATE_SELECT_FPA1;
6831 I915_WRITE(dpll_reg, dpll);
6832 intel_wait_for_vblank(dev, pipe);
6834 dpll = I915_READ(dpll_reg);
6835 if (dpll & DISPLAY_RATE_SELECT_FPA1)
6836 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
6840 static void intel_decrease_pllclock(struct drm_crtc *crtc)
6842 struct drm_device *dev = crtc->dev;
6843 drm_i915_private_t *dev_priv = dev->dev_private;
6844 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6846 if (HAS_PCH_SPLIT(dev))
6849 if (!dev_priv->lvds_downclock_avail)
6853 * Since this is called by a timer, we should never get here in
6856 if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
6857 int pipe = intel_crtc->pipe;
6858 int dpll_reg = DPLL(pipe);
6861 DRM_DEBUG_DRIVER("downclocking LVDS\n");
6863 assert_panel_unlocked(dev_priv, pipe);
6865 dpll = I915_READ(dpll_reg);
6866 dpll |= DISPLAY_RATE_SELECT_FPA1;
6867 I915_WRITE(dpll_reg, dpll);
6868 intel_wait_for_vblank(dev, pipe);
6869 dpll = I915_READ(dpll_reg);
6870 if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
6871 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
6875 void intel_mark_busy(struct drm_device *dev)
6877 i915_update_gfx_val(dev->dev_private);
6880 void intel_mark_idle(struct drm_device *dev)
6882 struct drm_crtc *crtc;
6884 if (!i915_powersave)
6887 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
6891 intel_decrease_pllclock(crtc);
6895 void intel_mark_fb_busy(struct drm_i915_gem_object *obj)
6897 struct drm_device *dev = obj->base.dev;
6898 struct drm_crtc *crtc;
6900 if (!i915_powersave)
6903 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
6907 if (to_intel_framebuffer(crtc->fb)->obj == obj)
6908 intel_increase_pllclock(crtc);
6912 static void intel_crtc_destroy(struct drm_crtc *crtc)
6914 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6915 struct drm_device *dev = crtc->dev;
6916 struct intel_unpin_work *work;
6918 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
6919 work = intel_crtc->unpin_work;
6920 intel_crtc->unpin_work = NULL;
6921 lockmgr(&dev->event_lock, LK_RELEASE);
6924 cancel_work_sync(&work->work);
6928 drm_crtc_cleanup(crtc);
6930 drm_free(intel_crtc, M_DRM);
6933 static void intel_unpin_work_fn(struct work_struct *__work)
6935 struct intel_unpin_work *work =
6936 container_of(__work, struct intel_unpin_work, work);
6937 struct drm_device *dev = work->crtc->dev;
6939 mutex_lock(&dev->struct_mutex);
6940 intel_unpin_fb_obj(work->old_fb_obj);
6941 drm_gem_object_unreference(&work->pending_flip_obj->base);
6942 drm_gem_object_unreference(&work->old_fb_obj->base);
6944 intel_update_fbc(dev);
6945 mutex_unlock(&dev->struct_mutex);
6947 BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
6948 atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
6950 drm_free(work, M_DRM);
6953 static void do_intel_finish_page_flip(struct drm_device *dev,
6954 struct drm_crtc *crtc)
6956 drm_i915_private_t *dev_priv = dev->dev_private;
6957 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6958 struct intel_unpin_work *work;
6959 struct drm_i915_gem_object *obj;
6961 /* Ignore early vblank irqs */
6962 if (intel_crtc == NULL)
6965 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
6966 work = intel_crtc->unpin_work;
6968 /* Ensure we don't miss a work->pending update ... */
6971 if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
6972 lockmgr(&dev->event_lock, LK_RELEASE);
6976 /* and that the unpin work is consistent wrt ->pending. */
6979 intel_crtc->unpin_work = NULL;
6982 drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
6984 drm_vblank_put(dev, intel_crtc->pipe);
6986 lockmgr(&dev->event_lock, LK_RELEASE);
6988 obj = work->old_fb_obj;
6990 wake_up_all(&dev_priv->pending_flip_queue);
6992 queue_work(dev_priv->wq, &work->work);
6995 void intel_finish_page_flip(struct drm_device *dev, int pipe)
6997 drm_i915_private_t *dev_priv = dev->dev_private;
6998 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
7000 do_intel_finish_page_flip(dev, crtc);
7003 void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
7005 drm_i915_private_t *dev_priv = dev->dev_private;
7006 struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
7008 do_intel_finish_page_flip(dev, crtc);
7011 void intel_prepare_page_flip(struct drm_device *dev, int plane)
7013 drm_i915_private_t *dev_priv = dev->dev_private;
7014 struct intel_crtc *intel_crtc =
7015 to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
7017 /* NB: An MMIO update of the plane base pointer will also
7018 * generate a page-flip completion irq, i.e. every modeset
7019 * is also accompanied by a spurious intel_prepare_page_flip().
7021 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
7022 if (intel_crtc->unpin_work)
7023 atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
7024 lockmgr(&dev->event_lock, LK_RELEASE);
7027 inline static void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
7029 /* Ensure that the work item is consistent when activating it ... */
7031 atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
7032 /* and that it is marked active as soon as the irq could fire. */
7036 static int intel_gen2_queue_flip(struct drm_device *dev,
7037 struct drm_crtc *crtc,
7038 struct drm_framebuffer *fb,
7039 struct drm_i915_gem_object *obj)
7041 struct drm_i915_private *dev_priv = dev->dev_private;
7042 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7044 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7047 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7051 ret = intel_ring_begin(ring, 6);
7055 /* Can't queue multiple flips, so wait for the previous
7056 * one to finish before executing the next.
7058 if (intel_crtc->plane)
7059 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
7061 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
7062 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
7063 intel_ring_emit(ring, MI_NOOP);
7064 intel_ring_emit(ring, MI_DISPLAY_FLIP |
7065 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7066 intel_ring_emit(ring, fb->pitches[0]);
7067 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7068 intel_ring_emit(ring, 0); /* aux display base address, unused */
7070 intel_mark_page_flip_active(intel_crtc);
7071 intel_ring_advance(ring);
7075 intel_unpin_fb_obj(obj);
7080 static int intel_gen3_queue_flip(struct drm_device *dev,
7081 struct drm_crtc *crtc,
7082 struct drm_framebuffer *fb,
7083 struct drm_i915_gem_object *obj)
7085 struct drm_i915_private *dev_priv = dev->dev_private;
7086 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7088 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7091 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7095 ret = intel_ring_begin(ring, 6);
7099 if (intel_crtc->plane)
7100 flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
7102 flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
7103 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
7104 intel_ring_emit(ring, MI_NOOP);
7105 intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
7106 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7107 intel_ring_emit(ring, fb->pitches[0]);
7108 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7109 intel_ring_emit(ring, MI_NOOP);
7111 intel_mark_page_flip_active(intel_crtc);
7112 intel_ring_advance(ring);
7116 intel_unpin_fb_obj(obj);
7121 static int intel_gen4_queue_flip(struct drm_device *dev,
7122 struct drm_crtc *crtc,
7123 struct drm_framebuffer *fb,
7124 struct drm_i915_gem_object *obj)
7126 struct drm_i915_private *dev_priv = dev->dev_private;
7127 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7128 uint32_t pf, pipesrc;
7129 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7132 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7136 ret = intel_ring_begin(ring, 4);
7140 /* i965+ uses the linear or tiled offsets from the
7141 * Display Registers (which do not change across a page-flip)
7142 * so we need only reprogram the base address.
7144 intel_ring_emit(ring, MI_DISPLAY_FLIP |
7145 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7146 intel_ring_emit(ring, fb->pitches[0]);
7147 intel_ring_emit(ring,
7148 (obj->gtt_offset + intel_crtc->dspaddr_offset) |
7151 /* XXX Enabling the panel-fitter across page-flip is so far
7152 * untested on non-native modes, so ignore it for now.
7153 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
7156 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
7157 intel_ring_emit(ring, pf | pipesrc);
7159 intel_mark_page_flip_active(intel_crtc);
7160 intel_ring_advance(ring);
7164 intel_unpin_fb_obj(obj);
7169 static int intel_gen6_queue_flip(struct drm_device *dev,
7170 struct drm_crtc *crtc,
7171 struct drm_framebuffer *fb,
7172 struct drm_i915_gem_object *obj)
7174 struct drm_i915_private *dev_priv = dev->dev_private;
7175 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7176 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
7177 uint32_t pf, pipesrc;
7180 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7184 ret = intel_ring_begin(ring, 4);
7188 intel_ring_emit(ring, MI_DISPLAY_FLIP |
7189 MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7190 intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
7191 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7193 /* Contrary to the suggestions in the documentation,
7194 * "Enable Panel Fitter" does not seem to be required when page
7195 * flipping with a non-native mode, and worse causes a normal
7197 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
7200 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
7201 intel_ring_emit(ring, pf | pipesrc);
7203 intel_mark_page_flip_active(intel_crtc);
7204 intel_ring_advance(ring);
7208 intel_unpin_fb_obj(obj);
7214 * On gen7 we currently use the blit ring because (in early silicon at least)
7215 * the render ring doesn't give us interrpts for page flip completion, which
7216 * means clients will hang after the first flip is queued. Fortunately the
7217 * blit ring generates interrupts properly, so use it instead.
7219 static int intel_gen7_queue_flip(struct drm_device *dev,
7220 struct drm_crtc *crtc,
7221 struct drm_framebuffer *fb,
7222 struct drm_i915_gem_object *obj)
7224 struct drm_i915_private *dev_priv = dev->dev_private;
7225 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7226 struct intel_ring_buffer *ring = &dev_priv->ring[BCS];
7227 uint32_t plane_bit = 0;
7230 ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
7234 switch(intel_crtc->plane) {
7236 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
7239 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
7242 plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
7245 WARN_ONCE(1, "unknown plane in flip command\n");
7250 ret = intel_ring_begin(ring, 4);
7254 intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
7255 intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
7256 intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7257 intel_ring_emit(ring, (MI_NOOP));
7259 intel_mark_page_flip_active(intel_crtc);
7260 intel_ring_advance(ring);
7264 intel_unpin_fb_obj(obj);
7269 static int intel_default_queue_flip(struct drm_device *dev,
7270 struct drm_crtc *crtc,
7271 struct drm_framebuffer *fb,
7272 struct drm_i915_gem_object *obj)
7277 static int intel_crtc_page_flip(struct drm_crtc *crtc,
7278 struct drm_framebuffer *fb,
7279 struct drm_pending_vblank_event *event)
7281 struct drm_device *dev = crtc->dev;
7282 struct drm_i915_private *dev_priv = dev->dev_private;
7283 struct drm_framebuffer *old_fb = crtc->fb;
7284 struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
7285 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
7286 struct intel_unpin_work *work;
7289 /* Can't change pixel format via MI display flips. */
7290 if (fb->pixel_format != crtc->fb->pixel_format)
7294 * TILEOFF/LINOFF registers can't be changed via MI display flips.
7295 * Note that pitch changes could also affect these register.
7297 if (INTEL_INFO(dev)->gen > 3 &&
7298 (fb->offsets[0] != crtc->fb->offsets[0] ||
7299 fb->pitches[0] != crtc->fb->pitches[0]))
7302 work = kmalloc(sizeof *work, M_DRM, M_WAITOK | M_ZERO);
7306 work->event = event;
7308 work->old_fb_obj = to_intel_framebuffer(old_fb)->obj;
7309 INIT_WORK(&work->work, intel_unpin_work_fn);
7311 ret = drm_vblank_get(dev, intel_crtc->pipe);
7315 /* We borrow the event spin lock for protecting unpin_work */
7316 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
7317 if (intel_crtc->unpin_work) {
7318 lockmgr(&dev->event_lock, LK_RELEASE);
7319 drm_free(work, M_DRM);
7320 drm_vblank_put(dev, intel_crtc->pipe);
7322 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
7325 intel_crtc->unpin_work = work;
7326 lockmgr(&dev->event_lock, LK_RELEASE);
7328 if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
7329 flush_workqueue(dev_priv->wq);
7331 ret = i915_mutex_lock_interruptible(dev);
7335 /* Reference the objects for the scheduled work. */
7336 drm_gem_object_reference(&work->old_fb_obj->base);
7337 drm_gem_object_reference(&obj->base);
7341 work->pending_flip_obj = obj;
7343 work->enable_stall_check = true;
7345 atomic_inc(&intel_crtc->unpin_work_count);
7346 intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
7348 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
7350 goto cleanup_pending;
7352 intel_disable_fbc(dev);
7353 intel_mark_fb_busy(obj);
7354 mutex_unlock(&dev->struct_mutex);
7359 atomic_dec(&intel_crtc->unpin_work_count);
7361 drm_gem_object_unreference(&work->old_fb_obj->base);
7362 drm_gem_object_unreference(&obj->base);
7363 mutex_unlock(&dev->struct_mutex);
7366 lockmgr(&dev->event_lock, LK_EXCLUSIVE);
7367 intel_crtc->unpin_work = NULL;
7368 lockmgr(&dev->event_lock, LK_RELEASE);
7370 drm_vblank_put(dev, intel_crtc->pipe);
7372 drm_free(work, M_DRM);
7377 static struct drm_crtc_helper_funcs intel_helper_funcs = {
7378 .mode_set_base_atomic = intel_pipe_set_base_atomic,
7379 .load_lut = intel_crtc_load_lut,
7380 .disable = intel_crtc_noop,
7383 bool intel_encoder_check_is_cloned(struct intel_encoder *encoder)
7385 struct intel_encoder *other_encoder;
7386 struct drm_crtc *crtc = &encoder->new_crtc->base;
7391 list_for_each_entry(other_encoder,
7392 &crtc->dev->mode_config.encoder_list,
7395 if (&other_encoder->new_crtc->base != crtc ||
7396 encoder == other_encoder)
7405 static bool intel_encoder_crtc_ok(struct drm_encoder *encoder,
7406 struct drm_crtc *crtc)
7408 struct drm_device *dev;
7409 struct drm_crtc *tmp;
7412 WARN(!crtc, "checking null crtc?\n");
7413 /* profmakx: this is to prevent the kernel from panicing */
7420 list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
7426 if (encoder->possible_crtcs & crtc_mask)
7432 * intel_modeset_update_staged_output_state
7434 * Updates the staged output configuration state, e.g. after we've read out the
7437 static void intel_modeset_update_staged_output_state(struct drm_device *dev)
7439 struct intel_encoder *encoder;
7440 struct intel_connector *connector;
7442 list_for_each_entry(connector, &dev->mode_config.connector_list,
7444 connector->new_encoder =
7445 to_intel_encoder(connector->base.encoder);
7448 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7451 to_intel_crtc(encoder->base.crtc);
7456 * intel_modeset_commit_output_state
7458 * This function copies the stage display pipe configuration to the real one.
7460 static void intel_modeset_commit_output_state(struct drm_device *dev)
7462 struct intel_encoder *encoder;
7463 struct intel_connector *connector;
7465 list_for_each_entry(connector, &dev->mode_config.connector_list,
7467 connector->base.encoder = &connector->new_encoder->base;
7470 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7472 encoder->base.crtc = &encoder->new_crtc->base;
7476 static struct drm_display_mode *
7477 intel_modeset_adjusted_mode(struct drm_crtc *crtc,
7478 struct drm_display_mode *mode)
7480 struct drm_device *dev = crtc->dev;
7481 struct drm_display_mode *adjusted_mode;
7482 struct drm_encoder_helper_funcs *encoder_funcs;
7483 struct intel_encoder *encoder;
7485 adjusted_mode = drm_mode_duplicate(dev, mode);
7487 return ERR_PTR(-ENOMEM);
7489 /* Pass our mode to the connectors and the CRTC to give them a chance to
7490 * adjust it according to limitations or connector properties, and also
7491 * a chance to reject the mode entirely.
7493 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7496 if (&encoder->new_crtc->base != crtc)
7498 encoder_funcs = encoder->base.helper_private;
7499 if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
7501 DRM_DEBUG_KMS("Encoder fixup failed\n");
7506 if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
7507 DRM_DEBUG_KMS("CRTC fixup failed\n");
7510 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
7512 return adjusted_mode;
7514 drm_mode_destroy(dev, adjusted_mode);
7515 return ERR_PTR(-EINVAL);
7518 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
7519 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
7521 intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
7522 unsigned *prepare_pipes, unsigned *disable_pipes)
7524 struct intel_crtc *intel_crtc;
7525 struct drm_device *dev = crtc->dev;
7526 struct intel_encoder *encoder;
7527 struct intel_connector *connector;
7528 struct drm_crtc *tmp_crtc;
7530 *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
7532 /* Check which crtcs have changed outputs connected to them, these need
7533 * to be part of the prepare_pipes mask. We don't (yet) support global
7534 * modeset across multiple crtcs, so modeset_pipes will only have one
7535 * bit set at most. */
7536 list_for_each_entry(connector, &dev->mode_config.connector_list,
7538 if (connector->base.encoder == &connector->new_encoder->base)
7541 if (connector->base.encoder) {
7542 tmp_crtc = connector->base.encoder->crtc;
7544 *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
7547 if (connector->new_encoder)
7549 1 << connector->new_encoder->new_crtc->pipe;
7552 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7554 if (encoder->base.crtc == &encoder->new_crtc->base)
7557 if (encoder->base.crtc) {
7558 tmp_crtc = encoder->base.crtc;
7560 *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
7563 if (encoder->new_crtc)
7564 *prepare_pipes |= 1 << encoder->new_crtc->pipe;
7567 /* Check for any pipes that will be fully disabled ... */
7568 list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
7572 /* Don't try to disable disabled crtcs. */
7573 if (!intel_crtc->base.enabled)
7576 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7578 if (encoder->new_crtc == intel_crtc)
7583 *disable_pipes |= 1 << intel_crtc->pipe;
7587 /* set_mode is also used to update properties on life display pipes. */
7588 intel_crtc = to_intel_crtc(crtc);
7590 *prepare_pipes |= 1 << intel_crtc->pipe;
7593 * For simplicity do a full modeset on any pipe where the output routing
7594 * changed. We could be more clever, but that would require us to be
7595 * more careful with calling the relevant encoder->mode_set functions.
7598 *modeset_pipes = *prepare_pipes;
7600 /* ... and mask these out. */
7601 *modeset_pipes &= ~(*disable_pipes);
7602 *prepare_pipes &= ~(*disable_pipes);
7605 * HACK: We don't (yet) fully support global modesets. intel_set_config
7606 * obies this rule, but the modeset restore mode of
7607 * intel_modeset_setup_hw_state does not.
7609 *modeset_pipes &= 1 << intel_crtc->pipe;
7610 *prepare_pipes &= 1 << intel_crtc->pipe;
7613 static bool intel_crtc_in_use(struct drm_crtc *crtc)
7615 struct drm_encoder *encoder;
7616 struct drm_device *dev = crtc->dev;
7618 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
7619 if (encoder->crtc == crtc)
7626 intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
7628 struct intel_encoder *intel_encoder;
7629 struct intel_crtc *intel_crtc;
7630 struct drm_connector *connector;
7632 list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
7634 if (!intel_encoder->base.crtc)
7637 intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
7639 if (prepare_pipes & (1 << intel_crtc->pipe))
7640 intel_encoder->connectors_active = false;
7643 intel_modeset_commit_output_state(dev);
7645 /* Update computed state. */
7646 list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
7648 intel_crtc->base.enabled = intel_crtc_in_use(&intel_crtc->base);
7651 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
7652 if (!connector->encoder || !connector->encoder->crtc)
7655 intel_crtc = to_intel_crtc(connector->encoder->crtc);
7657 if (prepare_pipes & (1 << intel_crtc->pipe)) {
7658 struct drm_property *dpms_property =
7659 dev->mode_config.dpms_property;
7661 connector->dpms = DRM_MODE_DPMS_ON;
7662 drm_object_property_set_value(&connector->base,
7666 intel_encoder = to_intel_encoder(connector->encoder);
7667 intel_encoder->connectors_active = true;
7673 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
7674 list_for_each_entry((intel_crtc), \
7675 &(dev)->mode_config.crtc_list, \
7677 if (mask & (1 <<(intel_crtc)->pipe)) \
7680 intel_modeset_check_state(struct drm_device *dev)
7682 struct intel_crtc *crtc;
7683 struct intel_encoder *encoder;
7684 struct intel_connector *connector;
7686 list_for_each_entry(connector, &dev->mode_config.connector_list,
7688 /* This also checks the encoder/connector hw state with the
7689 * ->get_hw_state callbacks. */
7690 intel_connector_check_state(connector);
7692 WARN(&connector->new_encoder->base != connector->base.encoder,
7693 "connector's staged encoder doesn't match current encoder\n");
7696 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7698 bool enabled = false;
7699 bool active = false;
7700 enum i915_pipe pipe, tracked_pipe;
7702 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
7703 encoder->base.base.id,
7704 drm_get_encoder_name(&encoder->base));
7706 WARN(&encoder->new_crtc->base != encoder->base.crtc,
7707 "encoder's stage crtc doesn't match current crtc\n");
7708 WARN(encoder->connectors_active && !encoder->base.crtc,
7709 "encoder's active_connectors set, but no crtc\n");
7711 list_for_each_entry(connector, &dev->mode_config.connector_list,
7713 if (connector->base.encoder != &encoder->base)
7716 if (connector->base.dpms != DRM_MODE_DPMS_OFF)
7719 WARN(!!encoder->base.crtc != enabled,
7720 "encoder's enabled state mismatch "
7721 "(expected %i, found %i)\n",
7722 !!encoder->base.crtc, enabled);
7723 WARN(active && !encoder->base.crtc,
7724 "active encoder with no crtc\n");
7726 WARN(encoder->connectors_active != active,
7727 "encoder's computed active state doesn't match tracked active state "
7728 "(expected %i, found %i)\n", active, encoder->connectors_active);
7730 active = encoder->get_hw_state(encoder, &pipe);
7731 WARN(active != encoder->connectors_active,
7732 "encoder's hw state doesn't match sw tracking "
7733 "(expected %i, found %i)\n",
7734 encoder->connectors_active, active);
7736 if (!encoder->base.crtc)
7739 tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
7740 WARN(active && pipe != tracked_pipe,
7741 "active encoder's pipe doesn't match"
7742 "(expected %i, found %i)\n",
7743 tracked_pipe, pipe);
7747 list_for_each_entry(crtc, &dev->mode_config.crtc_list,
7749 bool enabled = false;
7750 bool active = false;
7752 DRM_DEBUG_KMS("[CRTC:%d]\n",
7753 crtc->base.base.id);
7755 WARN(crtc->active && !crtc->base.enabled,
7756 "active crtc, but not enabled in sw tracking\n");
7758 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
7760 if (encoder->base.crtc != &crtc->base)
7763 if (encoder->connectors_active)
7766 WARN(active != crtc->active,
7767 "crtc's computed active state doesn't match tracked active state "
7768 "(expected %i, found %i)\n", active, crtc->active);
7769 WARN(enabled != crtc->base.enabled,
7770 "crtc's computed enabled state doesn't match tracked enabled state "
7771 "(expected %i, found %i)\n", enabled, crtc->base.enabled);
7773 assert_pipe(dev->dev_private, crtc->pipe, crtc->active);
7777 static int __intel_set_mode(struct drm_crtc *crtc,
7778 struct drm_display_mode *mode,
7779 int x, int y, struct drm_framebuffer *fb)
7781 struct drm_device *dev = crtc->dev;
7782 drm_i915_private_t *dev_priv = dev->dev_private;
7783 struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode;
7784 struct intel_crtc *intel_crtc;
7785 unsigned disable_pipes, prepare_pipes, modeset_pipes;
7788 saved_mode = kmalloc(2 * sizeof(*saved_mode), M_DRM, M_WAITOK);
7791 saved_hwmode = saved_mode + 1;
7793 intel_modeset_affected_pipes(crtc, &modeset_pipes,
7794 &prepare_pipes, &disable_pipes);
7796 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
7797 modeset_pipes, prepare_pipes, disable_pipes);
7799 for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
7800 intel_crtc_disable(&intel_crtc->base);
7802 *saved_hwmode = crtc->hwmode;
7803 *saved_mode = crtc->mode;
7805 /* Hack: Because we don't (yet) support global modeset on multiple
7806 * crtcs, we don't keep track of the new mode for more than one crtc.
7807 * Hence simply check whether any bit is set in modeset_pipes in all the
7808 * pieces of code that are not yet converted to deal with mutliple crtcs
7809 * changing their mode at the same time. */
7810 adjusted_mode = NULL;
7811 if (modeset_pipes) {
7812 adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
7813 if (IS_ERR(adjusted_mode)) {
7814 ret = PTR_ERR(adjusted_mode);
7819 for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
7820 if (intel_crtc->base.enabled)
7821 dev_priv->display.crtc_disable(&intel_crtc->base);
7824 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
7825 * to set it here already despite that we pass it down the callchain.
7830 /* Only after disabling all output pipelines that will be changed can we
7831 * update the the output configuration. */
7832 intel_modeset_update_state(dev, prepare_pipes);
7834 if (dev_priv->display.modeset_global_resources)
7835 dev_priv->display.modeset_global_resources(dev);
7837 /* Set up the DPLL and any encoders state that needs to adjust or depend
7840 for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
7841 ret = intel_crtc_mode_set(&intel_crtc->base,
7842 mode, adjusted_mode,
7848 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7849 for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
7850 dev_priv->display.crtc_enable(&intel_crtc->base);
7852 if (modeset_pipes) {
7853 /* Store real post-adjustment hardware mode. */
7854 crtc->hwmode = *adjusted_mode;
7856 /* Calculate and store various constants which
7857 * are later needed by vblank and swap-completion
7858 * timestamping. They are derived from true hwmode.
7860 drm_calc_timestamping_constants(crtc);
7863 /* FIXME: add subpixel order */
7865 drm_mode_destroy(dev, adjusted_mode);
7866 if (ret && crtc->enabled) {
7867 crtc->hwmode = *saved_hwmode;
7868 crtc->mode = *saved_mode;
7872 kfree(saved_mode, M_DRM);
7876 int intel_set_mode(struct drm_crtc *crtc,
7877 struct drm_display_mode *mode,
7878 int x, int y, struct drm_framebuffer *fb)
7882 ret = __intel_set_mode(crtc, mode, x, y, fb);
7885 intel_modeset_check_state(crtc->dev);
7890 void intel_crtc_restore_mode(struct drm_crtc *crtc)
7892 intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb);
7895 #undef for_each_intel_crtc_masked
7897 static void intel_set_config_free(struct intel_set_config *config)
7902 drm_free(config->save_connector_encoders, M_DRM);
7903 drm_free(config->save_encoder_crtcs, M_DRM);
7904 drm_free(config, M_DRM);
7907 static int intel_set_config_save_state(struct drm_device *dev,
7908 struct intel_set_config *config)
7910 struct drm_encoder *encoder;
7911 struct drm_connector *connector;
7914 config->save_encoder_crtcs =
7915 kmalloc(dev->mode_config.num_encoder *
7916 sizeof(struct drm_crtc *), M_DRM, M_WAITOK | M_ZERO );
7917 if (!config->save_encoder_crtcs)
7920 config->save_connector_encoders =
7921 kmalloc(dev->mode_config.num_connector *
7922 sizeof(struct drm_encoder *), M_DRM, M_WAITOK | M_ZERO );
7923 if (!config->save_connector_encoders)
7926 /* Copy data. Note that driver private data is not affected.
7927 * Should anything bad happen only the expected state is
7928 * restored, not the drivers personal bookkeeping.
7931 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
7932 config->save_encoder_crtcs[count++] = encoder->crtc;
7936 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
7937 config->save_connector_encoders[count++] = connector->encoder;
7943 static void intel_set_config_restore_state(struct drm_device *dev,
7944 struct intel_set_config *config)
7946 struct intel_encoder *encoder;
7947 struct intel_connector *connector;
7951 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
7953 to_intel_crtc(config->save_encoder_crtcs[count++]);
7957 list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
7958 connector->new_encoder =
7959 to_intel_encoder(config->save_connector_encoders[count++]);
7964 is_crtc_connector_off(struct drm_crtc *crtc, struct drm_connector *connectors,
7969 for (i = 0; i < num_connectors; i++)
7970 if (connectors[i].encoder &&
7971 connectors[i].encoder->crtc == crtc &&
7972 connectors[i].dpms != DRM_MODE_DPMS_ON)
7979 intel_set_config_compute_mode_changes(struct drm_mode_set *set,
7980 struct intel_set_config *config)
7983 /* We should be able to check here if the fb has the same properties
7984 * and then just flip_or_move it */
7985 if (set->connectors != NULL &&
7986 is_crtc_connector_off(set->crtc, *set->connectors,
7987 set->num_connectors)) {
7988 config->mode_changed = true;
7989 } else if (set->crtc->fb != set->fb) {
7990 /* If we have no fb then treat it as a full mode set */
7991 if (set->crtc->fb == NULL) {
7992 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
7993 config->mode_changed = true;
7994 } else if (set->fb == NULL) {
7995 config->mode_changed = true;
7996 } else if (set->fb->depth != set->crtc->fb->depth) {
7997 config->mode_changed = true;
7998 } else if (set->fb->bits_per_pixel !=
7999 set->crtc->fb->bits_per_pixel) {
8000 config->mode_changed = true;
8002 config->fb_changed = true;
8006 if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
8007 config->fb_changed = true;
8009 if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
8010 DRM_DEBUG_KMS("modes are different, full mode set\n");
8011 drm_mode_debug_printmodeline(&set->crtc->mode);
8012 drm_mode_debug_printmodeline(set->mode);
8013 config->mode_changed = true;
8018 intel_modeset_stage_output_state(struct drm_device *dev,
8019 struct drm_mode_set *set,
8020 struct intel_set_config *config)
8022 struct drm_crtc *new_crtc;
8023 struct intel_connector *connector;
8024 struct intel_encoder *encoder;
8027 /* The upper layers ensure that we either disable a crtc or have a list
8028 * of connectors. For paranoia, double-check this. */
8029 WARN_ON(!set->fb && (set->num_connectors != 0));
8030 WARN_ON(set->fb && (set->num_connectors == 0));
8033 list_for_each_entry(connector, &dev->mode_config.connector_list,
8035 /* Otherwise traverse passed in connector list and get encoders
8037 for (ro = 0; ro < set->num_connectors; ro++) {
8038 if (set->connectors[ro] == &connector->base) {
8039 connector->new_encoder = connector->encoder;
8044 /* If we disable the crtc, disable all its connectors. Also, if
8045 * the connector is on the changing crtc but not on the new
8046 * connector list, disable it. */
8047 if ((!set->fb || ro == set->num_connectors) &&
8048 connector->base.encoder &&
8049 connector->base.encoder->crtc == set->crtc) {
8050 connector->new_encoder = NULL;
8052 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
8053 connector->base.base.id,
8054 drm_get_connector_name(&connector->base));
8058 if (&connector->new_encoder->base != connector->base.encoder) {
8059 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
8060 config->mode_changed = true;
8063 /* connector->new_encoder is now updated for all connectors. */
8065 /* Update crtc of enabled connectors. */
8067 list_for_each_entry(connector, &dev->mode_config.connector_list,
8069 if (!connector->new_encoder)
8072 new_crtc = connector->new_encoder->base.crtc;
8074 for (ro = 0; ro < set->num_connectors; ro++) {
8075 if (set->connectors[ro] == &connector->base)
8076 new_crtc = set->crtc;
8079 /* Make sure the new CRTC will work with the encoder */
8080 if (!intel_encoder_crtc_ok(&connector->new_encoder->base,
8084 connector->encoder->new_crtc = to_intel_crtc(new_crtc);
8086 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
8087 connector->base.base.id,
8088 drm_get_connector_name(&connector->base),
8092 /* Check for any encoders that needs to be disabled. */
8093 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
8095 list_for_each_entry(connector,
8096 &dev->mode_config.connector_list,
8098 if (connector->new_encoder == encoder) {
8099 WARN_ON(!connector->new_encoder->new_crtc);
8104 encoder->new_crtc = NULL;
8106 /* Only now check for crtc changes so we don't miss encoders
8107 * that will be disabled. */
8108 if (&encoder->new_crtc->base != encoder->base.crtc) {
8109 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
8110 config->mode_changed = true;
8113 /* Now we've also updated encoder->new_crtc for all encoders. */
8118 static int intel_crtc_set_config(struct drm_mode_set *set)
8120 struct drm_device *dev;
8121 struct drm_mode_set save_set;
8122 struct intel_set_config *config;
8127 BUG_ON(!set->crtc->helper_private);
8129 /* Enforce sane interface api - has been abused by the fb helper. */
8130 BUG_ON(!set->mode && set->fb);
8131 BUG_ON(set->fb && set->num_connectors == 0);
8134 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
8135 set->crtc->base.id, set->fb->base.id,
8136 (int)set->num_connectors, set->x, set->y);
8138 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
8141 dev = set->crtc->dev;
8144 config = kmalloc(sizeof(*config), M_DRM, M_WAITOK | M_ZERO);
8148 ret = intel_set_config_save_state(dev, config);
8152 save_set.crtc = set->crtc;
8153 save_set.mode = &set->crtc->mode;
8154 save_set.x = set->crtc->x;
8155 save_set.y = set->crtc->y;
8156 save_set.fb = set->crtc->fb;
8158 /* Compute whether we need a full modeset, only an fb base update or no
8159 * change at all. In the future we might also check whether only the
8160 * mode changed, e.g. for LVDS where we only change the panel fitter in
8162 intel_set_config_compute_mode_changes(set, config);
8164 ret = intel_modeset_stage_output_state(dev, set, config);
8168 if (config->mode_changed) {
8170 DRM_DEBUG_KMS("attempting to set mode from"
8172 drm_mode_debug_printmodeline(set->mode);
8175 ret = intel_set_mode(set->crtc, set->mode,
8176 set->x, set->y, set->fb);
8178 DRM_ERROR("failed to set mode on [CRTC:%d], err = %d\n",
8179 set->crtc->base.id, ret);
8182 } else if (config->fb_changed) {
8183 ret = intel_pipe_set_base(set->crtc,
8184 set->x, set->y, set->fb);
8187 intel_set_config_free(config);
8192 intel_set_config_restore_state(dev, config);
8194 /* Try to restore the config */
8195 if (config->mode_changed &&
8196 intel_set_mode(save_set.crtc, save_set.mode,
8197 save_set.x, save_set.y, save_set.fb))
8198 DRM_ERROR("failed to restore config after modeset failure\n");
8201 intel_set_config_free(config);
8205 static const struct drm_crtc_funcs intel_crtc_funcs = {
8206 .cursor_set = intel_crtc_cursor_set,
8207 .cursor_move = intel_crtc_cursor_move,
8208 .gamma_set = intel_crtc_gamma_set,
8209 .set_config = intel_crtc_set_config,
8210 .destroy = intel_crtc_destroy,
8211 .page_flip = intel_crtc_page_flip,
8214 static void intel_cpu_pll_init(struct drm_device *dev)
8217 intel_ddi_pll_init(dev);
8220 static void intel_pch_pll_init(struct drm_device *dev)
8222 drm_i915_private_t *dev_priv = dev->dev_private;
8225 if (dev_priv->num_pch_pll == 0) {
8226 DRM_DEBUG_KMS("No PCH PLLs on this hardware, skipping initialisation\n");
8230 for (i = 0; i < dev_priv->num_pch_pll; i++) {
8231 dev_priv->pch_plls[i].pll_reg = _PCH_DPLL(i);
8232 dev_priv->pch_plls[i].fp0_reg = _PCH_FP0(i);
8233 dev_priv->pch_plls[i].fp1_reg = _PCH_FP1(i);
8237 static void intel_crtc_init(struct drm_device *dev, int pipe)
8239 drm_i915_private_t *dev_priv = dev->dev_private;
8240 struct intel_crtc *intel_crtc;
8243 intel_crtc = kmalloc(sizeof(struct intel_crtc) +
8244 (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)),
8245 M_DRM, M_WAITOK | M_ZERO);
8246 if (intel_crtc == NULL)
8249 drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
8251 drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
8252 for (i = 0; i < 256; i++) {
8253 intel_crtc->lut_r[i] = i;
8254 intel_crtc->lut_g[i] = i;
8255 intel_crtc->lut_b[i] = i;
8258 /* Swap pipes & planes for FBC on pre-965 */
8259 intel_crtc->pipe = pipe;
8260 intel_crtc->plane = pipe;
8261 intel_crtc->cpu_transcoder = pipe;
8262 if (IS_MOBILE(dev) && IS_GEN3(dev)) {
8263 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
8264 intel_crtc->plane = !pipe;
8267 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
8268 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
8269 dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
8270 dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
8272 intel_crtc->bpp = 24; /* default for pre-Ironlake */
8274 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
8277 int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
8278 struct drm_file *file)
8280 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
8281 struct drm_mode_object *drmmode_obj;
8282 struct intel_crtc *crtc;
8284 if (!drm_core_check_feature(dev, DRIVER_MODESET))
8287 drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
8288 DRM_MODE_OBJECT_CRTC);
8291 DRM_ERROR("no such CRTC id\n");
8295 crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
8296 pipe_from_crtc_id->pipe = crtc->pipe;
8301 static int intel_encoder_clones(struct intel_encoder *encoder)
8303 struct drm_device *dev = encoder->base.dev;
8304 struct intel_encoder *source_encoder;
8308 list_for_each_entry(source_encoder,
8309 &dev->mode_config.encoder_list, base.head) {
8311 if (encoder == source_encoder)
8312 index_mask |= (1 << entry);
8314 /* Intel hw has only one MUX where enocoders could be cloned. */
8315 if (encoder->cloneable && source_encoder->cloneable)
8316 index_mask |= (1 << entry);
8324 static bool has_edp_a(struct drm_device *dev)
8326 struct drm_i915_private *dev_priv = dev->dev_private;
8328 if (!IS_MOBILE(dev))
8331 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
8335 (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
8341 static void intel_setup_outputs(struct drm_device *dev)
8343 struct drm_i915_private *dev_priv = dev->dev_private;
8344 struct intel_encoder *encoder;
8345 bool dpd_is_edp = false;
8348 has_lvds = intel_lvds_init(dev);
8349 if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
8350 /* disable the panel fitter on everything but LVDS */
8351 I915_WRITE(PFIT_CONTROL, 0);
8355 intel_crt_init(dev);
8360 /* Haswell uses DDI functions to detect digital outputs */
8361 found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
8362 /* DDI A only supports eDP */
8364 intel_ddi_init(dev, PORT_A);
8366 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
8368 found = I915_READ(SFUSE_STRAP);
8370 if (found & SFUSE_STRAP_DDIB_DETECTED)
8371 intel_ddi_init(dev, PORT_B);
8372 if (found & SFUSE_STRAP_DDIC_DETECTED)
8373 intel_ddi_init(dev, PORT_C);
8374 if (found & SFUSE_STRAP_DDID_DETECTED)
8375 intel_ddi_init(dev, PORT_D);
8376 } else if (HAS_PCH_SPLIT(dev)) {
8378 dpd_is_edp = intel_dpd_is_edp(dev);
8381 intel_dp_init(dev, DP_A, PORT_A);
8383 if (I915_READ(HDMIB) & PORT_DETECTED) {
8384 /* PCH SDVOB multiplex with HDMIB */
8385 found = intel_sdvo_init(dev, PCH_SDVOB, true);
8387 intel_hdmi_init(dev, HDMIB, PORT_B);
8388 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
8389 intel_dp_init(dev, PCH_DP_B, PORT_B);
8392 if (I915_READ(HDMIC) & PORT_DETECTED)
8393 intel_hdmi_init(dev, HDMIC, PORT_C);
8395 if (!dpd_is_edp && I915_READ(HDMID) & PORT_DETECTED)
8396 intel_hdmi_init(dev, HDMID, PORT_D);
8398 if (I915_READ(PCH_DP_C) & DP_DETECTED)
8399 intel_dp_init(dev, PCH_DP_C, PORT_C);
8401 if (I915_READ(PCH_DP_D) & DP_DETECTED)
8402 intel_dp_init(dev, PCH_DP_D, PORT_D);
8403 } else if (IS_VALLEYVIEW(dev)) {
8404 /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
8405 if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
8406 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
8408 if (I915_READ(VLV_DISPLAY_BASE + SDVOB) & PORT_DETECTED) {
8409 intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOB, PORT_B);
8410 if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
8411 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
8414 if (I915_READ(VLV_DISPLAY_BASE + SDVOC) & PORT_DETECTED)
8415 intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOC, PORT_C);
8417 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
8420 if (I915_READ(SDVOB) & SDVO_DETECTED) {
8421 DRM_DEBUG_KMS("probing SDVOB\n");
8422 found = intel_sdvo_init(dev, SDVOB, true);
8423 if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
8424 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
8425 intel_hdmi_init(dev, SDVOB, PORT_B);
8428 if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
8429 DRM_DEBUG_KMS("probing DP_B\n");
8430 intel_dp_init(dev, DP_B, PORT_B);
8434 /* Before G4X SDVOC doesn't have its own detect register */
8436 if (I915_READ(SDVOB) & SDVO_DETECTED) {
8437 DRM_DEBUG_KMS("probing SDVOC\n");
8438 found = intel_sdvo_init(dev, SDVOC, false);
8441 if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
8443 if (SUPPORTS_INTEGRATED_HDMI(dev)) {
8444 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
8445 intel_hdmi_init(dev, SDVOC, PORT_C);
8447 if (SUPPORTS_INTEGRATED_DP(dev)) {
8448 DRM_DEBUG_KMS("probing DP_C\n");
8449 intel_dp_init(dev, DP_C, PORT_C);
8453 if (SUPPORTS_INTEGRATED_DP(dev) &&
8454 (I915_READ(DP_D) & DP_DETECTED)) {
8455 DRM_DEBUG_KMS("probing DP_D\n");
8456 intel_dp_init(dev, DP_D, PORT_D);
8458 } else if (IS_GEN2(dev)) {
8460 intel_dvo_init(dev);
8464 if (SUPPORTS_TV(dev))
8467 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
8468 encoder->base.possible_crtcs = encoder->crtc_mask;
8469 encoder->base.possible_clones =
8470 intel_encoder_clones(encoder);
8473 intel_init_pch_refclk(dev);
8475 drm_helper_move_panel_connectors_to_head(dev);
8478 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
8480 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
8482 drm_framebuffer_cleanup(fb);
8483 drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
8485 drm_free(intel_fb, M_DRM);
8488 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
8489 struct drm_file *file,
8490 unsigned int *handle)
8492 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
8493 struct drm_i915_gem_object *obj = intel_fb->obj;
8495 return drm_gem_handle_create(file, &obj->base, handle);
8498 static const struct drm_framebuffer_funcs intel_fb_funcs = {
8499 .destroy = intel_user_framebuffer_destroy,
8500 .create_handle = intel_user_framebuffer_create_handle,
8503 int intel_framebuffer_init(struct drm_device *dev,
8504 struct intel_framebuffer *intel_fb,
8505 struct drm_mode_fb_cmd2 *mode_cmd,
8506 struct drm_i915_gem_object *obj)
8510 if (obj->tiling_mode == I915_TILING_Y) {
8511 DRM_DEBUG("hardware does not support tiling Y\n");
8515 if (mode_cmd->pitches[0] & 63) {
8516 DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
8517 mode_cmd->pitches[0]);
8521 /* FIXME <= Gen4 stride limits are bit unclear */
8522 if (mode_cmd->pitches[0] > 32768) {
8523 DRM_DEBUG("pitch (%d) must be at less than 32768\n",
8524 mode_cmd->pitches[0]);
8528 if (obj->tiling_mode != I915_TILING_NONE &&
8529 mode_cmd->pitches[0] != obj->stride) {
8530 DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
8531 mode_cmd->pitches[0], obj->stride);
8535 /* Reject formats not supported by any plane early. */
8536 switch (mode_cmd->pixel_format) {
8538 case DRM_FORMAT_RGB565:
8539 case DRM_FORMAT_XRGB8888:
8540 case DRM_FORMAT_ARGB8888:
8542 case DRM_FORMAT_XRGB1555:
8543 case DRM_FORMAT_ARGB1555:
8544 if (INTEL_INFO(dev)->gen > 3) {
8545 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
8549 case DRM_FORMAT_XBGR8888:
8550 case DRM_FORMAT_ABGR8888:
8551 case DRM_FORMAT_XRGB2101010:
8552 case DRM_FORMAT_ARGB2101010:
8553 case DRM_FORMAT_XBGR2101010:
8554 case DRM_FORMAT_ABGR2101010:
8555 if (INTEL_INFO(dev)->gen < 4) {
8556 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
8560 case DRM_FORMAT_YUYV:
8561 case DRM_FORMAT_UYVY:
8562 case DRM_FORMAT_YVYU:
8563 case DRM_FORMAT_VYUY:
8564 if (INTEL_INFO(dev)->gen < 5) {
8565 DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
8570 DRM_DEBUG("unsupported pixel format 0x%08x\n", mode_cmd->pixel_format);
8574 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
8575 if (mode_cmd->offsets[0] != 0)
8578 drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
8579 intel_fb->obj = obj;
8581 ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
8583 DRM_ERROR("framebuffer init failed %d\n", ret);
8590 static struct drm_framebuffer *
8591 intel_user_framebuffer_create(struct drm_device *dev,
8592 struct drm_file *filp,
8593 struct drm_mode_fb_cmd2 *mode_cmd)
8595 struct drm_i915_gem_object *obj;
8597 obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
8598 mode_cmd->handles[0]));
8599 if (&obj->base == NULL)
8600 return ERR_PTR(-ENOENT);
8602 return intel_framebuffer_create(dev, mode_cmd, obj);
8605 static const struct drm_mode_config_funcs intel_mode_funcs = {
8606 .fb_create = intel_user_framebuffer_create,
8607 .output_poll_changed = intel_fb_output_poll_changed,
8610 /* Set up chip specific display functions */
8611 static void intel_init_display(struct drm_device *dev)
8613 struct drm_i915_private *dev_priv = dev->dev_private;
8615 /* We always want a DPMS function */
8617 dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
8618 dev_priv->display.crtc_enable = haswell_crtc_enable;
8619 dev_priv->display.crtc_disable = haswell_crtc_disable;
8620 dev_priv->display.off = haswell_crtc_off;
8621 dev_priv->display.update_plane = ironlake_update_plane;
8622 } else if (HAS_PCH_SPLIT(dev)) {
8623 dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
8624 dev_priv->display.crtc_enable = ironlake_crtc_enable;
8625 dev_priv->display.crtc_disable = ironlake_crtc_disable;
8626 dev_priv->display.off = ironlake_crtc_off;
8627 dev_priv->display.update_plane = ironlake_update_plane;
8629 dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
8630 dev_priv->display.crtc_enable = i9xx_crtc_enable;
8631 dev_priv->display.crtc_disable = i9xx_crtc_disable;
8632 dev_priv->display.off = i9xx_crtc_off;
8633 dev_priv->display.update_plane = i9xx_update_plane;
8636 /* Returns the core display clock speed */
8637 if (IS_VALLEYVIEW(dev))
8638 dev_priv->display.get_display_clock_speed =
8639 valleyview_get_display_clock_speed;
8640 else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
8641 dev_priv->display.get_display_clock_speed =
8642 i945_get_display_clock_speed;
8643 else if (IS_I915G(dev))
8644 dev_priv->display.get_display_clock_speed =
8645 i915_get_display_clock_speed;
8646 else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
8647 dev_priv->display.get_display_clock_speed =
8648 i9xx_misc_get_display_clock_speed;
8649 else if (IS_I915GM(dev))
8650 dev_priv->display.get_display_clock_speed =
8651 i915gm_get_display_clock_speed;
8652 else if (IS_I865G(dev))
8653 dev_priv->display.get_display_clock_speed =
8654 i865_get_display_clock_speed;
8655 else if (IS_I85X(dev))
8656 dev_priv->display.get_display_clock_speed =
8657 i855_get_display_clock_speed;
8659 dev_priv->display.get_display_clock_speed =
8660 i830_get_display_clock_speed;
8662 if (HAS_PCH_SPLIT(dev)) {
8664 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
8665 dev_priv->display.write_eld = ironlake_write_eld;
8666 } else if (IS_GEN6(dev)) {
8667 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
8668 dev_priv->display.write_eld = ironlake_write_eld;
8669 } else if (IS_IVYBRIDGE(dev)) {
8670 /* FIXME: detect B0+ stepping and use auto training */
8671 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
8672 dev_priv->display.write_eld = ironlake_write_eld;
8673 dev_priv->display.modeset_global_resources =
8674 ivb_modeset_global_resources;
8675 } else if (IS_HASWELL(dev)) {
8676 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
8677 dev_priv->display.write_eld = haswell_write_eld;
8678 dev_priv->display.modeset_global_resources =
8679 haswell_modeset_global_resources;
8681 } else if (IS_G4X(dev)) {
8682 dev_priv->display.write_eld = g4x_write_eld;
8685 /* Default just returns -ENODEV to indicate unsupported */
8686 dev_priv->display.queue_flip = intel_default_queue_flip;
8688 switch (INTEL_INFO(dev)->gen) {
8690 dev_priv->display.queue_flip = intel_gen2_queue_flip;
8694 dev_priv->display.queue_flip = intel_gen3_queue_flip;
8699 dev_priv->display.queue_flip = intel_gen4_queue_flip;
8703 dev_priv->display.queue_flip = intel_gen6_queue_flip;
8706 dev_priv->display.queue_flip = intel_gen7_queue_flip;
8712 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
8713 * resume, or other times. This quirk makes sure that's the case for
8716 static void quirk_pipea_force(struct drm_device *dev)
8718 struct drm_i915_private *dev_priv = dev->dev_private;
8720 dev_priv->quirks |= QUIRK_PIPEA_FORCE;
8721 DRM_INFO("applying pipe a force quirk\n");
8725 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
8727 static void quirk_ssc_force_disable(struct drm_device *dev)
8729 struct drm_i915_private *dev_priv = dev->dev_private;
8730 dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
8731 DRM_INFO("applying lvds SSC disable quirk\n");
8735 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
8738 static void quirk_invert_brightness(struct drm_device *dev)
8740 struct drm_i915_private *dev_priv = dev->dev_private;
8741 dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
8742 DRM_INFO("applying inverted panel brightness quirk\n");
8745 struct intel_quirk {
8747 int subsystem_vendor;
8748 int subsystem_device;
8749 void (*hook)(struct drm_device *dev);
8752 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
8753 struct intel_dmi_quirk {
8754 void (*hook)(struct drm_device *dev);
8755 const struct dmi_system_id (*dmi_id_list)[];
8758 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
8760 DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
8764 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
8766 .dmi_id_list = &(const struct dmi_system_id[]) {
8768 .callback = intel_dmi_reverse_brightness,
8769 .ident = "NCR Corporation",
8770 .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
8771 DMI_MATCH(DMI_PRODUCT_NAME, ""),
8774 { } /* terminating entry */
8776 .hook = quirk_invert_brightness,
8780 static struct intel_quirk intel_quirks[] = {
8781 /* HP Mini needs pipe A force quirk (LP: #322104) */
8782 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
8784 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
8785 { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
8787 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
8788 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
8790 /* 830/845 need to leave pipe A & dpll A up */
8791 { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
8792 { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
8794 /* Lenovo U160 cannot use SSC on LVDS */
8795 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
8797 /* Sony Vaio Y cannot use SSC on LVDS */
8798 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
8800 /* Acer Aspire 5734Z must invert backlight brightness */
8801 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
8803 /* Acer/eMachines G725 */
8804 { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
8806 /* Acer/eMachines e725 */
8807 { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
8809 /* Acer/Packard Bell NCL20 */
8810 { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
8812 /* Acer Aspire 4736Z */
8813 { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
8816 static void intel_init_quirks(struct drm_device *dev)
8822 for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
8823 struct intel_quirk *q = &intel_quirks[i];
8824 if (pci_get_device(d) == q->device &&
8825 (pci_get_subvendor(d) == q->subsystem_vendor ||
8826 q->subsystem_vendor == PCI_ANY_ID) &&
8827 (pci_get_subdevice(d) == q->subsystem_device ||
8828 q->subsystem_device == PCI_ANY_ID))
8831 for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
8832 if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
8833 intel_dmi_quirks[i].hook(dev);
8837 /* Disable the VGA plane that we never use */
8838 static void i915_disable_vga(struct drm_device *dev)
8840 struct drm_i915_private *dev_priv = dev->dev_private;
8842 u32 vga_reg = i915_vgacntrl_reg(dev);
8845 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
8847 outb(VGA_SR_INDEX, 1);
8848 sr1 = inb(VGA_SR_DATA);
8849 outb(VGA_SR_DATA, sr1 | 1 << 5);
8851 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
8855 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
8856 POSTING_READ(vga_reg);
8859 void intel_modeset_init_hw(struct drm_device *dev)
8861 intel_init_power_well(dev);
8863 intel_prepare_ddi(dev);
8865 intel_init_clock_gating(dev);
8867 mutex_lock(&dev->struct_mutex);
8868 intel_enable_gt_powersave(dev);
8869 mutex_unlock(&dev->struct_mutex);
8872 void intel_modeset_init(struct drm_device *dev)
8874 struct drm_i915_private *dev_priv = dev->dev_private;
8877 drm_mode_config_init(dev);
8879 dev->mode_config.min_width = 0;
8880 dev->mode_config.min_height = 0;
8882 dev->mode_config.preferred_depth = 24;
8883 dev->mode_config.prefer_shadow = 1;
8885 dev->mode_config.funcs = &intel_mode_funcs;
8887 intel_init_quirks(dev);
8891 intel_init_display(dev);
8894 dev->mode_config.max_width = 2048;
8895 dev->mode_config.max_height = 2048;
8896 } else if (IS_GEN3(dev)) {
8897 dev->mode_config.max_width = 4096;
8898 dev->mode_config.max_height = 4096;
8900 dev->mode_config.max_width = 8192;
8901 dev->mode_config.max_height = 8192;
8903 dev->mode_config.fb_base = dev->agp->base;
8905 DRM_DEBUG_KMS("%d display pipe%s available.\n",
8906 dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
8908 for (i = 0; i < dev_priv->num_pipe; i++) {
8909 intel_crtc_init(dev, i);
8910 ret = intel_plane_init(dev, i);
8912 DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
8915 intel_cpu_pll_init(dev);
8916 intel_pch_pll_init(dev);
8918 /* Just disable it once at startup */
8919 i915_disable_vga(dev);
8920 intel_setup_outputs(dev);
8922 /* Just in case the BIOS is doing something questionable. */
8923 intel_disable_fbc(dev);
8927 intel_connector_break_all_links(struct intel_connector *connector)
8929 connector->base.dpms = DRM_MODE_DPMS_OFF;
8930 connector->base.encoder = NULL;
8931 connector->encoder->connectors_active = false;
8932 connector->encoder->base.crtc = NULL;
8935 static void intel_enable_pipe_a(struct drm_device *dev)
8937 struct intel_connector *connector;
8938 struct drm_connector *crt = NULL;
8939 struct intel_load_detect_pipe load_detect_temp;
8941 /* We can't just switch on the pipe A, we need to set things up with a
8942 * proper mode and output configuration. As a gross hack, enable pipe A
8943 * by enabling the load detect pipe once. */
8944 list_for_each_entry(connector,
8945 &dev->mode_config.connector_list,
8947 if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
8948 crt = &connector->base;
8956 if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp))
8957 intel_release_load_detect_pipe(crt, &load_detect_temp);
8963 intel_check_plane_mapping(struct intel_crtc *crtc)
8965 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
8968 if (dev_priv->num_pipe == 1)
8971 reg = DSPCNTR(!crtc->plane);
8972 val = I915_READ(reg);
8974 if ((val & DISPLAY_PLANE_ENABLE) &&
8975 (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
8981 static void intel_sanitize_crtc(struct intel_crtc *crtc)
8983 struct drm_device *dev = crtc->base.dev;
8984 struct drm_i915_private *dev_priv = dev->dev_private;
8987 /* Clear any frame start delays used for debugging left by the BIOS */
8988 reg = PIPECONF(crtc->cpu_transcoder);
8989 I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
8991 /* We need to sanitize the plane -> pipe mapping first because this will
8992 * disable the crtc (and hence change the state) if it is wrong. Note
8993 * that gen4+ has a fixed plane -> pipe mapping. */
8994 if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
8995 struct intel_connector *connector;
8998 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
8999 crtc->base.base.id);
9001 /* Pipe has the wrong plane attached and the plane is active.
9002 * Temporarily change the plane mapping and disable everything
9004 plane = crtc->plane;
9005 crtc->plane = !plane;
9006 dev_priv->display.crtc_disable(&crtc->base);
9007 crtc->plane = plane;
9009 /* ... and break all links. */
9010 list_for_each_entry(connector, &dev->mode_config.connector_list,
9012 if (connector->encoder->base.crtc != &crtc->base)
9015 intel_connector_break_all_links(connector);
9018 WARN_ON(crtc->active);
9019 crtc->base.enabled = false;
9022 if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
9023 crtc->pipe == PIPE_A && !crtc->active) {
9024 /* BIOS forgot to enable pipe A, this mostly happens after
9025 * resume. Force-enable the pipe to fix this, the update_dpms
9026 * call below we restore the pipe to the right state, but leave
9027 * the required bits on. */
9028 intel_enable_pipe_a(dev);
9031 /* Adjust the state of the output pipe according to whether we
9032 * have active connectors/encoders. */
9033 intel_crtc_update_dpms(&crtc->base);
9035 if (crtc->active != crtc->base.enabled) {
9036 struct intel_encoder *encoder;
9038 /* This can happen either due to bugs in the get_hw_state
9039 * functions or because the pipe is force-enabled due to the
9041 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
9043 crtc->base.enabled ? "enabled" : "disabled",
9044 crtc->active ? "enabled" : "disabled");
9046 crtc->base.enabled = crtc->active;
9048 /* Because we only establish the connector -> encoder ->
9049 * crtc links if something is active, this means the
9050 * crtc is now deactivated. Break the links. connector
9051 * -> encoder links are only establish when things are
9052 * actually up, hence no need to break them. */
9053 WARN_ON(crtc->active);
9055 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
9056 WARN_ON(encoder->connectors_active);
9057 encoder->base.crtc = NULL;
9062 static void intel_sanitize_encoder(struct intel_encoder *encoder)
9064 struct intel_connector *connector;
9065 struct drm_device *dev = encoder->base.dev;
9067 /* We need to check both for a crtc link (meaning that the
9068 * encoder is active and trying to read from a pipe) and the
9069 * pipe itself being active. */
9070 bool has_active_crtc = encoder->base.crtc &&
9071 to_intel_crtc(encoder->base.crtc)->active;
9073 if (encoder->connectors_active && !has_active_crtc) {
9074 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
9075 encoder->base.base.id,
9076 drm_get_encoder_name(&encoder->base));
9078 /* Connector is active, but has no active pipe. This is
9079 * fallout from our resume register restoring. Disable
9080 * the encoder manually again. */
9081 if (encoder->base.crtc) {
9082 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
9083 encoder->base.base.id,
9084 drm_get_encoder_name(&encoder->base));
9085 encoder->disable(encoder);
9088 /* Inconsistent output/port/pipe state happens presumably due to
9089 * a bug in one of the get_hw_state functions. Or someplace else
9090 * in our code, like the register restore mess on resume. Clamp
9091 * things to off as a safer default. */
9092 list_for_each_entry(connector,
9093 &dev->mode_config.connector_list,
9095 if (connector->encoder != encoder)
9098 intel_connector_break_all_links(connector);
9101 /* Enabled encoders without active connectors will be fixed in
9102 * the crtc fixup. */
9105 void i915_redisable_vga(struct drm_device *dev)
9107 struct drm_i915_private *dev_priv = dev->dev_private;
9108 u32 vga_reg = i915_vgacntrl_reg(dev);
9110 if (I915_READ(vga_reg) != VGA_DISP_DISABLE) {
9111 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
9112 i915_disable_vga(dev);
9116 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
9117 * and i915 state tracking structures. */
9118 void intel_modeset_setup_hw_state(struct drm_device *dev,
9121 struct drm_i915_private *dev_priv = dev->dev_private;
9122 enum i915_pipe pipe;
9124 struct intel_crtc *crtc;
9125 struct intel_encoder *encoder;
9126 struct intel_connector *connector;
9129 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
9131 if (tmp & TRANS_DDI_FUNC_ENABLE) {
9132 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9133 case TRANS_DDI_EDP_INPUT_A_ON:
9134 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9137 case TRANS_DDI_EDP_INPUT_B_ONOFF:
9140 case TRANS_DDI_EDP_INPUT_C_ONOFF:
9145 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9146 crtc->cpu_transcoder = TRANSCODER_EDP;
9148 DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
9153 for_each_pipe(pipe) {
9154 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9156 tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
9157 if (tmp & PIPECONF_ENABLE)
9158 crtc->active = true;
9160 crtc->active = false;
9162 crtc->base.enabled = crtc->active;
9164 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
9166 crtc->active ? "enabled" : "disabled");
9170 intel_ddi_setup_hw_pll_state(dev);
9172 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
9176 if (encoder->get_hw_state(encoder, &pipe)) {
9177 encoder->base.crtc =
9178 dev_priv->pipe_to_crtc_mapping[pipe];
9180 encoder->base.crtc = NULL;
9183 encoder->connectors_active = false;
9184 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
9185 encoder->base.base.id,
9186 drm_get_encoder_name(&encoder->base),
9187 encoder->base.crtc ? "enabled" : "disabled",
9191 list_for_each_entry(connector, &dev->mode_config.connector_list,
9193 if (connector->get_hw_state(connector)) {
9194 connector->base.dpms = DRM_MODE_DPMS_ON;
9195 connector->encoder->connectors_active = true;
9196 connector->base.encoder = &connector->encoder->base;
9198 connector->base.dpms = DRM_MODE_DPMS_OFF;
9199 connector->base.encoder = NULL;
9201 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
9202 connector->base.base.id,
9203 drm_get_connector_name(&connector->base),
9204 connector->base.encoder ? "enabled" : "disabled");
9207 /* HW state is read out, now we need to sanitize this mess. */
9208 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
9210 intel_sanitize_encoder(encoder);
9213 for_each_pipe(pipe) {
9214 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9215 intel_sanitize_crtc(crtc);
9218 if (force_restore) {
9220 * We need to use raw interfaces for restoring state to avoid
9221 * checking (bogus) intermediate states.
9223 for_each_pipe(pipe) {
9224 struct drm_crtc *crtc =
9225 dev_priv->pipe_to_crtc_mapping[pipe];
9227 __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
9231 i915_redisable_vga(dev);
9233 intel_modeset_update_staged_output_state(dev);
9236 intel_modeset_check_state(dev);
9238 drm_mode_config_reset(dev);
9241 void intel_modeset_gem_init(struct drm_device *dev)
9243 intel_modeset_init_hw(dev);
9245 intel_setup_overlay(dev);
9247 intel_modeset_setup_hw_state(dev, false);
9250 void intel_modeset_cleanup(struct drm_device *dev)
9252 struct drm_i915_private *dev_priv = dev->dev_private;
9253 struct drm_crtc *crtc;
9254 struct intel_crtc *intel_crtc;
9256 drm_kms_helper_poll_fini(dev);
9257 mutex_lock(&dev->struct_mutex);
9260 intel_unregister_dsm_handler();
9264 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
9265 /* Skip inactive CRTCs */
9269 intel_crtc = to_intel_crtc(crtc);
9270 intel_increase_pllclock(crtc);
9273 intel_disable_fbc(dev);
9275 intel_disable_gt_powersave(dev);
9277 ironlake_teardown_rc6(dev);
9279 if (IS_VALLEYVIEW(dev))
9282 mutex_unlock(&dev->struct_mutex);
9284 /* Disable the irq before mode object teardown, for the irq might
9285 * enqueue unpin/hotplug work. */
9286 drm_irq_uninstall(dev);
9287 cancel_work_sync(&dev_priv->hotplug_work);
9288 cancel_work_sync(&dev_priv->rps.work);
9290 /* flush any delayed tasks or pending work */
9291 flush_scheduled_work();
9293 /* destroy backlight, if any, before the connectors */
9294 intel_panel_destroy_backlight(dev);
9296 drm_mode_config_cleanup(dev);
9298 intel_cleanup_overlay(dev);
9302 * Return which encoder is currently attached for connector.
9304 struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
9306 return &intel_attached_encoder(connector)->base;
9309 void intel_connector_attach_encoder(struct intel_connector *connector,
9310 struct intel_encoder *encoder)
9312 connector->encoder = encoder;
9313 drm_mode_connector_attach_encoder(&connector->base,
9318 * set vga decode state - true == enable VGA decode
9320 int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
9322 struct drm_i915_private *dev_priv = dev->dev_private;
9325 pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
9327 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
9329 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
9330 pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
9334 #ifdef CONFIG_DEBUG_FS
9335 #include <linux/seq_file.h>
9337 struct intel_display_error_state {
9338 struct intel_cursor_error_state {
9343 } cursor[I915_MAX_PIPES];
9345 struct intel_pipe_error_state {
9355 } pipe[I915_MAX_PIPES];
9357 struct intel_plane_error_state {
9365 } plane[I915_MAX_PIPES];
9368 struct intel_display_error_state *
9369 intel_display_capture_error_state(struct drm_device *dev)
9371 drm_i915_private_t *dev_priv = dev->dev_private;
9372 struct intel_display_error_state *error;
9373 enum transcoder cpu_transcoder;
9376 error = kmalloc(sizeof(*error), M_DRM, M_WAITOK | M_NULLOK);
9381 cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i);
9383 error->cursor[i].control = I915_READ(CURCNTR(i));
9384 error->cursor[i].position = I915_READ(CURPOS(i));
9385 error->cursor[i].base = I915_READ(CURBASE(i));
9387 error->plane[i].control = I915_READ(DSPCNTR(i));
9388 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
9389 error->plane[i].size = I915_READ(DSPSIZE(i));
9390 error->plane[i].pos = I915_READ(DSPPOS(i));
9391 error->plane[i].addr = I915_READ(DSPADDR(i));
9392 if (INTEL_INFO(dev)->gen >= 4) {
9393 error->plane[i].surface = I915_READ(DSPSURF(i));
9394 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
9397 error->pipe[i].conf = I915_READ(PIPECONF(cpu_transcoder));
9398 error->pipe[i].source = I915_READ(PIPESRC(i));
9399 error->pipe[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
9400 error->pipe[i].hblank = I915_READ(HBLANK(cpu_transcoder));
9401 error->pipe[i].hsync = I915_READ(HSYNC(cpu_transcoder));
9402 error->pipe[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
9403 error->pipe[i].vblank = I915_READ(VBLANK(cpu_transcoder));
9404 error->pipe[i].vsync = I915_READ(VSYNC(cpu_transcoder));
9411 intel_display_print_error_state(struct seq_file *m,
9412 struct drm_device *dev,
9413 struct intel_display_error_state *error)
9415 drm_i915_private_t *dev_priv = dev->dev_private;
9418 seq_printf(m, "Num Pipes: %d\n", dev_priv->num_pipe);
9420 seq_printf(m, "Pipe [%d]:\n", i);
9421 seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
9422 seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
9423 seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
9424 seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
9425 seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
9426 seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
9427 seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
9428 seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
9430 seq_printf(m, "Plane [%d]:\n", i);
9431 seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
9432 seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
9433 seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
9434 seq_printf(m, " POS: %08x\n", error->plane[i].pos);
9435 seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
9436 if (INTEL_INFO(dev)->gen >= 4) {
9437 seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
9438 seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
9441 seq_printf(m, "Cursor [%d]:\n", i);
9442 seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
9443 seq_printf(m, " POS: %08x\n", error->cursor[i].position);
9444 seq_printf(m, " BASE: %08x\n", error->cursor[i].base);