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 for_each_power_well(i, power_well, domain_mask, power_domains) \
54 i < (power_domains)->power_well_count && \
55 ((power_well) = &(power_domains)->power_wells[i]); \
57 for_each_if ((power_well)->domains & (domain_mask))
59 #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
60 for (i = (power_domains)->power_well_count - 1; \
61 i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
63 for_each_if ((power_well)->domains & (domain_mask))
65 bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
68 static struct i915_power_well *
69 lookup_power_well(struct drm_i915_private *dev_priv, int power_well_id);
72 intel_display_power_domain_str(enum intel_display_power_domain domain)
75 case POWER_DOMAIN_PIPE_A:
77 case POWER_DOMAIN_PIPE_B:
79 case POWER_DOMAIN_PIPE_C:
81 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
82 return "PIPE_A_PANEL_FITTER";
83 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
84 return "PIPE_B_PANEL_FITTER";
85 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
86 return "PIPE_C_PANEL_FITTER";
87 case POWER_DOMAIN_TRANSCODER_A:
88 return "TRANSCODER_A";
89 case POWER_DOMAIN_TRANSCODER_B:
90 return "TRANSCODER_B";
91 case POWER_DOMAIN_TRANSCODER_C:
92 return "TRANSCODER_C";
93 case POWER_DOMAIN_TRANSCODER_EDP:
94 return "TRANSCODER_EDP";
95 case POWER_DOMAIN_TRANSCODER_DSI_A:
96 return "TRANSCODER_DSI_A";
97 case POWER_DOMAIN_TRANSCODER_DSI_C:
98 return "TRANSCODER_DSI_C";
99 case POWER_DOMAIN_PORT_DDI_A_LANES:
100 return "PORT_DDI_A_LANES";
101 case POWER_DOMAIN_PORT_DDI_B_LANES:
102 return "PORT_DDI_B_LANES";
103 case POWER_DOMAIN_PORT_DDI_C_LANES:
104 return "PORT_DDI_C_LANES";
105 case POWER_DOMAIN_PORT_DDI_D_LANES:
106 return "PORT_DDI_D_LANES";
107 case POWER_DOMAIN_PORT_DDI_E_LANES:
108 return "PORT_DDI_E_LANES";
109 case POWER_DOMAIN_PORT_DSI:
111 case POWER_DOMAIN_PORT_CRT:
113 case POWER_DOMAIN_PORT_OTHER:
115 case POWER_DOMAIN_VGA:
117 case POWER_DOMAIN_AUDIO:
119 case POWER_DOMAIN_PLLS:
121 case POWER_DOMAIN_AUX_A:
123 case POWER_DOMAIN_AUX_B:
125 case POWER_DOMAIN_AUX_C:
127 case POWER_DOMAIN_AUX_D:
129 case POWER_DOMAIN_GMBUS:
131 case POWER_DOMAIN_INIT:
133 case POWER_DOMAIN_MODESET:
136 MISSING_CASE(domain);
141 static void intel_power_well_enable(struct drm_i915_private *dev_priv,
142 struct i915_power_well *power_well)
144 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
145 power_well->ops->enable(dev_priv, power_well);
146 power_well->hw_enabled = true;
149 static void intel_power_well_disable(struct drm_i915_private *dev_priv,
150 struct i915_power_well *power_well)
152 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
153 power_well->hw_enabled = false;
154 power_well->ops->disable(dev_priv, power_well);
157 static void intel_power_well_get(struct drm_i915_private *dev_priv,
158 struct i915_power_well *power_well)
160 if (!power_well->count++)
161 intel_power_well_enable(dev_priv, power_well);
164 static void intel_power_well_put(struct drm_i915_private *dev_priv,
165 struct i915_power_well *power_well)
167 WARN(!power_well->count, "Use count on power well %s is already zero",
170 if (!--power_well->count)
171 intel_power_well_disable(dev_priv, power_well);
175 * We should only use the power well if we explicitly asked the hardware to
176 * enable it, so check if it's enabled and also check if we've requested it to
179 static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
180 struct i915_power_well *power_well)
182 return I915_READ(HSW_PWR_WELL_DRIVER) ==
183 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
187 * __intel_display_power_is_enabled - unlocked check for a power domain
188 * @dev_priv: i915 device instance
189 * @domain: power domain to check
191 * This is the unlocked version of intel_display_power_is_enabled() and should
192 * only be used from error capture and recovery code where deadlocks are
196 * True when the power domain is enabled, false otherwise.
198 bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
199 enum intel_display_power_domain domain)
201 struct i915_power_domains *power_domains;
202 struct i915_power_well *power_well;
206 if (dev_priv->pm.suspended)
209 power_domains = &dev_priv->power_domains;
213 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
214 if (power_well->always_on)
217 if (!power_well->hw_enabled) {
227 * intel_display_power_is_enabled - check for a power domain
228 * @dev_priv: i915 device instance
229 * @domain: power domain to check
231 * This function can be used to check the hw power domain state. It is mostly
232 * used in hardware state readout functions. Everywhere else code should rely
233 * upon explicit power domain reference counting to ensure that the hardware
234 * block is powered up before accessing it.
236 * Callers must hold the relevant modesetting locks to ensure that concurrent
237 * threads can't disable the power well while the caller tries to read a few
241 * True when the power domain is enabled, false otherwise.
243 bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
244 enum intel_display_power_domain domain)
246 struct i915_power_domains *power_domains;
249 power_domains = &dev_priv->power_domains;
251 mutex_lock(&power_domains->lock);
252 ret = __intel_display_power_is_enabled(dev_priv, domain);
253 mutex_unlock(&power_domains->lock);
259 * intel_display_set_init_power - set the initial power domain state
260 * @dev_priv: i915 device instance
261 * @enable: whether to enable or disable the initial power domain state
263 * For simplicity our driver load/unload and system suspend/resume code assumes
264 * that all power domains are always enabled. This functions controls the state
265 * of this little hack. While the initial power domain state is enabled runtime
266 * pm is effectively disabled.
268 void intel_display_set_init_power(struct drm_i915_private *dev_priv,
271 if (dev_priv->power_domains.init_power_on == enable)
275 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
277 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
279 dev_priv->power_domains.init_power_on = enable;
283 * Starting with Haswell, we have a "Power Down Well" that can be turned off
284 * when not needed anymore. We have 4 registers that can request the power well
285 * to be enabled, and it will only be disabled if none of the registers is
286 * requesting it to be enabled.
288 static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
290 struct pci_dev *pdev = dev_priv->drm.pdev;
291 struct drm_device *dev = &dev_priv->drm;
294 * After we re-enable the power well, if we touch VGA register 0x3d5
295 * we'll get unclaimed register interrupts. This stops after we write
296 * anything to the VGA MSR register. The vgacon module uses this
297 * register all the time, so if we unbind our driver and, as a
298 * consequence, bind vgacon, we'll get stuck in an infinite loop at
299 * console_unlock(). So make here we touch the VGA MSR register, making
300 * sure vgacon can keep working normally without triggering interrupts
301 * and error messages.
303 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
304 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
305 vga_put(pdev, VGA_RSRC_LEGACY_IO);
307 if (IS_BROADWELL(dev))
308 gen8_irq_power_well_post_enable(dev_priv,
309 1 << PIPE_C | 1 << PIPE_B);
312 static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv)
314 if (IS_BROADWELL(dev_priv))
315 gen8_irq_power_well_pre_disable(dev_priv,
316 1 << PIPE_C | 1 << PIPE_B);
319 static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
320 struct i915_power_well *power_well)
322 struct pci_dev *pdev = dev_priv->drm.pdev;
325 * After we re-enable the power well, if we touch VGA register 0x3d5
326 * we'll get unclaimed register interrupts. This stops after we write
327 * anything to the VGA MSR register. The vgacon module uses this
328 * register all the time, so if we unbind our driver and, as a
329 * consequence, bind vgacon, we'll get stuck in an infinite loop at
330 * console_unlock(). So make here we touch the VGA MSR register, making
331 * sure vgacon can keep working normally without triggering interrupts
332 * and error messages.
334 if (power_well->data == SKL_DISP_PW_2) {
335 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
336 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
337 vga_put(pdev, VGA_RSRC_LEGACY_IO);
339 gen8_irq_power_well_post_enable(dev_priv,
340 1 << PIPE_C | 1 << PIPE_B);
344 static void skl_power_well_pre_disable(struct drm_i915_private *dev_priv,
345 struct i915_power_well *power_well)
347 if (power_well->data == SKL_DISP_PW_2)
348 gen8_irq_power_well_pre_disable(dev_priv,
349 1 << PIPE_C | 1 << PIPE_B);
352 static void hsw_set_power_well(struct drm_i915_private *dev_priv,
353 struct i915_power_well *power_well, bool enable)
355 bool is_enabled, enable_requested;
358 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
359 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
360 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
363 if (!enable_requested)
364 I915_WRITE(HSW_PWR_WELL_DRIVER,
365 HSW_PWR_WELL_ENABLE_REQUEST);
368 DRM_DEBUG_KMS("Enabling power well\n");
369 if (intel_wait_for_register(dev_priv,
371 HSW_PWR_WELL_STATE_ENABLED,
372 HSW_PWR_WELL_STATE_ENABLED,
374 DRM_ERROR("Timeout enabling power well\n");
375 hsw_power_well_post_enable(dev_priv);
379 if (enable_requested) {
380 hsw_power_well_pre_disable(dev_priv);
381 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
382 POSTING_READ(HSW_PWR_WELL_DRIVER);
383 DRM_DEBUG_KMS("Requesting to disable the power well\n");
388 #define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
389 BIT(POWER_DOMAIN_TRANSCODER_A) | \
390 BIT(POWER_DOMAIN_PIPE_B) | \
391 BIT(POWER_DOMAIN_TRANSCODER_B) | \
392 BIT(POWER_DOMAIN_PIPE_C) | \
393 BIT(POWER_DOMAIN_TRANSCODER_C) | \
394 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
395 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
396 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
397 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
398 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
399 BIT(POWER_DOMAIN_PORT_DDI_E_LANES) | \
400 BIT(POWER_DOMAIN_AUX_B) | \
401 BIT(POWER_DOMAIN_AUX_C) | \
402 BIT(POWER_DOMAIN_AUX_D) | \
403 BIT(POWER_DOMAIN_AUDIO) | \
404 BIT(POWER_DOMAIN_VGA) | \
405 BIT(POWER_DOMAIN_INIT))
406 #define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
407 BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \
408 BIT(POWER_DOMAIN_PORT_DDI_E_LANES) | \
409 BIT(POWER_DOMAIN_INIT))
410 #define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
411 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
412 BIT(POWER_DOMAIN_INIT))
413 #define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
414 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
415 BIT(POWER_DOMAIN_INIT))
416 #define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
417 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
418 BIT(POWER_DOMAIN_INIT))
419 #define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
420 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
421 BIT(POWER_DOMAIN_MODESET) | \
422 BIT(POWER_DOMAIN_AUX_A) | \
423 BIT(POWER_DOMAIN_INIT))
425 #define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
426 BIT(POWER_DOMAIN_TRANSCODER_A) | \
427 BIT(POWER_DOMAIN_PIPE_B) | \
428 BIT(POWER_DOMAIN_TRANSCODER_B) | \
429 BIT(POWER_DOMAIN_PIPE_C) | \
430 BIT(POWER_DOMAIN_TRANSCODER_C) | \
431 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
432 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
433 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
434 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
435 BIT(POWER_DOMAIN_AUX_B) | \
436 BIT(POWER_DOMAIN_AUX_C) | \
437 BIT(POWER_DOMAIN_AUDIO) | \
438 BIT(POWER_DOMAIN_VGA) | \
439 BIT(POWER_DOMAIN_GMBUS) | \
440 BIT(POWER_DOMAIN_INIT))
441 #define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
442 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
443 BIT(POWER_DOMAIN_MODESET) | \
444 BIT(POWER_DOMAIN_AUX_A) | \
445 BIT(POWER_DOMAIN_INIT))
446 #define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
447 BIT(POWER_DOMAIN_PORT_DDI_A_LANES) | \
448 BIT(POWER_DOMAIN_AUX_A) | \
449 BIT(POWER_DOMAIN_INIT))
450 #define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
451 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
452 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
453 BIT(POWER_DOMAIN_AUX_B) | \
454 BIT(POWER_DOMAIN_AUX_C) | \
455 BIT(POWER_DOMAIN_INIT))
457 static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
459 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
460 "DC9 already programmed to be enabled.\n");
461 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
462 "DC5 still not disabled to enable DC9.\n");
463 WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
464 WARN_ONCE(intel_irqs_enabled(dev_priv),
465 "Interrupts not disabled yet.\n");
468 * TODO: check for the following to verify the conditions to enter DC9
469 * state are satisfied:
470 * 1] Check relevant display engine registers to verify if mode set
471 * disable sequence was followed.
472 * 2] Check if display uninitialize sequence is initialized.
476 static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
478 WARN_ONCE(intel_irqs_enabled(dev_priv),
479 "Interrupts not disabled yet.\n");
480 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
481 "DC5 still not disabled.\n");
484 * TODO: check for the following to verify DC9 state was indeed
485 * entered before programming to disable it:
486 * 1] Check relevant display engine registers to verify if mode
487 * set disable sequence was followed.
488 * 2] Check if display uninitialize sequence is initialized.
492 static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
499 I915_WRITE(DC_STATE_EN, state);
501 /* It has been observed that disabling the dc6 state sometimes
502 * doesn't stick and dmc keeps returning old value. Make sure
503 * the write really sticks enough times and also force rewrite until
504 * we are confident that state is exactly what we want.
507 v = I915_READ(DC_STATE_EN);
510 I915_WRITE(DC_STATE_EN, state);
513 } else if (rereads++ > 5) {
517 } while (rewrites < 100);
520 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
523 /* Most of the times we need one retry, avoid spam */
525 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
529 static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
533 mask = DC_STATE_EN_UPTO_DC5;
534 if (IS_BROXTON(dev_priv))
535 mask |= DC_STATE_EN_DC9;
537 mask |= DC_STATE_EN_UPTO_DC6;
542 void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
546 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
548 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
549 dev_priv->csr.dc_state, val);
550 dev_priv->csr.dc_state = val;
553 static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
558 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
559 state &= dev_priv->csr.allowed_dc_mask;
561 val = I915_READ(DC_STATE_EN);
562 mask = gen9_dc_mask(dev_priv);
563 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
566 /* Check if DMC is ignoring our DC state requests */
567 if ((val & mask) != dev_priv->csr.dc_state)
568 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
569 dev_priv->csr.dc_state, val & mask);
574 gen9_write_dc_state(dev_priv, val);
576 dev_priv->csr.dc_state = val & mask;
579 void bxt_enable_dc9(struct drm_i915_private *dev_priv)
581 assert_can_enable_dc9(dev_priv);
583 DRM_DEBUG_KMS("Enabling DC9\n");
585 intel_power_sequencer_reset(dev_priv);
586 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
589 void bxt_disable_dc9(struct drm_i915_private *dev_priv)
591 assert_can_disable_dc9(dev_priv);
593 DRM_DEBUG_KMS("Disabling DC9\n");
595 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
597 intel_pps_unlock_regs_wa(dev_priv);
600 static void assert_csr_loaded(struct drm_i915_private *dev_priv)
602 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
603 "CSR program storage start is NULL\n");
604 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
605 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
608 static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
610 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
613 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
615 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
616 "DC5 already programmed to be enabled.\n");
617 assert_rpm_wakelock_held(dev_priv);
619 assert_csr_loaded(dev_priv);
622 void gen9_enable_dc5(struct drm_i915_private *dev_priv)
624 assert_can_enable_dc5(dev_priv);
626 DRM_DEBUG_KMS("Enabling DC5\n");
628 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
631 static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
633 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
634 "Backlight is not disabled.\n");
635 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
636 "DC6 already programmed to be enabled.\n");
638 assert_csr_loaded(dev_priv);
641 void skl_enable_dc6(struct drm_i915_private *dev_priv)
643 assert_can_enable_dc6(dev_priv);
645 DRM_DEBUG_KMS("Enabling DC6\n");
647 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
651 void skl_disable_dc6(struct drm_i915_private *dev_priv)
653 DRM_DEBUG_KMS("Disabling DC6\n");
655 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
659 gen9_sanitize_power_well_requests(struct drm_i915_private *dev_priv,
660 struct i915_power_well *power_well)
662 enum skl_disp_power_wells power_well_id = power_well->data;
666 mask = SKL_POWER_WELL_REQ(power_well_id);
668 val = I915_READ(HSW_PWR_WELL_KVMR);
669 if (WARN_ONCE(val & mask, "Clearing unexpected KVMR request for %s\n",
671 I915_WRITE(HSW_PWR_WELL_KVMR, val & ~mask);
673 val = I915_READ(HSW_PWR_WELL_BIOS);
674 val |= I915_READ(HSW_PWR_WELL_DEBUG);
680 * DMC is known to force on the request bits for power well 1 on SKL
681 * and BXT and the misc IO power well on SKL but we don't expect any
682 * other request bits to be set, so WARN for those.
684 if (power_well_id == SKL_DISP_PW_1 ||
685 ((IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) &&
686 power_well_id == SKL_DISP_PW_MISC_IO))
687 DRM_DEBUG_DRIVER("Clearing auxiliary requests for %s forced on "
688 "by DMC\n", power_well->name);
690 WARN_ONCE(1, "Clearing unexpected auxiliary requests for %s\n",
693 I915_WRITE(HSW_PWR_WELL_BIOS, val & ~mask);
694 I915_WRITE(HSW_PWR_WELL_DEBUG, val & ~mask);
697 static void skl_set_power_well(struct drm_i915_private *dev_priv,
698 struct i915_power_well *power_well, bool enable)
700 uint32_t tmp, fuse_status;
701 uint32_t req_mask, state_mask;
702 bool is_enabled, enable_requested, check_fuse_status = false;
704 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
705 fuse_status = I915_READ(SKL_FUSE_STATUS);
707 switch (power_well->data) {
709 if (intel_wait_for_register(dev_priv,
711 SKL_FUSE_PG0_DIST_STATUS,
712 SKL_FUSE_PG0_DIST_STATUS,
714 DRM_ERROR("PG0 not enabled\n");
719 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
720 DRM_ERROR("PG1 in disabled state\n");
724 case SKL_DISP_PW_DDI_A_E:
725 case SKL_DISP_PW_DDI_B:
726 case SKL_DISP_PW_DDI_C:
727 case SKL_DISP_PW_DDI_D:
728 case SKL_DISP_PW_MISC_IO:
731 WARN(1, "Unknown power well %lu\n", power_well->data);
735 req_mask = SKL_POWER_WELL_REQ(power_well->data);
736 enable_requested = tmp & req_mask;
737 state_mask = SKL_POWER_WELL_STATE(power_well->data);
738 is_enabled = tmp & state_mask;
740 if (!enable && enable_requested)
741 skl_power_well_pre_disable(dev_priv, power_well);
744 if (!enable_requested) {
745 WARN((tmp & state_mask) &&
746 !I915_READ(HSW_PWR_WELL_BIOS),
747 "Invalid for power well status to be enabled, unless done by the BIOS, \
748 when request is to disable!\n");
749 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
753 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
754 check_fuse_status = true;
757 if (enable_requested) {
758 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
759 POSTING_READ(HSW_PWR_WELL_DRIVER);
760 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
763 if (IS_GEN9(dev_priv))
764 gen9_sanitize_power_well_requests(dev_priv, power_well);
767 if (wait_for(!!(I915_READ(HSW_PWR_WELL_DRIVER) & state_mask) == enable,
769 DRM_ERROR("%s %s timeout\n",
770 power_well->name, enable ? "enable" : "disable");
772 if (check_fuse_status) {
773 if (power_well->data == SKL_DISP_PW_1) {
774 if (intel_wait_for_register(dev_priv,
776 SKL_FUSE_PG1_DIST_STATUS,
777 SKL_FUSE_PG1_DIST_STATUS,
779 DRM_ERROR("PG1 distributing status timeout\n");
780 } else if (power_well->data == SKL_DISP_PW_2) {
781 if (intel_wait_for_register(dev_priv,
783 SKL_FUSE_PG2_DIST_STATUS,
784 SKL_FUSE_PG2_DIST_STATUS,
786 DRM_ERROR("PG2 distributing status timeout\n");
790 if (enable && !is_enabled)
791 skl_power_well_post_enable(dev_priv, power_well);
794 static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
795 struct i915_power_well *power_well)
797 hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
800 * We're taking over the BIOS, so clear any requests made by it since
801 * the driver is in charge now.
803 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
804 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
807 static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
808 struct i915_power_well *power_well)
810 hsw_set_power_well(dev_priv, power_well, true);
813 static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
814 struct i915_power_well *power_well)
816 hsw_set_power_well(dev_priv, power_well, false);
819 static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
820 struct i915_power_well *power_well)
822 uint32_t mask = SKL_POWER_WELL_REQ(power_well->data) |
823 SKL_POWER_WELL_STATE(power_well->data);
825 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
828 static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
829 struct i915_power_well *power_well)
831 skl_set_power_well(dev_priv, power_well, power_well->count > 0);
833 /* Clear any request made by BIOS as driver is taking over */
834 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
837 static void skl_power_well_enable(struct drm_i915_private *dev_priv,
838 struct i915_power_well *power_well)
840 skl_set_power_well(dev_priv, power_well, true);
843 static void skl_power_well_disable(struct drm_i915_private *dev_priv,
844 struct i915_power_well *power_well)
846 skl_set_power_well(dev_priv, power_well, false);
849 static enum dpio_phy bxt_power_well_to_phy(struct i915_power_well *power_well)
851 enum skl_disp_power_wells power_well_id = power_well->data;
853 return power_well_id == BXT_DPIO_CMN_A ? DPIO_PHY1 : DPIO_PHY0;
856 static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
857 struct i915_power_well *power_well)
859 enum skl_disp_power_wells power_well_id = power_well->data;
860 struct i915_power_well *cmn_a_well = NULL;
862 if (power_well_id == BXT_DPIO_CMN_BC) {
864 * We need to copy the GRC calibration value from the eDP PHY,
865 * so make sure it's powered up.
867 cmn_a_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
868 intel_power_well_get(dev_priv, cmn_a_well);
871 bxt_ddi_phy_init(dev_priv, bxt_power_well_to_phy(power_well));
874 intel_power_well_put(dev_priv, cmn_a_well);
877 static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
878 struct i915_power_well *power_well)
880 bxt_ddi_phy_uninit(dev_priv, bxt_power_well_to_phy(power_well));
883 static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
884 struct i915_power_well *power_well)
886 return bxt_ddi_phy_is_enabled(dev_priv,
887 bxt_power_well_to_phy(power_well));
890 static void bxt_dpio_cmn_power_well_sync_hw(struct drm_i915_private *dev_priv,
891 struct i915_power_well *power_well)
893 if (power_well->count > 0)
894 bxt_dpio_cmn_power_well_enable(dev_priv, power_well);
896 bxt_dpio_cmn_power_well_disable(dev_priv, power_well);
900 static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
902 struct i915_power_well *power_well;
904 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
905 if (power_well->count > 0)
906 bxt_ddi_phy_verify_state(dev_priv,
907 bxt_power_well_to_phy(power_well));
909 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
910 if (power_well->count > 0)
911 bxt_ddi_phy_verify_state(dev_priv,
912 bxt_power_well_to_phy(power_well));
915 static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
916 struct i915_power_well *power_well)
918 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
921 static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
923 u32 tmp = I915_READ(DBUF_CTL);
925 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
926 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
927 "Unexpected DBuf power power state (0x%08x)\n", tmp);
930 static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
931 struct i915_power_well *power_well)
933 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
935 WARN_ON(dev_priv->cdclk_freq !=
936 dev_priv->display.get_display_clock_speed(&dev_priv->drm));
938 gen9_assert_dbuf_enabled(dev_priv);
940 if (IS_BROXTON(dev_priv))
941 bxt_verify_ddi_phy_power_wells(dev_priv);
944 static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
945 struct i915_power_well *power_well)
947 if (!dev_priv->csr.dmc_payload)
950 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
951 skl_enable_dc6(dev_priv);
952 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
953 gen9_enable_dc5(dev_priv);
956 static void gen9_dc_off_power_well_sync_hw(struct drm_i915_private *dev_priv,
957 struct i915_power_well *power_well)
959 if (power_well->count > 0)
960 gen9_dc_off_power_well_enable(dev_priv, power_well);
962 gen9_dc_off_power_well_disable(dev_priv, power_well);
965 static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
966 struct i915_power_well *power_well)
970 static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
971 struct i915_power_well *power_well)
976 static void vlv_set_power_well(struct drm_i915_private *dev_priv,
977 struct i915_power_well *power_well, bool enable)
979 enum punit_power_well power_well_id = power_well->data;
984 mask = PUNIT_PWRGT_MASK(power_well_id);
985 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
986 PUNIT_PWRGT_PWR_GATE(power_well_id);
988 mutex_lock(&dev_priv->rps.hw_lock);
991 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
996 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
999 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
1001 if (wait_for(COND, 100))
1002 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
1004 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
1009 mutex_unlock(&dev_priv->rps.hw_lock);
1012 static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
1013 struct i915_power_well *power_well)
1015 vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
1018 static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
1019 struct i915_power_well *power_well)
1021 vlv_set_power_well(dev_priv, power_well, true);
1024 static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
1025 struct i915_power_well *power_well)
1027 vlv_set_power_well(dev_priv, power_well, false);
1030 static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
1031 struct i915_power_well *power_well)
1033 int power_well_id = power_well->data;
1034 bool enabled = false;
1039 mask = PUNIT_PWRGT_MASK(power_well_id);
1040 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
1042 mutex_lock(&dev_priv->rps.hw_lock);
1044 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
1046 * We only ever set the power-on and power-gate states, anything
1047 * else is unexpected.
1049 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
1050 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
1055 * A transient state at this point would mean some unexpected party
1056 * is poking at the power controls too.
1058 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
1059 WARN_ON(ctrl != state);
1061 mutex_unlock(&dev_priv->rps.hw_lock);
1066 static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
1068 I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE);
1071 * Disable trickle feed and enable pnd deadline calculation
1073 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
1074 I915_WRITE(CBR1_VLV, 0);
1076 WARN_ON(dev_priv->rawclk_freq == 0);
1078 I915_WRITE(RAWCLK_FREQ_VLV,
1079 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
1082 static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
1084 struct intel_encoder *encoder;
1088 * Enable the CRI clock source so we can get at the
1089 * display and the reference clock for VGA
1090 * hotplug / manual detection. Supposedly DSI also
1091 * needs the ref clock up and running.
1093 * CHV DPLL B/C have some issues if VGA mode is enabled.
1095 for_each_pipe(&dev_priv->drm, pipe) {
1096 u32 val = I915_READ(DPLL(pipe));
1098 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1100 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1102 I915_WRITE(DPLL(pipe), val);
1105 vlv_init_display_clock_gating(dev_priv);
1107 spin_lock_irq(&dev_priv->irq_lock);
1108 valleyview_enable_display_irqs(dev_priv);
1109 spin_unlock_irq(&dev_priv->irq_lock);
1112 * During driver initialization/resume we can avoid restoring the
1113 * part of the HW/SW state that will be inited anyway explicitly.
1115 if (dev_priv->power_domains.initializing)
1118 intel_hpd_init(dev_priv);
1120 /* Re-enable the ADPA, if we have one */
1121 for_each_intel_encoder(&dev_priv->drm, encoder) {
1122 if (encoder->type == INTEL_OUTPUT_ANALOG)
1123 intel_crt_reset(&encoder->base);
1126 i915_redisable_vga_power_on(&dev_priv->drm);
1128 intel_pps_unlock_regs_wa(dev_priv);
1131 static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1133 spin_lock_irq(&dev_priv->irq_lock);
1134 valleyview_disable_display_irqs(dev_priv);
1135 spin_unlock_irq(&dev_priv->irq_lock);
1137 /* make sure we're done processing display irqs */
1138 synchronize_irq(dev_priv->drm.irq);
1140 intel_power_sequencer_reset(dev_priv);
1142 intel_hpd_poll_init(dev_priv);
1145 static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1146 struct i915_power_well *power_well)
1148 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
1150 vlv_set_power_well(dev_priv, power_well, true);
1152 vlv_display_power_well_init(dev_priv);
1155 static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1156 struct i915_power_well *power_well)
1158 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
1160 vlv_display_power_well_deinit(dev_priv);
1162 vlv_set_power_well(dev_priv, power_well, false);
1165 static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1166 struct i915_power_well *power_well)
1168 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
1170 /* since ref/cri clock was enabled */
1171 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1173 vlv_set_power_well(dev_priv, power_well, true);
1176 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1177 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1178 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1179 * b. The other bits such as sfr settings / modesel may all
1182 * This should only be done on init and resume from S3 with
1183 * both PLLs disabled, or we risk losing DPIO and PLL
1186 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1189 static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1190 struct i915_power_well *power_well)
1194 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
1196 for_each_pipe(dev_priv, pipe)
1197 assert_pll_disabled(dev_priv, pipe);
1199 /* Assert common reset */
1200 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1202 vlv_set_power_well(dev_priv, power_well, false);
1205 #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
1207 static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
1210 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1213 for (i = 0; i < power_domains->power_well_count; i++) {
1214 struct i915_power_well *power_well;
1216 power_well = &power_domains->power_wells[i];
1217 if (power_well->data == power_well_id)
1224 #define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1226 static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1228 struct i915_power_well *cmn_bc =
1229 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1230 struct i915_power_well *cmn_d =
1231 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1232 u32 phy_control = dev_priv->chv_phy_control;
1234 u32 phy_status_mask = 0xffffffff;
1237 * The BIOS can leave the PHY is some weird state
1238 * where it doesn't fully power down some parts.
1239 * Disable the asserts until the PHY has been fully
1240 * reset (ie. the power well has been disabled at
1243 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1244 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1245 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1246 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1247 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1248 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1249 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1251 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1252 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1253 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1254 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1256 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1257 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1259 /* this assumes override is only used to enable lanes */
1260 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1261 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1263 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1264 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1266 /* CL1 is on whenever anything is on in either channel */
1267 if (BITS_SET(phy_control,
1268 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1269 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1270 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1273 * The DPLLB check accounts for the pipe B + port A usage
1274 * with CL2 powered up but all the lanes in the second channel
1277 if (BITS_SET(phy_control,
1278 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1279 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1280 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1282 if (BITS_SET(phy_control,
1283 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1284 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1285 if (BITS_SET(phy_control,
1286 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1287 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1289 if (BITS_SET(phy_control,
1290 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1291 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1292 if (BITS_SET(phy_control,
1293 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1294 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1297 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1298 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1300 /* this assumes override is only used to enable lanes */
1301 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1302 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1304 if (BITS_SET(phy_control,
1305 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1306 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1308 if (BITS_SET(phy_control,
1309 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1310 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1311 if (BITS_SET(phy_control,
1312 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1313 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1316 phy_status &= phy_status_mask;
1319 * The PHY may be busy with some initial calibration and whatnot,
1320 * so the power state can take a while to actually change.
1322 if (intel_wait_for_register(dev_priv,
1327 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1328 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1329 phy_status, dev_priv->chv_phy_control);
1334 static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1335 struct i915_power_well *power_well)
1341 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1342 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
1344 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1352 /* since ref/cri clock was enabled */
1353 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1354 vlv_set_power_well(dev_priv, power_well, true);
1356 /* Poll for phypwrgood signal */
1357 if (intel_wait_for_register(dev_priv,
1362 DRM_ERROR("Display PHY %d is not power up\n", phy);
1364 mutex_lock(&dev_priv->sb_lock);
1366 /* Enable dynamic power down */
1367 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
1368 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1369 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
1370 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1372 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1373 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1374 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1375 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
1378 * Force the non-existing CL2 off. BXT does this
1379 * too, so maybe it saves some power even though
1380 * CL2 doesn't exist?
1382 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1383 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1384 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
1387 mutex_unlock(&dev_priv->sb_lock);
1389 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1390 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1392 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1393 phy, dev_priv->chv_phy_control);
1395 assert_chv_phy_status(dev_priv);
1398 static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1399 struct i915_power_well *power_well)
1403 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1404 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
1406 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
1408 assert_pll_disabled(dev_priv, PIPE_A);
1409 assert_pll_disabled(dev_priv, PIPE_B);
1412 assert_pll_disabled(dev_priv, PIPE_C);
1415 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1416 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1418 vlv_set_power_well(dev_priv, power_well, false);
1420 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1421 phy, dev_priv->chv_phy_control);
1423 /* PHY is fully reset now, so we can enable the PHY state asserts */
1424 dev_priv->chv_phy_assert[phy] = true;
1426 assert_chv_phy_status(dev_priv);
1429 static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1430 enum dpio_channel ch, bool override, unsigned int mask)
1432 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1433 u32 reg, val, expected, actual;
1436 * The BIOS can leave the PHY is some weird state
1437 * where it doesn't fully power down some parts.
1438 * Disable the asserts until the PHY has been fully
1439 * reset (ie. the power well has been disabled at
1442 if (!dev_priv->chv_phy_assert[phy])
1446 reg = _CHV_CMN_DW0_CH0;
1448 reg = _CHV_CMN_DW6_CH1;
1450 mutex_lock(&dev_priv->sb_lock);
1451 val = vlv_dpio_read(dev_priv, pipe, reg);
1452 mutex_unlock(&dev_priv->sb_lock);
1455 * This assumes !override is only used when the port is disabled.
1456 * All lanes should power down even without the override when
1457 * the port is disabled.
1459 if (!override || mask == 0xf) {
1460 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1462 * If CH1 common lane is not active anymore
1463 * (eg. for pipe B DPLL) the entire channel will
1464 * shut down, which causes the common lane registers
1465 * to read as 0. That means we can't actually check
1466 * the lane power down status bits, but as the entire
1467 * register reads as 0 it's a good indication that the
1468 * channel is indeed entirely powered down.
1470 if (ch == DPIO_CH1 && val == 0)
1472 } else if (mask != 0x0) {
1473 expected = DPIO_ANYDL_POWERDOWN;
1479 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1481 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1482 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1484 WARN(actual != expected,
1485 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1486 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1487 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1491 bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1492 enum dpio_channel ch, bool override)
1494 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1497 mutex_lock(&power_domains->lock);
1499 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1501 if (override == was_override)
1505 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1507 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1509 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1511 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1512 phy, ch, dev_priv->chv_phy_control);
1514 assert_chv_phy_status(dev_priv);
1517 mutex_unlock(&power_domains->lock);
1519 return was_override;
1522 void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1523 bool override, unsigned int mask)
1525 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1526 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1527 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1528 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1530 mutex_lock(&power_domains->lock);
1532 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1533 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1536 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1538 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1540 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1542 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1543 phy, ch, mask, dev_priv->chv_phy_control);
1545 assert_chv_phy_status(dev_priv);
1547 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1549 mutex_unlock(&power_domains->lock);
1552 static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1553 struct i915_power_well *power_well)
1555 enum pipe pipe = power_well->data;
1559 mutex_lock(&dev_priv->rps.hw_lock);
1561 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1563 * We only ever set the power-on and power-gate states, anything
1564 * else is unexpected.
1566 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1567 enabled = state == DP_SSS_PWR_ON(pipe);
1570 * A transient state at this point would mean some unexpected party
1571 * is poking at the power controls too.
1573 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1574 WARN_ON(ctrl << 16 != state);
1576 mutex_unlock(&dev_priv->rps.hw_lock);
1581 static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1582 struct i915_power_well *power_well,
1585 enum pipe pipe = power_well->data;
1589 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1591 mutex_lock(&dev_priv->rps.hw_lock);
1594 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1599 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1600 ctrl &= ~DP_SSC_MASK(pipe);
1601 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1602 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1604 if (wait_for(COND, 100))
1605 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
1607 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1612 mutex_unlock(&dev_priv->rps.hw_lock);
1615 static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
1616 struct i915_power_well *power_well)
1618 WARN_ON_ONCE(power_well->data != PIPE_A);
1620 chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
1623 static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1624 struct i915_power_well *power_well)
1626 WARN_ON_ONCE(power_well->data != PIPE_A);
1628 chv_set_pipe_power_well(dev_priv, power_well, true);
1630 vlv_display_power_well_init(dev_priv);
1633 static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1634 struct i915_power_well *power_well)
1636 WARN_ON_ONCE(power_well->data != PIPE_A);
1638 vlv_display_power_well_deinit(dev_priv);
1640 chv_set_pipe_power_well(dev_priv, power_well, false);
1644 __intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1645 enum intel_display_power_domain domain)
1647 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1648 struct i915_power_well *power_well;
1651 for_each_power_well(i, power_well, BIT(domain), power_domains)
1652 intel_power_well_get(dev_priv, power_well);
1654 power_domains->domain_use_count[domain]++;
1658 * intel_display_power_get - grab a power domain reference
1659 * @dev_priv: i915 device instance
1660 * @domain: power domain to reference
1662 * This function grabs a power domain reference for @domain and ensures that the
1663 * power domain and all its parents are powered up. Therefore users should only
1664 * grab a reference to the innermost power domain they need.
1666 * Any power domain reference obtained by this function must have a symmetric
1667 * call to intel_display_power_put() to release the reference again.
1669 void intel_display_power_get(struct drm_i915_private *dev_priv,
1670 enum intel_display_power_domain domain)
1672 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1674 intel_runtime_pm_get(dev_priv);
1676 mutex_lock(&power_domains->lock);
1678 __intel_display_power_get_domain(dev_priv, domain);
1680 mutex_unlock(&power_domains->lock);
1684 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1685 * @dev_priv: i915 device instance
1686 * @domain: power domain to reference
1688 * This function grabs a power domain reference for @domain and ensures that the
1689 * power domain and all its parents are powered up. Therefore users should only
1690 * grab a reference to the innermost power domain they need.
1692 * Any power domain reference obtained by this function must have a symmetric
1693 * call to intel_display_power_put() to release the reference again.
1695 bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1696 enum intel_display_power_domain domain)
1698 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1701 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1704 mutex_lock(&power_domains->lock);
1706 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1707 __intel_display_power_get_domain(dev_priv, domain);
1713 mutex_unlock(&power_domains->lock);
1716 intel_runtime_pm_put(dev_priv);
1722 * intel_display_power_put - release a power domain reference
1723 * @dev_priv: i915 device instance
1724 * @domain: power domain to reference
1726 * This function drops the power domain reference obtained by
1727 * intel_display_power_get() and might power down the corresponding hardware
1728 * block right away if this is the last reference.
1730 void intel_display_power_put(struct drm_i915_private *dev_priv,
1731 enum intel_display_power_domain domain)
1733 struct i915_power_domains *power_domains;
1734 struct i915_power_well *power_well;
1737 power_domains = &dev_priv->power_domains;
1739 mutex_lock(&power_domains->lock);
1741 WARN(!power_domains->domain_use_count[domain],
1742 "Use count on domain %s is already zero\n",
1743 intel_display_power_domain_str(domain));
1744 power_domains->domain_use_count[domain]--;
1746 for_each_power_well_rev(i, power_well, BIT(domain), power_domains)
1747 intel_power_well_put(dev_priv, power_well);
1749 mutex_unlock(&power_domains->lock);
1751 intel_runtime_pm_put(dev_priv);
1754 #define HSW_DISPLAY_POWER_DOMAINS ( \
1755 BIT(POWER_DOMAIN_PIPE_B) | \
1756 BIT(POWER_DOMAIN_PIPE_C) | \
1757 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1758 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1759 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1760 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1761 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1762 BIT(POWER_DOMAIN_TRANSCODER_C) | \
1763 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1764 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1765 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1766 BIT(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1767 BIT(POWER_DOMAIN_VGA) | \
1768 BIT(POWER_DOMAIN_AUDIO) | \
1769 BIT(POWER_DOMAIN_INIT))
1771 #define BDW_DISPLAY_POWER_DOMAINS ( \
1772 BIT(POWER_DOMAIN_PIPE_B) | \
1773 BIT(POWER_DOMAIN_PIPE_C) | \
1774 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1775 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1776 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1777 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1778 BIT(POWER_DOMAIN_TRANSCODER_C) | \
1779 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1780 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1781 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1782 BIT(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1783 BIT(POWER_DOMAIN_VGA) | \
1784 BIT(POWER_DOMAIN_AUDIO) | \
1785 BIT(POWER_DOMAIN_INIT))
1787 #define VLV_DISPLAY_POWER_DOMAINS ( \
1788 BIT(POWER_DOMAIN_PIPE_A) | \
1789 BIT(POWER_DOMAIN_PIPE_B) | \
1790 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1791 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1792 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1793 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1794 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1795 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1796 BIT(POWER_DOMAIN_PORT_DSI) | \
1797 BIT(POWER_DOMAIN_PORT_CRT) | \
1798 BIT(POWER_DOMAIN_VGA) | \
1799 BIT(POWER_DOMAIN_AUDIO) | \
1800 BIT(POWER_DOMAIN_AUX_B) | \
1801 BIT(POWER_DOMAIN_AUX_C) | \
1802 BIT(POWER_DOMAIN_GMBUS) | \
1803 BIT(POWER_DOMAIN_INIT))
1805 #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
1806 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1807 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1808 BIT(POWER_DOMAIN_PORT_CRT) | \
1809 BIT(POWER_DOMAIN_AUX_B) | \
1810 BIT(POWER_DOMAIN_AUX_C) | \
1811 BIT(POWER_DOMAIN_INIT))
1813 #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
1814 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1815 BIT(POWER_DOMAIN_AUX_B) | \
1816 BIT(POWER_DOMAIN_INIT))
1818 #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
1819 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1820 BIT(POWER_DOMAIN_AUX_B) | \
1821 BIT(POWER_DOMAIN_INIT))
1823 #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
1824 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1825 BIT(POWER_DOMAIN_AUX_C) | \
1826 BIT(POWER_DOMAIN_INIT))
1828 #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
1829 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1830 BIT(POWER_DOMAIN_AUX_C) | \
1831 BIT(POWER_DOMAIN_INIT))
1833 #define CHV_DISPLAY_POWER_DOMAINS ( \
1834 BIT(POWER_DOMAIN_PIPE_A) | \
1835 BIT(POWER_DOMAIN_PIPE_B) | \
1836 BIT(POWER_DOMAIN_PIPE_C) | \
1837 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1838 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1839 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1840 BIT(POWER_DOMAIN_TRANSCODER_A) | \
1841 BIT(POWER_DOMAIN_TRANSCODER_B) | \
1842 BIT(POWER_DOMAIN_TRANSCODER_C) | \
1843 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1844 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1845 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1846 BIT(POWER_DOMAIN_PORT_DSI) | \
1847 BIT(POWER_DOMAIN_VGA) | \
1848 BIT(POWER_DOMAIN_AUDIO) | \
1849 BIT(POWER_DOMAIN_AUX_B) | \
1850 BIT(POWER_DOMAIN_AUX_C) | \
1851 BIT(POWER_DOMAIN_AUX_D) | \
1852 BIT(POWER_DOMAIN_GMBUS) | \
1853 BIT(POWER_DOMAIN_INIT))
1855 #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
1856 BIT(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1857 BIT(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1858 BIT(POWER_DOMAIN_AUX_B) | \
1859 BIT(POWER_DOMAIN_AUX_C) | \
1860 BIT(POWER_DOMAIN_INIT))
1862 #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
1863 BIT(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1864 BIT(POWER_DOMAIN_AUX_D) | \
1865 BIT(POWER_DOMAIN_INIT))
1867 static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
1868 .sync_hw = i9xx_always_on_power_well_noop,
1869 .enable = i9xx_always_on_power_well_noop,
1870 .disable = i9xx_always_on_power_well_noop,
1871 .is_enabled = i9xx_always_on_power_well_enabled,
1874 static const struct i915_power_well_ops chv_pipe_power_well_ops = {
1875 .sync_hw = chv_pipe_power_well_sync_hw,
1876 .enable = chv_pipe_power_well_enable,
1877 .disable = chv_pipe_power_well_disable,
1878 .is_enabled = chv_pipe_power_well_enabled,
1881 static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
1882 .sync_hw = vlv_power_well_sync_hw,
1883 .enable = chv_dpio_cmn_power_well_enable,
1884 .disable = chv_dpio_cmn_power_well_disable,
1885 .is_enabled = vlv_power_well_enabled,
1888 static struct i915_power_well i9xx_always_on_power_well[] = {
1890 .name = "always-on",
1892 .domains = POWER_DOMAIN_MASK,
1893 .ops = &i9xx_always_on_power_well_ops,
1897 static const struct i915_power_well_ops hsw_power_well_ops = {
1898 .sync_hw = hsw_power_well_sync_hw,
1899 .enable = hsw_power_well_enable,
1900 .disable = hsw_power_well_disable,
1901 .is_enabled = hsw_power_well_enabled,
1904 static const struct i915_power_well_ops skl_power_well_ops = {
1905 .sync_hw = skl_power_well_sync_hw,
1906 .enable = skl_power_well_enable,
1907 .disable = skl_power_well_disable,
1908 .is_enabled = skl_power_well_enabled,
1911 static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
1912 .sync_hw = gen9_dc_off_power_well_sync_hw,
1913 .enable = gen9_dc_off_power_well_enable,
1914 .disable = gen9_dc_off_power_well_disable,
1915 .is_enabled = gen9_dc_off_power_well_enabled,
1918 static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
1919 .sync_hw = bxt_dpio_cmn_power_well_sync_hw,
1920 .enable = bxt_dpio_cmn_power_well_enable,
1921 .disable = bxt_dpio_cmn_power_well_disable,
1922 .is_enabled = bxt_dpio_cmn_power_well_enabled,
1925 static struct i915_power_well hsw_power_wells[] = {
1927 .name = "always-on",
1929 .domains = POWER_DOMAIN_MASK,
1930 .ops = &i9xx_always_on_power_well_ops,
1934 .domains = HSW_DISPLAY_POWER_DOMAINS,
1935 .ops = &hsw_power_well_ops,
1939 static struct i915_power_well bdw_power_wells[] = {
1941 .name = "always-on",
1943 .domains = POWER_DOMAIN_MASK,
1944 .ops = &i9xx_always_on_power_well_ops,
1948 .domains = BDW_DISPLAY_POWER_DOMAINS,
1949 .ops = &hsw_power_well_ops,
1953 static const struct i915_power_well_ops vlv_display_power_well_ops = {
1954 .sync_hw = vlv_power_well_sync_hw,
1955 .enable = vlv_display_power_well_enable,
1956 .disable = vlv_display_power_well_disable,
1957 .is_enabled = vlv_power_well_enabled,
1960 static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
1961 .sync_hw = vlv_power_well_sync_hw,
1962 .enable = vlv_dpio_cmn_power_well_enable,
1963 .disable = vlv_dpio_cmn_power_well_disable,
1964 .is_enabled = vlv_power_well_enabled,
1967 static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
1968 .sync_hw = vlv_power_well_sync_hw,
1969 .enable = vlv_power_well_enable,
1970 .disable = vlv_power_well_disable,
1971 .is_enabled = vlv_power_well_enabled,
1974 static struct i915_power_well vlv_power_wells[] = {
1976 .name = "always-on",
1978 .domains = POWER_DOMAIN_MASK,
1979 .ops = &i9xx_always_on_power_well_ops,
1980 .data = PUNIT_POWER_WELL_ALWAYS_ON,
1984 .domains = VLV_DISPLAY_POWER_DOMAINS,
1985 .data = PUNIT_POWER_WELL_DISP2D,
1986 .ops = &vlv_display_power_well_ops,
1989 .name = "dpio-tx-b-01",
1990 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1991 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1992 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1993 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1994 .ops = &vlv_dpio_power_well_ops,
1995 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1998 .name = "dpio-tx-b-23",
1999 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2000 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2001 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2002 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2003 .ops = &vlv_dpio_power_well_ops,
2004 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
2007 .name = "dpio-tx-c-01",
2008 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2009 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2010 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2011 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2012 .ops = &vlv_dpio_power_well_ops,
2013 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
2016 .name = "dpio-tx-c-23",
2017 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2018 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2019 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2020 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2021 .ops = &vlv_dpio_power_well_ops,
2022 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
2025 .name = "dpio-common",
2026 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
2027 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
2028 .ops = &vlv_dpio_cmn_power_well_ops,
2032 static struct i915_power_well chv_power_wells[] = {
2034 .name = "always-on",
2036 .domains = POWER_DOMAIN_MASK,
2037 .ops = &i9xx_always_on_power_well_ops,
2042 * Pipe A power well is the new disp2d well. Pipe B and C
2043 * power wells don't actually exist. Pipe A power well is
2044 * required for any pipe to work.
2046 .domains = CHV_DISPLAY_POWER_DOMAINS,
2048 .ops = &chv_pipe_power_well_ops,
2051 .name = "dpio-common-bc",
2052 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
2053 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
2054 .ops = &chv_dpio_cmn_power_well_ops,
2057 .name = "dpio-common-d",
2058 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
2059 .data = PUNIT_POWER_WELL_DPIO_CMN_D,
2060 .ops = &chv_dpio_cmn_power_well_ops,
2064 bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
2067 struct i915_power_well *power_well;
2070 power_well = lookup_power_well(dev_priv, power_well_id);
2071 ret = power_well->ops->is_enabled(dev_priv, power_well);
2076 static struct i915_power_well skl_power_wells[] = {
2078 .name = "always-on",
2080 .domains = POWER_DOMAIN_MASK,
2081 .ops = &i9xx_always_on_power_well_ops,
2082 .data = SKL_DISP_PW_ALWAYS_ON,
2085 .name = "power well 1",
2086 /* Handled by the DMC firmware */
2088 .ops = &skl_power_well_ops,
2089 .data = SKL_DISP_PW_1,
2092 .name = "MISC IO power well",
2093 /* Handled by the DMC firmware */
2095 .ops = &skl_power_well_ops,
2096 .data = SKL_DISP_PW_MISC_IO,
2100 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2101 .ops = &gen9_dc_off_power_well_ops,
2102 .data = SKL_DISP_PW_DC_OFF,
2105 .name = "power well 2",
2106 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2107 .ops = &skl_power_well_ops,
2108 .data = SKL_DISP_PW_2,
2111 .name = "DDI A/E power well",
2112 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
2113 .ops = &skl_power_well_ops,
2114 .data = SKL_DISP_PW_DDI_A_E,
2117 .name = "DDI B power well",
2118 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
2119 .ops = &skl_power_well_ops,
2120 .data = SKL_DISP_PW_DDI_B,
2123 .name = "DDI C power well",
2124 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
2125 .ops = &skl_power_well_ops,
2126 .data = SKL_DISP_PW_DDI_C,
2129 .name = "DDI D power well",
2130 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
2131 .ops = &skl_power_well_ops,
2132 .data = SKL_DISP_PW_DDI_D,
2136 static struct i915_power_well bxt_power_wells[] = {
2138 .name = "always-on",
2140 .domains = POWER_DOMAIN_MASK,
2141 .ops = &i9xx_always_on_power_well_ops,
2144 .name = "power well 1",
2146 .ops = &skl_power_well_ops,
2147 .data = SKL_DISP_PW_1,
2151 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2152 .ops = &gen9_dc_off_power_well_ops,
2153 .data = SKL_DISP_PW_DC_OFF,
2156 .name = "power well 2",
2157 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
2158 .ops = &skl_power_well_ops,
2159 .data = SKL_DISP_PW_2,
2162 .name = "dpio-common-a",
2163 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2164 .ops = &bxt_dpio_cmn_power_well_ops,
2165 .data = BXT_DPIO_CMN_A,
2168 .name = "dpio-common-bc",
2169 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2170 .ops = &bxt_dpio_cmn_power_well_ops,
2171 .data = BXT_DPIO_CMN_BC,
2176 sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2177 int disable_power_well)
2179 if (disable_power_well >= 0)
2180 return !!disable_power_well;
2185 static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2192 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
2195 } else if (IS_BROXTON(dev_priv)) {
2198 * DC9 has a separate HW flow from the rest of the DC states,
2199 * not depending on the DMC firmware. It's needed by system
2200 * suspend/resume, so allow it unconditionally.
2202 mask = DC_STATE_EN_DC9;
2208 if (!i915.disable_power_well)
2211 if (enable_dc >= 0 && enable_dc <= max_dc) {
2212 requested_dc = enable_dc;
2213 } else if (enable_dc == -1) {
2214 requested_dc = max_dc;
2215 } else if (enable_dc > max_dc && enable_dc <= 2) {
2216 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2218 requested_dc = max_dc;
2220 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2221 requested_dc = max_dc;
2224 if (requested_dc > 1)
2225 mask |= DC_STATE_EN_UPTO_DC6;
2226 if (requested_dc > 0)
2227 mask |= DC_STATE_EN_UPTO_DC5;
2229 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2234 #define set_power_wells(power_domains, __power_wells) ({ \
2235 (power_domains)->power_wells = (__power_wells); \
2236 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2240 * intel_power_domains_init - initializes the power domain structures
2241 * @dev_priv: i915 device instance
2243 * Initializes the power domain structures for @dev_priv depending upon the
2244 * supported platform.
2246 int intel_power_domains_init(struct drm_i915_private *dev_priv)
2248 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2250 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2251 i915.disable_power_well);
2252 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2255 BUILD_BUG_ON(POWER_DOMAIN_NUM > 31);
2257 mutex_init(&power_domains->lock);
2260 * The enabling order will be from lower to higher indexed wells,
2261 * the disabling order is reversed.
2263 if (IS_HASWELL(dev_priv)) {
2264 set_power_wells(power_domains, hsw_power_wells);
2265 } else if (IS_BROADWELL(dev_priv)) {
2266 set_power_wells(power_domains, bdw_power_wells);
2267 } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
2268 set_power_wells(power_domains, skl_power_wells);
2269 } else if (IS_BROXTON(dev_priv)) {
2270 set_power_wells(power_domains, bxt_power_wells);
2271 } else if (IS_CHERRYVIEW(dev_priv)) {
2272 set_power_wells(power_domains, chv_power_wells);
2273 } else if (IS_VALLEYVIEW(dev_priv)) {
2274 set_power_wells(power_domains, vlv_power_wells);
2276 set_power_wells(power_domains, i9xx_always_on_power_well);
2283 * intel_power_domains_fini - finalizes the power domain structures
2284 * @dev_priv: i915 device instance
2286 * Finalizes the power domain structures for @dev_priv depending upon the
2287 * supported platform. This function also disables runtime pm and ensures that
2288 * the device stays powered up so that the driver can be reloaded.
2290 void intel_power_domains_fini(struct drm_i915_private *dev_priv)
2292 struct device *kdev = &dev_priv->drm.pdev->dev;
2295 * The i915.ko module is still not prepared to be loaded when
2296 * the power well is not enabled, so just enable it in case
2297 * we're going to unload/reload.
2298 * The following also reacquires the RPM reference the core passed
2299 * to the driver during loading, which is dropped in
2300 * intel_runtime_pm_enable(). We have to hand back the control of the
2301 * device to the core with this reference held.
2303 intel_display_set_init_power(dev_priv, true);
2305 /* Remove the refcount we took to keep power well support disabled. */
2306 if (!i915.disable_power_well)
2307 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
2310 * Remove the refcount we took in intel_runtime_pm_enable() in case
2311 * the platform doesn't support runtime PM.
2313 if (!HAS_RUNTIME_PM(dev_priv))
2314 pm_runtime_put(kdev);
2317 static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
2319 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2320 struct i915_power_well *power_well;
2323 mutex_lock(&power_domains->lock);
2324 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
2325 power_well->ops->sync_hw(dev_priv, power_well);
2326 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2329 mutex_unlock(&power_domains->lock);
2332 static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2334 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2335 POSTING_READ(DBUF_CTL);
2339 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2340 DRM_ERROR("DBuf power enable timeout\n");
2343 static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2345 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2346 POSTING_READ(DBUF_CTL);
2350 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2351 DRM_ERROR("DBuf power disable timeout!\n");
2354 static void skl_display_core_init(struct drm_i915_private *dev_priv,
2357 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2358 struct i915_power_well *well;
2361 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2363 /* enable PCH reset handshake */
2364 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2365 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2367 /* enable PG1 and Misc I/O */
2368 mutex_lock(&power_domains->lock);
2370 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2371 intel_power_well_enable(dev_priv, well);
2373 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2374 intel_power_well_enable(dev_priv, well);
2376 mutex_unlock(&power_domains->lock);
2378 skl_init_cdclk(dev_priv);
2380 gen9_dbuf_enable(dev_priv);
2382 if (resume && dev_priv->csr.dmc_payload)
2383 intel_csr_load_program(dev_priv);
2386 static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2388 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2389 struct i915_power_well *well;
2391 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2393 gen9_dbuf_disable(dev_priv);
2395 skl_uninit_cdclk(dev_priv);
2397 /* The spec doesn't call for removing the reset handshake flag */
2398 /* disable PG1 and Misc I/O */
2400 mutex_lock(&power_domains->lock);
2402 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2403 intel_power_well_disable(dev_priv, well);
2405 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2406 intel_power_well_disable(dev_priv, well);
2408 mutex_unlock(&power_domains->lock);
2411 void bxt_display_core_init(struct drm_i915_private *dev_priv,
2414 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2415 struct i915_power_well *well;
2418 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2421 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2422 * or else the reset will hang because there is no PCH to respond.
2423 * Move the handshake programming to initialization sequence.
2424 * Previously was left up to BIOS.
2426 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2427 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2428 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2431 mutex_lock(&power_domains->lock);
2433 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2434 intel_power_well_enable(dev_priv, well);
2436 mutex_unlock(&power_domains->lock);
2438 bxt_init_cdclk(dev_priv);
2440 gen9_dbuf_enable(dev_priv);
2442 if (resume && dev_priv->csr.dmc_payload)
2443 intel_csr_load_program(dev_priv);
2446 void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2448 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2449 struct i915_power_well *well;
2451 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2453 gen9_dbuf_disable(dev_priv);
2455 bxt_uninit_cdclk(dev_priv);
2457 /* The spec doesn't call for removing the reset handshake flag */
2460 mutex_lock(&power_domains->lock);
2462 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2463 intel_power_well_disable(dev_priv, well);
2465 mutex_unlock(&power_domains->lock);
2468 static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2470 struct i915_power_well *cmn_bc =
2471 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2472 struct i915_power_well *cmn_d =
2473 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2476 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2477 * workaround never ever read DISPLAY_PHY_CONTROL, and
2478 * instead maintain a shadow copy ourselves. Use the actual
2479 * power well state and lane status to reconstruct the
2480 * expected initial value.
2482 dev_priv->chv_phy_control =
2483 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2484 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
2485 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2486 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2487 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2490 * If all lanes are disabled we leave the override disabled
2491 * with all power down bits cleared to match the state we
2492 * would use after disabling the port. Otherwise enable the
2493 * override and set the lane powerdown bits accding to the
2494 * current lane status.
2496 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2497 uint32_t status = I915_READ(DPLL(PIPE_A));
2500 mask = status & DPLL_PORTB_READY_MASK;
2504 dev_priv->chv_phy_control |=
2505 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2507 dev_priv->chv_phy_control |=
2508 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2510 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2514 dev_priv->chv_phy_control |=
2515 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2517 dev_priv->chv_phy_control |=
2518 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2520 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
2522 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2524 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
2527 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2528 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2531 mask = status & DPLL_PORTD_READY_MASK;
2536 dev_priv->chv_phy_control |=
2537 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2539 dev_priv->chv_phy_control |=
2540 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2542 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
2544 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2546 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
2549 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2551 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2552 dev_priv->chv_phy_control);
2555 static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2557 struct i915_power_well *cmn =
2558 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2559 struct i915_power_well *disp2d =
2560 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2562 /* If the display might be already active skip this */
2563 if (cmn->ops->is_enabled(dev_priv, cmn) &&
2564 disp2d->ops->is_enabled(dev_priv, disp2d) &&
2565 I915_READ(DPIO_CTL) & DPIO_CMNRST)
2568 DRM_DEBUG_KMS("toggling display PHY side reset\n");
2570 /* cmnlane needs DPLL registers */
2571 disp2d->ops->enable(dev_priv, disp2d);
2574 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2575 * Need to assert and de-assert PHY SB reset by gating the
2576 * common lane power, then un-gating it.
2577 * Simply ungating isn't enough to reset the PHY enough to get
2578 * ports and lanes running.
2580 cmn->ops->disable(dev_priv, cmn);
2584 * intel_power_domains_init_hw - initialize hardware power domain state
2585 * @dev_priv: i915 device instance
2586 * @resume: Called from resume code paths or not
2588 * This function initializes the hardware power domain state and enables all
2589 * power domains using intel_display_set_init_power().
2591 void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
2593 struct drm_device *dev = &dev_priv->drm;
2594 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2596 power_domains->initializing = true;
2598 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
2599 skl_display_core_init(dev_priv, resume);
2600 } else if (IS_BROXTON(dev)) {
2601 bxt_display_core_init(dev_priv, resume);
2602 } else if (IS_CHERRYVIEW(dev)) {
2603 mutex_lock(&power_domains->lock);
2604 chv_phy_control_init(dev_priv);
2605 mutex_unlock(&power_domains->lock);
2606 } else if (IS_VALLEYVIEW(dev)) {
2607 mutex_lock(&power_domains->lock);
2608 vlv_cmnlane_wa(dev_priv);
2609 mutex_unlock(&power_domains->lock);
2612 /* For now, we need the power well to be always enabled. */
2613 intel_display_set_init_power(dev_priv, true);
2614 /* Disable power support if the user asked so. */
2615 if (!i915.disable_power_well)
2616 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
2617 intel_power_domains_sync_hw(dev_priv);
2618 power_domains->initializing = false;
2622 * intel_power_domains_suspend - suspend power domain state
2623 * @dev_priv: i915 device instance
2625 * This function prepares the hardware power domain state before entering
2626 * system suspend. It must be paired with intel_power_domains_init_hw().
2628 void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
2631 * Even if power well support was disabled we still want to disable
2632 * power wells while we are system suspended.
2634 if (!i915.disable_power_well)
2635 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
2637 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
2638 skl_display_core_uninit(dev_priv);
2639 else if (IS_BROXTON(dev_priv))
2640 bxt_display_core_uninit(dev_priv);
2644 * intel_runtime_pm_get - grab a runtime pm reference
2645 * @dev_priv: i915 device instance
2647 * This function grabs a device-level runtime pm reference (mostly used for GEM
2648 * code to ensure the GTT or GT is on) and ensures that it is powered up.
2650 * Any runtime pm reference obtained by this function must have a symmetric
2651 * call to intel_runtime_pm_put() to release the reference again.
2653 void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
2655 struct pci_dev *pdev = dev_priv->drm.pdev;
2656 struct device *kdev = &pdev->dev;
2658 pm_runtime_get_sync(kdev);
2660 atomic_inc(&dev_priv->pm.wakeref_count);
2661 assert_rpm_wakelock_held(dev_priv);
2665 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
2666 * @dev_priv: i915 device instance
2668 * This function grabs a device-level runtime pm reference if the device is
2669 * already in use and ensures that it is powered up.
2671 * Any runtime pm reference obtained by this function must have a symmetric
2672 * call to intel_runtime_pm_put() to release the reference again.
2674 bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
2676 struct pci_dev *pdev = dev_priv->drm.pdev;
2677 struct device *kdev = &pdev->dev;
2679 if (IS_ENABLED(CONFIG_PM)) {
2680 int ret = pm_runtime_get_if_in_use(kdev);
2683 * In cases runtime PM is disabled by the RPM core and we get
2684 * an -EINVAL return value we are not supposed to call this
2685 * function, since the power state is undefined. This applies
2686 * atm to the late/early system suspend/resume handlers.
2688 WARN_ON_ONCE(ret < 0);
2693 atomic_inc(&dev_priv->pm.wakeref_count);
2694 assert_rpm_wakelock_held(dev_priv);
2700 * intel_runtime_pm_get_noresume - grab a runtime pm reference
2701 * @dev_priv: i915 device instance
2703 * This function grabs a device-level runtime pm reference (mostly used for GEM
2704 * code to ensure the GTT or GT is on).
2706 * It will _not_ power up the device but instead only check that it's powered
2707 * on. Therefore it is only valid to call this functions from contexts where
2708 * the device is known to be powered up and where trying to power it up would
2709 * result in hilarity and deadlocks. That pretty much means only the system
2710 * suspend/resume code where this is used to grab runtime pm references for
2711 * delayed setup down in work items.
2713 * Any runtime pm reference obtained by this function must have a symmetric
2714 * call to intel_runtime_pm_put() to release the reference again.
2716 void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
2718 struct pci_dev *pdev = dev_priv->drm.pdev;
2719 struct device *kdev = &pdev->dev;
2721 assert_rpm_wakelock_held(dev_priv);
2722 pm_runtime_get_noresume(kdev);
2724 atomic_inc(&dev_priv->pm.wakeref_count);
2728 * intel_runtime_pm_put - release a runtime pm reference
2729 * @dev_priv: i915 device instance
2731 * This function drops the device-level runtime pm reference obtained by
2732 * intel_runtime_pm_get() and might power down the corresponding
2733 * hardware block right away if this is the last reference.
2735 void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
2737 struct pci_dev *pdev = dev_priv->drm.pdev;
2738 struct device *kdev = &pdev->dev;
2740 assert_rpm_wakelock_held(dev_priv);
2741 if (atomic_dec_and_test(&dev_priv->pm.wakeref_count))
2742 atomic_inc(&dev_priv->pm.atomic_seq);
2744 pm_runtime_mark_last_busy(kdev);
2745 pm_runtime_put_autosuspend(kdev);
2749 * intel_runtime_pm_enable - enable runtime pm
2750 * @dev_priv: i915 device instance
2752 * This function enables runtime pm at the end of the driver load sequence.
2754 * Note that this function does currently not enable runtime pm for the
2755 * subordinate display power domains. That is only done on the first modeset
2756 * using intel_display_set_init_power().
2758 void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
2760 struct pci_dev *pdev = dev_priv->drm.pdev;
2761 struct drm_device *dev = &dev_priv->drm;
2762 struct device *kdev = &pdev->dev;
2764 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
2765 pm_runtime_mark_last_busy(kdev);
2768 * Take a permanent reference to disable the RPM functionality and drop
2769 * it only when unloading the driver. Use the low level get/put helpers,
2770 * so the driver's own RPM reference tracking asserts also work on
2771 * platforms without RPM support.
2773 if (!HAS_RUNTIME_PM(dev)) {
2774 pm_runtime_dont_use_autosuspend(kdev);
2775 pm_runtime_get_sync(kdev);
2777 pm_runtime_use_autosuspend(kdev);
2781 * The core calls the driver load handler with an RPM reference held.
2782 * We drop that here and will reacquire it during unloading in
2783 * intel_power_domains_fini().
2785 pm_runtime_put_autosuspend(kdev);