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 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 if ((power_well)->domains & (domain_mask))
66 * We should only use the power well if we explicitly asked the hardware to
67 * enable it, so check if it's enabled and also check if we've requested it to
70 static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
71 struct i915_power_well *power_well)
73 return I915_READ(HSW_PWR_WELL_DRIVER) ==
74 (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
78 * __intel_display_power_is_enabled - unlocked check for a power domain
79 * @dev_priv: i915 device instance
80 * @domain: power domain to check
82 * This is the unlocked version of intel_display_power_is_enabled() and should
83 * only be used from error capture and recovery code where deadlocks are
87 * True when the power domain is enabled, false otherwise.
89 bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
90 enum intel_display_power_domain domain)
92 struct i915_power_domains *power_domains;
93 struct i915_power_well *power_well;
97 if (dev_priv->pm.suspended)
100 power_domains = &dev_priv->power_domains;
104 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
105 if (power_well->always_on)
108 if (!power_well->hw_enabled) {
118 * intel_display_power_is_enabled - check for a power domain
119 * @dev_priv: i915 device instance
120 * @domain: power domain to check
122 * This function can be used to check the hw power domain state. It is mostly
123 * used in hardware state readout functions. Everywhere else code should rely
124 * upon explicit power domain reference counting to ensure that the hardware
125 * block is powered up before accessing it.
127 * Callers must hold the relevant modesetting locks to ensure that concurrent
128 * threads can't disable the power well while the caller tries to read a few
132 * True when the power domain is enabled, false otherwise.
134 bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
135 enum intel_display_power_domain domain)
137 struct i915_power_domains *power_domains;
140 power_domains = &dev_priv->power_domains;
142 mutex_lock(&power_domains->lock);
143 ret = __intel_display_power_is_enabled(dev_priv, domain);
144 mutex_unlock(&power_domains->lock);
150 * intel_display_set_init_power - set the initial power domain state
151 * @dev_priv: i915 device instance
152 * @enable: whether to enable or disable the initial power domain state
154 * For simplicity our driver load/unload and system suspend/resume code assumes
155 * that all power domains are always enabled. This functions controls the state
156 * of this little hack. While the initial power domain state is enabled runtime
157 * pm is effectively disabled.
159 void intel_display_set_init_power(struct drm_i915_private *dev_priv,
162 if (dev_priv->power_domains.init_power_on == enable)
166 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
168 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
170 dev_priv->power_domains.init_power_on = enable;
174 * Starting with Haswell, we have a "Power Down Well" that can be turned off
175 * when not needed anymore. We have 4 registers that can request the power well
176 * to be enabled, and it will only be disabled if none of the registers is
177 * requesting it to be enabled.
179 static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
181 struct drm_device *dev = dev_priv->dev;
184 * After we re-enable the power well, if we touch VGA register 0x3d5
185 * we'll get unclaimed register interrupts. This stops after we write
186 * anything to the VGA MSR register. The vgacon module uses this
187 * register all the time, so if we unbind our driver and, as a
188 * consequence, bind vgacon, we'll get stuck in an infinite loop at
189 * console_unlock(). So make here we touch the VGA MSR register, making
190 * sure vgacon can keep working normally without triggering interrupts
191 * and error messages.
193 vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
194 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
195 vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
197 if (IS_BROADWELL(dev) || (INTEL_INFO(dev)->gen >= 9))
198 gen8_irq_power_well_post_enable(dev_priv);
201 static void hsw_set_power_well(struct drm_i915_private *dev_priv,
202 struct i915_power_well *power_well, bool enable)
204 bool is_enabled, enable_requested;
207 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
208 is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
209 enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
212 if (!enable_requested)
213 I915_WRITE(HSW_PWR_WELL_DRIVER,
214 HSW_PWR_WELL_ENABLE_REQUEST);
217 DRM_DEBUG_KMS("Enabling power well\n");
218 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
219 HSW_PWR_WELL_STATE_ENABLED), 20))
220 DRM_ERROR("Timeout enabling power well\n");
221 hsw_power_well_post_enable(dev_priv);
225 if (enable_requested) {
226 I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
227 POSTING_READ(HSW_PWR_WELL_DRIVER);
228 DRM_DEBUG_KMS("Requesting to disable the power well\n");
233 #define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
234 BIT(POWER_DOMAIN_TRANSCODER_A) | \
235 BIT(POWER_DOMAIN_PIPE_B) | \
236 BIT(POWER_DOMAIN_TRANSCODER_B) | \
237 BIT(POWER_DOMAIN_PIPE_C) | \
238 BIT(POWER_DOMAIN_TRANSCODER_C) | \
239 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
240 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
241 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
242 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
243 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
244 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
245 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
246 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
247 BIT(POWER_DOMAIN_AUX_B) | \
248 BIT(POWER_DOMAIN_AUX_C) | \
249 BIT(POWER_DOMAIN_AUX_D) | \
250 BIT(POWER_DOMAIN_AUDIO) | \
251 BIT(POWER_DOMAIN_VGA) | \
252 BIT(POWER_DOMAIN_INIT))
253 #define SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
254 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
255 BIT(POWER_DOMAIN_PLLS) | \
256 BIT(POWER_DOMAIN_PIPE_A) | \
257 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
258 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
259 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
260 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
261 BIT(POWER_DOMAIN_AUX_A) | \
262 BIT(POWER_DOMAIN_INIT))
263 #define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
264 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
265 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
266 BIT(POWER_DOMAIN_INIT))
267 #define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
268 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
269 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
270 BIT(POWER_DOMAIN_INIT))
271 #define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
272 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
273 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
274 BIT(POWER_DOMAIN_INIT))
275 #define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
276 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
277 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
278 BIT(POWER_DOMAIN_INIT))
279 #define SKL_DISPLAY_MISC_IO_POWER_DOMAINS ( \
280 SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS)
281 #define SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
282 (POWER_DOMAIN_MASK & ~(SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
283 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
284 SKL_DISPLAY_DDI_A_E_POWER_DOMAINS | \
285 SKL_DISPLAY_DDI_B_POWER_DOMAINS | \
286 SKL_DISPLAY_DDI_C_POWER_DOMAINS | \
287 SKL_DISPLAY_DDI_D_POWER_DOMAINS | \
288 SKL_DISPLAY_MISC_IO_POWER_DOMAINS)) | \
289 BIT(POWER_DOMAIN_INIT))
291 static void skl_set_power_well(struct drm_i915_private *dev_priv,
292 struct i915_power_well *power_well, bool enable)
294 uint32_t tmp, fuse_status;
295 uint32_t req_mask, state_mask;
296 bool check_fuse_status = false;
298 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
299 fuse_status = I915_READ(SKL_FUSE_STATUS);
301 switch (power_well->data) {
303 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
304 SKL_FUSE_PG0_DIST_STATUS), 1)) {
305 DRM_ERROR("PG0 not enabled\n");
310 if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
311 DRM_ERROR("PG1 in disabled state\n");
315 case SKL_DISP_PW_DDI_A_E:
316 case SKL_DISP_PW_DDI_B:
317 case SKL_DISP_PW_DDI_C:
318 case SKL_DISP_PW_DDI_D:
319 case SKL_DISP_PW_MISC_IO:
322 WARN(1, "Unknown power well %lu\n", power_well->data);
326 req_mask = SKL_POWER_WELL_REQ(power_well->data);
327 state_mask = SKL_POWER_WELL_STATE(power_well->data);
330 if (!(tmp & req_mask)) {
331 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
332 DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
335 if (!(tmp & state_mask)) {
336 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
338 DRM_ERROR("%s enable timeout\n",
340 check_fuse_status = true;
343 if (tmp & req_mask) {
344 I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
345 POSTING_READ(HSW_PWR_WELL_DRIVER);
346 DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
350 if (check_fuse_status) {
351 if (power_well->data == SKL_DISP_PW_1) {
352 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
353 SKL_FUSE_PG1_DIST_STATUS), 1))
354 DRM_ERROR("PG1 distributing status timeout\n");
355 } else if (power_well->data == SKL_DISP_PW_2) {
356 if (wait_for((I915_READ(SKL_FUSE_STATUS) &
357 SKL_FUSE_PG2_DIST_STATUS), 1))
358 DRM_ERROR("PG2 distributing status timeout\n");
363 static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
364 struct i915_power_well *power_well)
366 hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
369 * We're taking over the BIOS, so clear any requests made by it since
370 * the driver is in charge now.
372 if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
373 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
376 static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
377 struct i915_power_well *power_well)
379 hsw_set_power_well(dev_priv, power_well, true);
382 static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
383 struct i915_power_well *power_well)
385 hsw_set_power_well(dev_priv, power_well, false);
388 static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
389 struct i915_power_well *power_well)
391 uint32_t mask = SKL_POWER_WELL_REQ(power_well->data) |
392 SKL_POWER_WELL_STATE(power_well->data);
394 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
397 static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
398 struct i915_power_well *power_well)
400 skl_set_power_well(dev_priv, power_well, power_well->count > 0);
402 /* Clear any request made by BIOS as driver is taking over */
403 I915_WRITE(HSW_PWR_WELL_BIOS, 0);
406 static void skl_power_well_enable(struct drm_i915_private *dev_priv,
407 struct i915_power_well *power_well)
409 skl_set_power_well(dev_priv, power_well, true);
412 static void skl_power_well_disable(struct drm_i915_private *dev_priv,
413 struct i915_power_well *power_well)
415 skl_set_power_well(dev_priv, power_well, false);
418 static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
419 struct i915_power_well *power_well)
423 static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
424 struct i915_power_well *power_well)
429 static void vlv_set_power_well(struct drm_i915_private *dev_priv,
430 struct i915_power_well *power_well, bool enable)
432 enum punit_power_well power_well_id = power_well->data;
437 mask = PUNIT_PWRGT_MASK(power_well_id);
438 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
439 PUNIT_PWRGT_PWR_GATE(power_well_id);
441 mutex_lock(&dev_priv->rps.hw_lock);
444 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
449 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
452 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
454 if (wait_for(COND, 100))
455 DRM_ERROR("timout setting power well state %08x (%08x)\n",
457 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
462 mutex_unlock(&dev_priv->rps.hw_lock);
465 static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
466 struct i915_power_well *power_well)
468 vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
471 static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
472 struct i915_power_well *power_well)
474 vlv_set_power_well(dev_priv, power_well, true);
477 static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
478 struct i915_power_well *power_well)
480 vlv_set_power_well(dev_priv, power_well, false);
483 static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
484 struct i915_power_well *power_well)
486 int power_well_id = power_well->data;
487 bool enabled = false;
492 mask = PUNIT_PWRGT_MASK(power_well_id);
493 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
495 mutex_lock(&dev_priv->rps.hw_lock);
497 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
499 * We only ever set the power-on and power-gate states, anything
500 * else is unexpected.
502 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
503 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
508 * A transient state at this point would mean some unexpected party
509 * is poking at the power controls too.
511 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
512 WARN_ON(ctrl != state);
514 mutex_unlock(&dev_priv->rps.hw_lock);
519 static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
520 struct i915_power_well *power_well)
522 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
524 vlv_set_power_well(dev_priv, power_well, true);
526 spin_lock_irq(&dev_priv->irq_lock);
527 valleyview_enable_display_irqs(dev_priv);
528 spin_unlock_irq(&dev_priv->irq_lock);
531 * During driver initialization/resume we can avoid restoring the
532 * part of the HW/SW state that will be inited anyway explicitly.
534 if (dev_priv->power_domains.initializing)
537 intel_hpd_init(dev_priv);
539 i915_redisable_vga_power_on(dev_priv->dev);
542 static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
543 struct i915_power_well *power_well)
545 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
547 spin_lock_irq(&dev_priv->irq_lock);
548 valleyview_disable_display_irqs(dev_priv);
549 spin_unlock_irq(&dev_priv->irq_lock);
551 vlv_set_power_well(dev_priv, power_well, false);
553 vlv_power_sequencer_reset(dev_priv);
556 static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
557 struct i915_power_well *power_well)
559 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
562 * Enable the CRI clock source so we can get at the
563 * display and the reference clock for VGA
564 * hotplug / manual detection.
566 I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
567 DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
568 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
570 vlv_set_power_well(dev_priv, power_well, true);
573 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
574 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
575 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
576 * b. The other bits such as sfr settings / modesel may all
579 * This should only be done on init and resume from S3 with
580 * both PLLs disabled, or we risk losing DPIO and PLL
583 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
586 static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
587 struct i915_power_well *power_well)
591 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
593 for_each_pipe(dev_priv, pipe)
594 assert_pll_disabled(dev_priv, pipe);
596 /* Assert common reset */
597 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
599 vlv_set_power_well(dev_priv, power_well, false);
602 static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
603 struct i915_power_well *power_well)
607 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
608 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
611 * Enable the CRI clock source so we can get at the
612 * display and the reference clock for VGA
613 * hotplug / manual detection.
615 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
617 I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
618 DPLL_REFA_CLK_ENABLE_VLV);
619 I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
620 DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
623 I915_WRITE(DPLL(PIPE_C), I915_READ(DPLL(PIPE_C)) |
624 DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
626 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
627 vlv_set_power_well(dev_priv, power_well, true);
629 /* Poll for phypwrgood signal */
630 if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1))
631 DRM_ERROR("Display PHY %d is not power up\n", phy);
633 I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) |
634 PHY_COM_LANE_RESET_DEASSERT(phy));
637 static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
638 struct i915_power_well *power_well)
642 WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
643 power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
645 if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
647 assert_pll_disabled(dev_priv, PIPE_A);
648 assert_pll_disabled(dev_priv, PIPE_B);
651 assert_pll_disabled(dev_priv, PIPE_C);
654 I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) &
655 ~PHY_COM_LANE_RESET_DEASSERT(phy));
657 vlv_set_power_well(dev_priv, power_well, false);
660 static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
661 struct i915_power_well *power_well)
663 enum pipe pipe = power_well->data;
667 mutex_lock(&dev_priv->rps.hw_lock);
669 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
671 * We only ever set the power-on and power-gate states, anything
672 * else is unexpected.
674 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
675 enabled = state == DP_SSS_PWR_ON(pipe);
678 * A transient state at this point would mean some unexpected party
679 * is poking at the power controls too.
681 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
682 WARN_ON(ctrl << 16 != state);
684 mutex_unlock(&dev_priv->rps.hw_lock);
689 static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
690 struct i915_power_well *power_well,
693 enum pipe pipe = power_well->data;
697 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
699 mutex_lock(&dev_priv->rps.hw_lock);
702 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
707 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
708 ctrl &= ~DP_SSC_MASK(pipe);
709 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
710 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
712 if (wait_for(COND, 100))
713 DRM_ERROR("timout setting power well state %08x (%08x)\n",
715 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
720 mutex_unlock(&dev_priv->rps.hw_lock);
723 static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
724 struct i915_power_well *power_well)
726 chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
729 static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
730 struct i915_power_well *power_well)
732 WARN_ON_ONCE(power_well->data != PIPE_A &&
733 power_well->data != PIPE_B &&
734 power_well->data != PIPE_C);
736 chv_set_pipe_power_well(dev_priv, power_well, true);
738 if (power_well->data == PIPE_A) {
739 spin_lock_irq(&dev_priv->irq_lock);
740 valleyview_enable_display_irqs(dev_priv);
741 spin_unlock_irq(&dev_priv->irq_lock);
744 * During driver initialization/resume we can avoid restoring the
745 * part of the HW/SW state that will be inited anyway explicitly.
747 if (dev_priv->power_domains.initializing)
750 intel_hpd_init(dev_priv);
752 i915_redisable_vga_power_on(dev_priv->dev);
756 static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
757 struct i915_power_well *power_well)
759 WARN_ON_ONCE(power_well->data != PIPE_A &&
760 power_well->data != PIPE_B &&
761 power_well->data != PIPE_C);
763 if (power_well->data == PIPE_A) {
764 spin_lock_irq(&dev_priv->irq_lock);
765 valleyview_disable_display_irqs(dev_priv);
766 spin_unlock_irq(&dev_priv->irq_lock);
769 chv_set_pipe_power_well(dev_priv, power_well, false);
771 if (power_well->data == PIPE_A)
772 vlv_power_sequencer_reset(dev_priv);
776 * intel_display_power_get - grab a power domain reference
777 * @dev_priv: i915 device instance
778 * @domain: power domain to reference
780 * This function grabs a power domain reference for @domain and ensures that the
781 * power domain and all its parents are powered up. Therefore users should only
782 * grab a reference to the innermost power domain they need.
784 * Any power domain reference obtained by this function must have a symmetric
785 * call to intel_display_power_put() to release the reference again.
787 void intel_display_power_get(struct drm_i915_private *dev_priv,
788 enum intel_display_power_domain domain)
790 struct i915_power_domains *power_domains;
791 struct i915_power_well *power_well;
794 intel_runtime_pm_get(dev_priv);
796 power_domains = &dev_priv->power_domains;
798 mutex_lock(&power_domains->lock);
800 for_each_power_well(i, power_well, BIT(domain), power_domains) {
801 if (!power_well->count++) {
802 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
803 power_well->ops->enable(dev_priv, power_well);
804 power_well->hw_enabled = true;
808 power_domains->domain_use_count[domain]++;
810 mutex_unlock(&power_domains->lock);
814 * intel_display_power_put - release a power domain reference
815 * @dev_priv: i915 device instance
816 * @domain: power domain to reference
818 * This function drops the power domain reference obtained by
819 * intel_display_power_get() and might power down the corresponding hardware
820 * block right away if this is the last reference.
822 void intel_display_power_put(struct drm_i915_private *dev_priv,
823 enum intel_display_power_domain domain)
825 struct i915_power_domains *power_domains;
826 struct i915_power_well *power_well;
829 power_domains = &dev_priv->power_domains;
831 mutex_lock(&power_domains->lock);
833 WARN_ON(!power_domains->domain_use_count[domain]);
834 power_domains->domain_use_count[domain]--;
836 for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
837 WARN_ON(!power_well->count);
839 if (!--power_well->count && i915.disable_power_well) {
840 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
841 power_well->hw_enabled = false;
842 power_well->ops->disable(dev_priv, power_well);
846 mutex_unlock(&power_domains->lock);
848 intel_runtime_pm_put(dev_priv);
851 #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
853 #define HSW_ALWAYS_ON_POWER_DOMAINS ( \
854 BIT(POWER_DOMAIN_PIPE_A) | \
855 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
856 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
857 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
858 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
859 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
860 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
861 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
862 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
863 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
864 BIT(POWER_DOMAIN_PORT_CRT) | \
865 BIT(POWER_DOMAIN_PLLS) | \
866 BIT(POWER_DOMAIN_AUX_A) | \
867 BIT(POWER_DOMAIN_AUX_B) | \
868 BIT(POWER_DOMAIN_AUX_C) | \
869 BIT(POWER_DOMAIN_AUX_D) | \
870 BIT(POWER_DOMAIN_INIT))
871 #define HSW_DISPLAY_POWER_DOMAINS ( \
872 (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
873 BIT(POWER_DOMAIN_INIT))
875 #define BDW_ALWAYS_ON_POWER_DOMAINS ( \
876 HSW_ALWAYS_ON_POWER_DOMAINS | \
877 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
878 #define BDW_DISPLAY_POWER_DOMAINS ( \
879 (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
880 BIT(POWER_DOMAIN_INIT))
882 #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
883 #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
885 #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
886 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
887 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
888 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
889 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
890 BIT(POWER_DOMAIN_PORT_CRT) | \
891 BIT(POWER_DOMAIN_AUX_B) | \
892 BIT(POWER_DOMAIN_AUX_C) | \
893 BIT(POWER_DOMAIN_INIT))
895 #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
896 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
897 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
898 BIT(POWER_DOMAIN_AUX_B) | \
899 BIT(POWER_DOMAIN_INIT))
901 #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
902 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
903 BIT(POWER_DOMAIN_AUX_B) | \
904 BIT(POWER_DOMAIN_INIT))
906 #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
907 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
908 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
909 BIT(POWER_DOMAIN_AUX_C) | \
910 BIT(POWER_DOMAIN_INIT))
912 #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
913 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
914 BIT(POWER_DOMAIN_AUX_C) | \
915 BIT(POWER_DOMAIN_INIT))
917 #define CHV_PIPE_A_POWER_DOMAINS ( \
918 BIT(POWER_DOMAIN_PIPE_A) | \
919 BIT(POWER_DOMAIN_INIT))
921 #define CHV_PIPE_B_POWER_DOMAINS ( \
922 BIT(POWER_DOMAIN_PIPE_B) | \
923 BIT(POWER_DOMAIN_INIT))
925 #define CHV_PIPE_C_POWER_DOMAINS ( \
926 BIT(POWER_DOMAIN_PIPE_C) | \
927 BIT(POWER_DOMAIN_INIT))
929 #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
930 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
931 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
932 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
933 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
934 BIT(POWER_DOMAIN_AUX_B) | \
935 BIT(POWER_DOMAIN_AUX_C) | \
936 BIT(POWER_DOMAIN_INIT))
938 #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
939 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
940 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
941 BIT(POWER_DOMAIN_AUX_D) | \
942 BIT(POWER_DOMAIN_INIT))
944 #define CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS ( \
945 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
946 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
947 BIT(POWER_DOMAIN_AUX_D) | \
948 BIT(POWER_DOMAIN_INIT))
950 #define CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS ( \
951 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
952 BIT(POWER_DOMAIN_AUX_D) | \
953 BIT(POWER_DOMAIN_INIT))
955 static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
956 .sync_hw = i9xx_always_on_power_well_noop,
957 .enable = i9xx_always_on_power_well_noop,
958 .disable = i9xx_always_on_power_well_noop,
959 .is_enabled = i9xx_always_on_power_well_enabled,
962 static const struct i915_power_well_ops chv_pipe_power_well_ops = {
963 .sync_hw = chv_pipe_power_well_sync_hw,
964 .enable = chv_pipe_power_well_enable,
965 .disable = chv_pipe_power_well_disable,
966 .is_enabled = chv_pipe_power_well_enabled,
969 static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
970 .sync_hw = vlv_power_well_sync_hw,
971 .enable = chv_dpio_cmn_power_well_enable,
972 .disable = chv_dpio_cmn_power_well_disable,
973 .is_enabled = vlv_power_well_enabled,
976 static struct i915_power_well i9xx_always_on_power_well[] = {
980 .domains = POWER_DOMAIN_MASK,
981 .ops = &i9xx_always_on_power_well_ops,
985 static const struct i915_power_well_ops hsw_power_well_ops = {
986 .sync_hw = hsw_power_well_sync_hw,
987 .enable = hsw_power_well_enable,
988 .disable = hsw_power_well_disable,
989 .is_enabled = hsw_power_well_enabled,
992 static const struct i915_power_well_ops skl_power_well_ops = {
993 .sync_hw = skl_power_well_sync_hw,
994 .enable = skl_power_well_enable,
995 .disable = skl_power_well_disable,
996 .is_enabled = skl_power_well_enabled,
999 static struct i915_power_well hsw_power_wells[] = {
1001 .name = "always-on",
1003 .domains = HSW_ALWAYS_ON_POWER_DOMAINS,
1004 .ops = &i9xx_always_on_power_well_ops,
1008 .domains = HSW_DISPLAY_POWER_DOMAINS,
1009 .ops = &hsw_power_well_ops,
1013 static struct i915_power_well bdw_power_wells[] = {
1015 .name = "always-on",
1017 .domains = BDW_ALWAYS_ON_POWER_DOMAINS,
1018 .ops = &i9xx_always_on_power_well_ops,
1022 .domains = BDW_DISPLAY_POWER_DOMAINS,
1023 .ops = &hsw_power_well_ops,
1027 static const struct i915_power_well_ops vlv_display_power_well_ops = {
1028 .sync_hw = vlv_power_well_sync_hw,
1029 .enable = vlv_display_power_well_enable,
1030 .disable = vlv_display_power_well_disable,
1031 .is_enabled = vlv_power_well_enabled,
1034 static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
1035 .sync_hw = vlv_power_well_sync_hw,
1036 .enable = vlv_dpio_cmn_power_well_enable,
1037 .disable = vlv_dpio_cmn_power_well_disable,
1038 .is_enabled = vlv_power_well_enabled,
1041 static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
1042 .sync_hw = vlv_power_well_sync_hw,
1043 .enable = vlv_power_well_enable,
1044 .disable = vlv_power_well_disable,
1045 .is_enabled = vlv_power_well_enabled,
1048 static struct i915_power_well vlv_power_wells[] = {
1050 .name = "always-on",
1052 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1053 .ops = &i9xx_always_on_power_well_ops,
1057 .domains = VLV_DISPLAY_POWER_DOMAINS,
1058 .data = PUNIT_POWER_WELL_DISP2D,
1059 .ops = &vlv_display_power_well_ops,
1062 .name = "dpio-tx-b-01",
1063 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1064 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1065 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1066 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1067 .ops = &vlv_dpio_power_well_ops,
1068 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1071 .name = "dpio-tx-b-23",
1072 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1073 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1074 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1075 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1076 .ops = &vlv_dpio_power_well_ops,
1077 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
1080 .name = "dpio-tx-c-01",
1081 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1082 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1083 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1084 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1085 .ops = &vlv_dpio_power_well_ops,
1086 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
1089 .name = "dpio-tx-c-23",
1090 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1091 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1092 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1093 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1094 .ops = &vlv_dpio_power_well_ops,
1095 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
1098 .name = "dpio-common",
1099 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
1100 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1101 .ops = &vlv_dpio_cmn_power_well_ops,
1105 static struct i915_power_well chv_power_wells[] = {
1107 .name = "always-on",
1109 .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
1110 .ops = &i9xx_always_on_power_well_ops,
1115 .domains = VLV_DISPLAY_POWER_DOMAINS,
1116 .data = PUNIT_POWER_WELL_DISP2D,
1117 .ops = &vlv_display_power_well_ops,
1123 * FIXME: pipe A power well seems to be the new disp2d well.
1124 * At least all registers seem to be housed there. Figure
1125 * out if this a a temporary situation in pre-production
1126 * hardware or a permanent state of affairs.
1128 .domains = CHV_PIPE_A_POWER_DOMAINS | VLV_DISPLAY_POWER_DOMAINS,
1130 .ops = &chv_pipe_power_well_ops,
1135 .domains = CHV_PIPE_B_POWER_DOMAINS,
1137 .ops = &chv_pipe_power_well_ops,
1141 .domains = CHV_PIPE_C_POWER_DOMAINS,
1143 .ops = &chv_pipe_power_well_ops,
1147 .name = "dpio-common-bc",
1149 * XXX: cmnreset for one PHY seems to disturb the other.
1150 * As a workaround keep both powered on at the same
1153 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS,
1154 .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
1155 .ops = &chv_dpio_cmn_power_well_ops,
1158 .name = "dpio-common-d",
1160 * XXX: cmnreset for one PHY seems to disturb the other.
1161 * As a workaround keep both powered on at the same
1164 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS,
1165 .data = PUNIT_POWER_WELL_DPIO_CMN_D,
1166 .ops = &chv_dpio_cmn_power_well_ops,
1170 .name = "dpio-tx-b-01",
1171 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1172 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS,
1173 .ops = &vlv_dpio_power_well_ops,
1174 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
1177 .name = "dpio-tx-b-23",
1178 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1179 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS,
1180 .ops = &vlv_dpio_power_well_ops,
1181 .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
1184 .name = "dpio-tx-c-01",
1185 .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1186 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1187 .ops = &vlv_dpio_power_well_ops,
1188 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
1191 .name = "dpio-tx-c-23",
1192 .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1193 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1194 .ops = &vlv_dpio_power_well_ops,
1195 .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
1198 .name = "dpio-tx-d-01",
1199 .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS |
1200 CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS,
1201 .ops = &vlv_dpio_power_well_ops,
1202 .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_01,
1205 .name = "dpio-tx-d-23",
1206 .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS |
1207 CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS,
1208 .ops = &vlv_dpio_power_well_ops,
1209 .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_23,
1214 static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
1215 enum punit_power_well power_well_id)
1217 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1218 struct i915_power_well *power_well;
1221 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
1222 if (power_well->data == power_well_id)
1229 static struct i915_power_well skl_power_wells[] = {
1231 .name = "always-on",
1233 .domains = SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
1234 .ops = &i9xx_always_on_power_well_ops,
1237 .name = "power well 1",
1238 .domains = SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS,
1239 .ops = &skl_power_well_ops,
1240 .data = SKL_DISP_PW_1,
1243 .name = "MISC IO power well",
1244 .domains = SKL_DISPLAY_MISC_IO_POWER_DOMAINS,
1245 .ops = &skl_power_well_ops,
1246 .data = SKL_DISP_PW_MISC_IO,
1249 .name = "power well 2",
1250 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
1251 .ops = &skl_power_well_ops,
1252 .data = SKL_DISP_PW_2,
1255 .name = "DDI A/E power well",
1256 .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
1257 .ops = &skl_power_well_ops,
1258 .data = SKL_DISP_PW_DDI_A_E,
1261 .name = "DDI B power well",
1262 .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
1263 .ops = &skl_power_well_ops,
1264 .data = SKL_DISP_PW_DDI_B,
1267 .name = "DDI C power well",
1268 .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
1269 .ops = &skl_power_well_ops,
1270 .data = SKL_DISP_PW_DDI_C,
1273 .name = "DDI D power well",
1274 .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
1275 .ops = &skl_power_well_ops,
1276 .data = SKL_DISP_PW_DDI_D,
1280 #define set_power_wells(power_domains, __power_wells) ({ \
1281 (power_domains)->power_wells = (__power_wells); \
1282 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
1286 * intel_power_domains_init - initializes the power domain structures
1287 * @dev_priv: i915 device instance
1289 * Initializes the power domain structures for @dev_priv depending upon the
1290 * supported platform.
1292 int intel_power_domains_init(struct drm_i915_private *dev_priv)
1294 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1296 mutex_init(&power_domains->lock);
1299 * The enabling order will be from lower to higher indexed wells,
1300 * the disabling order is reversed.
1302 if (IS_HASWELL(dev_priv->dev)) {
1303 set_power_wells(power_domains, hsw_power_wells);
1304 } else if (IS_BROADWELL(dev_priv->dev)) {
1305 set_power_wells(power_domains, bdw_power_wells);
1306 } else if (IS_SKYLAKE(dev_priv->dev)) {
1307 set_power_wells(power_domains, skl_power_wells);
1308 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1309 set_power_wells(power_domains, chv_power_wells);
1310 } else if (IS_VALLEYVIEW(dev_priv->dev)) {
1311 set_power_wells(power_domains, vlv_power_wells);
1313 set_power_wells(power_domains, i9xx_always_on_power_well);
1319 static void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
1321 struct drm_device *dev = dev_priv->dev;
1322 struct device *device = &dev->pdev->dev;
1324 if (!HAS_RUNTIME_PM(dev))
1327 if (!intel_enable_rc6(dev))
1330 /* Make sure we're not suspended first. */
1331 pm_runtime_get_sync(device);
1332 pm_runtime_disable(device);
1336 * intel_power_domains_fini - finalizes the power domain structures
1337 * @dev_priv: i915 device instance
1339 * Finalizes the power domain structures for @dev_priv depending upon the
1340 * supported platform. This function also disables runtime pm and ensures that
1341 * the device stays powered up so that the driver can be reloaded.
1343 void intel_power_domains_fini(struct drm_i915_private *dev_priv)
1345 intel_runtime_pm_disable(dev_priv);
1347 /* The i915.ko module is still not prepared to be loaded when
1348 * the power well is not enabled, so just enable it in case
1349 * we're going to unload/reload. */
1350 intel_display_set_init_power(dev_priv, true);
1353 static void intel_power_domains_resume(struct drm_i915_private *dev_priv)
1355 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1356 struct i915_power_well *power_well;
1359 mutex_lock(&power_domains->lock);
1360 for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
1361 power_well->ops->sync_hw(dev_priv, power_well);
1362 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
1365 mutex_unlock(&power_domains->lock);
1368 static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
1370 struct i915_power_well *cmn =
1371 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1372 struct i915_power_well *disp2d =
1373 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
1375 /* If the display might be already active skip this */
1376 if (cmn->ops->is_enabled(dev_priv, cmn) &&
1377 disp2d->ops->is_enabled(dev_priv, disp2d) &&
1378 I915_READ(DPIO_CTL) & DPIO_CMNRST)
1381 DRM_DEBUG_KMS("toggling display PHY side reset\n");
1383 /* cmnlane needs DPLL registers */
1384 disp2d->ops->enable(dev_priv, disp2d);
1387 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
1388 * Need to assert and de-assert PHY SB reset by gating the
1389 * common lane power, then un-gating it.
1390 * Simply ungating isn't enough to reset the PHY enough to get
1391 * ports and lanes running.
1393 cmn->ops->disable(dev_priv, cmn);
1397 * intel_power_domains_init_hw - initialize hardware power domain state
1398 * @dev_priv: i915 device instance
1400 * This function initializes the hardware power domain state and enables all
1401 * power domains using intel_display_set_init_power().
1403 void intel_power_domains_init_hw(struct drm_i915_private *dev_priv)
1405 struct drm_device *dev = dev_priv->dev;
1406 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1408 power_domains->initializing = true;
1410 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) {
1411 mutex_lock(&power_domains->lock);
1412 vlv_cmnlane_wa(dev_priv);
1413 mutex_unlock(&power_domains->lock);
1416 /* For now, we need the power well to be always enabled. */
1417 intel_display_set_init_power(dev_priv, true);
1418 intel_power_domains_resume(dev_priv);
1419 power_domains->initializing = false;
1423 * intel_aux_display_runtime_get - grab an auxilliary power domain reference
1424 * @dev_priv: i915 device instance
1426 * This function grabs a power domain reference for the auxiliary power domain
1427 * (for access to the GMBUS and DP AUX blocks) and ensures that it and all its
1428 * parents are powered up. Therefore users should only grab a reference to the
1429 * innermost power domain they need.
1431 * Any power domain reference obtained by this function must have a symmetric
1432 * call to intel_aux_display_runtime_put() to release the reference again.
1434 void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv)
1436 intel_runtime_pm_get(dev_priv);
1440 * intel_aux_display_runtime_put - release an auxilliary power domain reference
1441 * @dev_priv: i915 device instance
1443 * This function drops the auxilliary power domain reference obtained by
1444 * intel_aux_display_runtime_get() and might power down the corresponding
1445 * hardware block right away if this is the last reference.
1447 void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv)
1449 intel_runtime_pm_put(dev_priv);
1453 * intel_runtime_pm_get - grab a runtime pm reference
1454 * @dev_priv: i915 device instance
1456 * This function grabs a device-level runtime pm reference (mostly used for GEM
1457 * code to ensure the GTT or GT is on) and ensures that it is powered up.
1459 * Any runtime pm reference obtained by this function must have a symmetric
1460 * call to intel_runtime_pm_put() to release the reference again.
1462 void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
1464 struct drm_device *dev = dev_priv->dev;
1465 struct device *device = &dev->pdev->dev;
1467 if (!HAS_RUNTIME_PM(dev))
1470 pm_runtime_get_sync(device);
1471 WARN(dev_priv->pm.suspended, "Device still suspended.\n");
1475 * intel_runtime_pm_get_noresume - grab a runtime pm reference
1476 * @dev_priv: i915 device instance
1478 * This function grabs a device-level runtime pm reference (mostly used for GEM
1479 * code to ensure the GTT or GT is on).
1481 * It will _not_ power up the device but instead only check that it's powered
1482 * on. Therefore it is only valid to call this functions from contexts where
1483 * the device is known to be powered up and where trying to power it up would
1484 * result in hilarity and deadlocks. That pretty much means only the system
1485 * suspend/resume code where this is used to grab runtime pm references for
1486 * delayed setup down in work items.
1488 * Any runtime pm reference obtained by this function must have a symmetric
1489 * call to intel_runtime_pm_put() to release the reference again.
1491 void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
1493 struct drm_device *dev = dev_priv->dev;
1494 struct device *device = &dev->pdev->dev;
1496 if (!HAS_RUNTIME_PM(dev))
1499 WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n");
1500 pm_runtime_get_noresume(device);
1504 * intel_runtime_pm_put - release a runtime pm reference
1505 * @dev_priv: i915 device instance
1507 * This function drops the device-level runtime pm reference obtained by
1508 * intel_runtime_pm_get() and might power down the corresponding
1509 * hardware block right away if this is the last reference.
1511 void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
1513 struct drm_device *dev = dev_priv->dev;
1514 struct device *device = &dev->pdev->dev;
1516 if (!HAS_RUNTIME_PM(dev))
1519 pm_runtime_mark_last_busy(device);
1520 pm_runtime_put_autosuspend(device);
1524 * intel_runtime_pm_enable - enable runtime pm
1525 * @dev_priv: i915 device instance
1527 * This function enables runtime pm at the end of the driver load sequence.
1529 * Note that this function does currently not enable runtime pm for the
1530 * subordinate display power domains. That is only done on the first modeset
1531 * using intel_display_set_init_power().
1533 void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
1535 struct drm_device *dev = dev_priv->dev;
1536 struct device *device = &dev->pdev->dev;
1538 if (!HAS_RUNTIME_PM(dev))
1541 pm_runtime_set_active(device);
1544 * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
1547 if (!intel_enable_rc6(dev)) {
1548 DRM_INFO("RC6 disabled, disabling runtime PM support\n");
1552 pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */
1553 pm_runtime_mark_last_busy(device);
1554 pm_runtime_use_autosuspend(device);
1556 pm_runtime_put_autosuspend(device);