2 * Copyright © 2006-2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #include "intel_drv.h"
29 * The display engine uses several different clocks to do its work. There
30 * are two main clocks involved that aren't directly related to the actual
31 * pixel clock or any symbol/bit clock of the actual output port. These
32 * are the core display clock (CDCLK) and RAWCLK.
34 * CDCLK clocks most of the display pipe logic, and thus its frequency
35 * must be high enough to support the rate at which pixels are flowing
36 * through the pipes. Downscaling must also be accounted as that increases
37 * the effective pixel rate.
39 * On several platforms the CDCLK frequency can be changed dynamically
40 * to minimize power consumption for a given display configuration.
41 * Typically changes to the CDCLK frequency require all the display pipes
42 * to be shut down while the frequency is being changed.
44 * On SKL+ the DMC will toggle the CDCLK off/on during DC5/6 entry/exit.
45 * DMC will not change the active CDCLK frequency however, so that part
46 * will still be performed by the driver directly.
48 * RAWCLK is a fixed frequency clock, often used by various auxiliary
49 * blocks such as AUX CH or backlight PWM. Hence the only thing we
50 * really need to know about RAWCLK is its frequency so that various
51 * dividers can be programmed correctly.
54 static void fixed_133mhz_get_cdclk(struct drm_i915_private
*dev_priv
,
55 struct intel_cdclk_state
*cdclk_state
)
57 cdclk_state
->cdclk
= 133333;
60 static void fixed_200mhz_get_cdclk(struct drm_i915_private
*dev_priv
,
61 struct intel_cdclk_state
*cdclk_state
)
63 cdclk_state
->cdclk
= 200000;
66 static void fixed_266mhz_get_cdclk(struct drm_i915_private
*dev_priv
,
67 struct intel_cdclk_state
*cdclk_state
)
69 cdclk_state
->cdclk
= 266667;
72 static void fixed_333mhz_get_cdclk(struct drm_i915_private
*dev_priv
,
73 struct intel_cdclk_state
*cdclk_state
)
75 cdclk_state
->cdclk
= 333333;
78 static void fixed_400mhz_get_cdclk(struct drm_i915_private
*dev_priv
,
79 struct intel_cdclk_state
*cdclk_state
)
81 cdclk_state
->cdclk
= 400000;
84 static void fixed_450mhz_get_cdclk(struct drm_i915_private
*dev_priv
,
85 struct intel_cdclk_state
*cdclk_state
)
87 cdclk_state
->cdclk
= 450000;
90 static void i85x_get_cdclk(struct drm_i915_private
*dev_priv
,
91 struct intel_cdclk_state
*cdclk_state
)
93 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
97 * 852GM/852GMV only supports 133 MHz and the HPLLCC
98 * encoding is different :(
99 * FIXME is this the right way to detect 852GM/852GMV?
101 if (pdev
->revision
== 0x1) {
102 cdclk_state
->cdclk
= 133333;
106 pci_bus_read_config_word(pdev
->bus
,
107 PCI_DEVFN(0, 3), HPLLCC
, &hpllcc
);
109 /* Assume that the hardware is in the high speed state. This
110 * should be the default.
112 switch (hpllcc
& GC_CLOCK_CONTROL_MASK
) {
113 case GC_CLOCK_133_200
:
114 case GC_CLOCK_133_200_2
:
115 case GC_CLOCK_100_200
:
116 cdclk_state
->cdclk
= 200000;
118 case GC_CLOCK_166_250
:
119 cdclk_state
->cdclk
= 250000;
121 case GC_CLOCK_100_133
:
122 cdclk_state
->cdclk
= 133333;
124 case GC_CLOCK_133_266
:
125 case GC_CLOCK_133_266_2
:
126 case GC_CLOCK_166_266
:
127 cdclk_state
->cdclk
= 266667;
132 static void i915gm_get_cdclk(struct drm_i915_private
*dev_priv
,
133 struct intel_cdclk_state
*cdclk_state
)
135 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
138 pci_read_config_word(pdev
, GCFGC
, &gcfgc
);
140 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
) {
141 cdclk_state
->cdclk
= 133333;
145 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
146 case GC_DISPLAY_CLOCK_333_320_MHZ
:
147 cdclk_state
->cdclk
= 333333;
150 case GC_DISPLAY_CLOCK_190_200_MHZ
:
151 cdclk_state
->cdclk
= 190000;
156 static void i945gm_get_cdclk(struct drm_i915_private
*dev_priv
,
157 struct intel_cdclk_state
*cdclk_state
)
159 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
162 pci_read_config_word(pdev
, GCFGC
, &gcfgc
);
164 if (gcfgc
& GC_LOW_FREQUENCY_ENABLE
) {
165 cdclk_state
->cdclk
= 133333;
169 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
170 case GC_DISPLAY_CLOCK_333_320_MHZ
:
171 cdclk_state
->cdclk
= 320000;
174 case GC_DISPLAY_CLOCK_190_200_MHZ
:
175 cdclk_state
->cdclk
= 200000;
180 static unsigned int intel_hpll_vco(struct drm_i915_private
*dev_priv
)
182 static const unsigned int blb_vco
[8] = {
189 static const unsigned int pnv_vco
[8] = {
196 static const unsigned int cl_vco
[8] = {
205 static const unsigned int elk_vco
[8] = {
211 static const unsigned int ctg_vco
[8] = {
219 const unsigned int *vco_table
;
223 /* FIXME other chipsets? */
224 if (IS_GM45(dev_priv
))
226 else if (IS_G45(dev_priv
))
228 else if (IS_I965GM(dev_priv
))
230 else if (IS_PINEVIEW(dev_priv
))
232 else if (IS_G33(dev_priv
))
237 tmp
= I915_READ(IS_MOBILE(dev_priv
) ? HPLLVCO_MOBILE
: HPLLVCO
);
239 vco
= vco_table
[tmp
& 0x7];
241 DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp
);
243 DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco
);
248 static void g33_get_cdclk(struct drm_i915_private
*dev_priv
,
249 struct intel_cdclk_state
*cdclk_state
)
251 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
252 static const uint8_t div_3200
[] = { 12, 10, 8, 7, 5, 16 };
253 static const uint8_t div_4000
[] = { 14, 12, 10, 8, 6, 20 };
254 static const uint8_t div_4800
[] = { 20, 14, 12, 10, 8, 24 };
255 static const uint8_t div_5333
[] = { 20, 16, 12, 12, 8, 28 };
256 const uint8_t *div_table
;
257 unsigned int cdclk_sel
;
260 cdclk_state
->vco
= intel_hpll_vco(dev_priv
);
262 pci_read_config_word(pdev
, GCFGC
, &tmp
);
264 cdclk_sel
= (tmp
>> 4) & 0x7;
266 if (cdclk_sel
>= ARRAY_SIZE(div_3200
))
269 switch (cdclk_state
->vco
) {
271 div_table
= div_3200
;
274 div_table
= div_4000
;
277 div_table
= div_4800
;
280 div_table
= div_5333
;
286 cdclk_state
->cdclk
= DIV_ROUND_CLOSEST(cdclk_state
->vco
,
287 div_table
[cdclk_sel
]);
291 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n",
292 cdclk_state
->vco
, tmp
);
293 cdclk_state
->cdclk
= 190476;
296 static void pnv_get_cdclk(struct drm_i915_private
*dev_priv
,
297 struct intel_cdclk_state
*cdclk_state
)
299 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
302 pci_read_config_word(pdev
, GCFGC
, &gcfgc
);
304 switch (gcfgc
& GC_DISPLAY_CLOCK_MASK
) {
305 case GC_DISPLAY_CLOCK_267_MHZ_PNV
:
306 cdclk_state
->cdclk
= 266667;
308 case GC_DISPLAY_CLOCK_333_MHZ_PNV
:
309 cdclk_state
->cdclk
= 333333;
311 case GC_DISPLAY_CLOCK_444_MHZ_PNV
:
312 cdclk_state
->cdclk
= 444444;
314 case GC_DISPLAY_CLOCK_200_MHZ_PNV
:
315 cdclk_state
->cdclk
= 200000;
318 DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc
);
319 case GC_DISPLAY_CLOCK_133_MHZ_PNV
:
320 cdclk_state
->cdclk
= 133333;
322 case GC_DISPLAY_CLOCK_167_MHZ_PNV
:
323 cdclk_state
->cdclk
= 166667;
328 static void i965gm_get_cdclk(struct drm_i915_private
*dev_priv
,
329 struct intel_cdclk_state
*cdclk_state
)
331 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
332 static const uint8_t div_3200
[] = { 16, 10, 8 };
333 static const uint8_t div_4000
[] = { 20, 12, 10 };
334 static const uint8_t div_5333
[] = { 24, 16, 14 };
335 const uint8_t *div_table
;
336 unsigned int cdclk_sel
;
339 cdclk_state
->vco
= intel_hpll_vco(dev_priv
);
341 pci_read_config_word(pdev
, GCFGC
, &tmp
);
343 cdclk_sel
= ((tmp
>> 8) & 0x1f) - 1;
345 if (cdclk_sel
>= ARRAY_SIZE(div_3200
))
348 switch (cdclk_state
->vco
) {
350 div_table
= div_3200
;
353 div_table
= div_4000
;
356 div_table
= div_5333
;
362 cdclk_state
->cdclk
= DIV_ROUND_CLOSEST(cdclk_state
->vco
,
363 div_table
[cdclk_sel
]);
367 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n",
368 cdclk_state
->vco
, tmp
);
369 cdclk_state
->cdclk
= 200000;
372 static void gm45_get_cdclk(struct drm_i915_private
*dev_priv
,
373 struct intel_cdclk_state
*cdclk_state
)
375 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
376 unsigned int cdclk_sel
;
379 cdclk_state
->vco
= intel_hpll_vco(dev_priv
);
381 pci_read_config_word(pdev
, GCFGC
, &tmp
);
383 cdclk_sel
= (tmp
>> 12) & 0x1;
385 switch (cdclk_state
->vco
) {
389 cdclk_state
->cdclk
= cdclk_sel
? 333333 : 222222;
392 cdclk_state
->cdclk
= cdclk_sel
? 320000 : 228571;
395 DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n",
396 cdclk_state
->vco
, tmp
);
397 cdclk_state
->cdclk
= 222222;
402 static void hsw_get_cdclk(struct drm_i915_private
*dev_priv
,
403 struct intel_cdclk_state
*cdclk_state
)
405 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
406 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
408 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
409 cdclk_state
->cdclk
= 800000;
410 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
411 cdclk_state
->cdclk
= 450000;
412 else if (freq
== LCPLL_CLK_FREQ_450
)
413 cdclk_state
->cdclk
= 450000;
414 else if (IS_HSW_ULT(dev_priv
))
415 cdclk_state
->cdclk
= 337500;
417 cdclk_state
->cdclk
= 540000;
420 static int vlv_calc_cdclk(struct drm_i915_private
*dev_priv
, int min_cdclk
)
422 int freq_320
= (dev_priv
->hpll_freq
<< 1) % 320000 != 0 ?
426 * We seem to get an unstable or solid color picture at 200MHz.
427 * Not sure what's wrong. For now use 200MHz only when all pipes
430 if (IS_VALLEYVIEW(dev_priv
) && min_cdclk
> freq_320
)
432 else if (min_cdclk
> 266667)
434 else if (min_cdclk
> 0)
440 static u8
vlv_calc_voltage_level(struct drm_i915_private
*dev_priv
, int cdclk
)
442 if (IS_VALLEYVIEW(dev_priv
)) {
443 if (cdclk
>= 320000) /* jump to highest voltage for 400MHz too */
445 else if (cdclk
>= 266667)
451 * Specs are full of misinformation, but testing on actual
452 * hardware has shown that we just need to write the desired
453 * CCK divider into the Punit register.
455 return DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1, cdclk
) - 1;
459 static void vlv_get_cdclk(struct drm_i915_private
*dev_priv
,
460 struct intel_cdclk_state
*cdclk_state
)
464 cdclk_state
->vco
= vlv_get_hpll_vco(dev_priv
);
465 cdclk_state
->cdclk
= vlv_get_cck_clock(dev_priv
, "cdclk",
466 CCK_DISPLAY_CLOCK_CONTROL
,
469 mutex_lock(&dev_priv
->pcu_lock
);
470 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
471 mutex_unlock(&dev_priv
->pcu_lock
);
473 if (IS_VALLEYVIEW(dev_priv
))
474 cdclk_state
->voltage_level
= (val
& DSPFREQGUAR_MASK
) >>
477 cdclk_state
->voltage_level
= (val
& DSPFREQGUAR_MASK_CHV
) >>
478 DSPFREQGUAR_SHIFT_CHV
;
481 static void vlv_program_pfi_credits(struct drm_i915_private
*dev_priv
)
483 unsigned int credits
, default_credits
;
485 if (IS_CHERRYVIEW(dev_priv
))
486 default_credits
= PFI_CREDIT(12);
488 default_credits
= PFI_CREDIT(8);
490 if (dev_priv
->cdclk
.hw
.cdclk
>= dev_priv
->czclk_freq
) {
491 /* CHV suggested value is 31 or 63 */
492 if (IS_CHERRYVIEW(dev_priv
))
493 credits
= PFI_CREDIT_63
;
495 credits
= PFI_CREDIT(15);
497 credits
= default_credits
;
501 * WA - write default credits before re-programming
502 * FIXME: should we also set the resend bit here?
504 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
507 I915_WRITE(GCI_CONTROL
, VGA_FAST_MODE_DISABLE
|
508 credits
| PFI_CREDIT_RESEND
);
511 * FIXME is this guaranteed to clear
512 * immediately or should we poll for it?
514 WARN_ON(I915_READ(GCI_CONTROL
) & PFI_CREDIT_RESEND
);
517 static void vlv_set_cdclk(struct drm_i915_private
*dev_priv
,
518 const struct intel_cdclk_state
*cdclk_state
)
520 int cdclk
= cdclk_state
->cdclk
;
521 u32 val
, cmd
= cdclk_state
->voltage_level
;
535 /* There are cases where we can end up here with power domains
536 * off and a CDCLK frequency other than the minimum, like when
537 * issuing a modeset without actually changing any display after
538 * a system suspend. So grab the PIPE-A domain, which covers
539 * the HW blocks needed for the following programming.
541 intel_display_power_get(dev_priv
, POWER_DOMAIN_PIPE_A
);
543 mutex_lock(&dev_priv
->pcu_lock
);
544 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
545 val
&= ~DSPFREQGUAR_MASK
;
546 val
|= (cmd
<< DSPFREQGUAR_SHIFT
);
547 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
548 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
549 DSPFREQSTAT_MASK
) == (cmd
<< DSPFREQSTAT_SHIFT
),
551 DRM_ERROR("timed out waiting for CDclk change\n");
553 mutex_unlock(&dev_priv
->pcu_lock
);
555 mutex_lock(&dev_priv
->sb_lock
);
557 if (cdclk
== 400000) {
560 divider
= DIV_ROUND_CLOSEST(dev_priv
->hpll_freq
<< 1,
563 /* adjust cdclk divider */
564 val
= vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
);
565 val
&= ~CCK_FREQUENCY_VALUES
;
567 vlv_cck_write(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
, val
);
569 if (wait_for((vlv_cck_read(dev_priv
, CCK_DISPLAY_CLOCK_CONTROL
) &
570 CCK_FREQUENCY_STATUS
) == (divider
<< CCK_FREQUENCY_STATUS_SHIFT
),
572 DRM_ERROR("timed out waiting for CDclk change\n");
575 /* adjust self-refresh exit latency value */
576 val
= vlv_bunit_read(dev_priv
, BUNIT_REG_BISOC
);
580 * For high bandwidth configs, we set a higher latency in the bunit
581 * so that the core display fetch happens in time to avoid underruns.
584 val
|= 4500 / 250; /* 4.5 usec */
586 val
|= 3000 / 250; /* 3.0 usec */
587 vlv_bunit_write(dev_priv
, BUNIT_REG_BISOC
, val
);
589 mutex_unlock(&dev_priv
->sb_lock
);
591 intel_update_cdclk(dev_priv
);
593 vlv_program_pfi_credits(dev_priv
);
595 intel_display_power_put(dev_priv
, POWER_DOMAIN_PIPE_A
);
598 static void chv_set_cdclk(struct drm_i915_private
*dev_priv
,
599 const struct intel_cdclk_state
*cdclk_state
)
601 int cdclk
= cdclk_state
->cdclk
;
602 u32 val
, cmd
= cdclk_state
->voltage_level
;
615 /* There are cases where we can end up here with power domains
616 * off and a CDCLK frequency other than the minimum, like when
617 * issuing a modeset without actually changing any display after
618 * a system suspend. So grab the PIPE-A domain, which covers
619 * the HW blocks needed for the following programming.
621 intel_display_power_get(dev_priv
, POWER_DOMAIN_PIPE_A
);
623 mutex_lock(&dev_priv
->pcu_lock
);
624 val
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
625 val
&= ~DSPFREQGUAR_MASK_CHV
;
626 val
|= (cmd
<< DSPFREQGUAR_SHIFT_CHV
);
627 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, val
);
628 if (wait_for((vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) &
629 DSPFREQSTAT_MASK_CHV
) == (cmd
<< DSPFREQSTAT_SHIFT_CHV
),
631 DRM_ERROR("timed out waiting for CDclk change\n");
633 mutex_unlock(&dev_priv
->pcu_lock
);
635 intel_update_cdclk(dev_priv
);
637 vlv_program_pfi_credits(dev_priv
);
639 intel_display_power_put(dev_priv
, POWER_DOMAIN_PIPE_A
);
642 static int bdw_calc_cdclk(int min_cdclk
)
644 if (min_cdclk
> 540000)
646 else if (min_cdclk
> 450000)
648 else if (min_cdclk
> 337500)
654 static u8
bdw_calc_voltage_level(int cdclk
)
669 static void bdw_get_cdclk(struct drm_i915_private
*dev_priv
,
670 struct intel_cdclk_state
*cdclk_state
)
672 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
673 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
675 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
676 cdclk_state
->cdclk
= 800000;
677 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
678 cdclk_state
->cdclk
= 450000;
679 else if (freq
== LCPLL_CLK_FREQ_450
)
680 cdclk_state
->cdclk
= 450000;
681 else if (freq
== LCPLL_CLK_FREQ_54O_BDW
)
682 cdclk_state
->cdclk
= 540000;
683 else if (freq
== LCPLL_CLK_FREQ_337_5_BDW
)
684 cdclk_state
->cdclk
= 337500;
686 cdclk_state
->cdclk
= 675000;
689 * Can't read this out :( Let's assume it's
690 * at least what the CDCLK frequency requires.
692 cdclk_state
->voltage_level
=
693 bdw_calc_voltage_level(cdclk_state
->cdclk
);
696 static void bdw_set_cdclk(struct drm_i915_private
*dev_priv
,
697 const struct intel_cdclk_state
*cdclk_state
)
699 int cdclk
= cdclk_state
->cdclk
;
703 if (WARN((I915_READ(LCPLL_CTL
) &
704 (LCPLL_PLL_DISABLE
| LCPLL_PLL_LOCK
|
705 LCPLL_CD_CLOCK_DISABLE
| LCPLL_ROOT_CD_CLOCK_DISABLE
|
706 LCPLL_CD2X_CLOCK_DISABLE
| LCPLL_POWER_DOWN_ALLOW
|
707 LCPLL_CD_SOURCE_FCLK
)) != LCPLL_PLL_LOCK
,
708 "trying to change cdclk frequency with cdclk not enabled\n"))
711 mutex_lock(&dev_priv
->pcu_lock
);
712 ret
= sandybridge_pcode_write(dev_priv
,
713 BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ
, 0x0);
714 mutex_unlock(&dev_priv
->pcu_lock
);
716 DRM_ERROR("failed to inform pcode about cdclk change\n");
720 val
= I915_READ(LCPLL_CTL
);
721 val
|= LCPLL_CD_SOURCE_FCLK
;
722 I915_WRITE(LCPLL_CTL
, val
);
725 * According to the spec, it should be enough to poll for this 1 us.
726 * However, extensive testing shows that this can take longer.
728 if (wait_for_us(I915_READ(LCPLL_CTL
) &
729 LCPLL_CD_SOURCE_FCLK_DONE
, 100))
730 DRM_ERROR("Switching to FCLK failed\n");
732 val
= I915_READ(LCPLL_CTL
);
733 val
&= ~LCPLL_CLK_FREQ_MASK
;
740 val
|= LCPLL_CLK_FREQ_337_5_BDW
;
743 val
|= LCPLL_CLK_FREQ_450
;
746 val
|= LCPLL_CLK_FREQ_54O_BDW
;
749 val
|= LCPLL_CLK_FREQ_675_BDW
;
753 I915_WRITE(LCPLL_CTL
, val
);
755 val
= I915_READ(LCPLL_CTL
);
756 val
&= ~LCPLL_CD_SOURCE_FCLK
;
757 I915_WRITE(LCPLL_CTL
, val
);
759 if (wait_for_us((I915_READ(LCPLL_CTL
) &
760 LCPLL_CD_SOURCE_FCLK_DONE
) == 0, 1))
761 DRM_ERROR("Switching back to LCPLL failed\n");
763 mutex_lock(&dev_priv
->pcu_lock
);
764 sandybridge_pcode_write(dev_priv
, HSW_PCODE_DE_WRITE_FREQ_REQ
,
765 cdclk_state
->voltage_level
);
766 mutex_unlock(&dev_priv
->pcu_lock
);
768 I915_WRITE(CDCLK_FREQ
, DIV_ROUND_CLOSEST(cdclk
, 1000) - 1);
770 intel_update_cdclk(dev_priv
);
773 static int skl_calc_cdclk(int min_cdclk
, int vco
)
775 if (vco
== 8640000) {
776 if (min_cdclk
> 540000)
778 else if (min_cdclk
> 432000)
780 else if (min_cdclk
> 308571)
785 if (min_cdclk
> 540000)
787 else if (min_cdclk
> 450000)
789 else if (min_cdclk
> 337500)
796 static u8
skl_calc_voltage_level(int cdclk
)
814 static void skl_dpll0_update(struct drm_i915_private
*dev_priv
,
815 struct intel_cdclk_state
*cdclk_state
)
819 cdclk_state
->ref
= 24000;
820 cdclk_state
->vco
= 0;
822 val
= I915_READ(LCPLL1_CTL
);
823 if ((val
& LCPLL_PLL_ENABLE
) == 0)
826 if (WARN_ON((val
& LCPLL_PLL_LOCK
) == 0))
829 val
= I915_READ(DPLL_CTRL1
);
831 if (WARN_ON((val
& (DPLL_CTRL1_HDMI_MODE(SKL_DPLL0
) |
832 DPLL_CTRL1_SSC(SKL_DPLL0
) |
833 DPLL_CTRL1_OVERRIDE(SKL_DPLL0
))) !=
834 DPLL_CTRL1_OVERRIDE(SKL_DPLL0
)))
837 switch (val
& DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
)) {
838 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810
, SKL_DPLL0
):
839 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350
, SKL_DPLL0
):
840 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620
, SKL_DPLL0
):
841 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700
, SKL_DPLL0
):
842 cdclk_state
->vco
= 8100000;
844 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080
, SKL_DPLL0
):
845 case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2160
, SKL_DPLL0
):
846 cdclk_state
->vco
= 8640000;
849 MISSING_CASE(val
& DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
));
854 static void skl_get_cdclk(struct drm_i915_private
*dev_priv
,
855 struct intel_cdclk_state
*cdclk_state
)
859 skl_dpll0_update(dev_priv
, cdclk_state
);
861 cdclk_state
->cdclk
= cdclk_state
->ref
;
863 if (cdclk_state
->vco
== 0)
866 cdctl
= I915_READ(CDCLK_CTL
);
868 if (cdclk_state
->vco
== 8640000) {
869 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
870 case CDCLK_FREQ_450_432
:
871 cdclk_state
->cdclk
= 432000;
873 case CDCLK_FREQ_337_308
:
874 cdclk_state
->cdclk
= 308571;
877 cdclk_state
->cdclk
= 540000;
879 case CDCLK_FREQ_675_617
:
880 cdclk_state
->cdclk
= 617143;
883 MISSING_CASE(cdctl
& CDCLK_FREQ_SEL_MASK
);
887 switch (cdctl
& CDCLK_FREQ_SEL_MASK
) {
888 case CDCLK_FREQ_450_432
:
889 cdclk_state
->cdclk
= 450000;
891 case CDCLK_FREQ_337_308
:
892 cdclk_state
->cdclk
= 337500;
895 cdclk_state
->cdclk
= 540000;
897 case CDCLK_FREQ_675_617
:
898 cdclk_state
->cdclk
= 675000;
901 MISSING_CASE(cdctl
& CDCLK_FREQ_SEL_MASK
);
908 * Can't read this out :( Let's assume it's
909 * at least what the CDCLK frequency requires.
911 cdclk_state
->voltage_level
=
912 skl_calc_voltage_level(cdclk_state
->cdclk
);
915 /* convert from kHz to .1 fixpoint MHz with -1MHz offset */
916 static int skl_cdclk_decimal(int cdclk
)
918 return DIV_ROUND_CLOSEST(cdclk
- 1000, 500);
921 static void skl_set_preferred_cdclk_vco(struct drm_i915_private
*dev_priv
,
924 bool changed
= dev_priv
->skl_preferred_vco_freq
!= vco
;
926 dev_priv
->skl_preferred_vco_freq
= vco
;
929 intel_update_max_cdclk(dev_priv
);
932 static void skl_dpll0_enable(struct drm_i915_private
*dev_priv
, int vco
)
936 WARN_ON(vco
!= 8100000 && vco
!= 8640000);
939 * We always enable DPLL0 with the lowest link rate possible, but still
940 * taking into account the VCO required to operate the eDP panel at the
941 * desired frequency. The usual DP link rates operate with a VCO of
942 * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640.
943 * The modeset code is responsible for the selection of the exact link
944 * rate later on, with the constraint of choosing a frequency that
947 val
= I915_READ(DPLL_CTRL1
);
949 val
&= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0
) | DPLL_CTRL1_SSC(SKL_DPLL0
) |
950 DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0
));
951 val
|= DPLL_CTRL1_OVERRIDE(SKL_DPLL0
);
953 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080
,
956 val
|= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810
,
959 I915_WRITE(DPLL_CTRL1
, val
);
960 POSTING_READ(DPLL_CTRL1
);
962 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) | LCPLL_PLL_ENABLE
);
964 if (intel_wait_for_register(dev_priv
,
965 LCPLL1_CTL
, LCPLL_PLL_LOCK
, LCPLL_PLL_LOCK
,
967 DRM_ERROR("DPLL0 not locked\n");
969 dev_priv
->cdclk
.hw
.vco
= vco
;
971 /* We'll want to keep using the current vco from now on. */
972 skl_set_preferred_cdclk_vco(dev_priv
, vco
);
975 static void skl_dpll0_disable(struct drm_i915_private
*dev_priv
)
977 I915_WRITE(LCPLL1_CTL
, I915_READ(LCPLL1_CTL
) & ~LCPLL_PLL_ENABLE
);
978 if (intel_wait_for_register(dev_priv
,
979 LCPLL1_CTL
, LCPLL_PLL_LOCK
, 0,
981 DRM_ERROR("Couldn't disable DPLL0\n");
983 dev_priv
->cdclk
.hw
.vco
= 0;
986 static void skl_set_cdclk(struct drm_i915_private
*dev_priv
,
987 const struct intel_cdclk_state
*cdclk_state
)
989 int cdclk
= cdclk_state
->cdclk
;
990 int vco
= cdclk_state
->vco
;
991 u32 freq_select
, cdclk_ctl
;
994 mutex_lock(&dev_priv
->pcu_lock
);
995 ret
= skl_pcode_request(dev_priv
, SKL_PCODE_CDCLK_CONTROL
,
996 SKL_CDCLK_PREPARE_FOR_CHANGE
,
997 SKL_CDCLK_READY_FOR_CHANGE
,
998 SKL_CDCLK_READY_FOR_CHANGE
, 3);
999 mutex_unlock(&dev_priv
->pcu_lock
);
1001 DRM_ERROR("Failed to inform PCU about cdclk change (%d)\n",
1006 /* Choose frequency for this cdclk */
1009 WARN_ON(cdclk
!= dev_priv
->cdclk
.hw
.ref
);
1014 freq_select
= CDCLK_FREQ_337_308
;
1018 freq_select
= CDCLK_FREQ_450_432
;
1021 freq_select
= CDCLK_FREQ_540
;
1025 freq_select
= CDCLK_FREQ_675_617
;
1029 if (dev_priv
->cdclk
.hw
.vco
!= 0 &&
1030 dev_priv
->cdclk
.hw
.vco
!= vco
)
1031 skl_dpll0_disable(dev_priv
);
1033 cdclk_ctl
= I915_READ(CDCLK_CTL
);
1035 if (dev_priv
->cdclk
.hw
.vco
!= vco
) {
1036 /* Wa Display #1183: skl,kbl,cfl */
1037 cdclk_ctl
&= ~(CDCLK_FREQ_SEL_MASK
| CDCLK_FREQ_DECIMAL_MASK
);
1038 cdclk_ctl
|= freq_select
| skl_cdclk_decimal(cdclk
);
1039 I915_WRITE(CDCLK_CTL
, cdclk_ctl
);
1042 /* Wa Display #1183: skl,kbl,cfl */
1043 cdclk_ctl
|= CDCLK_DIVMUX_CD_OVERRIDE
;
1044 I915_WRITE(CDCLK_CTL
, cdclk_ctl
);
1045 POSTING_READ(CDCLK_CTL
);
1047 if (dev_priv
->cdclk
.hw
.vco
!= vco
)
1048 skl_dpll0_enable(dev_priv
, vco
);
1050 /* Wa Display #1183: skl,kbl,cfl */
1051 cdclk_ctl
&= ~(CDCLK_FREQ_SEL_MASK
| CDCLK_FREQ_DECIMAL_MASK
);
1052 I915_WRITE(CDCLK_CTL
, cdclk_ctl
);
1054 cdclk_ctl
|= freq_select
| skl_cdclk_decimal(cdclk
);
1055 I915_WRITE(CDCLK_CTL
, cdclk_ctl
);
1057 /* Wa Display #1183: skl,kbl,cfl */
1058 cdclk_ctl
&= ~CDCLK_DIVMUX_CD_OVERRIDE
;
1059 I915_WRITE(CDCLK_CTL
, cdclk_ctl
);
1060 POSTING_READ(CDCLK_CTL
);
1062 /* inform PCU of the change */
1063 mutex_lock(&dev_priv
->pcu_lock
);
1064 sandybridge_pcode_write(dev_priv
, SKL_PCODE_CDCLK_CONTROL
,
1065 cdclk_state
->voltage_level
);
1066 mutex_unlock(&dev_priv
->pcu_lock
);
1068 intel_update_cdclk(dev_priv
);
1071 static void skl_sanitize_cdclk(struct drm_i915_private
*dev_priv
)
1073 uint32_t cdctl
, expected
;
1076 * check if the pre-os initialized the display
1077 * There is SWF18 scratchpad register defined which is set by the
1078 * pre-os which can be used by the OS drivers to check the status
1080 if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0)
1083 intel_update_cdclk(dev_priv
);
1084 intel_dump_cdclk_state(&dev_priv
->cdclk
.hw
, "Current CDCLK");
1086 /* Is PLL enabled and locked ? */
1087 if (dev_priv
->cdclk
.hw
.vco
== 0 ||
1088 dev_priv
->cdclk
.hw
.cdclk
== dev_priv
->cdclk
.hw
.ref
)
1091 /* DPLL okay; verify the cdclock
1093 * Noticed in some instances that the freq selection is correct but
1094 * decimal part is programmed wrong from BIOS where pre-os does not
1095 * enable display. Verify the same as well.
1097 cdctl
= I915_READ(CDCLK_CTL
);
1098 expected
= (cdctl
& CDCLK_FREQ_SEL_MASK
) |
1099 skl_cdclk_decimal(dev_priv
->cdclk
.hw
.cdclk
);
1100 if (cdctl
== expected
)
1101 /* All well; nothing to sanitize */
1105 DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n");
1107 /* force cdclk programming */
1108 dev_priv
->cdclk
.hw
.cdclk
= 0;
1109 /* force full PLL disable + enable */
1110 dev_priv
->cdclk
.hw
.vco
= -1;
1114 * skl_init_cdclk - Initialize CDCLK on SKL
1115 * @dev_priv: i915 device
1117 * Initialize CDCLK for SKL and derivatives. This is generally
1118 * done only during the display core initialization sequence,
1119 * after which the DMC will take care of turning CDCLK off/on
1122 void skl_init_cdclk(struct drm_i915_private
*dev_priv
)
1124 struct intel_cdclk_state cdclk_state
;
1126 skl_sanitize_cdclk(dev_priv
);
1128 if (dev_priv
->cdclk
.hw
.cdclk
!= 0 &&
1129 dev_priv
->cdclk
.hw
.vco
!= 0) {
1131 * Use the current vco as our initial
1132 * guess as to what the preferred vco is.
1134 if (dev_priv
->skl_preferred_vco_freq
== 0)
1135 skl_set_preferred_cdclk_vco(dev_priv
,
1136 dev_priv
->cdclk
.hw
.vco
);
1140 cdclk_state
= dev_priv
->cdclk
.hw
;
1142 cdclk_state
.vco
= dev_priv
->skl_preferred_vco_freq
;
1143 if (cdclk_state
.vco
== 0)
1144 cdclk_state
.vco
= 8100000;
1145 cdclk_state
.cdclk
= skl_calc_cdclk(0, cdclk_state
.vco
);
1146 cdclk_state
.voltage_level
= skl_calc_voltage_level(cdclk_state
.cdclk
);
1148 skl_set_cdclk(dev_priv
, &cdclk_state
);
1152 * skl_uninit_cdclk - Uninitialize CDCLK on SKL
1153 * @dev_priv: i915 device
1155 * Uninitialize CDCLK for SKL and derivatives. This is done only
1156 * during the display core uninitialization sequence.
1158 void skl_uninit_cdclk(struct drm_i915_private
*dev_priv
)
1160 struct intel_cdclk_state cdclk_state
= dev_priv
->cdclk
.hw
;
1162 cdclk_state
.cdclk
= cdclk_state
.ref
;
1163 cdclk_state
.vco
= 0;
1164 cdclk_state
.voltage_level
= skl_calc_voltage_level(cdclk_state
.cdclk
);
1166 skl_set_cdclk(dev_priv
, &cdclk_state
);
1169 static int bxt_calc_cdclk(int min_cdclk
)
1171 if (min_cdclk
> 576000)
1173 else if (min_cdclk
> 384000)
1175 else if (min_cdclk
> 288000)
1177 else if (min_cdclk
> 144000)
1183 static int glk_calc_cdclk(int min_cdclk
)
1185 if (min_cdclk
> 158400)
1187 else if (min_cdclk
> 79200)
1193 static u8
bxt_calc_voltage_level(int cdclk
)
1195 return DIV_ROUND_UP(cdclk
, 25000);
1198 static int bxt_de_pll_vco(struct drm_i915_private
*dev_priv
, int cdclk
)
1202 if (cdclk
== dev_priv
->cdclk
.hw
.ref
)
1207 MISSING_CASE(cdclk
);
1220 return dev_priv
->cdclk
.hw
.ref
* ratio
;
1223 static int glk_de_pll_vco(struct drm_i915_private
*dev_priv
, int cdclk
)
1227 if (cdclk
== dev_priv
->cdclk
.hw
.ref
)
1232 MISSING_CASE(cdclk
);
1241 return dev_priv
->cdclk
.hw
.ref
* ratio
;
1244 static void bxt_de_pll_update(struct drm_i915_private
*dev_priv
,
1245 struct intel_cdclk_state
*cdclk_state
)
1249 cdclk_state
->ref
= 19200;
1250 cdclk_state
->vco
= 0;
1252 val
= I915_READ(BXT_DE_PLL_ENABLE
);
1253 if ((val
& BXT_DE_PLL_PLL_ENABLE
) == 0)
1256 if (WARN_ON((val
& BXT_DE_PLL_LOCK
) == 0))
1259 val
= I915_READ(BXT_DE_PLL_CTL
);
1260 cdclk_state
->vco
= (val
& BXT_DE_PLL_RATIO_MASK
) * cdclk_state
->ref
;
1263 static void bxt_get_cdclk(struct drm_i915_private
*dev_priv
,
1264 struct intel_cdclk_state
*cdclk_state
)
1269 bxt_de_pll_update(dev_priv
, cdclk_state
);
1271 cdclk_state
->cdclk
= cdclk_state
->ref
;
1273 if (cdclk_state
->vco
== 0)
1276 divider
= I915_READ(CDCLK_CTL
) & BXT_CDCLK_CD2X_DIV_SEL_MASK
;
1279 case BXT_CDCLK_CD2X_DIV_SEL_1
:
1282 case BXT_CDCLK_CD2X_DIV_SEL_1_5
:
1283 WARN(IS_GEMINILAKE(dev_priv
), "Unsupported divider\n");
1286 case BXT_CDCLK_CD2X_DIV_SEL_2
:
1289 case BXT_CDCLK_CD2X_DIV_SEL_4
:
1293 MISSING_CASE(divider
);
1297 cdclk_state
->cdclk
= DIV_ROUND_CLOSEST(cdclk_state
->vco
, div
);
1301 * Can't read this out :( Let's assume it's
1302 * at least what the CDCLK frequency requires.
1304 cdclk_state
->voltage_level
=
1305 bxt_calc_voltage_level(cdclk_state
->cdclk
);
1308 static void bxt_de_pll_disable(struct drm_i915_private
*dev_priv
)
1310 I915_WRITE(BXT_DE_PLL_ENABLE
, 0);
1313 if (intel_wait_for_register(dev_priv
,
1314 BXT_DE_PLL_ENABLE
, BXT_DE_PLL_LOCK
, 0,
1316 DRM_ERROR("timeout waiting for DE PLL unlock\n");
1318 dev_priv
->cdclk
.hw
.vco
= 0;
1321 static void bxt_de_pll_enable(struct drm_i915_private
*dev_priv
, int vco
)
1323 int ratio
= DIV_ROUND_CLOSEST(vco
, dev_priv
->cdclk
.hw
.ref
);
1326 val
= I915_READ(BXT_DE_PLL_CTL
);
1327 val
&= ~BXT_DE_PLL_RATIO_MASK
;
1328 val
|= BXT_DE_PLL_RATIO(ratio
);
1329 I915_WRITE(BXT_DE_PLL_CTL
, val
);
1331 I915_WRITE(BXT_DE_PLL_ENABLE
, BXT_DE_PLL_PLL_ENABLE
);
1334 if (intel_wait_for_register(dev_priv
,
1339 DRM_ERROR("timeout waiting for DE PLL lock\n");
1341 dev_priv
->cdclk
.hw
.vco
= vco
;
1344 static void bxt_set_cdclk(struct drm_i915_private
*dev_priv
,
1345 const struct intel_cdclk_state
*cdclk_state
)
1347 int cdclk
= cdclk_state
->cdclk
;
1348 int vco
= cdclk_state
->vco
;
1352 /* cdclk = vco / 2 / div{1,1.5,2,4} */
1353 switch (DIV_ROUND_CLOSEST(vco
, cdclk
)) {
1355 WARN_ON(cdclk
!= dev_priv
->cdclk
.hw
.ref
);
1359 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
1362 WARN(IS_GEMINILAKE(dev_priv
), "Unsupported divider\n");
1363 divider
= BXT_CDCLK_CD2X_DIV_SEL_1_5
;
1366 divider
= BXT_CDCLK_CD2X_DIV_SEL_2
;
1369 divider
= BXT_CDCLK_CD2X_DIV_SEL_4
;
1374 * Inform power controller of upcoming frequency change. BSpec
1375 * requires us to wait up to 150usec, but that leads to timeouts;
1376 * the 2ms used here is based on experiment.
1378 mutex_lock(&dev_priv
->pcu_lock
);
1379 ret
= sandybridge_pcode_write_timeout(dev_priv
,
1380 HSW_PCODE_DE_WRITE_FREQ_REQ
,
1382 mutex_unlock(&dev_priv
->pcu_lock
);
1385 DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n",
1390 if (dev_priv
->cdclk
.hw
.vco
!= 0 &&
1391 dev_priv
->cdclk
.hw
.vco
!= vco
)
1392 bxt_de_pll_disable(dev_priv
);
1394 if (dev_priv
->cdclk
.hw
.vco
!= vco
)
1395 bxt_de_pll_enable(dev_priv
, vco
);
1397 val
= divider
| skl_cdclk_decimal(cdclk
);
1399 * FIXME if only the cd2x divider needs changing, it could be done
1400 * without shutting off the pipe (if only one pipe is active).
1402 val
|= BXT_CDCLK_CD2X_PIPE_NONE
;
1404 * Disable SSA Precharge when CD clock frequency < 500 MHz,
1407 if (cdclk
>= 500000)
1408 val
|= BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
1409 I915_WRITE(CDCLK_CTL
, val
);
1411 mutex_lock(&dev_priv
->pcu_lock
);
1413 * The timeout isn't specified, the 2ms used here is based on
1415 * FIXME: Waiting for the request completion could be delayed until
1416 * the next PCODE request based on BSpec.
1418 ret
= sandybridge_pcode_write_timeout(dev_priv
,
1419 HSW_PCODE_DE_WRITE_FREQ_REQ
,
1420 cdclk_state
->voltage_level
, 2000);
1421 mutex_unlock(&dev_priv
->pcu_lock
);
1424 DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n",
1429 intel_update_cdclk(dev_priv
);
1432 static void bxt_sanitize_cdclk(struct drm_i915_private
*dev_priv
)
1434 u32 cdctl
, expected
;
1436 intel_update_cdclk(dev_priv
);
1437 intel_dump_cdclk_state(&dev_priv
->cdclk
.hw
, "Current CDCLK");
1439 if (dev_priv
->cdclk
.hw
.vco
== 0 ||
1440 dev_priv
->cdclk
.hw
.cdclk
== dev_priv
->cdclk
.hw
.ref
)
1443 /* DPLL okay; verify the cdclock
1445 * Some BIOS versions leave an incorrect decimal frequency value and
1446 * set reserved MBZ bits in CDCLK_CTL at least during exiting from S4,
1447 * so sanitize this register.
1449 cdctl
= I915_READ(CDCLK_CTL
);
1451 * Let's ignore the pipe field, since BIOS could have configured the
1452 * dividers both synching to an active pipe, or asynchronously
1455 cdctl
&= ~BXT_CDCLK_CD2X_PIPE_NONE
;
1457 expected
= (cdctl
& BXT_CDCLK_CD2X_DIV_SEL_MASK
) |
1458 skl_cdclk_decimal(dev_priv
->cdclk
.hw
.cdclk
);
1460 * Disable SSA Precharge when CD clock frequency < 500 MHz,
1463 if (dev_priv
->cdclk
.hw
.cdclk
>= 500000)
1464 expected
|= BXT_CDCLK_SSA_PRECHARGE_ENABLE
;
1466 if (cdctl
== expected
)
1467 /* All well; nothing to sanitize */
1471 DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n");
1473 /* force cdclk programming */
1474 dev_priv
->cdclk
.hw
.cdclk
= 0;
1476 /* force full PLL disable + enable */
1477 dev_priv
->cdclk
.hw
.vco
= -1;
1481 * bxt_init_cdclk - Initialize CDCLK on BXT
1482 * @dev_priv: i915 device
1484 * Initialize CDCLK for BXT and derivatives. This is generally
1485 * done only during the display core initialization sequence,
1486 * after which the DMC will take care of turning CDCLK off/on
1489 void bxt_init_cdclk(struct drm_i915_private
*dev_priv
)
1491 struct intel_cdclk_state cdclk_state
;
1493 bxt_sanitize_cdclk(dev_priv
);
1495 if (dev_priv
->cdclk
.hw
.cdclk
!= 0 &&
1496 dev_priv
->cdclk
.hw
.vco
!= 0)
1499 cdclk_state
= dev_priv
->cdclk
.hw
;
1503 * - The initial CDCLK needs to be read from VBT.
1504 * Need to make this change after VBT has changes for BXT.
1506 if (IS_GEMINILAKE(dev_priv
)) {
1507 cdclk_state
.cdclk
= glk_calc_cdclk(0);
1508 cdclk_state
.vco
= glk_de_pll_vco(dev_priv
, cdclk_state
.cdclk
);
1510 cdclk_state
.cdclk
= bxt_calc_cdclk(0);
1511 cdclk_state
.vco
= bxt_de_pll_vco(dev_priv
, cdclk_state
.cdclk
);
1513 cdclk_state
.voltage_level
= bxt_calc_voltage_level(cdclk_state
.cdclk
);
1515 bxt_set_cdclk(dev_priv
, &cdclk_state
);
1519 * bxt_uninit_cdclk - Uninitialize CDCLK on BXT
1520 * @dev_priv: i915 device
1522 * Uninitialize CDCLK for BXT and derivatives. This is done only
1523 * during the display core uninitialization sequence.
1525 void bxt_uninit_cdclk(struct drm_i915_private
*dev_priv
)
1527 struct intel_cdclk_state cdclk_state
= dev_priv
->cdclk
.hw
;
1529 cdclk_state
.cdclk
= cdclk_state
.ref
;
1530 cdclk_state
.vco
= 0;
1531 cdclk_state
.voltage_level
= bxt_calc_voltage_level(cdclk_state
.cdclk
);
1533 bxt_set_cdclk(dev_priv
, &cdclk_state
);
1536 static int cnl_calc_cdclk(int min_cdclk
)
1538 if (min_cdclk
> 336000)
1540 else if (min_cdclk
> 168000)
1546 static u8
cnl_calc_voltage_level(int cdclk
)
1559 static void cnl_cdclk_pll_update(struct drm_i915_private
*dev_priv
,
1560 struct intel_cdclk_state
*cdclk_state
)
1564 if (I915_READ(SKL_DSSM
) & CNL_DSSM_CDCLK_PLL_REFCLK_24MHz
)
1565 cdclk_state
->ref
= 24000;
1567 cdclk_state
->ref
= 19200;
1569 cdclk_state
->vco
= 0;
1571 val
= I915_READ(BXT_DE_PLL_ENABLE
);
1572 if ((val
& BXT_DE_PLL_PLL_ENABLE
) == 0)
1575 if (WARN_ON((val
& BXT_DE_PLL_LOCK
) == 0))
1578 cdclk_state
->vco
= (val
& CNL_CDCLK_PLL_RATIO_MASK
) * cdclk_state
->ref
;
1581 static void cnl_get_cdclk(struct drm_i915_private
*dev_priv
,
1582 struct intel_cdclk_state
*cdclk_state
)
1587 cnl_cdclk_pll_update(dev_priv
, cdclk_state
);
1589 cdclk_state
->cdclk
= cdclk_state
->ref
;
1591 if (cdclk_state
->vco
== 0)
1594 divider
= I915_READ(CDCLK_CTL
) & BXT_CDCLK_CD2X_DIV_SEL_MASK
;
1597 case BXT_CDCLK_CD2X_DIV_SEL_1
:
1600 case BXT_CDCLK_CD2X_DIV_SEL_2
:
1604 MISSING_CASE(divider
);
1608 cdclk_state
->cdclk
= DIV_ROUND_CLOSEST(cdclk_state
->vco
, div
);
1612 * Can't read this out :( Let's assume it's
1613 * at least what the CDCLK frequency requires.
1615 cdclk_state
->voltage_level
=
1616 cnl_calc_voltage_level(cdclk_state
->cdclk
);
1619 static void cnl_cdclk_pll_disable(struct drm_i915_private
*dev_priv
)
1623 val
= I915_READ(BXT_DE_PLL_ENABLE
);
1624 val
&= ~BXT_DE_PLL_PLL_ENABLE
;
1625 I915_WRITE(BXT_DE_PLL_ENABLE
, val
);
1628 if (wait_for((I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
) == 0, 1))
1629 DRM_ERROR("timout waiting for CDCLK PLL unlock\n");
1631 dev_priv
->cdclk
.hw
.vco
= 0;
1634 static void cnl_cdclk_pll_enable(struct drm_i915_private
*dev_priv
, int vco
)
1636 int ratio
= DIV_ROUND_CLOSEST(vco
, dev_priv
->cdclk
.hw
.ref
);
1639 val
= CNL_CDCLK_PLL_RATIO(ratio
);
1640 I915_WRITE(BXT_DE_PLL_ENABLE
, val
);
1642 val
|= BXT_DE_PLL_PLL_ENABLE
;
1643 I915_WRITE(BXT_DE_PLL_ENABLE
, val
);
1646 if (wait_for((I915_READ(BXT_DE_PLL_ENABLE
) & BXT_DE_PLL_LOCK
) != 0, 1))
1647 DRM_ERROR("timout waiting for CDCLK PLL lock\n");
1649 dev_priv
->cdclk
.hw
.vco
= vco
;
1652 static void cnl_set_cdclk(struct drm_i915_private
*dev_priv
,
1653 const struct intel_cdclk_state
*cdclk_state
)
1655 int cdclk
= cdclk_state
->cdclk
;
1656 int vco
= cdclk_state
->vco
;
1660 mutex_lock(&dev_priv
->pcu_lock
);
1661 ret
= skl_pcode_request(dev_priv
, SKL_PCODE_CDCLK_CONTROL
,
1662 SKL_CDCLK_PREPARE_FOR_CHANGE
,
1663 SKL_CDCLK_READY_FOR_CHANGE
,
1664 SKL_CDCLK_READY_FOR_CHANGE
, 3);
1665 mutex_unlock(&dev_priv
->pcu_lock
);
1667 DRM_ERROR("Failed to inform PCU about cdclk change (%d)\n",
1672 /* cdclk = vco / 2 / div{1,2} */
1673 switch (DIV_ROUND_CLOSEST(vco
, cdclk
)) {
1675 WARN_ON(cdclk
!= dev_priv
->cdclk
.hw
.ref
);
1679 divider
= BXT_CDCLK_CD2X_DIV_SEL_1
;
1682 divider
= BXT_CDCLK_CD2X_DIV_SEL_2
;
1686 if (dev_priv
->cdclk
.hw
.vco
!= 0 &&
1687 dev_priv
->cdclk
.hw
.vco
!= vco
)
1688 cnl_cdclk_pll_disable(dev_priv
);
1690 if (dev_priv
->cdclk
.hw
.vco
!= vco
)
1691 cnl_cdclk_pll_enable(dev_priv
, vco
);
1693 val
= divider
| skl_cdclk_decimal(cdclk
);
1695 * FIXME if only the cd2x divider needs changing, it could be done
1696 * without shutting off the pipe (if only one pipe is active).
1698 val
|= BXT_CDCLK_CD2X_PIPE_NONE
;
1699 I915_WRITE(CDCLK_CTL
, val
);
1701 /* inform PCU of the change */
1702 mutex_lock(&dev_priv
->pcu_lock
);
1703 sandybridge_pcode_write(dev_priv
, SKL_PCODE_CDCLK_CONTROL
,
1704 cdclk_state
->voltage_level
);
1705 mutex_unlock(&dev_priv
->pcu_lock
);
1707 intel_update_cdclk(dev_priv
);
1710 * Can't read out the voltage level :(
1711 * Let's just assume everything is as expected.
1713 dev_priv
->cdclk
.hw
.voltage_level
= cdclk_state
->voltage_level
;
1716 static int cnl_cdclk_pll_vco(struct drm_i915_private
*dev_priv
, int cdclk
)
1720 if (cdclk
== dev_priv
->cdclk
.hw
.ref
)
1725 MISSING_CASE(cdclk
);
1729 ratio
= dev_priv
->cdclk
.hw
.ref
== 19200 ? 35 : 28;
1732 ratio
= dev_priv
->cdclk
.hw
.ref
== 19200 ? 55 : 44;
1736 return dev_priv
->cdclk
.hw
.ref
* ratio
;
1739 static void cnl_sanitize_cdclk(struct drm_i915_private
*dev_priv
)
1741 u32 cdctl
, expected
;
1743 intel_update_cdclk(dev_priv
);
1744 intel_dump_cdclk_state(&dev_priv
->cdclk
.hw
, "Current CDCLK");
1746 if (dev_priv
->cdclk
.hw
.vco
== 0 ||
1747 dev_priv
->cdclk
.hw
.cdclk
== dev_priv
->cdclk
.hw
.ref
)
1750 /* DPLL okay; verify the cdclock
1752 * Some BIOS versions leave an incorrect decimal frequency value and
1753 * set reserved MBZ bits in CDCLK_CTL at least during exiting from S4,
1754 * so sanitize this register.
1756 cdctl
= I915_READ(CDCLK_CTL
);
1758 * Let's ignore the pipe field, since BIOS could have configured the
1759 * dividers both synching to an active pipe, or asynchronously
1762 cdctl
&= ~BXT_CDCLK_CD2X_PIPE_NONE
;
1764 expected
= (cdctl
& BXT_CDCLK_CD2X_DIV_SEL_MASK
) |
1765 skl_cdclk_decimal(dev_priv
->cdclk
.hw
.cdclk
);
1767 if (cdctl
== expected
)
1768 /* All well; nothing to sanitize */
1772 DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n");
1774 /* force cdclk programming */
1775 dev_priv
->cdclk
.hw
.cdclk
= 0;
1777 /* force full PLL disable + enable */
1778 dev_priv
->cdclk
.hw
.vco
= -1;
1782 * cnl_init_cdclk - Initialize CDCLK on CNL
1783 * @dev_priv: i915 device
1785 * Initialize CDCLK for CNL. This is generally
1786 * done only during the display core initialization sequence,
1787 * after which the DMC will take care of turning CDCLK off/on
1790 void cnl_init_cdclk(struct drm_i915_private
*dev_priv
)
1792 struct intel_cdclk_state cdclk_state
;
1794 cnl_sanitize_cdclk(dev_priv
);
1796 if (dev_priv
->cdclk
.hw
.cdclk
!= 0 &&
1797 dev_priv
->cdclk
.hw
.vco
!= 0)
1800 cdclk_state
= dev_priv
->cdclk
.hw
;
1802 cdclk_state
.cdclk
= cnl_calc_cdclk(0);
1803 cdclk_state
.vco
= cnl_cdclk_pll_vco(dev_priv
, cdclk_state
.cdclk
);
1804 cdclk_state
.voltage_level
= cnl_calc_voltage_level(cdclk_state
.cdclk
);
1806 cnl_set_cdclk(dev_priv
, &cdclk_state
);
1810 * cnl_uninit_cdclk - Uninitialize CDCLK on CNL
1811 * @dev_priv: i915 device
1813 * Uninitialize CDCLK for CNL. This is done only
1814 * during the display core uninitialization sequence.
1816 void cnl_uninit_cdclk(struct drm_i915_private
*dev_priv
)
1818 struct intel_cdclk_state cdclk_state
= dev_priv
->cdclk
.hw
;
1820 cdclk_state
.cdclk
= cdclk_state
.ref
;
1821 cdclk_state
.vco
= 0;
1822 cdclk_state
.voltage_level
= cnl_calc_voltage_level(cdclk_state
.cdclk
);
1824 cnl_set_cdclk(dev_priv
, &cdclk_state
);
1828 * intel_cdclk_needs_modeset - Determine if two CDCLK states require a modeset on all pipes
1829 * @a: first CDCLK state
1830 * @b: second CDCLK state
1833 * True if the CDCLK states require pipes to be off during reprogramming, false if not.
1835 bool intel_cdclk_needs_modeset(const struct intel_cdclk_state
*a
,
1836 const struct intel_cdclk_state
*b
)
1838 return a
->cdclk
!= b
->cdclk
||
1844 * intel_cdclk_changed - Determine if two CDCLK states are different
1845 * @a: first CDCLK state
1846 * @b: second CDCLK state
1849 * True if the CDCLK states don't match, false if they do.
1851 bool intel_cdclk_changed(const struct intel_cdclk_state
*a
,
1852 const struct intel_cdclk_state
*b
)
1854 return intel_cdclk_needs_modeset(a
, b
) ||
1855 a
->voltage_level
!= b
->voltage_level
;
1858 void intel_dump_cdclk_state(const struct intel_cdclk_state
*cdclk_state
,
1859 const char *context
)
1861 DRM_DEBUG_DRIVER("%s %d kHz, VCO %d kHz, ref %d kHz, voltage level %d\n",
1862 context
, cdclk_state
->cdclk
, cdclk_state
->vco
,
1863 cdclk_state
->ref
, cdclk_state
->voltage_level
);
1867 * intel_set_cdclk - Push the CDCLK state to the hardware
1868 * @dev_priv: i915 device
1869 * @cdclk_state: new CDCLK state
1871 * Program the hardware based on the passed in CDCLK state,
1874 void intel_set_cdclk(struct drm_i915_private
*dev_priv
,
1875 const struct intel_cdclk_state
*cdclk_state
)
1877 if (!intel_cdclk_changed(&dev_priv
->cdclk
.hw
, cdclk_state
))
1880 if (WARN_ON_ONCE(!dev_priv
->display
.set_cdclk
))
1883 intel_dump_cdclk_state(cdclk_state
, "Changing CDCLK to");
1885 dev_priv
->display
.set_cdclk(dev_priv
, cdclk_state
);
1887 if (WARN(intel_cdclk_changed(&dev_priv
->cdclk
.hw
, cdclk_state
),
1888 "cdclk state doesn't match!\n")) {
1889 intel_dump_cdclk_state(&dev_priv
->cdclk
.hw
, "[hw state]");
1890 intel_dump_cdclk_state(cdclk_state
, "[sw state]");
1894 static int intel_pixel_rate_to_cdclk(struct drm_i915_private
*dev_priv
,
1897 if (INTEL_GEN(dev_priv
) >= 10)
1898 return DIV_ROUND_UP(pixel_rate
, 2);
1899 else if (IS_GEMINILAKE(dev_priv
))
1901 * FIXME: Avoid using a pixel clock that is more than 99% of the cdclk
1902 * as a temporary workaround. Use a higher cdclk instead. (Note that
1903 * intel_compute_max_dotclk() limits the max pixel clock to 99% of max
1906 return DIV_ROUND_UP(pixel_rate
* 100, 2 * 99);
1907 else if (IS_GEN9(dev_priv
) ||
1908 IS_BROADWELL(dev_priv
) || IS_HASWELL(dev_priv
))
1910 else if (IS_CHERRYVIEW(dev_priv
))
1911 return DIV_ROUND_UP(pixel_rate
* 100, 95);
1913 return DIV_ROUND_UP(pixel_rate
* 100, 90);
1916 int intel_crtc_compute_min_cdclk(const struct intel_crtc_state
*crtc_state
)
1918 struct drm_i915_private
*dev_priv
=
1919 to_i915(crtc_state
->base
.crtc
->dev
);
1922 if (!crtc_state
->base
.enable
)
1925 min_cdclk
= intel_pixel_rate_to_cdclk(dev_priv
, crtc_state
->pixel_rate
);
1927 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
1928 if (IS_BROADWELL(dev_priv
) && hsw_crtc_state_ips_capable(crtc_state
))
1929 min_cdclk
= DIV_ROUND_UP(min_cdclk
* 100, 95);
1931 /* BSpec says "Do not use DisplayPort with CDCLK less than 432 MHz,
1932 * audio enabled, port width x4, and link rate HBR2 (5.4 GHz), or else
1933 * there may be audio corruption or screen corruption." This cdclk
1934 * restriction for GLK is 316.8 MHz.
1936 if (intel_crtc_has_dp_encoder(crtc_state
) &&
1937 crtc_state
->has_audio
&&
1938 crtc_state
->port_clock
>= 540000 &&
1939 crtc_state
->lane_count
== 4) {
1940 if (IS_CANNONLAKE(dev_priv
) || IS_GEMINILAKE(dev_priv
)) {
1941 /* Display WA #1145: glk,cnl */
1942 min_cdclk
= max(316800, min_cdclk
);
1943 } else if (IS_GEN9(dev_priv
) || IS_BROADWELL(dev_priv
)) {
1944 /* Display WA #1144: skl,bxt */
1945 min_cdclk
= max(432000, min_cdclk
);
1950 * According to BSpec, "The CD clock frequency must be at least twice
1951 * the frequency of the Azalia BCLK." and BCLK is 96 MHz by default.
1953 * FIXME: Check the actual, not default, BCLK being used.
1955 * FIXME: This does not depend on ->has_audio because the higher CDCLK
1956 * is required for audio probe, also when there are no audio capable
1957 * displays connected at probe time. This leads to unnecessarily high
1958 * CDCLK when audio is not required.
1960 * FIXME: This limit is only applied when there are displays connected
1961 * at probe time. If we probe without displays, we'll still end up using
1962 * the platform minimum CDCLK, failing audio probe.
1964 if (INTEL_GEN(dev_priv
) >= 9)
1965 min_cdclk
= max(2 * 96000, min_cdclk
);
1968 * On Valleyview some DSI panels lose (v|h)sync when the clock is lower
1971 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DSI
) &&
1972 IS_VALLEYVIEW(dev_priv
))
1973 min_cdclk
= max(320000, min_cdclk
);
1975 if (min_cdclk
> dev_priv
->max_cdclk_freq
) {
1976 DRM_DEBUG_KMS("required cdclk (%d kHz) exceeds max (%d kHz)\n",
1977 min_cdclk
, dev_priv
->max_cdclk_freq
);
1984 static int intel_compute_min_cdclk(struct drm_atomic_state
*state
)
1986 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
1987 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
1988 struct intel_crtc
*crtc
;
1989 struct intel_crtc_state
*crtc_state
;
1993 memcpy(intel_state
->min_cdclk
, dev_priv
->min_cdclk
,
1994 sizeof(intel_state
->min_cdclk
));
1996 for_each_new_intel_crtc_in_state(intel_state
, crtc
, crtc_state
, i
) {
1997 min_cdclk
= intel_crtc_compute_min_cdclk(crtc_state
);
2001 intel_state
->min_cdclk
[i
] = min_cdclk
;
2005 for_each_pipe(dev_priv
, pipe
)
2006 min_cdclk
= max(intel_state
->min_cdclk
[pipe
], min_cdclk
);
2012 * Note that this functions assumes that 0 is
2013 * the lowest voltage value, and higher values
2014 * correspond to increasingly higher voltages.
2016 * Should that relationship no longer hold on
2017 * future platforms this code will need to be
2020 static u8
cnl_compute_min_voltage_level(struct intel_atomic_state
*state
)
2022 struct drm_i915_private
*dev_priv
= to_i915(state
->base
.dev
);
2023 struct intel_crtc
*crtc
;
2024 struct intel_crtc_state
*crtc_state
;
2025 u8 min_voltage_level
;
2029 memcpy(state
->min_voltage_level
, dev_priv
->min_voltage_level
,
2030 sizeof(state
->min_voltage_level
));
2032 for_each_new_intel_crtc_in_state(state
, crtc
, crtc_state
, i
) {
2033 if (crtc_state
->base
.enable
)
2034 state
->min_voltage_level
[i
] =
2035 crtc_state
->min_voltage_level
;
2037 state
->min_voltage_level
[i
] = 0;
2040 min_voltage_level
= 0;
2041 for_each_pipe(dev_priv
, pipe
)
2042 min_voltage_level
= max(state
->min_voltage_level
[pipe
],
2045 return min_voltage_level
;
2048 static int vlv_modeset_calc_cdclk(struct drm_atomic_state
*state
)
2050 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
2051 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
2052 int min_cdclk
, cdclk
;
2054 min_cdclk
= intel_compute_min_cdclk(state
);
2058 cdclk
= vlv_calc_cdclk(dev_priv
, min_cdclk
);
2060 intel_state
->cdclk
.logical
.cdclk
= cdclk
;
2061 intel_state
->cdclk
.logical
.voltage_level
=
2062 vlv_calc_voltage_level(dev_priv
, cdclk
);
2064 if (!intel_state
->active_crtcs
) {
2065 cdclk
= vlv_calc_cdclk(dev_priv
, 0);
2067 intel_state
->cdclk
.actual
.cdclk
= cdclk
;
2068 intel_state
->cdclk
.actual
.voltage_level
=
2069 vlv_calc_voltage_level(dev_priv
, cdclk
);
2071 intel_state
->cdclk
.actual
=
2072 intel_state
->cdclk
.logical
;
2078 static int bdw_modeset_calc_cdclk(struct drm_atomic_state
*state
)
2080 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
2081 int min_cdclk
, cdclk
;
2083 min_cdclk
= intel_compute_min_cdclk(state
);
2088 * FIXME should also account for plane ratio
2089 * once 64bpp pixel formats are supported.
2091 cdclk
= bdw_calc_cdclk(min_cdclk
);
2093 intel_state
->cdclk
.logical
.cdclk
= cdclk
;
2094 intel_state
->cdclk
.logical
.voltage_level
=
2095 bdw_calc_voltage_level(cdclk
);
2097 if (!intel_state
->active_crtcs
) {
2098 cdclk
= bdw_calc_cdclk(0);
2100 intel_state
->cdclk
.actual
.cdclk
= cdclk
;
2101 intel_state
->cdclk
.actual
.voltage_level
=
2102 bdw_calc_voltage_level(cdclk
);
2104 intel_state
->cdclk
.actual
=
2105 intel_state
->cdclk
.logical
;
2111 static int skl_dpll0_vco(struct intel_atomic_state
*intel_state
)
2113 struct drm_i915_private
*dev_priv
= to_i915(intel_state
->base
.dev
);
2114 struct intel_crtc
*crtc
;
2115 struct intel_crtc_state
*crtc_state
;
2118 vco
= intel_state
->cdclk
.logical
.vco
;
2120 vco
= dev_priv
->skl_preferred_vco_freq
;
2122 for_each_new_intel_crtc_in_state(intel_state
, crtc
, crtc_state
, i
) {
2123 if (!crtc_state
->base
.enable
)
2126 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_EDP
))
2130 * DPLL0 VCO may need to be adjusted to get the correct
2131 * clock for eDP. This will affect cdclk as well.
2133 switch (crtc_state
->port_clock
/ 2) {
2147 static int skl_modeset_calc_cdclk(struct drm_atomic_state
*state
)
2149 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
2150 int min_cdclk
, cdclk
, vco
;
2152 min_cdclk
= intel_compute_min_cdclk(state
);
2156 vco
= skl_dpll0_vco(intel_state
);
2159 * FIXME should also account for plane ratio
2160 * once 64bpp pixel formats are supported.
2162 cdclk
= skl_calc_cdclk(min_cdclk
, vco
);
2164 intel_state
->cdclk
.logical
.vco
= vco
;
2165 intel_state
->cdclk
.logical
.cdclk
= cdclk
;
2166 intel_state
->cdclk
.logical
.voltage_level
=
2167 skl_calc_voltage_level(cdclk
);
2169 if (!intel_state
->active_crtcs
) {
2170 cdclk
= skl_calc_cdclk(0, vco
);
2172 intel_state
->cdclk
.actual
.vco
= vco
;
2173 intel_state
->cdclk
.actual
.cdclk
= cdclk
;
2174 intel_state
->cdclk
.actual
.voltage_level
=
2175 skl_calc_voltage_level(cdclk
);
2177 intel_state
->cdclk
.actual
=
2178 intel_state
->cdclk
.logical
;
2184 static int bxt_modeset_calc_cdclk(struct drm_atomic_state
*state
)
2186 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
2187 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
2188 int min_cdclk
, cdclk
, vco
;
2190 min_cdclk
= intel_compute_min_cdclk(state
);
2194 if (IS_GEMINILAKE(dev_priv
)) {
2195 cdclk
= glk_calc_cdclk(min_cdclk
);
2196 vco
= glk_de_pll_vco(dev_priv
, cdclk
);
2198 cdclk
= bxt_calc_cdclk(min_cdclk
);
2199 vco
= bxt_de_pll_vco(dev_priv
, cdclk
);
2202 intel_state
->cdclk
.logical
.vco
= vco
;
2203 intel_state
->cdclk
.logical
.cdclk
= cdclk
;
2204 intel_state
->cdclk
.logical
.voltage_level
=
2205 bxt_calc_voltage_level(cdclk
);
2207 if (!intel_state
->active_crtcs
) {
2208 if (IS_GEMINILAKE(dev_priv
)) {
2209 cdclk
= glk_calc_cdclk(0);
2210 vco
= glk_de_pll_vco(dev_priv
, cdclk
);
2212 cdclk
= bxt_calc_cdclk(0);
2213 vco
= bxt_de_pll_vco(dev_priv
, cdclk
);
2216 intel_state
->cdclk
.actual
.vco
= vco
;
2217 intel_state
->cdclk
.actual
.cdclk
= cdclk
;
2218 intel_state
->cdclk
.actual
.voltage_level
=
2219 bxt_calc_voltage_level(cdclk
);
2221 intel_state
->cdclk
.actual
=
2222 intel_state
->cdclk
.logical
;
2228 static int cnl_modeset_calc_cdclk(struct drm_atomic_state
*state
)
2230 struct drm_i915_private
*dev_priv
= to_i915(state
->dev
);
2231 struct intel_atomic_state
*intel_state
= to_intel_atomic_state(state
);
2232 int min_cdclk
, cdclk
, vco
;
2234 min_cdclk
= intel_compute_min_cdclk(state
);
2238 cdclk
= cnl_calc_cdclk(min_cdclk
);
2239 vco
= cnl_cdclk_pll_vco(dev_priv
, cdclk
);
2241 intel_state
->cdclk
.logical
.vco
= vco
;
2242 intel_state
->cdclk
.logical
.cdclk
= cdclk
;
2243 intel_state
->cdclk
.logical
.voltage_level
=
2244 max(cnl_calc_voltage_level(cdclk
),
2245 cnl_compute_min_voltage_level(intel_state
));
2247 if (!intel_state
->active_crtcs
) {
2248 cdclk
= cnl_calc_cdclk(0);
2249 vco
= cnl_cdclk_pll_vco(dev_priv
, cdclk
);
2251 intel_state
->cdclk
.actual
.vco
= vco
;
2252 intel_state
->cdclk
.actual
.cdclk
= cdclk
;
2253 intel_state
->cdclk
.actual
.voltage_level
=
2254 cnl_calc_voltage_level(cdclk
);
2256 intel_state
->cdclk
.actual
=
2257 intel_state
->cdclk
.logical
;
2263 static int intel_compute_max_dotclk(struct drm_i915_private
*dev_priv
)
2265 int max_cdclk_freq
= dev_priv
->max_cdclk_freq
;
2267 if (INTEL_GEN(dev_priv
) >= 10)
2268 return 2 * max_cdclk_freq
;
2269 else if (IS_GEMINILAKE(dev_priv
))
2271 * FIXME: Limiting to 99% as a temporary workaround. See
2272 * intel_min_cdclk() for details.
2274 return 2 * max_cdclk_freq
* 99 / 100;
2275 else if (IS_GEN9(dev_priv
) ||
2276 IS_BROADWELL(dev_priv
) || IS_HASWELL(dev_priv
))
2277 return max_cdclk_freq
;
2278 else if (IS_CHERRYVIEW(dev_priv
))
2279 return max_cdclk_freq
*95/100;
2280 else if (INTEL_INFO(dev_priv
)->gen
< 4)
2281 return 2*max_cdclk_freq
*90/100;
2283 return max_cdclk_freq
*90/100;
2287 * intel_update_max_cdclk - Determine the maximum support CDCLK frequency
2288 * @dev_priv: i915 device
2290 * Determine the maximum CDCLK frequency the platform supports, and also
2291 * derive the maximum dot clock frequency the maximum CDCLK frequency
2294 void intel_update_max_cdclk(struct drm_i915_private
*dev_priv
)
2296 if (IS_CANNONLAKE(dev_priv
)) {
2297 dev_priv
->max_cdclk_freq
= 528000;
2298 } else if (IS_GEN9_BC(dev_priv
)) {
2299 u32 limit
= I915_READ(SKL_DFSM
) & SKL_DFSM_CDCLK_LIMIT_MASK
;
2302 vco
= dev_priv
->skl_preferred_vco_freq
;
2303 WARN_ON(vco
!= 8100000 && vco
!= 8640000);
2306 * Use the lower (vco 8640) cdclk values as a
2307 * first guess. skl_calc_cdclk() will correct it
2308 * if the preferred vco is 8100 instead.
2310 if (limit
== SKL_DFSM_CDCLK_LIMIT_675
)
2312 else if (limit
== SKL_DFSM_CDCLK_LIMIT_540
)
2314 else if (limit
== SKL_DFSM_CDCLK_LIMIT_450
)
2319 dev_priv
->max_cdclk_freq
= skl_calc_cdclk(max_cdclk
, vco
);
2320 } else if (IS_GEMINILAKE(dev_priv
)) {
2321 dev_priv
->max_cdclk_freq
= 316800;
2322 } else if (IS_BROXTON(dev_priv
)) {
2323 dev_priv
->max_cdclk_freq
= 624000;
2324 } else if (IS_BROADWELL(dev_priv
)) {
2326 * FIXME with extra cooling we can allow
2327 * 540 MHz for ULX and 675 Mhz for ULT.
2328 * How can we know if extra cooling is
2329 * available? PCI ID, VTB, something else?
2331 if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
2332 dev_priv
->max_cdclk_freq
= 450000;
2333 else if (IS_BDW_ULX(dev_priv
))
2334 dev_priv
->max_cdclk_freq
= 450000;
2335 else if (IS_BDW_ULT(dev_priv
))
2336 dev_priv
->max_cdclk_freq
= 540000;
2338 dev_priv
->max_cdclk_freq
= 675000;
2339 } else if (IS_CHERRYVIEW(dev_priv
)) {
2340 dev_priv
->max_cdclk_freq
= 320000;
2341 } else if (IS_VALLEYVIEW(dev_priv
)) {
2342 dev_priv
->max_cdclk_freq
= 400000;
2344 /* otherwise assume cdclk is fixed */
2345 dev_priv
->max_cdclk_freq
= dev_priv
->cdclk
.hw
.cdclk
;
2348 dev_priv
->max_dotclk_freq
= intel_compute_max_dotclk(dev_priv
);
2350 DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n",
2351 dev_priv
->max_cdclk_freq
);
2353 DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n",
2354 dev_priv
->max_dotclk_freq
);
2358 * intel_update_cdclk - Determine the current CDCLK frequency
2359 * @dev_priv: i915 device
2361 * Determine the current CDCLK frequency.
2363 void intel_update_cdclk(struct drm_i915_private
*dev_priv
)
2365 dev_priv
->display
.get_cdclk(dev_priv
, &dev_priv
->cdclk
.hw
);
2368 * 9:0 CMBUS [sic] CDCLK frequency (cdfreq):
2369 * Programmng [sic] note: bit[9:2] should be programmed to the number
2370 * of cdclk that generates 4MHz reference clock freq which is used to
2371 * generate GMBus clock. This will vary with the cdclk freq.
2373 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
2374 I915_WRITE(GMBUSFREQ_VLV
,
2375 DIV_ROUND_UP(dev_priv
->cdclk
.hw
.cdclk
, 1000));
2378 static int cnp_rawclk(struct drm_i915_private
*dev_priv
)
2381 int divider
, fraction
;
2383 if (I915_READ(SFUSE_STRAP
) & SFUSE_STRAP_RAW_FREQUENCY
) {
2393 rawclk
= CNP_RAWCLK_DIV((divider
/ 1000) - 1);
2395 rawclk
|= CNP_RAWCLK_FRAC(DIV_ROUND_CLOSEST(1000,
2398 I915_WRITE(PCH_RAWCLK_FREQ
, rawclk
);
2399 return divider
+ fraction
;
2402 static int pch_rawclk(struct drm_i915_private
*dev_priv
)
2404 return (I915_READ(PCH_RAWCLK_FREQ
) & RAWCLK_FREQ_MASK
) * 1000;
2407 static int vlv_hrawclk(struct drm_i915_private
*dev_priv
)
2409 /* RAWCLK_FREQ_VLV register updated from power well code */
2410 return vlv_get_cck_clock_hpll(dev_priv
, "hrawclk",
2411 CCK_DISPLAY_REF_CLOCK_CONTROL
);
2414 static int g4x_hrawclk(struct drm_i915_private
*dev_priv
)
2418 /* hrawclock is 1/4 the FSB frequency */
2419 clkcfg
= I915_READ(CLKCFG
);
2420 switch (clkcfg
& CLKCFG_FSB_MASK
) {
2421 case CLKCFG_FSB_400
:
2423 case CLKCFG_FSB_533
:
2425 case CLKCFG_FSB_667
:
2427 case CLKCFG_FSB_800
:
2429 case CLKCFG_FSB_1067
:
2430 case CLKCFG_FSB_1067_ALT
:
2432 case CLKCFG_FSB_1333
:
2433 case CLKCFG_FSB_1333_ALT
:
2441 * intel_update_rawclk - Determine the current RAWCLK frequency
2442 * @dev_priv: i915 device
2444 * Determine the current RAWCLK frequency. RAWCLK is a fixed
2445 * frequency clock so this needs to done only once.
2447 void intel_update_rawclk(struct drm_i915_private
*dev_priv
)
2450 if (HAS_PCH_CNP(dev_priv
))
2451 dev_priv
->rawclk_freq
= cnp_rawclk(dev_priv
);
2452 else if (HAS_PCH_SPLIT(dev_priv
))
2453 dev_priv
->rawclk_freq
= pch_rawclk(dev_priv
);
2454 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
2455 dev_priv
->rawclk_freq
= vlv_hrawclk(dev_priv
);
2456 else if (IS_G4X(dev_priv
) || IS_PINEVIEW(dev_priv
))
2457 dev_priv
->rawclk_freq
= g4x_hrawclk(dev_priv
);
2459 /* no rawclk on other platforms, or no need to know it */
2462 DRM_DEBUG_DRIVER("rawclk rate: %d kHz\n", dev_priv
->rawclk_freq
);
2466 * intel_init_cdclk_hooks - Initialize CDCLK related modesetting hooks
2467 * @dev_priv: i915 device
2469 void intel_init_cdclk_hooks(struct drm_i915_private
*dev_priv
)
2471 if (IS_CHERRYVIEW(dev_priv
)) {
2472 dev_priv
->display
.set_cdclk
= chv_set_cdclk
;
2473 dev_priv
->display
.modeset_calc_cdclk
=
2474 vlv_modeset_calc_cdclk
;
2475 } else if (IS_VALLEYVIEW(dev_priv
)) {
2476 dev_priv
->display
.set_cdclk
= vlv_set_cdclk
;
2477 dev_priv
->display
.modeset_calc_cdclk
=
2478 vlv_modeset_calc_cdclk
;
2479 } else if (IS_BROADWELL(dev_priv
)) {
2480 dev_priv
->display
.set_cdclk
= bdw_set_cdclk
;
2481 dev_priv
->display
.modeset_calc_cdclk
=
2482 bdw_modeset_calc_cdclk
;
2483 } else if (IS_GEN9_LP(dev_priv
)) {
2484 dev_priv
->display
.set_cdclk
= bxt_set_cdclk
;
2485 dev_priv
->display
.modeset_calc_cdclk
=
2486 bxt_modeset_calc_cdclk
;
2487 } else if (IS_GEN9_BC(dev_priv
)) {
2488 dev_priv
->display
.set_cdclk
= skl_set_cdclk
;
2489 dev_priv
->display
.modeset_calc_cdclk
=
2490 skl_modeset_calc_cdclk
;
2491 } else if (IS_CANNONLAKE(dev_priv
)) {
2492 dev_priv
->display
.set_cdclk
= cnl_set_cdclk
;
2493 dev_priv
->display
.modeset_calc_cdclk
=
2494 cnl_modeset_calc_cdclk
;
2497 if (IS_CANNONLAKE(dev_priv
))
2498 dev_priv
->display
.get_cdclk
= cnl_get_cdclk
;
2499 else if (IS_GEN9_BC(dev_priv
))
2500 dev_priv
->display
.get_cdclk
= skl_get_cdclk
;
2501 else if (IS_GEN9_LP(dev_priv
))
2502 dev_priv
->display
.get_cdclk
= bxt_get_cdclk
;
2503 else if (IS_BROADWELL(dev_priv
))
2504 dev_priv
->display
.get_cdclk
= bdw_get_cdclk
;
2505 else if (IS_HASWELL(dev_priv
))
2506 dev_priv
->display
.get_cdclk
= hsw_get_cdclk
;
2507 else if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
2508 dev_priv
->display
.get_cdclk
= vlv_get_cdclk
;
2509 else if (IS_GEN6(dev_priv
) || IS_IVYBRIDGE(dev_priv
))
2510 dev_priv
->display
.get_cdclk
= fixed_400mhz_get_cdclk
;
2511 else if (IS_GEN5(dev_priv
))
2512 dev_priv
->display
.get_cdclk
= fixed_450mhz_get_cdclk
;
2513 else if (IS_GM45(dev_priv
))
2514 dev_priv
->display
.get_cdclk
= gm45_get_cdclk
;
2515 else if (IS_G45(dev_priv
))
2516 dev_priv
->display
.get_cdclk
= g33_get_cdclk
;
2517 else if (IS_I965GM(dev_priv
))
2518 dev_priv
->display
.get_cdclk
= i965gm_get_cdclk
;
2519 else if (IS_I965G(dev_priv
))
2520 dev_priv
->display
.get_cdclk
= fixed_400mhz_get_cdclk
;
2521 else if (IS_PINEVIEW(dev_priv
))
2522 dev_priv
->display
.get_cdclk
= pnv_get_cdclk
;
2523 else if (IS_G33(dev_priv
))
2524 dev_priv
->display
.get_cdclk
= g33_get_cdclk
;
2525 else if (IS_I945GM(dev_priv
))
2526 dev_priv
->display
.get_cdclk
= i945gm_get_cdclk
;
2527 else if (IS_I945G(dev_priv
))
2528 dev_priv
->display
.get_cdclk
= fixed_400mhz_get_cdclk
;
2529 else if (IS_I915GM(dev_priv
))
2530 dev_priv
->display
.get_cdclk
= i915gm_get_cdclk
;
2531 else if (IS_I915G(dev_priv
))
2532 dev_priv
->display
.get_cdclk
= fixed_333mhz_get_cdclk
;
2533 else if (IS_I865G(dev_priv
))
2534 dev_priv
->display
.get_cdclk
= fixed_266mhz_get_cdclk
;
2535 else if (IS_I85X(dev_priv
))
2536 dev_priv
->display
.get_cdclk
= i85x_get_cdclk
;
2537 else if (IS_I845G(dev_priv
))
2538 dev_priv
->display
.get_cdclk
= fixed_200mhz_get_cdclk
;
2540 WARN(!IS_I830(dev_priv
),
2541 "Unknown platform. Assuming 133 MHz CDCLK\n");
2542 dev_priv
->display
.get_cdclk
= fixed_133mhz_get_cdclk
;