1 // SPDX-License-Identifier: MIT
3 * Copyright © 2020 Intel Corporation
6 #include <linux/kernel.h>
8 #include "intel_crtc.h"
10 #include "intel_display.h"
11 #include "intel_display_types.h"
12 #include "intel_dpll.h"
13 #include "intel_lvds.h"
14 #include "intel_panel.h"
15 #include "intel_pps.h"
16 #include "intel_sideband.h"
17 #include "intel_snps_phy.h"
22 } dot, vco, n, m, m1, m2, p, p1;
29 static const struct intel_limit intel_limits_i8xx_dac = {
30 .dot = { .min = 25000, .max = 350000 },
31 .vco = { .min = 908000, .max = 1512000 },
32 .n = { .min = 2, .max = 16 },
33 .m = { .min = 96, .max = 140 },
34 .m1 = { .min = 18, .max = 26 },
35 .m2 = { .min = 6, .max = 16 },
36 .p = { .min = 4, .max = 128 },
37 .p1 = { .min = 2, .max = 33 },
38 .p2 = { .dot_limit = 165000,
39 .p2_slow = 4, .p2_fast = 2 },
42 static const struct intel_limit intel_limits_i8xx_dvo = {
43 .dot = { .min = 25000, .max = 350000 },
44 .vco = { .min = 908000, .max = 1512000 },
45 .n = { .min = 2, .max = 16 },
46 .m = { .min = 96, .max = 140 },
47 .m1 = { .min = 18, .max = 26 },
48 .m2 = { .min = 6, .max = 16 },
49 .p = { .min = 4, .max = 128 },
50 .p1 = { .min = 2, .max = 33 },
51 .p2 = { .dot_limit = 165000,
52 .p2_slow = 4, .p2_fast = 4 },
55 static const struct intel_limit intel_limits_i8xx_lvds = {
56 .dot = { .min = 25000, .max = 350000 },
57 .vco = { .min = 908000, .max = 1512000 },
58 .n = { .min = 2, .max = 16 },
59 .m = { .min = 96, .max = 140 },
60 .m1 = { .min = 18, .max = 26 },
61 .m2 = { .min = 6, .max = 16 },
62 .p = { .min = 4, .max = 128 },
63 .p1 = { .min = 1, .max = 6 },
64 .p2 = { .dot_limit = 165000,
65 .p2_slow = 14, .p2_fast = 7 },
68 static const struct intel_limit intel_limits_i9xx_sdvo = {
69 .dot = { .min = 20000, .max = 400000 },
70 .vco = { .min = 1400000, .max = 2800000 },
71 .n = { .min = 1, .max = 6 },
72 .m = { .min = 70, .max = 120 },
73 .m1 = { .min = 8, .max = 18 },
74 .m2 = { .min = 3, .max = 7 },
75 .p = { .min = 5, .max = 80 },
76 .p1 = { .min = 1, .max = 8 },
77 .p2 = { .dot_limit = 200000,
78 .p2_slow = 10, .p2_fast = 5 },
81 static const struct intel_limit intel_limits_i9xx_lvds = {
82 .dot = { .min = 20000, .max = 400000 },
83 .vco = { .min = 1400000, .max = 2800000 },
84 .n = { .min = 1, .max = 6 },
85 .m = { .min = 70, .max = 120 },
86 .m1 = { .min = 8, .max = 18 },
87 .m2 = { .min = 3, .max = 7 },
88 .p = { .min = 7, .max = 98 },
89 .p1 = { .min = 1, .max = 8 },
90 .p2 = { .dot_limit = 112000,
91 .p2_slow = 14, .p2_fast = 7 },
95 static const struct intel_limit intel_limits_g4x_sdvo = {
96 .dot = { .min = 25000, .max = 270000 },
97 .vco = { .min = 1750000, .max = 3500000},
98 .n = { .min = 1, .max = 4 },
99 .m = { .min = 104, .max = 138 },
100 .m1 = { .min = 17, .max = 23 },
101 .m2 = { .min = 5, .max = 11 },
102 .p = { .min = 10, .max = 30 },
103 .p1 = { .min = 1, .max = 3},
104 .p2 = { .dot_limit = 270000,
110 static const struct intel_limit intel_limits_g4x_hdmi = {
111 .dot = { .min = 22000, .max = 400000 },
112 .vco = { .min = 1750000, .max = 3500000},
113 .n = { .min = 1, .max = 4 },
114 .m = { .min = 104, .max = 138 },
115 .m1 = { .min = 16, .max = 23 },
116 .m2 = { .min = 5, .max = 11 },
117 .p = { .min = 5, .max = 80 },
118 .p1 = { .min = 1, .max = 8},
119 .p2 = { .dot_limit = 165000,
120 .p2_slow = 10, .p2_fast = 5 },
123 static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
124 .dot = { .min = 20000, .max = 115000 },
125 .vco = { .min = 1750000, .max = 3500000 },
126 .n = { .min = 1, .max = 3 },
127 .m = { .min = 104, .max = 138 },
128 .m1 = { .min = 17, .max = 23 },
129 .m2 = { .min = 5, .max = 11 },
130 .p = { .min = 28, .max = 112 },
131 .p1 = { .min = 2, .max = 8 },
132 .p2 = { .dot_limit = 0,
133 .p2_slow = 14, .p2_fast = 14
137 static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
138 .dot = { .min = 80000, .max = 224000 },
139 .vco = { .min = 1750000, .max = 3500000 },
140 .n = { .min = 1, .max = 3 },
141 .m = { .min = 104, .max = 138 },
142 .m1 = { .min = 17, .max = 23 },
143 .m2 = { .min = 5, .max = 11 },
144 .p = { .min = 14, .max = 42 },
145 .p1 = { .min = 2, .max = 6 },
146 .p2 = { .dot_limit = 0,
147 .p2_slow = 7, .p2_fast = 7
151 static const struct intel_limit pnv_limits_sdvo = {
152 .dot = { .min = 20000, .max = 400000},
153 .vco = { .min = 1700000, .max = 3500000 },
154 /* Pineview's Ncounter is a ring counter */
155 .n = { .min = 3, .max = 6 },
156 .m = { .min = 2, .max = 256 },
157 /* Pineview only has one combined m divider, which we treat as m2. */
158 .m1 = { .min = 0, .max = 0 },
159 .m2 = { .min = 0, .max = 254 },
160 .p = { .min = 5, .max = 80 },
161 .p1 = { .min = 1, .max = 8 },
162 .p2 = { .dot_limit = 200000,
163 .p2_slow = 10, .p2_fast = 5 },
166 static const struct intel_limit pnv_limits_lvds = {
167 .dot = { .min = 20000, .max = 400000 },
168 .vco = { .min = 1700000, .max = 3500000 },
169 .n = { .min = 3, .max = 6 },
170 .m = { .min = 2, .max = 256 },
171 .m1 = { .min = 0, .max = 0 },
172 .m2 = { .min = 0, .max = 254 },
173 .p = { .min = 7, .max = 112 },
174 .p1 = { .min = 1, .max = 8 },
175 .p2 = { .dot_limit = 112000,
176 .p2_slow = 14, .p2_fast = 14 },
179 /* Ironlake / Sandybridge
181 * We calculate clock using (register_value + 2) for N/M1/M2, so here
182 * the range value for them is (actual_value - 2).
184 static const struct intel_limit ilk_limits_dac = {
185 .dot = { .min = 25000, .max = 350000 },
186 .vco = { .min = 1760000, .max = 3510000 },
187 .n = { .min = 1, .max = 5 },
188 .m = { .min = 79, .max = 127 },
189 .m1 = { .min = 12, .max = 22 },
190 .m2 = { .min = 5, .max = 9 },
191 .p = { .min = 5, .max = 80 },
192 .p1 = { .min = 1, .max = 8 },
193 .p2 = { .dot_limit = 225000,
194 .p2_slow = 10, .p2_fast = 5 },
197 static const struct intel_limit ilk_limits_single_lvds = {
198 .dot = { .min = 25000, .max = 350000 },
199 .vco = { .min = 1760000, .max = 3510000 },
200 .n = { .min = 1, .max = 3 },
201 .m = { .min = 79, .max = 118 },
202 .m1 = { .min = 12, .max = 22 },
203 .m2 = { .min = 5, .max = 9 },
204 .p = { .min = 28, .max = 112 },
205 .p1 = { .min = 2, .max = 8 },
206 .p2 = { .dot_limit = 225000,
207 .p2_slow = 14, .p2_fast = 14 },
210 static const struct intel_limit ilk_limits_dual_lvds = {
211 .dot = { .min = 25000, .max = 350000 },
212 .vco = { .min = 1760000, .max = 3510000 },
213 .n = { .min = 1, .max = 3 },
214 .m = { .min = 79, .max = 127 },
215 .m1 = { .min = 12, .max = 22 },
216 .m2 = { .min = 5, .max = 9 },
217 .p = { .min = 14, .max = 56 },
218 .p1 = { .min = 2, .max = 8 },
219 .p2 = { .dot_limit = 225000,
220 .p2_slow = 7, .p2_fast = 7 },
223 /* LVDS 100mhz refclk limits. */
224 static const struct intel_limit ilk_limits_single_lvds_100m = {
225 .dot = { .min = 25000, .max = 350000 },
226 .vco = { .min = 1760000, .max = 3510000 },
227 .n = { .min = 1, .max = 2 },
228 .m = { .min = 79, .max = 126 },
229 .m1 = { .min = 12, .max = 22 },
230 .m2 = { .min = 5, .max = 9 },
231 .p = { .min = 28, .max = 112 },
232 .p1 = { .min = 2, .max = 8 },
233 .p2 = { .dot_limit = 225000,
234 .p2_slow = 14, .p2_fast = 14 },
237 static const struct intel_limit ilk_limits_dual_lvds_100m = {
238 .dot = { .min = 25000, .max = 350000 },
239 .vco = { .min = 1760000, .max = 3510000 },
240 .n = { .min = 1, .max = 3 },
241 .m = { .min = 79, .max = 126 },
242 .m1 = { .min = 12, .max = 22 },
243 .m2 = { .min = 5, .max = 9 },
244 .p = { .min = 14, .max = 42 },
245 .p1 = { .min = 2, .max = 6 },
246 .p2 = { .dot_limit = 225000,
247 .p2_slow = 7, .p2_fast = 7 },
250 static const struct intel_limit intel_limits_vlv = {
252 * These are the data rate limits (measured in fast clocks)
253 * since those are the strictest limits we have. The fast
254 * clock and actual rate limits are more relaxed, so checking
255 * them would make no difference.
257 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
258 .vco = { .min = 4000000, .max = 6000000 },
259 .n = { .min = 1, .max = 7 },
260 .m1 = { .min = 2, .max = 3 },
261 .m2 = { .min = 11, .max = 156 },
262 .p1 = { .min = 2, .max = 3 },
263 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
266 static const struct intel_limit intel_limits_chv = {
268 * These are the data rate limits (measured in fast clocks)
269 * since those are the strictest limits we have. The fast
270 * clock and actual rate limits are more relaxed, so checking
271 * them would make no difference.
273 .dot = { .min = 25000 * 5, .max = 540000 * 5},
274 .vco = { .min = 4800000, .max = 6480000 },
275 .n = { .min = 1, .max = 1 },
276 .m1 = { .min = 2, .max = 2 },
277 .m2 = { .min = 24 << 22, .max = 175 << 22 },
278 .p1 = { .min = 2, .max = 4 },
279 .p2 = { .p2_slow = 1, .p2_fast = 14 },
282 static const struct intel_limit intel_limits_bxt = {
283 /* FIXME: find real dot limits */
284 .dot = { .min = 0, .max = INT_MAX },
285 .vco = { .min = 4800000, .max = 6700000 },
286 .n = { .min = 1, .max = 1 },
287 .m1 = { .min = 2, .max = 2 },
288 /* FIXME: find real m2 limits */
289 .m2 = { .min = 2 << 22, .max = 255 << 22 },
290 .p1 = { .min = 2, .max = 4 },
291 .p2 = { .p2_slow = 1, .p2_fast = 20 },
295 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
296 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
297 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
298 * The helpers' return value is the rate of the clock that is fed to the
299 * display engine's pipe which can be the above fast dot clock rate or a
300 * divided-down version of it.
302 /* m1 is reserved as 0 in Pineview, n is a ring counter */
303 int pnv_calc_dpll_params(int refclk, struct dpll *clock)
305 clock->m = clock->m2 + 2;
306 clock->p = clock->p1 * clock->p2;
307 if (WARN_ON(clock->n == 0 || clock->p == 0))
309 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
310 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
315 static u32 i9xx_dpll_compute_m(const struct dpll *dpll)
317 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
320 int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
322 clock->m = i9xx_dpll_compute_m(clock);
323 clock->p = clock->p1 * clock->p2;
324 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
326 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
327 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
332 int vlv_calc_dpll_params(int refclk, struct dpll *clock)
334 clock->m = clock->m1 * clock->m2;
335 clock->p = clock->p1 * clock->p2;
336 if (WARN_ON(clock->n == 0 || clock->p == 0))
338 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
339 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
341 return clock->dot / 5;
344 int chv_calc_dpll_params(int refclk, struct dpll *clock)
346 clock->m = clock->m1 * clock->m2;
347 clock->p = clock->p1 * clock->p2;
348 if (WARN_ON(clock->n == 0 || clock->p == 0))
350 clock->vco = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(refclk, clock->m),
352 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
354 return clock->dot / 5;
358 * Returns whether the given set of divisors are valid for a given refclk with
359 * the given connectors.
361 static bool intel_pll_is_valid(struct drm_i915_private *dev_priv,
362 const struct intel_limit *limit,
363 const struct dpll *clock)
365 if (clock->n < limit->n.min || limit->n.max < clock->n)
367 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
369 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
371 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
374 if (!IS_PINEVIEW(dev_priv) && !IS_LP(dev_priv))
375 if (clock->m1 <= clock->m2)
378 if (!IS_LP(dev_priv)) {
379 if (clock->p < limit->p.min || limit->p.max < clock->p)
381 if (clock->m < limit->m.min || limit->m.max < clock->m)
385 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
387 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
388 * connector, etc., rather than just a single range.
390 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
397 i9xx_select_p2_div(const struct intel_limit *limit,
398 const struct intel_crtc_state *crtc_state,
401 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
403 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
405 * For LVDS just rely on its current settings for dual-channel.
406 * We haven't figured out how to reliably set up different
407 * single/dual channel state, if we even can.
409 if (intel_is_dual_link_lvds(dev_priv))
410 return limit->p2.p2_fast;
412 return limit->p2.p2_slow;
414 if (target < limit->p2.dot_limit)
415 return limit->p2.p2_slow;
417 return limit->p2.p2_fast;
422 * Returns a set of divisors for the desired target clock with the given
423 * refclk, or FALSE. The returned values represent the clock equation:
424 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
426 * Target and reference clocks are specified in kHz.
428 * If match_clock is provided, then best_clock P divider must match the P
429 * divider from @match_clock used for LVDS downclocking.
432 i9xx_find_best_dpll(const struct intel_limit *limit,
433 struct intel_crtc_state *crtc_state,
434 int target, int refclk,
435 const struct dpll *match_clock,
436 struct dpll *best_clock)
438 struct drm_device *dev = crtc_state->uapi.crtc->dev;
442 memset(best_clock, 0, sizeof(*best_clock));
444 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
446 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
448 for (clock.m2 = limit->m2.min;
449 clock.m2 <= limit->m2.max; clock.m2++) {
450 if (clock.m2 >= clock.m1)
452 for (clock.n = limit->n.min;
453 clock.n <= limit->n.max; clock.n++) {
454 for (clock.p1 = limit->p1.min;
455 clock.p1 <= limit->p1.max; clock.p1++) {
458 i9xx_calc_dpll_params(refclk, &clock);
459 if (!intel_pll_is_valid(to_i915(dev),
464 clock.p != match_clock->p)
467 this_err = abs(clock.dot - target);
468 if (this_err < err) {
477 return (err != target);
481 * Returns a set of divisors for the desired target clock with the given
482 * refclk, or FALSE. The returned values represent the clock equation:
483 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
485 * Target and reference clocks are specified in kHz.
487 * If match_clock is provided, then best_clock P divider must match the P
488 * divider from @match_clock used for LVDS downclocking.
491 pnv_find_best_dpll(const struct intel_limit *limit,
492 struct intel_crtc_state *crtc_state,
493 int target, int refclk,
494 const struct dpll *match_clock,
495 struct dpll *best_clock)
497 struct drm_device *dev = crtc_state->uapi.crtc->dev;
501 memset(best_clock, 0, sizeof(*best_clock));
503 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
505 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
507 for (clock.m2 = limit->m2.min;
508 clock.m2 <= limit->m2.max; clock.m2++) {
509 for (clock.n = limit->n.min;
510 clock.n <= limit->n.max; clock.n++) {
511 for (clock.p1 = limit->p1.min;
512 clock.p1 <= limit->p1.max; clock.p1++) {
515 pnv_calc_dpll_params(refclk, &clock);
516 if (!intel_pll_is_valid(to_i915(dev),
521 clock.p != match_clock->p)
524 this_err = abs(clock.dot - target);
525 if (this_err < err) {
534 return (err != target);
538 * Returns a set of divisors for the desired target clock with the given
539 * refclk, or FALSE. The returned values represent the clock equation:
540 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
542 * Target and reference clocks are specified in kHz.
544 * If match_clock is provided, then best_clock P divider must match the P
545 * divider from @match_clock used for LVDS downclocking.
548 g4x_find_best_dpll(const struct intel_limit *limit,
549 struct intel_crtc_state *crtc_state,
550 int target, int refclk,
551 const struct dpll *match_clock,
552 struct dpll *best_clock)
554 struct drm_device *dev = crtc_state->uapi.crtc->dev;
558 /* approximately equals target * 0.00585 */
559 int err_most = (target >> 8) + (target >> 9);
561 memset(best_clock, 0, sizeof(*best_clock));
563 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
565 max_n = limit->n.max;
566 /* based on hardware requirement, prefer smaller n to precision */
567 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
568 /* based on hardware requirement, prefere larger m1,m2 */
569 for (clock.m1 = limit->m1.max;
570 clock.m1 >= limit->m1.min; clock.m1--) {
571 for (clock.m2 = limit->m2.max;
572 clock.m2 >= limit->m2.min; clock.m2--) {
573 for (clock.p1 = limit->p1.max;
574 clock.p1 >= limit->p1.min; clock.p1--) {
577 i9xx_calc_dpll_params(refclk, &clock);
578 if (!intel_pll_is_valid(to_i915(dev),
583 this_err = abs(clock.dot - target);
584 if (this_err < err_most) {
598 * Check if the calculated PLL configuration is more optimal compared to the
599 * best configuration and error found so far. Return the calculated error.
601 static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
602 const struct dpll *calculated_clock,
603 const struct dpll *best_clock,
604 unsigned int best_error_ppm,
605 unsigned int *error_ppm)
608 * For CHV ignore the error and consider only the P value.
609 * Prefer a bigger P value based on HW requirements.
611 if (IS_CHERRYVIEW(to_i915(dev))) {
614 return calculated_clock->p > best_clock->p;
617 if (drm_WARN_ON_ONCE(dev, !target_freq))
620 *error_ppm = div_u64(1000000ULL *
621 abs(target_freq - calculated_clock->dot),
624 * Prefer a better P value over a better (smaller) error if the error
625 * is small. Ensure this preference for future configurations too by
626 * setting the error to 0.
628 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
634 return *error_ppm + 10 < best_error_ppm;
638 * Returns a set of divisors for the desired target clock with the given
639 * refclk, or FALSE. The returned values represent the clock equation:
640 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
643 vlv_find_best_dpll(const struct intel_limit *limit,
644 struct intel_crtc_state *crtc_state,
645 int target, int refclk,
646 const struct dpll *match_clock,
647 struct dpll *best_clock)
649 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
650 struct drm_device *dev = crtc->base.dev;
652 unsigned int bestppm = 1000000;
653 /* min update 19.2 MHz */
654 int max_n = min(limit->n.max, refclk / 19200);
657 target *= 5; /* fast clock */
659 memset(best_clock, 0, sizeof(*best_clock));
661 /* based on hardware requirement, prefer smaller n to precision */
662 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
663 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
664 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
665 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
666 clock.p = clock.p1 * clock.p2;
667 /* based on hardware requirement, prefer bigger m1,m2 values */
668 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
671 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
674 vlv_calc_dpll_params(refclk, &clock);
676 if (!intel_pll_is_valid(to_i915(dev),
681 if (!vlv_PLL_is_optimal(dev, target,
699 * Returns a set of divisors for the desired target clock with the given
700 * refclk, or FALSE. The returned values represent the clock equation:
701 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
704 chv_find_best_dpll(const struct intel_limit *limit,
705 struct intel_crtc_state *crtc_state,
706 int target, int refclk,
707 const struct dpll *match_clock,
708 struct dpll *best_clock)
710 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
711 struct drm_device *dev = crtc->base.dev;
712 unsigned int best_error_ppm;
717 memset(best_clock, 0, sizeof(*best_clock));
718 best_error_ppm = 1000000;
721 * Based on hardware doc, the n always set to 1, and m1 always
722 * set to 2. If requires to support 200Mhz refclk, we need to
723 * revisit this because n may not 1 anymore.
727 target *= 5; /* fast clock */
729 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
730 for (clock.p2 = limit->p2.p2_fast;
731 clock.p2 >= limit->p2.p2_slow;
732 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
733 unsigned int error_ppm;
735 clock.p = clock.p1 * clock.p2;
737 m2 = DIV_ROUND_CLOSEST_ULL(mul_u32_u32(target, clock.p * clock.n) << 22,
740 if (m2 > INT_MAX/clock.m1)
745 chv_calc_dpll_params(refclk, &clock);
747 if (!intel_pll_is_valid(to_i915(dev), limit, &clock))
750 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
751 best_error_ppm, &error_ppm))
755 best_error_ppm = error_ppm;
763 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state,
764 struct dpll *best_clock)
767 const struct intel_limit *limit = &intel_limits_bxt;
769 return chv_find_best_dpll(limit, crtc_state,
770 crtc_state->port_clock, refclk,
774 u32 i9xx_dpll_compute_fp(const struct dpll *dpll)
776 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
779 static u32 pnv_dpll_compute_fp(const struct dpll *dpll)
781 return (1 << dpll->n) << 16 | dpll->m2;
784 static void i9xx_update_pll_dividers(struct intel_crtc_state *crtc_state,
785 const struct dpll *clock,
786 const struct dpll *reduced_clock)
788 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
789 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
792 if (IS_PINEVIEW(dev_priv)) {
793 fp = pnv_dpll_compute_fp(clock);
794 fp2 = pnv_dpll_compute_fp(reduced_clock);
796 fp = i9xx_dpll_compute_fp(clock);
797 fp2 = i9xx_dpll_compute_fp(reduced_clock);
800 crtc_state->dpll_hw_state.fp0 = fp;
801 crtc_state->dpll_hw_state.fp1 = fp2;
804 static void i9xx_compute_dpll(struct intel_crtc_state *crtc_state,
805 const struct dpll *clock,
806 const struct dpll *reduced_clock)
808 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
809 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
812 i9xx_update_pll_dividers(crtc_state, clock, reduced_clock);
814 dpll = DPLL_VGA_MODE_DIS;
816 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
817 dpll |= DPLLB_MODE_LVDS;
819 dpll |= DPLLB_MODE_DAC_SERIAL;
821 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
822 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
823 dpll |= (crtc_state->pixel_multiplier - 1)
824 << SDVO_MULTIPLIER_SHIFT_HIRES;
827 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
828 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
829 dpll |= DPLL_SDVO_HIGH_SPEED;
831 if (intel_crtc_has_dp_encoder(crtc_state))
832 dpll |= DPLL_SDVO_HIGH_SPEED;
834 /* compute bitmask from p1 value */
835 if (IS_G4X(dev_priv)) {
836 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
837 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
838 } else if (IS_PINEVIEW(dev_priv)) {
839 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
840 WARN_ON(reduced_clock->p1 != clock->p1);
842 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
843 WARN_ON(reduced_clock->p1 != clock->p1);
848 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
851 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
854 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
857 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
860 WARN_ON(reduced_clock->p2 != clock->p2);
862 if (DISPLAY_VER(dev_priv) >= 4)
863 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
865 if (crtc_state->sdvo_tv_clock)
866 dpll |= PLL_REF_INPUT_TVCLKINBC;
867 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
868 intel_panel_use_ssc(dev_priv))
869 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
871 dpll |= PLL_REF_INPUT_DREFCLK;
873 dpll |= DPLL_VCO_ENABLE;
874 crtc_state->dpll_hw_state.dpll = dpll;
876 if (DISPLAY_VER(dev_priv) >= 4) {
877 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
878 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
879 crtc_state->dpll_hw_state.dpll_md = dpll_md;
883 static void i8xx_compute_dpll(struct intel_crtc_state *crtc_state,
884 const struct dpll *clock,
885 const struct dpll *reduced_clock)
887 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
888 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
891 i9xx_update_pll_dividers(crtc_state, clock, reduced_clock);
893 dpll = DPLL_VGA_MODE_DIS;
895 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
896 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
899 dpll |= PLL_P1_DIVIDE_BY_TWO;
901 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
903 dpll |= PLL_P2_DIVIDE_BY_4;
905 WARN_ON(reduced_clock->p1 != clock->p1);
906 WARN_ON(reduced_clock->p2 != clock->p2);
910 * "[Almador Errata}: For the correct operation of the muxed DVO pins
911 * (GDEVSELB/I2Cdata, GIRDBY/I2CClk) and (GFRAMEB/DVI_Data,
912 * GTRDYB/DVI_Clk): Bit 31 (DPLL VCO Enable) and Bit 30 (2X Clock
913 * Enable) must be set to “1” in both the DPLL A Control Register
914 * (06014h-06017h) and DPLL B Control Register (06018h-0601Bh)."
916 * For simplicity We simply keep both bits always enabled in
917 * both DPLLS. The spec says we should disable the DVO 2X clock
918 * when not needed, but this seems to work fine in practice.
920 if (IS_I830(dev_priv) ||
921 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
922 dpll |= DPLL_DVO_2X_MODE;
924 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
925 intel_panel_use_ssc(dev_priv))
926 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
928 dpll |= PLL_REF_INPUT_DREFCLK;
930 dpll |= DPLL_VCO_ENABLE;
931 crtc_state->dpll_hw_state.dpll = dpll;
934 static int hsw_crtc_compute_clock(struct intel_crtc_state *crtc_state)
936 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
937 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
938 struct intel_atomic_state *state =
939 to_intel_atomic_state(crtc_state->uapi.state);
940 struct intel_encoder *encoder =
941 intel_get_crtc_new_encoder(state, crtc_state);
943 if (IS_DG2(dev_priv))
944 return intel_mpllb_calc_state(crtc_state, encoder);
946 if (DISPLAY_VER(dev_priv) < 11 &&
947 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI))
950 if (!intel_reserve_shared_dplls(state, crtc, encoder)) {
951 drm_dbg_kms(&dev_priv->drm,
952 "failed to find PLL for pipe %c\n",
953 pipe_name(crtc->pipe));
960 static bool ilk_needs_fb_cb_tune(const struct dpll *dpll, int factor)
962 return dpll->m < factor * dpll->n;
965 static void ilk_update_pll_dividers(struct intel_crtc_state *crtc_state,
966 const struct dpll *clock,
967 const struct dpll *reduced_clock)
969 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
970 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
974 /* Enable autotuning of the PLL clock (if permissible) */
976 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
977 if ((intel_panel_use_ssc(dev_priv) &&
978 dev_priv->vbt.lvds_ssc_freq == 100000) ||
979 (HAS_PCH_IBX(dev_priv) &&
980 intel_is_dual_link_lvds(dev_priv)))
982 } else if (crtc_state->sdvo_tv_clock) {
986 fp = i9xx_dpll_compute_fp(clock);
987 if (ilk_needs_fb_cb_tune(clock, factor))
990 fp2 = i9xx_dpll_compute_fp(reduced_clock);
991 if (ilk_needs_fb_cb_tune(reduced_clock, factor))
994 crtc_state->dpll_hw_state.fp0 = fp;
995 crtc_state->dpll_hw_state.fp1 = fp2;
998 static void ilk_compute_dpll(struct intel_crtc_state *crtc_state,
999 const struct dpll *clock,
1000 const struct dpll *reduced_clock)
1002 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1003 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1006 ilk_update_pll_dividers(crtc_state, clock, reduced_clock);
1010 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
1011 dpll |= DPLLB_MODE_LVDS;
1013 dpll |= DPLLB_MODE_DAC_SERIAL;
1015 dpll |= (crtc_state->pixel_multiplier - 1)
1016 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
1018 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
1019 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1020 dpll |= DPLL_SDVO_HIGH_SPEED;
1022 if (intel_crtc_has_dp_encoder(crtc_state))
1023 dpll |= DPLL_SDVO_HIGH_SPEED;
1026 * The high speed IO clock is only really required for
1027 * SDVO/HDMI/DP, but we also enable it for CRT to make it
1028 * possible to share the DPLL between CRT and HDMI. Enabling
1029 * the clock needlessly does no real harm, except use up a
1030 * bit of power potentially.
1032 * We'll limit this to IVB with 3 pipes, since it has only two
1033 * DPLLs and so DPLL sharing is the only way to get three pipes
1034 * driving PCH ports at the same time. On SNB we could do this,
1035 * and potentially avoid enabling the second DPLL, but it's not
1036 * clear if it''s a win or loss power wise. No point in doing
1037 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
1039 if (INTEL_NUM_PIPES(dev_priv) == 3 &&
1040 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
1041 dpll |= DPLL_SDVO_HIGH_SPEED;
1043 /* compute bitmask from p1 value */
1044 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
1046 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
1048 switch (clock->p2) {
1050 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
1053 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
1056 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
1059 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
1062 WARN_ON(reduced_clock->p2 != clock->p2);
1064 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
1065 intel_panel_use_ssc(dev_priv))
1066 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
1068 dpll |= PLL_REF_INPUT_DREFCLK;
1070 dpll |= DPLL_VCO_ENABLE;
1072 crtc_state->dpll_hw_state.dpll = dpll;
1075 static int ilk_crtc_compute_clock(struct intel_crtc_state *crtc_state)
1077 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1078 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1079 struct intel_atomic_state *state =
1080 to_intel_atomic_state(crtc_state->uapi.state);
1081 const struct intel_limit *limit;
1082 int refclk = 120000;
1084 memset(&crtc_state->dpll_hw_state, 0,
1085 sizeof(crtc_state->dpll_hw_state));
1087 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
1088 if (!crtc_state->has_pch_encoder)
1091 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
1092 if (intel_panel_use_ssc(dev_priv)) {
1093 drm_dbg_kms(&dev_priv->drm,
1094 "using SSC reference clock of %d kHz\n",
1095 dev_priv->vbt.lvds_ssc_freq);
1096 refclk = dev_priv->vbt.lvds_ssc_freq;
1099 if (intel_is_dual_link_lvds(dev_priv)) {
1100 if (refclk == 100000)
1101 limit = &ilk_limits_dual_lvds_100m;
1103 limit = &ilk_limits_dual_lvds;
1105 if (refclk == 100000)
1106 limit = &ilk_limits_single_lvds_100m;
1108 limit = &ilk_limits_single_lvds;
1111 limit = &ilk_limits_dac;
1114 if (!crtc_state->clock_set &&
1115 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
1116 refclk, NULL, &crtc_state->dpll)) {
1117 drm_err(&dev_priv->drm,
1118 "Couldn't find PLL settings for mode!\n");
1122 ilk_compute_dpll(crtc_state, &crtc_state->dpll,
1125 if (!intel_reserve_shared_dplls(state, crtc, NULL)) {
1126 drm_dbg_kms(&dev_priv->drm,
1127 "failed to find PLL for pipe %c\n",
1128 pipe_name(crtc->pipe));
1135 void vlv_compute_dpll(struct intel_crtc_state *crtc_state)
1137 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1139 crtc_state->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
1140 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1141 if (crtc->pipe != PIPE_A)
1142 crtc_state->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
1144 /* DPLL not used with DSI, but still need the rest set up */
1145 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI))
1146 crtc_state->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
1147 DPLL_EXT_BUFFER_ENABLE_VLV;
1149 crtc_state->dpll_hw_state.dpll_md =
1150 (crtc_state->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
1153 void chv_compute_dpll(struct intel_crtc_state *crtc_state)
1155 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1157 crtc_state->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
1158 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1159 if (crtc->pipe != PIPE_A)
1160 crtc_state->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
1162 /* DPLL not used with DSI, but still need the rest set up */
1163 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI))
1164 crtc_state->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
1166 crtc_state->dpll_hw_state.dpll_md =
1167 (crtc_state->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
1170 static int chv_crtc_compute_clock(struct intel_crtc_state *crtc_state)
1172 int refclk = 100000;
1173 const struct intel_limit *limit = &intel_limits_chv;
1174 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
1176 memset(&crtc_state->dpll_hw_state, 0,
1177 sizeof(crtc_state->dpll_hw_state));
1179 if (!crtc_state->clock_set &&
1180 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
1181 refclk, NULL, &crtc_state->dpll)) {
1182 drm_err(&i915->drm, "Couldn't find PLL settings for mode!\n");
1186 chv_compute_dpll(crtc_state);
1191 static int vlv_crtc_compute_clock(struct intel_crtc_state *crtc_state)
1193 int refclk = 100000;
1194 const struct intel_limit *limit = &intel_limits_vlv;
1195 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
1197 memset(&crtc_state->dpll_hw_state, 0,
1198 sizeof(crtc_state->dpll_hw_state));
1200 if (!crtc_state->clock_set &&
1201 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
1202 refclk, NULL, &crtc_state->dpll)) {
1203 drm_err(&i915->drm, "Couldn't find PLL settings for mode!\n");
1207 vlv_compute_dpll(crtc_state);
1212 static int g4x_crtc_compute_clock(struct intel_crtc_state *crtc_state)
1214 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1215 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1216 const struct intel_limit *limit;
1219 memset(&crtc_state->dpll_hw_state, 0,
1220 sizeof(crtc_state->dpll_hw_state));
1222 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
1223 if (intel_panel_use_ssc(dev_priv)) {
1224 refclk = dev_priv->vbt.lvds_ssc_freq;
1225 drm_dbg_kms(&dev_priv->drm,
1226 "using SSC reference clock of %d kHz\n",
1230 if (intel_is_dual_link_lvds(dev_priv))
1231 limit = &intel_limits_g4x_dual_channel_lvds;
1233 limit = &intel_limits_g4x_single_channel_lvds;
1234 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
1235 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
1236 limit = &intel_limits_g4x_hdmi;
1237 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
1238 limit = &intel_limits_g4x_sdvo;
1240 /* The option is for other outputs */
1241 limit = &intel_limits_i9xx_sdvo;
1244 if (!crtc_state->clock_set &&
1245 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
1246 refclk, NULL, &crtc_state->dpll)) {
1247 drm_err(&dev_priv->drm,
1248 "Couldn't find PLL settings for mode!\n");
1252 i9xx_compute_dpll(crtc_state, &crtc_state->dpll,
1258 static int pnv_crtc_compute_clock(struct intel_crtc_state *crtc_state)
1260 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1261 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1262 const struct intel_limit *limit;
1265 memset(&crtc_state->dpll_hw_state, 0,
1266 sizeof(crtc_state->dpll_hw_state));
1268 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
1269 if (intel_panel_use_ssc(dev_priv)) {
1270 refclk = dev_priv->vbt.lvds_ssc_freq;
1271 drm_dbg_kms(&dev_priv->drm,
1272 "using SSC reference clock of %d kHz\n",
1276 limit = &pnv_limits_lvds;
1278 limit = &pnv_limits_sdvo;
1281 if (!crtc_state->clock_set &&
1282 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
1283 refclk, NULL, &crtc_state->dpll)) {
1284 drm_err(&dev_priv->drm,
1285 "Couldn't find PLL settings for mode!\n");
1289 i9xx_compute_dpll(crtc_state, &crtc_state->dpll,
1295 static int i9xx_crtc_compute_clock(struct intel_crtc_state *crtc_state)
1297 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1298 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1299 const struct intel_limit *limit;
1302 memset(&crtc_state->dpll_hw_state, 0,
1303 sizeof(crtc_state->dpll_hw_state));
1305 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
1306 if (intel_panel_use_ssc(dev_priv)) {
1307 refclk = dev_priv->vbt.lvds_ssc_freq;
1308 drm_dbg_kms(&dev_priv->drm,
1309 "using SSC reference clock of %d kHz\n",
1313 limit = &intel_limits_i9xx_lvds;
1315 limit = &intel_limits_i9xx_sdvo;
1318 if (!crtc_state->clock_set &&
1319 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
1320 refclk, NULL, &crtc_state->dpll)) {
1321 drm_err(&dev_priv->drm,
1322 "Couldn't find PLL settings for mode!\n");
1326 i9xx_compute_dpll(crtc_state, &crtc_state->dpll,
1332 static int i8xx_crtc_compute_clock(struct intel_crtc_state *crtc_state)
1334 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1335 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1336 const struct intel_limit *limit;
1339 memset(&crtc_state->dpll_hw_state, 0,
1340 sizeof(crtc_state->dpll_hw_state));
1342 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
1343 if (intel_panel_use_ssc(dev_priv)) {
1344 refclk = dev_priv->vbt.lvds_ssc_freq;
1345 drm_dbg_kms(&dev_priv->drm,
1346 "using SSC reference clock of %d kHz\n",
1350 limit = &intel_limits_i8xx_lvds;
1351 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
1352 limit = &intel_limits_i8xx_dvo;
1354 limit = &intel_limits_i8xx_dac;
1357 if (!crtc_state->clock_set &&
1358 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
1359 refclk, NULL, &crtc_state->dpll)) {
1360 drm_err(&dev_priv->drm,
1361 "Couldn't find PLL settings for mode!\n");
1365 i8xx_compute_dpll(crtc_state, &crtc_state->dpll,
1371 static const struct intel_dpll_funcs hsw_dpll_funcs = {
1372 .crtc_compute_clock = hsw_crtc_compute_clock,
1375 static const struct intel_dpll_funcs ilk_dpll_funcs = {
1376 .crtc_compute_clock = ilk_crtc_compute_clock,
1379 static const struct intel_dpll_funcs chv_dpll_funcs = {
1380 .crtc_compute_clock = chv_crtc_compute_clock,
1383 static const struct intel_dpll_funcs vlv_dpll_funcs = {
1384 .crtc_compute_clock = vlv_crtc_compute_clock,
1387 static const struct intel_dpll_funcs g4x_dpll_funcs = {
1388 .crtc_compute_clock = g4x_crtc_compute_clock,
1391 static const struct intel_dpll_funcs pnv_dpll_funcs = {
1392 .crtc_compute_clock = pnv_crtc_compute_clock,
1395 static const struct intel_dpll_funcs i9xx_dpll_funcs = {
1396 .crtc_compute_clock = i9xx_crtc_compute_clock,
1399 static const struct intel_dpll_funcs i8xx_dpll_funcs = {
1400 .crtc_compute_clock = i8xx_crtc_compute_clock,
1404 intel_dpll_init_clock_hook(struct drm_i915_private *dev_priv)
1406 if (DISPLAY_VER(dev_priv) >= 9 || HAS_DDI(dev_priv))
1407 dev_priv->dpll_funcs = &hsw_dpll_funcs;
1408 else if (HAS_PCH_SPLIT(dev_priv))
1409 dev_priv->dpll_funcs = &ilk_dpll_funcs;
1410 else if (IS_CHERRYVIEW(dev_priv))
1411 dev_priv->dpll_funcs = &chv_dpll_funcs;
1412 else if (IS_VALLEYVIEW(dev_priv))
1413 dev_priv->dpll_funcs = &vlv_dpll_funcs;
1414 else if (IS_G4X(dev_priv))
1415 dev_priv->dpll_funcs = &g4x_dpll_funcs;
1416 else if (IS_PINEVIEW(dev_priv))
1417 dev_priv->dpll_funcs = &pnv_dpll_funcs;
1418 else if (DISPLAY_VER(dev_priv) != 2)
1419 dev_priv->dpll_funcs = &i9xx_dpll_funcs;
1421 dev_priv->dpll_funcs = &i8xx_dpll_funcs;
1424 static bool i9xx_has_pps(struct drm_i915_private *dev_priv)
1426 if (IS_I830(dev_priv))
1429 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
1432 void i9xx_enable_pll(const struct intel_crtc_state *crtc_state)
1434 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1435 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1436 u32 dpll = crtc_state->dpll_hw_state.dpll;
1437 enum pipe pipe = crtc->pipe;
1440 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder);
1442 /* PLL is protected by panel, make sure we can write it */
1443 if (i9xx_has_pps(dev_priv))
1444 assert_pps_unlocked(dev_priv, pipe);
1446 intel_de_write(dev_priv, FP0(pipe), crtc_state->dpll_hw_state.fp0);
1447 intel_de_write(dev_priv, FP1(pipe), crtc_state->dpll_hw_state.fp1);
1450 * Apparently we need to have VGA mode enabled prior to changing
1451 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1452 * dividers, even though the register value does change.
1454 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
1455 intel_de_write(dev_priv, DPLL(pipe), dpll);
1457 /* Wait for the clocks to stabilize. */
1458 intel_de_posting_read(dev_priv, DPLL(pipe));
1461 if (DISPLAY_VER(dev_priv) >= 4) {
1462 intel_de_write(dev_priv, DPLL_MD(pipe),
1463 crtc_state->dpll_hw_state.dpll_md);
1465 /* The pixel multiplier can only be updated once the
1466 * DPLL is enabled and the clocks are stable.
1468 * So write it again.
1470 intel_de_write(dev_priv, DPLL(pipe), dpll);
1473 /* We do this three times for luck */
1474 for (i = 0; i < 3; i++) {
1475 intel_de_write(dev_priv, DPLL(pipe), dpll);
1476 intel_de_posting_read(dev_priv, DPLL(pipe));
1477 udelay(150); /* wait for warmup */
1481 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv,
1487 * PLLB opamp always calibrates to max value of 0x3f, force enable it
1488 * and set it to a reasonable value instead.
1490 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
1491 reg_val &= 0xffffff00;
1492 reg_val |= 0x00000030;
1493 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
1495 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
1496 reg_val &= 0x00ffffff;
1497 reg_val |= 0x8c000000;
1498 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
1500 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
1501 reg_val &= 0xffffff00;
1502 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
1504 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
1505 reg_val &= 0x00ffffff;
1506 reg_val |= 0xb0000000;
1507 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
1510 static void vlv_prepare_pll(const struct intel_crtc_state *crtc_state)
1512 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1513 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1514 enum pipe pipe = crtc->pipe;
1516 u32 bestn, bestm1, bestm2, bestp1, bestp2;
1517 u32 coreclk, reg_val;
1519 vlv_dpio_get(dev_priv);
1521 bestn = crtc_state->dpll.n;
1522 bestm1 = crtc_state->dpll.m1;
1523 bestm2 = crtc_state->dpll.m2;
1524 bestp1 = crtc_state->dpll.p1;
1525 bestp2 = crtc_state->dpll.p2;
1527 /* See eDP HDMI DPIO driver vbios notes doc */
1529 /* PLL B needs special handling */
1531 vlv_pllb_recal_opamp(dev_priv, pipe);
1533 /* Set up Tx target for periodic Rcomp update */
1534 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
1536 /* Disable target IRef on PLL */
1537 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
1538 reg_val &= 0x00ffffff;
1539 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
1541 /* Disable fast lock */
1542 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
1544 /* Set idtafcrecal before PLL is enabled */
1545 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
1546 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
1547 mdiv |= ((bestn << DPIO_N_SHIFT));
1548 mdiv |= (1 << DPIO_K_SHIFT);
1551 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
1552 * but we don't support that).
1553 * Note: don't use the DAC post divider as it seems unstable.
1555 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
1556 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
1558 mdiv |= DPIO_ENABLE_CALIBRATION;
1559 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
1561 /* Set HBR and RBR LPF coefficients */
1562 if (crtc_state->port_clock == 162000 ||
1563 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG) ||
1564 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1565 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
1568 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
1571 if (intel_crtc_has_dp_encoder(crtc_state)) {
1572 /* Use SSC source */
1574 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
1577 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
1579 } else { /* HDMI or VGA */
1580 /* Use bend source */
1582 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
1585 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
1589 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
1590 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
1591 if (intel_crtc_has_dp_encoder(crtc_state))
1592 coreclk |= 0x01000000;
1593 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
1595 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
1597 vlv_dpio_put(dev_priv);
1600 static void _vlv_enable_pll(const struct intel_crtc_state *crtc_state)
1602 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1603 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1604 enum pipe pipe = crtc->pipe;
1606 intel_de_write(dev_priv, DPLL(pipe), crtc_state->dpll_hw_state.dpll);
1607 intel_de_posting_read(dev_priv, DPLL(pipe));
1610 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1611 drm_err(&dev_priv->drm, "DPLL %d failed to lock\n", pipe);
1614 void vlv_enable_pll(const struct intel_crtc_state *crtc_state)
1616 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1617 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1618 enum pipe pipe = crtc->pipe;
1620 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder);
1622 /* PLL is protected by panel, make sure we can write it */
1623 assert_pps_unlocked(dev_priv, pipe);
1626 intel_de_write(dev_priv, DPLL(pipe),
1627 crtc_state->dpll_hw_state.dpll &
1628 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
1630 if (crtc_state->dpll_hw_state.dpll & DPLL_VCO_ENABLE) {
1631 vlv_prepare_pll(crtc_state);
1632 _vlv_enable_pll(crtc_state);
1635 intel_de_write(dev_priv, DPLL_MD(pipe),
1636 crtc_state->dpll_hw_state.dpll_md);
1637 intel_de_posting_read(dev_priv, DPLL_MD(pipe));
1640 static void chv_prepare_pll(const struct intel_crtc_state *crtc_state)
1642 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1643 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1644 enum pipe pipe = crtc->pipe;
1645 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1646 u32 loopfilter, tribuf_calcntr;
1647 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
1651 bestn = crtc_state->dpll.n;
1652 bestm2_frac = crtc_state->dpll.m2 & 0x3fffff;
1653 bestm1 = crtc_state->dpll.m1;
1654 bestm2 = crtc_state->dpll.m2 >> 22;
1655 bestp1 = crtc_state->dpll.p1;
1656 bestp2 = crtc_state->dpll.p2;
1657 vco = crtc_state->dpll.vco;
1661 vlv_dpio_get(dev_priv);
1663 /* p1 and p2 divider */
1664 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
1665 5 << DPIO_CHV_S1_DIV_SHIFT |
1666 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
1667 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
1668 1 << DPIO_CHV_K_DIV_SHIFT);
1670 /* Feedback post-divider - m2 */
1671 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
1673 /* Feedback refclk divider - n and m1 */
1674 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
1675 DPIO_CHV_M1_DIV_BY_2 |
1676 1 << DPIO_CHV_N_DIV_SHIFT);
1678 /* M2 fraction division */
1679 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
1681 /* M2 fraction division enable */
1682 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
1683 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
1684 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
1686 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
1687 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
1689 /* Program digital lock detect threshold */
1690 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
1691 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
1692 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
1693 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
1695 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
1696 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
1699 if (vco == 5400000) {
1700 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
1701 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
1702 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
1703 tribuf_calcntr = 0x9;
1704 } else if (vco <= 6200000) {
1705 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
1706 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
1707 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
1708 tribuf_calcntr = 0x9;
1709 } else if (vco <= 6480000) {
1710 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
1711 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
1712 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
1713 tribuf_calcntr = 0x8;
1715 /* Not supported. Apply the same limits as in the max case */
1716 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
1717 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
1718 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
1721 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
1723 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
1724 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
1725 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
1726 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
1729 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
1730 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
1733 vlv_dpio_put(dev_priv);
1736 static void _chv_enable_pll(const struct intel_crtc_state *crtc_state)
1738 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1739 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1740 enum pipe pipe = crtc->pipe;
1741 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1744 vlv_dpio_get(dev_priv);
1746 /* Enable back the 10bit clock to display controller */
1747 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1748 tmp |= DPIO_DCLKP_EN;
1749 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1751 vlv_dpio_put(dev_priv);
1754 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1759 intel_de_write(dev_priv, DPLL(pipe), crtc_state->dpll_hw_state.dpll);
1761 /* Check PLL is locked */
1762 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
1763 drm_err(&dev_priv->drm, "PLL %d failed to lock\n", pipe);
1766 void chv_enable_pll(const struct intel_crtc_state *crtc_state)
1768 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1769 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1770 enum pipe pipe = crtc->pipe;
1772 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder);
1774 /* PLL is protected by panel, make sure we can write it */
1775 assert_pps_unlocked(dev_priv, pipe);
1777 /* Enable Refclk and SSC */
1778 intel_de_write(dev_priv, DPLL(pipe),
1779 crtc_state->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
1781 if (crtc_state->dpll_hw_state.dpll & DPLL_VCO_ENABLE) {
1782 chv_prepare_pll(crtc_state);
1783 _chv_enable_pll(crtc_state);
1786 if (pipe != PIPE_A) {
1788 * WaPixelRepeatModeFixForC0:chv
1790 * DPLLCMD is AWOL. Use chicken bits to propagate
1791 * the value from DPLLBMD to either pipe B or C.
1793 intel_de_write(dev_priv, CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
1794 intel_de_write(dev_priv, DPLL_MD(PIPE_B),
1795 crtc_state->dpll_hw_state.dpll_md);
1796 intel_de_write(dev_priv, CBR4_VLV, 0);
1797 dev_priv->chv_dpll_md[pipe] = crtc_state->dpll_hw_state.dpll_md;
1800 * DPLLB VGA mode also seems to cause problems.
1801 * We should always have it disabled.
1803 drm_WARN_ON(&dev_priv->drm,
1804 (intel_de_read(dev_priv, DPLL(PIPE_B)) &
1805 DPLL_VGA_MODE_DIS) == 0);
1807 intel_de_write(dev_priv, DPLL_MD(pipe),
1808 crtc_state->dpll_hw_state.dpll_md);
1809 intel_de_posting_read(dev_priv, DPLL_MD(pipe));
1814 * vlv_force_pll_on - forcibly enable just the PLL
1815 * @dev_priv: i915 private structure
1816 * @pipe: pipe PLL to enable
1817 * @dpll: PLL configuration
1819 * Enable the PLL for @pipe using the supplied @dpll config. To be used
1820 * in cases where we need the PLL enabled even when @pipe is not going to
1823 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
1824 const struct dpll *dpll)
1826 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1827 struct intel_crtc_state *crtc_state;
1829 crtc_state = intel_crtc_state_alloc(crtc);
1833 crtc_state->cpu_transcoder = (enum transcoder)pipe;
1834 crtc_state->pixel_multiplier = 1;
1835 crtc_state->dpll = *dpll;
1836 crtc_state->output_types = BIT(INTEL_OUTPUT_EDP);
1838 if (IS_CHERRYVIEW(dev_priv)) {
1839 chv_compute_dpll(crtc_state);
1840 chv_enable_pll(crtc_state);
1842 vlv_compute_dpll(crtc_state);
1843 vlv_enable_pll(crtc_state);
1851 void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1855 /* Make sure the pipe isn't still relying on us */
1856 assert_transcoder_disabled(dev_priv, (enum transcoder)pipe);
1858 val = DPLL_INTEGRATED_REF_CLK_VLV |
1859 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1861 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1863 intel_de_write(dev_priv, DPLL(pipe), val);
1864 intel_de_posting_read(dev_priv, DPLL(pipe));
1867 void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1869 enum dpio_channel port = vlv_pipe_to_channel(pipe);
1872 /* Make sure the pipe isn't still relying on us */
1873 assert_transcoder_disabled(dev_priv, (enum transcoder)pipe);
1875 val = DPLL_SSC_REF_CLK_CHV |
1876 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1878 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1880 intel_de_write(dev_priv, DPLL(pipe), val);
1881 intel_de_posting_read(dev_priv, DPLL(pipe));
1883 vlv_dpio_get(dev_priv);
1885 /* Disable 10bit clock to display controller */
1886 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1887 val &= ~DPIO_DCLKP_EN;
1888 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1890 vlv_dpio_put(dev_priv);
1893 void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
1895 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1896 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1897 enum pipe pipe = crtc->pipe;
1899 /* Don't disable pipe or pipe PLLs if needed */
1900 if (IS_I830(dev_priv))
1903 /* Make sure the pipe isn't still relying on us */
1904 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder);
1906 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
1907 intel_de_posting_read(dev_priv, DPLL(pipe));
1912 * vlv_force_pll_off - forcibly disable just the PLL
1913 * @dev_priv: i915 private structure
1914 * @pipe: pipe PLL to disable
1916 * Disable the PLL for @pipe. To be used in cases where we need
1917 * the PLL enabled even when @pipe is not going to be enabled.
1919 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
1921 if (IS_CHERRYVIEW(dev_priv))
1922 chv_disable_pll(dev_priv, pipe);
1924 vlv_disable_pll(dev_priv, pipe);
1927 /* Only for pre-ILK configs */
1928 static void assert_pll(struct drm_i915_private *dev_priv,
1929 enum pipe pipe, bool state)
1933 cur_state = intel_de_read(dev_priv, DPLL(pipe)) & DPLL_VCO_ENABLE;
1934 I915_STATE_WARN(cur_state != state,
1935 "PLL state assertion failure (expected %s, current %s)\n",
1936 onoff(state), onoff(cur_state));
1939 void assert_pll_enabled(struct drm_i915_private *i915, enum pipe pipe)
1941 assert_pll(i915, pipe, true);
1944 void assert_pll_disabled(struct drm_i915_private *i915, enum pipe pipe)
1946 assert_pll(i915, pipe, false);