2 * Copyright © 2012-2014 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 DEALINGS
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
29 #include <linux/pm_runtime.h>
30 #include <linux/vgaarb.h>
33 #include "intel_drv.h"
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
52 #define GEN9_ENABLE_DC5(dev) 0
53 #define SKL_ENABLE_DC6(dev) IS_SKYLAKE(dev)
55 #define for_each_power_well(i, power_well, domain_mask, power_domains) \
57 i < (power_domains)->power_well_count && \
58 ((power_well) = &(power_domains)->power_wells[i]); \
60 if ((power_well)->domains & (domain_mask))
62 #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
63 for (i = (power_domains)->power_well_count - 1; \
64 i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
66 if ((power_well)->domains & (domain_mask))
68 bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
71 static void intel_power_well_enable(struct drm_i915_private *dev_priv,
72 struct i915_power_well *power_well)
74 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
75 power_well->ops->enable(dev_priv, power_well);
76 power_well->hw_enabled = true;
79 static void intel_power_well_disable(struct drm_i915_private *dev_priv,
80 struct i915_power_well *power_well)
82 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
83 power_well->hw_enabled = false;
84 power_well->ops->disable(dev_priv, power_well);
88 * We should only use the power well if we explicitly asked the hardware to
89 * enable it, so check if it's enabled and also check if we've requested it to
92 static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
93 struct i915_power_well *power_well)
95 return I915_READ(HSW_PWR_WELL_DRIVER) ==
96 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
100 * __intel_display_power_is_enabled - unlocked check for a power domain
101 * @dev_priv: i915 device instance
102 * @domain: power domain to check
104 * This is the unlocked version of intel_display_power_is_enabled() and should
105 * only be used from error capture and recovery code where deadlocks are
109 * True when the power domain is enabled, false otherwise.
111 bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
112 enum intel_display_power_domain domain)
114 struct i915_power_domains *power_domains;
115 struct i915_power_well *power_well;
119 if (dev_priv->pm.suspended)
122 power_domains = &dev_priv->power_domains;
126 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
127 if (power_well->always_on)
130 if (!power_well->hw_enabled) {
140 * intel_display_power_is_enabled - check for a power domain
141 * @dev_priv: i915 device instance
142 * @domain: power domain to check
144 * This function can be used to check the hw power domain state. It is mostly
145 * used in hardware state readout functions. Everywhere else code should rely
146 * upon explicit power domain reference counting to ensure that the hardware
147 * block is powered up before accessing it.
149 * Callers must hold the relevant modesetting locks to ensure that concurrent
150 * threads can't disable the power well while the caller tries to read a few
154 * True when the power domain is enabled, false otherwise.
156 bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
157 enum intel_display_power_domain domain)
159 struct i915_power_domains *power_domains;
162 power_domains = &dev_priv->power_domains;
164 mutex_lock(&power_domains->lock);
165 ret = __intel_display_power_is_enabled(dev_priv, domain);
166 mutex_unlock(&power_domains->lock);
172 * intel_display_set_init_power - set the initial power domain state
173 * @dev_priv: i915 device instance
174 * @enable: whether to enable or disable the initial power domain state
176 * For simplicity our driver load/unload and system suspend/resume code assumes
177 * that all power domains are always enabled. This functions controls the state
178 * of this little hack. While the initial power domain state is enabled runtime
179 * pm is effectively disabled.
181 void intel_display_set_init_power(struct drm_i915_private *dev_priv,
184 if (dev_priv->power_domains.init_power_on == enable)
188 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
190 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
192 dev_priv->power_domains.init_power_on = enable;
196 * Starting with Haswell, we have a "Power Down Well" that can be turned off
197 * when not needed anymore. We have 4 registers that can request the power well
198 * to be enabled, and it will only be disabled if none of the registers is
199 * requesting it to be enabled.
201 static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
203 struct drm_device *dev = dev_priv->dev;
206 * After we re-enable the power well, if we touch VGA register 0x3d5
207 * we'll get unclaimed register interrupts. This stops after we write
208 * anything to the VGA MSR register. The vgacon module uses this
209 * register all the time, so if we unbind our driver and, as a
210 * consequence, bind vgacon, we'll get stuck in an infinite loop at
211 * console_unlock(). So make here we touch the VGA MSR register, making
212 * sure vgacon can keep working normally without triggering interrupts
213 * and error messages.
215 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
216 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
217 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
219 if (IS_BROADWELL(dev))
220 gen8_irq_power_well_post_enable(dev_priv,
221 1 << PIPE_C | 1 << PIPE_B);
224 static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
225 struct i915_power_well *power_well)
227 struct drm_device *dev = dev_priv->dev;
230 * After we re-enable the power well, if we touch VGA register 0x3d5
231 * we'll get unclaimed register interrupts. This stops after we write
232 * anything to the VGA MSR register. The vgacon module uses this
233 * register all the time, so if we unbind our driver and, as a
234 * consequence, bind vgacon, we'll get stuck in an infinite loop at
235 * console_unlock(). So make here we touch the VGA MSR register, making
236 * sure vgacon can keep working normally without triggering interrupts
237 * and error messages.
239 if (power_well->data == SKL_DISP_PW_2) {
240 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
241 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
242 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
244 gen8_irq_power_well_post_enable(dev_priv,
245 1 << PIPE_C | 1 << PIPE_B);
249 static void hsw_set_power_well(struct drm_i915_private *dev_priv,
250 struct i915_power_well *power_well, bool enable)
252 bool is_enabled, enable_requested;
255 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
256 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
257 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
260 if (!enable_requested)
261 I915_WRITE(HSW_PWR_WELL_DRIVER,
262 HSW_PWR_WELL_ENABLE_REQUEST);
265 DRM_DEBUG_KMS("Enabling power well\n");
266 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
267 HSW_PWR_WELL_STATE_ENABLED), 20))
268 DRM_ERROR("Timeout enabling power well\n");
269 hsw_power_well_post_enable(dev_priv);
273 if (enable_requested) {
274 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
275 POSTING_READ(HSW_PWR_WELL_DRIVER);
276 DRM_DEBUG_KMS("Requesting to disable the power well\n");
281 #define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
282 BIT(POWER_DOMAIN_TRANSCODER_A) | \
283 BIT(POWER_DOMAIN_PIPE_B) | \
284 BIT(POWER_DOMAIN_TRANSCODER_B) | \
285 BIT(POWER_DOMAIN_PIPE_C) | \
286 BIT(POWER_DOMAIN_TRANSCODER_C) | \
287 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
288 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
289 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
290 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
291 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
292 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
293 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
294 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
295 BIT(POWER_DOMAIN_PORT_DDI_E_2_LANES) | \
296 BIT(POWER_DOMAIN_AUX_B) | \
297 BIT(POWER_DOMAIN_AUX_C) | \
298 BIT(POWER_DOMAIN_AUX_D) | \
299 BIT(POWER_DOMAIN_AUDIO) | \
300 BIT(POWER_DOMAIN_VGA) | \
301 BIT(POWER_DOMAIN_INIT))
302 #define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
303 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
304 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
305 BIT(POWER_DOMAIN_PORT_DDI_E_2_LANES) | \
306 BIT(POWER_DOMAIN_INIT))
307 #define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
308 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
309 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
310 BIT(POWER_DOMAIN_INIT))
311 #define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
312 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
313 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
314 BIT(POWER_DOMAIN_INIT))
315 #define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
316 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
317 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
318 BIT(POWER_DOMAIN_INIT))
319 #define SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
320 (POWER_DOMAIN_MASK & ~( \
321 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
322 SKL_DISPLAY_DDI_A_E_POWER_DOMAINS | \
323 SKL_DISPLAY_DDI_B_POWER_DOMAINS | \
324 SKL_DISPLAY_DDI_C_POWER_DOMAINS | \
325 SKL_DISPLAY_DDI_D_POWER_DOMAINS)) | \
326 BIT(POWER_DOMAIN_INIT))
328 #define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
329 BIT(POWER_DOMAIN_TRANSCODER_A) | \
330 BIT(POWER_DOMAIN_PIPE_B) | \
331 BIT(POWER_DOMAIN_TRANSCODER_B) | \
332 BIT(POWER_DOMAIN_PIPE_C) | \
333 BIT(POWER_DOMAIN_TRANSCODER_C) | \
334 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
335 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
336 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
337 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
338 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
339 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
340 BIT(POWER_DOMAIN_AUX_B) | \
341 BIT(POWER_DOMAIN_AUX_C) | \
342 BIT(POWER_DOMAIN_AUDIO) | \
343 BIT(POWER_DOMAIN_VGA) | \
344 BIT(POWER_DOMAIN_INIT))
345 #define BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
346 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
347 BIT(POWER_DOMAIN_PIPE_A) | \
348 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
349 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
350 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
351 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
352 BIT(POWER_DOMAIN_AUX_A) | \
353 BIT(POWER_DOMAIN_PLLS) | \
354 BIT(POWER_DOMAIN_INIT))
355 #define BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
356 (POWER_DOMAIN_MASK & ~(BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
357 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS)) | \
358 BIT(POWER_DOMAIN_INIT))
360 static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
362 struct drm_device *dev = dev_priv->dev;
364 WARN(!IS_BROXTON(dev), "Platform doesn't support DC9.\n");
365 WARN((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
366 "DC9 already programmed to be enabled.\n");
367 WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
368 "DC5 still not disabled to enable DC9.\n");
369 WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
370 WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
373 * TODO: check for the following to verify the conditions to enter DC9
374 * state are satisfied:
375 * 1] Check relevant display engine registers to verify if mode set
376 * disable sequence was followed.
377 * 2] Check if display uninitialize sequence is initialized.
381 static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
383 WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
384 WARN(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
385 "DC9 already programmed to be disabled.\n");
386 WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
387 "DC5 still not disabled.\n");
390 * TODO: check for the following to verify DC9 state was indeed
391 * entered before programming to disable it:
392 * 1] Check relevant display engine registers to verify if mode
393 * set disable sequence was followed.
394 * 2] Check if display uninitialize sequence is initialized.
398 static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
403 mask = DC_STATE_EN_UPTO_DC5;
404 if (IS_BROXTON(dev_priv))
405 mask |= DC_STATE_EN_DC9;
407 mask |= DC_STATE_EN_UPTO_DC6;
409 WARN_ON_ONCE(state & ~mask);
411 val = I915_READ(DC_STATE_EN);
412 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
416 I915_WRITE(DC_STATE_EN, val);
417 POSTING_READ(DC_STATE_EN);
420 void bxt_enable_dc9(struct drm_i915_private *dev_priv)
422 assert_can_enable_dc9(dev_priv);
424 DRM_DEBUG_KMS("Enabling DC9\n");
426 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
429 void bxt_disable_dc9(struct drm_i915_private *dev_priv)
431 assert_can_disable_dc9(dev_priv);
433 DRM_DEBUG_KMS("Disabling DC9\n");
435 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
438 static void gen9_set_dc_state_debugmask_memory_up(
439 struct drm_i915_private *dev_priv)
443 /* The below bit doesn't need to be cleared ever afterwards */
444 val = I915_READ(DC_STATE_DEBUG);
445 if (!(val & DC_STATE_DEBUG_MASK_MEMORY_UP)) {
446 val |= DC_STATE_DEBUG_MASK_MEMORY_UP;
447 I915_WRITE(DC_STATE_DEBUG, val);
448 POSTING_READ(DC_STATE_DEBUG);
452 static void assert_csr_loaded(struct drm_i915_private *dev_priv)
454 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
455 "CSR program storage start is NULL\n");
456 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
457 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
460 static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
462 struct drm_device *dev = dev_priv->dev;
463 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
466 WARN_ONCE(!IS_SKYLAKE(dev), "Platform doesn't support DC5.\n");
467 WARN_ONCE(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
468 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
470 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
471 "DC5 already programmed to be enabled.\n");
472 WARN_ONCE(dev_priv->pm.suspended,
473 "DC5 cannot be enabled, if platform is runtime-suspended.\n");
475 assert_csr_loaded(dev_priv);
478 static void assert_can_disable_dc5(struct drm_i915_private *dev_priv)
480 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
483 * During initialization, the firmware may not be loaded yet.
484 * We still want to make sure that the DC enabling flag is cleared.
486 if (dev_priv->power_domains.initializing)
489 WARN_ONCE(!pg2_enabled, "PG2 not enabled to disable DC5.\n");
490 WARN_ONCE(dev_priv->pm.suspended,
491 "Disabling of DC5 while platform is runtime-suspended should never happen.\n");
494 static void gen9_enable_dc5(struct drm_i915_private *dev_priv)
496 assert_can_enable_dc5(dev_priv);
498 DRM_DEBUG_KMS("Enabling DC5\n");
500 gen9_set_dc_state_debugmask_memory_up(dev_priv);
502 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
505 static void gen9_disable_dc5(struct drm_i915_private *dev_priv)
507 assert_can_disable_dc5(dev_priv);
509 DRM_DEBUG_KMS("Disabling DC5\n");
511 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
514 static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
516 struct drm_device *dev = dev_priv->dev;
518 WARN_ONCE(!IS_SKYLAKE(dev), "Platform doesn't support DC6.\n");
519 WARN_ONCE(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
520 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
521 "Backlight is not disabled.\n");
522 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
523 "DC6 already programmed to be enabled.\n");
525 assert_csr_loaded(dev_priv);
528 static void assert_can_disable_dc6(struct drm_i915_private *dev_priv)
531 * During initialization, the firmware may not be loaded yet.
532 * We still want to make sure that the DC enabling flag is cleared.
534 if (dev_priv->power_domains.initializing)
537 WARN_ONCE(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
538 "DC6 already programmed to be disabled.\n");
541 void skl_enable_dc6(struct drm_i915_private *dev_priv)
543 assert_can_enable_dc6(dev_priv);
545 DRM_DEBUG_KMS("Enabling DC6\n");
547 gen9_set_dc_state_debugmask_memory_up(dev_priv);
549 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
553 void skl_disable_dc6(struct drm_i915_private *dev_priv)
555 assert_can_disable_dc6(dev_priv);
557 DRM_DEBUG_KMS("Disabling DC6\n");
559 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
562 static void skl_set_power_well(struct drm_i915_private *dev_priv,
563 struct i915_power_well *power_well, bool enable)
565 struct drm_device *dev = dev_priv->dev;
566 uint32_t tmp, fuse_status;
567 uint32_t req_mask, state_mask;
568 bool is_enabled, enable_requested, check_fuse_status = false;
570 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
571 fuse_status = I915_READ(SKL_FUSE_STATUS);
573 switch (power_well->data) {
575 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
576 SKL_FUSE_PG0_DIST_STATUS), 1)) {
577 DRM_ERROR("PG0 not enabled\n");
582 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
583 DRM_ERROR("PG1 in disabled state\n");
587 case SKL_DISP_PW_DDI_A_E:
588 case SKL_DISP_PW_DDI_B:
589 case SKL_DISP_PW_DDI_C:
590 case SKL_DISP_PW_DDI_D:
591 case SKL_DISP_PW_MISC_IO:
594 WARN(1, "Unknown power well %lu\n", power_well->data);
598 req_mask = SKL_POWER_WELL_REQ(power_well->data);
599 enable_requested = tmp & req_mask;
600 state_mask = SKL_POWER_WELL_STATE(power_well->data);
601 is_enabled = tmp & state_mask;
604 if (!enable_requested) {
605 WARN((tmp & state_mask) &&
606 !I915_READ(HSW_PWR_WELL_BIOS),
607 "Invalid for power well status to be enabled, unless done by the BIOS, \
608 when request is to disable!\n");
609 if (power_well->data == SKL_DISP_PW_2) {
610 if (GEN9_ENABLE_DC5(dev))
611 gen9_disable_dc5(dev_priv);
612 if (SKL_ENABLE_DC6(dev)) {
614 * DDI buffer programming unnecessary during driver-load/resume
615 * as it's already done during modeset initialization then.
616 * It's also invalid here as encoder list is still uninitialized.
618 if (!dev_priv->power_domains.initializing)
619 intel_prepare_ddi(dev);
622 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
626 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
627 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
629 DRM_ERROR("%s enable timeout\n",
631 check_fuse_status = true;
634 if (enable_requested) {
635 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
636 POSTING_READ(HSW_PWR_WELL_DRIVER);
637 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
639 if (GEN9_ENABLE_DC5(dev) &&
640 power_well->data == SKL_DISP_PW_2)
641 gen9_enable_dc5(dev_priv);
645 if (check_fuse_status) {
646 if (power_well->data == SKL_DISP_PW_1) {
647 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
648 SKL_FUSE_PG1_DIST_STATUS), 1))
649 DRM_ERROR("PG1 distributing status timeout\n");
650 } else if (power_well->data == SKL_DISP_PW_2) {
651 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
652 SKL_FUSE_PG2_DIST_STATUS), 1))
653 DRM_ERROR("PG2 distributing status timeout\n");
657 if (enable && !is_enabled)
658 skl_power_well_post_enable(dev_priv, power_well);
661 static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
662 struct i915_power_well *power_well)
664 hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
667 * We're taking over the BIOS, so clear any requests made by it since
668 * the driver is in charge now.
670 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
671 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
674 static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
675 struct i915_power_well *power_well)
677 hsw_set_power_well(dev_priv, power_well, true);
680 static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
681 struct i915_power_well *power_well)
683 hsw_set_power_well(dev_priv, power_well, false);
686 static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
687 struct i915_power_well *power_well)
689 uint32_t mask = SKL_POWER_WELL_REQ(power_well->data) |
690 SKL_POWER_WELL_STATE(power_well->data);
692 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
695 static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
696 struct i915_power_well *power_well)
698 skl_set_power_well(dev_priv, power_well, power_well->count > 0);
700 /* Clear any request made by BIOS as driver is taking over */
701 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
704 static void skl_power_well_enable(struct drm_i915_private *dev_priv,
705 struct i915_power_well *power_well)
707 skl_set_power_well(dev_priv, power_well, true);
710 static void skl_power_well_disable(struct drm_i915_private *dev_priv,
711 struct i915_power_well *power_well)
713 skl_set_power_well(dev_priv, power_well, false);
716 static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
717 struct i915_power_well *power_well)
721 static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
722 struct i915_power_well *power_well)
727 static void vlv_set_power_well(struct drm_i915_private *dev_priv,
728 struct i915_power_well *power_well, bool enable)
730 enum punit_power_well power_well_id = power_well->data;
735 mask = PUNIT_PWRGT_MASK(power_well_id);
736 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
737 PUNIT_PWRGT_PWR_GATE(power_well_id);
739 mutex_lock(&dev_priv->rps.hw_lock);
742 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
747 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
750 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
752 if (wait_for(COND, 100))
753 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
755 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
760 mutex_unlock(&dev_priv->rps.hw_lock);
763 static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
764 struct i915_power_well *power_well)
766 vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
769 static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
770 struct i915_power_well *power_well)
772 vlv_set_power_well(dev_priv, power_well, true);
775 static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
776 struct i915_power_well *power_well)
778 vlv_set_power_well(dev_priv, power_well, false);
781 static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
782 struct i915_power_well *power_well)
784 int power_well_id = power_well->data;
785 bool enabled = false;
790 mask = PUNIT_PWRGT_MASK(power_well_id);
791 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
793 mutex_lock(&dev_priv->rps.hw_lock);
795 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
797 * We only ever set the power-on and power-gate states, anything
798 * else is unexpected.
800 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
801 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
806 * A transient state at this point would mean some unexpected party
807 * is poking at the power controls too.
809 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
810 WARN_ON(ctrl != state);
812 mutex_unlock(&dev_priv->rps.hw_lock);
817 static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
822 * Enable the CRI clock source so we can get at the
823 * display and the reference clock for VGA
824 * hotplug / manual detection. Supposedly DSI also
825 * needs the ref clock up and running.
827 * CHV DPLL B/C have some issues if VGA mode is enabled.
829 for_each_pipe(dev_priv->dev, pipe) {
830 u32 val = I915_READ(DPLL(pipe));
832 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
834 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
836 I915_WRITE(DPLL(pipe), val);
839 spin_lock_irq(&dev_priv->irq_lock);
840 valleyview_enable_display_irqs(dev_priv);
841 spin_unlock_irq(&dev_priv->irq_lock);
844 * During driver initialization/resume we can avoid restoring the
845 * part of the HW/SW state that will be inited anyway explicitly.
847 if (dev_priv->power_domains.initializing)
850 intel_hpd_init(dev_priv);
852 i915_redisable_vga_power_on(dev_priv->dev);
855 static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
857 spin_lock_irq(&dev_priv->irq_lock);
858 valleyview_disable_display_irqs(dev_priv);
859 spin_unlock_irq(&dev_priv->irq_lock);
861 vlv_power_sequencer_reset(dev_priv);
864 static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
865 struct i915_power_well *power_well)
867 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
869 vlv_set_power_well(dev_priv, power_well, true);
871 vlv_display_power_well_init(dev_priv);
874 static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
875 struct i915_power_well *power_well)
877 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
879 vlv_display_power_well_deinit(dev_priv);
881 vlv_set_power_well(dev_priv, power_well, false);
884 static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
885 struct i915_power_well *power_well)
887 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
889 /* since ref/cri clock was enabled */
890 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
892 vlv_set_power_well(dev_priv, power_well, true);
895 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
896 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
897 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
898 * b. The other bits such as sfr settings / modesel may all
901 * This should only be done on init and resume from S3 with
902 * both PLLs disabled, or we risk losing DPIO and PLL
905 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
908 static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
909 struct i915_power_well *power_well)
913 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
915 for_each_pipe(dev_priv, pipe)
916 assert_pll_disabled(dev_priv, pipe);
918 /* Assert common reset */
919 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
921 vlv_set_power_well(dev_priv, power_well, false);
924 #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
926 static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
929 struct i915_power_domains *power_domains = &dev_priv->power_domains;
932 for (i = 0; i < power_domains->power_well_count; i++) {
933 struct i915_power_well *power_well;
935 power_well = &power_domains->power_wells[i];
936 if (power_well->data == power_well_id)
943 #define BITS_SET(val, bits) (((val) & (bits)) == (bits))
945 static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
947 struct i915_power_well *cmn_bc =
948 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
949 struct i915_power_well *cmn_d =
950 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
951 u32 phy_control = dev_priv->chv_phy_control;
953 u32 phy_status_mask = 0xffffffff;
957 * The BIOS can leave the PHY is some weird state
958 * where it doesn't fully power down some parts.
959 * Disable the asserts until the PHY has been fully
960 * reset (ie. the power well has been disabled at
963 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
964 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
965 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
966 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
967 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
968 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
969 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
971 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
972 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
973 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
974 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
976 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
977 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
979 /* this assumes override is only used to enable lanes */
980 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
981 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
983 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
984 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
986 /* CL1 is on whenever anything is on in either channel */
987 if (BITS_SET(phy_control,
988 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
989 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
990 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
993 * The DPLLB check accounts for the pipe B + port A usage
994 * with CL2 powered up but all the lanes in the second channel
997 if (BITS_SET(phy_control,
998 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
999 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1000 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1002 if (BITS_SET(phy_control,
1003 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1004 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1005 if (BITS_SET(phy_control,
1006 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1007 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1009 if (BITS_SET(phy_control,
1010 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1011 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1012 if (BITS_SET(phy_control,
1013 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1014 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1017 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1018 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1020 /* this assumes override is only used to enable lanes */
1021 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1022 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1024 if (BITS_SET(phy_control,
1025 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1026 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1028 if (BITS_SET(phy_control,
1029 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1030 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1031 if (BITS_SET(phy_control,
1032 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1033 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1036 phy_status &= phy_status_mask;
1039 * The PHY may be busy with some initial calibration and whatnot,
1040 * so the power state can take a while to actually change.
1042 if (wait_for((tmp = I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask) == phy_status, 10))
1043 WARN(phy_status != tmp,
1044 "Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1045 tmp, phy_status, dev_priv->chv_phy_control);
1050 static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1051 struct i915_power_well *power_well)
1057 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1058 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
1060 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1068 /* since ref/cri clock was enabled */
1069 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1070 vlv_set_power_well(dev_priv, power_well, true);
1072 /* Poll for phypwrgood signal */
1073 if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1))
1074 DRM_ERROR("Display PHY %d is not power up\n", phy);
1076 mutex_lock(&dev_priv->sb_lock);
1078 /* Enable dynamic power down */
1079 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
1080 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1081 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
1082 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1084 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1085 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1086 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1087 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
1090 * Force the non-existing CL2 off. BXT does this
1091 * too, so maybe it saves some power even though
1092 * CL2 doesn't exist?
1094 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1095 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1096 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
1099 mutex_unlock(&dev_priv->sb_lock);
1101 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1102 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1104 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1105 phy, dev_priv->chv_phy_control);
1107 assert_chv_phy_status(dev_priv);
1110 static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1111 struct i915_power_well *power_well)
1115 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1116 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
1118 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1120 assert_pll_disabled(dev_priv, PIPE_A);
1121 assert_pll_disabled(dev_priv, PIPE_B);
1124 assert_pll_disabled(dev_priv, PIPE_C);
1127 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1128 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1130 vlv_set_power_well(dev_priv, power_well, false);
1132 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1133 phy, dev_priv->chv_phy_control);
1135 /* PHY is fully reset now, so we can enable the PHY state asserts */
1136 dev_priv->chv_phy_assert[phy] = true;
1138 assert_chv_phy_status(dev_priv);
1141 static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1142 enum dpio_channel ch, bool override, unsigned int mask)
1144 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1145 u32 reg, val, expected, actual;
1148 * The BIOS can leave the PHY is some weird state
1149 * where it doesn't fully power down some parts.
1150 * Disable the asserts until the PHY has been fully
1151 * reset (ie. the power well has been disabled at
1154 if (!dev_priv->chv_phy_assert[phy])
1158 reg = _CHV_CMN_DW0_CH0;
1160 reg = _CHV_CMN_DW6_CH1;
1162 mutex_lock(&dev_priv->sb_lock);
1163 val = vlv_dpio_read(dev_priv, pipe, reg);
1164 mutex_unlock(&dev_priv->sb_lock);
1167 * This assumes !override is only used when the port is disabled.
1168 * All lanes should power down even without the override when
1169 * the port is disabled.
1171 if (!override || mask == 0xf) {
1172 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1174 * If CH1 common lane is not active anymore
1175 * (eg. for pipe B DPLL) the entire channel will
1176 * shut down, which causes the common lane registers
1177 * to read as 0. That means we can't actually check
1178 * the lane power down status bits, but as the entire
1179 * register reads as 0 it's a good indication that the
1180 * channel is indeed entirely powered down.
1182 if (ch == DPIO_CH1 && val == 0)
1184 } else if (mask != 0x0) {
1185 expected = DPIO_ANYDL_POWERDOWN;
1191 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1193 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1194 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1196 WARN(actual != expected,
1197 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1198 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1199 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1203 bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1204 enum dpio_channel ch, bool override)
1206 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1209 mutex_lock(&power_domains->lock);
1211 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1213 if (override == was_override)
1217 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1219 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1221 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1223 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1224 phy, ch, dev_priv->chv_phy_control);
1226 assert_chv_phy_status(dev_priv);
1229 mutex_unlock(&power_domains->lock);
1231 return was_override;
1234 void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1235 bool override, unsigned int mask)
1237 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1238 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1239 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1240 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1242 mutex_lock(&power_domains->lock);
1244 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1245 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1248 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1250 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1252 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1254 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1255 phy, ch, mask, dev_priv->chv_phy_control);
1257 assert_chv_phy_status(dev_priv);
1259 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1261 mutex_unlock(&power_domains->lock);
1264 static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1265 struct i915_power_well *power_well)
1267 enum pipe pipe = power_well->data;
1271 mutex_lock(&dev_priv->rps.hw_lock);
1273 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1275 * We only ever set the power-on and power-gate states, anything
1276 * else is unexpected.
1278 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1279 enabled = state == DP_SSS_PWR_ON(pipe);
1282 * A transient state at this point would mean some unexpected party
1283 * is poking at the power controls too.
1285 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1286 WARN_ON(ctrl << 16 != state);
1288 mutex_unlock(&dev_priv->rps.hw_lock);
1293 static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1294 struct i915_power_well *power_well,
1297 enum pipe pipe = power_well->data;
1301 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1303 mutex_lock(&dev_priv->rps.hw_lock);
1306 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1311 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1312 ctrl &= ~DP_SSC_MASK(pipe);
1313 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1314 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1316 if (wait_for(COND, 100))
1317 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
1319 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1324 mutex_unlock(&dev_priv->rps.hw_lock);
1327 static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
1328 struct i915_power_well *power_well)
1330 WARN_ON_ONCE(power_well->data != PIPE_A);
1332 chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
1335 static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1336 struct i915_power_well *power_well)
1338 WARN_ON_ONCE(power_well->data != PIPE_A);
1340 chv_set_pipe_power_well(dev_priv, power_well, true);
1342 vlv_display_power_well_init(dev_priv);
1345 static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1346 struct i915_power_well *power_well)
1348 WARN_ON_ONCE(power_well->data != PIPE_A);
1350 vlv_display_power_well_deinit(dev_priv);
1352 chv_set_pipe_power_well(dev_priv, power_well, false);
1356 * intel_display_power_get - grab a power domain reference
1357 * @dev_priv: i915 device instance
1358 * @domain: power domain to reference
1360 * This function grabs a power domain reference for @domain and ensures that the
1361 * power domain and all its parents are powered up. Therefore users should only
1362 * grab a reference to the innermost power domain they need.
1364 * Any power domain reference obtained by this function must have a symmetric
1365 * call to intel_display_power_put() to release the reference again.
1367 void intel_display_power_get(struct drm_i915_private *dev_priv,
1368 enum intel_display_power_domain domain)
1370 struct i915_power_domains *power_domains;
1371 struct i915_power_well *power_well;
1374 intel_runtime_pm_get(dev_priv);
1376 power_domains = &dev_priv->power_domains;
1378 mutex_lock(&power_domains->lock);
1380 for_each_power_well(i, power_well, BIT(domain), power_domains) {
1381 if (!power_well->count++)
1382 intel_power_well_enable(dev_priv, power_well);
1385 power_domains->domain_use_count[domain]++;
1387 mutex_unlock(&power_domains->lock);
1391 * intel_display_power_put - release a power domain reference
1392 * @dev_priv: i915 device instance
1393 * @domain: power domain to reference
1395 * This function drops the power domain reference obtained by
1396 * intel_display_power_get() and might power down the corresponding hardware
1397 * block right away if this is the last reference.
1399 void intel_display_power_put(struct drm_i915_private *dev_priv,
1400 enum intel_display_power_domain domain)
1402 struct i915_power_domains *power_domains;
1403 struct i915_power_well *power_well;
1406 power_domains = &dev_priv->power_domains;
1408 mutex_lock(&power_domains->lock);
1410 WARN_ON(!power_domains->domain_use_count[domain]);
1411 power_domains->domain_use_count[domain]--;
1413 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
1414 WARN_ON(!power_well->count);
1416 if (!--power_well->count)
1417 intel_power_well_disable(dev_priv, power_well);
1420 mutex_unlock(&power_domains->lock);
1422 intel_runtime_pm_put(dev_priv);
1425 #define HSW_ALWAYS_ON_POWER_DOMAINS ( \
1426 BIT(POWER_DOMAIN_PIPE_A) | \
1427 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
1428 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
1429 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
1430 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1431 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1432 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1433 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1434 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
1435 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
1436 BIT(POWER_DOMAIN_PORT_CRT) | \
1437 BIT(POWER_DOMAIN_PLLS) | \
1438 BIT(POWER_DOMAIN_AUX_A) | \
1439 BIT(POWER_DOMAIN_AUX_B) | \
1440 BIT(POWER_DOMAIN_AUX_C) | \
1441 BIT(POWER_DOMAIN_AUX_D) | \
1442 BIT(POWER_DOMAIN_INIT))
1443 #define HSW_DISPLAY_POWER_DOMAINS ( \
1444 (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
1445 BIT(POWER_DOMAIN_INIT))
1447 #define BDW_ALWAYS_ON_POWER_DOMAINS ( \
1448 HSW_ALWAYS_ON_POWER_DOMAINS | \
1449 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
1450 #define BDW_DISPLAY_POWER_DOMAINS ( \
1451 (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
1452 BIT(POWER_DOMAIN_INIT))
1454 #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
1455 #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
1457 #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
1458 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1459 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1460 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1461 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1462 BIT(POWER_DOMAIN_PORT_CRT) | \
1463 BIT(POWER_DOMAIN_AUX_B) | \
1464 BIT(POWER_DOMAIN_AUX_C) | \
1465 BIT(POWER_DOMAIN_INIT))
1467 #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
1468 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1469 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1470 BIT(POWER_DOMAIN_AUX_B) | \
1471 BIT(POWER_DOMAIN_INIT))
1473 #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
1474 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1475 BIT(POWER_DOMAIN_AUX_B) | \
1476 BIT(POWER_DOMAIN_INIT))
1478 #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
1479 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1480 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1481 BIT(POWER_DOMAIN_AUX_C) | \
1482 BIT(POWER_DOMAIN_INIT))
1484 #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
1485 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1486 BIT(POWER_DOMAIN_AUX_C) | \
1487 BIT(POWER_DOMAIN_INIT))
1489 #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
1490 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1491 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1492 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1493 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1494 BIT(POWER_DOMAIN_AUX_B) | \
1495 BIT(POWER_DOMAIN_AUX_C) | \
1496 BIT(POWER_DOMAIN_INIT))
1498 #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
1499 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
1500 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
1501 BIT(POWER_DOMAIN_AUX_D) | \
1502 BIT(POWER_DOMAIN_INIT))
1504 static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
1505 .sync_hw = i9xx_always_on_power_well_noop,
1506 .enable = i9xx_always_on_power_well_noop,
1507 .disable = i9xx_always_on_power_well_noop,
1508 .is_enabled = i9xx_always_on_power_well_enabled,
1511 static const struct i915_power_well_ops chv_pipe_power_well_ops = {
1512 .sync_hw = chv_pipe_power_well_sync_hw,
1513 .enable = chv_pipe_power_well_enable,
1514 .disable = chv_pipe_power_well_disable,
1515 .is_enabled = chv_pipe_power_well_enabled,
1518 static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
1519 .sync_hw = vlv_power_well_sync_hw,
1520 .enable = chv_dpio_cmn_power_well_enable,
1521 .disable = chv_dpio_cmn_power_well_disable,
1522 .is_enabled = vlv_power_well_enabled,
1525 static struct i915_power_well i9xx_always_on_power_well[] = {
1527 .name = "always-on",
1529 .domains = POWER_DOMAIN_MASK,
1530 .ops = &i9xx_always_on_power_well_ops,
1534 static const struct i915_power_well_ops hsw_power_well_ops = {
1535 .sync_hw = hsw_power_well_sync_hw,
1536 .enable = hsw_power_well_enable,
1537 .disable = hsw_power_well_disable,
1538 .is_enabled = hsw_power_well_enabled,
1541 static const struct i915_power_well_ops skl_power_well_ops = {
1542 .sync_hw = skl_power_well_sync_hw,
1543 .enable = skl_power_well_enable,
1544 .disable = skl_power_well_disable,
1545 .is_enabled = skl_power_well_enabled,
1548 static struct i915_power_well hsw_power_wells[] = {
1550 .name = "always-on",
1552 .domains = HSW_ALWAYS_ON_POWER_DOMAINS,
1553 .ops = &i9xx_always_on_power_well_ops,
1557 .domains = HSW_DISPLAY_POWER_DOMAINS,
1558 .ops = &hsw_power_well_ops,
1562 static struct i915_power_well bdw_power_wells[] = {
1564 .name = "always-on",
1566 .domains = BDW_ALWAYS_ON_POWER_DOMAINS,
1567 .ops = &i9xx_always_on_power_well_ops,
1571 .domains = BDW_DISPLAY_POWER_DOMAINS,
1572 .ops = &hsw_power_well_ops,
1576 static const struct i915_power_well_ops vlv_display_power_well_ops = {
1577 .sync_hw = vlv_power_well_sync_hw,
1578 .enable = vlv_display_power_well_enable,
1579 .disable = vlv_display_power_well_disable,
1580 .is_enabled = vlv_power_well_enabled,
1583 static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
1584 .sync_hw = vlv_power_well_sync_hw,
1585 .enable = vlv_dpio_cmn_power_well_enable,
1586 .disable = vlv_dpio_cmn_power_well_disable,
1587 .is_enabled = vlv_power_well_enabled,
1590 static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
1591 .sync_hw = vlv_power_well_sync_hw,
1592 .enable = vlv_power_well_enable,
1593 .disable = vlv_power_well_disable,
1594 .is_enabled = vlv_power_well_enabled,
1597 static struct i915_power_well vlv_power_wells[] = {
1599 .name = "always-on",
1601 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1602 .ops = &i9xx_always_on_power_well_ops,
1603 .data = PUNIT_POWER_WELL_ALWAYS_ON,
1607 .domains = VLV_DISPLAY_POWER_DOMAINS,
1608 .data = PUNIT_POWER_WELL_DISP2D,
1609 .ops = &vlv_display_power_well_ops,
1612 .name = "dpio-tx-b-01",
1613 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1614 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1615 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1616 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1617 .ops = &vlv_dpio_power_well_ops,
1618 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1621 .name = "dpio-tx-b-23",
1622 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1623 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1624 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1625 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1626 .ops = &vlv_dpio_power_well_ops,
1627 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
1630 .name = "dpio-tx-c-01",
1631 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1632 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1633 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1634 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1635 .ops = &vlv_dpio_power_well_ops,
1636 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
1639 .name = "dpio-tx-c-23",
1640 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1641 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1642 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1643 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1644 .ops = &vlv_dpio_power_well_ops,
1645 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
1648 .name = "dpio-common",
1649 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
1650 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1651 .ops = &vlv_dpio_cmn_power_well_ops,
1655 static struct i915_power_well chv_power_wells[] = {
1657 .name = "always-on",
1659 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1660 .ops = &i9xx_always_on_power_well_ops,
1665 * Pipe A power well is the new disp2d well. Pipe B and C
1666 * power wells don't actually exist. Pipe A power well is
1667 * required for any pipe to work.
1669 .domains = VLV_DISPLAY_POWER_DOMAINS,
1671 .ops = &chv_pipe_power_well_ops,
1674 .name = "dpio-common-bc",
1675 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
1676 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1677 .ops = &chv_dpio_cmn_power_well_ops,
1680 .name = "dpio-common-d",
1681 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
1682 .data = PUNIT_POWER_WELL_DPIO_CMN_D,
1683 .ops = &chv_dpio_cmn_power_well_ops,
1687 bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
1690 struct i915_power_well *power_well;
1693 power_well = lookup_power_well(dev_priv, power_well_id);
1694 ret = power_well->ops->is_enabled(dev_priv, power_well);
1699 static struct i915_power_well skl_power_wells[] = {
1701 .name = "always-on",
1703 .domains = SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1704 .ops = &i9xx_always_on_power_well_ops,
1705 .data = SKL_DISP_PW_ALWAYS_ON,
1708 .name = "power well 1",
1709 /* Handled by the DMC firmware */
1711 .ops = &skl_power_well_ops,
1712 .data = SKL_DISP_PW_1,
1715 .name = "MISC IO power well",
1716 /* Handled by the DMC firmware */
1718 .ops = &skl_power_well_ops,
1719 .data = SKL_DISP_PW_MISC_IO,
1722 .name = "power well 2",
1723 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1724 .ops = &skl_power_well_ops,
1725 .data = SKL_DISP_PW_2,
1728 .name = "DDI A/E power well",
1729 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
1730 .ops = &skl_power_well_ops,
1731 .data = SKL_DISP_PW_DDI_A_E,
1734 .name = "DDI B power well",
1735 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
1736 .ops = &skl_power_well_ops,
1737 .data = SKL_DISP_PW_DDI_B,
1740 .name = "DDI C power well",
1741 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
1742 .ops = &skl_power_well_ops,
1743 .data = SKL_DISP_PW_DDI_C,
1746 .name = "DDI D power well",
1747 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
1748 .ops = &skl_power_well_ops,
1749 .data = SKL_DISP_PW_DDI_D,
1753 void skl_pw1_misc_io_init(struct drm_i915_private *dev_priv)
1755 struct i915_power_well *well;
1757 if (!IS_SKYLAKE(dev_priv))
1760 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
1761 intel_power_well_enable(dev_priv, well);
1763 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
1764 intel_power_well_enable(dev_priv, well);
1767 void skl_pw1_misc_io_fini(struct drm_i915_private *dev_priv)
1769 struct i915_power_well *well;
1771 if (!IS_SKYLAKE(dev_priv))
1774 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
1775 intel_power_well_disable(dev_priv, well);
1777 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
1778 intel_power_well_disable(dev_priv, well);
1781 static struct i915_power_well bxt_power_wells[] = {
1783 .name = "always-on",
1785 .domains = BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1786 .ops = &i9xx_always_on_power_well_ops,
1789 .name = "power well 1",
1790 .domains = BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS,
1791 .ops = &skl_power_well_ops,
1792 .data = SKL_DISP_PW_1,
1795 .name = "power well 2",
1796 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1797 .ops = &skl_power_well_ops,
1798 .data = SKL_DISP_PW_2,
1802 #define set_power_wells(power_domains, __power_wells) ({ \
1803 (power_domains)->power_wells = (__power_wells); \
1804 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
1808 * intel_power_domains_init - initializes the power domain structures
1809 * @dev_priv: i915 device instance
1811 * Initializes the power domain structures for @dev_priv depending upon the
1812 * supported platform.
1814 int intel_power_domains_init(struct drm_i915_private *dev_priv)
1816 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1818 mutex_init(&power_domains->lock);
1821 * The enabling order will be from lower to higher indexed wells,
1822 * the disabling order is reversed.
1824 if (IS_HASWELL(dev_priv->dev)) {
1825 set_power_wells(power_domains, hsw_power_wells);
1826 } else if (IS_BROADWELL(dev_priv->dev)) {
1827 set_power_wells(power_domains, bdw_power_wells);
1828 } else if (IS_SKYLAKE(dev_priv->dev) || IS_KABYLAKE(dev_priv->dev)) {
1829 set_power_wells(power_domains, skl_power_wells);
1830 } else if (IS_BROXTON(dev_priv->dev)) {
1831 set_power_wells(power_domains, bxt_power_wells);
1832 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1833 set_power_wells(power_domains, chv_power_wells);
1834 } else if (IS_VALLEYVIEW(dev_priv->dev)) {
1835 set_power_wells(power_domains, vlv_power_wells);
1837 set_power_wells(power_domains, i9xx_always_on_power_well);
1844 * intel_power_domains_fini - finalizes the power domain structures
1845 * @dev_priv: i915 device instance
1847 * Finalizes the power domain structures for @dev_priv depending upon the
1848 * supported platform. This function also disables runtime pm and ensures that
1849 * the device stays powered up so that the driver can be reloaded.
1851 void intel_power_domains_fini(struct drm_i915_private *dev_priv)
1853 /* The i915.ko module is still not prepared to be loaded when
1854 * the power well is not enabled, so just enable it in case
1855 * we're going to unload/reload. */
1856 intel_display_set_init_power(dev_priv, true);
1858 /* Remove the refcount we took to keep power well support disabled. */
1859 if (!i915.disable_power_well)
1860 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
1863 static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
1865 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1866 struct i915_power_well *power_well;
1869 mutex_lock(&power_domains->lock);
1870 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
1871 power_well->ops->sync_hw(dev_priv, power_well);
1872 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
1875 mutex_unlock(&power_domains->lock);
1878 static void skl_display_core_init(struct drm_i915_private *dev_priv,
1881 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1884 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
1886 /* enable PCH reset handshake */
1887 val = I915_READ(HSW_NDE_RSTWRN_OPT);
1888 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
1890 /* enable PG1 and Misc I/O */
1891 mutex_lock(&power_domains->lock);
1892 skl_pw1_misc_io_init(dev_priv);
1893 mutex_unlock(&power_domains->lock);
1898 skl_init_cdclk(dev_priv);
1900 if (dev_priv->csr.dmc_payload)
1901 intel_csr_load_program(dev_priv);
1904 static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
1906 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1908 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
1910 skl_uninit_cdclk(dev_priv);
1912 /* The spec doesn't call for removing the reset handshake flag */
1913 /* disable PG1 and Misc I/O */
1914 mutex_lock(&power_domains->lock);
1915 skl_pw1_misc_io_fini(dev_priv);
1916 mutex_unlock(&power_domains->lock);
1919 static void chv_phy_control_init(struct drm_i915_private *dev_priv)
1921 struct i915_power_well *cmn_bc =
1922 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1923 struct i915_power_well *cmn_d =
1924 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1927 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
1928 * workaround never ever read DISPLAY_PHY_CONTROL, and
1929 * instead maintain a shadow copy ourselves. Use the actual
1930 * power well state and lane status to reconstruct the
1931 * expected initial value.
1933 dev_priv->chv_phy_control =
1934 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
1935 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
1936 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
1937 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
1938 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
1941 * If all lanes are disabled we leave the override disabled
1942 * with all power down bits cleared to match the state we
1943 * would use after disabling the port. Otherwise enable the
1944 * override and set the lane powerdown bits accding to the
1945 * current lane status.
1947 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1948 uint32_t status = I915_READ(DPLL(PIPE_A));
1951 mask = status & DPLL_PORTB_READY_MASK;
1955 dev_priv->chv_phy_control |=
1956 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
1958 dev_priv->chv_phy_control |=
1959 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
1961 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
1965 dev_priv->chv_phy_control |=
1966 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
1968 dev_priv->chv_phy_control |=
1969 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
1971 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
1973 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
1975 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
1978 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1979 uint32_t status = I915_READ(DPIO_PHY_STATUS);
1982 mask = status & DPLL_PORTD_READY_MASK;
1987 dev_priv->chv_phy_control |=
1988 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
1990 dev_priv->chv_phy_control |=
1991 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
1993 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
1995 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
1997 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
2000 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2002 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2003 dev_priv->chv_phy_control);
2006 static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2008 struct i915_power_well *cmn =
2009 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2010 struct i915_power_well *disp2d =
2011 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2013 /* If the display might be already active skip this */
2014 if (cmn->ops->is_enabled(dev_priv, cmn) &&
2015 disp2d->ops->is_enabled(dev_priv, disp2d) &&
2016 I915_READ(DPIO_CTL) & DPIO_CMNRST)
2019 DRM_DEBUG_KMS("toggling display PHY side reset\n");
2021 /* cmnlane needs DPLL registers */
2022 disp2d->ops->enable(dev_priv, disp2d);
2025 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2026 * Need to assert and de-assert PHY SB reset by gating the
2027 * common lane power, then un-gating it.
2028 * Simply ungating isn't enough to reset the PHY enough to get
2029 * ports and lanes running.
2031 cmn->ops->disable(dev_priv, cmn);
2035 * intel_power_domains_init_hw - initialize hardware power domain state
2036 * @dev_priv: i915 device instance
2038 * This function initializes the hardware power domain state and enables all
2039 * power domains using intel_display_set_init_power().
2041 void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
2043 struct drm_device *dev = dev_priv->dev;
2044 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2046 power_domains->initializing = true;
2048 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
2049 skl_display_core_init(dev_priv, resume);
2050 } else if (IS_CHERRYVIEW(dev)) {
2051 mutex_lock(&power_domains->lock);
2052 chv_phy_control_init(dev_priv);
2053 mutex_unlock(&power_domains->lock);
2054 } else if (IS_VALLEYVIEW(dev)) {
2055 mutex_lock(&power_domains->lock);
2056 vlv_cmnlane_wa(dev_priv);
2057 mutex_unlock(&power_domains->lock);
2060 /* For now, we need the power well to be always enabled. */
2061 intel_display_set_init_power(dev_priv, true);
2062 /* Disable power support if the user asked so. */
2063 if (!i915.disable_power_well)
2064 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
2065 intel_power_domains_sync_hw(dev_priv);
2066 power_domains->initializing = false;
2070 * intel_power_domains_suspend - suspend power domain state
2071 * @dev_priv: i915 device instance
2073 * This function prepares the hardware power domain state before entering
2074 * system suspend. It must be paired with intel_power_domains_init_hw().
2076 void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
2078 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
2079 skl_display_core_uninit(dev_priv);
2082 * Even if power well support was disabled we still want to disable
2083 * power wells while we are system suspended.
2085 if (!i915.disable_power_well)
2086 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
2090 * intel_aux_display_runtime_get - grab an auxiliary power domain reference
2091 * @dev_priv: i915 device instance
2093 * This function grabs a power domain reference for the auxiliary power domain
2094 * (for access to the GMBUS and DP AUX blocks) and ensures that it and all its
2095 * parents are powered up. Therefore users should only grab a reference to the
2096 * innermost power domain they need.
2098 * Any power domain reference obtained by this function must have a symmetric
2099 * call to intel_aux_display_runtime_put() to release the reference again.
2101 void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv)
2103 intel_runtime_pm_get(dev_priv);
2107 * intel_aux_display_runtime_put - release an auxiliary power domain reference
2108 * @dev_priv: i915 device instance
2110 * This function drops the auxiliary power domain reference obtained by
2111 * intel_aux_display_runtime_get() and might power down the corresponding
2112 * hardware block right away if this is the last reference.
2114 void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv)
2116 intel_runtime_pm_put(dev_priv);
2120 * intel_runtime_pm_get - grab a runtime pm reference
2121 * @dev_priv: i915 device instance
2123 * This function grabs a device-level runtime pm reference (mostly used for GEM
2124 * code to ensure the GTT or GT is on) and ensures that it is powered up.
2126 * Any runtime pm reference obtained by this function must have a symmetric
2127 * call to intel_runtime_pm_put() to release the reference again.
2129 void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
2131 struct drm_device *dev = dev_priv->dev;
2132 struct device *device = &dev->pdev->dev;
2134 if (!HAS_RUNTIME_PM(dev))
2137 pm_runtime_get_sync(device);
2138 WARN(dev_priv->pm.suspended, "Device still suspended.\n");
2142 * intel_runtime_pm_get_noresume - grab a runtime pm reference
2143 * @dev_priv: i915 device instance
2145 * This function grabs a device-level runtime pm reference (mostly used for GEM
2146 * code to ensure the GTT or GT is on).
2148 * It will _not_ power up the device but instead only check that it's powered
2149 * on. Therefore it is only valid to call this functions from contexts where
2150 * the device is known to be powered up and where trying to power it up would
2151 * result in hilarity and deadlocks. That pretty much means only the system
2152 * suspend/resume code where this is used to grab runtime pm references for
2153 * delayed setup down in work items.
2155 * Any runtime pm reference obtained by this function must have a symmetric
2156 * call to intel_runtime_pm_put() to release the reference again.
2158 void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
2160 struct drm_device *dev = dev_priv->dev;
2161 struct device *device = &dev->pdev->dev;
2163 if (!HAS_RUNTIME_PM(dev))
2166 WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n");
2167 pm_runtime_get_noresume(device);
2171 * intel_runtime_pm_put - release a runtime pm reference
2172 * @dev_priv: i915 device instance
2174 * This function drops the device-level runtime pm reference obtained by
2175 * intel_runtime_pm_get() and might power down the corresponding
2176 * hardware block right away if this is the last reference.
2178 void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
2180 struct drm_device *dev = dev_priv->dev;
2181 struct device *device = &dev->pdev->dev;
2183 if (!HAS_RUNTIME_PM(dev))
2186 pm_runtime_mark_last_busy(device);
2187 pm_runtime_put_autosuspend(device);
2191 * intel_runtime_pm_enable - enable runtime pm
2192 * @dev_priv: i915 device instance
2194 * This function enables runtime pm at the end of the driver load sequence.
2196 * Note that this function does currently not enable runtime pm for the
2197 * subordinate display power domains. That is only done on the first modeset
2198 * using intel_display_set_init_power().
2200 void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
2202 struct drm_device *dev = dev_priv->dev;
2203 struct device *device = &dev->pdev->dev;
2205 if (!HAS_RUNTIME_PM(dev))
2209 * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
2212 if (!intel_enable_rc6(dev)) {
2213 DRM_INFO("RC6 disabled, disabling runtime PM support\n");
2217 pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */
2218 pm_runtime_mark_last_busy(device);
2219 pm_runtime_use_autosuspend(device);
2221 pm_runtime_put_autosuspend(device);