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>
37 #include <drm/i915_drm.h>
44 #define HAS_eDP (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
47 static void intel_increase_pllclock(
struct drm_crtc *
crtc);
48 static void intel_crtc_update_cursor(
struct drm_crtc *
crtc,
bool on);
71 #define INTEL_P2_NUM 2
81 #define IRONLAKE_FDI_FREQ 2700000
117 .
dot = { .
min = 25000, .max = 350000 },
118 .vco = { .min = 930000, .max = 1400000 },
119 .n = { .min = 3, .max = 16 },
120 .m = { .min = 96, .max = 140 },
121 .m1 = { .min = 18, .max = 26 },
122 .m2 = { .min = 6, .max = 16 },
123 .p = { .min = 4, .max = 128 },
124 .p1 = { .min = 2, .max = 33 },
125 .p2 = { .dot_limit = 165000,
126 .p2_slow = 4, .p2_fast = 2 },
127 .find_pll = intel_find_best_PLL,
131 .
dot = { .
min = 25000, .max = 350000 },
132 .vco = { .min = 930000, .max = 1400000 },
133 .n = { .min = 3, .max = 16 },
134 .m = { .min = 96, .max = 140 },
135 .m1 = { .min = 18, .max = 26 },
136 .m2 = { .min = 6, .max = 16 },
137 .p = { .min = 4, .max = 128 },
138 .p1 = { .min = 1, .max = 6 },
139 .p2 = { .dot_limit = 165000,
140 .p2_slow = 14, .p2_fast = 7 },
141 .find_pll = intel_find_best_PLL,
145 .
dot = { .
min = 20000, .max = 400000 },
146 .vco = { .min = 1400000, .max = 2800000 },
147 .n = { .min = 1, .max = 6 },
148 .m = { .min = 70, .max = 120 },
149 .m1 = { .min = 10, .max = 22 },
150 .m2 = { .min = 5, .max = 9 },
151 .p = { .min = 5, .max = 80 },
152 .p1 = { .min = 1, .max = 8 },
153 .p2 = { .dot_limit = 200000,
154 .p2_slow = 10, .p2_fast = 5 },
155 .find_pll = intel_find_best_PLL,
159 .
dot = { .
min = 20000, .max = 400000 },
160 .vco = { .min = 1400000, .max = 2800000 },
161 .n = { .min = 1, .max = 6 },
162 .m = { .min = 70, .max = 120 },
163 .m1 = { .min = 10, .max = 22 },
164 .m2 = { .min = 5, .max = 9 },
165 .p = { .min = 7, .max = 98 },
166 .p1 = { .min = 1, .max = 8 },
167 .p2 = { .dot_limit = 112000,
168 .p2_slow = 14, .p2_fast = 7 },
169 .find_pll = intel_find_best_PLL,
174 .
dot = { .
min = 25000, .max = 270000 },
175 .vco = { .min = 1750000, .max = 3500000},
176 .n = { .min = 1, .max = 4 },
177 .m = { .min = 104, .max = 138 },
178 .m1 = { .min = 17, .max = 23 },
179 .m2 = { .min = 5, .max = 11 },
180 .p = { .min = 10, .max = 30 },
181 .p1 = { .min = 1, .max = 3},
182 .p2 = { .dot_limit = 270000,
186 .find_pll = intel_g4x_find_best_PLL,
190 .
dot = { .
min = 22000, .max = 400000 },
191 .vco = { .min = 1750000, .max = 3500000},
192 .n = { .min = 1, .max = 4 },
193 .m = { .min = 104, .max = 138 },
194 .m1 = { .min = 16, .max = 23 },
195 .m2 = { .min = 5, .max = 11 },
196 .p = { .min = 5, .max = 80 },
197 .p1 = { .min = 1, .max = 8},
198 .p2 = { .dot_limit = 165000,
199 .p2_slow = 10, .p2_fast = 5 },
200 .find_pll = intel_g4x_find_best_PLL,
203 static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
204 .
dot = { .
min = 20000, .max = 115000 },
205 .vco = { .min = 1750000, .max = 3500000 },
206 .n = { .min = 1, .max = 3 },
207 .m = { .min = 104, .max = 138 },
208 .m1 = { .min = 17, .max = 23 },
209 .m2 = { .min = 5, .max = 11 },
210 .p = { .min = 28, .max = 112 },
211 .p1 = { .min = 2, .max = 8 },
212 .p2 = { .dot_limit = 0,
213 .p2_slow = 14, .p2_fast = 14
215 .find_pll = intel_g4x_find_best_PLL,
218 static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
219 .
dot = { .
min = 80000, .max = 224000 },
220 .vco = { .min = 1750000, .max = 3500000 },
221 .n = { .min = 1, .max = 3 },
222 .m = { .min = 104, .max = 138 },
223 .m1 = { .min = 17, .max = 23 },
224 .m2 = { .min = 5, .max = 11 },
225 .p = { .min = 14, .max = 42 },
226 .p1 = { .min = 2, .max = 6 },
227 .p2 = { .dot_limit = 0,
228 .p2_slow = 7, .p2_fast = 7
230 .find_pll = intel_g4x_find_best_PLL,
234 .
dot = { .
min = 161670, .max = 227000 },
235 .vco = { .min = 1750000, .max = 3500000},
236 .n = { .min = 1, .max = 2 },
237 .m = { .min = 97, .max = 108 },
238 .m1 = { .min = 0x10, .max = 0x12 },
239 .m2 = { .min = 0x05, .max = 0x06 },
240 .p = { .min = 10, .max = 20 },
241 .p1 = { .min = 1, .max = 2},
242 .p2 = { .dot_limit = 0,
243 .p2_slow = 10, .p2_fast = 10 },
244 .find_pll = intel_find_pll_g4x_dp,
248 .
dot = { .
min = 20000, .max = 400000},
249 .vco = { .min = 1700000, .max = 3500000 },
251 .n = { .min = 3, .max = 6 },
252 .m = { .min = 2, .max = 256 },
254 .m1 = { .min = 0, .max = 0 },
255 .m2 = { .min = 0, .max = 254 },
256 .p = { .min = 5, .max = 80 },
257 .p1 = { .min = 1, .max = 8 },
258 .p2 = { .dot_limit = 200000,
259 .p2_slow = 10, .p2_fast = 5 },
260 .find_pll = intel_find_best_PLL,
264 .
dot = { .
min = 20000, .max = 400000 },
265 .vco = { .min = 1700000, .max = 3500000 },
266 .n = { .min = 3, .max = 6 },
267 .m = { .min = 2, .max = 256 },
268 .m1 = { .min = 0, .max = 0 },
269 .m2 = { .min = 0, .max = 254 },
270 .p = { .min = 7, .max = 112 },
271 .p1 = { .min = 1, .max = 8 },
272 .p2 = { .dot_limit = 112000,
273 .p2_slow = 14, .p2_fast = 14 },
274 .find_pll = intel_find_best_PLL,
283 .
dot = { .
min = 25000, .max = 350000 },
284 .vco = { .min = 1760000, .max = 3510000 },
285 .n = { .min = 1, .max = 5 },
286 .m = { .min = 79, .max = 127 },
287 .m1 = { .min = 12, .max = 22 },
288 .m2 = { .min = 5, .max = 9 },
289 .p = { .min = 5, .max = 80 },
290 .p1 = { .min = 1, .max = 8 },
291 .p2 = { .dot_limit = 225000,
292 .p2_slow = 10, .p2_fast = 5 },
293 .find_pll = intel_g4x_find_best_PLL,
296 static const intel_limit_t intel_limits_ironlake_single_lvds = {
297 .
dot = { .
min = 25000, .max = 350000 },
298 .vco = { .min = 1760000, .max = 3510000 },
299 .n = { .min = 1, .max = 3 },
300 .m = { .min = 79, .max = 118 },
301 .m1 = { .min = 12, .max = 22 },
302 .m2 = { .min = 5, .max = 9 },
303 .p = { .min = 28, .max = 112 },
304 .p1 = { .min = 2, .max = 8 },
305 .p2 = { .dot_limit = 225000,
306 .p2_slow = 14, .p2_fast = 14 },
307 .find_pll = intel_g4x_find_best_PLL,
310 static const intel_limit_t intel_limits_ironlake_dual_lvds = {
311 .
dot = { .
min = 25000, .max = 350000 },
312 .vco = { .min = 1760000, .max = 3510000 },
313 .n = { .min = 1, .max = 3 },
314 .m = { .min = 79, .max = 127 },
315 .m1 = { .min = 12, .max = 22 },
316 .m2 = { .min = 5, .max = 9 },
317 .p = { .min = 14, .max = 56 },
318 .p1 = { .min = 2, .max = 8 },
319 .p2 = { .dot_limit = 225000,
320 .p2_slow = 7, .p2_fast = 7 },
321 .find_pll = intel_g4x_find_best_PLL,
325 static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
326 .
dot = { .
min = 25000, .max = 350000 },
327 .vco = { .min = 1760000, .max = 3510000 },
328 .n = { .min = 1, .max = 2 },
329 .m = { .min = 79, .max = 126 },
330 .m1 = { .min = 12, .max = 22 },
331 .m2 = { .min = 5, .max = 9 },
332 .p = { .min = 28, .max = 112 },
333 .p1 = { .min = 2, .max = 8 },
334 .p2 = { .dot_limit = 225000,
335 .p2_slow = 14, .p2_fast = 14 },
336 .find_pll = intel_g4x_find_best_PLL,
339 static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
340 .
dot = { .
min = 25000, .max = 350000 },
341 .vco = { .min = 1760000, .max = 3510000 },
342 .n = { .min = 1, .max = 3 },
343 .m = { .min = 79, .max = 126 },
344 .m1 = { .min = 12, .max = 22 },
345 .m2 = { .min = 5, .max = 9 },
346 .p = { .min = 14, .max = 42 },
347 .p1 = { .min = 2, .max = 6 },
348 .p2 = { .dot_limit = 225000,
349 .p2_slow = 7, .p2_fast = 7 },
350 .find_pll = intel_g4x_find_best_PLL,
353 static const intel_limit_t intel_limits_ironlake_display_port = {
354 .
dot = { .
min = 25000, .max = 350000 },
355 .vco = { .min = 1760000, .max = 3510000},
356 .n = { .min = 1, .max = 2 },
357 .m = { .min = 81, .max = 90 },
358 .m1 = { .min = 12, .max = 22 },
359 .m2 = { .min = 5, .max = 9 },
360 .p = { .min = 10, .max = 20 },
361 .p1 = { .min = 1, .max = 2},
362 .p2 = { .dot_limit = 0,
363 .p2_slow = 10, .p2_fast = 10 },
364 .find_pll = intel_find_pll_ironlake_dp,
368 .
dot = { .
min = 25000, .max = 270000 },
369 .vco = { .min = 4000000, .max = 6000000 },
370 .n = { .min = 1, .max = 7 },
371 .m = { .min = 22, .max = 450 },
372 .m1 = { .min = 2, .max = 3 },
373 .m2 = { .min = 11, .max = 156 },
374 .p = { .min = 10, .max = 30 },
375 .p1 = { .min = 2, .max = 3 },
376 .p2 = { .dot_limit = 270000,
377 .p2_slow = 2, .p2_fast = 20 },
378 .find_pll = intel_vlv_find_best_pll,
382 .
dot = { .
min = 20000, .max = 165000 },
383 .vco = { .min = 5994000, .max = 4000000 },
384 .n = { .min = 1, .max = 7 },
385 .m = { .min = 60, .max = 300 },
386 .m1 = { .min = 2, .max = 3 },
387 .m2 = { .min = 11, .max = 156 },
388 .p = { .min = 10, .max = 30 },
389 .p1 = { .min = 2, .max = 3 },
390 .p2 = { .dot_limit = 270000,
391 .p2_slow = 2, .p2_fast = 20 },
392 .find_pll = intel_vlv_find_best_pll,
396 .
dot = { .
min = 162000, .max = 270000 },
397 .vco = { .min = 5994000, .max = 4000000 },
398 .n = { .min = 1, .max = 7 },
399 .m = { .min = 60, .max = 300 },
400 .m1 = { .min = 2, .max = 3 },
401 .m2 = { .min = 11, .max = 156 },
402 .p = { .min = 10, .max = 30 },
403 .p1 = { .min = 2, .max = 3 },
404 .p2 = { .dot_limit = 270000,
405 .p2_slow = 2, .p2_fast = 20 },
406 .find_pll = intel_vlv_find_best_pll,
416 DRM_ERROR(
"DPIO idle wait timed out\n");
424 DRM_ERROR(
"DPIO read wait timed out\n");
430 spin_unlock_irqrestore(&dev_priv->
dpio_lock, flags);
441 DRM_ERROR(
"DPIO idle wait timed out\n");
450 DRM_ERROR(
"DPIO write wait timed out\n");
453 spin_unlock_irqrestore(&dev_priv->
dpio_lock, flags);
456 static void vlv_init_dpio(
struct drm_device *dev)
467 static int intel_dual_link_lvds_callback(
const struct dmi_system_id *
id)
469 DRM_INFO(
"Forcing lvds to dual link mode on %s\n", id->
ident);
475 .callback = intel_dual_link_lvds_callback,
476 .ident =
"Apple MacBook Pro (Core i5/i7 Series)",
491 if (i915_lvds_channel_mode > 0)
492 return i915_lvds_channel_mode == 2;
521 if (is_dual_link_lvds(dev_priv,
PCH_LVDS)) {
523 if (refclk == 100000)
524 limit = &intel_limits_ironlake_dual_lvds_100m;
526 limit = &intel_limits_ironlake_dual_lvds;
528 if (refclk == 100000)
529 limit = &intel_limits_ironlake_single_lvds_100m;
531 limit = &intel_limits_ironlake_single_lvds;
535 limit = &intel_limits_ironlake_display_port;
537 limit = &intel_limits_ironlake_dac;
549 if (is_dual_link_lvds(dev_priv,
LVDS))
551 limit = &intel_limits_g4x_dual_channel_lvds;
554 limit = &intel_limits_g4x_single_channel_lvds;
557 limit = &intel_limits_g4x_hdmi;
559 limit = &intel_limits_g4x_sdvo;
561 limit = &intel_limits_g4x_display_port;
563 limit = &intel_limits_i9xx_sdvo;
574 limit = intel_ironlake_limit(crtc, refclk);
576 limit = intel_g4x_limit(crtc);
579 limit = &intel_limits_pineview_lvds;
581 limit = &intel_limits_pineview_sdvo;
584 limit = &intel_limits_vlv_dac;
586 limit = &intel_limits_vlv_hdmi;
588 limit = &intel_limits_vlv_dp;
591 limit = &intel_limits_i9xx_lvds;
593 limit = &intel_limits_i9xx_sdvo;
596 limit = &intel_limits_i8xx_lvds;
598 limit = &intel_limits_i8xx_dvo;
606 clock->
m = clock->
m2 + 2;
607 clock->
p = clock->
p1 * clock->
p2;
608 clock->
vco = refclk * clock->
m / clock->
n;
609 clock->
dot = clock->
vco / clock->
p;
615 pineview_clock(refclk, clock);
618 clock->
m = 5 * (clock->
m1 + 2) + (clock->
m2 + 2);
619 clock->
p = clock->
p1 * clock->
p2;
620 clock->
vco = refclk * clock->
m / (clock->
n + 2);
621 clock->
dot = clock->
vco / clock->
p;
633 if (encoder->
type == type)
639 #define INTELPllInvalid(s) do { return false; } while (0)
645 static bool intel_PLL_is_valid(
struct drm_device *dev,
651 if (clock->
p < limit->
p.
min || limit->
p.
max < clock->
p)
659 if (clock->
m < limit->
m.
min || limit->
m.
max < clock->
m)
661 if (clock->
n < limit->
n.
min || limit->
n.
max < clock->
n)
693 if (is_dual_link_lvds(dev_priv,
LVDS))
698 if (target < limit->p2.dot_limit)
704 memset(best_clock, 0,
sizeof(*best_clock));
713 for (clock.
n = limit->
n.
min;
714 clock.
n <= limit->
n.
max; clock.
n++) {
719 intel_clock(dev, refclk, &clock);
720 if (!intel_PLL_is_valid(dev, limit,
724 clock.
p != match_clock->
p)
727 this_err =
abs(clock.
dot - target);
728 if (this_err < err) {
737 return (err != target);
751 int err_most = (target >> 8) + (target >> 9);
767 if (target < limit->p2.dot_limit)
773 memset(best_clock, 0,
sizeof(*best_clock));
774 max_n = limit->
n.
max;
776 for (clock.
n = limit->
n.
min; clock.
n <= max_n; clock.
n++) {
786 intel_clock(dev, refclk, &clock);
787 if (!intel_PLL_is_valid(dev, limit,
791 clock.
p != match_clock->
p)
794 this_err =
abs(clock.
dot - target);
795 if (this_err < err_most) {
816 if (target < 200000) {
829 intel_clock(dev, refclk, &clock);
841 if (target < 200000) {
854 clock.
m = 5 * (clock.
m1 + 2) + (clock.
m2 + 2);
855 clock.
p = (clock.
p1 * clock.
p2);
856 clock.
dot = 96000 * clock.
m / (clock.
n + 2) / clock.
p;
866 u32 p1, p2, m1, m2, vco, bestn, bestm1, bestm2, bestp1, bestp2;
868 u32 updrate, minupdate, fracbits,
p;
869 unsigned long bestppm, ppm, absppm;
873 dotclk = target * 1000;
876 fastclk = dotclk / (2*100);
880 n = p = p1 = p2 = m = m1 = m2 = vco = bestn = 0;
881 bestm1 = bestm2 = bestp1 = bestp2 = 0;
884 for (n = limit->
n.
min; n <= ((refclk) / minupdate); n++) {
885 updrate = refclk /
n;
886 for (p1 = limit->
p1.
max; p1 > limit->
p1.
min; p1--) {
887 for (p2 = limit->
p2.
p2_fast+1; p2 > 0; p2--) {
892 for (m1 = limit->
m1.
min; m1 <= limit->m1.max; m1++) {
893 m2 = (((2*(fastclk * p * n / m1 )) +
894 refclk) / (2*refclk));
897 if (vco >= limit->
vco.
min && vco < limit->vco.max) {
898 ppm = 1000000 * ((vco /
p) - fastclk) / fastclk;
899 absppm = (ppm > 0) ? ppm : (-ppm);
900 if (absppm < 100 && ((p1 * p2) > (bestp1 * bestp2))) {
904 if (absppm < bestppm - 10) {
921 best_clock->
n = bestn;
922 best_clock->
m1 = bestm1;
923 best_clock->
m2 = bestm2;
924 best_clock->
p1 = bestp1;
925 best_clock->
p2 = bestp2;
930 static void ironlake_wait_for_vblank(
struct drm_device *dev,
int pipe)
938 DRM_DEBUG_KMS(
"vblank wait timed out\n");
955 ironlake_wait_for_vblank(dev, pipe);
979 DRM_DEBUG_KMS(
"vblank wait timed out\n");
1009 WARN(1,
"pipe_off wait timed out\n");
1011 u32 last_line, line_mask;
1024 }
while (((
I915_READ(reg) & line_mask) != last_line) &&
1027 WARN(1,
"pipe_off wait timed out\n");
1031 static const char *state_string(
bool enabled)
1033 return enabled ?
"on" :
"off";
1038 enum pipe pipe,
bool state)
1047 WARN(cur_state != state,
1048 "PLL state assertion failure (expected %s, current %s)\n",
1049 state_string(state), state_string(cur_state));
1051 #define assert_pll_enabled(d, p) assert_pll(d, p, true)
1052 #define assert_pll_disabled(d, p) assert_pll(d, p, false)
1064 DRM_DEBUG_DRIVER(
"LPT detected: skipping PCH PLL test\n");
1069 "asserting PCH PLL %s with no PLL\n", state_string(state)))
1074 WARN(cur_state != state,
1075 "PCH PLL state for reg %x assertion failure (expected %s, current %s), val=%08x\n",
1076 pll->
pll_reg, state_string(state), state_string(cur_state), val);
1084 if (!
WARN(((pch_dpll >> (4 * crtc->
pipe)) & 1) != cur_state,
1085 "PLL[%d] not attached to this transcoder %d: %08x\n",
1086 cur_state, crtc->
pipe, pch_dpll)) {
1087 cur_state = !!(val >> (4*crtc->
pipe + 3));
1088 WARN(cur_state != state,
1089 "PLL[%d] not %s on this transcoder %d: %08x\n",
1091 state_string(state),
1097 #define assert_pch_pll_enabled(d, p, c) assert_pch_pll(d, p, c, true)
1098 #define assert_pch_pll_disabled(d, p, c) assert_pch_pll(d, p, c, false)
1101 enum pipe pipe,
bool state)
1117 WARN(cur_state != state,
1118 "FDI TX state assertion failure (expected %s, current %s)\n",
1119 state_string(state), state_string(cur_state));
1121 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1122 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1125 enum pipe pipe,
bool state)
1132 DRM_ERROR(
"Attempting to enable FDI_RX on Haswell pipe > 0\n");
1139 WARN(cur_state != state,
1140 "FDI RX state assertion failure (expected %s, current %s)\n",
1141 state_string(state), state_string(cur_state));
1143 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1144 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1153 if (dev_priv->
info->gen == 5)
1162 WARN(!(val &
FDI_TX_PLL_ENABLE),
"FDI TX PLL assertion failure, should be active but is disabled\n");
1172 DRM_ERROR(
"Attempting to enable FDI on Haswell with pipe > 0\n");
1177 WARN(!(val &
FDI_RX_PLL_ENABLE),
"FDI RX PLL assertion failure, should be active but is disabled\n");
1185 enum pipe panel_pipe =
PIPE_A;
1204 WARN(panel_pipe == pipe && locked,
1205 "panel assertion failure, pipe %c regs locked\n",
1210 enum pipe pipe,
bool state)
1223 WARN(cur_state != state,
1224 "pipe %c assertion failure (expected %s, current %s)\n",
1225 pipe_name(pipe), state_string(state), state_string(cur_state));
1238 WARN(cur_state != state,
1239 "plane %c assertion failure (expected %s, current %s)\n",
1240 plane_name(plane), state_string(state), state_string(cur_state));
1243 #define assert_plane_enabled(d, p) assert_plane(d, p, true)
1244 #define assert_plane_disabled(d, p) assert_plane(d, p, false)
1258 "plane %c assertion failure, should be disabled but not\n",
1264 for (i = 0; i < 2; i++) {
1270 "plane %c assertion failure, should be off on pipe %c but is still active\n",
1281 DRM_DEBUG_DRIVER(
"LPT does not has PCH refclk, skipping check\n");
1288 WARN(!enabled,
"PCH refclk assertion failure, should be active but is disabled\n");
1302 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1325 enum pipe pipe,
u32 val)
1341 enum pipe pipe,
u32 val)
1357 enum pipe pipe,
u32 val)
1372 enum pipe pipe,
int reg,
u32 port_sel)
1375 WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
1376 "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
1381 "IBX PCH dp port still using transcoder B\n");
1385 enum pipe pipe,
int reg)
1388 WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
1389 "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
1394 "IBX PCH hdmi port still using transcoder B\n");
1409 WARN(adpa_pipe_enabled(dev_priv, pipe, val),
1410 "PCH VGA enabled on transcoder %c, should be disabled\n",
1415 WARN(lvds_pipe_enabled(dev_priv, pipe, val),
1416 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1419 assert_pch_hdmi_disabled(dev_priv, pipe,
HDMIB);
1420 assert_pch_hdmi_disabled(dev_priv, pipe,
HDMIC);
1421 assert_pch_hdmi_disabled(dev_priv, pipe,
HDMID);
1437 static void intel_enable_pll(
struct drm_i915_private *dev_priv,
enum pipe pipe)
1447 assert_panel_unlocked(dev_priv, pipe);
1474 static void intel_disable_pll(
struct drm_i915_private *dev_priv,
enum pipe pipe)
1497 unsigned long flags;
1502 DRM_ERROR(
"timeout waiting for SBI to become ready\n");
1516 DRM_ERROR(
"timeout waiting for SBI to complete write transaction\n");
1521 spin_unlock_irqrestore(&dev_priv->
dpio_lock, flags);
1527 unsigned long flags;
1533 DRM_ERROR(
"timeout waiting for SBI to become ready\n");
1545 DRM_ERROR(
"timeout waiting for SBI to complete read transaction\n");
1552 spin_unlock_irqrestore(&dev_priv->
dpio_lock, flags);
1580 DRM_DEBUG_KMS(
"enable PCH PLL %x (active %d, on? %d)for crtc %d\n",
1582 intel_crtc->
base.base.id);
1585 assert_pch_refclk_enabled(dev_priv);
1592 DRM_DEBUG_KMS(
"enabling PCH PLL %x\n", pll->
pll_reg);
1604 static void intel_disable_pch_pll(
struct intel_crtc *intel_crtc)
1619 DRM_DEBUG_KMS(
"disable PCH PLL %x (active %d, on? %d) for crtc %d\n",
1621 intel_crtc->
base.base.id);
1633 DRM_DEBUG_KMS(
"disabling PCH PLL %x\n", pll->
pll_reg);
1636 assert_transcoder_disabled(dev_priv, intel_crtc->
pipe);
1668 DRM_ERROR(
"Attempting to enable transcoder on Haswell with pipe > 0\n");
1696 DRM_ERROR(
"failed to enable transcoder %d\n", pipe);
1710 assert_pch_ports_disabled(dev_priv, pipe);
1718 DRM_ERROR(
"failed to disable transcoder %d\n", pipe);
1735 static void intel_enable_pipe(
struct drm_i915_private *dev_priv,
enum pipe pipe,
1751 assert_fdi_rx_pll_enabled(dev_priv, pipe);
1752 assert_fdi_tx_pll_enabled(dev_priv, pipe);
1788 assert_planes_disabled(dev_priv, pipe);
1823 enum plane plane,
enum pipe pipe)
1850 enum plane plane,
enum pipe pipe)
1860 I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
1877 alignment = 128 * 1024;
1879 alignment = 4 * 1024;
1881 alignment = 64 * 1024;
1889 DRM_ERROR(
"Y tiled not allowed for scan out buffers\n");
1895 dev_priv->
mm.interruptible =
false;
1898 goto err_interruptible;
1909 i915_gem_object_pin_fence(obj);
1911 dev_priv->
mm.interruptible =
true;
1917 dev_priv->
mm.interruptible =
true;
1923 i915_gem_object_unpin_fence(obj);
1929 static unsigned long gen4_compute_dspaddr_offset_xtiled(
int *
x,
int *
y,
1933 int tile_rows, tiles;
1937 tiles = *x / (512/
bpp);
1940 return tile_rows * pitch * 8 + tiles * 4096;
1951 int plane = intel_crtc->
plane;
1952 unsigned long linear_offset;
1961 DRM_ERROR(
"Can't update plane %d in SAREA\n", plane);
1966 obj = intel_fb->
obj;
1977 if (fb->
depth == 15)
2003 gen4_compute_dspaddr_offset_xtiled(&x, &y,
2011 DRM_DEBUG_KMS(
"Writing base %08X %08lX %d %d %d\n",
2026 static int ironlake_update_plane(
struct drm_crtc *crtc,
2034 int plane = intel_crtc->
plane;
2035 unsigned long linear_offset;
2045 DRM_ERROR(
"Can't update plane %d in SAREA\n", plane);
2050 obj = intel_fb->
obj;
2061 if (fb->
depth != 16)
2068 if (fb->
depth == 24)
2070 else if (fb->
depth == 30)
2092 gen4_compute_dspaddr_offset_xtiled(&x, &y,
2097 DRM_DEBUG_KMS(
"Writing base %08X %08lX %d %d %d\n",
2117 if (dev_priv->
display.disable_fbc)
2118 dev_priv->
display.disable_fbc(dev);
2119 intel_increase_pllclock(crtc);
2121 return dev_priv->
display.update_plane(crtc, fb, x, y);
2129 bool was_interruptible = dev_priv->
mm.interruptible;
2144 dev_priv->
mm.interruptible =
false;
2146 dev_priv->
mm.interruptible = was_interruptible;
2152 intel_pipe_set_base(
struct drm_crtc *crtc,
int x,
int y,
2164 DRM_ERROR(
"No FB bound\n");
2169 DRM_ERROR(
"no plane for crtc: plane %d, num_pipes %d\n",
2181 DRM_ERROR(
"pin & fence failed\n");
2186 intel_finish_fb(crtc->
fb);
2188 ret = dev_priv->
display.update_plane(crtc, fb, x, y);
2192 DRM_ERROR(
"failed to update base address\n");
2209 if (!dev->primary->master)
2212 master_priv = dev->primary->master->driver_priv;
2216 if (intel_crtc->
pipe) {
2227 static void ironlake_set_pll_edp(
struct drm_crtc *crtc,
int clock)
2233 DRM_DEBUG_KMS(
"eDP PLL enable for clock %d\n", clock);
2237 if (clock < 200000) {
2264 static void intel_fdi_normal_train(
struct drm_crtc *crtc)
2269 int pipe = intel_crtc->
pipe;
2305 static void cpt_phase_pointer_enable(
struct drm_device *dev,
int pipe)
2318 static void ironlake_fdi_link_train(
struct drm_crtc *crtc)
2323 int pipe = intel_crtc->
pipe;
2324 int plane = intel_crtc->
plane;
2345 temp |= (intel_crtc->
fdi_lanes - 1) << 19;
2367 for (tries = 0; tries < 5; tries++) {
2369 DRM_DEBUG_KMS(
"FDI_RX_IIR 0x%x\n", temp);
2372 DRM_DEBUG_KMS(
"FDI train 1 done.\n");
2378 DRM_ERROR(
"FDI train 1 fail!\n");
2397 for (tries = 0; tries < 5; tries++) {
2399 DRM_DEBUG_KMS(
"FDI_RX_IIR 0x%x\n", temp);
2403 DRM_DEBUG_KMS(
"FDI train 2 done.\n");
2408 DRM_ERROR(
"FDI train 2 fail!\n");
2410 DRM_DEBUG_KMS(
"FDI train done\n");
2414 static const int snb_b_fdi_train_param[] = {
2422 static void gen6_fdi_link_train(
struct drm_crtc *crtc)
2427 int pipe = intel_crtc->
pipe;
2445 temp |= (intel_crtc->
fdi_lanes - 1) << 19;
2468 cpt_phase_pointer_enable(dev, pipe);
2470 for (i = 0; i < 4; i++) {
2474 temp |= snb_b_fdi_train_param[
i];
2480 for (retry = 0; retry < 5; retry++) {
2483 DRM_DEBUG_KMS(
"FDI_RX_IIR 0x%x\n", temp);
2486 DRM_DEBUG_KMS(
"FDI train 1 done.\n");
2495 DRM_ERROR(
"FDI train 1 fail!\n");
2523 for (i = 0; i < 4; i++) {
2527 temp |= snb_b_fdi_train_param[
i];
2533 for (retry = 0; retry < 5; retry++) {
2536 DRM_DEBUG_KMS(
"FDI_RX_IIR 0x%x\n", temp);
2539 DRM_DEBUG_KMS(
"FDI train 2 done.\n");
2548 DRM_ERROR(
"FDI train 2 fail!\n");
2550 DRM_DEBUG_KMS(
"FDI train done.\n");
2554 static void ivb_manual_fdi_link_train(
struct drm_crtc *crtc)
2559 int pipe = intel_crtc->
pipe;
2577 temp |= (intel_crtc->
fdi_lanes - 1) << 19;
2597 cpt_phase_pointer_enable(dev, pipe);
2599 for (i = 0; i < 4; i++) {
2603 temp |= snb_b_fdi_train_param[
i];
2611 DRM_DEBUG_KMS(
"FDI_RX_IIR 0x%x\n", temp);
2616 DRM_DEBUG_KMS(
"FDI train 1 done.\n");
2621 DRM_ERROR(
"FDI train 1 fail!\n");
2641 for (i = 0; i < 4; i++) {
2645 temp |= snb_b_fdi_train_param[
i];
2653 DRM_DEBUG_KMS(
"FDI_RX_IIR 0x%x\n", temp);
2657 DRM_DEBUG_KMS(
"FDI train 2 done.\n");
2662 DRM_ERROR(
"FDI train 2 fail!\n");
2664 DRM_DEBUG_KMS(
"FDI train done.\n");
2667 static void ironlake_fdi_pll_enable(
struct intel_crtc *intel_crtc)
2671 int pipe = intel_crtc->
pipe;
2681 temp &= ~((0x7 << 19) | (0x7 << 16));
2682 temp |= (intel_crtc->
fdi_lanes - 1) << 19;
2711 static void ironlake_fdi_pll_disable(
struct intel_crtc *intel_crtc)
2715 int pipe = intel_crtc->
pipe;
2740 static void cpt_phase_pointer_disable(
struct drm_device *dev,
int pipe)
2751 static void ironlake_fdi_disable(
struct drm_crtc *crtc)
2756 int pipe = intel_crtc->
pipe;
2767 temp &= ~(0x7 << 16);
2781 cpt_phase_pointer_disable(dev, pipe);
2801 temp &= ~(0x07 << 16);
2809 static bool intel_crtc_has_pending_flip(
struct drm_crtc *crtc)
2813 unsigned long flags;
2821 spin_unlock_irqrestore(&dev->event_lock, flags);
2826 static void intel_crtc_wait_for_pending_flips(
struct drm_crtc *crtc)
2835 !intel_crtc_has_pending_flip(crtc));
2838 intel_finish_fb(crtc->
fb);
2842 static bool intel_crtc_driving_pch(
struct drm_crtc *crtc)
2860 DRM_DEBUG_KMS(
"Haswell detected DAC encoder, assuming is PCH\n");
2863 DRM_DEBUG_KMS(
"Haswell detected encoder %d, assuming is CPU\n",
2864 intel_encoder->
type);
2869 switch (intel_encoder->
type) {
2881 static void lpt_program_iclkip(
struct drm_crtc *crtc)
2885 u32 divsel, phaseinc, auxdiv, phasedir = 0;
2899 if (crtc->
mode.clock == 20000) {
2910 u32 iclk_virtual_root_freq = 172800 * 1000;
2911 u32 iclk_pi_range = 64;
2912 u32 desired_divisor, msb_divisor_value, pi_value;
2914 desired_divisor = (iclk_virtual_root_freq / crtc->
mode.clock);
2915 msb_divisor_value = desired_divisor / iclk_pi_range;
2916 pi_value = desired_divisor % iclk_pi_range;
2919 divsel = msb_divisor_value - 2;
2920 phaseinc = pi_value;
2929 DRM_DEBUG_KMS(
"iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
2945 intel_sbi_write(dev_priv,
2953 intel_sbi_write(dev_priv,
2961 intel_sbi_write(dev_priv,
2979 static void ironlake_pch_enable(
struct drm_crtc *crtc)
2984 int pipe = intel_crtc->
pipe;
2987 assert_transcoder_disabled(dev_priv, pipe);
2990 dev_priv->
display.fdi_link_train(crtc);
2992 intel_enable_pch_pll(intel_crtc);
2995 DRM_DEBUG_KMS(
"LPT detected: programming iCLKIP\n");
2996 lpt_program_iclkip(crtc);
3024 assert_panel_unlocked(dev_priv, pipe);
3035 intel_fdi_normal_train(crtc);
3067 DRM_DEBUG_KMS(
"Wrong PCH DP port return. Guess port B\n");
3075 intel_enable_transcoder(dev_priv, pipe);
3078 static void intel_put_pch_pll(
struct intel_crtc *intel_crtc)
3086 WARN(1,
"bad PCH PLL refcount\n");
3102 DRM_DEBUG_KMS(
"CRTC:%d reusing existing PCH PLL %x\n",
3109 i = intel_crtc->
pipe;
3112 DRM_DEBUG_KMS(
"CRTC:%d using pre-allocated PCH PLL %x\n",
3127 DRM_DEBUG_KMS(
"CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n",
3128 intel_crtc->
base.base.id,
3139 DRM_DEBUG_KMS(
"CRTC:%d allocated PCH PLL %x\n",
3150 DRM_DEBUG_DRIVER(
"using pll %d for pipe %d\n", i, intel_crtc->
pipe);
3152 DRM_DEBUG_DRIVER(
"switching PLL %x off\n", pll->
pll_reg);
3179 DRM_ERROR(
"mode set failed: pipe %d stuck\n", pipe);
3183 static void ironlake_crtc_enable(
struct drm_crtc *crtc)
3188 struct intel_encoder *encoder;
3189 int pipe = intel_crtc->
pipe;
3190 int plane = intel_crtc->
plane;
3199 intel_crtc->
active =
true;
3204 if ((temp & LVDS_PORT_EN) == 0)
3208 is_pch_port = intel_crtc_driving_pch(crtc);
3211 ironlake_fdi_pll_enable(intel_crtc);
3222 if (dev_priv->pch_pf_size &&
3239 intel_enable_pipe(dev_priv, pipe, is_pch_port);
3240 intel_enable_plane(dev_priv, plane, pipe);
3243 ironlake_pch_enable(crtc);
3249 intel_crtc_update_cursor(crtc,
true);
3252 encoder->
enable(encoder);
3273 struct intel_encoder *encoder;
3274 int pipe = intel_crtc->
pipe;
3275 int plane = intel_crtc->
plane;
3285 intel_crtc_wait_for_pending_flips(crtc);
3287 intel_crtc_update_cursor(crtc,
false);
3289 intel_disable_plane(dev_priv, plane, pipe);
3291 if (dev_priv->cfb_plane == plane)
3294 intel_disable_pipe(dev_priv, pipe);
3304 ironlake_fdi_disable(crtc);
3306 intel_disable_transcoder(dev_priv, pipe);
3336 intel_disable_pch_pll(intel_crtc);
3338 ironlake_fdi_pll_disable(intel_crtc);
3340 intel_crtc->
active =
false;
3348 static void ironlake_crtc_off(
struct drm_crtc *crtc)
3351 intel_put_pch_pll(intel_crtc);
3354 static void intel_crtc_dpms_overlay(
struct intel_crtc *intel_crtc,
bool enable)
3356 if (!enable && intel_crtc->
overlay) {
3361 dev_priv->
mm.interruptible =
false;
3363 dev_priv->
mm.interruptible =
true;
3372 static void i9xx_crtc_enable(
struct drm_crtc *crtc)
3377 struct intel_encoder *encoder;
3378 int pipe = intel_crtc->
pipe;
3379 int plane = intel_crtc->
plane;
3386 intel_crtc->
active =
true;
3389 intel_enable_pll(dev_priv, pipe);
3390 intel_enable_pipe(dev_priv, pipe,
false);
3391 intel_enable_plane(dev_priv, plane, pipe);
3397 intel_crtc_dpms_overlay(intel_crtc,
true);
3398 intel_crtc_update_cursor(crtc,
true);
3401 encoder->enable(encoder);
3409 struct intel_encoder *encoder;
3410 int pipe = intel_crtc->
pipe;
3411 int plane = intel_crtc->
plane;
3421 intel_crtc_wait_for_pending_flips(crtc);
3423 intel_crtc_dpms_overlay(intel_crtc,
false);
3424 intel_crtc_update_cursor(crtc, false);
3426 if (dev_priv->cfb_plane == plane)
3429 intel_disable_plane(dev_priv, plane, pipe);
3430 intel_disable_pipe(dev_priv, pipe);
3431 intel_disable_pll(dev_priv, pipe);
3433 intel_crtc->
active = false;
3442 static void intel_crtc_update_sarea(
struct drm_crtc *crtc,
3448 int pipe = intel_crtc->
pipe;
3450 if (!dev->primary->master)
3453 master_priv = dev->primary->master->driver_priv;
3459 master_priv->
sarea_priv->pipeA_w = enabled ? crtc->
mode.hdisplay : 0;
3460 master_priv->
sarea_priv->pipeA_h = enabled ? crtc->
mode.vdisplay : 0;
3463 master_priv->
sarea_priv->pipeB_w = enabled ? crtc->
mode.hdisplay : 0;
3464 master_priv->
sarea_priv->pipeB_h = enabled ? crtc->
mode.vdisplay : 0;
3467 DRM_ERROR(
"Can't update pipe %c in SAREA\n",
pipe_name(pipe));
3479 struct intel_encoder *intel_encoder;
3480 bool enable =
false;
3486 dev_priv->
display.crtc_enable(crtc);
3488 dev_priv->
display.crtc_disable(crtc);
3490 intel_crtc_update_sarea(crtc, enable);
3493 static void intel_crtc_noop(
struct drm_crtc *crtc)
3497 static void intel_crtc_disable(
struct drm_crtc *crtc)
3506 dev_priv->
display.crtc_disable(crtc);
3507 intel_crtc_update_sarea(crtc,
false);
3525 if (connector->
encoder->crtc != crtc)
3539 intel_crtc_disable(crtc);
3552 kfree(intel_encoder);
3573 static void intel_connector_check_state(
struct intel_connector *connector)
3576 struct intel_encoder *encoder = connector->
encoder;
3578 bool encoder_enabled;
3581 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s]\n",
3582 connector->
base.base.id,
3586 "wrong connector dpms state\n");
3588 "active connector not linked to encoder\n");
3590 "encoder->connectors_active not set\n");
3592 encoder_enabled = encoder->
get_hw_state(encoder, &pipe);
3593 WARN(!encoder_enabled,
"encoder not enabled\n");
3597 crtc = encoder->
base.crtc;
3602 "encoder active on the wrong pipe\n");
3610 struct intel_encoder *encoder = intel_attached_encoder(connector);
3616 if (mode == connector->
dpms)
3622 if (encoder->
base.crtc)
3636 struct intel_encoder *encoder = connector->
encoder;
3641 static bool intel_crtc_mode_fixup(
struct drm_crtc *crtc,
3669 static int valleyview_get_display_clock_speed(
struct drm_device *dev)
3674 static int i945_get_display_clock_speed(
struct drm_device *dev)
3679 static int i915_get_display_clock_speed(
struct drm_device *dev)
3684 static int i9xx_misc_get_display_clock_speed(
struct drm_device *dev)
3689 static int i915gm_get_display_clock_speed(
struct drm_device *dev)
3693 pci_read_config_word(dev->pdev,
GCFGC, &gcfgc);
3708 static int i865_get_display_clock_speed(
struct drm_device *dev)
3713 static int i855_get_display_clock_speed(
struct drm_device *dev)
3733 static int i830_get_display_clock_speed(
struct drm_device *dev)
3749 while (*num > 0xffffff || *den > 0xffffff) {
3757 int link_clock,
struct fdi_m_n *m_n)
3763 m_n->
gmch_n = link_clock * nlanes * 8;
3767 m_n->
link_n = link_clock;
3773 if (i915_panel_use_ssc >= 0)
3774 return i915_panel_use_ssc != 0;
3800 static bool intel_choose_pipe_bpp_dither(
struct drm_crtc *crtc,
3802 unsigned int *pipe_bpp,
3808 struct intel_encoder *intel_encoder;
3809 unsigned int display_bpc =
UINT_MAX, bpc;
3815 unsigned int lvds_bpc;
3823 if (lvds_bpc < display_bpc) {
3824 DRM_DEBUG_KMS(
"clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
3825 display_bpc = lvds_bpc;
3839 DRM_DEBUG_KMS(
"clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->
display_info.bpc);
3846 unsigned int edp_bpc = dev_priv->
edp.bpp / 3;
3848 if (edp_bpc && edp_bpc < display_bpc) {
3849 DRM_DEBUG_KMS(
"clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
3850 display_bpc = edp_bpc;
3860 if (display_bpc > 8 && display_bpc < 12) {
3861 DRM_DEBUG_KMS(
"forcing bpc to 12 for HDMI\n");
3864 DRM_DEBUG_KMS(
"forcing bpc to 8 for HDMI\n");
3871 DRM_DEBUG_KMS(
"Dithering DP to 6bpc\n");
3882 switch (fb->
depth) {
3900 DRM_DEBUG(
"unsupported depth, assuming 24 bits\n");
3901 bpc =
min((
unsigned int)8, display_bpc);
3905 display_bpc =
min(display_bpc, bpc);
3907 DRM_DEBUG_KMS(
"setting pipe bpc to %d (max display bpc %d)\n",
3910 *pipe_bpp = display_bpc * 3;
3912 return display_bpc != bpc;
3915 static int vlv_get_refclk(
struct drm_crtc *crtc)
3926 if (intel_panel_use_ssc(dev_priv))
3937 static int i9xx_get_refclk(
struct drm_crtc *crtc,
int num_connectors)
3944 refclk = vlv_get_refclk(crtc);
3946 intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
3948 DRM_DEBUG_KMS(
"using SSC reference clock of %d MHz\n",
3959 static void i9xx_adjust_sdvo_tv_clock(
struct drm_display_mode *adjusted_mode,
3964 if (adjusted_mode->
clock >= 100000
3965 && adjusted_mode->
clock < 140500) {
3971 }
else if (adjusted_mode->
clock >= 140500
3972 && adjusted_mode->
clock <= 200000) {
3981 static void i9xx_update_pll_dividers(
struct drm_crtc *crtc,
3988 int pipe = intel_crtc->
pipe;
3992 fp = (1 << clock->
n) << 16 | clock->
m1 << 8 | clock->
m2;
3994 fp2 = (1 << reduced_clock->
n) << 16 |
3995 reduced_clock->
m1 << 8 | reduced_clock->
m2;
3997 fp = clock->
n << 16 | clock->
m1 << 8 | clock->
m2;
3999 fp2 = reduced_clock->
n << 16 | reduced_clock->
m1 << 8 |
4007 reduced_clock && i915_powersave) {
4021 int pipe = intel_crtc->
pipe;
4029 temp &= ~LVDS_PIPEB_SELECT;
4060 static void vlv_update_pll(
struct drm_crtc *crtc,
4064 int refclk,
int num_connectors)
4069 int pipe = intel_crtc->
pipe;
4070 u32 dpll, mdiv, pdiv;
4071 u32 bestn, bestm1, bestm2, bestp1, bestp2;
4094 intel_dpio_write(dev_priv,
DPIO_DIV(pipe), mdiv);
4096 intel_dpio_write(dev_priv,
DPIO_CORE_CLK(pipe), 0x01000000);
4101 intel_dpio_write(dev_priv,
DPIO_REFSFR(pipe), pdiv);
4109 DRM_ERROR(
"DPLL %d failed to lock\n", pipe);
4112 u32 temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4126 static void i9xx_update_pll(
struct drm_crtc *crtc,
4135 int pipe = intel_crtc->
pipe;
4149 int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
4150 if (pixel_multiplier > 1) {
4164 if (
IS_G4X(dev) && reduced_clock)
4167 switch (clock->
p2) {
4191 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4206 intel_update_lvds(crtc, clock, adjusted_mode);
4220 temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4237 static void i8xx_update_pll(
struct drm_crtc *crtc,
4245 int pipe = intel_crtc->
pipe;
4266 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4281 intel_update_lvds(crtc, clock, adjusted_mode);
4297 static int i9xx_crtc_mode_set(
struct drm_crtc *crtc,
4306 int pipe = intel_crtc->
pipe;
4307 int plane = intel_crtc->
plane;
4308 int refclk, num_connectors = 0;
4310 u32 dspcntr, pipeconf, vsyncshift;
4311 bool ok, has_reduced_clock =
false, is_sdvo =
false;
4312 bool is_lvds =
false, is_tv =
false, is_dp =
false;
4313 struct intel_encoder *encoder;
4318 switch (encoder->
type) {
4339 refclk = i9xx_get_refclk(crtc, num_connectors);
4350 DRM_ERROR(
"Couldn't find PLL settings for mode!\n");
4355 intel_crtc_update_cursor(crtc,
true);
4364 has_reduced_clock = limit->
find_pll(limit, crtc,
4371 if (is_sdvo && is_tv)
4372 i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
4374 i9xx_update_pll_dividers(crtc, &clock, has_reduced_clock ?
4375 &reduced_clock :
NULL);
4378 i8xx_update_pll(crtc, adjusted_mode, &clock, num_connectors);
4380 vlv_update_pll(crtc, mode,adjusted_mode, &clock,
NULL,
4381 refclk, num_connectors);
4383 i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
4384 has_reduced_clock ? &reduced_clock :
NULL,
4406 dev_priv->
display.get_display_clock_speed(dev) * 9 / 10)
4422 DRM_DEBUG_KMS(
"Mode for pipe %c:\n", pipe == 0 ?
'A' :
'B');
4427 DRM_DEBUG_KMS(
"enabling CxSR downclocking\n");
4430 DRM_DEBUG_KMS(
"disabling CxSR downclocking\n");
4435 pipeconf &= ~PIPECONF_INTERLACE_MASK;
4484 intel_enable_pipe(dev_priv, pipe,
false);
4491 ret = intel_pipe_set_base(crtc, x, y, fb);
4505 struct intel_encoder *encoder;
4507 bool has_lvds =
false;
4508 bool has_cpu_edp =
false;
4509 bool has_pch_edp =
false;
4510 bool has_panel =
false;
4511 bool has_ck505 =
false;
4512 bool can_ssc =
false;
4517 switch (encoder->
type) {
4534 can_ssc = has_ck505;
4540 DRM_DEBUG_KMS(
"has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n",
4541 has_panel, has_lvds, has_pch_edp, has_cpu_edp,
4563 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4564 DRM_DEBUG_KMS(
"Using SSC on panel\n");
4578 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4579 DRM_DEBUG_KMS(
"Using SSC on eDP\n");
4591 DRM_DEBUG_KMS(
"Disabling SSC entirely\n");
4615 static int ironlake_get_refclk(
struct drm_crtc *crtc)
4619 struct intel_encoder *encoder;
4620 struct intel_encoder *edp_encoder =
NULL;
4621 int num_connectors = 0;
4622 bool is_lvds =
false;
4625 switch (encoder->
type) {
4630 edp_encoder = encoder;
4636 if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
4637 DRM_DEBUG_KMS(
"using SSC reference clock of %d MHz\n",
4645 static void ironlake_set_pipeconf(
struct drm_crtc *crtc,
4651 int pipe = intel_crtc->
pipe;
4657 switch (intel_crtc->
bpp) {
4679 val &= ~PIPECONF_INTERLACE_MASK;
4689 static bool ironlake_compute_clocks(
struct drm_crtc *crtc,
4692 bool *has_reduced_clock,
4697 struct intel_encoder *intel_encoder;
4700 bool ret, is_sdvo =
false, is_tv =
false, is_lvds =
false;
4703 switch (intel_encoder->
type) {
4719 refclk = ironlake_get_refclk(crtc);
4739 *has_reduced_clock = limit->
find_pll(limit, crtc,
4746 if (is_sdvo && is_tv)
4747 i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
4752 static int ironlake_crtc_mode_set(
struct drm_crtc *crtc,
4761 int pipe = intel_crtc->
pipe;
4762 int plane = intel_crtc->
plane;
4763 int num_connectors = 0;
4765 u32 dpll, fp = 0, fp2 = 0;
4766 bool ok, has_reduced_clock =
false, is_sdvo =
false;
4767 bool is_crt =
false, is_lvds =
false, is_tv =
false, is_dp =
false;
4768 struct intel_encoder *encoder, *edp_encoder =
NULL;
4772 int target_clock, pixel_multiplier, lane, link_bw, factor;
4773 unsigned int pipe_bpp;
4775 bool is_cpu_edp =
false, is_pch_edp =
false;
4778 switch (encoder->
type) {
4803 edp_encoder = encoder;
4810 ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
4811 &has_reduced_clock, &reduced_clock);
4813 DRM_ERROR(
"Couldn't find PLL settings for mode!\n");
4818 intel_crtc_update_cursor(crtc,
true);
4821 pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
4835 link_bw = intel_fdi_link_freq(dev) *
MHz(100)/
KHz(1)/10;
4842 target_clock = mode->
clock;
4844 target_clock = adjusted_mode->
clock;
4847 dither = intel_choose_pipe_bpp_dither(crtc, fb, &pipe_bpp,
4852 if (pipe_bpp != 18 && pipe_bpp != 24 && pipe_bpp != 30 &&
4854 WARN(1,
"intel_choose_pipe_bpp returned invalid value %d\n",
4858 intel_crtc->
bpp = pipe_bpp;
4866 u32 bps = target_clock * intel_crtc->
bpp * 21 / 20;
4867 lane = bps / (link_bw * 8) + 1;
4872 if (pixel_multiplier > 1)
4873 link_bw *= pixel_multiplier;
4874 ironlake_compute_m_n(intel_crtc->
bpp, lane, target_clock, link_bw,
4877 fp = clock.
n << 16 | clock.
m1 << 8 | clock.
m2;
4878 if (has_reduced_clock)
4879 fp2 = reduced_clock.
n << 16 | reduced_clock.
m1 << 8 |
4885 if ((intel_panel_use_ssc(dev_priv) &&
4889 }
else if (is_sdvo && is_tv)
4892 if (clock.
m < factor * clock.
n)
4902 int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
4903 if (pixel_multiplier > 1) {
4908 if (is_dp && !is_cpu_edp)
4931 if (is_sdvo && is_tv)
4937 else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4942 DRM_DEBUG_KMS(
"Mode for pipe %d:\n", pipe);
4948 DRM_DEBUG_KMS(
"LPT detected: no PLL for pipe %d necessary\n",
4950 }
else if (!is_cpu_edp) {
4953 pll = intel_get_pch_pll(intel_crtc, dpll, fp);
4955 DRM_DEBUG_DRIVER(
"failed to find PLL for pipe %d\n",
4960 intel_put_pch_pll(intel_crtc);
4970 temp &= ~PORT_TRANS_SEL_MASK;
4976 temp &= ~LVDS_PIPEB_SELECT;
5001 if (is_dp && !is_cpu_edp) {
5028 if (is_lvds && has_reduced_clock && i915_powersave) {
5079 ironlake_set_pll_edp(crtc, adjusted_mode->
clock);
5081 ironlake_set_pipeconf(crtc, adjusted_mode, dither);
5089 ret = intel_pipe_set_base(crtc, x, y, fb);
5098 static int intel_crtc_mode_set(
struct drm_crtc *crtc,
5107 int pipe = intel_crtc->
pipe;
5112 ret = dev_priv->
display.crtc_mode_set(crtc, mode, adjusted_mode,
5119 static bool intel_eld_uptodate(
struct drm_connector *connector,
5141 for (i = 0; i < eld[2]; i++)
5164 if (intel_eld_uptodate(connector,
5172 len = (i >> 9) & 0x1f;
5179 DRM_DEBUG_DRIVER(
"ELD size %d\n", len);
5180 for (i = 0; i < len; i++)
5188 static void haswell_write_eld(
struct drm_connector *connector,
5206 DRM_DEBUG_DRIVER(
"HDMI: Haswell Audio initialize....\n");
5209 DRM_DEBUG_DRIVER(
"HDMI audio: enable codec\n");
5219 DRM_DEBUG_DRIVER(
"HDMI audio: pin eld vld status=0x%8x\n", tmp);
5223 DRM_DEBUG_DRIVER(
"HDMI audio: eld vld status=0x%8x\n", tmp);
5227 DRM_DEBUG_DRIVER(
"HDMI audio: audio conf: 0x%8x\n", tmp);
5232 DRM_DEBUG_DRIVER(
"ELD on pipe %c\n",
pipe_name(pipe));
5237 DRM_DEBUG_DRIVER(
"ELD: DisplayPort detected\n");
5243 if (intel_eld_uptodate(connector,
5244 aud_cntrl_st2, eldv,
5260 DRM_DEBUG_DRIVER(
"port num:%d\n", i);
5263 DRM_DEBUG_DRIVER(
"ELD size %d\n", len);
5264 for (i = 0; i < len; i++)
5273 static void ironlake_write_eld(
struct drm_connector *connector,
5299 DRM_DEBUG_DRIVER(
"ELD on pipe %c\n",
pipe_name(pipe));
5304 DRM_DEBUG_DRIVER(
"Audio directed to unknown port\n");
5310 DRM_DEBUG_DRIVER(
"ELD on port %c\n",
'A' + i);
5315 DRM_DEBUG_DRIVER(
"ELD: DisplayPort detected\n");
5321 if (intel_eld_uptodate(connector,
5322 aud_cntrl_st2, eldv,
5339 DRM_DEBUG_DRIVER(
"ELD size %d\n", len);
5340 for (i = 0; i < len; i++)
5360 DRM_DEBUG_DRIVER(
"ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
5368 if (dev_priv->
display.write_eld)
5369 dev_priv->
display.write_eld(connector, crtc);
5389 for (i = 0; i < 256; i++) {
5391 (intel_crtc->
lut_r[i] << 16) |
5392 (intel_crtc->
lut_g[i] << 8) |
5393 intel_crtc->
lut_b[i]);
5402 bool visible = base != 0;
5427 static void i9xx_update_cursor(
struct drm_crtc *crtc,
u32 base)
5432 int pipe = intel_crtc->
pipe;
5433 bool visible = base != 0;
5453 static void ivb_update_cursor(
struct drm_crtc *crtc,
u32 base)
5458 int pipe = intel_crtc->
pipe;
5459 bool visible = base != 0;
5479 static void intel_crtc_update_cursor(
struct drm_crtc *crtc,
5485 int pipe = intel_crtc->
pipe;
5495 if (x > (
int) crtc->
fb->width)
5498 if (y > (
int) crtc->
fb->height)
5521 visible = base != 0;
5527 ivb_update_cursor(crtc, base);
5531 i845_update_cursor(crtc, base);
5533 i9xx_update_cursor(crtc, base);
5537 static int intel_crtc_cursor_set(
struct drm_crtc *crtc,
5538 struct drm_file *
file,
5551 DRM_DEBUG_KMS(
"cursor off\n");
5559 if (width != 64 || height != 64) {
5560 DRM_ERROR(
"we currently only support 64x64 cursors\n");
5568 if (obj->
base.size < width * height * 4) {
5569 DRM_ERROR(
"buffer is to small\n");
5576 if (!dev_priv->
info->cursor_needs_physical) {
5578 DRM_ERROR(
"cursor cannot be tiled\n");
5585 DRM_ERROR(
"failed to move cursor bo into the GTT\n");
5591 DRM_ERROR(
"failed to release fence for cursor");
5602 DRM_ERROR(
"failed to attach phys object\n");
5605 addr = obj->
phys_obj->handle->busaddr;
5613 if (dev_priv->
info->cursor_needs_physical) {
5618 drm_gem_object_unreference(&intel_crtc->
cursor_bo->base);
5628 intel_crtc_update_cursor(crtc,
true);
5636 drm_gem_object_unreference_unlocked(&obj->
base);
5640 static int intel_crtc_cursor_move(
struct drm_crtc *crtc,
int x,
int y)
5647 intel_crtc_update_cursor(crtc,
true);
5658 intel_crtc->
lut_r[regno] = red >> 8;
5659 intel_crtc->
lut_g[regno] = green >> 8;
5660 intel_crtc->
lut_b[regno] = blue >> 8;
5668 *red = intel_crtc->
lut_r[regno] << 8;
5669 *green = intel_crtc->
lut_g[regno] << 8;
5670 *blue = intel_crtc->
lut_b[regno] << 8;
5676 int end = (start + size > 256) ? 256 : start + size, i;
5679 for (i = start; i <
end; i++) {
5680 intel_crtc->
lut_r[
i] = red[
i] >> 8;
5681 intel_crtc->
lut_g[
i] = green[
i] >> 8;
5682 intel_crtc->
lut_b[
i] = blue[
i] >> 8;
5709 intel_framebuffer_create(
struct drm_device *dev,
5716 intel_fb = kzalloc(
sizeof(*intel_fb),
GFP_KERNEL);
5718 drm_gem_object_unreference_unlocked(&obj->
base);
5724 drm_gem_object_unreference_unlocked(&obj->
base);
5726 return ERR_PTR(ret);
5729 return &intel_fb->
base;
5733 intel_framebuffer_pitch_for_width(
int width,
int bpp)
5736 return ALIGN(pitch, 64);
5742 u32 pitch = intel_framebuffer_pitch_for_width(mode->
hdisplay, bpp);
5747 intel_framebuffer_create_for_mode(
struct drm_device *dev,
5755 intel_framebuffer_size_for_mode(mode, bpp));
5761 mode_cmd.
pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.
width,
5765 return intel_framebuffer_create(dev, &mode_cmd, obj);
5779 obj = dev_priv->
fbdev->ifb.obj;
5783 fb = &dev_priv->
fbdev->ifb.base;
5784 if (fb->
pitches[0] < intel_framebuffer_pitch_for_width(mode->
hdisplay,
5798 struct intel_crtc *intel_crtc;
5799 struct intel_encoder *intel_encoder =
5800 intel_attached_encoder(connector);
5808 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
5823 if (encoder->
crtc) {
5824 crtc = encoder->
crtc;
5841 if (!possible_crtc->
enabled) {
5842 crtc = possible_crtc;
5851 DRM_DEBUG_KMS(
"no pipe available for load-detect\n");
5864 mode = &load_detect_mode;
5873 fb = mode_fits_in_fbdev(dev, mode);
5875 DRM_DEBUG_KMS(
"creating tmp fb for load-detection\n");
5876 fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
5879 DRM_DEBUG_KMS(
"reusing fbdev for load-detection framebuffer\n");
5881 DRM_DEBUG_KMS(
"failed to allocate framebuffer for load-detection\n");
5886 DRM_DEBUG_KMS(
"failed to set mode on load-detect pipe\n");
5905 struct intel_encoder *intel_encoder =
5906 intel_attached_encoder(connector);
5909 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
5936 int pipe = intel_crtc->
pipe;
5973 DRM_DEBUG_KMS(
"Unknown DPLL mode %08x in programmed "
5974 "mode\n", (
int)(dpll & DPLL_MODE_MASK));
5979 intel_clock(dev, 96000, &clock);
5991 intel_clock(dev, 66000, &clock);
5993 intel_clock(dev, 48000, &clock);
6006 intel_clock(dev, 48000, &clock);
6024 int pipe = intel_crtc->
pipe;
6035 mode->
clock = intel_crtc_clock_get(dev, crtc);
6036 mode->
hdisplay = (htot & 0xffff) + 1;
6037 mode->
htotal = ((htot & 0xffff0000) >> 16) + 1;
6039 mode->
hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
6040 mode->
vdisplay = (vtot & 0xffff) + 1;
6041 mode->
vtotal = ((vtot & 0xffff0000) >> 16) + 1;
6043 mode->
vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
6050 static void intel_increase_pllclock(
struct drm_crtc *crtc)
6055 int pipe = intel_crtc->
pipe;
6056 int dpll_reg =
DPLL(pipe);
6066 if (!
HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
6067 DRM_DEBUG_DRIVER(
"upclocking LVDS\n");
6069 assert_panel_unlocked(dev_priv, pipe);
6071 dpll &= ~DISPLAY_RATE_SELECT_FPA1;
6076 if (dpll & DISPLAY_RATE_SELECT_FPA1)
6077 DRM_DEBUG_DRIVER(
"failed to upclock LVDS!\n");
6081 static void intel_decrease_pllclock(
struct drm_crtc *crtc)
6098 int pipe = intel_crtc->
pipe;
6099 int dpll_reg =
DPLL(pipe);
6102 DRM_DEBUG_DRIVER(
"downclocking LVDS\n");
6104 assert_panel_unlocked(dev_priv, pipe);
6111 if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
6112 DRM_DEBUG_DRIVER(
"failed to downclock LVDS!\n");
6131 if (!i915_powersave)
6139 intel_increase_pllclock(crtc);
6148 if (!i915_powersave)
6156 intel_decrease_pllclock(crtc);
6160 static void intel_crtc_destroy(
struct drm_crtc *crtc)
6165 unsigned long flags;
6170 spin_unlock_irqrestore(&dev->event_lock, flags);
6182 static void intel_unpin_work_fn(
struct work_struct *__work)
6190 drm_gem_object_unreference(&work->
old_fb_obj->base);
6197 static void do_intel_finish_page_flip(
struct drm_device *dev,
6204 struct drm_pending_vblank_event *
e;
6206 unsigned long flags;
6209 if (intel_crtc ==
NULL)
6215 spin_unlock_irqrestore(&dev->event_lock, flags);
6225 e->event.tv_sec = tvbl.tv_sec;
6226 e->event.tv_usec = tvbl.tv_usec;
6229 &e->base.file_priv->event_list);
6235 spin_unlock_irqrestore(&dev->event_lock, flags);
6253 do_intel_finish_page_flip(dev, crtc);
6261 do_intel_finish_page_flip(dev, crtc);
6267 struct intel_crtc *intel_crtc =
6269 unsigned long flags;
6274 DRM_ERROR(
"Prepared flip multiple times\n");
6276 DRM_DEBUG_DRIVER(
"preparing flip with no unpin work?\n");
6278 spin_unlock_irqrestore(&dev->event_lock, flags);
6281 static int intel_gen2_queue_flip(
struct drm_device *dev,
6303 if (intel_crtc->
plane)
6308 intel_ring_emit(ring,
MI_NOOP);
6311 intel_ring_emit(ring, fb->
pitches[0]);
6313 intel_ring_emit(ring, 0);
6323 static int intel_gen3_queue_flip(
struct drm_device *dev,
6342 if (intel_crtc->
plane)
6347 intel_ring_emit(ring,
MI_NOOP);
6350 intel_ring_emit(ring, fb->
pitches[0]);
6352 intel_ring_emit(ring,
MI_NOOP);
6363 static int intel_gen4_queue_flip(
struct drm_device *dev,
6388 intel_ring_emit(ring, fb->
pitches[0]);
6389 intel_ring_emit(ring,
6399 intel_ring_emit(ring, pf | pipesrc);
6409 static int intel_gen6_queue_flip(
struct drm_device *dev,
6441 intel_ring_emit(ring, pf | pipesrc);
6457 static int intel_gen7_queue_flip(
struct drm_device *dev,
6472 switch(intel_crtc->
plane) {
6483 WARN_ONCE(1,
"unknown plane in flip command\n");
6495 intel_ring_emit(ring, (
MI_NOOP));
6505 static int intel_default_queue_flip(
struct drm_device *dev,
6513 static int intel_crtc_page_flip(
struct drm_crtc *crtc,
6515 struct drm_pending_vblank_event *
event)
6523 unsigned long flags;
6535 (fb->
offsets[0] != crtc->
fb->offsets[0] ||
6536 fb->
pitches[0] != crtc->
fb->pitches[0]))
6556 spin_unlock_irqrestore(&dev->event_lock, flags);
6560 DRM_DEBUG_DRIVER(
"flip queue: crtc already busy\n");
6564 spin_unlock_irqrestore(&dev->event_lock, flags);
6567 obj = intel_fb->
obj;
6574 drm_gem_object_reference(&work->
old_fb_obj->base);
6575 drm_gem_object_reference(&obj->
base);
6588 ret = dev_priv->
display.queue_flip(dev, crtc, fb, obj);
6590 goto cleanup_pending;
6596 trace_i915_flip_request(intel_crtc->
plane, obj);
6602 drm_gem_object_unreference(&work->
old_fb_obj->base);
6603 drm_gem_object_unreference(&obj->
base);
6609 spin_unlock_irqrestore(&dev->event_lock, flags);
6619 .mode_set_base_atomic = intel_pipe_set_base_atomic,
6621 .disable = intel_crtc_noop,
6626 struct intel_encoder *other_encoder;
6633 &crtc->
dev->mode_config.encoder_list,
6636 if (&other_encoder->
new_crtc->base != crtc ||
6637 encoder == other_encoder)
6646 static bool intel_encoder_crtc_ok(
struct drm_encoder *encoder,
6653 WARN(!crtc,
"checking null crtc?\n");
6674 static void intel_modeset_update_staged_output_state(
struct drm_device *dev)
6676 struct intel_encoder *encoder;
6697 static void intel_modeset_commit_output_state(
struct drm_device *dev)
6699 struct intel_encoder *encoder;
6714 intel_modeset_adjusted_mode(
struct drm_crtc *crtc,
6720 struct intel_encoder *encoder;
6733 if (&encoder->
new_crtc->base != crtc)
6735 encoder_funcs = encoder->
base.helper_private;
6738 DRM_DEBUG_KMS(
"Encoder fixup failed\n");
6743 if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
6744 DRM_DEBUG_KMS(
"CRTC fixup failed\n");
6747 DRM_DEBUG_KMS(
"[CRTC:%d]\n", crtc->
base.id);
6749 return adjusted_mode;
6758 intel_modeset_affected_pipes(
struct drm_crtc *crtc,
unsigned *modeset_pipes,
6759 unsigned *prepare_pipes,
unsigned *disable_pipes)
6761 struct intel_crtc *intel_crtc;
6763 struct intel_encoder *encoder;
6767 *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
6778 if (connector->
base.encoder) {
6779 tmp_crtc = connector->
base.encoder->crtc;
6794 if (encoder->
base.crtc) {
6795 tmp_crtc = encoder->
base.crtc;
6801 *prepare_pipes |= 1 << encoder->
new_crtc->pipe;
6810 if (!intel_crtc->
base.enabled)
6815 if (encoder->
new_crtc == intel_crtc)
6820 *disable_pipes |= 1 << intel_crtc->
pipe;
6827 *prepare_pipes |= 1 << intel_crtc->
pipe;
6840 *modeset_pipes = *prepare_pipes;
6843 *modeset_pipes &= ~(*disable_pipes);
6844 *prepare_pipes &= ~(*disable_pipes);
6847 static bool intel_crtc_in_use(
struct drm_crtc *crtc)
6853 if (encoder->crtc == crtc)
6862 struct intel_encoder *intel_encoder;
6863 struct intel_crtc *intel_crtc;
6868 if (!intel_encoder->
base.crtc)
6873 if (prepare_pipes & (1 << intel_crtc->
pipe))
6877 intel_modeset_commit_output_state(dev);
6882 intel_crtc->
base.enabled = intel_crtc_in_use(&intel_crtc->
base);
6891 if (prepare_pipes & (1 << intel_crtc->
pipe)) {
6893 dev->mode_config.dpms_property;
6907 #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
6908 list_for_each_entry((intel_crtc), \
6909 &(dev)->mode_config.crtc_list, \
6911 if (mask & (1 <<(intel_crtc)->pipe)) \
6916 struct intel_crtc *crtc;
6917 struct intel_encoder *encoder;
6924 intel_connector_check_state(connector);
6927 "connector's staged encoder doesn't match current encoder\n");
6932 bool enabled =
false;
6934 enum pipe
pipe, tracked_pipe;
6936 DRM_DEBUG_KMS(
"[ENCODER:%d:%s]\n",
6937 encoder->
base.base.id,
6941 "encoder's stage crtc doesn't match current crtc\n");
6943 "encoder's active_connectors set, but no crtc\n");
6947 if (connector->
base.encoder != &encoder->
base)
6953 WARN(!!encoder->
base.crtc != enabled,
6954 "encoder's enabled state mismatch "
6955 "(expected %i, found %i)\n",
6956 !!encoder->
base.crtc, enabled);
6957 WARN(active && !encoder->
base.crtc,
6958 "active encoder with no crtc\n");
6961 "encoder's computed active state doesn't match tracked active state "
6966 "encoder's hw state doesn't match sw tracking "
6967 "(expected %i, found %i)\n",
6970 if (!encoder->
base.crtc)
6974 WARN(active && pipe != tracked_pipe,
6975 "active encoder's pipe doesn't match"
6976 "(expected %i, found %i)\n",
6977 tracked_pipe, pipe);
6983 bool enabled =
false;
6986 DRM_DEBUG_KMS(
"[CRTC:%d]\n",
6987 crtc->
base.base.id);
6990 "active crtc, but not enabled in sw tracking\n");
6994 if (encoder->
base.crtc != &crtc->
base)
7001 "crtc's computed active state doesn't match tracked active state "
7002 "(expected %i, found %i)\n", active, crtc->
active);
7003 WARN(enabled != crtc->
base.enabled,
7004 "crtc's computed enabled state doesn't match tracked enabled state "
7005 "(expected %i, found %i)\n", enabled, crtc->
base.enabled);
7020 struct intel_crtc *intel_crtc;
7021 unsigned disable_pipes, prepare_pipes, modeset_pipes;
7024 intel_modeset_affected_pipes(crtc, &modeset_pipes,
7025 &prepare_pipes, &disable_pipes);
7027 DRM_DEBUG_KMS(
"set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
7028 modeset_pipes, prepare_pipes, disable_pipes);
7031 intel_crtc_disable(&intel_crtc->
base);
7033 saved_hwmode = crtc->
hwmode;
7034 saved_mode = crtc->
mode;
7041 adjusted_mode =
NULL;
7042 if (modeset_pipes) {
7043 adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
7044 if (IS_ERR(adjusted_mode)) {
7050 if (intel_crtc->
base.enabled)
7051 dev_priv->
display.crtc_disable(&intel_crtc->
base);
7062 intel_modeset_update_state(dev, prepare_pipes);
7068 ret = !intel_crtc_mode_set(&intel_crtc->
base,
7069 mode, adjusted_mode,
7076 if (encoder->
crtc != &intel_crtc->
base)
7079 DRM_DEBUG_KMS(
"[ENCODER:%d:%s] set [MODE:%d:%s]\n",
7083 encoder_funcs->
mode_set(encoder, mode, adjusted_mode);
7091 if (modeset_pipes) {
7093 crtc->
hwmode = *adjusted_mode;
7106 crtc->
hwmode = saved_hwmode;
7107 crtc->
mode = saved_mode;
7115 #undef for_each_intel_crtc_masked
7127 static int intel_set_config_save_state(
struct drm_device *dev,
7135 kcalloc(dev->mode_config.num_encoder,
7141 kcalloc(dev->mode_config.num_connector,
7163 static void intel_set_config_restore_state(
struct drm_device *dev,
7166 struct intel_encoder *encoder;
7184 intel_set_config_compute_mode_changes(
struct drm_mode_set *
set,
7190 if (
set->crtc->fb !=
set->fb) {
7193 DRM_DEBUG_KMS(
"crtc has no fb, full mode set\n");
7197 }
else if (
set->fb->depth !=
set->crtc->fb->depth) {
7199 }
else if (
set->fb->bits_per_pixel !=
7200 set->crtc->fb->bits_per_pixel) {
7210 DRM_DEBUG_KMS(
"modes are different, full mode set\n");
7218 intel_modeset_stage_output_state(
struct drm_device *dev,
7224 struct intel_encoder *encoder;
7237 for (ro = 0; ro <
set->num_connectors; ro++) {
7238 if (
set->connectors[ro] == &connector->
base) {
7247 if ((!
set->fb || ro ==
set->num_connectors) &&
7248 connector->
base.encoder &&
7249 connector->
base.encoder->crtc ==
set->crtc) {
7252 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s] to [NOCRTC]\n",
7253 connector->
base.base.id,
7259 DRM_DEBUG_KMS(
"encoder changed, full mode switch\n");
7278 for (ro = 0; ro <
set->num_connectors; ro++) {
7279 if (
set->connectors[ro] == &connector->
base)
7280 new_crtc =
set->crtc;
7284 if (!intel_encoder_crtc_ok(&connector->
new_encoder->base,
7290 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s] to [CRTC:%d]\n",
7291 connector->
base.base.id,
7300 &dev->mode_config.connector_list,
7313 DRM_DEBUG_KMS(
"crtc changed, full mode switch\n");
7322 static int intel_crtc_set_config(
struct drm_mode_set *
set)
7339 if (
set->fb &&
set->num_connectors == 0)
7343 DRM_DEBUG_KMS(
"[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
7344 set->crtc->base.id,
set->fb->base.id,
7345 (
int)
set->num_connectors,
set->x,
set->y);
7347 DRM_DEBUG_KMS(
"[CRTC:%d] [NOFB]\n",
set->crtc->base.id);
7350 dev =
set->crtc->dev;
7353 config = kzalloc(
sizeof(*config),
GFP_KERNEL);
7357 ret = intel_set_config_save_state(dev, config);
7361 save_set.crtc =
set->crtc;
7362 save_set.mode = &
set->crtc->mode;
7363 save_set.x =
set->crtc->x;
7364 save_set.y =
set->crtc->y;
7365 save_set.fb =
set->crtc->fb;
7371 intel_set_config_compute_mode_changes(
set, config);
7373 ret = intel_modeset_stage_output_state(dev,
set, config);
7379 DRM_DEBUG_KMS(
"attempting to set mode from"
7386 DRM_ERROR(
"failed to set mode on [CRTC:%d]\n",
7387 set->crtc->base.id);
7392 ret = intel_pipe_set_base(
set->crtc,
7396 intel_set_config_free(config);
7401 intel_set_config_restore_state(dev, config);
7406 save_set.x, save_set.y, save_set.fb))
7407 DRM_ERROR(
"failed to restore config after modeset failure\n");
7410 intel_set_config_free(config);
7415 .cursor_set = intel_crtc_cursor_set,
7416 .cursor_move = intel_crtc_cursor_move,
7417 .gamma_set = intel_crtc_gamma_set,
7418 .set_config = intel_crtc_set_config,
7419 .destroy = intel_crtc_destroy,
7420 .page_flip = intel_crtc_page_flip,
7423 static void intel_pch_pll_init(
struct drm_device *dev)
7429 DRM_DEBUG_KMS(
"No PCH PLLs on this hardware, skipping initialisation\n");
7440 static void intel_crtc_init(
struct drm_device *dev,
int pipe)
7443 struct intel_crtc *intel_crtc;
7447 if (intel_crtc ==
NULL)
7453 for (i = 0; i < 256; i++) {
7463 DRM_DEBUG_KMS(
"swapping pipes & planes for FBC\n");
7472 intel_crtc->
bpp = 24;
7474 drm_crtc_helper_add(&intel_crtc->
base, &intel_helper_funcs);
7478 struct drm_file *file)
7482 struct intel_crtc *crtc;
7484 if (!drm_core_check_feature(dev, DRIVER_MODESET))
7491 DRM_ERROR(
"no such CRTC id\n");
7496 pipe_from_crtc_id->
pipe = crtc->
pipe;
7501 static int intel_encoder_clones(
struct intel_encoder *encoder)
7504 struct intel_encoder *source_encoder;
7509 &dev->mode_config.encoder_list, base.head) {
7511 if (encoder == source_encoder)
7512 index_mask |= (1 <<
entry);
7516 index_mask |= (1 <<
entry);
7524 static bool has_edp_a(
struct drm_device *dev)
7541 static void intel_setup_outputs(
struct drm_device *dev)
7544 struct intel_encoder *encoder;
7545 bool dpd_is_edp =
false;
7630 DRM_DEBUG_KMS(
"probing SDVOB\n");
7633 DRM_DEBUG_KMS(
"probing HDMI on SDVOB\n");
7638 DRM_DEBUG_KMS(
"probing DP_B\n");
7646 DRM_DEBUG_KMS(
"probing SDVOC\n");
7653 DRM_DEBUG_KMS(
"probing HDMI on SDVOC\n");
7657 DRM_DEBUG_KMS(
"probing DP_C\n");
7664 DRM_DEBUG_KMS(
"probing DP_D\n");
7675 encoder->
base.possible_clones =
7676 intel_encoder_clones(encoder);
7683 static void intel_user_framebuffer_destroy(
struct drm_framebuffer *fb)
7688 drm_gem_object_unreference_unlocked(&intel_fb->
obj->base);
7693 static int intel_user_framebuffer_create_handle(
struct drm_framebuffer *fb,
7694 struct drm_file *file,
7695 unsigned int *handle)
7704 .destroy = intel_user_framebuffer_destroy,
7705 .create_handle = intel_user_framebuffer_create_handle,
7718 if (mode_cmd->
pitches[0] & 63)
7737 DRM_DEBUG_KMS(
"unsupported pixel format %u\n",
7744 DRM_ERROR(
"framebuffer init failed %d\n", ret);
7749 intel_fb->
obj = obj;
7754 intel_user_framebuffer_create(
struct drm_device *dev,
7755 struct drm_file *filp,
7765 return intel_framebuffer_create(dev, mode_cmd, obj);
7769 .fb_create = intel_user_framebuffer_create,
7774 static void intel_init_display(
struct drm_device *dev)
7780 dev_priv->
display.crtc_mode_set = ironlake_crtc_mode_set;
7781 dev_priv->
display.crtc_enable = ironlake_crtc_enable;
7782 dev_priv->
display.crtc_disable = ironlake_crtc_disable;
7783 dev_priv->
display.off = ironlake_crtc_off;
7784 dev_priv->
display.update_plane = ironlake_update_plane;
7786 dev_priv->
display.crtc_mode_set = i9xx_crtc_mode_set;
7787 dev_priv->
display.crtc_enable = i9xx_crtc_enable;
7788 dev_priv->
display.crtc_disable = i9xx_crtc_disable;
7789 dev_priv->
display.off = i9xx_crtc_off;
7790 dev_priv->
display.update_plane = i9xx_update_plane;
7795 dev_priv->
display.get_display_clock_speed =
7796 valleyview_get_display_clock_speed;
7798 dev_priv->
display.get_display_clock_speed =
7799 i945_get_display_clock_speed;
7801 dev_priv->
display.get_display_clock_speed =
7802 i915_get_display_clock_speed;
7804 dev_priv->
display.get_display_clock_speed =
7805 i9xx_misc_get_display_clock_speed;
7807 dev_priv->
display.get_display_clock_speed =
7808 i915gm_get_display_clock_speed;
7810 dev_priv->
display.get_display_clock_speed =
7811 i865_get_display_clock_speed;
7813 dev_priv->
display.get_display_clock_speed =
7814 i855_get_display_clock_speed;
7816 dev_priv->
display.get_display_clock_speed =
7817 i830_get_display_clock_speed;
7821 dev_priv->
display.fdi_link_train = ironlake_fdi_link_train;
7822 dev_priv->
display.write_eld = ironlake_write_eld;
7824 dev_priv->
display.fdi_link_train = gen6_fdi_link_train;
7825 dev_priv->
display.write_eld = ironlake_write_eld;
7828 dev_priv->
display.fdi_link_train = ivb_manual_fdi_link_train;
7829 dev_priv->
display.write_eld = ironlake_write_eld;
7832 dev_priv->
display.write_eld = haswell_write_eld;
7835 }
else if (
IS_G4X(dev)) {
7836 dev_priv->
display.write_eld = g4x_write_eld;
7840 dev_priv->
display.queue_flip = intel_default_queue_flip;
7844 dev_priv->
display.queue_flip = intel_gen2_queue_flip;
7848 dev_priv->
display.queue_flip = intel_gen3_queue_flip;
7853 dev_priv->
display.queue_flip = intel_gen4_queue_flip;
7857 dev_priv->
display.queue_flip = intel_gen6_queue_flip;
7860 dev_priv->
display.queue_flip = intel_gen7_queue_flip;
7870 static void quirk_pipea_force(
struct drm_device *dev)
7875 DRM_INFO(
"applying pipe a force quirk\n");
7881 static void quirk_ssc_force_disable(
struct drm_device *dev)
7885 DRM_INFO(
"applying lvds SSC disable quirk\n");
7892 static void quirk_invert_brightness(
struct drm_device *dev)
7896 DRM_INFO(
"applying inverted panel brightness quirk\n");
7912 static int intel_dmi_reverse_brightness(
const struct dmi_system_id *
id)
7914 DRM_INFO(
"Backlight polarity reversed on %s\n", id->
ident);
7922 .callback = intel_dmi_reverse_brightness,
7923 .ident =
"NCR Corporation",
7930 .hook = quirk_invert_brightness,
7936 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
7939 { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
7942 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
7949 { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
7952 { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
7955 { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
7958 static void intel_init_quirks(
struct drm_device *dev)
7963 for (i = 0; i <
ARRAY_SIZE(intel_quirks); i++) {
7973 for (i = 0; i <
ARRAY_SIZE(intel_dmi_quirks); i++) {
7975 intel_dmi_quirks[i].
hook(dev);
7980 static void i915_disable_vga(
struct drm_device *dev)
8025 dev->mode_config.min_width = 0;
8026 dev->mode_config.min_height = 0;
8028 dev->mode_config.preferred_depth = 24;
8029 dev->mode_config.prefer_shadow = 1;
8031 dev->mode_config.funcs = &intel_mode_funcs;
8033 intel_init_quirks(dev);
8037 intel_init_display(dev);
8040 dev->mode_config.max_width = 2048;
8041 dev->mode_config.max_height = 2048;
8043 dev->mode_config.max_width = 4096;
8044 dev->mode_config.max_height = 4096;
8046 dev->mode_config.max_width = 8192;
8047 dev->mode_config.max_height = 8192;
8049 dev->mode_config.fb_base = dev_priv->
mm.gtt_base_addr;
8051 DRM_DEBUG_KMS(
"%d display pipe%s available.\n",
8054 for (i = 0; i < dev_priv->
num_pipe; i++) {
8055 intel_crtc_init(dev, i);
8058 DRM_DEBUG_KMS(
"plane %d init failed: %d\n", i, ret);
8061 intel_pch_pll_init(dev);
8064 i915_disable_vga(dev);
8065 intel_setup_outputs(dev);
8073 connector->
encoder->connectors_active =
false;
8077 static void intel_enable_pipe_a(
struct drm_device *dev)
8087 &dev->mode_config.connector_list,
8090 crt = &connector->
base;
8105 intel_check_plane_mapping(
struct intel_crtc *crtc)
8123 static void intel_sanitize_crtc(
struct intel_crtc *crtc)
8136 if (
INTEL_INFO(dev)->
gen < 4 && !intel_check_plane_mapping(crtc)) {
8140 DRM_DEBUG_KMS(
"[CRTC:%d] wrong plane connection detected!\n",
8141 crtc->
base.base.id);
8146 plane = crtc->
plane;
8157 intel_connector_break_all_links(connector);
8161 crtc->
base.enabled =
false;
8170 intel_enable_pipe_a(dev);
8178 struct intel_encoder *encoder;
8183 DRM_DEBUG_KMS(
"[CRTC:%d] hw state adjusted, was %s, now %s\n",
8185 crtc->
base.enabled ?
"enabled" :
"disabled",
8186 crtc->
active ?
"enabled" :
"disabled");
8204 static void intel_sanitize_encoder(
struct intel_encoder *encoder)
8212 bool has_active_crtc = encoder->
base.crtc &&
8216 DRM_DEBUG_KMS(
"[ENCODER:%d:%s] has active connectors but no active pipe!\n",
8217 encoder->
base.base.id,
8223 if (encoder->
base.crtc) {
8224 DRM_DEBUG_KMS(
"[ENCODER:%d:%s] manually disabled\n",
8225 encoder->
base.base.id,
8235 &dev->mode_config.connector_list,
8237 if (connector->
encoder != encoder)
8240 intel_connector_break_all_links(connector);
8254 struct intel_crtc *crtc;
8255 struct intel_encoder *encoder;
8269 DRM_DEBUG_KMS(
"[CRTC:%d] hw state readout: %s\n",
8271 crtc->
active ?
"enabled" :
"disabled");
8279 encoder->
base.crtc =
8286 DRM_DEBUG_KMS(
"[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
8287 encoder->
base.base.id,
8289 encoder->
base.crtc ?
"enabled" :
"disabled",
8297 connector->
encoder->connectors_active =
true;
8298 connector->
base.encoder = &connector->
encoder->base;
8303 DRM_DEBUG_KMS(
"[CONNECTOR:%d:%s] hw state readout: %s\n",
8304 connector->
base.base.id,
8306 connector->
base.encoder ?
"enabled" :
"disabled");
8312 intel_sanitize_encoder(encoder);
8317 intel_sanitize_crtc(crtc);
8320 intel_modeset_update_staged_output_state(dev);
8338 struct intel_crtc *intel_crtc;
8352 intel_increase_pllclock(crtc);
8383 return &intel_attached_encoder(connector)->base;
8387 struct intel_encoder *encoder)
8411 #ifdef CONFIG_DEBUG_FS
8414 struct intel_display_error_state {
8415 struct intel_cursor_error_state {
8422 struct intel_pipe_error_state {
8434 struct intel_plane_error_state {
8445 struct intel_display_error_state *
8446 intel_display_capture_error_state(
struct drm_device *dev)
8449 struct intel_display_error_state *
error;
8485 intel_display_print_error_state(
struct seq_file *m,
8487 struct intel_display_error_state *error)
8495 seq_printf(m,
" CONF: %08x\n", error->pipe[i].conf);
8496 seq_printf(m,
" SRC: %08x\n", error->pipe[i].source);
8497 seq_printf(m,
" HTOTAL: %08x\n", error->pipe[i].htotal);
8498 seq_printf(m,
" HBLANK: %08x\n", error->pipe[i].hblank);
8499 seq_printf(m,
" HSYNC: %08x\n", error->pipe[i].hsync);
8500 seq_printf(m,
" VTOTAL: %08x\n", error->pipe[i].vtotal);
8501 seq_printf(m,
" VBLANK: %08x\n", error->pipe[i].vblank);
8502 seq_printf(m,
" VSYNC: %08x\n", error->pipe[i].vsync);
8505 seq_printf(m,
" CNTR: %08x\n", error->plane[i].control);
8506 seq_printf(m,
" STRIDE: %08x\n", error->plane[i].stride);
8507 seq_printf(m,
" SIZE: %08x\n", error->plane[i].size);
8508 seq_printf(m,
" POS: %08x\n", error->plane[i].pos);
8509 seq_printf(m,
" ADDR: %08x\n", error->plane[i].addr);
8511 seq_printf(m,
" SURF: %08x\n", error->plane[i].surface);
8512 seq_printf(m,
" TILEOFF: %08x\n", error->plane[i].tile_offset);
8516 seq_printf(m,
" CNTR: %08x\n", error->cursor[i].control);
8517 seq_printf(m,
" POS: %08x\n", error->cursor[i].position);
8518 seq_printf(m,
" BASE: %08x\n", error->cursor[i].base);