2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/dmi.h>
28 #include <linux/module.h>
29 #include <linux/input.h>
30 #include <linux/i2c.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/vgaarb.h>
34 #include <drm/drm_edid.h>
36 #include "intel_drv.h"
37 #include <drm/i915_drm.h>
39 #include "i915_trace.h"
40 #include <drm/drm_dp_helper.h>
41 #include <drm/drm_crtc_helper.h>
42 #include <linux/dma_remapping.h>
44 bool intel_pipe_has_type(struct drm_crtc
*crtc
, int type
);
45 static void intel_increase_pllclock(struct drm_crtc
*crtc
);
46 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
, bool on
);
69 #define INTEL_P2_NUM 2
70 typedef struct intel_limit intel_limit_t
;
72 intel_range_t dot
, vco
, n
, m
, m1
, m2
, p
, p1
;
74 bool (* find_pll
)(const intel_limit_t
*, struct drm_crtc
*,
75 int, int, intel_clock_t
*, intel_clock_t
*);
79 #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
82 intel_pch_rawclk(struct drm_device
*dev
)
84 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
86 WARN_ON(!HAS_PCH_SPLIT(dev
));
88 return I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
;
92 intel_find_best_PLL(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
93 int target
, int refclk
, intel_clock_t
*match_clock
,
94 intel_clock_t
*best_clock
);
96 intel_g4x_find_best_PLL(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
97 int target
, int refclk
, intel_clock_t
*match_clock
,
98 intel_clock_t
*best_clock
);
101 intel_find_pll_g4x_dp(const intel_limit_t
*, struct drm_crtc
*crtc
,
102 int target
, int refclk
, intel_clock_t
*match_clock
,
103 intel_clock_t
*best_clock
);
105 intel_find_pll_ironlake_dp(const intel_limit_t
*, struct drm_crtc
*crtc
,
106 int target
, int refclk
, intel_clock_t
*match_clock
,
107 intel_clock_t
*best_clock
);
110 intel_vlv_find_best_pll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
111 int target
, int refclk
, intel_clock_t
*match_clock
,
112 intel_clock_t
*best_clock
);
114 static inline u32
/* units of 100MHz */
115 intel_fdi_link_freq(struct drm_device
*dev
)
118 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
119 return (I915_READ(FDI_PLL_BIOS_0
) & FDI_PLL_FB_CLOCK_MASK
) + 2;
124 static const intel_limit_t intel_limits_i8xx_dvo
= {
125 .dot
= { .min
= 25000, .max
= 350000 },
126 .vco
= { .min
= 930000, .max
= 1400000 },
127 .n
= { .min
= 3, .max
= 16 },
128 .m
= { .min
= 96, .max
= 140 },
129 .m1
= { .min
= 18, .max
= 26 },
130 .m2
= { .min
= 6, .max
= 16 },
131 .p
= { .min
= 4, .max
= 128 },
132 .p1
= { .min
= 2, .max
= 33 },
133 .p2
= { .dot_limit
= 165000,
134 .p2_slow
= 4, .p2_fast
= 2 },
135 .find_pll
= intel_find_best_PLL
,
138 static const intel_limit_t intel_limits_i8xx_lvds
= {
139 .dot
= { .min
= 25000, .max
= 350000 },
140 .vco
= { .min
= 930000, .max
= 1400000 },
141 .n
= { .min
= 3, .max
= 16 },
142 .m
= { .min
= 96, .max
= 140 },
143 .m1
= { .min
= 18, .max
= 26 },
144 .m2
= { .min
= 6, .max
= 16 },
145 .p
= { .min
= 4, .max
= 128 },
146 .p1
= { .min
= 1, .max
= 6 },
147 .p2
= { .dot_limit
= 165000,
148 .p2_slow
= 14, .p2_fast
= 7 },
149 .find_pll
= intel_find_best_PLL
,
152 static const intel_limit_t intel_limits_i9xx_sdvo
= {
153 .dot
= { .min
= 20000, .max
= 400000 },
154 .vco
= { .min
= 1400000, .max
= 2800000 },
155 .n
= { .min
= 1, .max
= 6 },
156 .m
= { .min
= 70, .max
= 120 },
157 .m1
= { .min
= 10, .max
= 22 },
158 .m2
= { .min
= 5, .max
= 9 },
159 .p
= { .min
= 5, .max
= 80 },
160 .p1
= { .min
= 1, .max
= 8 },
161 .p2
= { .dot_limit
= 200000,
162 .p2_slow
= 10, .p2_fast
= 5 },
163 .find_pll
= intel_find_best_PLL
,
166 static const intel_limit_t intel_limits_i9xx_lvds
= {
167 .dot
= { .min
= 20000, .max
= 400000 },
168 .vco
= { .min
= 1400000, .max
= 2800000 },
169 .n
= { .min
= 1, .max
= 6 },
170 .m
= { .min
= 70, .max
= 120 },
171 .m1
= { .min
= 10, .max
= 22 },
172 .m2
= { .min
= 5, .max
= 9 },
173 .p
= { .min
= 7, .max
= 98 },
174 .p1
= { .min
= 1, .max
= 8 },
175 .p2
= { .dot_limit
= 112000,
176 .p2_slow
= 14, .p2_fast
= 7 },
177 .find_pll
= intel_find_best_PLL
,
181 static const intel_limit_t intel_limits_g4x_sdvo
= {
182 .dot
= { .min
= 25000, .max
= 270000 },
183 .vco
= { .min
= 1750000, .max
= 3500000},
184 .n
= { .min
= 1, .max
= 4 },
185 .m
= { .min
= 104, .max
= 138 },
186 .m1
= { .min
= 17, .max
= 23 },
187 .m2
= { .min
= 5, .max
= 11 },
188 .p
= { .min
= 10, .max
= 30 },
189 .p1
= { .min
= 1, .max
= 3},
190 .p2
= { .dot_limit
= 270000,
194 .find_pll
= intel_g4x_find_best_PLL
,
197 static const intel_limit_t intel_limits_g4x_hdmi
= {
198 .dot
= { .min
= 22000, .max
= 400000 },
199 .vco
= { .min
= 1750000, .max
= 3500000},
200 .n
= { .min
= 1, .max
= 4 },
201 .m
= { .min
= 104, .max
= 138 },
202 .m1
= { .min
= 16, .max
= 23 },
203 .m2
= { .min
= 5, .max
= 11 },
204 .p
= { .min
= 5, .max
= 80 },
205 .p1
= { .min
= 1, .max
= 8},
206 .p2
= { .dot_limit
= 165000,
207 .p2_slow
= 10, .p2_fast
= 5 },
208 .find_pll
= intel_g4x_find_best_PLL
,
211 static const intel_limit_t intel_limits_g4x_single_channel_lvds
= {
212 .dot
= { .min
= 20000, .max
= 115000 },
213 .vco
= { .min
= 1750000, .max
= 3500000 },
214 .n
= { .min
= 1, .max
= 3 },
215 .m
= { .min
= 104, .max
= 138 },
216 .m1
= { .min
= 17, .max
= 23 },
217 .m2
= { .min
= 5, .max
= 11 },
218 .p
= { .min
= 28, .max
= 112 },
219 .p1
= { .min
= 2, .max
= 8 },
220 .p2
= { .dot_limit
= 0,
221 .p2_slow
= 14, .p2_fast
= 14
223 .find_pll
= intel_g4x_find_best_PLL
,
226 static const intel_limit_t intel_limits_g4x_dual_channel_lvds
= {
227 .dot
= { .min
= 80000, .max
= 224000 },
228 .vco
= { .min
= 1750000, .max
= 3500000 },
229 .n
= { .min
= 1, .max
= 3 },
230 .m
= { .min
= 104, .max
= 138 },
231 .m1
= { .min
= 17, .max
= 23 },
232 .m2
= { .min
= 5, .max
= 11 },
233 .p
= { .min
= 14, .max
= 42 },
234 .p1
= { .min
= 2, .max
= 6 },
235 .p2
= { .dot_limit
= 0,
236 .p2_slow
= 7, .p2_fast
= 7
238 .find_pll
= intel_g4x_find_best_PLL
,
241 static const intel_limit_t intel_limits_g4x_display_port
= {
242 .dot
= { .min
= 161670, .max
= 227000 },
243 .vco
= { .min
= 1750000, .max
= 3500000},
244 .n
= { .min
= 1, .max
= 2 },
245 .m
= { .min
= 97, .max
= 108 },
246 .m1
= { .min
= 0x10, .max
= 0x12 },
247 .m2
= { .min
= 0x05, .max
= 0x06 },
248 .p
= { .min
= 10, .max
= 20 },
249 .p1
= { .min
= 1, .max
= 2},
250 .p2
= { .dot_limit
= 0,
251 .p2_slow
= 10, .p2_fast
= 10 },
252 .find_pll
= intel_find_pll_g4x_dp
,
255 static const intel_limit_t intel_limits_pineview_sdvo
= {
256 .dot
= { .min
= 20000, .max
= 400000},
257 .vco
= { .min
= 1700000, .max
= 3500000 },
258 /* Pineview's Ncounter is a ring counter */
259 .n
= { .min
= 3, .max
= 6 },
260 .m
= { .min
= 2, .max
= 256 },
261 /* Pineview only has one combined m divider, which we treat as m2. */
262 .m1
= { .min
= 0, .max
= 0 },
263 .m2
= { .min
= 0, .max
= 254 },
264 .p
= { .min
= 5, .max
= 80 },
265 .p1
= { .min
= 1, .max
= 8 },
266 .p2
= { .dot_limit
= 200000,
267 .p2_slow
= 10, .p2_fast
= 5 },
268 .find_pll
= intel_find_best_PLL
,
271 static const intel_limit_t intel_limits_pineview_lvds
= {
272 .dot
= { .min
= 20000, .max
= 400000 },
273 .vco
= { .min
= 1700000, .max
= 3500000 },
274 .n
= { .min
= 3, .max
= 6 },
275 .m
= { .min
= 2, .max
= 256 },
276 .m1
= { .min
= 0, .max
= 0 },
277 .m2
= { .min
= 0, .max
= 254 },
278 .p
= { .min
= 7, .max
= 112 },
279 .p1
= { .min
= 1, .max
= 8 },
280 .p2
= { .dot_limit
= 112000,
281 .p2_slow
= 14, .p2_fast
= 14 },
282 .find_pll
= intel_find_best_PLL
,
285 /* Ironlake / Sandybridge
287 * We calculate clock using (register_value + 2) for N/M1/M2, so here
288 * the range value for them is (actual_value - 2).
290 static const intel_limit_t intel_limits_ironlake_dac
= {
291 .dot
= { .min
= 25000, .max
= 350000 },
292 .vco
= { .min
= 1760000, .max
= 3510000 },
293 .n
= { .min
= 1, .max
= 5 },
294 .m
= { .min
= 79, .max
= 127 },
295 .m1
= { .min
= 12, .max
= 22 },
296 .m2
= { .min
= 5, .max
= 9 },
297 .p
= { .min
= 5, .max
= 80 },
298 .p1
= { .min
= 1, .max
= 8 },
299 .p2
= { .dot_limit
= 225000,
300 .p2_slow
= 10, .p2_fast
= 5 },
301 .find_pll
= intel_g4x_find_best_PLL
,
304 static const intel_limit_t intel_limits_ironlake_single_lvds
= {
305 .dot
= { .min
= 25000, .max
= 350000 },
306 .vco
= { .min
= 1760000, .max
= 3510000 },
307 .n
= { .min
= 1, .max
= 3 },
308 .m
= { .min
= 79, .max
= 118 },
309 .m1
= { .min
= 12, .max
= 22 },
310 .m2
= { .min
= 5, .max
= 9 },
311 .p
= { .min
= 28, .max
= 112 },
312 .p1
= { .min
= 2, .max
= 8 },
313 .p2
= { .dot_limit
= 225000,
314 .p2_slow
= 14, .p2_fast
= 14 },
315 .find_pll
= intel_g4x_find_best_PLL
,
318 static const intel_limit_t intel_limits_ironlake_dual_lvds
= {
319 .dot
= { .min
= 25000, .max
= 350000 },
320 .vco
= { .min
= 1760000, .max
= 3510000 },
321 .n
= { .min
= 1, .max
= 3 },
322 .m
= { .min
= 79, .max
= 127 },
323 .m1
= { .min
= 12, .max
= 22 },
324 .m2
= { .min
= 5, .max
= 9 },
325 .p
= { .min
= 14, .max
= 56 },
326 .p1
= { .min
= 2, .max
= 8 },
327 .p2
= { .dot_limit
= 225000,
328 .p2_slow
= 7, .p2_fast
= 7 },
329 .find_pll
= intel_g4x_find_best_PLL
,
332 /* LVDS 100mhz refclk limits. */
333 static const intel_limit_t intel_limits_ironlake_single_lvds_100m
= {
334 .dot
= { .min
= 25000, .max
= 350000 },
335 .vco
= { .min
= 1760000, .max
= 3510000 },
336 .n
= { .min
= 1, .max
= 2 },
337 .m
= { .min
= 79, .max
= 126 },
338 .m1
= { .min
= 12, .max
= 22 },
339 .m2
= { .min
= 5, .max
= 9 },
340 .p
= { .min
= 28, .max
= 112 },
341 .p1
= { .min
= 2, .max
= 8 },
342 .p2
= { .dot_limit
= 225000,
343 .p2_slow
= 14, .p2_fast
= 14 },
344 .find_pll
= intel_g4x_find_best_PLL
,
347 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m
= {
348 .dot
= { .min
= 25000, .max
= 350000 },
349 .vco
= { .min
= 1760000, .max
= 3510000 },
350 .n
= { .min
= 1, .max
= 3 },
351 .m
= { .min
= 79, .max
= 126 },
352 .m1
= { .min
= 12, .max
= 22 },
353 .m2
= { .min
= 5, .max
= 9 },
354 .p
= { .min
= 14, .max
= 42 },
355 .p1
= { .min
= 2, .max
= 6 },
356 .p2
= { .dot_limit
= 225000,
357 .p2_slow
= 7, .p2_fast
= 7 },
358 .find_pll
= intel_g4x_find_best_PLL
,
361 static const intel_limit_t intel_limits_ironlake_display_port
= {
362 .dot
= { .min
= 25000, .max
= 350000 },
363 .vco
= { .min
= 1760000, .max
= 3510000},
364 .n
= { .min
= 1, .max
= 2 },
365 .m
= { .min
= 81, .max
= 90 },
366 .m1
= { .min
= 12, .max
= 22 },
367 .m2
= { .min
= 5, .max
= 9 },
368 .p
= { .min
= 10, .max
= 20 },
369 .p1
= { .min
= 1, .max
= 2},
370 .p2
= { .dot_limit
= 0,
371 .p2_slow
= 10, .p2_fast
= 10 },
372 .find_pll
= intel_find_pll_ironlake_dp
,
375 static const intel_limit_t intel_limits_vlv_dac
= {
376 .dot
= { .min
= 25000, .max
= 270000 },
377 .vco
= { .min
= 4000000, .max
= 6000000 },
378 .n
= { .min
= 1, .max
= 7 },
379 .m
= { .min
= 22, .max
= 450 }, /* guess */
380 .m1
= { .min
= 2, .max
= 3 },
381 .m2
= { .min
= 11, .max
= 156 },
382 .p
= { .min
= 10, .max
= 30 },
383 .p1
= { .min
= 2, .max
= 3 },
384 .p2
= { .dot_limit
= 270000,
385 .p2_slow
= 2, .p2_fast
= 20 },
386 .find_pll
= intel_vlv_find_best_pll
,
389 static const intel_limit_t intel_limits_vlv_hdmi
= {
390 .dot
= { .min
= 20000, .max
= 165000 },
391 .vco
= { .min
= 4000000, .max
= 5994000},
392 .n
= { .min
= 1, .max
= 7 },
393 .m
= { .min
= 60, .max
= 300 }, /* guess */
394 .m1
= { .min
= 2, .max
= 3 },
395 .m2
= { .min
= 11, .max
= 156 },
396 .p
= { .min
= 10, .max
= 30 },
397 .p1
= { .min
= 2, .max
= 3 },
398 .p2
= { .dot_limit
= 270000,
399 .p2_slow
= 2, .p2_fast
= 20 },
400 .find_pll
= intel_vlv_find_best_pll
,
403 static const intel_limit_t intel_limits_vlv_dp
= {
404 .dot
= { .min
= 25000, .max
= 270000 },
405 .vco
= { .min
= 4000000, .max
= 6000000 },
406 .n
= { .min
= 1, .max
= 7 },
407 .m
= { .min
= 22, .max
= 450 },
408 .m1
= { .min
= 2, .max
= 3 },
409 .m2
= { .min
= 11, .max
= 156 },
410 .p
= { .min
= 10, .max
= 30 },
411 .p1
= { .min
= 2, .max
= 3 },
412 .p2
= { .dot_limit
= 270000,
413 .p2_slow
= 2, .p2_fast
= 20 },
414 .find_pll
= intel_vlv_find_best_pll
,
417 u32
intel_dpio_read(struct drm_i915_private
*dev_priv
, int reg
)
422 spin_lock_irqsave(&dev_priv
->dpio_lock
, flags
);
423 if (wait_for_atomic_us((I915_READ(DPIO_PKT
) & DPIO_BUSY
) == 0, 100)) {
424 DRM_ERROR("DPIO idle wait timed out\n");
428 I915_WRITE(DPIO_REG
, reg
);
429 I915_WRITE(DPIO_PKT
, DPIO_RID
| DPIO_OP_READ
| DPIO_PORTID
|
431 if (wait_for_atomic_us((I915_READ(DPIO_PKT
) & DPIO_BUSY
) == 0, 100)) {
432 DRM_ERROR("DPIO read wait timed out\n");
435 val
= I915_READ(DPIO_DATA
);
438 spin_unlock_irqrestore(&dev_priv
->dpio_lock
, flags
);
442 static void intel_dpio_write(struct drm_i915_private
*dev_priv
, int reg
,
447 spin_lock_irqsave(&dev_priv
->dpio_lock
, flags
);
448 if (wait_for_atomic_us((I915_READ(DPIO_PKT
) & DPIO_BUSY
) == 0, 100)) {
449 DRM_ERROR("DPIO idle wait timed out\n");
453 I915_WRITE(DPIO_DATA
, val
);
454 I915_WRITE(DPIO_REG
, reg
);
455 I915_WRITE(DPIO_PKT
, DPIO_RID
| DPIO_OP_WRITE
| DPIO_PORTID
|
457 if (wait_for_atomic_us((I915_READ(DPIO_PKT
) & DPIO_BUSY
) == 0, 100))
458 DRM_ERROR("DPIO write wait timed out\n");
461 spin_unlock_irqrestore(&dev_priv
->dpio_lock
, flags
);
464 static void vlv_init_dpio(struct drm_device
*dev
)
466 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
468 /* Reset the DPIO config */
469 I915_WRITE(DPIO_CTL
, 0);
470 POSTING_READ(DPIO_CTL
);
471 I915_WRITE(DPIO_CTL
, 1);
472 POSTING_READ(DPIO_CTL
);
475 static int intel_dual_link_lvds_callback(const struct dmi_system_id
*id
)
477 DRM_INFO("Forcing lvds to dual link mode on %s\n", id
->ident
);
481 static const struct dmi_system_id intel_dual_link_lvds
[] = {
483 .callback
= intel_dual_link_lvds_callback
,
484 .ident
= "Apple MacBook Pro (Core i5/i7 Series)",
486 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
487 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBookPro8,2"),
490 { } /* terminating entry */
493 static bool is_dual_link_lvds(struct drm_i915_private
*dev_priv
,
498 /* use the module option value if specified */
499 if (i915_lvds_channel_mode
> 0)
500 return i915_lvds_channel_mode
== 2;
502 if (dmi_check_system(intel_dual_link_lvds
))
505 if (dev_priv
->lvds_val
)
506 val
= dev_priv
->lvds_val
;
508 /* BIOS should set the proper LVDS register value at boot, but
509 * in reality, it doesn't set the value when the lid is closed;
510 * we need to check "the value to be set" in VBT when LVDS
511 * register is uninitialized.
513 val
= I915_READ(reg
);
514 if (!(val
& ~(LVDS_PIPE_MASK
| LVDS_DETECTED
)))
515 val
= dev_priv
->bios_lvds_val
;
516 dev_priv
->lvds_val
= val
;
518 return (val
& LVDS_CLKB_POWER_MASK
) == LVDS_CLKB_POWER_UP
;
521 static const intel_limit_t
*intel_ironlake_limit(struct drm_crtc
*crtc
,
524 struct drm_device
*dev
= crtc
->dev
;
525 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
526 const intel_limit_t
*limit
;
528 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
529 if (is_dual_link_lvds(dev_priv
, PCH_LVDS
)) {
530 /* LVDS dual channel */
531 if (refclk
== 100000)
532 limit
= &intel_limits_ironlake_dual_lvds_100m
;
534 limit
= &intel_limits_ironlake_dual_lvds
;
536 if (refclk
== 100000)
537 limit
= &intel_limits_ironlake_single_lvds_100m
;
539 limit
= &intel_limits_ironlake_single_lvds
;
541 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
542 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))
543 limit
= &intel_limits_ironlake_display_port
;
545 limit
= &intel_limits_ironlake_dac
;
550 static const intel_limit_t
*intel_g4x_limit(struct drm_crtc
*crtc
)
552 struct drm_device
*dev
= crtc
->dev
;
553 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
554 const intel_limit_t
*limit
;
556 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
557 if (is_dual_link_lvds(dev_priv
, LVDS
))
558 /* LVDS with dual channel */
559 limit
= &intel_limits_g4x_dual_channel_lvds
;
561 /* LVDS with dual channel */
562 limit
= &intel_limits_g4x_single_channel_lvds
;
563 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
) ||
564 intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
565 limit
= &intel_limits_g4x_hdmi
;
566 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
)) {
567 limit
= &intel_limits_g4x_sdvo
;
568 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
569 limit
= &intel_limits_g4x_display_port
;
570 } else /* The option is for other outputs */
571 limit
= &intel_limits_i9xx_sdvo
;
576 static const intel_limit_t
*intel_limit(struct drm_crtc
*crtc
, int refclk
)
578 struct drm_device
*dev
= crtc
->dev
;
579 const intel_limit_t
*limit
;
581 if (HAS_PCH_SPLIT(dev
))
582 limit
= intel_ironlake_limit(crtc
, refclk
);
583 else if (IS_G4X(dev
)) {
584 limit
= intel_g4x_limit(crtc
);
585 } else if (IS_PINEVIEW(dev
)) {
586 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
587 limit
= &intel_limits_pineview_lvds
;
589 limit
= &intel_limits_pineview_sdvo
;
590 } else if (IS_VALLEYVIEW(dev
)) {
591 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
))
592 limit
= &intel_limits_vlv_dac
;
593 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
))
594 limit
= &intel_limits_vlv_hdmi
;
596 limit
= &intel_limits_vlv_dp
;
597 } else if (!IS_GEN2(dev
)) {
598 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
599 limit
= &intel_limits_i9xx_lvds
;
601 limit
= &intel_limits_i9xx_sdvo
;
603 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
604 limit
= &intel_limits_i8xx_lvds
;
606 limit
= &intel_limits_i8xx_dvo
;
611 /* m1 is reserved as 0 in Pineview, n is a ring counter */
612 static void pineview_clock(int refclk
, intel_clock_t
*clock
)
614 clock
->m
= clock
->m2
+ 2;
615 clock
->p
= clock
->p1
* clock
->p2
;
616 clock
->vco
= refclk
* clock
->m
/ clock
->n
;
617 clock
->dot
= clock
->vco
/ clock
->p
;
620 static void intel_clock(struct drm_device
*dev
, int refclk
, intel_clock_t
*clock
)
622 if (IS_PINEVIEW(dev
)) {
623 pineview_clock(refclk
, clock
);
626 clock
->m
= 5 * (clock
->m1
+ 2) + (clock
->m2
+ 2);
627 clock
->p
= clock
->p1
* clock
->p2
;
628 clock
->vco
= refclk
* clock
->m
/ (clock
->n
+ 2);
629 clock
->dot
= clock
->vco
/ clock
->p
;
633 * Returns whether any output on the specified pipe is of the specified type
635 bool intel_pipe_has_type(struct drm_crtc
*crtc
, int type
)
637 struct drm_device
*dev
= crtc
->dev
;
638 struct intel_encoder
*encoder
;
640 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
641 if (encoder
->type
== type
)
647 #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
649 * Returns whether the given set of divisors are valid for a given refclk with
650 * the given connectors.
653 static bool intel_PLL_is_valid(struct drm_device
*dev
,
654 const intel_limit_t
*limit
,
655 const intel_clock_t
*clock
)
657 if (clock
->p1
< limit
->p1
.min
|| limit
->p1
.max
< clock
->p1
)
658 INTELPllInvalid("p1 out of range\n");
659 if (clock
->p
< limit
->p
.min
|| limit
->p
.max
< clock
->p
)
660 INTELPllInvalid("p out of range\n");
661 if (clock
->m2
< limit
->m2
.min
|| limit
->m2
.max
< clock
->m2
)
662 INTELPllInvalid("m2 out of range\n");
663 if (clock
->m1
< limit
->m1
.min
|| limit
->m1
.max
< clock
->m1
)
664 INTELPllInvalid("m1 out of range\n");
665 if (clock
->m1
<= clock
->m2
&& !IS_PINEVIEW(dev
))
666 INTELPllInvalid("m1 <= m2\n");
667 if (clock
->m
< limit
->m
.min
|| limit
->m
.max
< clock
->m
)
668 INTELPllInvalid("m out of range\n");
669 if (clock
->n
< limit
->n
.min
|| limit
->n
.max
< clock
->n
)
670 INTELPllInvalid("n out of range\n");
671 if (clock
->vco
< limit
->vco
.min
|| limit
->vco
.max
< clock
->vco
)
672 INTELPllInvalid("vco out of range\n");
673 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
674 * connector, etc., rather than just a single range.
676 if (clock
->dot
< limit
->dot
.min
|| limit
->dot
.max
< clock
->dot
)
677 INTELPllInvalid("dot out of range\n");
683 intel_find_best_PLL(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
684 int target
, int refclk
, intel_clock_t
*match_clock
,
685 intel_clock_t
*best_clock
)
688 struct drm_device
*dev
= crtc
->dev
;
689 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
693 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
694 (I915_READ(LVDS
)) != 0) {
696 * For LVDS, if the panel is on, just rely on its current
697 * settings for dual-channel. We haven't figured out how to
698 * reliably set up different single/dual channel state, if we
701 if (is_dual_link_lvds(dev_priv
, LVDS
))
702 clock
.p2
= limit
->p2
.p2_fast
;
704 clock
.p2
= limit
->p2
.p2_slow
;
706 if (target
< limit
->p2
.dot_limit
)
707 clock
.p2
= limit
->p2
.p2_slow
;
709 clock
.p2
= limit
->p2
.p2_fast
;
712 memset(best_clock
, 0, sizeof(*best_clock
));
714 for (clock
.m1
= limit
->m1
.min
; clock
.m1
<= limit
->m1
.max
;
716 for (clock
.m2
= limit
->m2
.min
;
717 clock
.m2
<= limit
->m2
.max
; clock
.m2
++) {
718 /* m1 is always 0 in Pineview */
719 if (clock
.m2
>= clock
.m1
&& !IS_PINEVIEW(dev
))
721 for (clock
.n
= limit
->n
.min
;
722 clock
.n
<= limit
->n
.max
; clock
.n
++) {
723 for (clock
.p1
= limit
->p1
.min
;
724 clock
.p1
<= limit
->p1
.max
; clock
.p1
++) {
727 intel_clock(dev
, refclk
, &clock
);
728 if (!intel_PLL_is_valid(dev
, limit
,
732 clock
.p
!= match_clock
->p
)
735 this_err
= abs(clock
.dot
- target
);
736 if (this_err
< err
) {
745 return (err
!= target
);
749 intel_g4x_find_best_PLL(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
750 int target
, int refclk
, intel_clock_t
*match_clock
,
751 intel_clock_t
*best_clock
)
753 struct drm_device
*dev
= crtc
->dev
;
754 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
758 /* approximately equals target * 0.00585 */
759 int err_most
= (target
>> 8) + (target
>> 9);
762 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
765 if (HAS_PCH_SPLIT(dev
))
769 if ((I915_READ(lvds_reg
) & LVDS_CLKB_POWER_MASK
) ==
771 clock
.p2
= limit
->p2
.p2_fast
;
773 clock
.p2
= limit
->p2
.p2_slow
;
775 if (target
< limit
->p2
.dot_limit
)
776 clock
.p2
= limit
->p2
.p2_slow
;
778 clock
.p2
= limit
->p2
.p2_fast
;
781 memset(best_clock
, 0, sizeof(*best_clock
));
782 max_n
= limit
->n
.max
;
783 /* based on hardware requirement, prefer smaller n to precision */
784 for (clock
.n
= limit
->n
.min
; clock
.n
<= max_n
; clock
.n
++) {
785 /* based on hardware requirement, prefere larger m1,m2 */
786 for (clock
.m1
= limit
->m1
.max
;
787 clock
.m1
>= limit
->m1
.min
; clock
.m1
--) {
788 for (clock
.m2
= limit
->m2
.max
;
789 clock
.m2
>= limit
->m2
.min
; clock
.m2
--) {
790 for (clock
.p1
= limit
->p1
.max
;
791 clock
.p1
>= limit
->p1
.min
; clock
.p1
--) {
794 intel_clock(dev
, refclk
, &clock
);
795 if (!intel_PLL_is_valid(dev
, limit
,
799 clock
.p
!= match_clock
->p
)
802 this_err
= abs(clock
.dot
- target
);
803 if (this_err
< err_most
) {
817 intel_find_pll_ironlake_dp(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
818 int target
, int refclk
, intel_clock_t
*match_clock
,
819 intel_clock_t
*best_clock
)
821 struct drm_device
*dev
= crtc
->dev
;
824 if (target
< 200000) {
837 intel_clock(dev
, refclk
, &clock
);
838 memcpy(best_clock
, &clock
, sizeof(intel_clock_t
));
842 /* DisplayPort has only two frequencies, 162MHz and 270MHz */
844 intel_find_pll_g4x_dp(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
845 int target
, int refclk
, intel_clock_t
*match_clock
,
846 intel_clock_t
*best_clock
)
849 if (target
< 200000) {
862 clock
.m
= 5 * (clock
.m1
+ 2) + (clock
.m2
+ 2);
863 clock
.p
= (clock
.p1
* clock
.p2
);
864 clock
.dot
= 96000 * clock
.m
/ (clock
.n
+ 2) / clock
.p
;
866 memcpy(best_clock
, &clock
, sizeof(intel_clock_t
));
870 intel_vlv_find_best_pll(const intel_limit_t
*limit
, struct drm_crtc
*crtc
,
871 int target
, int refclk
, intel_clock_t
*match_clock
,
872 intel_clock_t
*best_clock
)
874 u32 p1
, p2
, m1
, m2
, vco
, bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
876 u32 updrate
, minupdate
, fracbits
, p
;
877 unsigned long bestppm
, ppm
, absppm
;
881 dotclk
= target
* 1000;
884 fastclk
= dotclk
/ (2*100);
888 n
= p
= p1
= p2
= m
= m1
= m2
= vco
= bestn
= 0;
889 bestm1
= bestm2
= bestp1
= bestp2
= 0;
891 /* based on hardware requirement, prefer smaller n to precision */
892 for (n
= limit
->n
.min
; n
<= ((refclk
) / minupdate
); n
++) {
893 updrate
= refclk
/ n
;
894 for (p1
= limit
->p1
.max
; p1
> limit
->p1
.min
; p1
--) {
895 for (p2
= limit
->p2
.p2_fast
+1; p2
> 0; p2
--) {
899 /* based on hardware requirement, prefer bigger m1,m2 values */
900 for (m1
= limit
->m1
.min
; m1
<= limit
->m1
.max
; m1
++) {
901 m2
= (((2*(fastclk
* p
* n
/ m1
)) +
902 refclk
) / (2*refclk
));
905 if (vco
>= limit
->vco
.min
&& vco
< limit
->vco
.max
) {
906 ppm
= 1000000 * ((vco
/ p
) - fastclk
) / fastclk
;
907 absppm
= (ppm
> 0) ? ppm
: (-ppm
);
908 if (absppm
< 100 && ((p1
* p2
) > (bestp1
* bestp2
))) {
912 if (absppm
< bestppm
- 10) {
929 best_clock
->n
= bestn
;
930 best_clock
->m1
= bestm1
;
931 best_clock
->m2
= bestm2
;
932 best_clock
->p1
= bestp1
;
933 best_clock
->p2
= bestp2
;
938 enum transcoder
intel_pipe_to_cpu_transcoder(struct drm_i915_private
*dev_priv
,
941 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
942 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
944 return intel_crtc
->cpu_transcoder
;
947 static void ironlake_wait_for_vblank(struct drm_device
*dev
, int pipe
)
949 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
950 u32 frame
, frame_reg
= PIPEFRAME(pipe
);
952 frame
= I915_READ(frame_reg
);
954 if (wait_for(I915_READ_NOTRACE(frame_reg
) != frame
, 50))
955 DRM_DEBUG_KMS("vblank wait timed out\n");
959 * intel_wait_for_vblank - wait for vblank on a given pipe
961 * @pipe: pipe to wait for
963 * Wait for vblank to occur on a given pipe. Needed for various bits of
966 void intel_wait_for_vblank(struct drm_device
*dev
, int pipe
)
968 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
969 int pipestat_reg
= PIPESTAT(pipe
);
971 if (INTEL_INFO(dev
)->gen
>= 5) {
972 ironlake_wait_for_vblank(dev
, pipe
);
976 /* Clear existing vblank status. Note this will clear any other
977 * sticky status fields as well.
979 * This races with i915_driver_irq_handler() with the result
980 * that either function could miss a vblank event. Here it is not
981 * fatal, as we will either wait upon the next vblank interrupt or
982 * timeout. Generally speaking intel_wait_for_vblank() is only
983 * called during modeset at which time the GPU should be idle and
984 * should *not* be performing page flips and thus not waiting on
986 * Currently, the result of us stealing a vblank from the irq
987 * handler is that a single frame will be skipped during swapbuffers.
989 I915_WRITE(pipestat_reg
,
990 I915_READ(pipestat_reg
) | PIPE_VBLANK_INTERRUPT_STATUS
);
992 /* Wait for vblank interrupt bit to set */
993 if (wait_for(I915_READ(pipestat_reg
) &
994 PIPE_VBLANK_INTERRUPT_STATUS
,
996 DRM_DEBUG_KMS("vblank wait timed out\n");
1000 * intel_wait_for_pipe_off - wait for pipe to turn off
1002 * @pipe: pipe to wait for
1004 * After disabling a pipe, we can't wait for vblank in the usual way,
1005 * spinning on the vblank interrupt status bit, since we won't actually
1006 * see an interrupt when the pipe is disabled.
1008 * On Gen4 and above:
1009 * wait for the pipe register state bit to turn off
1012 * wait for the display line value to settle (it usually
1013 * ends up stopping at the start of the next frame).
1016 void intel_wait_for_pipe_off(struct drm_device
*dev
, int pipe
)
1018 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1019 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1022 if (INTEL_INFO(dev
)->gen
>= 4) {
1023 int reg
= PIPECONF(cpu_transcoder
);
1025 /* Wait for the Pipe State to go off */
1026 if (wait_for((I915_READ(reg
) & I965_PIPECONF_ACTIVE
) == 0,
1028 WARN(1, "pipe_off wait timed out\n");
1030 u32 last_line
, line_mask
;
1031 int reg
= PIPEDSL(pipe
);
1032 unsigned long timeout
= jiffies
+ msecs_to_jiffies(100);
1035 line_mask
= DSL_LINEMASK_GEN2
;
1037 line_mask
= DSL_LINEMASK_GEN3
;
1039 /* Wait for the display line to settle */
1041 last_line
= I915_READ(reg
) & line_mask
;
1043 } while (((I915_READ(reg
) & line_mask
) != last_line
) &&
1044 time_after(timeout
, jiffies
));
1045 if (time_after(jiffies
, timeout
))
1046 WARN(1, "pipe_off wait timed out\n");
1050 static const char *state_string(bool enabled
)
1052 return enabled
? "on" : "off";
1055 /* Only for pre-ILK configs */
1056 static void assert_pll(struct drm_i915_private
*dev_priv
,
1057 enum pipe pipe
, bool state
)
1064 val
= I915_READ(reg
);
1065 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1066 WARN(cur_state
!= state
,
1067 "PLL state assertion failure (expected %s, current %s)\n",
1068 state_string(state
), state_string(cur_state
));
1070 #define assert_pll_enabled(d, p) assert_pll(d, p, true)
1071 #define assert_pll_disabled(d, p) assert_pll(d, p, false)
1074 static void assert_pch_pll(struct drm_i915_private
*dev_priv
,
1075 struct intel_pch_pll
*pll
,
1076 struct intel_crtc
*crtc
,
1082 if (HAS_PCH_LPT(dev_priv
->dev
)) {
1083 DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
1088 "asserting PCH PLL %s with no PLL\n", state_string(state
)))
1091 val
= I915_READ(pll
->pll_reg
);
1092 cur_state
= !!(val
& DPLL_VCO_ENABLE
);
1093 WARN(cur_state
!= state
,
1094 "PCH PLL state for reg %x assertion failure (expected %s, current %s), val=%08x\n",
1095 pll
->pll_reg
, state_string(state
), state_string(cur_state
), val
);
1097 /* Make sure the selected PLL is correctly attached to the transcoder */
1098 if (crtc
&& HAS_PCH_CPT(dev_priv
->dev
)) {
1101 pch_dpll
= I915_READ(PCH_DPLL_SEL
);
1102 cur_state
= pll
->pll_reg
== _PCH_DPLL_B
;
1103 if (!WARN(((pch_dpll
>> (4 * crtc
->pipe
)) & 1) != cur_state
,
1104 "PLL[%d] not attached to this transcoder %d: %08x\n",
1105 cur_state
, crtc
->pipe
, pch_dpll
)) {
1106 cur_state
= !!(val
>> (4*crtc
->pipe
+ 3));
1107 WARN(cur_state
!= state
,
1108 "PLL[%d] not %s on this transcoder %d: %08x\n",
1109 pll
->pll_reg
== _PCH_DPLL_B
,
1110 state_string(state
),
1116 #define assert_pch_pll_enabled(d, p, c) assert_pch_pll(d, p, c, true)
1117 #define assert_pch_pll_disabled(d, p, c) assert_pch_pll(d, p, c, false)
1119 static void assert_fdi_tx(struct drm_i915_private
*dev_priv
,
1120 enum pipe pipe
, bool state
)
1125 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1128 if (IS_HASWELL(dev_priv
->dev
)) {
1129 /* On Haswell, DDI is used instead of FDI_TX_CTL */
1130 reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1131 val
= I915_READ(reg
);
1132 cur_state
= !!(val
& TRANS_DDI_FUNC_ENABLE
);
1134 reg
= FDI_TX_CTL(pipe
);
1135 val
= I915_READ(reg
);
1136 cur_state
= !!(val
& FDI_TX_ENABLE
);
1138 WARN(cur_state
!= state
,
1139 "FDI TX state assertion failure (expected %s, current %s)\n",
1140 state_string(state
), state_string(cur_state
));
1142 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1143 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1145 static void assert_fdi_rx(struct drm_i915_private
*dev_priv
,
1146 enum pipe pipe
, bool state
)
1152 reg
= FDI_RX_CTL(pipe
);
1153 val
= I915_READ(reg
);
1154 cur_state
= !!(val
& FDI_RX_ENABLE
);
1155 WARN(cur_state
!= state
,
1156 "FDI RX state assertion failure (expected %s, current %s)\n",
1157 state_string(state
), state_string(cur_state
));
1159 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1160 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1162 static void assert_fdi_tx_pll_enabled(struct drm_i915_private
*dev_priv
,
1168 /* ILK FDI PLL is always enabled */
1169 if (dev_priv
->info
->gen
== 5)
1172 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
1173 if (IS_HASWELL(dev_priv
->dev
))
1176 reg
= FDI_TX_CTL(pipe
);
1177 val
= I915_READ(reg
);
1178 WARN(!(val
& FDI_TX_PLL_ENABLE
), "FDI TX PLL assertion failure, should be active but is disabled\n");
1181 static void assert_fdi_rx_pll_enabled(struct drm_i915_private
*dev_priv
,
1187 reg
= FDI_RX_CTL(pipe
);
1188 val
= I915_READ(reg
);
1189 WARN(!(val
& FDI_RX_PLL_ENABLE
), "FDI RX PLL assertion failure, should be active but is disabled\n");
1192 static void assert_panel_unlocked(struct drm_i915_private
*dev_priv
,
1195 int pp_reg
, lvds_reg
;
1197 enum pipe panel_pipe
= PIPE_A
;
1200 if (HAS_PCH_SPLIT(dev_priv
->dev
)) {
1201 pp_reg
= PCH_PP_CONTROL
;
1202 lvds_reg
= PCH_LVDS
;
1204 pp_reg
= PP_CONTROL
;
1208 val
= I915_READ(pp_reg
);
1209 if (!(val
& PANEL_POWER_ON
) ||
1210 ((val
& PANEL_UNLOCK_REGS
) == PANEL_UNLOCK_REGS
))
1213 if (I915_READ(lvds_reg
) & LVDS_PIPEB_SELECT
)
1214 panel_pipe
= PIPE_B
;
1216 WARN(panel_pipe
== pipe
&& locked
,
1217 "panel assertion failure, pipe %c regs locked\n",
1221 void assert_pipe(struct drm_i915_private
*dev_priv
,
1222 enum pipe pipe
, bool state
)
1227 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1230 /* if we need the pipe A quirk it must be always on */
1231 if (pipe
== PIPE_A
&& dev_priv
->quirks
& QUIRK_PIPEA_FORCE
)
1234 reg
= PIPECONF(cpu_transcoder
);
1235 val
= I915_READ(reg
);
1236 cur_state
= !!(val
& PIPECONF_ENABLE
);
1237 WARN(cur_state
!= state
,
1238 "pipe %c assertion failure (expected %s, current %s)\n",
1239 pipe_name(pipe
), state_string(state
), state_string(cur_state
));
1242 static void assert_plane(struct drm_i915_private
*dev_priv
,
1243 enum plane plane
, bool state
)
1249 reg
= DSPCNTR(plane
);
1250 val
= I915_READ(reg
);
1251 cur_state
= !!(val
& DISPLAY_PLANE_ENABLE
);
1252 WARN(cur_state
!= state
,
1253 "plane %c assertion failure (expected %s, current %s)\n",
1254 plane_name(plane
), state_string(state
), state_string(cur_state
));
1257 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1258 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1260 static void assert_planes_disabled(struct drm_i915_private
*dev_priv
,
1267 /* Planes are fixed to pipes on ILK+ */
1268 if (HAS_PCH_SPLIT(dev_priv
->dev
)) {
1269 reg
= DSPCNTR(pipe
);
1270 val
= I915_READ(reg
);
1271 WARN((val
& DISPLAY_PLANE_ENABLE
),
1272 "plane %c assertion failure, should be disabled but not\n",
1277 /* Need to check both planes against the pipe */
1278 for (i
= 0; i
< 2; i
++) {
1280 val
= I915_READ(reg
);
1281 cur_pipe
= (val
& DISPPLANE_SEL_PIPE_MASK
) >>
1282 DISPPLANE_SEL_PIPE_SHIFT
;
1283 WARN((val
& DISPLAY_PLANE_ENABLE
) && pipe
== cur_pipe
,
1284 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1285 plane_name(i
), pipe_name(pipe
));
1289 static void assert_pch_refclk_enabled(struct drm_i915_private
*dev_priv
)
1294 if (HAS_PCH_LPT(dev_priv
->dev
)) {
1295 DRM_DEBUG_DRIVER("LPT does not has PCH refclk, skipping check\n");
1299 val
= I915_READ(PCH_DREF_CONTROL
);
1300 enabled
= !!(val
& (DREF_SSC_SOURCE_MASK
| DREF_NONSPREAD_SOURCE_MASK
|
1301 DREF_SUPERSPREAD_SOURCE_MASK
));
1302 WARN(!enabled
, "PCH refclk assertion failure, should be active but is disabled\n");
1305 static void assert_transcoder_disabled(struct drm_i915_private
*dev_priv
,
1312 reg
= TRANSCONF(pipe
);
1313 val
= I915_READ(reg
);
1314 enabled
= !!(val
& TRANS_ENABLE
);
1316 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1320 static bool dp_pipe_enabled(struct drm_i915_private
*dev_priv
,
1321 enum pipe pipe
, u32 port_sel
, u32 val
)
1323 if ((val
& DP_PORT_EN
) == 0)
1326 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1327 u32 trans_dp_ctl_reg
= TRANS_DP_CTL(pipe
);
1328 u32 trans_dp_ctl
= I915_READ(trans_dp_ctl_reg
);
1329 if ((trans_dp_ctl
& TRANS_DP_PORT_SEL_MASK
) != port_sel
)
1332 if ((val
& DP_PIPE_MASK
) != (pipe
<< 30))
1338 static bool hdmi_pipe_enabled(struct drm_i915_private
*dev_priv
,
1339 enum pipe pipe
, u32 val
)
1341 if ((val
& PORT_ENABLE
) == 0)
1344 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1345 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1348 if ((val
& TRANSCODER_MASK
) != TRANSCODER(pipe
))
1354 static bool lvds_pipe_enabled(struct drm_i915_private
*dev_priv
,
1355 enum pipe pipe
, u32 val
)
1357 if ((val
& LVDS_PORT_EN
) == 0)
1360 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1361 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1364 if ((val
& LVDS_PIPE_MASK
) != LVDS_PIPE(pipe
))
1370 static bool adpa_pipe_enabled(struct drm_i915_private
*dev_priv
,
1371 enum pipe pipe
, u32 val
)
1373 if ((val
& ADPA_DAC_ENABLE
) == 0)
1375 if (HAS_PCH_CPT(dev_priv
->dev
)) {
1376 if ((val
& PORT_TRANS_SEL_MASK
) != PORT_TRANS_SEL_CPT(pipe
))
1379 if ((val
& ADPA_PIPE_SELECT_MASK
) != ADPA_PIPE_SELECT(pipe
))
1385 static void assert_pch_dp_disabled(struct drm_i915_private
*dev_priv
,
1386 enum pipe pipe
, int reg
, u32 port_sel
)
1388 u32 val
= I915_READ(reg
);
1389 WARN(dp_pipe_enabled(dev_priv
, pipe
, port_sel
, val
),
1390 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1391 reg
, pipe_name(pipe
));
1393 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& DP_PORT_EN
) == 0
1394 && (val
& DP_PIPEB_SELECT
),
1395 "IBX PCH dp port still using transcoder B\n");
1398 static void assert_pch_hdmi_disabled(struct drm_i915_private
*dev_priv
,
1399 enum pipe pipe
, int reg
)
1401 u32 val
= I915_READ(reg
);
1402 WARN(hdmi_pipe_enabled(dev_priv
, pipe
, val
),
1403 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1404 reg
, pipe_name(pipe
));
1406 WARN(HAS_PCH_IBX(dev_priv
->dev
) && (val
& PORT_ENABLE
) == 0
1407 && (val
& SDVO_PIPE_B_SELECT
),
1408 "IBX PCH hdmi port still using transcoder B\n");
1411 static void assert_pch_ports_disabled(struct drm_i915_private
*dev_priv
,
1417 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_B
, TRANS_DP_PORT_SEL_B
);
1418 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_C
, TRANS_DP_PORT_SEL_C
);
1419 assert_pch_dp_disabled(dev_priv
, pipe
, PCH_DP_D
, TRANS_DP_PORT_SEL_D
);
1422 val
= I915_READ(reg
);
1423 WARN(adpa_pipe_enabled(dev_priv
, pipe
, val
),
1424 "PCH VGA enabled on transcoder %c, should be disabled\n",
1428 val
= I915_READ(reg
);
1429 WARN(lvds_pipe_enabled(dev_priv
, pipe
, val
),
1430 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1433 assert_pch_hdmi_disabled(dev_priv
, pipe
, HDMIB
);
1434 assert_pch_hdmi_disabled(dev_priv
, pipe
, HDMIC
);
1435 assert_pch_hdmi_disabled(dev_priv
, pipe
, HDMID
);
1439 * intel_enable_pll - enable a PLL
1440 * @dev_priv: i915 private structure
1441 * @pipe: pipe PLL to enable
1443 * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to
1444 * make sure the PLL reg is writable first though, since the panel write
1445 * protect mechanism may be enabled.
1447 * Note! This is for pre-ILK only.
1449 * Unfortunately needed by dvo_ns2501 since the dvo depends on it running.
1451 static void intel_enable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1456 /* No really, not for ILK+ */
1457 BUG_ON(!IS_VALLEYVIEW(dev_priv
->dev
) && dev_priv
->info
->gen
>= 5);
1459 /* PLL is protected by panel, make sure we can write it */
1460 if (IS_MOBILE(dev_priv
->dev
) && !IS_I830(dev_priv
->dev
))
1461 assert_panel_unlocked(dev_priv
, pipe
);
1464 val
= I915_READ(reg
);
1465 val
|= DPLL_VCO_ENABLE
;
1467 /* We do this three times for luck */
1468 I915_WRITE(reg
, val
);
1470 udelay(150); /* wait for warmup */
1471 I915_WRITE(reg
, val
);
1473 udelay(150); /* wait for warmup */
1474 I915_WRITE(reg
, val
);
1476 udelay(150); /* wait for warmup */
1480 * intel_disable_pll - disable a PLL
1481 * @dev_priv: i915 private structure
1482 * @pipe: pipe PLL to disable
1484 * Disable the PLL for @pipe, making sure the pipe is off first.
1486 * Note! This is for pre-ILK only.
1488 static void intel_disable_pll(struct drm_i915_private
*dev_priv
, enum pipe pipe
)
1493 /* Don't disable pipe A or pipe A PLLs if needed */
1494 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
1497 /* Make sure the pipe isn't still relying on us */
1498 assert_pipe_disabled(dev_priv
, pipe
);
1501 val
= I915_READ(reg
);
1502 val
&= ~DPLL_VCO_ENABLE
;
1503 I915_WRITE(reg
, val
);
1509 intel_sbi_write(struct drm_i915_private
*dev_priv
, u16 reg
, u32 value
)
1511 unsigned long flags
;
1513 spin_lock_irqsave(&dev_priv
->dpio_lock
, flags
);
1514 if (wait_for((I915_READ(SBI_CTL_STAT
) & SBI_BUSY
) == 0,
1516 DRM_ERROR("timeout waiting for SBI to become ready\n");
1520 I915_WRITE(SBI_ADDR
,
1522 I915_WRITE(SBI_DATA
,
1524 I915_WRITE(SBI_CTL_STAT
,
1528 if (wait_for((I915_READ(SBI_CTL_STAT
) & (SBI_BUSY
| SBI_RESPONSE_FAIL
)) == 0,
1530 DRM_ERROR("timeout waiting for SBI to complete write transaction\n");
1535 spin_unlock_irqrestore(&dev_priv
->dpio_lock
, flags
);
1539 intel_sbi_read(struct drm_i915_private
*dev_priv
, u16 reg
)
1541 unsigned long flags
;
1544 spin_lock_irqsave(&dev_priv
->dpio_lock
, flags
);
1545 if (wait_for((I915_READ(SBI_CTL_STAT
) & SBI_BUSY
) == 0,
1547 DRM_ERROR("timeout waiting for SBI to become ready\n");
1551 I915_WRITE(SBI_ADDR
,
1553 I915_WRITE(SBI_CTL_STAT
,
1557 if (wait_for((I915_READ(SBI_CTL_STAT
) & (SBI_BUSY
| SBI_RESPONSE_FAIL
)) == 0,
1559 DRM_ERROR("timeout waiting for SBI to complete read transaction\n");
1563 value
= I915_READ(SBI_DATA
);
1566 spin_unlock_irqrestore(&dev_priv
->dpio_lock
, flags
);
1571 * ironlake_enable_pch_pll - enable PCH PLL
1572 * @dev_priv: i915 private structure
1573 * @pipe: pipe PLL to enable
1575 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1576 * drives the transcoder clock.
1578 static void ironlake_enable_pch_pll(struct intel_crtc
*intel_crtc
)
1580 struct drm_i915_private
*dev_priv
= intel_crtc
->base
.dev
->dev_private
;
1581 struct intel_pch_pll
*pll
;
1585 /* PCH PLLs only available on ILK, SNB and IVB */
1586 BUG_ON(dev_priv
->info
->gen
< 5);
1587 pll
= intel_crtc
->pch_pll
;
1591 if (WARN_ON(pll
->refcount
== 0))
1594 DRM_DEBUG_KMS("enable PCH PLL %x (active %d, on? %d)for crtc %d\n",
1595 pll
->pll_reg
, pll
->active
, pll
->on
,
1596 intel_crtc
->base
.base
.id
);
1598 /* PCH refclock must be enabled first */
1599 assert_pch_refclk_enabled(dev_priv
);
1601 if (pll
->active
++ && pll
->on
) {
1602 assert_pch_pll_enabled(dev_priv
, pll
, NULL
);
1606 DRM_DEBUG_KMS("enabling PCH PLL %x\n", pll
->pll_reg
);
1609 val
= I915_READ(reg
);
1610 val
|= DPLL_VCO_ENABLE
;
1611 I915_WRITE(reg
, val
);
1618 static void intel_disable_pch_pll(struct intel_crtc
*intel_crtc
)
1620 struct drm_i915_private
*dev_priv
= intel_crtc
->base
.dev
->dev_private
;
1621 struct intel_pch_pll
*pll
= intel_crtc
->pch_pll
;
1625 /* PCH only available on ILK+ */
1626 BUG_ON(dev_priv
->info
->gen
< 5);
1630 if (WARN_ON(pll
->refcount
== 0))
1633 DRM_DEBUG_KMS("disable PCH PLL %x (active %d, on? %d) for crtc %d\n",
1634 pll
->pll_reg
, pll
->active
, pll
->on
,
1635 intel_crtc
->base
.base
.id
);
1637 if (WARN_ON(pll
->active
== 0)) {
1638 assert_pch_pll_disabled(dev_priv
, pll
, NULL
);
1642 if (--pll
->active
) {
1643 assert_pch_pll_enabled(dev_priv
, pll
, NULL
);
1647 DRM_DEBUG_KMS("disabling PCH PLL %x\n", pll
->pll_reg
);
1649 /* Make sure transcoder isn't still depending on us */
1650 assert_transcoder_disabled(dev_priv
, intel_crtc
->pipe
);
1653 val
= I915_READ(reg
);
1654 val
&= ~DPLL_VCO_ENABLE
;
1655 I915_WRITE(reg
, val
);
1662 static void ironlake_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1665 struct drm_device
*dev
= dev_priv
->dev
;
1666 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1667 uint32_t reg
, val
, pipeconf_val
;
1669 /* PCH only available on ILK+ */
1670 BUG_ON(dev_priv
->info
->gen
< 5);
1672 /* Make sure PCH DPLL is enabled */
1673 assert_pch_pll_enabled(dev_priv
,
1674 to_intel_crtc(crtc
)->pch_pll
,
1675 to_intel_crtc(crtc
));
1677 /* FDI must be feeding us bits for PCH ports */
1678 assert_fdi_tx_enabled(dev_priv
, pipe
);
1679 assert_fdi_rx_enabled(dev_priv
, pipe
);
1681 if (HAS_PCH_CPT(dev
)) {
1682 /* Workaround: Set the timing override bit before enabling the
1683 * pch transcoder. */
1684 reg
= TRANS_CHICKEN2(pipe
);
1685 val
= I915_READ(reg
);
1686 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1687 I915_WRITE(reg
, val
);
1690 reg
= TRANSCONF(pipe
);
1691 val
= I915_READ(reg
);
1692 pipeconf_val
= I915_READ(PIPECONF(pipe
));
1694 if (HAS_PCH_IBX(dev_priv
->dev
)) {
1696 * make the BPC in transcoder be consistent with
1697 * that in pipeconf reg.
1699 val
&= ~PIPE_BPC_MASK
;
1700 val
|= pipeconf_val
& PIPE_BPC_MASK
;
1703 val
&= ~TRANS_INTERLACE_MASK
;
1704 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK
) == PIPECONF_INTERLACED_ILK
)
1705 if (HAS_PCH_IBX(dev_priv
->dev
) &&
1706 intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
))
1707 val
|= TRANS_LEGACY_INTERLACED_ILK
;
1709 val
|= TRANS_INTERLACED
;
1711 val
|= TRANS_PROGRESSIVE
;
1713 I915_WRITE(reg
, val
| TRANS_ENABLE
);
1714 if (wait_for(I915_READ(reg
) & TRANS_STATE_ENABLE
, 100))
1715 DRM_ERROR("failed to enable transcoder %d\n", pipe
);
1718 static void lpt_enable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1719 enum transcoder cpu_transcoder
)
1721 u32 val
, pipeconf_val
;
1723 /* PCH only available on ILK+ */
1724 BUG_ON(dev_priv
->info
->gen
< 5);
1726 /* FDI must be feeding us bits for PCH ports */
1727 assert_fdi_tx_enabled(dev_priv
, cpu_transcoder
);
1728 assert_fdi_rx_enabled(dev_priv
, TRANSCODER_A
);
1730 /* Workaround: set timing override bit. */
1731 val
= I915_READ(_TRANSA_CHICKEN2
);
1732 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
1733 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1736 pipeconf_val
= I915_READ(PIPECONF(cpu_transcoder
));
1738 if ((pipeconf_val
& PIPECONF_INTERLACE_MASK_HSW
) ==
1739 PIPECONF_INTERLACED_ILK
)
1740 val
|= TRANS_INTERLACED
;
1742 val
|= TRANS_PROGRESSIVE
;
1744 I915_WRITE(TRANSCONF(TRANSCODER_A
), val
);
1745 if (wait_for(I915_READ(_TRANSACONF
) & TRANS_STATE_ENABLE
, 100))
1746 DRM_ERROR("Failed to enable PCH transcoder\n");
1749 static void ironlake_disable_pch_transcoder(struct drm_i915_private
*dev_priv
,
1752 struct drm_device
*dev
= dev_priv
->dev
;
1755 /* FDI relies on the transcoder */
1756 assert_fdi_tx_disabled(dev_priv
, pipe
);
1757 assert_fdi_rx_disabled(dev_priv
, pipe
);
1759 /* Ports must be off as well */
1760 assert_pch_ports_disabled(dev_priv
, pipe
);
1762 reg
= TRANSCONF(pipe
);
1763 val
= I915_READ(reg
);
1764 val
&= ~TRANS_ENABLE
;
1765 I915_WRITE(reg
, val
);
1766 /* wait for PCH transcoder off, transcoder state */
1767 if (wait_for((I915_READ(reg
) & TRANS_STATE_ENABLE
) == 0, 50))
1768 DRM_ERROR("failed to disable transcoder %d\n", pipe
);
1770 if (!HAS_PCH_IBX(dev
)) {
1771 /* Workaround: Clear the timing override chicken bit again. */
1772 reg
= TRANS_CHICKEN2(pipe
);
1773 val
= I915_READ(reg
);
1774 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1775 I915_WRITE(reg
, val
);
1779 static void lpt_disable_pch_transcoder(struct drm_i915_private
*dev_priv
)
1783 val
= I915_READ(_TRANSACONF
);
1784 val
&= ~TRANS_ENABLE
;
1785 I915_WRITE(_TRANSACONF
, val
);
1786 /* wait for PCH transcoder off, transcoder state */
1787 if (wait_for((I915_READ(_TRANSACONF
) & TRANS_STATE_ENABLE
) == 0, 50))
1788 DRM_ERROR("Failed to disable PCH transcoder\n");
1790 /* Workaround: clear timing override bit. */
1791 val
= I915_READ(_TRANSA_CHICKEN2
);
1792 val
&= ~TRANS_CHICKEN2_TIMING_OVERRIDE
;
1793 I915_WRITE(_TRANSA_CHICKEN2
, val
);
1797 * intel_enable_pipe - enable a pipe, asserting requirements
1798 * @dev_priv: i915 private structure
1799 * @pipe: pipe to enable
1800 * @pch_port: on ILK+, is this pipe driving a PCH port or not
1802 * Enable @pipe, making sure that various hardware specific requirements
1803 * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
1805 * @pipe should be %PIPE_A or %PIPE_B.
1807 * Will wait until the pipe is actually running (i.e. first vblank) before
1810 static void intel_enable_pipe(struct drm_i915_private
*dev_priv
, enum pipe pipe
,
1813 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1819 * A pipe without a PLL won't actually be able to drive bits from
1820 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1823 if (!HAS_PCH_SPLIT(dev_priv
->dev
))
1824 assert_pll_enabled(dev_priv
, pipe
);
1827 /* if driving the PCH, we need FDI enabled */
1828 assert_fdi_rx_pll_enabled(dev_priv
, pipe
);
1829 assert_fdi_tx_pll_enabled(dev_priv
, pipe
);
1831 /* FIXME: assert CPU port conditions for SNB+ */
1834 reg
= PIPECONF(cpu_transcoder
);
1835 val
= I915_READ(reg
);
1836 if (val
& PIPECONF_ENABLE
)
1839 I915_WRITE(reg
, val
| PIPECONF_ENABLE
);
1840 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
1844 * intel_disable_pipe - disable a pipe, asserting requirements
1845 * @dev_priv: i915 private structure
1846 * @pipe: pipe to disable
1848 * Disable @pipe, making sure that various hardware specific requirements
1849 * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
1851 * @pipe should be %PIPE_A or %PIPE_B.
1853 * Will wait until the pipe has shut down before returning.
1855 static void intel_disable_pipe(struct drm_i915_private
*dev_priv
,
1858 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
1864 * Make sure planes won't keep trying to pump pixels to us,
1865 * or we might hang the display.
1867 assert_planes_disabled(dev_priv
, pipe
);
1869 /* Don't disable pipe A or pipe A PLLs if needed */
1870 if (pipe
== PIPE_A
&& (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
))
1873 reg
= PIPECONF(cpu_transcoder
);
1874 val
= I915_READ(reg
);
1875 if ((val
& PIPECONF_ENABLE
) == 0)
1878 I915_WRITE(reg
, val
& ~PIPECONF_ENABLE
);
1879 intel_wait_for_pipe_off(dev_priv
->dev
, pipe
);
1883 * Plane regs are double buffered, going from enabled->disabled needs a
1884 * trigger in order to latch. The display address reg provides this.
1886 void intel_flush_display_plane(struct drm_i915_private
*dev_priv
,
1889 if (dev_priv
->info
->gen
>= 4)
1890 I915_WRITE(DSPSURF(plane
), I915_READ(DSPSURF(plane
)));
1892 I915_WRITE(DSPADDR(plane
), I915_READ(DSPADDR(plane
)));
1896 * intel_enable_plane - enable a display plane on a given pipe
1897 * @dev_priv: i915 private structure
1898 * @plane: plane to enable
1899 * @pipe: pipe being fed
1901 * Enable @plane on @pipe, making sure that @pipe is running first.
1903 static void intel_enable_plane(struct drm_i915_private
*dev_priv
,
1904 enum plane plane
, enum pipe pipe
)
1909 /* If the pipe isn't enabled, we can't pump pixels and may hang */
1910 assert_pipe_enabled(dev_priv
, pipe
);
1912 reg
= DSPCNTR(plane
);
1913 val
= I915_READ(reg
);
1914 if (val
& DISPLAY_PLANE_ENABLE
)
1917 I915_WRITE(reg
, val
| DISPLAY_PLANE_ENABLE
);
1918 intel_flush_display_plane(dev_priv
, plane
);
1919 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
1923 * intel_disable_plane - disable a display plane
1924 * @dev_priv: i915 private structure
1925 * @plane: plane to disable
1926 * @pipe: pipe consuming the data
1928 * Disable @plane; should be an independent operation.
1930 static void intel_disable_plane(struct drm_i915_private
*dev_priv
,
1931 enum plane plane
, enum pipe pipe
)
1936 reg
= DSPCNTR(plane
);
1937 val
= I915_READ(reg
);
1938 if ((val
& DISPLAY_PLANE_ENABLE
) == 0)
1941 I915_WRITE(reg
, val
& ~DISPLAY_PLANE_ENABLE
);
1942 intel_flush_display_plane(dev_priv
, plane
);
1943 intel_wait_for_vblank(dev_priv
->dev
, pipe
);
1947 intel_pin_and_fence_fb_obj(struct drm_device
*dev
,
1948 struct drm_i915_gem_object
*obj
,
1949 struct intel_ring_buffer
*pipelined
)
1951 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1955 switch (obj
->tiling_mode
) {
1956 case I915_TILING_NONE
:
1957 if (IS_BROADWATER(dev
) || IS_CRESTLINE(dev
))
1958 alignment
= 128 * 1024;
1959 else if (INTEL_INFO(dev
)->gen
>= 4)
1960 alignment
= 4 * 1024;
1962 alignment
= 64 * 1024;
1965 /* pin() will align the object as required by fence */
1969 /* FIXME: Is this true? */
1970 DRM_ERROR("Y tiled not allowed for scan out buffers\n");
1976 dev_priv
->mm
.interruptible
= false;
1977 ret
= i915_gem_object_pin_to_display_plane(obj
, alignment
, pipelined
);
1979 goto err_interruptible
;
1981 /* Install a fence for tiled scan-out. Pre-i965 always needs a
1982 * fence, whereas 965+ only requires a fence if using
1983 * framebuffer compression. For simplicity, we always install
1984 * a fence as the cost is not that onerous.
1986 ret
= i915_gem_object_get_fence(obj
);
1990 i915_gem_object_pin_fence(obj
);
1992 dev_priv
->mm
.interruptible
= true;
1996 i915_gem_object_unpin(obj
);
1998 dev_priv
->mm
.interruptible
= true;
2002 void intel_unpin_fb_obj(struct drm_i915_gem_object
*obj
)
2004 i915_gem_object_unpin_fence(obj
);
2005 i915_gem_object_unpin(obj
);
2008 /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2009 * is assumed to be a power-of-two. */
2010 unsigned long intel_gen4_compute_offset_xtiled(int *x
, int *y
,
2014 int tile_rows
, tiles
;
2018 tiles
= *x
/ (512/bpp
);
2021 return tile_rows
* pitch
* 8 + tiles
* 4096;
2024 static int i9xx_update_plane(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
2027 struct drm_device
*dev
= crtc
->dev
;
2028 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2029 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2030 struct intel_framebuffer
*intel_fb
;
2031 struct drm_i915_gem_object
*obj
;
2032 int plane
= intel_crtc
->plane
;
2033 unsigned long linear_offset
;
2042 DRM_ERROR("Can't update plane %d in SAREA\n", plane
);
2046 intel_fb
= to_intel_framebuffer(fb
);
2047 obj
= intel_fb
->obj
;
2049 reg
= DSPCNTR(plane
);
2050 dspcntr
= I915_READ(reg
);
2051 /* Mask out pixel format bits in case we change it */
2052 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
2053 switch (fb
->pixel_format
) {
2055 dspcntr
|= DISPPLANE_8BPP
;
2057 case DRM_FORMAT_XRGB1555
:
2058 case DRM_FORMAT_ARGB1555
:
2059 dspcntr
|= DISPPLANE_BGRX555
;
2061 case DRM_FORMAT_RGB565
:
2062 dspcntr
|= DISPPLANE_BGRX565
;
2064 case DRM_FORMAT_XRGB8888
:
2065 case DRM_FORMAT_ARGB8888
:
2066 dspcntr
|= DISPPLANE_BGRX888
;
2068 case DRM_FORMAT_XBGR8888
:
2069 case DRM_FORMAT_ABGR8888
:
2070 dspcntr
|= DISPPLANE_RGBX888
;
2072 case DRM_FORMAT_XRGB2101010
:
2073 case DRM_FORMAT_ARGB2101010
:
2074 dspcntr
|= DISPPLANE_BGRX101010
;
2076 case DRM_FORMAT_XBGR2101010
:
2077 case DRM_FORMAT_ABGR2101010
:
2078 dspcntr
|= DISPPLANE_RGBX101010
;
2081 DRM_ERROR("Unknown pixel format 0x%08x\n", fb
->pixel_format
);
2085 if (INTEL_INFO(dev
)->gen
>= 4) {
2086 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2087 dspcntr
|= DISPPLANE_TILED
;
2089 dspcntr
&= ~DISPPLANE_TILED
;
2092 I915_WRITE(reg
, dspcntr
);
2094 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2096 if (INTEL_INFO(dev
)->gen
>= 4) {
2097 intel_crtc
->dspaddr_offset
=
2098 intel_gen4_compute_offset_xtiled(&x
, &y
,
2099 fb
->bits_per_pixel
/ 8,
2101 linear_offset
-= intel_crtc
->dspaddr_offset
;
2103 intel_crtc
->dspaddr_offset
= linear_offset
;
2106 DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
2107 obj
->gtt_offset
, linear_offset
, x
, y
, fb
->pitches
[0]);
2108 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2109 if (INTEL_INFO(dev
)->gen
>= 4) {
2110 I915_MODIFY_DISPBASE(DSPSURF(plane
),
2111 obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
2112 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2113 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2115 I915_WRITE(DSPADDR(plane
), obj
->gtt_offset
+ linear_offset
);
2121 static int ironlake_update_plane(struct drm_crtc
*crtc
,
2122 struct drm_framebuffer
*fb
, int x
, int y
)
2124 struct drm_device
*dev
= crtc
->dev
;
2125 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2126 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2127 struct intel_framebuffer
*intel_fb
;
2128 struct drm_i915_gem_object
*obj
;
2129 int plane
= intel_crtc
->plane
;
2130 unsigned long linear_offset
;
2140 DRM_ERROR("Can't update plane %d in SAREA\n", plane
);
2144 intel_fb
= to_intel_framebuffer(fb
);
2145 obj
= intel_fb
->obj
;
2147 reg
= DSPCNTR(plane
);
2148 dspcntr
= I915_READ(reg
);
2149 /* Mask out pixel format bits in case we change it */
2150 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
2151 switch (fb
->pixel_format
) {
2153 dspcntr
|= DISPPLANE_8BPP
;
2155 case DRM_FORMAT_RGB565
:
2156 dspcntr
|= DISPPLANE_BGRX565
;
2158 case DRM_FORMAT_XRGB8888
:
2159 case DRM_FORMAT_ARGB8888
:
2160 dspcntr
|= DISPPLANE_BGRX888
;
2162 case DRM_FORMAT_XBGR8888
:
2163 case DRM_FORMAT_ABGR8888
:
2164 dspcntr
|= DISPPLANE_RGBX888
;
2166 case DRM_FORMAT_XRGB2101010
:
2167 case DRM_FORMAT_ARGB2101010
:
2168 dspcntr
|= DISPPLANE_BGRX101010
;
2170 case DRM_FORMAT_XBGR2101010
:
2171 case DRM_FORMAT_ABGR2101010
:
2172 dspcntr
|= DISPPLANE_RGBX101010
;
2175 DRM_ERROR("Unknown pixel format 0x%08x\n", fb
->pixel_format
);
2179 if (obj
->tiling_mode
!= I915_TILING_NONE
)
2180 dspcntr
|= DISPPLANE_TILED
;
2182 dspcntr
&= ~DISPPLANE_TILED
;
2185 dspcntr
|= DISPPLANE_TRICKLE_FEED_DISABLE
;
2187 I915_WRITE(reg
, dspcntr
);
2189 linear_offset
= y
* fb
->pitches
[0] + x
* (fb
->bits_per_pixel
/ 8);
2190 intel_crtc
->dspaddr_offset
=
2191 intel_gen4_compute_offset_xtiled(&x
, &y
,
2192 fb
->bits_per_pixel
/ 8,
2194 linear_offset
-= intel_crtc
->dspaddr_offset
;
2196 DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
2197 obj
->gtt_offset
, linear_offset
, x
, y
, fb
->pitches
[0]);
2198 I915_WRITE(DSPSTRIDE(plane
), fb
->pitches
[0]);
2199 I915_MODIFY_DISPBASE(DSPSURF(plane
),
2200 obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
2201 if (IS_HASWELL(dev
)) {
2202 I915_WRITE(DSPOFFSET(plane
), (y
<< 16) | x
);
2204 I915_WRITE(DSPTILEOFF(plane
), (y
<< 16) | x
);
2205 I915_WRITE(DSPLINOFF(plane
), linear_offset
);
2212 /* Assume fb object is pinned & idle & fenced and just update base pointers */
2214 intel_pipe_set_base_atomic(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
2215 int x
, int y
, enum mode_set_atomic state
)
2217 struct drm_device
*dev
= crtc
->dev
;
2218 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2220 if (dev_priv
->display
.disable_fbc
)
2221 dev_priv
->display
.disable_fbc(dev
);
2222 intel_increase_pllclock(crtc
);
2224 return dev_priv
->display
.update_plane(crtc
, fb
, x
, y
);
2228 intel_finish_fb(struct drm_framebuffer
*old_fb
)
2230 struct drm_i915_gem_object
*obj
= to_intel_framebuffer(old_fb
)->obj
;
2231 struct drm_i915_private
*dev_priv
= obj
->base
.dev
->dev_private
;
2232 bool was_interruptible
= dev_priv
->mm
.interruptible
;
2235 wait_event(dev_priv
->pending_flip_queue
,
2236 atomic_read(&dev_priv
->mm
.wedged
) ||
2237 atomic_read(&obj
->pending_flip
) == 0);
2239 /* Big Hammer, we also need to ensure that any pending
2240 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
2241 * current scanout is retired before unpinning the old
2244 * This should only fail upon a hung GPU, in which case we
2245 * can safely continue.
2247 dev_priv
->mm
.interruptible
= false;
2248 ret
= i915_gem_object_finish_gpu(obj
);
2249 dev_priv
->mm
.interruptible
= was_interruptible
;
2254 static void intel_crtc_update_sarea_pos(struct drm_crtc
*crtc
, int x
, int y
)
2256 struct drm_device
*dev
= crtc
->dev
;
2257 struct drm_i915_master_private
*master_priv
;
2258 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2260 if (!dev
->primary
->master
)
2263 master_priv
= dev
->primary
->master
->driver_priv
;
2264 if (!master_priv
->sarea_priv
)
2267 switch (intel_crtc
->pipe
) {
2269 master_priv
->sarea_priv
->pipeA_x
= x
;
2270 master_priv
->sarea_priv
->pipeA_y
= y
;
2273 master_priv
->sarea_priv
->pipeB_x
= x
;
2274 master_priv
->sarea_priv
->pipeB_y
= y
;
2282 intel_pipe_set_base(struct drm_crtc
*crtc
, int x
, int y
,
2283 struct drm_framebuffer
*fb
)
2285 struct drm_device
*dev
= crtc
->dev
;
2286 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2287 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2288 struct drm_framebuffer
*old_fb
;
2293 DRM_ERROR("No FB bound\n");
2297 if(intel_crtc
->plane
> dev_priv
->num_pipe
) {
2298 DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
2300 dev_priv
->num_pipe
);
2304 mutex_lock(&dev
->struct_mutex
);
2305 ret
= intel_pin_and_fence_fb_obj(dev
,
2306 to_intel_framebuffer(fb
)->obj
,
2309 mutex_unlock(&dev
->struct_mutex
);
2310 DRM_ERROR("pin & fence failed\n");
2315 intel_finish_fb(crtc
->fb
);
2317 ret
= dev_priv
->display
.update_plane(crtc
, fb
, x
, y
);
2319 intel_unpin_fb_obj(to_intel_framebuffer(fb
)->obj
);
2320 mutex_unlock(&dev
->struct_mutex
);
2321 DRM_ERROR("failed to update base address\n");
2331 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
2332 intel_unpin_fb_obj(to_intel_framebuffer(old_fb
)->obj
);
2335 intel_update_fbc(dev
);
2336 mutex_unlock(&dev
->struct_mutex
);
2338 intel_crtc_update_sarea_pos(crtc
, x
, y
);
2343 static void ironlake_set_pll_edp(struct drm_crtc
*crtc
, int clock
)
2345 struct drm_device
*dev
= crtc
->dev
;
2346 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2349 DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", clock
);
2350 dpa_ctl
= I915_READ(DP_A
);
2351 dpa_ctl
&= ~DP_PLL_FREQ_MASK
;
2353 if (clock
< 200000) {
2355 dpa_ctl
|= DP_PLL_FREQ_160MHZ
;
2356 /* workaround for 160Mhz:
2357 1) program 0x4600c bits 15:0 = 0x8124
2358 2) program 0x46010 bit 0 = 1
2359 3) program 0x46034 bit 24 = 1
2360 4) program 0x64000 bit 14 = 1
2362 temp
= I915_READ(0x4600c);
2364 I915_WRITE(0x4600c, temp
| 0x8124);
2366 temp
= I915_READ(0x46010);
2367 I915_WRITE(0x46010, temp
| 1);
2369 temp
= I915_READ(0x46034);
2370 I915_WRITE(0x46034, temp
| (1 << 24));
2372 dpa_ctl
|= DP_PLL_FREQ_270MHZ
;
2374 I915_WRITE(DP_A
, dpa_ctl
);
2380 static void intel_fdi_normal_train(struct drm_crtc
*crtc
)
2382 struct drm_device
*dev
= crtc
->dev
;
2383 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2384 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2385 int pipe
= intel_crtc
->pipe
;
2388 /* enable normal train */
2389 reg
= FDI_TX_CTL(pipe
);
2390 temp
= I915_READ(reg
);
2391 if (IS_IVYBRIDGE(dev
)) {
2392 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2393 temp
|= FDI_LINK_TRAIN_NONE_IVB
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2395 temp
&= ~FDI_LINK_TRAIN_NONE
;
2396 temp
|= FDI_LINK_TRAIN_NONE
| FDI_TX_ENHANCE_FRAME_ENABLE
;
2398 I915_WRITE(reg
, temp
);
2400 reg
= FDI_RX_CTL(pipe
);
2401 temp
= I915_READ(reg
);
2402 if (HAS_PCH_CPT(dev
)) {
2403 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2404 temp
|= FDI_LINK_TRAIN_NORMAL_CPT
;
2406 temp
&= ~FDI_LINK_TRAIN_NONE
;
2407 temp
|= FDI_LINK_TRAIN_NONE
;
2409 I915_WRITE(reg
, temp
| FDI_RX_ENHANCE_FRAME_ENABLE
);
2411 /* wait one idle pattern time */
2415 /* IVB wants error correction enabled */
2416 if (IS_IVYBRIDGE(dev
))
2417 I915_WRITE(reg
, I915_READ(reg
) | FDI_FS_ERRC_ENABLE
|
2418 FDI_FE_ERRC_ENABLE
);
2421 static void cpt_phase_pointer_enable(struct drm_device
*dev
, int pipe
)
2423 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2424 u32 flags
= I915_READ(SOUTH_CHICKEN1
);
2426 flags
|= FDI_PHASE_SYNC_OVR(pipe
);
2427 I915_WRITE(SOUTH_CHICKEN1
, flags
); /* once to unlock... */
2428 flags
|= FDI_PHASE_SYNC_EN(pipe
);
2429 I915_WRITE(SOUTH_CHICKEN1
, flags
); /* then again to enable */
2430 POSTING_READ(SOUTH_CHICKEN1
);
2433 static void ivb_modeset_global_resources(struct drm_device
*dev
)
2435 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2436 struct intel_crtc
*pipe_B_crtc
=
2437 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
2438 struct intel_crtc
*pipe_C_crtc
=
2439 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]);
2442 /* When everything is off disable fdi C so that we could enable fdi B
2443 * with all lanes. XXX: This misses the case where a pipe is not using
2444 * any pch resources and so doesn't need any fdi lanes. */
2445 if (!pipe_B_crtc
->base
.enabled
&& !pipe_C_crtc
->base
.enabled
) {
2446 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
2447 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
2449 temp
= I915_READ(SOUTH_CHICKEN1
);
2450 temp
&= ~FDI_BC_BIFURCATION_SELECT
;
2451 DRM_DEBUG_KMS("disabling fdi C rx\n");
2452 I915_WRITE(SOUTH_CHICKEN1
, temp
);
2456 /* The FDI link training functions for ILK/Ibexpeak. */
2457 static void ironlake_fdi_link_train(struct drm_crtc
*crtc
)
2459 struct drm_device
*dev
= crtc
->dev
;
2460 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2461 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2462 int pipe
= intel_crtc
->pipe
;
2463 int plane
= intel_crtc
->plane
;
2464 u32 reg
, temp
, tries
;
2466 /* FDI needs bits from pipe & plane first */
2467 assert_pipe_enabled(dev_priv
, pipe
);
2468 assert_plane_enabled(dev_priv
, plane
);
2470 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2472 reg
= FDI_RX_IMR(pipe
);
2473 temp
= I915_READ(reg
);
2474 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2475 temp
&= ~FDI_RX_BIT_LOCK
;
2476 I915_WRITE(reg
, temp
);
2480 /* enable CPU FDI TX and PCH FDI RX */
2481 reg
= FDI_TX_CTL(pipe
);
2482 temp
= I915_READ(reg
);
2484 temp
|= (intel_crtc
->fdi_lanes
- 1) << 19;
2485 temp
&= ~FDI_LINK_TRAIN_NONE
;
2486 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2487 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2489 reg
= FDI_RX_CTL(pipe
);
2490 temp
= I915_READ(reg
);
2491 temp
&= ~FDI_LINK_TRAIN_NONE
;
2492 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2493 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2498 /* Ironlake workaround, enable clock pointer after FDI enable*/
2499 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
2500 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
|
2501 FDI_RX_PHASE_SYNC_POINTER_EN
);
2503 reg
= FDI_RX_IIR(pipe
);
2504 for (tries
= 0; tries
< 5; tries
++) {
2505 temp
= I915_READ(reg
);
2506 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2508 if ((temp
& FDI_RX_BIT_LOCK
)) {
2509 DRM_DEBUG_KMS("FDI train 1 done.\n");
2510 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2515 DRM_ERROR("FDI train 1 fail!\n");
2518 reg
= FDI_TX_CTL(pipe
);
2519 temp
= I915_READ(reg
);
2520 temp
&= ~FDI_LINK_TRAIN_NONE
;
2521 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2522 I915_WRITE(reg
, temp
);
2524 reg
= FDI_RX_CTL(pipe
);
2525 temp
= I915_READ(reg
);
2526 temp
&= ~FDI_LINK_TRAIN_NONE
;
2527 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2528 I915_WRITE(reg
, temp
);
2533 reg
= FDI_RX_IIR(pipe
);
2534 for (tries
= 0; tries
< 5; tries
++) {
2535 temp
= I915_READ(reg
);
2536 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2538 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2539 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2540 DRM_DEBUG_KMS("FDI train 2 done.\n");
2545 DRM_ERROR("FDI train 2 fail!\n");
2547 DRM_DEBUG_KMS("FDI train done\n");
2551 static const int snb_b_fdi_train_param
[] = {
2552 FDI_LINK_TRAIN_400MV_0DB_SNB_B
,
2553 FDI_LINK_TRAIN_400MV_6DB_SNB_B
,
2554 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B
,
2555 FDI_LINK_TRAIN_800MV_0DB_SNB_B
,
2558 /* The FDI link training functions for SNB/Cougarpoint. */
2559 static void gen6_fdi_link_train(struct drm_crtc
*crtc
)
2561 struct drm_device
*dev
= crtc
->dev
;
2562 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2563 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2564 int pipe
= intel_crtc
->pipe
;
2565 u32 reg
, temp
, i
, retry
;
2567 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2569 reg
= FDI_RX_IMR(pipe
);
2570 temp
= I915_READ(reg
);
2571 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2572 temp
&= ~FDI_RX_BIT_LOCK
;
2573 I915_WRITE(reg
, temp
);
2578 /* enable CPU FDI TX and PCH FDI RX */
2579 reg
= FDI_TX_CTL(pipe
);
2580 temp
= I915_READ(reg
);
2582 temp
|= (intel_crtc
->fdi_lanes
- 1) << 19;
2583 temp
&= ~FDI_LINK_TRAIN_NONE
;
2584 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2585 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2587 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2588 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2590 I915_WRITE(FDI_RX_MISC(pipe
),
2591 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
2593 reg
= FDI_RX_CTL(pipe
);
2594 temp
= I915_READ(reg
);
2595 if (HAS_PCH_CPT(dev
)) {
2596 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2597 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2599 temp
&= ~FDI_LINK_TRAIN_NONE
;
2600 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2602 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2607 cpt_phase_pointer_enable(dev
, pipe
);
2609 for (i
= 0; i
< 4; i
++) {
2610 reg
= FDI_TX_CTL(pipe
);
2611 temp
= I915_READ(reg
);
2612 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2613 temp
|= snb_b_fdi_train_param
[i
];
2614 I915_WRITE(reg
, temp
);
2619 for (retry
= 0; retry
< 5; retry
++) {
2620 reg
= FDI_RX_IIR(pipe
);
2621 temp
= I915_READ(reg
);
2622 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2623 if (temp
& FDI_RX_BIT_LOCK
) {
2624 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2625 DRM_DEBUG_KMS("FDI train 1 done.\n");
2634 DRM_ERROR("FDI train 1 fail!\n");
2637 reg
= FDI_TX_CTL(pipe
);
2638 temp
= I915_READ(reg
);
2639 temp
&= ~FDI_LINK_TRAIN_NONE
;
2640 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2642 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2644 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2646 I915_WRITE(reg
, temp
);
2648 reg
= FDI_RX_CTL(pipe
);
2649 temp
= I915_READ(reg
);
2650 if (HAS_PCH_CPT(dev
)) {
2651 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2652 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
2654 temp
&= ~FDI_LINK_TRAIN_NONE
;
2655 temp
|= FDI_LINK_TRAIN_PATTERN_2
;
2657 I915_WRITE(reg
, temp
);
2662 for (i
= 0; i
< 4; i
++) {
2663 reg
= FDI_TX_CTL(pipe
);
2664 temp
= I915_READ(reg
);
2665 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2666 temp
|= snb_b_fdi_train_param
[i
];
2667 I915_WRITE(reg
, temp
);
2672 for (retry
= 0; retry
< 5; retry
++) {
2673 reg
= FDI_RX_IIR(pipe
);
2674 temp
= I915_READ(reg
);
2675 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2676 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2677 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2678 DRM_DEBUG_KMS("FDI train 2 done.\n");
2687 DRM_ERROR("FDI train 2 fail!\n");
2689 DRM_DEBUG_KMS("FDI train done.\n");
2692 /* Manual link training for Ivy Bridge A0 parts */
2693 static void ivb_manual_fdi_link_train(struct drm_crtc
*crtc
)
2695 struct drm_device
*dev
= crtc
->dev
;
2696 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2697 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2698 int pipe
= intel_crtc
->pipe
;
2701 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
2703 reg
= FDI_RX_IMR(pipe
);
2704 temp
= I915_READ(reg
);
2705 temp
&= ~FDI_RX_SYMBOL_LOCK
;
2706 temp
&= ~FDI_RX_BIT_LOCK
;
2707 I915_WRITE(reg
, temp
);
2712 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
2713 I915_READ(FDI_RX_IIR(pipe
)));
2715 /* enable CPU FDI TX and PCH FDI RX */
2716 reg
= FDI_TX_CTL(pipe
);
2717 temp
= I915_READ(reg
);
2719 temp
|= (intel_crtc
->fdi_lanes
- 1) << 19;
2720 temp
&= ~(FDI_LINK_TRAIN_AUTO
| FDI_LINK_TRAIN_NONE_IVB
);
2721 temp
|= FDI_LINK_TRAIN_PATTERN_1_IVB
;
2722 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2723 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2724 temp
|= FDI_COMPOSITE_SYNC
;
2725 I915_WRITE(reg
, temp
| FDI_TX_ENABLE
);
2727 I915_WRITE(FDI_RX_MISC(pipe
),
2728 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
2730 reg
= FDI_RX_CTL(pipe
);
2731 temp
= I915_READ(reg
);
2732 temp
&= ~FDI_LINK_TRAIN_AUTO
;
2733 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2734 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2735 temp
|= FDI_COMPOSITE_SYNC
;
2736 I915_WRITE(reg
, temp
| FDI_RX_ENABLE
);
2741 cpt_phase_pointer_enable(dev
, pipe
);
2743 for (i
= 0; i
< 4; i
++) {
2744 reg
= FDI_TX_CTL(pipe
);
2745 temp
= I915_READ(reg
);
2746 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2747 temp
|= snb_b_fdi_train_param
[i
];
2748 I915_WRITE(reg
, temp
);
2753 reg
= FDI_RX_IIR(pipe
);
2754 temp
= I915_READ(reg
);
2755 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2757 if (temp
& FDI_RX_BIT_LOCK
||
2758 (I915_READ(reg
) & FDI_RX_BIT_LOCK
)) {
2759 I915_WRITE(reg
, temp
| FDI_RX_BIT_LOCK
);
2760 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i
);
2765 DRM_ERROR("FDI train 1 fail!\n");
2768 reg
= FDI_TX_CTL(pipe
);
2769 temp
= I915_READ(reg
);
2770 temp
&= ~FDI_LINK_TRAIN_NONE_IVB
;
2771 temp
|= FDI_LINK_TRAIN_PATTERN_2_IVB
;
2772 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2773 temp
|= FDI_LINK_TRAIN_400MV_0DB_SNB_B
;
2774 I915_WRITE(reg
, temp
);
2776 reg
= FDI_RX_CTL(pipe
);
2777 temp
= I915_READ(reg
);
2778 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2779 temp
|= FDI_LINK_TRAIN_PATTERN_2_CPT
;
2780 I915_WRITE(reg
, temp
);
2785 for (i
= 0; i
< 4; i
++) {
2786 reg
= FDI_TX_CTL(pipe
);
2787 temp
= I915_READ(reg
);
2788 temp
&= ~FDI_LINK_TRAIN_VOL_EMP_MASK
;
2789 temp
|= snb_b_fdi_train_param
[i
];
2790 I915_WRITE(reg
, temp
);
2795 reg
= FDI_RX_IIR(pipe
);
2796 temp
= I915_READ(reg
);
2797 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp
);
2799 if (temp
& FDI_RX_SYMBOL_LOCK
) {
2800 I915_WRITE(reg
, temp
| FDI_RX_SYMBOL_LOCK
);
2801 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i
);
2806 DRM_ERROR("FDI train 2 fail!\n");
2808 DRM_DEBUG_KMS("FDI train done.\n");
2811 static void ironlake_fdi_pll_enable(struct intel_crtc
*intel_crtc
)
2813 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2814 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2815 int pipe
= intel_crtc
->pipe
;
2819 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
2820 reg
= FDI_RX_CTL(pipe
);
2821 temp
= I915_READ(reg
);
2822 temp
&= ~((0x7 << 19) | (0x7 << 16));
2823 temp
|= (intel_crtc
->fdi_lanes
- 1) << 19;
2824 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPE_BPC_MASK
) << 11;
2825 I915_WRITE(reg
, temp
| FDI_RX_PLL_ENABLE
);
2830 /* Switch from Rawclk to PCDclk */
2831 temp
= I915_READ(reg
);
2832 I915_WRITE(reg
, temp
| FDI_PCDCLK
);
2837 /* On Haswell, the PLL configuration for ports and pipes is handled
2838 * separately, as part of DDI setup */
2839 if (!IS_HASWELL(dev
)) {
2840 /* Enable CPU FDI TX PLL, always on for Ironlake */
2841 reg
= FDI_TX_CTL(pipe
);
2842 temp
= I915_READ(reg
);
2843 if ((temp
& FDI_TX_PLL_ENABLE
) == 0) {
2844 I915_WRITE(reg
, temp
| FDI_TX_PLL_ENABLE
);
2852 static void ironlake_fdi_pll_disable(struct intel_crtc
*intel_crtc
)
2854 struct drm_device
*dev
= intel_crtc
->base
.dev
;
2855 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2856 int pipe
= intel_crtc
->pipe
;
2859 /* Switch from PCDclk to Rawclk */
2860 reg
= FDI_RX_CTL(pipe
);
2861 temp
= I915_READ(reg
);
2862 I915_WRITE(reg
, temp
& ~FDI_PCDCLK
);
2864 /* Disable CPU FDI TX PLL */
2865 reg
= FDI_TX_CTL(pipe
);
2866 temp
= I915_READ(reg
);
2867 I915_WRITE(reg
, temp
& ~FDI_TX_PLL_ENABLE
);
2872 reg
= FDI_RX_CTL(pipe
);
2873 temp
= I915_READ(reg
);
2874 I915_WRITE(reg
, temp
& ~FDI_RX_PLL_ENABLE
);
2876 /* Wait for the clocks to turn off. */
2881 static void cpt_phase_pointer_disable(struct drm_device
*dev
, int pipe
)
2883 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2884 u32 flags
= I915_READ(SOUTH_CHICKEN1
);
2886 flags
&= ~(FDI_PHASE_SYNC_EN(pipe
));
2887 I915_WRITE(SOUTH_CHICKEN1
, flags
); /* once to disable... */
2888 flags
&= ~(FDI_PHASE_SYNC_OVR(pipe
));
2889 I915_WRITE(SOUTH_CHICKEN1
, flags
); /* then again to lock */
2890 POSTING_READ(SOUTH_CHICKEN1
);
2892 static void ironlake_fdi_disable(struct drm_crtc
*crtc
)
2894 struct drm_device
*dev
= crtc
->dev
;
2895 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2896 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2897 int pipe
= intel_crtc
->pipe
;
2900 /* disable CPU FDI tx and PCH FDI rx */
2901 reg
= FDI_TX_CTL(pipe
);
2902 temp
= I915_READ(reg
);
2903 I915_WRITE(reg
, temp
& ~FDI_TX_ENABLE
);
2906 reg
= FDI_RX_CTL(pipe
);
2907 temp
= I915_READ(reg
);
2908 temp
&= ~(0x7 << 16);
2909 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPE_BPC_MASK
) << 11;
2910 I915_WRITE(reg
, temp
& ~FDI_RX_ENABLE
);
2915 /* Ironlake workaround, disable clock pointer after downing FDI */
2916 if (HAS_PCH_IBX(dev
)) {
2917 I915_WRITE(FDI_RX_CHICKEN(pipe
), FDI_RX_PHASE_SYNC_POINTER_OVR
);
2918 } else if (HAS_PCH_CPT(dev
)) {
2919 cpt_phase_pointer_disable(dev
, pipe
);
2922 /* still set train pattern 1 */
2923 reg
= FDI_TX_CTL(pipe
);
2924 temp
= I915_READ(reg
);
2925 temp
&= ~FDI_LINK_TRAIN_NONE
;
2926 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2927 I915_WRITE(reg
, temp
);
2929 reg
= FDI_RX_CTL(pipe
);
2930 temp
= I915_READ(reg
);
2931 if (HAS_PCH_CPT(dev
)) {
2932 temp
&= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT
;
2933 temp
|= FDI_LINK_TRAIN_PATTERN_1_CPT
;
2935 temp
&= ~FDI_LINK_TRAIN_NONE
;
2936 temp
|= FDI_LINK_TRAIN_PATTERN_1
;
2938 /* BPC in FDI rx is consistent with that in PIPECONF */
2939 temp
&= ~(0x07 << 16);
2940 temp
|= (I915_READ(PIPECONF(pipe
)) & PIPE_BPC_MASK
) << 11;
2941 I915_WRITE(reg
, temp
);
2947 static bool intel_crtc_has_pending_flip(struct drm_crtc
*crtc
)
2949 struct drm_device
*dev
= crtc
->dev
;
2950 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2951 unsigned long flags
;
2954 if (atomic_read(&dev_priv
->mm
.wedged
))
2957 spin_lock_irqsave(&dev
->event_lock
, flags
);
2958 pending
= to_intel_crtc(crtc
)->unpin_work
!= NULL
;
2959 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2964 static void intel_crtc_wait_for_pending_flips(struct drm_crtc
*crtc
)
2966 struct drm_device
*dev
= crtc
->dev
;
2967 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2969 if (crtc
->fb
== NULL
)
2972 wait_event(dev_priv
->pending_flip_queue
,
2973 !intel_crtc_has_pending_flip(crtc
));
2975 mutex_lock(&dev
->struct_mutex
);
2976 intel_finish_fb(crtc
->fb
);
2977 mutex_unlock(&dev
->struct_mutex
);
2980 static bool ironlake_crtc_driving_pch(struct drm_crtc
*crtc
)
2982 struct drm_device
*dev
= crtc
->dev
;
2983 struct intel_encoder
*intel_encoder
;
2986 * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
2987 * must be driven by its own crtc; no sharing is possible.
2989 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
2990 switch (intel_encoder
->type
) {
2991 case INTEL_OUTPUT_EDP
:
2992 if (!intel_encoder_is_pch_edp(&intel_encoder
->base
))
3001 static bool haswell_crtc_driving_pch(struct drm_crtc
*crtc
)
3003 return intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
);
3006 /* Program iCLKIP clock to the desired frequency */
3007 static void lpt_program_iclkip(struct drm_crtc
*crtc
)
3009 struct drm_device
*dev
= crtc
->dev
;
3010 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3011 u32 divsel
, phaseinc
, auxdiv
, phasedir
= 0;
3014 /* It is necessary to ungate the pixclk gate prior to programming
3015 * the divisors, and gate it back when it is done.
3017 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_GATE
);
3019 /* Disable SSCCTL */
3020 intel_sbi_write(dev_priv
, SBI_SSCCTL6
,
3021 intel_sbi_read(dev_priv
, SBI_SSCCTL6
) |
3022 SBI_SSCCTL_DISABLE
);
3024 /* 20MHz is a corner case which is out of range for the 7-bit divisor */
3025 if (crtc
->mode
.clock
== 20000) {
3030 /* The iCLK virtual clock root frequency is in MHz,
3031 * but the crtc->mode.clock in in KHz. To get the divisors,
3032 * it is necessary to divide one by another, so we
3033 * convert the virtual clock precision to KHz here for higher
3036 u32 iclk_virtual_root_freq
= 172800 * 1000;
3037 u32 iclk_pi_range
= 64;
3038 u32 desired_divisor
, msb_divisor_value
, pi_value
;
3040 desired_divisor
= (iclk_virtual_root_freq
/ crtc
->mode
.clock
);
3041 msb_divisor_value
= desired_divisor
/ iclk_pi_range
;
3042 pi_value
= desired_divisor
% iclk_pi_range
;
3045 divsel
= msb_divisor_value
- 2;
3046 phaseinc
= pi_value
;
3049 /* This should not happen with any sane values */
3050 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel
) &
3051 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
);
3052 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir
) &
3053 ~SBI_SSCDIVINTPHASE_INCVAL_MASK
);
3055 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3062 /* Program SSCDIVINTPHASE6 */
3063 temp
= intel_sbi_read(dev_priv
, SBI_SSCDIVINTPHASE6
);
3064 temp
&= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK
;
3065 temp
|= SBI_SSCDIVINTPHASE_DIVSEL(divsel
);
3066 temp
&= ~SBI_SSCDIVINTPHASE_INCVAL_MASK
;
3067 temp
|= SBI_SSCDIVINTPHASE_INCVAL(phaseinc
);
3068 temp
|= SBI_SSCDIVINTPHASE_DIR(phasedir
);
3069 temp
|= SBI_SSCDIVINTPHASE_PROPAGATE
;
3071 intel_sbi_write(dev_priv
,
3072 SBI_SSCDIVINTPHASE6
,
3075 /* Program SSCAUXDIV */
3076 temp
= intel_sbi_read(dev_priv
, SBI_SSCAUXDIV6
);
3077 temp
&= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3078 temp
|= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv
);
3079 intel_sbi_write(dev_priv
,
3084 /* Enable modulator and associated divider */
3085 temp
= intel_sbi_read(dev_priv
, SBI_SSCCTL6
);
3086 temp
&= ~SBI_SSCCTL_DISABLE
;
3087 intel_sbi_write(dev_priv
,
3091 /* Wait for initialization time */
3094 I915_WRITE(PIXCLK_GATE
, PIXCLK_GATE_UNGATE
);
3098 * Enable PCH resources required for PCH ports:
3100 * - FDI training & RX/TX
3101 * - update transcoder timings
3102 * - DP transcoding bits
3105 static void ironlake_pch_enable(struct drm_crtc
*crtc
)
3107 struct drm_device
*dev
= crtc
->dev
;
3108 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3109 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3110 int pipe
= intel_crtc
->pipe
;
3113 assert_transcoder_disabled(dev_priv
, pipe
);
3115 /* Write the TU size bits before fdi link training, so that error
3116 * detection works. */
3117 I915_WRITE(FDI_RX_TUSIZE1(pipe
),
3118 I915_READ(PIPE_DATA_M1(pipe
)) & TU_SIZE_MASK
);
3120 /* For PCH output, training FDI link */
3121 dev_priv
->display
.fdi_link_train(crtc
);
3123 /* XXX: pch pll's can be enabled any time before we enable the PCH
3124 * transcoder, and we actually should do this to not upset any PCH
3125 * transcoder that already use the clock when we share it.
3127 * Note that enable_pch_pll tries to do the right thing, but get_pch_pll
3128 * unconditionally resets the pll - we need that to have the right LVDS
3129 * enable sequence. */
3130 ironlake_enable_pch_pll(intel_crtc
);
3132 if (HAS_PCH_CPT(dev
)) {
3135 temp
= I915_READ(PCH_DPLL_SEL
);
3139 temp
|= TRANSA_DPLL_ENABLE
;
3140 sel
= TRANSA_DPLLB_SEL
;
3143 temp
|= TRANSB_DPLL_ENABLE
;
3144 sel
= TRANSB_DPLLB_SEL
;
3147 temp
|= TRANSC_DPLL_ENABLE
;
3148 sel
= TRANSC_DPLLB_SEL
;
3151 if (intel_crtc
->pch_pll
->pll_reg
== _PCH_DPLL_B
)
3155 I915_WRITE(PCH_DPLL_SEL
, temp
);
3158 /* set transcoder timing, panel must allow it */
3159 assert_panel_unlocked(dev_priv
, pipe
);
3160 I915_WRITE(TRANS_HTOTAL(pipe
), I915_READ(HTOTAL(pipe
)));
3161 I915_WRITE(TRANS_HBLANK(pipe
), I915_READ(HBLANK(pipe
)));
3162 I915_WRITE(TRANS_HSYNC(pipe
), I915_READ(HSYNC(pipe
)));
3164 I915_WRITE(TRANS_VTOTAL(pipe
), I915_READ(VTOTAL(pipe
)));
3165 I915_WRITE(TRANS_VBLANK(pipe
), I915_READ(VBLANK(pipe
)));
3166 I915_WRITE(TRANS_VSYNC(pipe
), I915_READ(VSYNC(pipe
)));
3167 I915_WRITE(TRANS_VSYNCSHIFT(pipe
), I915_READ(VSYNCSHIFT(pipe
)));
3169 intel_fdi_normal_train(crtc
);
3171 /* For PCH DP, enable TRANS_DP_CTL */
3172 if (HAS_PCH_CPT(dev
) &&
3173 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
) ||
3174 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3175 u32 bpc
= (I915_READ(PIPECONF(pipe
)) & PIPE_BPC_MASK
) >> 5;
3176 reg
= TRANS_DP_CTL(pipe
);
3177 temp
= I915_READ(reg
);
3178 temp
&= ~(TRANS_DP_PORT_SEL_MASK
|
3179 TRANS_DP_SYNC_MASK
|
3181 temp
|= (TRANS_DP_OUTPUT_ENABLE
|
3182 TRANS_DP_ENH_FRAMING
);
3183 temp
|= bpc
<< 9; /* same format but at 11:9 */
3185 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
3186 temp
|= TRANS_DP_HSYNC_ACTIVE_HIGH
;
3187 if (crtc
->mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
3188 temp
|= TRANS_DP_VSYNC_ACTIVE_HIGH
;
3190 switch (intel_trans_dp_port_sel(crtc
)) {
3192 temp
|= TRANS_DP_PORT_SEL_B
;
3195 temp
|= TRANS_DP_PORT_SEL_C
;
3198 temp
|= TRANS_DP_PORT_SEL_D
;
3204 I915_WRITE(reg
, temp
);
3207 ironlake_enable_pch_transcoder(dev_priv
, pipe
);
3210 static void lpt_pch_enable(struct drm_crtc
*crtc
)
3212 struct drm_device
*dev
= crtc
->dev
;
3213 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3214 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3215 enum transcoder cpu_transcoder
= intel_crtc
->cpu_transcoder
;
3217 assert_transcoder_disabled(dev_priv
, TRANSCODER_A
);
3219 lpt_program_iclkip(crtc
);
3221 /* Set transcoder timing. */
3222 I915_WRITE(_TRANS_HTOTAL_A
, I915_READ(HTOTAL(cpu_transcoder
)));
3223 I915_WRITE(_TRANS_HBLANK_A
, I915_READ(HBLANK(cpu_transcoder
)));
3224 I915_WRITE(_TRANS_HSYNC_A
, I915_READ(HSYNC(cpu_transcoder
)));
3226 I915_WRITE(_TRANS_VTOTAL_A
, I915_READ(VTOTAL(cpu_transcoder
)));
3227 I915_WRITE(_TRANS_VBLANK_A
, I915_READ(VBLANK(cpu_transcoder
)));
3228 I915_WRITE(_TRANS_VSYNC_A
, I915_READ(VSYNC(cpu_transcoder
)));
3229 I915_WRITE(_TRANS_VSYNCSHIFT_A
, I915_READ(VSYNCSHIFT(cpu_transcoder
)));
3231 lpt_enable_pch_transcoder(dev_priv
, cpu_transcoder
);
3234 static void intel_put_pch_pll(struct intel_crtc
*intel_crtc
)
3236 struct intel_pch_pll
*pll
= intel_crtc
->pch_pll
;
3241 if (pll
->refcount
== 0) {
3242 WARN(1, "bad PCH PLL refcount\n");
3247 intel_crtc
->pch_pll
= NULL
;
3250 static struct intel_pch_pll
*intel_get_pch_pll(struct intel_crtc
*intel_crtc
, u32 dpll
, u32 fp
)
3252 struct drm_i915_private
*dev_priv
= intel_crtc
->base
.dev
->dev_private
;
3253 struct intel_pch_pll
*pll
;
3256 pll
= intel_crtc
->pch_pll
;
3258 DRM_DEBUG_KMS("CRTC:%d reusing existing PCH PLL %x\n",
3259 intel_crtc
->base
.base
.id
, pll
->pll_reg
);
3263 if (HAS_PCH_IBX(dev_priv
->dev
)) {
3264 /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
3265 i
= intel_crtc
->pipe
;
3266 pll
= &dev_priv
->pch_plls
[i
];
3268 DRM_DEBUG_KMS("CRTC:%d using pre-allocated PCH PLL %x\n",
3269 intel_crtc
->base
.base
.id
, pll
->pll_reg
);
3274 for (i
= 0; i
< dev_priv
->num_pch_pll
; i
++) {
3275 pll
= &dev_priv
->pch_plls
[i
];
3277 /* Only want to check enabled timings first */
3278 if (pll
->refcount
== 0)
3281 if (dpll
== (I915_READ(pll
->pll_reg
) & 0x7fffffff) &&
3282 fp
== I915_READ(pll
->fp0_reg
)) {
3283 DRM_DEBUG_KMS("CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n",
3284 intel_crtc
->base
.base
.id
,
3285 pll
->pll_reg
, pll
->refcount
, pll
->active
);
3291 /* Ok no matching timings, maybe there's a free one? */
3292 for (i
= 0; i
< dev_priv
->num_pch_pll
; i
++) {
3293 pll
= &dev_priv
->pch_plls
[i
];
3294 if (pll
->refcount
== 0) {
3295 DRM_DEBUG_KMS("CRTC:%d allocated PCH PLL %x\n",
3296 intel_crtc
->base
.base
.id
, pll
->pll_reg
);
3304 intel_crtc
->pch_pll
= pll
;
3306 DRM_DEBUG_DRIVER("using pll %d for pipe %d\n", i
, intel_crtc
->pipe
);
3307 prepare
: /* separate function? */
3308 DRM_DEBUG_DRIVER("switching PLL %x off\n", pll
->pll_reg
);
3310 /* Wait for the clocks to stabilize before rewriting the regs */
3311 I915_WRITE(pll
->pll_reg
, dpll
& ~DPLL_VCO_ENABLE
);
3312 POSTING_READ(pll
->pll_reg
);
3315 I915_WRITE(pll
->fp0_reg
, fp
);
3316 I915_WRITE(pll
->pll_reg
, dpll
& ~DPLL_VCO_ENABLE
);
3321 void intel_cpt_verify_modeset(struct drm_device
*dev
, int pipe
)
3323 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3324 int dslreg
= PIPEDSL(pipe
);
3327 temp
= I915_READ(dslreg
);
3329 if (wait_for(I915_READ(dslreg
) != temp
, 5)) {
3330 if (wait_for(I915_READ(dslreg
) != temp
, 5))
3331 DRM_ERROR("mode set failed: pipe %d stuck\n", pipe
);
3335 static void ironlake_crtc_enable(struct drm_crtc
*crtc
)
3337 struct drm_device
*dev
= crtc
->dev
;
3338 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3339 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3340 struct intel_encoder
*encoder
;
3341 int pipe
= intel_crtc
->pipe
;
3342 int plane
= intel_crtc
->plane
;
3346 WARN_ON(!crtc
->enabled
);
3348 if (intel_crtc
->active
)
3351 intel_crtc
->active
= true;
3352 intel_update_watermarks(dev
);
3354 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
3355 temp
= I915_READ(PCH_LVDS
);
3356 if ((temp
& LVDS_PORT_EN
) == 0)
3357 I915_WRITE(PCH_LVDS
, temp
| LVDS_PORT_EN
);
3360 is_pch_port
= ironlake_crtc_driving_pch(crtc
);
3363 /* Note: FDI PLL enabling _must_ be done before we enable the
3364 * cpu pipes, hence this is separate from all the other fdi/pch
3366 ironlake_fdi_pll_enable(intel_crtc
);
3368 assert_fdi_tx_disabled(dev_priv
, pipe
);
3369 assert_fdi_rx_disabled(dev_priv
, pipe
);
3372 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3373 if (encoder
->pre_enable
)
3374 encoder
->pre_enable(encoder
);
3376 /* Enable panel fitting for LVDS */
3377 if (dev_priv
->pch_pf_size
&&
3378 (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) ||
3379 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
))) {
3380 /* Force use of hard-coded filter coefficients
3381 * as some pre-programmed values are broken,
3384 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
3385 I915_WRITE(PF_WIN_POS(pipe
), dev_priv
->pch_pf_pos
);
3386 I915_WRITE(PF_WIN_SZ(pipe
), dev_priv
->pch_pf_size
);
3390 * On ILK+ LUT must be loaded before the pipe is running but with
3393 intel_crtc_load_lut(crtc
);
3395 intel_enable_pipe(dev_priv
, pipe
, is_pch_port
);
3396 intel_enable_plane(dev_priv
, plane
, pipe
);
3399 ironlake_pch_enable(crtc
);
3401 mutex_lock(&dev
->struct_mutex
);
3402 intel_update_fbc(dev
);
3403 mutex_unlock(&dev
->struct_mutex
);
3405 intel_crtc_update_cursor(crtc
, true);
3407 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3408 encoder
->enable(encoder
);
3410 if (HAS_PCH_CPT(dev
))
3411 intel_cpt_verify_modeset(dev
, intel_crtc
->pipe
);
3414 * There seems to be a race in PCH platform hw (at least on some
3415 * outputs) where an enabled pipe still completes any pageflip right
3416 * away (as if the pipe is off) instead of waiting for vblank. As soon
3417 * as the first vblank happend, everything works as expected. Hence just
3418 * wait for one vblank before returning to avoid strange things
3421 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
3424 static void haswell_crtc_enable(struct drm_crtc
*crtc
)
3426 struct drm_device
*dev
= crtc
->dev
;
3427 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3428 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3429 struct intel_encoder
*encoder
;
3430 int pipe
= intel_crtc
->pipe
;
3431 int plane
= intel_crtc
->plane
;
3434 WARN_ON(!crtc
->enabled
);
3436 if (intel_crtc
->active
)
3439 intel_crtc
->active
= true;
3440 intel_update_watermarks(dev
);
3442 is_pch_port
= haswell_crtc_driving_pch(crtc
);
3445 dev_priv
->display
.fdi_link_train(crtc
);
3447 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3448 if (encoder
->pre_enable
)
3449 encoder
->pre_enable(encoder
);
3451 intel_ddi_enable_pipe_clock(intel_crtc
);
3453 /* Enable panel fitting for eDP */
3454 if (dev_priv
->pch_pf_size
&&
3455 intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
)) {
3456 /* Force use of hard-coded filter coefficients
3457 * as some pre-programmed values are broken,
3460 I915_WRITE(PF_CTL(pipe
), PF_ENABLE
| PF_FILTER_MED_3x3
);
3461 I915_WRITE(PF_WIN_POS(pipe
), dev_priv
->pch_pf_pos
);
3462 I915_WRITE(PF_WIN_SZ(pipe
), dev_priv
->pch_pf_size
);
3466 * On ILK+ LUT must be loaded before the pipe is running but with
3469 intel_crtc_load_lut(crtc
);
3471 intel_ddi_set_pipe_settings(crtc
);
3472 intel_ddi_enable_pipe_func(crtc
);
3474 intel_enable_pipe(dev_priv
, pipe
, is_pch_port
);
3475 intel_enable_plane(dev_priv
, plane
, pipe
);
3478 lpt_pch_enable(crtc
);
3480 mutex_lock(&dev
->struct_mutex
);
3481 intel_update_fbc(dev
);
3482 mutex_unlock(&dev
->struct_mutex
);
3484 intel_crtc_update_cursor(crtc
, true);
3486 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3487 encoder
->enable(encoder
);
3490 * There seems to be a race in PCH platform hw (at least on some
3491 * outputs) where an enabled pipe still completes any pageflip right
3492 * away (as if the pipe is off) instead of waiting for vblank. As soon
3493 * as the first vblank happend, everything works as expected. Hence just
3494 * wait for one vblank before returning to avoid strange things
3497 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
3500 static void ironlake_crtc_disable(struct drm_crtc
*crtc
)
3502 struct drm_device
*dev
= crtc
->dev
;
3503 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3504 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3505 struct intel_encoder
*encoder
;
3506 int pipe
= intel_crtc
->pipe
;
3507 int plane
= intel_crtc
->plane
;
3511 if (!intel_crtc
->active
)
3514 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3515 encoder
->disable(encoder
);
3517 intel_crtc_wait_for_pending_flips(crtc
);
3518 drm_vblank_off(dev
, pipe
);
3519 intel_crtc_update_cursor(crtc
, false);
3521 intel_disable_plane(dev_priv
, plane
, pipe
);
3523 if (dev_priv
->cfb_plane
== plane
)
3524 intel_disable_fbc(dev
);
3526 intel_disable_pipe(dev_priv
, pipe
);
3529 I915_WRITE(PF_CTL(pipe
), 0);
3530 I915_WRITE(PF_WIN_SZ(pipe
), 0);
3532 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3533 if (encoder
->post_disable
)
3534 encoder
->post_disable(encoder
);
3536 ironlake_fdi_disable(crtc
);
3538 ironlake_disable_pch_transcoder(dev_priv
, pipe
);
3540 if (HAS_PCH_CPT(dev
)) {
3541 /* disable TRANS_DP_CTL */
3542 reg
= TRANS_DP_CTL(pipe
);
3543 temp
= I915_READ(reg
);
3544 temp
&= ~(TRANS_DP_OUTPUT_ENABLE
| TRANS_DP_PORT_SEL_MASK
);
3545 temp
|= TRANS_DP_PORT_SEL_NONE
;
3546 I915_WRITE(reg
, temp
);
3548 /* disable DPLL_SEL */
3549 temp
= I915_READ(PCH_DPLL_SEL
);
3552 temp
&= ~(TRANSA_DPLL_ENABLE
| TRANSA_DPLLB_SEL
);
3555 temp
&= ~(TRANSB_DPLL_ENABLE
| TRANSB_DPLLB_SEL
);
3558 /* C shares PLL A or B */
3559 temp
&= ~(TRANSC_DPLL_ENABLE
| TRANSC_DPLLB_SEL
);
3564 I915_WRITE(PCH_DPLL_SEL
, temp
);
3567 /* disable PCH DPLL */
3568 intel_disable_pch_pll(intel_crtc
);
3570 ironlake_fdi_pll_disable(intel_crtc
);
3572 intel_crtc
->active
= false;
3573 intel_update_watermarks(dev
);
3575 mutex_lock(&dev
->struct_mutex
);
3576 intel_update_fbc(dev
);
3577 mutex_unlock(&dev
->struct_mutex
);
3580 static void haswell_crtc_disable(struct drm_crtc
*crtc
)
3582 struct drm_device
*dev
= crtc
->dev
;
3583 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3584 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3585 struct intel_encoder
*encoder
;
3586 int pipe
= intel_crtc
->pipe
;
3587 int plane
= intel_crtc
->plane
;
3588 enum transcoder cpu_transcoder
= intel_crtc
->cpu_transcoder
;
3591 if (!intel_crtc
->active
)
3594 is_pch_port
= haswell_crtc_driving_pch(crtc
);
3596 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3597 encoder
->disable(encoder
);
3599 intel_crtc_wait_for_pending_flips(crtc
);
3600 drm_vblank_off(dev
, pipe
);
3601 intel_crtc_update_cursor(crtc
, false);
3603 intel_disable_plane(dev_priv
, plane
, pipe
);
3605 if (dev_priv
->cfb_plane
== plane
)
3606 intel_disable_fbc(dev
);
3608 intel_disable_pipe(dev_priv
, pipe
);
3610 intel_ddi_disable_transcoder_func(dev_priv
, cpu_transcoder
);
3613 I915_WRITE(PF_CTL(pipe
), 0);
3614 I915_WRITE(PF_WIN_SZ(pipe
), 0);
3616 intel_ddi_disable_pipe_clock(intel_crtc
);
3618 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3619 if (encoder
->post_disable
)
3620 encoder
->post_disable(encoder
);
3623 lpt_disable_pch_transcoder(dev_priv
);
3624 intel_ddi_fdi_disable(crtc
);
3627 intel_crtc
->active
= false;
3628 intel_update_watermarks(dev
);
3630 mutex_lock(&dev
->struct_mutex
);
3631 intel_update_fbc(dev
);
3632 mutex_unlock(&dev
->struct_mutex
);
3635 static void ironlake_crtc_off(struct drm_crtc
*crtc
)
3637 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3638 intel_put_pch_pll(intel_crtc
);
3641 static void haswell_crtc_off(struct drm_crtc
*crtc
)
3643 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3645 /* Stop saying we're using TRANSCODER_EDP because some other CRTC might
3646 * start using it. */
3647 intel_crtc
->cpu_transcoder
= intel_crtc
->pipe
;
3649 intel_ddi_put_crtc_pll(crtc
);
3652 static void intel_crtc_dpms_overlay(struct intel_crtc
*intel_crtc
, bool enable
)
3654 if (!enable
&& intel_crtc
->overlay
) {
3655 struct drm_device
*dev
= intel_crtc
->base
.dev
;
3656 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3658 mutex_lock(&dev
->struct_mutex
);
3659 dev_priv
->mm
.interruptible
= false;
3660 (void) intel_overlay_switch_off(intel_crtc
->overlay
);
3661 dev_priv
->mm
.interruptible
= true;
3662 mutex_unlock(&dev
->struct_mutex
);
3665 /* Let userspace switch the overlay on again. In most cases userspace
3666 * has to recompute where to put it anyway.
3670 static void i9xx_crtc_enable(struct drm_crtc
*crtc
)
3672 struct drm_device
*dev
= crtc
->dev
;
3673 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3674 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3675 struct intel_encoder
*encoder
;
3676 int pipe
= intel_crtc
->pipe
;
3677 int plane
= intel_crtc
->plane
;
3679 WARN_ON(!crtc
->enabled
);
3681 if (intel_crtc
->active
)
3684 intel_crtc
->active
= true;
3685 intel_update_watermarks(dev
);
3687 intel_enable_pll(dev_priv
, pipe
);
3688 intel_enable_pipe(dev_priv
, pipe
, false);
3689 intel_enable_plane(dev_priv
, plane
, pipe
);
3691 intel_crtc_load_lut(crtc
);
3692 intel_update_fbc(dev
);
3694 /* Give the overlay scaler a chance to enable if it's on this pipe */
3695 intel_crtc_dpms_overlay(intel_crtc
, true);
3696 intel_crtc_update_cursor(crtc
, true);
3698 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3699 encoder
->enable(encoder
);
3702 static void i9xx_crtc_disable(struct drm_crtc
*crtc
)
3704 struct drm_device
*dev
= crtc
->dev
;
3705 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3706 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3707 struct intel_encoder
*encoder
;
3708 int pipe
= intel_crtc
->pipe
;
3709 int plane
= intel_crtc
->plane
;
3712 if (!intel_crtc
->active
)
3715 for_each_encoder_on_crtc(dev
, crtc
, encoder
)
3716 encoder
->disable(encoder
);
3718 /* Give the overlay scaler a chance to disable if it's on this pipe */
3719 intel_crtc_wait_for_pending_flips(crtc
);
3720 drm_vblank_off(dev
, pipe
);
3721 intel_crtc_dpms_overlay(intel_crtc
, false);
3722 intel_crtc_update_cursor(crtc
, false);
3724 if (dev_priv
->cfb_plane
== plane
)
3725 intel_disable_fbc(dev
);
3727 intel_disable_plane(dev_priv
, plane
, pipe
);
3728 intel_disable_pipe(dev_priv
, pipe
);
3729 intel_disable_pll(dev_priv
, pipe
);
3731 intel_crtc
->active
= false;
3732 intel_update_fbc(dev
);
3733 intel_update_watermarks(dev
);
3736 static void i9xx_crtc_off(struct drm_crtc
*crtc
)
3740 static void intel_crtc_update_sarea(struct drm_crtc
*crtc
,
3743 struct drm_device
*dev
= crtc
->dev
;
3744 struct drm_i915_master_private
*master_priv
;
3745 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
3746 int pipe
= intel_crtc
->pipe
;
3748 if (!dev
->primary
->master
)
3751 master_priv
= dev
->primary
->master
->driver_priv
;
3752 if (!master_priv
->sarea_priv
)
3757 master_priv
->sarea_priv
->pipeA_w
= enabled
? crtc
->mode
.hdisplay
: 0;
3758 master_priv
->sarea_priv
->pipeA_h
= enabled
? crtc
->mode
.vdisplay
: 0;
3761 master_priv
->sarea_priv
->pipeB_w
= enabled
? crtc
->mode
.hdisplay
: 0;
3762 master_priv
->sarea_priv
->pipeB_h
= enabled
? crtc
->mode
.vdisplay
: 0;
3765 DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe
));
3771 * Sets the power management mode of the pipe and plane.
3773 void intel_crtc_update_dpms(struct drm_crtc
*crtc
)
3775 struct drm_device
*dev
= crtc
->dev
;
3776 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3777 struct intel_encoder
*intel_encoder
;
3778 bool enable
= false;
3780 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
)
3781 enable
|= intel_encoder
->connectors_active
;
3784 dev_priv
->display
.crtc_enable(crtc
);
3786 dev_priv
->display
.crtc_disable(crtc
);
3788 intel_crtc_update_sarea(crtc
, enable
);
3791 static void intel_crtc_noop(struct drm_crtc
*crtc
)
3795 static void intel_crtc_disable(struct drm_crtc
*crtc
)
3797 struct drm_device
*dev
= crtc
->dev
;
3798 struct drm_connector
*connector
;
3799 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3801 /* crtc should still be enabled when we disable it. */
3802 WARN_ON(!crtc
->enabled
);
3804 dev_priv
->display
.crtc_disable(crtc
);
3805 intel_crtc_update_sarea(crtc
, false);
3806 dev_priv
->display
.off(crtc
);
3808 assert_plane_disabled(dev
->dev_private
, to_intel_crtc(crtc
)->plane
);
3809 assert_pipe_disabled(dev
->dev_private
, to_intel_crtc(crtc
)->pipe
);
3812 mutex_lock(&dev
->struct_mutex
);
3813 intel_unpin_fb_obj(to_intel_framebuffer(crtc
->fb
)->obj
);
3814 mutex_unlock(&dev
->struct_mutex
);
3818 /* Update computed state. */
3819 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
3820 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
3823 if (connector
->encoder
->crtc
!= crtc
)
3826 connector
->dpms
= DRM_MODE_DPMS_OFF
;
3827 to_intel_encoder(connector
->encoder
)->connectors_active
= false;
3831 void intel_modeset_disable(struct drm_device
*dev
)
3833 struct drm_crtc
*crtc
;
3835 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
3837 intel_crtc_disable(crtc
);
3841 void intel_encoder_noop(struct drm_encoder
*encoder
)
3845 void intel_encoder_destroy(struct drm_encoder
*encoder
)
3847 struct intel_encoder
*intel_encoder
= to_intel_encoder(encoder
);
3849 drm_encoder_cleanup(encoder
);
3850 kfree(intel_encoder
);
3853 /* Simple dpms helper for encodres with just one connector, no cloning and only
3854 * one kind of off state. It clamps all !ON modes to fully OFF and changes the
3855 * state of the entire output pipe. */
3856 void intel_encoder_dpms(struct intel_encoder
*encoder
, int mode
)
3858 if (mode
== DRM_MODE_DPMS_ON
) {
3859 encoder
->connectors_active
= true;
3861 intel_crtc_update_dpms(encoder
->base
.crtc
);
3863 encoder
->connectors_active
= false;
3865 intel_crtc_update_dpms(encoder
->base
.crtc
);
3869 /* Cross check the actual hw state with our own modeset state tracking (and it's
3870 * internal consistency). */
3871 static void intel_connector_check_state(struct intel_connector
*connector
)
3873 if (connector
->get_hw_state(connector
)) {
3874 struct intel_encoder
*encoder
= connector
->encoder
;
3875 struct drm_crtc
*crtc
;
3876 bool encoder_enabled
;
3879 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
3880 connector
->base
.base
.id
,
3881 drm_get_connector_name(&connector
->base
));
3883 WARN(connector
->base
.dpms
== DRM_MODE_DPMS_OFF
,
3884 "wrong connector dpms state\n");
3885 WARN(connector
->base
.encoder
!= &encoder
->base
,
3886 "active connector not linked to encoder\n");
3887 WARN(!encoder
->connectors_active
,
3888 "encoder->connectors_active not set\n");
3890 encoder_enabled
= encoder
->get_hw_state(encoder
, &pipe
);
3891 WARN(!encoder_enabled
, "encoder not enabled\n");
3892 if (WARN_ON(!encoder
->base
.crtc
))
3895 crtc
= encoder
->base
.crtc
;
3897 WARN(!crtc
->enabled
, "crtc not enabled\n");
3898 WARN(!to_intel_crtc(crtc
)->active
, "crtc not active\n");
3899 WARN(pipe
!= to_intel_crtc(crtc
)->pipe
,
3900 "encoder active on the wrong pipe\n");
3904 /* Even simpler default implementation, if there's really no special case to
3906 void intel_connector_dpms(struct drm_connector
*connector
, int mode
)
3908 struct intel_encoder
*encoder
= intel_attached_encoder(connector
);
3910 /* All the simple cases only support two dpms states. */
3911 if (mode
!= DRM_MODE_DPMS_ON
)
3912 mode
= DRM_MODE_DPMS_OFF
;
3914 if (mode
== connector
->dpms
)
3917 connector
->dpms
= mode
;
3919 /* Only need to change hw state when actually enabled */
3920 if (encoder
->base
.crtc
)
3921 intel_encoder_dpms(encoder
, mode
);
3923 WARN_ON(encoder
->connectors_active
!= false);
3925 intel_modeset_check_state(connector
->dev
);
3928 /* Simple connector->get_hw_state implementation for encoders that support only
3929 * one connector and no cloning and hence the encoder state determines the state
3930 * of the connector. */
3931 bool intel_connector_get_hw_state(struct intel_connector
*connector
)
3934 struct intel_encoder
*encoder
= connector
->encoder
;
3936 return encoder
->get_hw_state(encoder
, &pipe
);
3939 static bool intel_crtc_mode_fixup(struct drm_crtc
*crtc
,
3940 const struct drm_display_mode
*mode
,
3941 struct drm_display_mode
*adjusted_mode
)
3943 struct drm_device
*dev
= crtc
->dev
;
3945 if (HAS_PCH_SPLIT(dev
)) {
3946 /* FDI link clock is fixed at 2.7G */
3947 if (mode
->clock
* 3 > IRONLAKE_FDI_FREQ
* 4)
3951 /* All interlaced capable intel hw wants timings in frames. Note though
3952 * that intel_lvds_mode_fixup does some funny tricks with the crtc
3953 * timings, so we need to be careful not to clobber these.*/
3954 if (!(adjusted_mode
->private_flags
& INTEL_MODE_CRTC_TIMINGS_SET
))
3955 drm_mode_set_crtcinfo(adjusted_mode
, 0);
3957 /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
3958 * with a hsync front porch of 0.
3960 if ((INTEL_INFO(dev
)->gen
> 4 || IS_G4X(dev
)) &&
3961 adjusted_mode
->hsync_start
== adjusted_mode
->hdisplay
)
3967 static int valleyview_get_display_clock_speed(struct drm_device
*dev
)
3969 return 400000; /* FIXME */
3972 static int i945_get_display_clock_speed(struct drm_device
*dev
)
3977 static int i915_get_display_clock_speed(struct drm_device
*dev
)
3982 static int i9xx_misc_get_display_clock_speed(struct drm_device
*dev
)
3987 static int i915gm_get_display_clock_speed(struct drm_device
*dev
)
3991 pci_read_config_word(dev
->pdev
, GCFGC
, &gcfgc
);
3993 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
)
3996 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
3997 case GC_DISPLAY_CLOCK_333_MHZ
:
4000 case GC_DISPLAY_CLOCK_190_200_MHZ
:
4006 static int i865_get_display_clock_speed(struct drm_device
*dev
)
4011 static int i855_get_display_clock_speed(struct drm_device
*dev
)
4014 /* Assume that the hardware is in the high speed state. This
4015 * should be the default.
4017 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
4018 case GC_CLOCK_133_200
:
4019 case GC_CLOCK_100_200
:
4021 case GC_CLOCK_166_250
:
4023 case GC_CLOCK_100_133
:
4027 /* Shouldn't happen */
4031 static int i830_get_display_clock_speed(struct drm_device
*dev
)
4045 fdi_reduce_ratio(u32
*num
, u32
*den
)
4047 while (*num
> 0xffffff || *den
> 0xffffff) {
4054 ironlake_compute_m_n(int bits_per_pixel
, int nlanes
, int pixel_clock
,
4055 int link_clock
, struct fdi_m_n
*m_n
)
4057 m_n
->tu
= 64; /* default size */
4059 /* BUG_ON(pixel_clock > INT_MAX / 36); */
4060 m_n
->gmch_m
= bits_per_pixel
* pixel_clock
;
4061 m_n
->gmch_n
= link_clock
* nlanes
* 8;
4062 fdi_reduce_ratio(&m_n
->gmch_m
, &m_n
->gmch_n
);
4064 m_n
->link_m
= pixel_clock
;
4065 m_n
->link_n
= link_clock
;
4066 fdi_reduce_ratio(&m_n
->link_m
, &m_n
->link_n
);
4069 static inline bool intel_panel_use_ssc(struct drm_i915_private
*dev_priv
)
4071 if (i915_panel_use_ssc
>= 0)
4072 return i915_panel_use_ssc
!= 0;
4073 return dev_priv
->lvds_use_ssc
4074 && !(dev_priv
->quirks
& QUIRK_LVDS_SSC_DISABLE
);
4078 * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
4079 * @crtc: CRTC structure
4080 * @mode: requested mode
4082 * A pipe may be connected to one or more outputs. Based on the depth of the
4083 * attached framebuffer, choose a good color depth to use on the pipe.
4085 * If possible, match the pipe depth to the fb depth. In some cases, this
4086 * isn't ideal, because the connected output supports a lesser or restricted
4087 * set of depths. Resolve that here:
4088 * LVDS typically supports only 6bpc, so clamp down in that case
4089 * HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
4090 * Displays may support a restricted set as well, check EDID and clamp as
4092 * DP may want to dither down to 6bpc to fit larger modes
4095 * Dithering requirement (i.e. false if display bpc and pipe bpc match,
4096 * true if they don't match).
4098 static bool intel_choose_pipe_bpp_dither(struct drm_crtc
*crtc
,
4099 struct drm_framebuffer
*fb
,
4100 unsigned int *pipe_bpp
,
4101 struct drm_display_mode
*mode
)
4103 struct drm_device
*dev
= crtc
->dev
;
4104 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4105 struct drm_connector
*connector
;
4106 struct intel_encoder
*intel_encoder
;
4107 unsigned int display_bpc
= UINT_MAX
, bpc
;
4109 /* Walk the encoders & connectors on this crtc, get min bpc */
4110 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
4112 if (intel_encoder
->type
== INTEL_OUTPUT_LVDS
) {
4113 unsigned int lvds_bpc
;
4115 if ((I915_READ(PCH_LVDS
) & LVDS_A3_POWER_MASK
) ==
4121 if (lvds_bpc
< display_bpc
) {
4122 DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc
, lvds_bpc
);
4123 display_bpc
= lvds_bpc
;
4128 /* Not one of the known troublemakers, check the EDID */
4129 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
4131 if (connector
->encoder
!= &intel_encoder
->base
)
4134 /* Don't use an invalid EDID bpc value */
4135 if (connector
->display_info
.bpc
&&
4136 connector
->display_info
.bpc
< display_bpc
) {
4137 DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc
, connector
->display_info
.bpc
);
4138 display_bpc
= connector
->display_info
.bpc
;
4143 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
4144 * through, clamp it down. (Note: >12bpc will be caught below.)
4146 if (intel_encoder
->type
== INTEL_OUTPUT_HDMI
) {
4147 if (display_bpc
> 8 && display_bpc
< 12) {
4148 DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
4151 DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
4157 if (mode
->private_flags
& INTEL_MODE_DP_FORCE_6BPC
) {
4158 DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
4163 * We could just drive the pipe at the highest bpc all the time and
4164 * enable dithering as needed, but that costs bandwidth. So choose
4165 * the minimum value that expresses the full color range of the fb but
4166 * also stays within the max display bpc discovered above.
4169 switch (fb
->depth
) {
4171 bpc
= 8; /* since we go through a colormap */
4175 bpc
= 6; /* min is 18bpp */
4187 DRM_DEBUG("unsupported depth, assuming 24 bits\n");
4188 bpc
= min((unsigned int)8, display_bpc
);
4192 display_bpc
= min(display_bpc
, bpc
);
4194 DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
4197 *pipe_bpp
= display_bpc
* 3;
4199 return display_bpc
!= bpc
;
4202 static int vlv_get_refclk(struct drm_crtc
*crtc
)
4204 struct drm_device
*dev
= crtc
->dev
;
4205 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4206 int refclk
= 27000; /* for DP & HDMI */
4208 return 100000; /* only one validated so far */
4210 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_ANALOG
)) {
4212 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
4213 if (intel_panel_use_ssc(dev_priv
))
4217 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
)) {
4224 static int i9xx_get_refclk(struct drm_crtc
*crtc
, int num_connectors
)
4226 struct drm_device
*dev
= crtc
->dev
;
4227 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4230 if (IS_VALLEYVIEW(dev
)) {
4231 refclk
= vlv_get_refclk(crtc
);
4232 } else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
4233 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
4234 refclk
= dev_priv
->lvds_ssc_freq
* 1000;
4235 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
4237 } else if (!IS_GEN2(dev
)) {
4246 static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode
*adjusted_mode
,
4247 intel_clock_t
*clock
)
4249 /* SDVO TV has fixed PLL values depend on its clock range,
4250 this mirrors vbios setting. */
4251 if (adjusted_mode
->clock
>= 100000
4252 && adjusted_mode
->clock
< 140500) {
4258 } else if (adjusted_mode
->clock
>= 140500
4259 && adjusted_mode
->clock
<= 200000) {
4268 static void i9xx_update_pll_dividers(struct drm_crtc
*crtc
,
4269 intel_clock_t
*clock
,
4270 intel_clock_t
*reduced_clock
)
4272 struct drm_device
*dev
= crtc
->dev
;
4273 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4274 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4275 int pipe
= intel_crtc
->pipe
;
4278 if (IS_PINEVIEW(dev
)) {
4279 fp
= (1 << clock
->n
) << 16 | clock
->m1
<< 8 | clock
->m2
;
4281 fp2
= (1 << reduced_clock
->n
) << 16 |
4282 reduced_clock
->m1
<< 8 | reduced_clock
->m2
;
4284 fp
= clock
->n
<< 16 | clock
->m1
<< 8 | clock
->m2
;
4286 fp2
= reduced_clock
->n
<< 16 | reduced_clock
->m1
<< 8 |
4290 I915_WRITE(FP0(pipe
), fp
);
4292 intel_crtc
->lowfreq_avail
= false;
4293 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
4294 reduced_clock
&& i915_powersave
) {
4295 I915_WRITE(FP1(pipe
), fp2
);
4296 intel_crtc
->lowfreq_avail
= true;
4298 I915_WRITE(FP1(pipe
), fp
);
4302 static void intel_update_lvds(struct drm_crtc
*crtc
, intel_clock_t
*clock
,
4303 struct drm_display_mode
*adjusted_mode
)
4305 struct drm_device
*dev
= crtc
->dev
;
4306 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4307 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4308 int pipe
= intel_crtc
->pipe
;
4311 temp
= I915_READ(LVDS
);
4312 temp
|= LVDS_PORT_EN
| LVDS_A0A2_CLKA_POWER_UP
;
4314 temp
|= LVDS_PIPEB_SELECT
;
4316 temp
&= ~LVDS_PIPEB_SELECT
;
4318 /* set the corresponsding LVDS_BORDER bit */
4319 temp
|= dev_priv
->lvds_border_bits
;
4320 /* Set the B0-B3 data pairs corresponding to whether we're going to
4321 * set the DPLLs for dual-channel mode or not.
4324 temp
|= LVDS_B0B3_POWER_UP
| LVDS_CLKB_POWER_UP
;
4326 temp
&= ~(LVDS_B0B3_POWER_UP
| LVDS_CLKB_POWER_UP
);
4328 /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
4329 * appropriately here, but we need to look more thoroughly into how
4330 * panels behave in the two modes.
4332 /* set the dithering flag on LVDS as needed */
4333 if (INTEL_INFO(dev
)->gen
>= 4) {
4334 if (dev_priv
->lvds_dither
)
4335 temp
|= LVDS_ENABLE_DITHER
;
4337 temp
&= ~LVDS_ENABLE_DITHER
;
4339 temp
&= ~(LVDS_HSYNC_POLARITY
| LVDS_VSYNC_POLARITY
);
4340 if (adjusted_mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
4341 temp
|= LVDS_HSYNC_POLARITY
;
4342 if (adjusted_mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
4343 temp
|= LVDS_VSYNC_POLARITY
;
4344 I915_WRITE(LVDS
, temp
);
4347 static void vlv_update_pll(struct drm_crtc
*crtc
,
4348 struct drm_display_mode
*mode
,
4349 struct drm_display_mode
*adjusted_mode
,
4350 intel_clock_t
*clock
, intel_clock_t
*reduced_clock
,
4353 struct drm_device
*dev
= crtc
->dev
;
4354 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4355 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4356 int pipe
= intel_crtc
->pipe
;
4357 u32 dpll
, mdiv
, pdiv
;
4358 u32 bestn
, bestm1
, bestm2
, bestp1
, bestp2
;
4362 is_sdvo
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
) ||
4363 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
);
4365 dpll
= DPLL_VGA_MODE_DIS
;
4366 dpll
|= DPLL_EXT_BUFFER_ENABLE_VLV
;
4367 dpll
|= DPLL_REFA_CLK_ENABLE_VLV
;
4368 dpll
|= DPLL_INTEGRATED_CLOCK_VLV
;
4370 I915_WRITE(DPLL(pipe
), dpll
);
4371 POSTING_READ(DPLL(pipe
));
4380 * In Valleyview PLL and program lane counter registers are exposed
4381 * through DPIO interface
4383 mdiv
= ((bestm1
<< DPIO_M1DIV_SHIFT
) | (bestm2
& DPIO_M2DIV_MASK
));
4384 mdiv
|= ((bestp1
<< DPIO_P1_SHIFT
) | (bestp2
<< DPIO_P2_SHIFT
));
4385 mdiv
|= ((bestn
<< DPIO_N_SHIFT
));
4386 mdiv
|= (1 << DPIO_POST_DIV_SHIFT
);
4387 mdiv
|= (1 << DPIO_K_SHIFT
);
4388 mdiv
|= DPIO_ENABLE_CALIBRATION
;
4389 intel_dpio_write(dev_priv
, DPIO_DIV(pipe
), mdiv
);
4391 intel_dpio_write(dev_priv
, DPIO_CORE_CLK(pipe
), 0x01000000);
4393 pdiv
= (1 << DPIO_REFSEL_OVERRIDE
) | (5 << DPIO_PLL_MODESEL_SHIFT
) |
4394 (3 << DPIO_BIAS_CURRENT_CTL_SHIFT
) | (1<<20) |
4395 (7 << DPIO_PLL_REFCLK_SEL_SHIFT
) | (8 << DPIO_DRIVER_CTL_SHIFT
) |
4396 (5 << DPIO_CLK_BIAS_CTL_SHIFT
);
4397 intel_dpio_write(dev_priv
, DPIO_REFSFR(pipe
), pdiv
);
4399 intel_dpio_write(dev_priv
, DPIO_LFP_COEFF(pipe
), 0x005f003b);
4401 dpll
|= DPLL_VCO_ENABLE
;
4402 I915_WRITE(DPLL(pipe
), dpll
);
4403 POSTING_READ(DPLL(pipe
));
4404 if (wait_for(((I915_READ(DPLL(pipe
)) & DPLL_LOCK_VLV
) == DPLL_LOCK_VLV
), 1))
4405 DRM_ERROR("DPLL %d failed to lock\n", pipe
);
4407 intel_dpio_write(dev_priv
, DPIO_FASTCLK_DISABLE
, 0x620);
4409 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
))
4410 intel_dp_set_m_n(crtc
, mode
, adjusted_mode
);
4412 I915_WRITE(DPLL(pipe
), dpll
);
4414 /* Wait for the clocks to stabilize. */
4415 POSTING_READ(DPLL(pipe
));
4420 temp
= intel_mode_get_pixel_multiplier(adjusted_mode
);
4422 temp
= (temp
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
4426 I915_WRITE(DPLL_MD(pipe
), temp
);
4427 POSTING_READ(DPLL_MD(pipe
));
4429 /* Now program lane control registers */
4430 if(intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)
4431 || intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
))
4436 intel_dpio_write(dev_priv
, DPIO_DATA_CHANNEL1
, temp
);
4438 if(intel_pipe_has_type(crtc
,INTEL_OUTPUT_EDP
))
4443 intel_dpio_write(dev_priv
, DPIO_DATA_CHANNEL2
, temp
);
4447 static void i9xx_update_pll(struct drm_crtc
*crtc
,
4448 struct drm_display_mode
*mode
,
4449 struct drm_display_mode
*adjusted_mode
,
4450 intel_clock_t
*clock
, intel_clock_t
*reduced_clock
,
4453 struct drm_device
*dev
= crtc
->dev
;
4454 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4455 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4456 int pipe
= intel_crtc
->pipe
;
4460 i9xx_update_pll_dividers(crtc
, clock
, reduced_clock
);
4462 is_sdvo
= intel_pipe_has_type(crtc
, INTEL_OUTPUT_SDVO
) ||
4463 intel_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
);
4465 dpll
= DPLL_VGA_MODE_DIS
;
4467 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
4468 dpll
|= DPLLB_MODE_LVDS
;
4470 dpll
|= DPLLB_MODE_DAC_SERIAL
;
4472 int pixel_multiplier
= intel_mode_get_pixel_multiplier(adjusted_mode
);
4473 if (pixel_multiplier
> 1) {
4474 if (IS_I945G(dev
) || IS_I945GM(dev
) || IS_G33(dev
))
4475 dpll
|= (pixel_multiplier
- 1) << SDVO_MULTIPLIER_SHIFT_HIRES
;
4477 dpll
|= DPLL_DVO_HIGH_SPEED
;
4479 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
))
4480 dpll
|= DPLL_DVO_HIGH_SPEED
;
4482 /* compute bitmask from p1 value */
4483 if (IS_PINEVIEW(dev
))
4484 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
;
4486 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
4487 if (IS_G4X(dev
) && reduced_clock
)
4488 dpll
|= (1 << (reduced_clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
4490 switch (clock
->p2
) {
4492 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
4495 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
4498 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
4501 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
4504 if (INTEL_INFO(dev
)->gen
>= 4)
4505 dpll
|= (6 << PLL_LOAD_PULSE_PHASE_SHIFT
);
4507 if (is_sdvo
&& intel_pipe_has_type(crtc
, INTEL_OUTPUT_TVOUT
))
4508 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
4509 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_TVOUT
))
4510 /* XXX: just matching BIOS for now */
4511 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
4513 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
4514 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
4515 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
4517 dpll
|= PLL_REF_INPUT_DREFCLK
;
4519 dpll
|= DPLL_VCO_ENABLE
;
4520 I915_WRITE(DPLL(pipe
), dpll
& ~DPLL_VCO_ENABLE
);
4521 POSTING_READ(DPLL(pipe
));
4524 /* The LVDS pin pair needs to be on before the DPLLs are enabled.
4525 * This is an exception to the general rule that mode_set doesn't turn
4528 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
4529 intel_update_lvds(crtc
, clock
, adjusted_mode
);
4531 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
))
4532 intel_dp_set_m_n(crtc
, mode
, adjusted_mode
);
4534 I915_WRITE(DPLL(pipe
), dpll
);
4536 /* Wait for the clocks to stabilize. */
4537 POSTING_READ(DPLL(pipe
));
4540 if (INTEL_INFO(dev
)->gen
>= 4) {
4543 temp
= intel_mode_get_pixel_multiplier(adjusted_mode
);
4545 temp
= (temp
- 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT
;
4549 I915_WRITE(DPLL_MD(pipe
), temp
);
4551 /* The pixel multiplier can only be updated once the
4552 * DPLL is enabled and the clocks are stable.
4554 * So write it again.
4556 I915_WRITE(DPLL(pipe
), dpll
);
4560 static void i8xx_update_pll(struct drm_crtc
*crtc
,
4561 struct drm_display_mode
*adjusted_mode
,
4562 intel_clock_t
*clock
, intel_clock_t
*reduced_clock
,
4565 struct drm_device
*dev
= crtc
->dev
;
4566 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4567 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4568 int pipe
= intel_crtc
->pipe
;
4571 i9xx_update_pll_dividers(crtc
, clock
, reduced_clock
);
4573 dpll
= DPLL_VGA_MODE_DIS
;
4575 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
)) {
4576 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
4579 dpll
|= PLL_P1_DIVIDE_BY_TWO
;
4581 dpll
|= (clock
->p1
- 2) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
4583 dpll
|= PLL_P2_DIVIDE_BY_4
;
4586 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_TVOUT
))
4587 /* XXX: just matching BIOS for now */
4588 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
4590 else if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
) &&
4591 intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
4592 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
4594 dpll
|= PLL_REF_INPUT_DREFCLK
;
4596 dpll
|= DPLL_VCO_ENABLE
;
4597 I915_WRITE(DPLL(pipe
), dpll
& ~DPLL_VCO_ENABLE
);
4598 POSTING_READ(DPLL(pipe
));
4601 /* The LVDS pin pair needs to be on before the DPLLs are enabled.
4602 * This is an exception to the general rule that mode_set doesn't turn
4605 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_LVDS
))
4606 intel_update_lvds(crtc
, clock
, adjusted_mode
);
4608 I915_WRITE(DPLL(pipe
), dpll
);
4610 /* Wait for the clocks to stabilize. */
4611 POSTING_READ(DPLL(pipe
));
4614 /* The pixel multiplier can only be updated once the
4615 * DPLL is enabled and the clocks are stable.
4617 * So write it again.
4619 I915_WRITE(DPLL(pipe
), dpll
);
4622 static void intel_set_pipe_timings(struct intel_crtc
*intel_crtc
,
4623 struct drm_display_mode
*mode
,
4624 struct drm_display_mode
*adjusted_mode
)
4626 struct drm_device
*dev
= intel_crtc
->base
.dev
;
4627 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4628 enum pipe pipe
= intel_crtc
->pipe
;
4629 enum transcoder cpu_transcoder
= intel_crtc
->cpu_transcoder
;
4630 uint32_t vsyncshift
;
4632 if (!IS_GEN2(dev
) && adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
4633 /* the chip adds 2 halflines automatically */
4634 adjusted_mode
->crtc_vtotal
-= 1;
4635 adjusted_mode
->crtc_vblank_end
-= 1;
4636 vsyncshift
= adjusted_mode
->crtc_hsync_start
4637 - adjusted_mode
->crtc_htotal
/ 2;
4642 if (INTEL_INFO(dev
)->gen
> 3)
4643 I915_WRITE(VSYNCSHIFT(cpu_transcoder
), vsyncshift
);
4645 I915_WRITE(HTOTAL(cpu_transcoder
),
4646 (adjusted_mode
->crtc_hdisplay
- 1) |
4647 ((adjusted_mode
->crtc_htotal
- 1) << 16));
4648 I915_WRITE(HBLANK(cpu_transcoder
),
4649 (adjusted_mode
->crtc_hblank_start
- 1) |
4650 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
4651 I915_WRITE(HSYNC(cpu_transcoder
),
4652 (adjusted_mode
->crtc_hsync_start
- 1) |
4653 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
4655 I915_WRITE(VTOTAL(cpu_transcoder
),
4656 (adjusted_mode
->crtc_vdisplay
- 1) |
4657 ((adjusted_mode
->crtc_vtotal
- 1) << 16));
4658 I915_WRITE(VBLANK(cpu_transcoder
),
4659 (adjusted_mode
->crtc_vblank_start
- 1) |
4660 ((adjusted_mode
->crtc_vblank_end
- 1) << 16));
4661 I915_WRITE(VSYNC(cpu_transcoder
),
4662 (adjusted_mode
->crtc_vsync_start
- 1) |
4663 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
4665 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
4666 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
4667 * documented on the DDI_FUNC_CTL register description, EDP Input Select
4669 if (IS_HASWELL(dev
) && cpu_transcoder
== TRANSCODER_EDP
&&
4670 (pipe
== PIPE_B
|| pipe
== PIPE_C
))
4671 I915_WRITE(VTOTAL(pipe
), I915_READ(VTOTAL(cpu_transcoder
)));
4673 /* pipesrc controls the size that is scaled from, which should
4674 * always be the user's requested size.
4676 I915_WRITE(PIPESRC(pipe
),
4677 ((mode
->hdisplay
- 1) << 16) | (mode
->vdisplay
- 1));
4680 static int i9xx_crtc_mode_set(struct drm_crtc
*crtc
,
4681 struct drm_display_mode
*mode
,
4682 struct drm_display_mode
*adjusted_mode
,
4684 struct drm_framebuffer
*fb
)
4686 struct drm_device
*dev
= crtc
->dev
;
4687 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4688 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
4689 int pipe
= intel_crtc
->pipe
;
4690 int plane
= intel_crtc
->plane
;
4691 int refclk
, num_connectors
= 0;
4692 intel_clock_t clock
, reduced_clock
;
4693 u32 dspcntr
, pipeconf
;
4694 bool ok
, has_reduced_clock
= false, is_sdvo
= false;
4695 bool is_lvds
= false, is_tv
= false, is_dp
= false;
4696 struct intel_encoder
*encoder
;
4697 const intel_limit_t
*limit
;
4700 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4701 switch (encoder
->type
) {
4702 case INTEL_OUTPUT_LVDS
:
4705 case INTEL_OUTPUT_SDVO
:
4706 case INTEL_OUTPUT_HDMI
:
4708 if (encoder
->needs_tv_clock
)
4711 case INTEL_OUTPUT_TVOUT
:
4714 case INTEL_OUTPUT_DISPLAYPORT
:
4722 refclk
= i9xx_get_refclk(crtc
, num_connectors
);
4725 * Returns a set of divisors for the desired target clock with the given
4726 * refclk, or FALSE. The returned values represent the clock equation:
4727 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
4729 limit
= intel_limit(crtc
, refclk
);
4730 ok
= limit
->find_pll(limit
, crtc
, adjusted_mode
->clock
, refclk
, NULL
,
4733 DRM_ERROR("Couldn't find PLL settings for mode!\n");
4737 /* Ensure that the cursor is valid for the new mode before changing... */
4738 intel_crtc_update_cursor(crtc
, true);
4740 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
4742 * Ensure we match the reduced clock's P to the target clock.
4743 * If the clocks don't match, we can't switch the display clock
4744 * by using the FP0/FP1. In such case we will disable the LVDS
4745 * downclock feature.
4747 has_reduced_clock
= limit
->find_pll(limit
, crtc
,
4748 dev_priv
->lvds_downclock
,
4754 if (is_sdvo
&& is_tv
)
4755 i9xx_adjust_sdvo_tv_clock(adjusted_mode
, &clock
);
4758 i8xx_update_pll(crtc
, adjusted_mode
, &clock
,
4759 has_reduced_clock
? &reduced_clock
: NULL
,
4761 else if (IS_VALLEYVIEW(dev
))
4762 vlv_update_pll(crtc
, mode
, adjusted_mode
, &clock
,
4763 has_reduced_clock
? &reduced_clock
: NULL
,
4766 i9xx_update_pll(crtc
, mode
, adjusted_mode
, &clock
,
4767 has_reduced_clock
? &reduced_clock
: NULL
,
4770 /* setup pipeconf */
4771 pipeconf
= I915_READ(PIPECONF(pipe
));
4773 /* Set up the display plane register */
4774 dspcntr
= DISPPLANE_GAMMA_ENABLE
;
4777 dspcntr
&= ~DISPPLANE_SEL_PIPE_MASK
;
4779 dspcntr
|= DISPPLANE_SEL_PIPE_B
;
4781 if (pipe
== 0 && INTEL_INFO(dev
)->gen
< 4) {
4782 /* Enable pixel doubling when the dot clock is > 90% of the (display)
4785 * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
4789 dev_priv
->display
.get_display_clock_speed(dev
) * 9 / 10)
4790 pipeconf
|= PIPECONF_DOUBLE_WIDE
;
4792 pipeconf
&= ~PIPECONF_DOUBLE_WIDE
;
4795 /* default to 8bpc */
4796 pipeconf
&= ~(PIPECONF_BPP_MASK
| PIPECONF_DITHER_EN
);
4798 if (adjusted_mode
->private_flags
& INTEL_MODE_DP_FORCE_6BPC
) {
4799 pipeconf
|= PIPECONF_BPP_6
|
4800 PIPECONF_DITHER_EN
|
4801 PIPECONF_DITHER_TYPE_SP
;
4805 if (IS_VALLEYVIEW(dev
) && intel_pipe_has_type(crtc
, INTEL_OUTPUT_EDP
)) {
4806 if (adjusted_mode
->private_flags
& INTEL_MODE_DP_FORCE_6BPC
) {
4807 pipeconf
|= PIPECONF_BPP_6
|
4809 I965_PIPECONF_ACTIVE
;
4813 DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe
== 0 ? 'A' : 'B');
4814 drm_mode_debug_printmodeline(mode
);
4816 if (HAS_PIPE_CXSR(dev
)) {
4817 if (intel_crtc
->lowfreq_avail
) {
4818 DRM_DEBUG_KMS("enabling CxSR downclocking\n");
4819 pipeconf
|= PIPECONF_CXSR_DOWNCLOCK
;
4821 DRM_DEBUG_KMS("disabling CxSR downclocking\n");
4822 pipeconf
&= ~PIPECONF_CXSR_DOWNCLOCK
;
4826 pipeconf
&= ~PIPECONF_INTERLACE_MASK
;
4827 if (!IS_GEN2(dev
) &&
4828 adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
4829 pipeconf
|= PIPECONF_INTERLACE_W_FIELD_INDICATION
;
4831 pipeconf
|= PIPECONF_PROGRESSIVE
;
4833 intel_set_pipe_timings(intel_crtc
, mode
, adjusted_mode
);
4835 /* pipesrc and dspsize control the size that is scaled from,
4836 * which should always be the user's requested size.
4838 I915_WRITE(DSPSIZE(plane
),
4839 ((mode
->vdisplay
- 1) << 16) |
4840 (mode
->hdisplay
- 1));
4841 I915_WRITE(DSPPOS(plane
), 0);
4843 I915_WRITE(PIPECONF(pipe
), pipeconf
);
4844 POSTING_READ(PIPECONF(pipe
));
4845 intel_enable_pipe(dev_priv
, pipe
, false);
4847 intel_wait_for_vblank(dev
, pipe
);
4849 I915_WRITE(DSPCNTR(plane
), dspcntr
);
4850 POSTING_READ(DSPCNTR(plane
));
4852 ret
= intel_pipe_set_base(crtc
, x
, y
, fb
);
4854 intel_update_watermarks(dev
);
4860 * Initialize reference clocks when the driver loads
4862 void ironlake_init_pch_refclk(struct drm_device
*dev
)
4864 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4865 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
4866 struct intel_encoder
*encoder
;
4868 bool has_lvds
= false;
4869 bool has_cpu_edp
= false;
4870 bool has_pch_edp
= false;
4871 bool has_panel
= false;
4872 bool has_ck505
= false;
4873 bool can_ssc
= false;
4875 /* We need to take the global config into account */
4876 list_for_each_entry(encoder
, &mode_config
->encoder_list
,
4878 switch (encoder
->type
) {
4879 case INTEL_OUTPUT_LVDS
:
4883 case INTEL_OUTPUT_EDP
:
4885 if (intel_encoder_is_pch_edp(&encoder
->base
))
4893 if (HAS_PCH_IBX(dev
)) {
4894 has_ck505
= dev_priv
->display_clock_mode
;
4895 can_ssc
= has_ck505
;
4901 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n",
4902 has_panel
, has_lvds
, has_pch_edp
, has_cpu_edp
,
4905 /* Ironlake: try to setup display ref clock before DPLL
4906 * enabling. This is only under driver's control after
4907 * PCH B stepping, previous chipset stepping should be
4908 * ignoring this setting.
4910 temp
= I915_READ(PCH_DREF_CONTROL
);
4911 /* Always enable nonspread source */
4912 temp
&= ~DREF_NONSPREAD_SOURCE_MASK
;
4915 temp
|= DREF_NONSPREAD_CK505_ENABLE
;
4917 temp
|= DREF_NONSPREAD_SOURCE_ENABLE
;
4920 temp
&= ~DREF_SSC_SOURCE_MASK
;
4921 temp
|= DREF_SSC_SOURCE_ENABLE
;
4923 /* SSC must be turned on before enabling the CPU output */
4924 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
4925 DRM_DEBUG_KMS("Using SSC on panel\n");
4926 temp
|= DREF_SSC1_ENABLE
;
4928 temp
&= ~DREF_SSC1_ENABLE
;
4930 /* Get SSC going before enabling the outputs */
4931 I915_WRITE(PCH_DREF_CONTROL
, temp
);
4932 POSTING_READ(PCH_DREF_CONTROL
);
4935 temp
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
4937 /* Enable CPU source on CPU attached eDP */
4939 if (intel_panel_use_ssc(dev_priv
) && can_ssc
) {
4940 DRM_DEBUG_KMS("Using SSC on eDP\n");
4941 temp
|= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD
;
4944 temp
|= DREF_CPU_SOURCE_OUTPUT_NONSPREAD
;
4946 temp
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
4948 I915_WRITE(PCH_DREF_CONTROL
, temp
);
4949 POSTING_READ(PCH_DREF_CONTROL
);
4952 DRM_DEBUG_KMS("Disabling SSC entirely\n");
4954 temp
&= ~DREF_CPU_SOURCE_OUTPUT_MASK
;
4956 /* Turn off CPU output */
4957 temp
|= DREF_CPU_SOURCE_OUTPUT_DISABLE
;
4959 I915_WRITE(PCH_DREF_CONTROL
, temp
);
4960 POSTING_READ(PCH_DREF_CONTROL
);
4963 /* Turn off the SSC source */
4964 temp
&= ~DREF_SSC_SOURCE_MASK
;
4965 temp
|= DREF_SSC_SOURCE_DISABLE
;
4968 temp
&= ~ DREF_SSC1_ENABLE
;
4970 I915_WRITE(PCH_DREF_CONTROL
, temp
);
4971 POSTING_READ(PCH_DREF_CONTROL
);
4976 static int ironlake_get_refclk(struct drm_crtc
*crtc
)
4978 struct drm_device
*dev
= crtc
->dev
;
4979 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4980 struct intel_encoder
*encoder
;
4981 struct intel_encoder
*edp_encoder
= NULL
;
4982 int num_connectors
= 0;
4983 bool is_lvds
= false;
4985 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
4986 switch (encoder
->type
) {
4987 case INTEL_OUTPUT_LVDS
:
4990 case INTEL_OUTPUT_EDP
:
4991 edp_encoder
= encoder
;
4997 if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2) {
4998 DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
4999 dev_priv
->lvds_ssc_freq
);
5000 return dev_priv
->lvds_ssc_freq
* 1000;
5006 static void ironlake_set_pipeconf(struct drm_crtc
*crtc
,
5007 struct drm_display_mode
*adjusted_mode
,
5010 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
5011 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5012 int pipe
= intel_crtc
->pipe
;
5015 val
= I915_READ(PIPECONF(pipe
));
5017 val
&= ~PIPE_BPC_MASK
;
5018 switch (intel_crtc
->bpp
) {
5032 /* Case prevented by intel_choose_pipe_bpp_dither. */
5036 val
&= ~(PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_MASK
);
5038 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
5040 val
&= ~PIPECONF_INTERLACE_MASK
;
5041 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
5042 val
|= PIPECONF_INTERLACED_ILK
;
5044 val
|= PIPECONF_PROGRESSIVE
;
5046 I915_WRITE(PIPECONF(pipe
), val
);
5047 POSTING_READ(PIPECONF(pipe
));
5050 static void haswell_set_pipeconf(struct drm_crtc
*crtc
,
5051 struct drm_display_mode
*adjusted_mode
,
5054 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
5055 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5056 enum transcoder cpu_transcoder
= intel_crtc
->cpu_transcoder
;
5059 val
= I915_READ(PIPECONF(cpu_transcoder
));
5061 val
&= ~(PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_MASK
);
5063 val
|= (PIPECONF_DITHER_EN
| PIPECONF_DITHER_TYPE_SP
);
5065 val
&= ~PIPECONF_INTERLACE_MASK_HSW
;
5066 if (adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
5067 val
|= PIPECONF_INTERLACED_ILK
;
5069 val
|= PIPECONF_PROGRESSIVE
;
5071 I915_WRITE(PIPECONF(cpu_transcoder
), val
);
5072 POSTING_READ(PIPECONF(cpu_transcoder
));
5075 static bool ironlake_compute_clocks(struct drm_crtc
*crtc
,
5076 struct drm_display_mode
*adjusted_mode
,
5077 intel_clock_t
*clock
,
5078 bool *has_reduced_clock
,
5079 intel_clock_t
*reduced_clock
)
5081 struct drm_device
*dev
= crtc
->dev
;
5082 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5083 struct intel_encoder
*intel_encoder
;
5085 const intel_limit_t
*limit
;
5086 bool ret
, is_sdvo
= false, is_tv
= false, is_lvds
= false;
5088 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
5089 switch (intel_encoder
->type
) {
5090 case INTEL_OUTPUT_LVDS
:
5093 case INTEL_OUTPUT_SDVO
:
5094 case INTEL_OUTPUT_HDMI
:
5096 if (intel_encoder
->needs_tv_clock
)
5099 case INTEL_OUTPUT_TVOUT
:
5105 refclk
= ironlake_get_refclk(crtc
);
5108 * Returns a set of divisors for the desired target clock with the given
5109 * refclk, or FALSE. The returned values represent the clock equation:
5110 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
5112 limit
= intel_limit(crtc
, refclk
);
5113 ret
= limit
->find_pll(limit
, crtc
, adjusted_mode
->clock
, refclk
, NULL
,
5118 if (is_lvds
&& dev_priv
->lvds_downclock_avail
) {
5120 * Ensure we match the reduced clock's P to the target clock.
5121 * If the clocks don't match, we can't switch the display clock
5122 * by using the FP0/FP1. In such case we will disable the LVDS
5123 * downclock feature.
5125 *has_reduced_clock
= limit
->find_pll(limit
, crtc
,
5126 dev_priv
->lvds_downclock
,
5132 if (is_sdvo
&& is_tv
)
5133 i9xx_adjust_sdvo_tv_clock(adjusted_mode
, clock
);
5138 static void cpt_enable_fdi_bc_bifurcation(struct drm_device
*dev
)
5140 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5143 temp
= I915_READ(SOUTH_CHICKEN1
);
5144 if (temp
& FDI_BC_BIFURCATION_SELECT
)
5147 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B
)) & FDI_RX_ENABLE
);
5148 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C
)) & FDI_RX_ENABLE
);
5150 temp
|= FDI_BC_BIFURCATION_SELECT
;
5151 DRM_DEBUG_KMS("enabling fdi C rx\n");
5152 I915_WRITE(SOUTH_CHICKEN1
, temp
);
5153 POSTING_READ(SOUTH_CHICKEN1
);
5156 static bool ironlake_check_fdi_lanes(struct intel_crtc
*intel_crtc
)
5158 struct drm_device
*dev
= intel_crtc
->base
.dev
;
5159 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5160 struct intel_crtc
*pipe_B_crtc
=
5161 to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[PIPE_B
]);
5163 DRM_DEBUG_KMS("checking fdi config on pipe %i, lanes %i\n",
5164 intel_crtc
->pipe
, intel_crtc
->fdi_lanes
);
5165 if (intel_crtc
->fdi_lanes
> 4) {
5166 DRM_DEBUG_KMS("invalid fdi lane config on pipe %i: %i lanes\n",
5167 intel_crtc
->pipe
, intel_crtc
->fdi_lanes
);
5168 /* Clamp lanes to avoid programming the hw with bogus values. */
5169 intel_crtc
->fdi_lanes
= 4;
5174 if (dev_priv
->num_pipe
== 2)
5177 switch (intel_crtc
->pipe
) {
5181 if (dev_priv
->pipe_to_crtc_mapping
[PIPE_C
]->enabled
&&
5182 intel_crtc
->fdi_lanes
> 2) {
5183 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
5184 intel_crtc
->pipe
, intel_crtc
->fdi_lanes
);
5185 /* Clamp lanes to avoid programming the hw with bogus values. */
5186 intel_crtc
->fdi_lanes
= 2;
5191 if (intel_crtc
->fdi_lanes
> 2)
5192 WARN_ON(I915_READ(SOUTH_CHICKEN1
) & FDI_BC_BIFURCATION_SELECT
);
5194 cpt_enable_fdi_bc_bifurcation(dev
);
5198 if (!pipe_B_crtc
->base
.enabled
|| pipe_B_crtc
->fdi_lanes
<= 2) {
5199 if (intel_crtc
->fdi_lanes
> 2) {
5200 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
5201 intel_crtc
->pipe
, intel_crtc
->fdi_lanes
);
5202 /* Clamp lanes to avoid programming the hw with bogus values. */
5203 intel_crtc
->fdi_lanes
= 2;
5208 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
5212 cpt_enable_fdi_bc_bifurcation(dev
);
5220 static void ironlake_set_m_n(struct drm_crtc
*crtc
,
5221 struct drm_display_mode
*mode
,
5222 struct drm_display_mode
*adjusted_mode
)
5224 struct drm_device
*dev
= crtc
->dev
;
5225 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5226 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5227 enum transcoder cpu_transcoder
= intel_crtc
->cpu_transcoder
;
5228 struct intel_encoder
*intel_encoder
, *edp_encoder
= NULL
;
5229 struct fdi_m_n m_n
= {0};
5230 int target_clock
, pixel_multiplier
, lane
, link_bw
;
5231 bool is_dp
= false, is_cpu_edp
= false;
5233 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
5234 switch (intel_encoder
->type
) {
5235 case INTEL_OUTPUT_DISPLAYPORT
:
5238 case INTEL_OUTPUT_EDP
:
5240 if (!intel_encoder_is_pch_edp(&intel_encoder
->base
))
5242 edp_encoder
= intel_encoder
;
5248 pixel_multiplier
= intel_mode_get_pixel_multiplier(adjusted_mode
);
5250 /* CPU eDP doesn't require FDI link, so just set DP M/N
5251 according to current link config */
5253 intel_edp_link_config(edp_encoder
, &lane
, &link_bw
);
5255 /* FDI is a binary signal running at ~2.7GHz, encoding
5256 * each output octet as 10 bits. The actual frequency
5257 * is stored as a divider into a 100MHz clock, and the
5258 * mode pixel clock is stored in units of 1KHz.
5259 * Hence the bw of each lane in terms of the mode signal
5262 link_bw
= intel_fdi_link_freq(dev
) * MHz(100)/KHz(1)/10;
5265 /* [e]DP over FDI requires target mode clock instead of link clock. */
5267 target_clock
= intel_edp_target_clock(edp_encoder
, mode
);
5269 target_clock
= mode
->clock
;
5271 target_clock
= adjusted_mode
->clock
;
5275 * Account for spread spectrum to avoid
5276 * oversubscribing the link. Max center spread
5277 * is 2.5%; use 5% for safety's sake.
5279 u32 bps
= target_clock
* intel_crtc
->bpp
* 21 / 20;
5280 lane
= bps
/ (link_bw
* 8) + 1;
5283 intel_crtc
->fdi_lanes
= lane
;
5285 if (pixel_multiplier
> 1)
5286 link_bw
*= pixel_multiplier
;
5287 ironlake_compute_m_n(intel_crtc
->bpp
, lane
, target_clock
, link_bw
,
5290 I915_WRITE(PIPE_DATA_M1(cpu_transcoder
), TU_SIZE(m_n
.tu
) | m_n
.gmch_m
);
5291 I915_WRITE(PIPE_DATA_N1(cpu_transcoder
), m_n
.gmch_n
);
5292 I915_WRITE(PIPE_LINK_M1(cpu_transcoder
), m_n
.link_m
);
5293 I915_WRITE(PIPE_LINK_N1(cpu_transcoder
), m_n
.link_n
);
5296 static uint32_t ironlake_compute_dpll(struct intel_crtc
*intel_crtc
,
5297 struct drm_display_mode
*adjusted_mode
,
5298 intel_clock_t
*clock
, u32 fp
)
5300 struct drm_crtc
*crtc
= &intel_crtc
->base
;
5301 struct drm_device
*dev
= crtc
->dev
;
5302 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5303 struct intel_encoder
*intel_encoder
;
5305 int factor
, pixel_multiplier
, num_connectors
= 0;
5306 bool is_lvds
= false, is_sdvo
= false, is_tv
= false;
5307 bool is_dp
= false, is_cpu_edp
= false;
5309 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
5310 switch (intel_encoder
->type
) {
5311 case INTEL_OUTPUT_LVDS
:
5314 case INTEL_OUTPUT_SDVO
:
5315 case INTEL_OUTPUT_HDMI
:
5317 if (intel_encoder
->needs_tv_clock
)
5320 case INTEL_OUTPUT_TVOUT
:
5323 case INTEL_OUTPUT_DISPLAYPORT
:
5326 case INTEL_OUTPUT_EDP
:
5328 if (!intel_encoder_is_pch_edp(&intel_encoder
->base
))
5336 /* Enable autotuning of the PLL clock (if permissible) */
5339 if ((intel_panel_use_ssc(dev_priv
) &&
5340 dev_priv
->lvds_ssc_freq
== 100) ||
5341 (I915_READ(PCH_LVDS
) & LVDS_CLKB_POWER_MASK
) == LVDS_CLKB_POWER_UP
)
5343 } else if (is_sdvo
&& is_tv
)
5346 if (clock
->m
< factor
* clock
->n
)
5352 dpll
|= DPLLB_MODE_LVDS
;
5354 dpll
|= DPLLB_MODE_DAC_SERIAL
;
5356 pixel_multiplier
= intel_mode_get_pixel_multiplier(adjusted_mode
);
5357 if (pixel_multiplier
> 1) {
5358 dpll
|= (pixel_multiplier
- 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT
;
5360 dpll
|= DPLL_DVO_HIGH_SPEED
;
5362 if (is_dp
&& !is_cpu_edp
)
5363 dpll
|= DPLL_DVO_HIGH_SPEED
;
5365 /* compute bitmask from p1 value */
5366 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT
;
5368 dpll
|= (1 << (clock
->p1
- 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT
;
5370 switch (clock
->p2
) {
5372 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
;
5375 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_7
;
5378 dpll
|= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
;
5381 dpll
|= DPLLB_LVDS_P2_CLOCK_DIV_14
;
5385 if (is_sdvo
&& is_tv
)
5386 dpll
|= PLL_REF_INPUT_TVCLKINBC
;
5388 /* XXX: just matching BIOS for now */
5389 /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
5391 else if (is_lvds
&& intel_panel_use_ssc(dev_priv
) && num_connectors
< 2)
5392 dpll
|= PLLB_REF_INPUT_SPREADSPECTRUMIN
;
5394 dpll
|= PLL_REF_INPUT_DREFCLK
;
5399 static int ironlake_crtc_mode_set(struct drm_crtc
*crtc
,
5400 struct drm_display_mode
*mode
,
5401 struct drm_display_mode
*adjusted_mode
,
5403 struct drm_framebuffer
*fb
)
5405 struct drm_device
*dev
= crtc
->dev
;
5406 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5407 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5408 int pipe
= intel_crtc
->pipe
;
5409 int plane
= intel_crtc
->plane
;
5410 int num_connectors
= 0;
5411 intel_clock_t clock
, reduced_clock
;
5412 u32 dpll
, fp
= 0, fp2
= 0;
5413 bool ok
, has_reduced_clock
= false;
5414 bool is_lvds
= false, is_dp
= false, is_cpu_edp
= false;
5415 struct intel_encoder
*encoder
;
5418 bool dither
, fdi_config_ok
;
5420 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5421 switch (encoder
->type
) {
5422 case INTEL_OUTPUT_LVDS
:
5425 case INTEL_OUTPUT_DISPLAYPORT
:
5428 case INTEL_OUTPUT_EDP
:
5430 if (!intel_encoder_is_pch_edp(&encoder
->base
))
5438 WARN(!(HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)),
5439 "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev
));
5441 ok
= ironlake_compute_clocks(crtc
, adjusted_mode
, &clock
,
5442 &has_reduced_clock
, &reduced_clock
);
5444 DRM_ERROR("Couldn't find PLL settings for mode!\n");
5448 /* Ensure that the cursor is valid for the new mode before changing... */
5449 intel_crtc_update_cursor(crtc
, true);
5451 /* determine panel color depth */
5452 dither
= intel_choose_pipe_bpp_dither(crtc
, fb
, &intel_crtc
->bpp
,
5454 if (is_lvds
&& dev_priv
->lvds_dither
)
5457 fp
= clock
.n
<< 16 | clock
.m1
<< 8 | clock
.m2
;
5458 if (has_reduced_clock
)
5459 fp2
= reduced_clock
.n
<< 16 | reduced_clock
.m1
<< 8 |
5462 dpll
= ironlake_compute_dpll(intel_crtc
, adjusted_mode
, &clock
, fp
);
5464 DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe
);
5465 drm_mode_debug_printmodeline(mode
);
5467 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
5469 struct intel_pch_pll
*pll
;
5471 pll
= intel_get_pch_pll(intel_crtc
, dpll
, fp
);
5473 DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
5478 intel_put_pch_pll(intel_crtc
);
5480 /* The LVDS pin pair needs to be on before the DPLLs are enabled.
5481 * This is an exception to the general rule that mode_set doesn't turn
5485 temp
= I915_READ(PCH_LVDS
);
5486 temp
|= LVDS_PORT_EN
| LVDS_A0A2_CLKA_POWER_UP
;
5487 if (HAS_PCH_CPT(dev
)) {
5488 temp
&= ~PORT_TRANS_SEL_MASK
;
5489 temp
|= PORT_TRANS_SEL_CPT(pipe
);
5492 temp
|= LVDS_PIPEB_SELECT
;
5494 temp
&= ~LVDS_PIPEB_SELECT
;
5497 /* set the corresponsding LVDS_BORDER bit */
5498 temp
|= dev_priv
->lvds_border_bits
;
5499 /* Set the B0-B3 data pairs corresponding to whether we're going to
5500 * set the DPLLs for dual-channel mode or not.
5503 temp
|= LVDS_B0B3_POWER_UP
| LVDS_CLKB_POWER_UP
;
5505 temp
&= ~(LVDS_B0B3_POWER_UP
| LVDS_CLKB_POWER_UP
);
5507 /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
5508 * appropriately here, but we need to look more thoroughly into how
5509 * panels behave in the two modes.
5511 temp
&= ~(LVDS_HSYNC_POLARITY
| LVDS_VSYNC_POLARITY
);
5512 if (adjusted_mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
5513 temp
|= LVDS_HSYNC_POLARITY
;
5514 if (adjusted_mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
5515 temp
|= LVDS_VSYNC_POLARITY
;
5516 I915_WRITE(PCH_LVDS
, temp
);
5519 if (is_dp
&& !is_cpu_edp
) {
5520 intel_dp_set_m_n(crtc
, mode
, adjusted_mode
);
5522 /* For non-DP output, clear any trans DP clock recovery setting.*/
5523 I915_WRITE(TRANSDATA_M1(pipe
), 0);
5524 I915_WRITE(TRANSDATA_N1(pipe
), 0);
5525 I915_WRITE(TRANSDPLINK_M1(pipe
), 0);
5526 I915_WRITE(TRANSDPLINK_N1(pipe
), 0);
5529 if (intel_crtc
->pch_pll
) {
5530 I915_WRITE(intel_crtc
->pch_pll
->pll_reg
, dpll
);
5532 /* Wait for the clocks to stabilize. */
5533 POSTING_READ(intel_crtc
->pch_pll
->pll_reg
);
5536 /* The pixel multiplier can only be updated once the
5537 * DPLL is enabled and the clocks are stable.
5539 * So write it again.
5541 I915_WRITE(intel_crtc
->pch_pll
->pll_reg
, dpll
);
5544 intel_crtc
->lowfreq_avail
= false;
5545 if (intel_crtc
->pch_pll
) {
5546 if (is_lvds
&& has_reduced_clock
&& i915_powersave
) {
5547 I915_WRITE(intel_crtc
->pch_pll
->fp1_reg
, fp2
);
5548 intel_crtc
->lowfreq_avail
= true;
5550 I915_WRITE(intel_crtc
->pch_pll
->fp1_reg
, fp
);
5554 intel_set_pipe_timings(intel_crtc
, mode
, adjusted_mode
);
5556 /* Note, this also computes intel_crtc->fdi_lanes which is used below in
5557 * ironlake_check_fdi_lanes. */
5558 ironlake_set_m_n(crtc
, mode
, adjusted_mode
);
5560 fdi_config_ok
= ironlake_check_fdi_lanes(intel_crtc
);
5563 ironlake_set_pll_edp(crtc
, adjusted_mode
->clock
);
5565 ironlake_set_pipeconf(crtc
, adjusted_mode
, dither
);
5567 intel_wait_for_vblank(dev
, pipe
);
5569 /* Set up the display plane register */
5570 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
);
5571 POSTING_READ(DSPCNTR(plane
));
5573 ret
= intel_pipe_set_base(crtc
, x
, y
, fb
);
5575 intel_update_watermarks(dev
);
5577 intel_update_linetime_watermarks(dev
, pipe
, adjusted_mode
);
5579 return fdi_config_ok
? ret
: -EINVAL
;
5582 static int haswell_crtc_mode_set(struct drm_crtc
*crtc
,
5583 struct drm_display_mode
*mode
,
5584 struct drm_display_mode
*adjusted_mode
,
5586 struct drm_framebuffer
*fb
)
5588 struct drm_device
*dev
= crtc
->dev
;
5589 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5590 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5591 int pipe
= intel_crtc
->pipe
;
5592 int plane
= intel_crtc
->plane
;
5593 int num_connectors
= 0;
5594 intel_clock_t clock
, reduced_clock
;
5595 u32 dpll
= 0, fp
= 0, fp2
= 0;
5596 bool ok
, has_reduced_clock
= false;
5597 bool is_lvds
= false, is_dp
= false, is_cpu_edp
= false;
5598 struct intel_encoder
*encoder
;
5603 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5604 switch (encoder
->type
) {
5605 case INTEL_OUTPUT_LVDS
:
5608 case INTEL_OUTPUT_DISPLAYPORT
:
5611 case INTEL_OUTPUT_EDP
:
5613 if (!intel_encoder_is_pch_edp(&encoder
->base
))
5622 intel_crtc
->cpu_transcoder
= TRANSCODER_EDP
;
5624 intel_crtc
->cpu_transcoder
= pipe
;
5626 /* We are not sure yet this won't happen. */
5627 WARN(!HAS_PCH_LPT(dev
), "Unexpected PCH type %d\n",
5628 INTEL_PCH_TYPE(dev
));
5630 WARN(num_connectors
!= 1, "%d connectors attached to pipe %c\n",
5631 num_connectors
, pipe_name(pipe
));
5633 WARN_ON(I915_READ(PIPECONF(intel_crtc
->cpu_transcoder
)) &
5634 (PIPECONF_ENABLE
| I965_PIPECONF_ACTIVE
));
5636 WARN_ON(I915_READ(DSPCNTR(plane
)) & DISPLAY_PLANE_ENABLE
);
5638 if (!intel_ddi_pll_mode_set(crtc
, adjusted_mode
->clock
))
5641 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)) {
5642 ok
= ironlake_compute_clocks(crtc
, adjusted_mode
, &clock
,
5646 DRM_ERROR("Couldn't find PLL settings for mode!\n");
5651 /* Ensure that the cursor is valid for the new mode before changing... */
5652 intel_crtc_update_cursor(crtc
, true);
5654 /* determine panel color depth */
5655 dither
= intel_choose_pipe_bpp_dither(crtc
, fb
, &intel_crtc
->bpp
,
5657 if (is_lvds
&& dev_priv
->lvds_dither
)
5660 DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe
);
5661 drm_mode_debug_printmodeline(mode
);
5663 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)) {
5664 fp
= clock
.n
<< 16 | clock
.m1
<< 8 | clock
.m2
;
5665 if (has_reduced_clock
)
5666 fp2
= reduced_clock
.n
<< 16 | reduced_clock
.m1
<< 8 |
5669 dpll
= ironlake_compute_dpll(intel_crtc
, adjusted_mode
, &clock
,
5672 /* CPU eDP is the only output that doesn't need a PCH PLL of its
5673 * own on pre-Haswell/LPT generation */
5675 struct intel_pch_pll
*pll
;
5677 pll
= intel_get_pch_pll(intel_crtc
, dpll
, fp
);
5679 DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
5684 intel_put_pch_pll(intel_crtc
);
5686 /* The LVDS pin pair needs to be on before the DPLLs are
5687 * enabled. This is an exception to the general rule that
5688 * mode_set doesn't turn things on.
5691 temp
= I915_READ(PCH_LVDS
);
5692 temp
|= LVDS_PORT_EN
| LVDS_A0A2_CLKA_POWER_UP
;
5693 if (HAS_PCH_CPT(dev
)) {
5694 temp
&= ~PORT_TRANS_SEL_MASK
;
5695 temp
|= PORT_TRANS_SEL_CPT(pipe
);
5698 temp
|= LVDS_PIPEB_SELECT
;
5700 temp
&= ~LVDS_PIPEB_SELECT
;
5703 /* set the corresponsding LVDS_BORDER bit */
5704 temp
|= dev_priv
->lvds_border_bits
;
5705 /* Set the B0-B3 data pairs corresponding to whether
5706 * we're going to set the DPLLs for dual-channel mode or
5710 temp
|= LVDS_B0B3_POWER_UP
| LVDS_CLKB_POWER_UP
;
5712 temp
&= ~(LVDS_B0B3_POWER_UP
|
5713 LVDS_CLKB_POWER_UP
);
5715 /* It would be nice to set 24 vs 18-bit mode
5716 * (LVDS_A3_POWER_UP) appropriately here, but we need to
5717 * look more thoroughly into how panels behave in the
5720 temp
&= ~(LVDS_HSYNC_POLARITY
| LVDS_VSYNC_POLARITY
);
5721 if (adjusted_mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
5722 temp
|= LVDS_HSYNC_POLARITY
;
5723 if (adjusted_mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
5724 temp
|= LVDS_VSYNC_POLARITY
;
5725 I915_WRITE(PCH_LVDS
, temp
);
5729 if (is_dp
&& !is_cpu_edp
) {
5730 intel_dp_set_m_n(crtc
, mode
, adjusted_mode
);
5732 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)) {
5733 /* For non-DP output, clear any trans DP clock recovery
5735 I915_WRITE(TRANSDATA_M1(pipe
), 0);
5736 I915_WRITE(TRANSDATA_N1(pipe
), 0);
5737 I915_WRITE(TRANSDPLINK_M1(pipe
), 0);
5738 I915_WRITE(TRANSDPLINK_N1(pipe
), 0);
5742 intel_crtc
->lowfreq_avail
= false;
5743 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
)) {
5744 if (intel_crtc
->pch_pll
) {
5745 I915_WRITE(intel_crtc
->pch_pll
->pll_reg
, dpll
);
5747 /* Wait for the clocks to stabilize. */
5748 POSTING_READ(intel_crtc
->pch_pll
->pll_reg
);
5751 /* The pixel multiplier can only be updated once the
5752 * DPLL is enabled and the clocks are stable.
5754 * So write it again.
5756 I915_WRITE(intel_crtc
->pch_pll
->pll_reg
, dpll
);
5759 if (intel_crtc
->pch_pll
) {
5760 if (is_lvds
&& has_reduced_clock
&& i915_powersave
) {
5761 I915_WRITE(intel_crtc
->pch_pll
->fp1_reg
, fp2
);
5762 intel_crtc
->lowfreq_avail
= true;
5764 I915_WRITE(intel_crtc
->pch_pll
->fp1_reg
, fp
);
5769 intel_set_pipe_timings(intel_crtc
, mode
, adjusted_mode
);
5771 if (!is_dp
|| is_cpu_edp
)
5772 ironlake_set_m_n(crtc
, mode
, adjusted_mode
);
5774 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
5776 ironlake_set_pll_edp(crtc
, adjusted_mode
->clock
);
5778 haswell_set_pipeconf(crtc
, adjusted_mode
, dither
);
5780 /* Set up the display plane register */
5781 I915_WRITE(DSPCNTR(plane
), DISPPLANE_GAMMA_ENABLE
);
5782 POSTING_READ(DSPCNTR(plane
));
5784 ret
= intel_pipe_set_base(crtc
, x
, y
, fb
);
5786 intel_update_watermarks(dev
);
5788 intel_update_linetime_watermarks(dev
, pipe
, adjusted_mode
);
5793 static int intel_crtc_mode_set(struct drm_crtc
*crtc
,
5794 struct drm_display_mode
*mode
,
5795 struct drm_display_mode
*adjusted_mode
,
5797 struct drm_framebuffer
*fb
)
5799 struct drm_device
*dev
= crtc
->dev
;
5800 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5801 struct drm_encoder_helper_funcs
*encoder_funcs
;
5802 struct intel_encoder
*encoder
;
5803 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
5804 int pipe
= intel_crtc
->pipe
;
5807 drm_vblank_pre_modeset(dev
, pipe
);
5809 ret
= dev_priv
->display
.crtc_mode_set(crtc
, mode
, adjusted_mode
,
5811 drm_vblank_post_modeset(dev
, pipe
);
5816 for_each_encoder_on_crtc(dev
, crtc
, encoder
) {
5817 DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
5818 encoder
->base
.base
.id
,
5819 drm_get_encoder_name(&encoder
->base
),
5820 mode
->base
.id
, mode
->name
);
5821 encoder_funcs
= encoder
->base
.helper_private
;
5822 encoder_funcs
->mode_set(&encoder
->base
, mode
, adjusted_mode
);
5828 static bool intel_eld_uptodate(struct drm_connector
*connector
,
5829 int reg_eldv
, uint32_t bits_eldv
,
5830 int reg_elda
, uint32_t bits_elda
,
5833 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
5834 uint8_t *eld
= connector
->eld
;
5837 i
= I915_READ(reg_eldv
);
5846 i
= I915_READ(reg_elda
);
5848 I915_WRITE(reg_elda
, i
);
5850 for (i
= 0; i
< eld
[2]; i
++)
5851 if (I915_READ(reg_edid
) != *((uint32_t *)eld
+ i
))
5857 static void g4x_write_eld(struct drm_connector
*connector
,
5858 struct drm_crtc
*crtc
)
5860 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
5861 uint8_t *eld
= connector
->eld
;
5866 i
= I915_READ(G4X_AUD_VID_DID
);
5868 if (i
== INTEL_AUDIO_DEVBLC
|| i
== INTEL_AUDIO_DEVCL
)
5869 eldv
= G4X_ELDV_DEVCL_DEVBLC
;
5871 eldv
= G4X_ELDV_DEVCTG
;
5873 if (intel_eld_uptodate(connector
,
5874 G4X_AUD_CNTL_ST
, eldv
,
5875 G4X_AUD_CNTL_ST
, G4X_ELD_ADDR
,
5876 G4X_HDMIW_HDMIEDID
))
5879 i
= I915_READ(G4X_AUD_CNTL_ST
);
5880 i
&= ~(eldv
| G4X_ELD_ADDR
);
5881 len
= (i
>> 9) & 0x1f; /* ELD buffer size */
5882 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
5887 len
= min_t(uint8_t, eld
[2], len
);
5888 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
5889 for (i
= 0; i
< len
; i
++)
5890 I915_WRITE(G4X_HDMIW_HDMIEDID
, *((uint32_t *)eld
+ i
));
5892 i
= I915_READ(G4X_AUD_CNTL_ST
);
5894 I915_WRITE(G4X_AUD_CNTL_ST
, i
);
5897 static void haswell_write_eld(struct drm_connector
*connector
,
5898 struct drm_crtc
*crtc
)
5900 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
5901 uint8_t *eld
= connector
->eld
;
5902 struct drm_device
*dev
= crtc
->dev
;
5906 int pipe
= to_intel_crtc(crtc
)->pipe
;
5909 int hdmiw_hdmiedid
= HSW_AUD_EDID_DATA(pipe
);
5910 int aud_cntl_st
= HSW_AUD_DIP_ELD_CTRL(pipe
);
5911 int aud_config
= HSW_AUD_CFG(pipe
);
5912 int aud_cntrl_st2
= HSW_AUD_PIN_ELD_CP_VLD
;
5915 DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n");
5917 /* Audio output enable */
5918 DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
5919 tmp
= I915_READ(aud_cntrl_st2
);
5920 tmp
|= (AUDIO_OUTPUT_ENABLE_A
<< (pipe
* 4));
5921 I915_WRITE(aud_cntrl_st2
, tmp
);
5923 /* Wait for 1 vertical blank */
5924 intel_wait_for_vblank(dev
, pipe
);
5926 /* Set ELD valid state */
5927 tmp
= I915_READ(aud_cntrl_st2
);
5928 DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp
);
5929 tmp
|= (AUDIO_ELD_VALID_A
<< (pipe
* 4));
5930 I915_WRITE(aud_cntrl_st2
, tmp
);
5931 tmp
= I915_READ(aud_cntrl_st2
);
5932 DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp
);
5934 /* Enable HDMI mode */
5935 tmp
= I915_READ(aud_config
);
5936 DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp
);
5937 /* clear N_programing_enable and N_value_index */
5938 tmp
&= ~(AUD_CONFIG_N_VALUE_INDEX
| AUD_CONFIG_N_PROG_ENABLE
);
5939 I915_WRITE(aud_config
, tmp
);
5941 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
5943 eldv
= AUDIO_ELD_VALID_A
<< (pipe
* 4);
5945 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
5946 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
5947 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
5948 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
5950 I915_WRITE(aud_config
, 0);
5952 if (intel_eld_uptodate(connector
,
5953 aud_cntrl_st2
, eldv
,
5954 aud_cntl_st
, IBX_ELD_ADDRESS
,
5958 i
= I915_READ(aud_cntrl_st2
);
5960 I915_WRITE(aud_cntrl_st2
, i
);
5965 i
= I915_READ(aud_cntl_st
);
5966 i
&= ~IBX_ELD_ADDRESS
;
5967 I915_WRITE(aud_cntl_st
, i
);
5968 i
= (i
>> 29) & DIP_PORT_SEL_MASK
; /* DIP_Port_Select, 0x1 = PortB */
5969 DRM_DEBUG_DRIVER("port num:%d\n", i
);
5971 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
5972 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
5973 for (i
= 0; i
< len
; i
++)
5974 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
5976 i
= I915_READ(aud_cntrl_st2
);
5978 I915_WRITE(aud_cntrl_st2
, i
);
5982 static void ironlake_write_eld(struct drm_connector
*connector
,
5983 struct drm_crtc
*crtc
)
5985 struct drm_i915_private
*dev_priv
= connector
->dev
->dev_private
;
5986 uint8_t *eld
= connector
->eld
;
5994 int pipe
= to_intel_crtc(crtc
)->pipe
;
5996 if (HAS_PCH_IBX(connector
->dev
)) {
5997 hdmiw_hdmiedid
= IBX_HDMIW_HDMIEDID(pipe
);
5998 aud_config
= IBX_AUD_CFG(pipe
);
5999 aud_cntl_st
= IBX_AUD_CNTL_ST(pipe
);
6000 aud_cntrl_st2
= IBX_AUD_CNTL_ST2
;
6002 hdmiw_hdmiedid
= CPT_HDMIW_HDMIEDID(pipe
);
6003 aud_config
= CPT_AUD_CFG(pipe
);
6004 aud_cntl_st
= CPT_AUD_CNTL_ST(pipe
);
6005 aud_cntrl_st2
= CPT_AUD_CNTRL_ST2
;
6008 DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe
));
6010 i
= I915_READ(aud_cntl_st
);
6011 i
= (i
>> 29) & DIP_PORT_SEL_MASK
; /* DIP_Port_Select, 0x1 = PortB */
6013 DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
6014 /* operate blindly on all ports */
6015 eldv
= IBX_ELD_VALIDB
;
6016 eldv
|= IBX_ELD_VALIDB
<< 4;
6017 eldv
|= IBX_ELD_VALIDB
<< 8;
6019 DRM_DEBUG_DRIVER("ELD on port %c\n", 'A' + i
);
6020 eldv
= IBX_ELD_VALIDB
<< ((i
- 1) * 4);
6023 if (intel_pipe_has_type(crtc
, INTEL_OUTPUT_DISPLAYPORT
)) {
6024 DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
6025 eld
[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
6026 I915_WRITE(aud_config
, AUD_CONFIG_N_VALUE_INDEX
); /* 0x1 = DP */
6028 I915_WRITE(aud_config
, 0);
6030 if (intel_eld_uptodate(connector
,
6031 aud_cntrl_st2
, eldv
,
6032 aud_cntl_st
, IBX_ELD_ADDRESS
,
6036 i
= I915_READ(aud_cntrl_st2
);
6038 I915_WRITE(aud_cntrl_st2
, i
);
6043 i
= I915_READ(aud_cntl_st
);
6044 i
&= ~IBX_ELD_ADDRESS
;
6045 I915_WRITE(aud_cntl_st
, i
);
6047 len
= min_t(uint8_t, eld
[2], 21); /* 84 bytes of hw ELD buffer */
6048 DRM_DEBUG_DRIVER("ELD size %d\n", len
);
6049 for (i
= 0; i
< len
; i
++)
6050 I915_WRITE(hdmiw_hdmiedid
, *((uint32_t *)eld
+ i
));
6052 i
= I915_READ(aud_cntrl_st2
);
6054 I915_WRITE(aud_cntrl_st2
, i
);
6057 void intel_write_eld(struct drm_encoder
*encoder
,
6058 struct drm_display_mode
*mode
)
6060 struct drm_crtc
*crtc
= encoder
->crtc
;
6061 struct drm_connector
*connector
;
6062 struct drm_device
*dev
= encoder
->dev
;
6063 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6065 connector
= drm_select_eld(encoder
, mode
);
6069 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6071 drm_get_connector_name(connector
),
6072 connector
->encoder
->base
.id
,
6073 drm_get_encoder_name(connector
->encoder
));
6075 connector
->eld
[6] = drm_av_sync_delay(connector
, mode
) / 2;
6077 if (dev_priv
->display
.write_eld
)
6078 dev_priv
->display
.write_eld(connector
, crtc
);
6081 /** Loads the palette/gamma unit for the CRTC with the prepared values */
6082 void intel_crtc_load_lut(struct drm_crtc
*crtc
)
6084 struct drm_device
*dev
= crtc
->dev
;
6085 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6086 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6087 int palreg
= PALETTE(intel_crtc
->pipe
);
6090 /* The clocks have to be on to load the palette. */
6091 if (!crtc
->enabled
|| !intel_crtc
->active
)
6094 /* use legacy palette for Ironlake */
6095 if (HAS_PCH_SPLIT(dev
))
6096 palreg
= LGC_PALETTE(intel_crtc
->pipe
);
6098 for (i
= 0; i
< 256; i
++) {
6099 I915_WRITE(palreg
+ 4 * i
,
6100 (intel_crtc
->lut_r
[i
] << 16) |
6101 (intel_crtc
->lut_g
[i
] << 8) |
6102 intel_crtc
->lut_b
[i
]);
6106 static void i845_update_cursor(struct drm_crtc
*crtc
, u32 base
)
6108 struct drm_device
*dev
= crtc
->dev
;
6109 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6110 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6111 bool visible
= base
!= 0;
6114 if (intel_crtc
->cursor_visible
== visible
)
6117 cntl
= I915_READ(_CURACNTR
);
6119 /* On these chipsets we can only modify the base whilst
6120 * the cursor is disabled.
6122 I915_WRITE(_CURABASE
, base
);
6124 cntl
&= ~(CURSOR_FORMAT_MASK
);
6125 /* XXX width must be 64, stride 256 => 0x00 << 28 */
6126 cntl
|= CURSOR_ENABLE
|
6127 CURSOR_GAMMA_ENABLE
|
6130 cntl
&= ~(CURSOR_ENABLE
| CURSOR_GAMMA_ENABLE
);
6131 I915_WRITE(_CURACNTR
, cntl
);
6133 intel_crtc
->cursor_visible
= visible
;
6136 static void i9xx_update_cursor(struct drm_crtc
*crtc
, u32 base
)
6138 struct drm_device
*dev
= crtc
->dev
;
6139 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6140 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6141 int pipe
= intel_crtc
->pipe
;
6142 bool visible
= base
!= 0;
6144 if (intel_crtc
->cursor_visible
!= visible
) {
6145 uint32_t cntl
= I915_READ(CURCNTR(pipe
));
6147 cntl
&= ~(CURSOR_MODE
| MCURSOR_PIPE_SELECT
);
6148 cntl
|= CURSOR_MODE_64_ARGB_AX
| MCURSOR_GAMMA_ENABLE
;
6149 cntl
|= pipe
<< 28; /* Connect to correct pipe */
6151 cntl
&= ~(CURSOR_MODE
| MCURSOR_GAMMA_ENABLE
);
6152 cntl
|= CURSOR_MODE_DISABLE
;
6154 I915_WRITE(CURCNTR(pipe
), cntl
);
6156 intel_crtc
->cursor_visible
= visible
;
6158 /* and commit changes on next vblank */
6159 I915_WRITE(CURBASE(pipe
), base
);
6162 static void ivb_update_cursor(struct drm_crtc
*crtc
, u32 base
)
6164 struct drm_device
*dev
= crtc
->dev
;
6165 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6166 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6167 int pipe
= intel_crtc
->pipe
;
6168 bool visible
= base
!= 0;
6170 if (intel_crtc
->cursor_visible
!= visible
) {
6171 uint32_t cntl
= I915_READ(CURCNTR_IVB(pipe
));
6173 cntl
&= ~CURSOR_MODE
;
6174 cntl
|= CURSOR_MODE_64_ARGB_AX
| MCURSOR_GAMMA_ENABLE
;
6176 cntl
&= ~(CURSOR_MODE
| MCURSOR_GAMMA_ENABLE
);
6177 cntl
|= CURSOR_MODE_DISABLE
;
6179 I915_WRITE(CURCNTR_IVB(pipe
), cntl
);
6181 intel_crtc
->cursor_visible
= visible
;
6183 /* and commit changes on next vblank */
6184 I915_WRITE(CURBASE_IVB(pipe
), base
);
6187 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
6188 static void intel_crtc_update_cursor(struct drm_crtc
*crtc
,
6191 struct drm_device
*dev
= crtc
->dev
;
6192 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6193 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6194 int pipe
= intel_crtc
->pipe
;
6195 int x
= intel_crtc
->cursor_x
;
6196 int y
= intel_crtc
->cursor_y
;
6202 if (on
&& crtc
->enabled
&& crtc
->fb
) {
6203 base
= intel_crtc
->cursor_addr
;
6204 if (x
> (int) crtc
->fb
->width
)
6207 if (y
> (int) crtc
->fb
->height
)
6213 if (x
+ intel_crtc
->cursor_width
< 0)
6216 pos
|= CURSOR_POS_SIGN
<< CURSOR_X_SHIFT
;
6219 pos
|= x
<< CURSOR_X_SHIFT
;
6222 if (y
+ intel_crtc
->cursor_height
< 0)
6225 pos
|= CURSOR_POS_SIGN
<< CURSOR_Y_SHIFT
;
6228 pos
|= y
<< CURSOR_Y_SHIFT
;
6230 visible
= base
!= 0;
6231 if (!visible
&& !intel_crtc
->cursor_visible
)
6234 if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
)) {
6235 I915_WRITE(CURPOS_IVB(pipe
), pos
);
6236 ivb_update_cursor(crtc
, base
);
6238 I915_WRITE(CURPOS(pipe
), pos
);
6239 if (IS_845G(dev
) || IS_I865G(dev
))
6240 i845_update_cursor(crtc
, base
);
6242 i9xx_update_cursor(crtc
, base
);
6246 static int intel_crtc_cursor_set(struct drm_crtc
*crtc
,
6247 struct drm_file
*file
,
6249 uint32_t width
, uint32_t height
)
6251 struct drm_device
*dev
= crtc
->dev
;
6252 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6253 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6254 struct drm_i915_gem_object
*obj
;
6258 /* if we want to turn off the cursor ignore width and height */
6260 DRM_DEBUG_KMS("cursor off\n");
6263 mutex_lock(&dev
->struct_mutex
);
6267 /* Currently we only support 64x64 cursors */
6268 if (width
!= 64 || height
!= 64) {
6269 DRM_ERROR("we currently only support 64x64 cursors\n");
6273 obj
= to_intel_bo(drm_gem_object_lookup(dev
, file
, handle
));
6274 if (&obj
->base
== NULL
)
6277 if (obj
->base
.size
< width
* height
* 4) {
6278 DRM_ERROR("buffer is to small\n");
6283 /* we only need to pin inside GTT if cursor is non-phy */
6284 mutex_lock(&dev
->struct_mutex
);
6285 if (!dev_priv
->info
->cursor_needs_physical
) {
6286 if (obj
->tiling_mode
) {
6287 DRM_ERROR("cursor cannot be tiled\n");
6292 ret
= i915_gem_object_pin_to_display_plane(obj
, 0, NULL
);
6294 DRM_ERROR("failed to move cursor bo into the GTT\n");
6298 ret
= i915_gem_object_put_fence(obj
);
6300 DRM_ERROR("failed to release fence for cursor");
6304 addr
= obj
->gtt_offset
;
6306 int align
= IS_I830(dev
) ? 16 * 1024 : 256;
6307 ret
= i915_gem_attach_phys_object(dev
, obj
,
6308 (intel_crtc
->pipe
== 0) ? I915_GEM_PHYS_CURSOR_0
: I915_GEM_PHYS_CURSOR_1
,
6311 DRM_ERROR("failed to attach phys object\n");
6314 addr
= obj
->phys_obj
->handle
->busaddr
;
6318 I915_WRITE(CURSIZE
, (height
<< 12) | width
);
6321 if (intel_crtc
->cursor_bo
) {
6322 if (dev_priv
->info
->cursor_needs_physical
) {
6323 if (intel_crtc
->cursor_bo
!= obj
)
6324 i915_gem_detach_phys_object(dev
, intel_crtc
->cursor_bo
);
6326 i915_gem_object_unpin(intel_crtc
->cursor_bo
);
6327 drm_gem_object_unreference(&intel_crtc
->cursor_bo
->base
);
6330 mutex_unlock(&dev
->struct_mutex
);
6332 intel_crtc
->cursor_addr
= addr
;
6333 intel_crtc
->cursor_bo
= obj
;
6334 intel_crtc
->cursor_width
= width
;
6335 intel_crtc
->cursor_height
= height
;
6337 intel_crtc_update_cursor(crtc
, true);
6341 i915_gem_object_unpin(obj
);
6343 mutex_unlock(&dev
->struct_mutex
);
6345 drm_gem_object_unreference_unlocked(&obj
->base
);
6349 static int intel_crtc_cursor_move(struct drm_crtc
*crtc
, int x
, int y
)
6351 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6353 intel_crtc
->cursor_x
= x
;
6354 intel_crtc
->cursor_y
= y
;
6356 intel_crtc_update_cursor(crtc
, true);
6361 /** Sets the color ramps on behalf of RandR */
6362 void intel_crtc_fb_gamma_set(struct drm_crtc
*crtc
, u16 red
, u16 green
,
6363 u16 blue
, int regno
)
6365 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6367 intel_crtc
->lut_r
[regno
] = red
>> 8;
6368 intel_crtc
->lut_g
[regno
] = green
>> 8;
6369 intel_crtc
->lut_b
[regno
] = blue
>> 8;
6372 void intel_crtc_fb_gamma_get(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
6373 u16
*blue
, int regno
)
6375 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6377 *red
= intel_crtc
->lut_r
[regno
] << 8;
6378 *green
= intel_crtc
->lut_g
[regno
] << 8;
6379 *blue
= intel_crtc
->lut_b
[regno
] << 8;
6382 static void intel_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
6383 u16
*blue
, uint32_t start
, uint32_t size
)
6385 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
6386 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6388 for (i
= start
; i
< end
; i
++) {
6389 intel_crtc
->lut_r
[i
] = red
[i
] >> 8;
6390 intel_crtc
->lut_g
[i
] = green
[i
] >> 8;
6391 intel_crtc
->lut_b
[i
] = blue
[i
] >> 8;
6394 intel_crtc_load_lut(crtc
);
6398 * Get a pipe with a simple mode set on it for doing load-based monitor
6401 * It will be up to the load-detect code to adjust the pipe as appropriate for
6402 * its requirements. The pipe will be connected to no other encoders.
6404 * Currently this code will only succeed if there is a pipe with no encoders
6405 * configured for it. In the future, it could choose to temporarily disable
6406 * some outputs to free up a pipe for its use.
6408 * \return crtc, or NULL if no pipes are available.
6411 /* VESA 640x480x72Hz mode to set on the pipe */
6412 static struct drm_display_mode load_detect_mode
= {
6413 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT
, 31500, 640, 664,
6414 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
6417 static struct drm_framebuffer
*
6418 intel_framebuffer_create(struct drm_device
*dev
,
6419 struct drm_mode_fb_cmd2
*mode_cmd
,
6420 struct drm_i915_gem_object
*obj
)
6422 struct intel_framebuffer
*intel_fb
;
6425 intel_fb
= kzalloc(sizeof(*intel_fb
), GFP_KERNEL
);
6427 drm_gem_object_unreference_unlocked(&obj
->base
);
6428 return ERR_PTR(-ENOMEM
);
6431 ret
= intel_framebuffer_init(dev
, intel_fb
, mode_cmd
, obj
);
6433 drm_gem_object_unreference_unlocked(&obj
->base
);
6435 return ERR_PTR(ret
);
6438 return &intel_fb
->base
;
6442 intel_framebuffer_pitch_for_width(int width
, int bpp
)
6444 u32 pitch
= DIV_ROUND_UP(width
* bpp
, 8);
6445 return ALIGN(pitch
, 64);
6449 intel_framebuffer_size_for_mode(struct drm_display_mode
*mode
, int bpp
)
6451 u32 pitch
= intel_framebuffer_pitch_for_width(mode
->hdisplay
, bpp
);
6452 return ALIGN(pitch
* mode
->vdisplay
, PAGE_SIZE
);
6455 static struct drm_framebuffer
*
6456 intel_framebuffer_create_for_mode(struct drm_device
*dev
,
6457 struct drm_display_mode
*mode
,
6460 struct drm_i915_gem_object
*obj
;
6461 struct drm_mode_fb_cmd2 mode_cmd
= { 0 };
6463 obj
= i915_gem_alloc_object(dev
,
6464 intel_framebuffer_size_for_mode(mode
, bpp
));
6466 return ERR_PTR(-ENOMEM
);
6468 mode_cmd
.width
= mode
->hdisplay
;
6469 mode_cmd
.height
= mode
->vdisplay
;
6470 mode_cmd
.pitches
[0] = intel_framebuffer_pitch_for_width(mode_cmd
.width
,
6472 mode_cmd
.pixel_format
= drm_mode_legacy_fb_format(bpp
, depth
);
6474 return intel_framebuffer_create(dev
, &mode_cmd
, obj
);
6477 static struct drm_framebuffer
*
6478 mode_fits_in_fbdev(struct drm_device
*dev
,
6479 struct drm_display_mode
*mode
)
6481 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6482 struct drm_i915_gem_object
*obj
;
6483 struct drm_framebuffer
*fb
;
6485 if (dev_priv
->fbdev
== NULL
)
6488 obj
= dev_priv
->fbdev
->ifb
.obj
;
6492 fb
= &dev_priv
->fbdev
->ifb
.base
;
6493 if (fb
->pitches
[0] < intel_framebuffer_pitch_for_width(mode
->hdisplay
,
6494 fb
->bits_per_pixel
))
6497 if (obj
->base
.size
< mode
->vdisplay
* fb
->pitches
[0])
6503 bool intel_get_load_detect_pipe(struct drm_connector
*connector
,
6504 struct drm_display_mode
*mode
,
6505 struct intel_load_detect_pipe
*old
)
6507 struct intel_crtc
*intel_crtc
;
6508 struct intel_encoder
*intel_encoder
=
6509 intel_attached_encoder(connector
);
6510 struct drm_crtc
*possible_crtc
;
6511 struct drm_encoder
*encoder
= &intel_encoder
->base
;
6512 struct drm_crtc
*crtc
= NULL
;
6513 struct drm_device
*dev
= encoder
->dev
;
6514 struct drm_framebuffer
*fb
;
6517 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6518 connector
->base
.id
, drm_get_connector_name(connector
),
6519 encoder
->base
.id
, drm_get_encoder_name(encoder
));
6522 * Algorithm gets a little messy:
6524 * - if the connector already has an assigned crtc, use it (but make
6525 * sure it's on first)
6527 * - try to find the first unused crtc that can drive this connector,
6528 * and use that if we find one
6531 /* See if we already have a CRTC for this connector */
6532 if (encoder
->crtc
) {
6533 crtc
= encoder
->crtc
;
6535 old
->dpms_mode
= connector
->dpms
;
6536 old
->load_detect_temp
= false;
6538 /* Make sure the crtc and connector are running */
6539 if (connector
->dpms
!= DRM_MODE_DPMS_ON
)
6540 connector
->funcs
->dpms(connector
, DRM_MODE_DPMS_ON
);
6545 /* Find an unused one (if possible) */
6546 list_for_each_entry(possible_crtc
, &dev
->mode_config
.crtc_list
, head
) {
6548 if (!(encoder
->possible_crtcs
& (1 << i
)))
6550 if (!possible_crtc
->enabled
) {
6551 crtc
= possible_crtc
;
6557 * If we didn't find an unused CRTC, don't use any.
6560 DRM_DEBUG_KMS("no pipe available for load-detect\n");
6564 intel_encoder
->new_crtc
= to_intel_crtc(crtc
);
6565 to_intel_connector(connector
)->new_encoder
= intel_encoder
;
6567 intel_crtc
= to_intel_crtc(crtc
);
6568 old
->dpms_mode
= connector
->dpms
;
6569 old
->load_detect_temp
= true;
6570 old
->release_fb
= NULL
;
6573 mode
= &load_detect_mode
;
6575 /* We need a framebuffer large enough to accommodate all accesses
6576 * that the plane may generate whilst we perform load detection.
6577 * We can not rely on the fbcon either being present (we get called
6578 * during its initialisation to detect all boot displays, or it may
6579 * not even exist) or that it is large enough to satisfy the
6582 fb
= mode_fits_in_fbdev(dev
, mode
);
6584 DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
6585 fb
= intel_framebuffer_create_for_mode(dev
, mode
, 24, 32);
6586 old
->release_fb
= fb
;
6588 DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
6590 DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
6594 if (!intel_set_mode(crtc
, mode
, 0, 0, fb
)) {
6595 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
6596 if (old
->release_fb
)
6597 old
->release_fb
->funcs
->destroy(old
->release_fb
);
6601 /* let the connector get through one full cycle before testing */
6602 intel_wait_for_vblank(dev
, intel_crtc
->pipe
);
6606 void intel_release_load_detect_pipe(struct drm_connector
*connector
,
6607 struct intel_load_detect_pipe
*old
)
6609 struct intel_encoder
*intel_encoder
=
6610 intel_attached_encoder(connector
);
6611 struct drm_encoder
*encoder
= &intel_encoder
->base
;
6613 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6614 connector
->base
.id
, drm_get_connector_name(connector
),
6615 encoder
->base
.id
, drm_get_encoder_name(encoder
));
6617 if (old
->load_detect_temp
) {
6618 struct drm_crtc
*crtc
= encoder
->crtc
;
6620 to_intel_connector(connector
)->new_encoder
= NULL
;
6621 intel_encoder
->new_crtc
= NULL
;
6622 intel_set_mode(crtc
, NULL
, 0, 0, NULL
);
6624 if (old
->release_fb
)
6625 old
->release_fb
->funcs
->destroy(old
->release_fb
);
6630 /* Switch crtc and encoder back off if necessary */
6631 if (old
->dpms_mode
!= DRM_MODE_DPMS_ON
)
6632 connector
->funcs
->dpms(connector
, old
->dpms_mode
);
6635 /* Returns the clock of the currently programmed mode of the given pipe. */
6636 static int intel_crtc_clock_get(struct drm_device
*dev
, struct drm_crtc
*crtc
)
6638 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6639 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6640 int pipe
= intel_crtc
->pipe
;
6641 u32 dpll
= I915_READ(DPLL(pipe
));
6643 intel_clock_t clock
;
6645 if ((dpll
& DISPLAY_RATE_SELECT_FPA1
) == 0)
6646 fp
= I915_READ(FP0(pipe
));
6648 fp
= I915_READ(FP1(pipe
));
6650 clock
.m1
= (fp
& FP_M1_DIV_MASK
) >> FP_M1_DIV_SHIFT
;
6651 if (IS_PINEVIEW(dev
)) {
6652 clock
.n
= ffs((fp
& FP_N_PINEVIEW_DIV_MASK
) >> FP_N_DIV_SHIFT
) - 1;
6653 clock
.m2
= (fp
& FP_M2_PINEVIEW_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
6655 clock
.n
= (fp
& FP_N_DIV_MASK
) >> FP_N_DIV_SHIFT
;
6656 clock
.m2
= (fp
& FP_M2_DIV_MASK
) >> FP_M2_DIV_SHIFT
;
6659 if (!IS_GEN2(dev
)) {
6660 if (IS_PINEVIEW(dev
))
6661 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW
) >>
6662 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW
);
6664 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK
) >>
6665 DPLL_FPA01_P1_POST_DIV_SHIFT
);
6667 switch (dpll
& DPLL_MODE_MASK
) {
6668 case DPLLB_MODE_DAC_SERIAL
:
6669 clock
.p2
= dpll
& DPLL_DAC_SERIAL_P2_CLOCK_DIV_5
?
6672 case DPLLB_MODE_LVDS
:
6673 clock
.p2
= dpll
& DPLLB_LVDS_P2_CLOCK_DIV_7
?
6677 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
6678 "mode\n", (int)(dpll
& DPLL_MODE_MASK
));
6682 /* XXX: Handle the 100Mhz refclk */
6683 intel_clock(dev
, 96000, &clock
);
6685 bool is_lvds
= (pipe
== 1) && (I915_READ(LVDS
) & LVDS_PORT_EN
);
6688 clock
.p1
= ffs((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS
) >>
6689 DPLL_FPA01_P1_POST_DIV_SHIFT
);
6692 if ((dpll
& PLL_REF_INPUT_MASK
) ==
6693 PLLB_REF_INPUT_SPREADSPECTRUMIN
) {
6694 /* XXX: might not be 66MHz */
6695 intel_clock(dev
, 66000, &clock
);
6697 intel_clock(dev
, 48000, &clock
);
6699 if (dpll
& PLL_P1_DIVIDE_BY_TWO
)
6702 clock
.p1
= ((dpll
& DPLL_FPA01_P1_POST_DIV_MASK_I830
) >>
6703 DPLL_FPA01_P1_POST_DIV_SHIFT
) + 2;
6705 if (dpll
& PLL_P2_DIVIDE_BY_4
)
6710 intel_clock(dev
, 48000, &clock
);
6714 /* XXX: It would be nice to validate the clocks, but we can't reuse
6715 * i830PllIsValid() because it relies on the xf86_config connector
6716 * configuration being accurate, which it isn't necessarily.
6722 /** Returns the currently programmed mode of the given pipe. */
6723 struct drm_display_mode
*intel_crtc_mode_get(struct drm_device
*dev
,
6724 struct drm_crtc
*crtc
)
6726 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6727 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6728 enum transcoder cpu_transcoder
= intel_crtc
->cpu_transcoder
;
6729 struct drm_display_mode
*mode
;
6730 int htot
= I915_READ(HTOTAL(cpu_transcoder
));
6731 int hsync
= I915_READ(HSYNC(cpu_transcoder
));
6732 int vtot
= I915_READ(VTOTAL(cpu_transcoder
));
6733 int vsync
= I915_READ(VSYNC(cpu_transcoder
));
6735 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
6739 mode
->clock
= intel_crtc_clock_get(dev
, crtc
);
6740 mode
->hdisplay
= (htot
& 0xffff) + 1;
6741 mode
->htotal
= ((htot
& 0xffff0000) >> 16) + 1;
6742 mode
->hsync_start
= (hsync
& 0xffff) + 1;
6743 mode
->hsync_end
= ((hsync
& 0xffff0000) >> 16) + 1;
6744 mode
->vdisplay
= (vtot
& 0xffff) + 1;
6745 mode
->vtotal
= ((vtot
& 0xffff0000) >> 16) + 1;
6746 mode
->vsync_start
= (vsync
& 0xffff) + 1;
6747 mode
->vsync_end
= ((vsync
& 0xffff0000) >> 16) + 1;
6749 drm_mode_set_name(mode
);
6754 static void intel_increase_pllclock(struct drm_crtc
*crtc
)
6756 struct drm_device
*dev
= crtc
->dev
;
6757 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
6758 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6759 int pipe
= intel_crtc
->pipe
;
6760 int dpll_reg
= DPLL(pipe
);
6763 if (HAS_PCH_SPLIT(dev
))
6766 if (!dev_priv
->lvds_downclock_avail
)
6769 dpll
= I915_READ(dpll_reg
);
6770 if (!HAS_PIPE_CXSR(dev
) && (dpll
& DISPLAY_RATE_SELECT_FPA1
)) {
6771 DRM_DEBUG_DRIVER("upclocking LVDS\n");
6773 assert_panel_unlocked(dev_priv
, pipe
);
6775 dpll
&= ~DISPLAY_RATE_SELECT_FPA1
;
6776 I915_WRITE(dpll_reg
, dpll
);
6777 intel_wait_for_vblank(dev
, pipe
);
6779 dpll
= I915_READ(dpll_reg
);
6780 if (dpll
& DISPLAY_RATE_SELECT_FPA1
)
6781 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
6785 static void intel_decrease_pllclock(struct drm_crtc
*crtc
)
6787 struct drm_device
*dev
= crtc
->dev
;
6788 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
6789 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6791 if (HAS_PCH_SPLIT(dev
))
6794 if (!dev_priv
->lvds_downclock_avail
)
6798 * Since this is called by a timer, we should never get here in
6801 if (!HAS_PIPE_CXSR(dev
) && intel_crtc
->lowfreq_avail
) {
6802 int pipe
= intel_crtc
->pipe
;
6803 int dpll_reg
= DPLL(pipe
);
6806 DRM_DEBUG_DRIVER("downclocking LVDS\n");
6808 assert_panel_unlocked(dev_priv
, pipe
);
6810 dpll
= I915_READ(dpll_reg
);
6811 dpll
|= DISPLAY_RATE_SELECT_FPA1
;
6812 I915_WRITE(dpll_reg
, dpll
);
6813 intel_wait_for_vblank(dev
, pipe
);
6814 dpll
= I915_READ(dpll_reg
);
6815 if (!(dpll
& DISPLAY_RATE_SELECT_FPA1
))
6816 DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
6821 void intel_mark_busy(struct drm_device
*dev
)
6823 i915_update_gfx_val(dev
->dev_private
);
6826 void intel_mark_idle(struct drm_device
*dev
)
6830 void intel_mark_fb_busy(struct drm_i915_gem_object
*obj
)
6832 struct drm_device
*dev
= obj
->base
.dev
;
6833 struct drm_crtc
*crtc
;
6835 if (!i915_powersave
)
6838 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
6842 if (to_intel_framebuffer(crtc
->fb
)->obj
== obj
)
6843 intel_increase_pllclock(crtc
);
6847 void intel_mark_fb_idle(struct drm_i915_gem_object
*obj
)
6849 struct drm_device
*dev
= obj
->base
.dev
;
6850 struct drm_crtc
*crtc
;
6852 if (!i915_powersave
)
6855 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
6859 if (to_intel_framebuffer(crtc
->fb
)->obj
== obj
)
6860 intel_decrease_pllclock(crtc
);
6864 static void intel_crtc_destroy(struct drm_crtc
*crtc
)
6866 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6867 struct drm_device
*dev
= crtc
->dev
;
6868 struct intel_unpin_work
*work
;
6869 unsigned long flags
;
6871 spin_lock_irqsave(&dev
->event_lock
, flags
);
6872 work
= intel_crtc
->unpin_work
;
6873 intel_crtc
->unpin_work
= NULL
;
6874 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
6877 cancel_work_sync(&work
->work
);
6881 drm_crtc_cleanup(crtc
);
6886 static void intel_unpin_work_fn(struct work_struct
*__work
)
6888 struct intel_unpin_work
*work
=
6889 container_of(__work
, struct intel_unpin_work
, work
);
6890 struct drm_device
*dev
= work
->crtc
->dev
;
6892 mutex_lock(&dev
->struct_mutex
);
6893 intel_unpin_fb_obj(work
->old_fb_obj
);
6894 drm_gem_object_unreference(&work
->pending_flip_obj
->base
);
6895 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
6897 intel_update_fbc(dev
);
6898 mutex_unlock(&dev
->struct_mutex
);
6900 BUG_ON(atomic_read(&to_intel_crtc(work
->crtc
)->unpin_work_count
) == 0);
6901 atomic_dec(&to_intel_crtc(work
->crtc
)->unpin_work_count
);
6906 static void do_intel_finish_page_flip(struct drm_device
*dev
,
6907 struct drm_crtc
*crtc
)
6909 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
6910 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6911 struct intel_unpin_work
*work
;
6912 struct drm_i915_gem_object
*obj
;
6913 struct drm_pending_vblank_event
*e
;
6914 struct timeval tvbl
;
6915 unsigned long flags
;
6917 /* Ignore early vblank irqs */
6918 if (intel_crtc
== NULL
)
6921 spin_lock_irqsave(&dev
->event_lock
, flags
);
6922 work
= intel_crtc
->unpin_work
;
6923 if (work
== NULL
|| !work
->pending
) {
6924 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
6928 intel_crtc
->unpin_work
= NULL
;
6932 e
->event
.sequence
= drm_vblank_count_and_time(dev
, intel_crtc
->pipe
, &tvbl
);
6934 e
->event
.tv_sec
= tvbl
.tv_sec
;
6935 e
->event
.tv_usec
= tvbl
.tv_usec
;
6937 list_add_tail(&e
->base
.link
,
6938 &e
->base
.file_priv
->event_list
);
6939 wake_up_interruptible(&e
->base
.file_priv
->event_wait
);
6942 drm_vblank_put(dev
, intel_crtc
->pipe
);
6944 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
6946 obj
= work
->old_fb_obj
;
6948 atomic_clear_mask(1 << intel_crtc
->plane
,
6949 &obj
->pending_flip
.counter
);
6950 wake_up(&dev_priv
->pending_flip_queue
);
6952 queue_work(dev_priv
->wq
, &work
->work
);
6954 trace_i915_flip_complete(intel_crtc
->plane
, work
->pending_flip_obj
);
6957 void intel_finish_page_flip(struct drm_device
*dev
, int pipe
)
6959 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
6960 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
6962 do_intel_finish_page_flip(dev
, crtc
);
6965 void intel_finish_page_flip_plane(struct drm_device
*dev
, int plane
)
6967 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
6968 struct drm_crtc
*crtc
= dev_priv
->plane_to_crtc_mapping
[plane
];
6970 do_intel_finish_page_flip(dev
, crtc
);
6973 void intel_prepare_page_flip(struct drm_device
*dev
, int plane
)
6975 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
6976 struct intel_crtc
*intel_crtc
=
6977 to_intel_crtc(dev_priv
->plane_to_crtc_mapping
[plane
]);
6978 unsigned long flags
;
6980 spin_lock_irqsave(&dev
->event_lock
, flags
);
6981 if (intel_crtc
->unpin_work
) {
6982 if ((++intel_crtc
->unpin_work
->pending
) > 1)
6983 DRM_ERROR("Prepared flip multiple times\n");
6985 DRM_DEBUG_DRIVER("preparing flip with no unpin work?\n");
6987 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
6990 static int intel_gen2_queue_flip(struct drm_device
*dev
,
6991 struct drm_crtc
*crtc
,
6992 struct drm_framebuffer
*fb
,
6993 struct drm_i915_gem_object
*obj
)
6995 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6996 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
6998 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7001 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7005 ret
= intel_ring_begin(ring
, 6);
7009 /* Can't queue multiple flips, so wait for the previous
7010 * one to finish before executing the next.
7012 if (intel_crtc
->plane
)
7013 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
7015 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
7016 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
7017 intel_ring_emit(ring
, MI_NOOP
);
7018 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
7019 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7020 intel_ring_emit(ring
, fb
->pitches
[0]);
7021 intel_ring_emit(ring
, obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
7022 intel_ring_emit(ring
, 0); /* aux display base address, unused */
7023 intel_ring_advance(ring
);
7027 intel_unpin_fb_obj(obj
);
7032 static int intel_gen3_queue_flip(struct drm_device
*dev
,
7033 struct drm_crtc
*crtc
,
7034 struct drm_framebuffer
*fb
,
7035 struct drm_i915_gem_object
*obj
)
7037 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7038 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7040 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7043 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7047 ret
= intel_ring_begin(ring
, 6);
7051 if (intel_crtc
->plane
)
7052 flip_mask
= MI_WAIT_FOR_PLANE_B_FLIP
;
7054 flip_mask
= MI_WAIT_FOR_PLANE_A_FLIP
;
7055 intel_ring_emit(ring
, MI_WAIT_FOR_EVENT
| flip_mask
);
7056 intel_ring_emit(ring
, MI_NOOP
);
7057 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
|
7058 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7059 intel_ring_emit(ring
, fb
->pitches
[0]);
7060 intel_ring_emit(ring
, obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
7061 intel_ring_emit(ring
, MI_NOOP
);
7063 intel_ring_advance(ring
);
7067 intel_unpin_fb_obj(obj
);
7072 static int intel_gen4_queue_flip(struct drm_device
*dev
,
7073 struct drm_crtc
*crtc
,
7074 struct drm_framebuffer
*fb
,
7075 struct drm_i915_gem_object
*obj
)
7077 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7078 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7079 uint32_t pf
, pipesrc
;
7080 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7083 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7087 ret
= intel_ring_begin(ring
, 4);
7091 /* i965+ uses the linear or tiled offsets from the
7092 * Display Registers (which do not change across a page-flip)
7093 * so we need only reprogram the base address.
7095 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
7096 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7097 intel_ring_emit(ring
, fb
->pitches
[0]);
7098 intel_ring_emit(ring
,
7099 (obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
) |
7102 /* XXX Enabling the panel-fitter across page-flip is so far
7103 * untested on non-native modes, so ignore it for now.
7104 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
7107 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
7108 intel_ring_emit(ring
, pf
| pipesrc
);
7109 intel_ring_advance(ring
);
7113 intel_unpin_fb_obj(obj
);
7118 static int intel_gen6_queue_flip(struct drm_device
*dev
,
7119 struct drm_crtc
*crtc
,
7120 struct drm_framebuffer
*fb
,
7121 struct drm_i915_gem_object
*obj
)
7123 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7124 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7125 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[RCS
];
7126 uint32_t pf
, pipesrc
;
7129 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7133 ret
= intel_ring_begin(ring
, 4);
7137 intel_ring_emit(ring
, MI_DISPLAY_FLIP
|
7138 MI_DISPLAY_FLIP_PLANE(intel_crtc
->plane
));
7139 intel_ring_emit(ring
, fb
->pitches
[0] | obj
->tiling_mode
);
7140 intel_ring_emit(ring
, obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
7142 /* Contrary to the suggestions in the documentation,
7143 * "Enable Panel Fitter" does not seem to be required when page
7144 * flipping with a non-native mode, and worse causes a normal
7146 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
7149 pipesrc
= I915_READ(PIPESRC(intel_crtc
->pipe
)) & 0x0fff0fff;
7150 intel_ring_emit(ring
, pf
| pipesrc
);
7151 intel_ring_advance(ring
);
7155 intel_unpin_fb_obj(obj
);
7161 * On gen7 we currently use the blit ring because (in early silicon at least)
7162 * the render ring doesn't give us interrpts for page flip completion, which
7163 * means clients will hang after the first flip is queued. Fortunately the
7164 * blit ring generates interrupts properly, so use it instead.
7166 static int intel_gen7_queue_flip(struct drm_device
*dev
,
7167 struct drm_crtc
*crtc
,
7168 struct drm_framebuffer
*fb
,
7169 struct drm_i915_gem_object
*obj
)
7171 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7172 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7173 struct intel_ring_buffer
*ring
= &dev_priv
->ring
[BCS
];
7174 uint32_t plane_bit
= 0;
7177 ret
= intel_pin_and_fence_fb_obj(dev
, obj
, ring
);
7181 switch(intel_crtc
->plane
) {
7183 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_A
;
7186 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_B
;
7189 plane_bit
= MI_DISPLAY_FLIP_IVB_PLANE_C
;
7192 WARN_ONCE(1, "unknown plane in flip command\n");
7197 ret
= intel_ring_begin(ring
, 4);
7201 intel_ring_emit(ring
, MI_DISPLAY_FLIP_I915
| plane_bit
);
7202 intel_ring_emit(ring
, (fb
->pitches
[0] | obj
->tiling_mode
));
7203 intel_ring_emit(ring
, obj
->gtt_offset
+ intel_crtc
->dspaddr_offset
);
7204 intel_ring_emit(ring
, (MI_NOOP
));
7205 intel_ring_advance(ring
);
7209 intel_unpin_fb_obj(obj
);
7214 static int intel_default_queue_flip(struct drm_device
*dev
,
7215 struct drm_crtc
*crtc
,
7216 struct drm_framebuffer
*fb
,
7217 struct drm_i915_gem_object
*obj
)
7222 static int intel_crtc_page_flip(struct drm_crtc
*crtc
,
7223 struct drm_framebuffer
*fb
,
7224 struct drm_pending_vblank_event
*event
)
7226 struct drm_device
*dev
= crtc
->dev
;
7227 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7228 struct intel_framebuffer
*intel_fb
;
7229 struct drm_i915_gem_object
*obj
;
7230 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
7231 struct intel_unpin_work
*work
;
7232 unsigned long flags
;
7235 /* Can't change pixel format via MI display flips. */
7236 if (fb
->pixel_format
!= crtc
->fb
->pixel_format
)
7240 * TILEOFF/LINOFF registers can't be changed via MI display flips.
7241 * Note that pitch changes could also affect these register.
7243 if (INTEL_INFO(dev
)->gen
> 3 &&
7244 (fb
->offsets
[0] != crtc
->fb
->offsets
[0] ||
7245 fb
->pitches
[0] != crtc
->fb
->pitches
[0]))
7248 work
= kzalloc(sizeof *work
, GFP_KERNEL
);
7252 work
->event
= event
;
7254 intel_fb
= to_intel_framebuffer(crtc
->fb
);
7255 work
->old_fb_obj
= intel_fb
->obj
;
7256 INIT_WORK(&work
->work
, intel_unpin_work_fn
);
7258 ret
= drm_vblank_get(dev
, intel_crtc
->pipe
);
7262 /* We borrow the event spin lock for protecting unpin_work */
7263 spin_lock_irqsave(&dev
->event_lock
, flags
);
7264 if (intel_crtc
->unpin_work
) {
7265 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7267 drm_vblank_put(dev
, intel_crtc
->pipe
);
7269 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
7272 intel_crtc
->unpin_work
= work
;
7273 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7275 intel_fb
= to_intel_framebuffer(fb
);
7276 obj
= intel_fb
->obj
;
7278 if (atomic_read(&intel_crtc
->unpin_work_count
) >= 2)
7279 flush_workqueue(dev_priv
->wq
);
7281 ret
= i915_mutex_lock_interruptible(dev
);
7285 /* Reference the objects for the scheduled work. */
7286 drm_gem_object_reference(&work
->old_fb_obj
->base
);
7287 drm_gem_object_reference(&obj
->base
);
7291 work
->pending_flip_obj
= obj
;
7293 work
->enable_stall_check
= true;
7295 /* Block clients from rendering to the new back buffer until
7296 * the flip occurs and the object is no longer visible.
7298 atomic_add(1 << intel_crtc
->plane
, &work
->old_fb_obj
->pending_flip
);
7299 atomic_inc(&intel_crtc
->unpin_work_count
);
7301 ret
= dev_priv
->display
.queue_flip(dev
, crtc
, fb
, obj
);
7303 goto cleanup_pending
;
7305 intel_disable_fbc(dev
);
7306 intel_mark_fb_busy(obj
);
7307 mutex_unlock(&dev
->struct_mutex
);
7309 trace_i915_flip_request(intel_crtc
->plane
, obj
);
7314 atomic_dec(&intel_crtc
->unpin_work_count
);
7315 atomic_sub(1 << intel_crtc
->plane
, &work
->old_fb_obj
->pending_flip
);
7316 drm_gem_object_unreference(&work
->old_fb_obj
->base
);
7317 drm_gem_object_unreference(&obj
->base
);
7318 mutex_unlock(&dev
->struct_mutex
);
7321 spin_lock_irqsave(&dev
->event_lock
, flags
);
7322 intel_crtc
->unpin_work
= NULL
;
7323 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
7325 drm_vblank_put(dev
, intel_crtc
->pipe
);
7332 static struct drm_crtc_helper_funcs intel_helper_funcs
= {
7333 .mode_set_base_atomic
= intel_pipe_set_base_atomic
,
7334 .load_lut
= intel_crtc_load_lut
,
7335 .disable
= intel_crtc_noop
,
7338 bool intel_encoder_check_is_cloned(struct intel_encoder
*encoder
)
7340 struct intel_encoder
*other_encoder
;
7341 struct drm_crtc
*crtc
= &encoder
->new_crtc
->base
;
7346 list_for_each_entry(other_encoder
,
7347 &crtc
->dev
->mode_config
.encoder_list
,
7350 if (&other_encoder
->new_crtc
->base
!= crtc
||
7351 encoder
== other_encoder
)
7360 static bool intel_encoder_crtc_ok(struct drm_encoder
*encoder
,
7361 struct drm_crtc
*crtc
)
7363 struct drm_device
*dev
;
7364 struct drm_crtc
*tmp
;
7367 WARN(!crtc
, "checking null crtc?\n");
7371 list_for_each_entry(tmp
, &dev
->mode_config
.crtc_list
, head
) {
7377 if (encoder
->possible_crtcs
& crtc_mask
)
7383 * intel_modeset_update_staged_output_state
7385 * Updates the staged output configuration state, e.g. after we've read out the
7388 static void intel_modeset_update_staged_output_state(struct drm_device
*dev
)
7390 struct intel_encoder
*encoder
;
7391 struct intel_connector
*connector
;
7393 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7395 connector
->new_encoder
=
7396 to_intel_encoder(connector
->base
.encoder
);
7399 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7402 to_intel_crtc(encoder
->base
.crtc
);
7407 * intel_modeset_commit_output_state
7409 * This function copies the stage display pipe configuration to the real one.
7411 static void intel_modeset_commit_output_state(struct drm_device
*dev
)
7413 struct intel_encoder
*encoder
;
7414 struct intel_connector
*connector
;
7416 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7418 connector
->base
.encoder
= &connector
->new_encoder
->base
;
7421 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7423 encoder
->base
.crtc
= &encoder
->new_crtc
->base
;
7427 static struct drm_display_mode
*
7428 intel_modeset_adjusted_mode(struct drm_crtc
*crtc
,
7429 struct drm_display_mode
*mode
)
7431 struct drm_device
*dev
= crtc
->dev
;
7432 struct drm_display_mode
*adjusted_mode
;
7433 struct drm_encoder_helper_funcs
*encoder_funcs
;
7434 struct intel_encoder
*encoder
;
7436 adjusted_mode
= drm_mode_duplicate(dev
, mode
);
7438 return ERR_PTR(-ENOMEM
);
7440 /* Pass our mode to the connectors and the CRTC to give them a chance to
7441 * adjust it according to limitations or connector properties, and also
7442 * a chance to reject the mode entirely.
7444 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7447 if (&encoder
->new_crtc
->base
!= crtc
)
7449 encoder_funcs
= encoder
->base
.helper_private
;
7450 if (!(encoder_funcs
->mode_fixup(&encoder
->base
, mode
,
7452 DRM_DEBUG_KMS("Encoder fixup failed\n");
7457 if (!(intel_crtc_mode_fixup(crtc
, mode
, adjusted_mode
))) {
7458 DRM_DEBUG_KMS("CRTC fixup failed\n");
7461 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
7463 return adjusted_mode
;
7465 drm_mode_destroy(dev
, adjusted_mode
);
7466 return ERR_PTR(-EINVAL
);
7469 /* Computes which crtcs are affected and sets the relevant bits in the mask. For
7470 * simplicity we use the crtc's pipe number (because it's easier to obtain). */
7472 intel_modeset_affected_pipes(struct drm_crtc
*crtc
, unsigned *modeset_pipes
,
7473 unsigned *prepare_pipes
, unsigned *disable_pipes
)
7475 struct intel_crtc
*intel_crtc
;
7476 struct drm_device
*dev
= crtc
->dev
;
7477 struct intel_encoder
*encoder
;
7478 struct intel_connector
*connector
;
7479 struct drm_crtc
*tmp_crtc
;
7481 *disable_pipes
= *modeset_pipes
= *prepare_pipes
= 0;
7483 /* Check which crtcs have changed outputs connected to them, these need
7484 * to be part of the prepare_pipes mask. We don't (yet) support global
7485 * modeset across multiple crtcs, so modeset_pipes will only have one
7486 * bit set at most. */
7487 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7489 if (connector
->base
.encoder
== &connector
->new_encoder
->base
)
7492 if (connector
->base
.encoder
) {
7493 tmp_crtc
= connector
->base
.encoder
->crtc
;
7495 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
7498 if (connector
->new_encoder
)
7500 1 << connector
->new_encoder
->new_crtc
->pipe
;
7503 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7505 if (encoder
->base
.crtc
== &encoder
->new_crtc
->base
)
7508 if (encoder
->base
.crtc
) {
7509 tmp_crtc
= encoder
->base
.crtc
;
7511 *prepare_pipes
|= 1 << to_intel_crtc(tmp_crtc
)->pipe
;
7514 if (encoder
->new_crtc
)
7515 *prepare_pipes
|= 1 << encoder
->new_crtc
->pipe
;
7518 /* Check for any pipes that will be fully disabled ... */
7519 list_for_each_entry(intel_crtc
, &dev
->mode_config
.crtc_list
,
7523 /* Don't try to disable disabled crtcs. */
7524 if (!intel_crtc
->base
.enabled
)
7527 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7529 if (encoder
->new_crtc
== intel_crtc
)
7534 *disable_pipes
|= 1 << intel_crtc
->pipe
;
7538 /* set_mode is also used to update properties on life display pipes. */
7539 intel_crtc
= to_intel_crtc(crtc
);
7541 *prepare_pipes
|= 1 << intel_crtc
->pipe
;
7543 /* We only support modeset on one single crtc, hence we need to do that
7544 * only for the passed in crtc iff we change anything else than just
7547 * This is actually not true, to be fully compatible with the old crtc
7548 * helper we automatically disable _any_ output (i.e. doesn't need to be
7549 * connected to the crtc we're modesetting on) if it's disconnected.
7550 * Which is a rather nutty api (since changed the output configuration
7551 * without userspace's explicit request can lead to confusion), but
7552 * alas. Hence we currently need to modeset on all pipes we prepare. */
7554 *modeset_pipes
= *prepare_pipes
;
7556 /* ... and mask these out. */
7557 *modeset_pipes
&= ~(*disable_pipes
);
7558 *prepare_pipes
&= ~(*disable_pipes
);
7561 static bool intel_crtc_in_use(struct drm_crtc
*crtc
)
7563 struct drm_encoder
*encoder
;
7564 struct drm_device
*dev
= crtc
->dev
;
7566 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
7567 if (encoder
->crtc
== crtc
)
7574 intel_modeset_update_state(struct drm_device
*dev
, unsigned prepare_pipes
)
7576 struct intel_encoder
*intel_encoder
;
7577 struct intel_crtc
*intel_crtc
;
7578 struct drm_connector
*connector
;
7580 list_for_each_entry(intel_encoder
, &dev
->mode_config
.encoder_list
,
7582 if (!intel_encoder
->base
.crtc
)
7585 intel_crtc
= to_intel_crtc(intel_encoder
->base
.crtc
);
7587 if (prepare_pipes
& (1 << intel_crtc
->pipe
))
7588 intel_encoder
->connectors_active
= false;
7591 intel_modeset_commit_output_state(dev
);
7593 /* Update computed state. */
7594 list_for_each_entry(intel_crtc
, &dev
->mode_config
.crtc_list
,
7596 intel_crtc
->base
.enabled
= intel_crtc_in_use(&intel_crtc
->base
);
7599 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
7600 if (!connector
->encoder
|| !connector
->encoder
->crtc
)
7603 intel_crtc
= to_intel_crtc(connector
->encoder
->crtc
);
7605 if (prepare_pipes
& (1 << intel_crtc
->pipe
)) {
7606 struct drm_property
*dpms_property
=
7607 dev
->mode_config
.dpms_property
;
7609 connector
->dpms
= DRM_MODE_DPMS_ON
;
7610 drm_connector_property_set_value(connector
,
7614 intel_encoder
= to_intel_encoder(connector
->encoder
);
7615 intel_encoder
->connectors_active
= true;
7621 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
7622 list_for_each_entry((intel_crtc), \
7623 &(dev)->mode_config.crtc_list, \
7625 if (mask & (1 <<(intel_crtc)->pipe)) \
7628 intel_modeset_check_state(struct drm_device
*dev
)
7630 struct intel_crtc
*crtc
;
7631 struct intel_encoder
*encoder
;
7632 struct intel_connector
*connector
;
7634 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7636 /* This also checks the encoder/connector hw state with the
7637 * ->get_hw_state callbacks. */
7638 intel_connector_check_state(connector
);
7640 WARN(&connector
->new_encoder
->base
!= connector
->base
.encoder
,
7641 "connector's staged encoder doesn't match current encoder\n");
7644 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7646 bool enabled
= false;
7647 bool active
= false;
7648 enum pipe pipe
, tracked_pipe
;
7650 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
7651 encoder
->base
.base
.id
,
7652 drm_get_encoder_name(&encoder
->base
));
7654 WARN(&encoder
->new_crtc
->base
!= encoder
->base
.crtc
,
7655 "encoder's stage crtc doesn't match current crtc\n");
7656 WARN(encoder
->connectors_active
&& !encoder
->base
.crtc
,
7657 "encoder's active_connectors set, but no crtc\n");
7659 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7661 if (connector
->base
.encoder
!= &encoder
->base
)
7664 if (connector
->base
.dpms
!= DRM_MODE_DPMS_OFF
)
7667 WARN(!!encoder
->base
.crtc
!= enabled
,
7668 "encoder's enabled state mismatch "
7669 "(expected %i, found %i)\n",
7670 !!encoder
->base
.crtc
, enabled
);
7671 WARN(active
&& !encoder
->base
.crtc
,
7672 "active encoder with no crtc\n");
7674 WARN(encoder
->connectors_active
!= active
,
7675 "encoder's computed active state doesn't match tracked active state "
7676 "(expected %i, found %i)\n", active
, encoder
->connectors_active
);
7678 active
= encoder
->get_hw_state(encoder
, &pipe
);
7679 WARN(active
!= encoder
->connectors_active
,
7680 "encoder's hw state doesn't match sw tracking "
7681 "(expected %i, found %i)\n",
7682 encoder
->connectors_active
, active
);
7684 if (!encoder
->base
.crtc
)
7687 tracked_pipe
= to_intel_crtc(encoder
->base
.crtc
)->pipe
;
7688 WARN(active
&& pipe
!= tracked_pipe
,
7689 "active encoder's pipe doesn't match"
7690 "(expected %i, found %i)\n",
7691 tracked_pipe
, pipe
);
7695 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
7697 bool enabled
= false;
7698 bool active
= false;
7700 DRM_DEBUG_KMS("[CRTC:%d]\n",
7701 crtc
->base
.base
.id
);
7703 WARN(crtc
->active
&& !crtc
->base
.enabled
,
7704 "active crtc, but not enabled in sw tracking\n");
7706 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
7708 if (encoder
->base
.crtc
!= &crtc
->base
)
7711 if (encoder
->connectors_active
)
7714 WARN(active
!= crtc
->active
,
7715 "crtc's computed active state doesn't match tracked active state "
7716 "(expected %i, found %i)\n", active
, crtc
->active
);
7717 WARN(enabled
!= crtc
->base
.enabled
,
7718 "crtc's computed enabled state doesn't match tracked enabled state "
7719 "(expected %i, found %i)\n", enabled
, crtc
->base
.enabled
);
7721 assert_pipe(dev
->dev_private
, crtc
->pipe
, crtc
->active
);
7725 bool intel_set_mode(struct drm_crtc
*crtc
,
7726 struct drm_display_mode
*mode
,
7727 int x
, int y
, struct drm_framebuffer
*fb
)
7729 struct drm_device
*dev
= crtc
->dev
;
7730 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
7731 struct drm_display_mode
*adjusted_mode
, saved_mode
, saved_hwmode
;
7732 struct intel_crtc
*intel_crtc
;
7733 unsigned disable_pipes
, prepare_pipes
, modeset_pipes
;
7736 intel_modeset_affected_pipes(crtc
, &modeset_pipes
,
7737 &prepare_pipes
, &disable_pipes
);
7739 DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
7740 modeset_pipes
, prepare_pipes
, disable_pipes
);
7742 for_each_intel_crtc_masked(dev
, disable_pipes
, intel_crtc
)
7743 intel_crtc_disable(&intel_crtc
->base
);
7745 saved_hwmode
= crtc
->hwmode
;
7746 saved_mode
= crtc
->mode
;
7748 /* Hack: Because we don't (yet) support global modeset on multiple
7749 * crtcs, we don't keep track of the new mode for more than one crtc.
7750 * Hence simply check whether any bit is set in modeset_pipes in all the
7751 * pieces of code that are not yet converted to deal with mutliple crtcs
7752 * changing their mode at the same time. */
7753 adjusted_mode
= NULL
;
7754 if (modeset_pipes
) {
7755 adjusted_mode
= intel_modeset_adjusted_mode(crtc
, mode
);
7756 if (IS_ERR(adjusted_mode
)) {
7761 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
) {
7762 if (intel_crtc
->base
.enabled
)
7763 dev_priv
->display
.crtc_disable(&intel_crtc
->base
);
7766 /* crtc->mode is already used by the ->mode_set callbacks, hence we need
7767 * to set it here already despite that we pass it down the callchain.
7772 /* Only after disabling all output pipelines that will be changed can we
7773 * update the the output configuration. */
7774 intel_modeset_update_state(dev
, prepare_pipes
);
7776 if (dev_priv
->display
.modeset_global_resources
)
7777 dev_priv
->display
.modeset_global_resources(dev
);
7779 /* Set up the DPLL and any encoders state that needs to adjust or depend
7782 for_each_intel_crtc_masked(dev
, modeset_pipes
, intel_crtc
) {
7783 ret
= !intel_crtc_mode_set(&intel_crtc
->base
,
7784 mode
, adjusted_mode
,
7790 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7791 for_each_intel_crtc_masked(dev
, prepare_pipes
, intel_crtc
)
7792 dev_priv
->display
.crtc_enable(&intel_crtc
->base
);
7794 if (modeset_pipes
) {
7795 /* Store real post-adjustment hardware mode. */
7796 crtc
->hwmode
= *adjusted_mode
;
7798 /* Calculate and store various constants which
7799 * are later needed by vblank and swap-completion
7800 * timestamping. They are derived from true hwmode.
7802 drm_calc_timestamping_constants(crtc
);
7805 /* FIXME: add subpixel order */
7807 drm_mode_destroy(dev
, adjusted_mode
);
7808 if (!ret
&& crtc
->enabled
) {
7809 crtc
->hwmode
= saved_hwmode
;
7810 crtc
->mode
= saved_mode
;
7812 intel_modeset_check_state(dev
);
7818 #undef for_each_intel_crtc_masked
7820 static void intel_set_config_free(struct intel_set_config
*config
)
7825 kfree(config
->save_connector_encoders
);
7826 kfree(config
->save_encoder_crtcs
);
7830 static int intel_set_config_save_state(struct drm_device
*dev
,
7831 struct intel_set_config
*config
)
7833 struct drm_encoder
*encoder
;
7834 struct drm_connector
*connector
;
7837 config
->save_encoder_crtcs
=
7838 kcalloc(dev
->mode_config
.num_encoder
,
7839 sizeof(struct drm_crtc
*), GFP_KERNEL
);
7840 if (!config
->save_encoder_crtcs
)
7843 config
->save_connector_encoders
=
7844 kcalloc(dev
->mode_config
.num_connector
,
7845 sizeof(struct drm_encoder
*), GFP_KERNEL
);
7846 if (!config
->save_connector_encoders
)
7849 /* Copy data. Note that driver private data is not affected.
7850 * Should anything bad happen only the expected state is
7851 * restored, not the drivers personal bookkeeping.
7854 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
7855 config
->save_encoder_crtcs
[count
++] = encoder
->crtc
;
7859 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
7860 config
->save_connector_encoders
[count
++] = connector
->encoder
;
7866 static void intel_set_config_restore_state(struct drm_device
*dev
,
7867 struct intel_set_config
*config
)
7869 struct intel_encoder
*encoder
;
7870 struct intel_connector
*connector
;
7874 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
7876 to_intel_crtc(config
->save_encoder_crtcs
[count
++]);
7880 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, base
.head
) {
7881 connector
->new_encoder
=
7882 to_intel_encoder(config
->save_connector_encoders
[count
++]);
7887 intel_set_config_compute_mode_changes(struct drm_mode_set
*set
,
7888 struct intel_set_config
*config
)
7891 /* We should be able to check here if the fb has the same properties
7892 * and then just flip_or_move it */
7893 if (set
->crtc
->fb
!= set
->fb
) {
7894 /* If we have no fb then treat it as a full mode set */
7895 if (set
->crtc
->fb
== NULL
) {
7896 DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
7897 config
->mode_changed
= true;
7898 } else if (set
->fb
== NULL
) {
7899 config
->mode_changed
= true;
7900 } else if (set
->fb
->depth
!= set
->crtc
->fb
->depth
) {
7901 config
->mode_changed
= true;
7902 } else if (set
->fb
->bits_per_pixel
!=
7903 set
->crtc
->fb
->bits_per_pixel
) {
7904 config
->mode_changed
= true;
7906 config
->fb_changed
= true;
7909 if (set
->fb
&& (set
->x
!= set
->crtc
->x
|| set
->y
!= set
->crtc
->y
))
7910 config
->fb_changed
= true;
7912 if (set
->mode
&& !drm_mode_equal(set
->mode
, &set
->crtc
->mode
)) {
7913 DRM_DEBUG_KMS("modes are different, full mode set\n");
7914 drm_mode_debug_printmodeline(&set
->crtc
->mode
);
7915 drm_mode_debug_printmodeline(set
->mode
);
7916 config
->mode_changed
= true;
7921 intel_modeset_stage_output_state(struct drm_device
*dev
,
7922 struct drm_mode_set
*set
,
7923 struct intel_set_config
*config
)
7925 struct drm_crtc
*new_crtc
;
7926 struct intel_connector
*connector
;
7927 struct intel_encoder
*encoder
;
7930 /* The upper layers ensure that we either disabl a crtc or have a list
7931 * of connectors. For paranoia, double-check this. */
7932 WARN_ON(!set
->fb
&& (set
->num_connectors
!= 0));
7933 WARN_ON(set
->fb
&& (set
->num_connectors
== 0));
7936 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7938 /* Otherwise traverse passed in connector list and get encoders
7940 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
7941 if (set
->connectors
[ro
] == &connector
->base
) {
7942 connector
->new_encoder
= connector
->encoder
;
7947 /* If we disable the crtc, disable all its connectors. Also, if
7948 * the connector is on the changing crtc but not on the new
7949 * connector list, disable it. */
7950 if ((!set
->fb
|| ro
== set
->num_connectors
) &&
7951 connector
->base
.encoder
&&
7952 connector
->base
.encoder
->crtc
== set
->crtc
) {
7953 connector
->new_encoder
= NULL
;
7955 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
7956 connector
->base
.base
.id
,
7957 drm_get_connector_name(&connector
->base
));
7961 if (&connector
->new_encoder
->base
!= connector
->base
.encoder
) {
7962 DRM_DEBUG_KMS("encoder changed, full mode switch\n");
7963 config
->mode_changed
= true;
7966 /* Disable all disconnected encoders. */
7967 if (connector
->base
.status
== connector_status_disconnected
)
7968 connector
->new_encoder
= NULL
;
7970 /* connector->new_encoder is now updated for all connectors. */
7972 /* Update crtc of enabled connectors. */
7974 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
7976 if (!connector
->new_encoder
)
7979 new_crtc
= connector
->new_encoder
->base
.crtc
;
7981 for (ro
= 0; ro
< set
->num_connectors
; ro
++) {
7982 if (set
->connectors
[ro
] == &connector
->base
)
7983 new_crtc
= set
->crtc
;
7986 /* Make sure the new CRTC will work with the encoder */
7987 if (!intel_encoder_crtc_ok(&connector
->new_encoder
->base
,
7991 connector
->encoder
->new_crtc
= to_intel_crtc(new_crtc
);
7993 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
7994 connector
->base
.base
.id
,
7995 drm_get_connector_name(&connector
->base
),
7999 /* Check for any encoders that needs to be disabled. */
8000 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
8002 list_for_each_entry(connector
,
8003 &dev
->mode_config
.connector_list
,
8005 if (connector
->new_encoder
== encoder
) {
8006 WARN_ON(!connector
->new_encoder
->new_crtc
);
8011 encoder
->new_crtc
= NULL
;
8013 /* Only now check for crtc changes so we don't miss encoders
8014 * that will be disabled. */
8015 if (&encoder
->new_crtc
->base
!= encoder
->base
.crtc
) {
8016 DRM_DEBUG_KMS("crtc changed, full mode switch\n");
8017 config
->mode_changed
= true;
8020 /* Now we've also updated encoder->new_crtc for all encoders. */
8025 static int intel_crtc_set_config(struct drm_mode_set
*set
)
8027 struct drm_device
*dev
;
8028 struct drm_mode_set save_set
;
8029 struct intel_set_config
*config
;
8034 BUG_ON(!set
->crtc
->helper_private
);
8039 /* The fb helper likes to play gross jokes with ->mode_set_config.
8040 * Unfortunately the crtc helper doesn't do much at all for this case,
8041 * so we have to cope with this madness until the fb helper is fixed up. */
8042 if (set
->fb
&& set
->num_connectors
== 0)
8046 DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
8047 set
->crtc
->base
.id
, set
->fb
->base
.id
,
8048 (int)set
->num_connectors
, set
->x
, set
->y
);
8050 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set
->crtc
->base
.id
);
8053 dev
= set
->crtc
->dev
;
8056 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
8060 ret
= intel_set_config_save_state(dev
, config
);
8064 save_set
.crtc
= set
->crtc
;
8065 save_set
.mode
= &set
->crtc
->mode
;
8066 save_set
.x
= set
->crtc
->x
;
8067 save_set
.y
= set
->crtc
->y
;
8068 save_set
.fb
= set
->crtc
->fb
;
8070 /* Compute whether we need a full modeset, only an fb base update or no
8071 * change at all. In the future we might also check whether only the
8072 * mode changed, e.g. for LVDS where we only change the panel fitter in
8074 intel_set_config_compute_mode_changes(set
, config
);
8076 ret
= intel_modeset_stage_output_state(dev
, set
, config
);
8080 if (config
->mode_changed
) {
8082 DRM_DEBUG_KMS("attempting to set mode from"
8084 drm_mode_debug_printmodeline(set
->mode
);
8087 if (!intel_set_mode(set
->crtc
, set
->mode
,
8088 set
->x
, set
->y
, set
->fb
)) {
8089 DRM_ERROR("failed to set mode on [CRTC:%d]\n",
8090 set
->crtc
->base
.id
);
8094 } else if (config
->fb_changed
) {
8095 ret
= intel_pipe_set_base(set
->crtc
,
8096 set
->x
, set
->y
, set
->fb
);
8099 intel_set_config_free(config
);
8104 intel_set_config_restore_state(dev
, config
);
8106 /* Try to restore the config */
8107 if (config
->mode_changed
&&
8108 !intel_set_mode(save_set
.crtc
, save_set
.mode
,
8109 save_set
.x
, save_set
.y
, save_set
.fb
))
8110 DRM_ERROR("failed to restore config after modeset failure\n");
8113 intel_set_config_free(config
);
8117 static const struct drm_crtc_funcs intel_crtc_funcs
= {
8118 .cursor_set
= intel_crtc_cursor_set
,
8119 .cursor_move
= intel_crtc_cursor_move
,
8120 .gamma_set
= intel_crtc_gamma_set
,
8121 .set_config
= intel_crtc_set_config
,
8122 .destroy
= intel_crtc_destroy
,
8123 .page_flip
= intel_crtc_page_flip
,
8126 static void intel_cpu_pll_init(struct drm_device
*dev
)
8128 if (IS_HASWELL(dev
))
8129 intel_ddi_pll_init(dev
);
8132 static void intel_pch_pll_init(struct drm_device
*dev
)
8134 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
8137 if (dev_priv
->num_pch_pll
== 0) {
8138 DRM_DEBUG_KMS("No PCH PLLs on this hardware, skipping initialisation\n");
8142 for (i
= 0; i
< dev_priv
->num_pch_pll
; i
++) {
8143 dev_priv
->pch_plls
[i
].pll_reg
= _PCH_DPLL(i
);
8144 dev_priv
->pch_plls
[i
].fp0_reg
= _PCH_FP0(i
);
8145 dev_priv
->pch_plls
[i
].fp1_reg
= _PCH_FP1(i
);
8149 static void intel_crtc_init(struct drm_device
*dev
, int pipe
)
8151 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
8152 struct intel_crtc
*intel_crtc
;
8155 intel_crtc
= kzalloc(sizeof(struct intel_crtc
) + (INTELFB_CONN_LIMIT
* sizeof(struct drm_connector
*)), GFP_KERNEL
);
8156 if (intel_crtc
== NULL
)
8159 drm_crtc_init(dev
, &intel_crtc
->base
, &intel_crtc_funcs
);
8161 drm_mode_crtc_set_gamma_size(&intel_crtc
->base
, 256);
8162 for (i
= 0; i
< 256; i
++) {
8163 intel_crtc
->lut_r
[i
] = i
;
8164 intel_crtc
->lut_g
[i
] = i
;
8165 intel_crtc
->lut_b
[i
] = i
;
8168 /* Swap pipes & planes for FBC on pre-965 */
8169 intel_crtc
->pipe
= pipe
;
8170 intel_crtc
->plane
= pipe
;
8171 intel_crtc
->cpu_transcoder
= pipe
;
8172 if (IS_MOBILE(dev
) && IS_GEN3(dev
)) {
8173 DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
8174 intel_crtc
->plane
= !pipe
;
8177 BUG_ON(pipe
>= ARRAY_SIZE(dev_priv
->plane_to_crtc_mapping
) ||
8178 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] != NULL
);
8179 dev_priv
->plane_to_crtc_mapping
[intel_crtc
->plane
] = &intel_crtc
->base
;
8180 dev_priv
->pipe_to_crtc_mapping
[intel_crtc
->pipe
] = &intel_crtc
->base
;
8182 intel_crtc
->bpp
= 24; /* default for pre-Ironlake */
8184 drm_crtc_helper_add(&intel_crtc
->base
, &intel_helper_funcs
);
8187 int intel_get_pipe_from_crtc_id(struct drm_device
*dev
, void *data
,
8188 struct drm_file
*file
)
8190 struct drm_i915_get_pipe_from_crtc_id
*pipe_from_crtc_id
= data
;
8191 struct drm_mode_object
*drmmode_obj
;
8192 struct intel_crtc
*crtc
;
8194 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
8197 drmmode_obj
= drm_mode_object_find(dev
, pipe_from_crtc_id
->crtc_id
,
8198 DRM_MODE_OBJECT_CRTC
);
8201 DRM_ERROR("no such CRTC id\n");
8205 crtc
= to_intel_crtc(obj_to_crtc(drmmode_obj
));
8206 pipe_from_crtc_id
->pipe
= crtc
->pipe
;
8211 static int intel_encoder_clones(struct intel_encoder
*encoder
)
8213 struct drm_device
*dev
= encoder
->base
.dev
;
8214 struct intel_encoder
*source_encoder
;
8218 list_for_each_entry(source_encoder
,
8219 &dev
->mode_config
.encoder_list
, base
.head
) {
8221 if (encoder
== source_encoder
)
8222 index_mask
|= (1 << entry
);
8224 /* Intel hw has only one MUX where enocoders could be cloned. */
8225 if (encoder
->cloneable
&& source_encoder
->cloneable
)
8226 index_mask
|= (1 << entry
);
8234 static bool has_edp_a(struct drm_device
*dev
)
8236 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8238 if (!IS_MOBILE(dev
))
8241 if ((I915_READ(DP_A
) & DP_DETECTED
) == 0)
8245 (I915_READ(ILK_DISPLAY_CHICKEN_FUSES
) & ILK_eDP_A_DISABLE
))
8251 static void intel_setup_outputs(struct drm_device
*dev
)
8253 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8254 struct intel_encoder
*encoder
;
8255 bool dpd_is_edp
= false;
8258 has_lvds
= intel_lvds_init(dev
);
8259 if (!has_lvds
&& !HAS_PCH_SPLIT(dev
)) {
8260 /* disable the panel fitter on everything but LVDS */
8261 I915_WRITE(PFIT_CONTROL
, 0);
8264 intel_crt_init(dev
);
8266 if (IS_HASWELL(dev
)) {
8269 /* Haswell uses DDI functions to detect digital outputs */
8270 found
= I915_READ(DDI_BUF_CTL_A
) & DDI_INIT_DISPLAY_DETECTED
;
8271 /* DDI A only supports eDP */
8273 intel_ddi_init(dev
, PORT_A
);
8275 /* DDI B, C and D detection is indicated by the SFUSE_STRAP
8277 found
= I915_READ(SFUSE_STRAP
);
8279 if (found
& SFUSE_STRAP_DDIB_DETECTED
)
8280 intel_ddi_init(dev
, PORT_B
);
8281 if (found
& SFUSE_STRAP_DDIC_DETECTED
)
8282 intel_ddi_init(dev
, PORT_C
);
8283 if (found
& SFUSE_STRAP_DDID_DETECTED
)
8284 intel_ddi_init(dev
, PORT_D
);
8285 } else if (HAS_PCH_SPLIT(dev
)) {
8287 dpd_is_edp
= intel_dpd_is_edp(dev
);
8290 intel_dp_init(dev
, DP_A
, PORT_A
);
8292 if (I915_READ(HDMIB
) & PORT_DETECTED
) {
8293 /* PCH SDVOB multiplex with HDMIB */
8294 found
= intel_sdvo_init(dev
, PCH_SDVOB
, true);
8296 intel_hdmi_init(dev
, HDMIB
, PORT_B
);
8297 if (!found
&& (I915_READ(PCH_DP_B
) & DP_DETECTED
))
8298 intel_dp_init(dev
, PCH_DP_B
, PORT_B
);
8301 if (I915_READ(HDMIC
) & PORT_DETECTED
)
8302 intel_hdmi_init(dev
, HDMIC
, PORT_C
);
8304 if (!dpd_is_edp
&& I915_READ(HDMID
) & PORT_DETECTED
)
8305 intel_hdmi_init(dev
, HDMID
, PORT_D
);
8307 if (I915_READ(PCH_DP_C
) & DP_DETECTED
)
8308 intel_dp_init(dev
, PCH_DP_C
, PORT_C
);
8310 if (I915_READ(PCH_DP_D
) & DP_DETECTED
)
8311 intel_dp_init(dev
, PCH_DP_D
, PORT_D
);
8312 } else if (IS_VALLEYVIEW(dev
)) {
8315 /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
8316 if (I915_READ(DP_C
) & DP_DETECTED
)
8317 intel_dp_init(dev
, DP_C
, PORT_C
);
8319 if (I915_READ(SDVOB
) & PORT_DETECTED
) {
8320 /* SDVOB multiplex with HDMIB */
8321 found
= intel_sdvo_init(dev
, SDVOB
, true);
8323 intel_hdmi_init(dev
, SDVOB
, PORT_B
);
8324 if (!found
&& (I915_READ(DP_B
) & DP_DETECTED
))
8325 intel_dp_init(dev
, DP_B
, PORT_B
);
8328 if (I915_READ(SDVOC
) & PORT_DETECTED
)
8329 intel_hdmi_init(dev
, SDVOC
, PORT_C
);
8331 } else if (SUPPORTS_DIGITAL_OUTPUTS(dev
)) {
8334 if (I915_READ(SDVOB
) & SDVO_DETECTED
) {
8335 DRM_DEBUG_KMS("probing SDVOB\n");
8336 found
= intel_sdvo_init(dev
, SDVOB
, true);
8337 if (!found
&& SUPPORTS_INTEGRATED_HDMI(dev
)) {
8338 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
8339 intel_hdmi_init(dev
, SDVOB
, PORT_B
);
8342 if (!found
&& SUPPORTS_INTEGRATED_DP(dev
)) {
8343 DRM_DEBUG_KMS("probing DP_B\n");
8344 intel_dp_init(dev
, DP_B
, PORT_B
);
8348 /* Before G4X SDVOC doesn't have its own detect register */
8350 if (I915_READ(SDVOB
) & SDVO_DETECTED
) {
8351 DRM_DEBUG_KMS("probing SDVOC\n");
8352 found
= intel_sdvo_init(dev
, SDVOC
, false);
8355 if (!found
&& (I915_READ(SDVOC
) & SDVO_DETECTED
)) {
8357 if (SUPPORTS_INTEGRATED_HDMI(dev
)) {
8358 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
8359 intel_hdmi_init(dev
, SDVOC
, PORT_C
);
8361 if (SUPPORTS_INTEGRATED_DP(dev
)) {
8362 DRM_DEBUG_KMS("probing DP_C\n");
8363 intel_dp_init(dev
, DP_C
, PORT_C
);
8367 if (SUPPORTS_INTEGRATED_DP(dev
) &&
8368 (I915_READ(DP_D
) & DP_DETECTED
)) {
8369 DRM_DEBUG_KMS("probing DP_D\n");
8370 intel_dp_init(dev
, DP_D
, PORT_D
);
8372 } else if (IS_GEN2(dev
))
8373 intel_dvo_init(dev
);
8375 if (SUPPORTS_TV(dev
))
8378 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, base
.head
) {
8379 encoder
->base
.possible_crtcs
= encoder
->crtc_mask
;
8380 encoder
->base
.possible_clones
=
8381 intel_encoder_clones(encoder
);
8384 if (HAS_PCH_IBX(dev
) || HAS_PCH_CPT(dev
))
8385 ironlake_init_pch_refclk(dev
);
8387 drm_helper_move_panel_connectors_to_head(dev
);
8390 static void intel_user_framebuffer_destroy(struct drm_framebuffer
*fb
)
8392 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
8394 drm_framebuffer_cleanup(fb
);
8395 drm_gem_object_unreference_unlocked(&intel_fb
->obj
->base
);
8400 static int intel_user_framebuffer_create_handle(struct drm_framebuffer
*fb
,
8401 struct drm_file
*file
,
8402 unsigned int *handle
)
8404 struct intel_framebuffer
*intel_fb
= to_intel_framebuffer(fb
);
8405 struct drm_i915_gem_object
*obj
= intel_fb
->obj
;
8407 return drm_gem_handle_create(file
, &obj
->base
, handle
);
8410 static const struct drm_framebuffer_funcs intel_fb_funcs
= {
8411 .destroy
= intel_user_framebuffer_destroy
,
8412 .create_handle
= intel_user_framebuffer_create_handle
,
8415 int intel_framebuffer_init(struct drm_device
*dev
,
8416 struct intel_framebuffer
*intel_fb
,
8417 struct drm_mode_fb_cmd2
*mode_cmd
,
8418 struct drm_i915_gem_object
*obj
)
8422 if (obj
->tiling_mode
== I915_TILING_Y
)
8425 if (mode_cmd
->pitches
[0] & 63)
8428 /* FIXME <= Gen4 stride limits are bit unclear */
8429 if (mode_cmd
->pitches
[0] > 32768)
8432 if (obj
->tiling_mode
!= I915_TILING_NONE
&&
8433 mode_cmd
->pitches
[0] != obj
->stride
)
8436 /* Reject formats not supported by any plane early. */
8437 switch (mode_cmd
->pixel_format
) {
8439 case DRM_FORMAT_RGB565
:
8440 case DRM_FORMAT_XRGB8888
:
8441 case DRM_FORMAT_ARGB8888
:
8443 case DRM_FORMAT_XRGB1555
:
8444 case DRM_FORMAT_ARGB1555
:
8445 if (INTEL_INFO(dev
)->gen
> 3)
8448 case DRM_FORMAT_XBGR8888
:
8449 case DRM_FORMAT_ABGR8888
:
8450 case DRM_FORMAT_XRGB2101010
:
8451 case DRM_FORMAT_ARGB2101010
:
8452 case DRM_FORMAT_XBGR2101010
:
8453 case DRM_FORMAT_ABGR2101010
:
8454 if (INTEL_INFO(dev
)->gen
< 4)
8457 case DRM_FORMAT_YUYV
:
8458 case DRM_FORMAT_UYVY
:
8459 case DRM_FORMAT_YVYU
:
8460 case DRM_FORMAT_VYUY
:
8461 if (INTEL_INFO(dev
)->gen
< 6)
8465 DRM_DEBUG_KMS("unsupported pixel format 0x%08x\n", mode_cmd
->pixel_format
);
8469 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
8470 if (mode_cmd
->offsets
[0] != 0)
8473 ret
= drm_framebuffer_init(dev
, &intel_fb
->base
, &intel_fb_funcs
);
8475 DRM_ERROR("framebuffer init failed %d\n", ret
);
8479 drm_helper_mode_fill_fb_struct(&intel_fb
->base
, mode_cmd
);
8480 intel_fb
->obj
= obj
;
8484 static struct drm_framebuffer
*
8485 intel_user_framebuffer_create(struct drm_device
*dev
,
8486 struct drm_file
*filp
,
8487 struct drm_mode_fb_cmd2
*mode_cmd
)
8489 struct drm_i915_gem_object
*obj
;
8491 obj
= to_intel_bo(drm_gem_object_lookup(dev
, filp
,
8492 mode_cmd
->handles
[0]));
8493 if (&obj
->base
== NULL
)
8494 return ERR_PTR(-ENOENT
);
8496 return intel_framebuffer_create(dev
, mode_cmd
, obj
);
8499 static const struct drm_mode_config_funcs intel_mode_funcs
= {
8500 .fb_create
= intel_user_framebuffer_create
,
8501 .output_poll_changed
= intel_fb_output_poll_changed
,
8504 /* Set up chip specific display functions */
8505 static void intel_init_display(struct drm_device
*dev
)
8507 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8509 /* We always want a DPMS function */
8510 if (IS_HASWELL(dev
)) {
8511 dev_priv
->display
.crtc_mode_set
= haswell_crtc_mode_set
;
8512 dev_priv
->display
.crtc_enable
= haswell_crtc_enable
;
8513 dev_priv
->display
.crtc_disable
= haswell_crtc_disable
;
8514 dev_priv
->display
.off
= haswell_crtc_off
;
8515 dev_priv
->display
.update_plane
= ironlake_update_plane
;
8516 } else if (HAS_PCH_SPLIT(dev
)) {
8517 dev_priv
->display
.crtc_mode_set
= ironlake_crtc_mode_set
;
8518 dev_priv
->display
.crtc_enable
= ironlake_crtc_enable
;
8519 dev_priv
->display
.crtc_disable
= ironlake_crtc_disable
;
8520 dev_priv
->display
.off
= ironlake_crtc_off
;
8521 dev_priv
->display
.update_plane
= ironlake_update_plane
;
8523 dev_priv
->display
.crtc_mode_set
= i9xx_crtc_mode_set
;
8524 dev_priv
->display
.crtc_enable
= i9xx_crtc_enable
;
8525 dev_priv
->display
.crtc_disable
= i9xx_crtc_disable
;
8526 dev_priv
->display
.off
= i9xx_crtc_off
;
8527 dev_priv
->display
.update_plane
= i9xx_update_plane
;
8530 /* Returns the core display clock speed */
8531 if (IS_VALLEYVIEW(dev
))
8532 dev_priv
->display
.get_display_clock_speed
=
8533 valleyview_get_display_clock_speed
;
8534 else if (IS_I945G(dev
) || (IS_G33(dev
) && !IS_PINEVIEW_M(dev
)))
8535 dev_priv
->display
.get_display_clock_speed
=
8536 i945_get_display_clock_speed
;
8537 else if (IS_I915G(dev
))
8538 dev_priv
->display
.get_display_clock_speed
=
8539 i915_get_display_clock_speed
;
8540 else if (IS_I945GM(dev
) || IS_845G(dev
) || IS_PINEVIEW_M(dev
))
8541 dev_priv
->display
.get_display_clock_speed
=
8542 i9xx_misc_get_display_clock_speed
;
8543 else if (IS_I915GM(dev
))
8544 dev_priv
->display
.get_display_clock_speed
=
8545 i915gm_get_display_clock_speed
;
8546 else if (IS_I865G(dev
))
8547 dev_priv
->display
.get_display_clock_speed
=
8548 i865_get_display_clock_speed
;
8549 else if (IS_I85X(dev
))
8550 dev_priv
->display
.get_display_clock_speed
=
8551 i855_get_display_clock_speed
;
8553 dev_priv
->display
.get_display_clock_speed
=
8554 i830_get_display_clock_speed
;
8556 if (HAS_PCH_SPLIT(dev
)) {
8558 dev_priv
->display
.fdi_link_train
= ironlake_fdi_link_train
;
8559 dev_priv
->display
.write_eld
= ironlake_write_eld
;
8560 } else if (IS_GEN6(dev
)) {
8561 dev_priv
->display
.fdi_link_train
= gen6_fdi_link_train
;
8562 dev_priv
->display
.write_eld
= ironlake_write_eld
;
8563 } else if (IS_IVYBRIDGE(dev
)) {
8564 /* FIXME: detect B0+ stepping and use auto training */
8565 dev_priv
->display
.fdi_link_train
= ivb_manual_fdi_link_train
;
8566 dev_priv
->display
.write_eld
= ironlake_write_eld
;
8567 dev_priv
->display
.modeset_global_resources
=
8568 ivb_modeset_global_resources
;
8569 } else if (IS_HASWELL(dev
)) {
8570 dev_priv
->display
.fdi_link_train
= hsw_fdi_link_train
;
8571 dev_priv
->display
.write_eld
= haswell_write_eld
;
8573 dev_priv
->display
.update_wm
= NULL
;
8574 } else if (IS_G4X(dev
)) {
8575 dev_priv
->display
.write_eld
= g4x_write_eld
;
8578 /* Default just returns -ENODEV to indicate unsupported */
8579 dev_priv
->display
.queue_flip
= intel_default_queue_flip
;
8581 switch (INTEL_INFO(dev
)->gen
) {
8583 dev_priv
->display
.queue_flip
= intel_gen2_queue_flip
;
8587 dev_priv
->display
.queue_flip
= intel_gen3_queue_flip
;
8592 dev_priv
->display
.queue_flip
= intel_gen4_queue_flip
;
8596 dev_priv
->display
.queue_flip
= intel_gen6_queue_flip
;
8599 dev_priv
->display
.queue_flip
= intel_gen7_queue_flip
;
8605 * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
8606 * resume, or other times. This quirk makes sure that's the case for
8609 static void quirk_pipea_force(struct drm_device
*dev
)
8611 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8613 dev_priv
->quirks
|= QUIRK_PIPEA_FORCE
;
8614 DRM_INFO("applying pipe a force quirk\n");
8618 * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
8620 static void quirk_ssc_force_disable(struct drm_device
*dev
)
8622 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8623 dev_priv
->quirks
|= QUIRK_LVDS_SSC_DISABLE
;
8624 DRM_INFO("applying lvds SSC disable quirk\n");
8628 * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
8631 static void quirk_invert_brightness(struct drm_device
*dev
)
8633 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8634 dev_priv
->quirks
|= QUIRK_INVERT_BRIGHTNESS
;
8635 DRM_INFO("applying inverted panel brightness quirk\n");
8638 struct intel_quirk
{
8640 int subsystem_vendor
;
8641 int subsystem_device
;
8642 void (*hook
)(struct drm_device
*dev
);
8645 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
8646 struct intel_dmi_quirk
{
8647 void (*hook
)(struct drm_device
*dev
);
8648 const struct dmi_system_id (*dmi_id_list
)[];
8651 static int intel_dmi_reverse_brightness(const struct dmi_system_id
*id
)
8653 DRM_INFO("Backlight polarity reversed on %s\n", id
->ident
);
8657 static const struct intel_dmi_quirk intel_dmi_quirks
[] = {
8659 .dmi_id_list
= &(const struct dmi_system_id
[]) {
8661 .callback
= intel_dmi_reverse_brightness
,
8662 .ident
= "NCR Corporation",
8663 .matches
= {DMI_MATCH(DMI_SYS_VENDOR
, "NCR Corporation"),
8664 DMI_MATCH(DMI_PRODUCT_NAME
, ""),
8667 { } /* terminating entry */
8669 .hook
= quirk_invert_brightness
,
8673 static struct intel_quirk intel_quirks
[] = {
8674 /* HP Mini needs pipe A force quirk (LP: #322104) */
8675 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force
},
8677 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
8678 { 0x2592, 0x1179, 0x0001, quirk_pipea_force
},
8680 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
8681 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force
},
8683 /* 830/845 need to leave pipe A & dpll A up */
8684 { 0x2562, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
8685 { 0x3577, PCI_ANY_ID
, PCI_ANY_ID
, quirk_pipea_force
},
8687 /* Lenovo U160 cannot use SSC on LVDS */
8688 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable
},
8690 /* Sony Vaio Y cannot use SSC on LVDS */
8691 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable
},
8693 /* Acer Aspire 5734Z must invert backlight brightness */
8694 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness
},
8697 static void intel_init_quirks(struct drm_device
*dev
)
8699 struct pci_dev
*d
= dev
->pdev
;
8702 for (i
= 0; i
< ARRAY_SIZE(intel_quirks
); i
++) {
8703 struct intel_quirk
*q
= &intel_quirks
[i
];
8705 if (d
->device
== q
->device
&&
8706 (d
->subsystem_vendor
== q
->subsystem_vendor
||
8707 q
->subsystem_vendor
== PCI_ANY_ID
) &&
8708 (d
->subsystem_device
== q
->subsystem_device
||
8709 q
->subsystem_device
== PCI_ANY_ID
))
8712 for (i
= 0; i
< ARRAY_SIZE(intel_dmi_quirks
); i
++) {
8713 if (dmi_check_system(*intel_dmi_quirks
[i
].dmi_id_list
) != 0)
8714 intel_dmi_quirks
[i
].hook(dev
);
8718 /* Disable the VGA plane that we never use */
8719 static void i915_disable_vga(struct drm_device
*dev
)
8721 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8725 if (HAS_PCH_SPLIT(dev
))
8726 vga_reg
= CPU_VGACNTRL
;
8730 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
8731 outb(SR01
, VGA_SR_INDEX
);
8732 sr1
= inb(VGA_SR_DATA
);
8733 outb(sr1
| 1<<5, VGA_SR_DATA
);
8734 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
8737 I915_WRITE(vga_reg
, VGA_DISP_DISABLE
);
8738 POSTING_READ(vga_reg
);
8741 void intel_modeset_init_hw(struct drm_device
*dev
)
8743 /* We attempt to init the necessary power wells early in the initialization
8744 * time, so the subsystems that expect power to be enabled can work.
8746 intel_init_power_wells(dev
);
8748 intel_prepare_ddi(dev
);
8750 intel_init_clock_gating(dev
);
8752 mutex_lock(&dev
->struct_mutex
);
8753 intel_enable_gt_powersave(dev
);
8754 mutex_unlock(&dev
->struct_mutex
);
8757 void intel_modeset_init(struct drm_device
*dev
)
8759 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8762 drm_mode_config_init(dev
);
8764 dev
->mode_config
.min_width
= 0;
8765 dev
->mode_config
.min_height
= 0;
8767 dev
->mode_config
.preferred_depth
= 24;
8768 dev
->mode_config
.prefer_shadow
= 1;
8770 dev
->mode_config
.funcs
= &intel_mode_funcs
;
8772 intel_init_quirks(dev
);
8776 intel_init_display(dev
);
8779 dev
->mode_config
.max_width
= 2048;
8780 dev
->mode_config
.max_height
= 2048;
8781 } else if (IS_GEN3(dev
)) {
8782 dev
->mode_config
.max_width
= 4096;
8783 dev
->mode_config
.max_height
= 4096;
8785 dev
->mode_config
.max_width
= 8192;
8786 dev
->mode_config
.max_height
= 8192;
8788 dev
->mode_config
.fb_base
= dev_priv
->mm
.gtt_base_addr
;
8790 DRM_DEBUG_KMS("%d display pipe%s available.\n",
8791 dev_priv
->num_pipe
, dev_priv
->num_pipe
> 1 ? "s" : "");
8793 for (i
= 0; i
< dev_priv
->num_pipe
; i
++) {
8794 intel_crtc_init(dev
, i
);
8795 ret
= intel_plane_init(dev
, i
);
8797 DRM_DEBUG_KMS("plane %d init failed: %d\n", i
, ret
);
8800 intel_cpu_pll_init(dev
);
8801 intel_pch_pll_init(dev
);
8803 /* Just disable it once at startup */
8804 i915_disable_vga(dev
);
8805 intel_setup_outputs(dev
);
8809 intel_connector_break_all_links(struct intel_connector
*connector
)
8811 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
8812 connector
->base
.encoder
= NULL
;
8813 connector
->encoder
->connectors_active
= false;
8814 connector
->encoder
->base
.crtc
= NULL
;
8817 static void intel_enable_pipe_a(struct drm_device
*dev
)
8819 struct intel_connector
*connector
;
8820 struct drm_connector
*crt
= NULL
;
8821 struct intel_load_detect_pipe load_detect_temp
;
8823 /* We can't just switch on the pipe A, we need to set things up with a
8824 * proper mode and output configuration. As a gross hack, enable pipe A
8825 * by enabling the load detect pipe once. */
8826 list_for_each_entry(connector
,
8827 &dev
->mode_config
.connector_list
,
8829 if (connector
->encoder
->type
== INTEL_OUTPUT_ANALOG
) {
8830 crt
= &connector
->base
;
8838 if (intel_get_load_detect_pipe(crt
, NULL
, &load_detect_temp
))
8839 intel_release_load_detect_pipe(crt
, &load_detect_temp
);
8845 intel_check_plane_mapping(struct intel_crtc
*crtc
)
8847 struct drm_i915_private
*dev_priv
= crtc
->base
.dev
->dev_private
;
8850 if (dev_priv
->num_pipe
== 1)
8853 reg
= DSPCNTR(!crtc
->plane
);
8854 val
= I915_READ(reg
);
8856 if ((val
& DISPLAY_PLANE_ENABLE
) &&
8857 (!!(val
& DISPPLANE_SEL_PIPE_MASK
) == crtc
->pipe
))
8863 static void intel_sanitize_crtc(struct intel_crtc
*crtc
)
8865 struct drm_device
*dev
= crtc
->base
.dev
;
8866 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8869 /* Clear any frame start delays used for debugging left by the BIOS */
8870 reg
= PIPECONF(crtc
->cpu_transcoder
);
8871 I915_WRITE(reg
, I915_READ(reg
) & ~PIPECONF_FRAME_START_DELAY_MASK
);
8873 /* We need to sanitize the plane -> pipe mapping first because this will
8874 * disable the crtc (and hence change the state) if it is wrong. Note
8875 * that gen4+ has a fixed plane -> pipe mapping. */
8876 if (INTEL_INFO(dev
)->gen
< 4 && !intel_check_plane_mapping(crtc
)) {
8877 struct intel_connector
*connector
;
8880 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
8881 crtc
->base
.base
.id
);
8883 /* Pipe has the wrong plane attached and the plane is active.
8884 * Temporarily change the plane mapping and disable everything
8886 plane
= crtc
->plane
;
8887 crtc
->plane
= !plane
;
8888 dev_priv
->display
.crtc_disable(&crtc
->base
);
8889 crtc
->plane
= plane
;
8891 /* ... and break all links. */
8892 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
8894 if (connector
->encoder
->base
.crtc
!= &crtc
->base
)
8897 intel_connector_break_all_links(connector
);
8900 WARN_ON(crtc
->active
);
8901 crtc
->base
.enabled
= false;
8904 if (dev_priv
->quirks
& QUIRK_PIPEA_FORCE
&&
8905 crtc
->pipe
== PIPE_A
&& !crtc
->active
) {
8906 /* BIOS forgot to enable pipe A, this mostly happens after
8907 * resume. Force-enable the pipe to fix this, the update_dpms
8908 * call below we restore the pipe to the right state, but leave
8909 * the required bits on. */
8910 intel_enable_pipe_a(dev
);
8913 /* Adjust the state of the output pipe according to whether we
8914 * have active connectors/encoders. */
8915 intel_crtc_update_dpms(&crtc
->base
);
8917 if (crtc
->active
!= crtc
->base
.enabled
) {
8918 struct intel_encoder
*encoder
;
8920 /* This can happen either due to bugs in the get_hw_state
8921 * functions or because the pipe is force-enabled due to the
8923 DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
8925 crtc
->base
.enabled
? "enabled" : "disabled",
8926 crtc
->active
? "enabled" : "disabled");
8928 crtc
->base
.enabled
= crtc
->active
;
8930 /* Because we only establish the connector -> encoder ->
8931 * crtc links if something is active, this means the
8932 * crtc is now deactivated. Break the links. connector
8933 * -> encoder links are only establish when things are
8934 * actually up, hence no need to break them. */
8935 WARN_ON(crtc
->active
);
8937 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
8938 WARN_ON(encoder
->connectors_active
);
8939 encoder
->base
.crtc
= NULL
;
8944 static void intel_sanitize_encoder(struct intel_encoder
*encoder
)
8946 struct intel_connector
*connector
;
8947 struct drm_device
*dev
= encoder
->base
.dev
;
8949 /* We need to check both for a crtc link (meaning that the
8950 * encoder is active and trying to read from a pipe) and the
8951 * pipe itself being active. */
8952 bool has_active_crtc
= encoder
->base
.crtc
&&
8953 to_intel_crtc(encoder
->base
.crtc
)->active
;
8955 if (encoder
->connectors_active
&& !has_active_crtc
) {
8956 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
8957 encoder
->base
.base
.id
,
8958 drm_get_encoder_name(&encoder
->base
));
8960 /* Connector is active, but has no active pipe. This is
8961 * fallout from our resume register restoring. Disable
8962 * the encoder manually again. */
8963 if (encoder
->base
.crtc
) {
8964 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
8965 encoder
->base
.base
.id
,
8966 drm_get_encoder_name(&encoder
->base
));
8967 encoder
->disable(encoder
);
8970 /* Inconsistent output/port/pipe state happens presumably due to
8971 * a bug in one of the get_hw_state functions. Or someplace else
8972 * in our code, like the register restore mess on resume. Clamp
8973 * things to off as a safer default. */
8974 list_for_each_entry(connector
,
8975 &dev
->mode_config
.connector_list
,
8977 if (connector
->encoder
!= encoder
)
8980 intel_connector_break_all_links(connector
);
8983 /* Enabled encoders without active connectors will be fixed in
8984 * the crtc fixup. */
8987 /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
8988 * and i915 state tracking structures. */
8989 void intel_modeset_setup_hw_state(struct drm_device
*dev
)
8991 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
8994 struct intel_crtc
*crtc
;
8995 struct intel_encoder
*encoder
;
8996 struct intel_connector
*connector
;
8998 if (IS_HASWELL(dev
)) {
8999 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
9001 if (tmp
& TRANS_DDI_FUNC_ENABLE
) {
9002 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
9003 case TRANS_DDI_EDP_INPUT_A_ON
:
9004 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
9007 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
9010 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
9015 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
9016 crtc
->cpu_transcoder
= TRANSCODER_EDP
;
9018 DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
9023 for_each_pipe(pipe
) {
9024 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
9026 tmp
= I915_READ(PIPECONF(crtc
->cpu_transcoder
));
9027 if (tmp
& PIPECONF_ENABLE
)
9028 crtc
->active
= true;
9030 crtc
->active
= false;
9032 crtc
->base
.enabled
= crtc
->active
;
9034 DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
9036 crtc
->active
? "enabled" : "disabled");
9039 if (IS_HASWELL(dev
))
9040 intel_ddi_setup_hw_pll_state(dev
);
9042 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9046 if (encoder
->get_hw_state(encoder
, &pipe
)) {
9047 encoder
->base
.crtc
=
9048 dev_priv
->pipe_to_crtc_mapping
[pipe
];
9050 encoder
->base
.crtc
= NULL
;
9053 encoder
->connectors_active
= false;
9054 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
9055 encoder
->base
.base
.id
,
9056 drm_get_encoder_name(&encoder
->base
),
9057 encoder
->base
.crtc
? "enabled" : "disabled",
9061 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
9063 if (connector
->get_hw_state(connector
)) {
9064 connector
->base
.dpms
= DRM_MODE_DPMS_ON
;
9065 connector
->encoder
->connectors_active
= true;
9066 connector
->base
.encoder
= &connector
->encoder
->base
;
9068 connector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
9069 connector
->base
.encoder
= NULL
;
9071 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
9072 connector
->base
.base
.id
,
9073 drm_get_connector_name(&connector
->base
),
9074 connector
->base
.encoder
? "enabled" : "disabled");
9077 /* HW state is read out, now we need to sanitize this mess. */
9078 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
,
9080 intel_sanitize_encoder(encoder
);
9083 for_each_pipe(pipe
) {
9084 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
9085 intel_sanitize_crtc(crtc
);
9088 intel_modeset_update_staged_output_state(dev
);
9090 intel_modeset_check_state(dev
);
9092 drm_mode_config_reset(dev
);
9095 void intel_modeset_gem_init(struct drm_device
*dev
)
9097 intel_modeset_init_hw(dev
);
9099 intel_setup_overlay(dev
);
9101 intel_modeset_setup_hw_state(dev
);
9104 void intel_modeset_cleanup(struct drm_device
*dev
)
9106 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9107 struct drm_crtc
*crtc
;
9108 struct intel_crtc
*intel_crtc
;
9110 drm_kms_helper_poll_fini(dev
);
9111 mutex_lock(&dev
->struct_mutex
);
9113 intel_unregister_dsm_handler();
9116 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
9117 /* Skip inactive CRTCs */
9121 intel_crtc
= to_intel_crtc(crtc
);
9122 intel_increase_pllclock(crtc
);
9125 intel_disable_fbc(dev
);
9127 intel_disable_gt_powersave(dev
);
9129 ironlake_teardown_rc6(dev
);
9131 if (IS_VALLEYVIEW(dev
))
9134 mutex_unlock(&dev
->struct_mutex
);
9136 /* Disable the irq before mode object teardown, for the irq might
9137 * enqueue unpin/hotplug work. */
9138 drm_irq_uninstall(dev
);
9139 cancel_work_sync(&dev_priv
->hotplug_work
);
9140 cancel_work_sync(&dev_priv
->rps
.work
);
9142 /* flush any delayed tasks or pending work */
9143 flush_scheduled_work();
9145 drm_mode_config_cleanup(dev
);
9149 * Return which encoder is currently attached for connector.
9151 struct drm_encoder
*intel_best_encoder(struct drm_connector
*connector
)
9153 return &intel_attached_encoder(connector
)->base
;
9156 void intel_connector_attach_encoder(struct intel_connector
*connector
,
9157 struct intel_encoder
*encoder
)
9159 connector
->encoder
= encoder
;
9160 drm_mode_connector_attach_encoder(&connector
->base
,
9165 * set vga decode state - true == enable VGA decode
9167 int intel_modeset_vga_set_state(struct drm_device
*dev
, bool state
)
9169 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
9172 pci_read_config_word(dev_priv
->bridge_dev
, INTEL_GMCH_CTRL
, &gmch_ctrl
);
9174 gmch_ctrl
&= ~INTEL_GMCH_VGA_DISABLE
;
9176 gmch_ctrl
|= INTEL_GMCH_VGA_DISABLE
;
9177 pci_write_config_word(dev_priv
->bridge_dev
, INTEL_GMCH_CTRL
, gmch_ctrl
);
9181 #ifdef CONFIG_DEBUG_FS
9182 #include <linux/seq_file.h>
9184 struct intel_display_error_state
{
9185 struct intel_cursor_error_state
{
9190 } cursor
[I915_MAX_PIPES
];
9192 struct intel_pipe_error_state
{
9202 } pipe
[I915_MAX_PIPES
];
9204 struct intel_plane_error_state
{
9212 } plane
[I915_MAX_PIPES
];
9215 struct intel_display_error_state
*
9216 intel_display_capture_error_state(struct drm_device
*dev
)
9218 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
9219 struct intel_display_error_state
*error
;
9220 enum transcoder cpu_transcoder
;
9223 error
= kmalloc(sizeof(*error
), GFP_ATOMIC
);
9228 cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
, i
);
9230 error
->cursor
[i
].control
= I915_READ(CURCNTR(i
));
9231 error
->cursor
[i
].position
= I915_READ(CURPOS(i
));
9232 error
->cursor
[i
].base
= I915_READ(CURBASE(i
));
9234 error
->plane
[i
].control
= I915_READ(DSPCNTR(i
));
9235 error
->plane
[i
].stride
= I915_READ(DSPSTRIDE(i
));
9236 error
->plane
[i
].size
= I915_READ(DSPSIZE(i
));
9237 error
->plane
[i
].pos
= I915_READ(DSPPOS(i
));
9238 error
->plane
[i
].addr
= I915_READ(DSPADDR(i
));
9239 if (INTEL_INFO(dev
)->gen
>= 4) {
9240 error
->plane
[i
].surface
= I915_READ(DSPSURF(i
));
9241 error
->plane
[i
].tile_offset
= I915_READ(DSPTILEOFF(i
));
9244 error
->pipe
[i
].conf
= I915_READ(PIPECONF(cpu_transcoder
));
9245 error
->pipe
[i
].source
= I915_READ(PIPESRC(i
));
9246 error
->pipe
[i
].htotal
= I915_READ(HTOTAL(cpu_transcoder
));
9247 error
->pipe
[i
].hblank
= I915_READ(HBLANK(cpu_transcoder
));
9248 error
->pipe
[i
].hsync
= I915_READ(HSYNC(cpu_transcoder
));
9249 error
->pipe
[i
].vtotal
= I915_READ(VTOTAL(cpu_transcoder
));
9250 error
->pipe
[i
].vblank
= I915_READ(VBLANK(cpu_transcoder
));
9251 error
->pipe
[i
].vsync
= I915_READ(VSYNC(cpu_transcoder
));
9258 intel_display_print_error_state(struct seq_file
*m
,
9259 struct drm_device
*dev
,
9260 struct intel_display_error_state
*error
)
9262 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
9265 seq_printf(m
, "Num Pipes: %d\n", dev_priv
->num_pipe
);
9267 seq_printf(m
, "Pipe [%d]:\n", i
);
9268 seq_printf(m
, " CONF: %08x\n", error
->pipe
[i
].conf
);
9269 seq_printf(m
, " SRC: %08x\n", error
->pipe
[i
].source
);
9270 seq_printf(m
, " HTOTAL: %08x\n", error
->pipe
[i
].htotal
);
9271 seq_printf(m
, " HBLANK: %08x\n", error
->pipe
[i
].hblank
);
9272 seq_printf(m
, " HSYNC: %08x\n", error
->pipe
[i
].hsync
);
9273 seq_printf(m
, " VTOTAL: %08x\n", error
->pipe
[i
].vtotal
);
9274 seq_printf(m
, " VBLANK: %08x\n", error
->pipe
[i
].vblank
);
9275 seq_printf(m
, " VSYNC: %08x\n", error
->pipe
[i
].vsync
);
9277 seq_printf(m
, "Plane [%d]:\n", i
);
9278 seq_printf(m
, " CNTR: %08x\n", error
->plane
[i
].control
);
9279 seq_printf(m
, " STRIDE: %08x\n", error
->plane
[i
].stride
);
9280 seq_printf(m
, " SIZE: %08x\n", error
->plane
[i
].size
);
9281 seq_printf(m
, " POS: %08x\n", error
->plane
[i
].pos
);
9282 seq_printf(m
, " ADDR: %08x\n", error
->plane
[i
].addr
);
9283 if (INTEL_INFO(dev
)->gen
>= 4) {
9284 seq_printf(m
, " SURF: %08x\n", error
->plane
[i
].surface
);
9285 seq_printf(m
, " TILEOFF: %08x\n", error
->plane
[i
].tile_offset
);
9288 seq_printf(m
, "Cursor [%d]:\n", i
);
9289 seq_printf(m
, " CNTR: %08x\n", error
->cursor
[i
].control
);
9290 seq_printf(m
, " POS: %08x\n", error
->cursor
[i
].position
);
9291 seq_printf(m
, " BASE: %08x\n", error
->cursor
[i
].base
);