2 * Copyright © 2012-2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
29 #include <linux/pm_runtime.h>
30 #include <linux/vgaarb.h>
33 #include "intel_drv.h"
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
52 #define GEN9_ENABLE_DC5(dev) 0
53 #define SKL_ENABLE_DC6(dev) IS_SKYLAKE(dev)
55 #define for_each_power_well(i, power_well, domain_mask, power_domains) \
57 i < (power_domains)->power_well_count && \
58 ((power_well) = &(power_domains)->power_wells[i]); \
60 if ((power_well)->domains & (domain_mask))
62 #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
63 for (i = (power_domains)->power_well_count - 1; \
64 i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
66 if ((power_well)->domains & (domain_mask))
68 bool intel_display_power_well_is_enabled(struct drm_i915_private
*dev_priv
,
71 static void intel_power_well_enable(struct drm_i915_private
*dev_priv
,
72 struct i915_power_well
*power_well
)
74 DRM_DEBUG_KMS("enabling %s\n", power_well
->name
);
75 power_well
->ops
->enable(dev_priv
, power_well
);
76 power_well
->hw_enabled
= true;
79 static void intel_power_well_disable(struct drm_i915_private
*dev_priv
,
80 struct i915_power_well
*power_well
)
82 DRM_DEBUG_KMS("disabling %s\n", power_well
->name
);
83 power_well
->hw_enabled
= false;
84 power_well
->ops
->disable(dev_priv
, power_well
);
88 * We should only use the power well if we explicitly asked the hardware to
89 * enable it, so check if it's enabled and also check if we've requested it to
92 static bool hsw_power_well_enabled(struct drm_i915_private
*dev_priv
,
93 struct i915_power_well
*power_well
)
95 return I915_READ(HSW_PWR_WELL_DRIVER
) ==
96 (HSW_PWR_WELL_ENABLE_REQUEST
| HSW_PWR_WELL_STATE_ENABLED
);
100 * __intel_display_power_is_enabled - unlocked check for a power domain
101 * @dev_priv: i915 device instance
102 * @domain: power domain to check
104 * This is the unlocked version of intel_display_power_is_enabled() and should
105 * only be used from error capture and recovery code where deadlocks are
109 * True when the power domain is enabled, false otherwise.
111 bool __intel_display_power_is_enabled(struct drm_i915_private
*dev_priv
,
112 enum intel_display_power_domain domain
)
114 struct i915_power_domains
*power_domains
;
115 struct i915_power_well
*power_well
;
119 if (dev_priv
->pm
.suspended
)
122 power_domains
= &dev_priv
->power_domains
;
126 for_each_power_well_rev(i
, power_well
, BIT(domain
), power_domains
) {
127 if (power_well
->always_on
)
130 if (!power_well
->hw_enabled
) {
140 * intel_display_power_is_enabled - check for a power domain
141 * @dev_priv: i915 device instance
142 * @domain: power domain to check
144 * This function can be used to check the hw power domain state. It is mostly
145 * used in hardware state readout functions. Everywhere else code should rely
146 * upon explicit power domain reference counting to ensure that the hardware
147 * block is powered up before accessing it.
149 * Callers must hold the relevant modesetting locks to ensure that concurrent
150 * threads can't disable the power well while the caller tries to read a few
154 * True when the power domain is enabled, false otherwise.
156 bool intel_display_power_is_enabled(struct drm_i915_private
*dev_priv
,
157 enum intel_display_power_domain domain
)
159 struct i915_power_domains
*power_domains
;
162 power_domains
= &dev_priv
->power_domains
;
164 mutex_lock(&power_domains
->lock
);
165 ret
= __intel_display_power_is_enabled(dev_priv
, domain
);
166 mutex_unlock(&power_domains
->lock
);
172 * intel_display_set_init_power - set the initial power domain state
173 * @dev_priv: i915 device instance
174 * @enable: whether to enable or disable the initial power domain state
176 * For simplicity our driver load/unload and system suspend/resume code assumes
177 * that all power domains are always enabled. This functions controls the state
178 * of this little hack. While the initial power domain state is enabled runtime
179 * pm is effectively disabled.
181 void intel_display_set_init_power(struct drm_i915_private
*dev_priv
,
184 if (dev_priv
->power_domains
.init_power_on
== enable
)
188 intel_display_power_get(dev_priv
, POWER_DOMAIN_INIT
);
190 intel_display_power_put(dev_priv
, POWER_DOMAIN_INIT
);
192 dev_priv
->power_domains
.init_power_on
= enable
;
196 * Starting with Haswell, we have a "Power Down Well" that can be turned off
197 * when not needed anymore. We have 4 registers that can request the power well
198 * to be enabled, and it will only be disabled if none of the registers is
199 * requesting it to be enabled.
201 static void hsw_power_well_post_enable(struct drm_i915_private
*dev_priv
)
203 struct drm_device
*dev
= dev_priv
->dev
;
206 * After we re-enable the power well, if we touch VGA register 0x3d5
207 * we'll get unclaimed register interrupts. This stops after we write
208 * anything to the VGA MSR register. The vgacon module uses this
209 * register all the time, so if we unbind our driver and, as a
210 * consequence, bind vgacon, we'll get stuck in an infinite loop at
211 * console_unlock(). So make here we touch the VGA MSR register, making
212 * sure vgacon can keep working normally without triggering interrupts
213 * and error messages.
215 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
216 outb(inb(VGA_MSR_READ
), VGA_MSR_WRITE
);
217 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
219 if (IS_BROADWELL(dev
))
220 gen8_irq_power_well_post_enable(dev_priv
,
221 1 << PIPE_C
| 1 << PIPE_B
);
224 static void skl_power_well_post_enable(struct drm_i915_private
*dev_priv
,
225 struct i915_power_well
*power_well
)
227 struct drm_device
*dev
= dev_priv
->dev
;
230 * After we re-enable the power well, if we touch VGA register 0x3d5
231 * we'll get unclaimed register interrupts. This stops after we write
232 * anything to the VGA MSR register. The vgacon module uses this
233 * register all the time, so if we unbind our driver and, as a
234 * consequence, bind vgacon, we'll get stuck in an infinite loop at
235 * console_unlock(). So make here we touch the VGA MSR register, making
236 * sure vgacon can keep working normally without triggering interrupts
237 * and error messages.
239 if (power_well
->data
== SKL_DISP_PW_2
) {
240 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
241 outb(inb(VGA_MSR_READ
), VGA_MSR_WRITE
);
242 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
244 gen8_irq_power_well_post_enable(dev_priv
,
245 1 << PIPE_C
| 1 << PIPE_B
);
248 if (power_well
->data
== SKL_DISP_PW_1
) {
249 if (!dev_priv
->power_domains
.initializing
)
250 intel_prepare_ddi(dev
);
251 gen8_irq_power_well_post_enable(dev_priv
, 1 << PIPE_A
);
255 static void hsw_set_power_well(struct drm_i915_private
*dev_priv
,
256 struct i915_power_well
*power_well
, bool enable
)
258 bool is_enabled
, enable_requested
;
261 tmp
= I915_READ(HSW_PWR_WELL_DRIVER
);
262 is_enabled
= tmp
& HSW_PWR_WELL_STATE_ENABLED
;
263 enable_requested
= tmp
& HSW_PWR_WELL_ENABLE_REQUEST
;
266 if (!enable_requested
)
267 I915_WRITE(HSW_PWR_WELL_DRIVER
,
268 HSW_PWR_WELL_ENABLE_REQUEST
);
271 DRM_DEBUG_KMS("Enabling power well\n");
272 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER
) &
273 HSW_PWR_WELL_STATE_ENABLED
), 20))
274 DRM_ERROR("Timeout enabling power well\n");
275 hsw_power_well_post_enable(dev_priv
);
279 if (enable_requested
) {
280 I915_WRITE(HSW_PWR_WELL_DRIVER
, 0);
281 POSTING_READ(HSW_PWR_WELL_DRIVER
);
282 DRM_DEBUG_KMS("Requesting to disable the power well\n");
287 #define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
288 BIT(POWER_DOMAIN_TRANSCODER_A) | \
289 BIT(POWER_DOMAIN_PIPE_B) | \
290 BIT(POWER_DOMAIN_TRANSCODER_B) | \
291 BIT(POWER_DOMAIN_PIPE_C) | \
292 BIT(POWER_DOMAIN_TRANSCODER_C) | \
293 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
294 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
295 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
296 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
297 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
298 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
299 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
300 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
301 BIT(POWER_DOMAIN_PORT_DDI_E_2_LANES) | \
302 BIT(POWER_DOMAIN_AUX_B) | \
303 BIT(POWER_DOMAIN_AUX_C) | \
304 BIT(POWER_DOMAIN_AUX_D) | \
305 BIT(POWER_DOMAIN_AUDIO) | \
306 BIT(POWER_DOMAIN_VGA) | \
307 BIT(POWER_DOMAIN_INIT))
308 #define SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
309 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
310 BIT(POWER_DOMAIN_PLLS) | \
311 BIT(POWER_DOMAIN_PIPE_A) | \
312 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
313 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
314 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
315 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
316 BIT(POWER_DOMAIN_AUX_A) | \
317 BIT(POWER_DOMAIN_INIT))
318 #define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
319 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
320 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
321 BIT(POWER_DOMAIN_PORT_DDI_E_2_LANES) | \
322 BIT(POWER_DOMAIN_INIT))
323 #define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
324 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
325 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
326 BIT(POWER_DOMAIN_INIT))
327 #define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
328 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
329 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
330 BIT(POWER_DOMAIN_INIT))
331 #define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
332 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
333 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
334 BIT(POWER_DOMAIN_INIT))
335 #define SKL_DISPLAY_MISC_IO_POWER_DOMAINS ( \
336 SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
337 BIT(POWER_DOMAIN_PLLS) | \
338 BIT(POWER_DOMAIN_INIT))
339 #define SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
340 (POWER_DOMAIN_MASK & ~(SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
341 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
342 SKL_DISPLAY_DDI_A_E_POWER_DOMAINS | \
343 SKL_DISPLAY_DDI_B_POWER_DOMAINS | \
344 SKL_DISPLAY_DDI_C_POWER_DOMAINS | \
345 SKL_DISPLAY_DDI_D_POWER_DOMAINS | \
346 SKL_DISPLAY_MISC_IO_POWER_DOMAINS)) | \
347 BIT(POWER_DOMAIN_INIT))
349 #define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
350 BIT(POWER_DOMAIN_TRANSCODER_A) | \
351 BIT(POWER_DOMAIN_PIPE_B) | \
352 BIT(POWER_DOMAIN_TRANSCODER_B) | \
353 BIT(POWER_DOMAIN_PIPE_C) | \
354 BIT(POWER_DOMAIN_TRANSCODER_C) | \
355 BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
356 BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
357 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
358 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
359 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
360 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
361 BIT(POWER_DOMAIN_AUX_B) | \
362 BIT(POWER_DOMAIN_AUX_C) | \
363 BIT(POWER_DOMAIN_AUDIO) | \
364 BIT(POWER_DOMAIN_VGA) | \
365 BIT(POWER_DOMAIN_GMBUS) | \
366 BIT(POWER_DOMAIN_INIT))
367 #define BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
368 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
369 BIT(POWER_DOMAIN_PIPE_A) | \
370 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
371 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
372 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
373 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
374 BIT(POWER_DOMAIN_AUX_A) | \
375 BIT(POWER_DOMAIN_PLLS) | \
376 BIT(POWER_DOMAIN_INIT))
377 #define BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
378 (POWER_DOMAIN_MASK & ~(BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
379 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS)) | \
380 BIT(POWER_DOMAIN_INIT))
382 static void assert_can_enable_dc9(struct drm_i915_private
*dev_priv
)
384 struct drm_device
*dev
= dev_priv
->dev
;
386 WARN(!IS_BROXTON(dev
), "Platform doesn't support DC9.\n");
387 WARN((I915_READ(DC_STATE_EN
) & DC_STATE_EN_DC9
),
388 "DC9 already programmed to be enabled.\n");
389 WARN(I915_READ(DC_STATE_EN
) & DC_STATE_EN_UPTO_DC5
,
390 "DC5 still not disabled to enable DC9.\n");
391 WARN(I915_READ(HSW_PWR_WELL_DRIVER
), "Power well on.\n");
392 WARN(intel_irqs_enabled(dev_priv
), "Interrupts not disabled yet.\n");
395 * TODO: check for the following to verify the conditions to enter DC9
396 * state are satisfied:
397 * 1] Check relevant display engine registers to verify if mode set
398 * disable sequence was followed.
399 * 2] Check if display uninitialize sequence is initialized.
403 static void assert_can_disable_dc9(struct drm_i915_private
*dev_priv
)
405 WARN(intel_irqs_enabled(dev_priv
), "Interrupts not disabled yet.\n");
406 WARN(!(I915_READ(DC_STATE_EN
) & DC_STATE_EN_DC9
),
407 "DC9 already programmed to be disabled.\n");
408 WARN(I915_READ(DC_STATE_EN
) & DC_STATE_EN_UPTO_DC5
,
409 "DC5 still not disabled.\n");
412 * TODO: check for the following to verify DC9 state was indeed
413 * entered before programming to disable it:
414 * 1] Check relevant display engine registers to verify if mode
415 * set disable sequence was followed.
416 * 2] Check if display uninitialize sequence is initialized.
420 void bxt_enable_dc9(struct drm_i915_private
*dev_priv
)
424 assert_can_enable_dc9(dev_priv
);
426 DRM_DEBUG_KMS("Enabling DC9\n");
428 val
= I915_READ(DC_STATE_EN
);
429 val
|= DC_STATE_EN_DC9
;
430 I915_WRITE(DC_STATE_EN
, val
);
431 POSTING_READ(DC_STATE_EN
);
434 void bxt_disable_dc9(struct drm_i915_private
*dev_priv
)
438 assert_can_disable_dc9(dev_priv
);
440 DRM_DEBUG_KMS("Disabling DC9\n");
442 val
= I915_READ(DC_STATE_EN
);
443 val
&= ~DC_STATE_EN_DC9
;
444 I915_WRITE(DC_STATE_EN
, val
);
445 POSTING_READ(DC_STATE_EN
);
448 static void gen9_set_dc_state_debugmask_memory_up(
449 struct drm_i915_private
*dev_priv
)
453 /* The below bit doesn't need to be cleared ever afterwards */
454 val
= I915_READ(DC_STATE_DEBUG
);
455 if (!(val
& DC_STATE_DEBUG_MASK_MEMORY_UP
)) {
456 val
|= DC_STATE_DEBUG_MASK_MEMORY_UP
;
457 I915_WRITE(DC_STATE_DEBUG
, val
);
458 POSTING_READ(DC_STATE_DEBUG
);
462 static void assert_can_enable_dc5(struct drm_i915_private
*dev_priv
)
464 struct drm_device
*dev
= dev_priv
->dev
;
465 bool pg2_enabled
= intel_display_power_well_is_enabled(dev_priv
,
468 WARN_ONCE(!IS_SKYLAKE(dev
), "Platform doesn't support DC5.\n");
469 WARN_ONCE(!HAS_RUNTIME_PM(dev
), "Runtime PM not enabled.\n");
470 WARN_ONCE(pg2_enabled
, "PG2 not disabled to enable DC5.\n");
472 WARN_ONCE((I915_READ(DC_STATE_EN
) & DC_STATE_EN_UPTO_DC5
),
473 "DC5 already programmed to be enabled.\n");
474 WARN_ONCE(dev_priv
->pm
.suspended
,
475 "DC5 cannot be enabled, if platform is runtime-suspended.\n");
477 assert_csr_loaded(dev_priv
);
480 static void assert_can_disable_dc5(struct drm_i915_private
*dev_priv
)
482 bool pg2_enabled
= intel_display_power_well_is_enabled(dev_priv
,
485 * During initialization, the firmware may not be loaded yet.
486 * We still want to make sure that the DC enabling flag is cleared.
488 if (dev_priv
->power_domains
.initializing
)
491 WARN_ONCE(!pg2_enabled
, "PG2 not enabled to disable DC5.\n");
492 WARN_ONCE(dev_priv
->pm
.suspended
,
493 "Disabling of DC5 while platform is runtime-suspended should never happen.\n");
496 static void gen9_enable_dc5(struct drm_i915_private
*dev_priv
)
500 assert_can_enable_dc5(dev_priv
);
502 DRM_DEBUG_KMS("Enabling DC5\n");
504 gen9_set_dc_state_debugmask_memory_up(dev_priv
);
506 val
= I915_READ(DC_STATE_EN
);
507 val
&= ~DC_STATE_EN_UPTO_DC5_DC6_MASK
;
508 val
|= DC_STATE_EN_UPTO_DC5
;
509 I915_WRITE(DC_STATE_EN
, val
);
510 POSTING_READ(DC_STATE_EN
);
513 static void gen9_disable_dc5(struct drm_i915_private
*dev_priv
)
517 assert_can_disable_dc5(dev_priv
);
519 DRM_DEBUG_KMS("Disabling DC5\n");
521 val
= I915_READ(DC_STATE_EN
);
522 val
&= ~DC_STATE_EN_UPTO_DC5
;
523 I915_WRITE(DC_STATE_EN
, val
);
524 POSTING_READ(DC_STATE_EN
);
527 static void assert_can_enable_dc6(struct drm_i915_private
*dev_priv
)
529 struct drm_device
*dev
= dev_priv
->dev
;
531 WARN_ONCE(!IS_SKYLAKE(dev
), "Platform doesn't support DC6.\n");
532 WARN_ONCE(!HAS_RUNTIME_PM(dev
), "Runtime PM not enabled.\n");
533 WARN_ONCE(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
534 "Backlight is not disabled.\n");
535 WARN_ONCE((I915_READ(DC_STATE_EN
) & DC_STATE_EN_UPTO_DC6
),
536 "DC6 already programmed to be enabled.\n");
538 assert_csr_loaded(dev_priv
);
541 static void assert_can_disable_dc6(struct drm_i915_private
*dev_priv
)
544 * During initialization, the firmware may not be loaded yet.
545 * We still want to make sure that the DC enabling flag is cleared.
547 if (dev_priv
->power_domains
.initializing
)
550 assert_csr_loaded(dev_priv
);
551 WARN_ONCE(!(I915_READ(DC_STATE_EN
) & DC_STATE_EN_UPTO_DC6
),
552 "DC6 already programmed to be disabled.\n");
555 static void skl_enable_dc6(struct drm_i915_private
*dev_priv
)
559 assert_can_enable_dc6(dev_priv
);
561 DRM_DEBUG_KMS("Enabling DC6\n");
563 gen9_set_dc_state_debugmask_memory_up(dev_priv
);
565 val
= I915_READ(DC_STATE_EN
);
566 val
&= ~DC_STATE_EN_UPTO_DC5_DC6_MASK
;
567 val
|= DC_STATE_EN_UPTO_DC6
;
568 I915_WRITE(DC_STATE_EN
, val
);
569 POSTING_READ(DC_STATE_EN
);
572 static void skl_disable_dc6(struct drm_i915_private
*dev_priv
)
576 assert_can_disable_dc6(dev_priv
);
578 DRM_DEBUG_KMS("Disabling DC6\n");
580 val
= I915_READ(DC_STATE_EN
);
581 val
&= ~DC_STATE_EN_UPTO_DC6
;
582 I915_WRITE(DC_STATE_EN
, val
);
583 POSTING_READ(DC_STATE_EN
);
586 static void skl_set_power_well(struct drm_i915_private
*dev_priv
,
587 struct i915_power_well
*power_well
, bool enable
)
589 struct drm_device
*dev
= dev_priv
->dev
;
590 uint32_t tmp
, fuse_status
;
591 uint32_t req_mask
, state_mask
;
592 bool is_enabled
, enable_requested
, check_fuse_status
= false;
594 tmp
= I915_READ(HSW_PWR_WELL_DRIVER
);
595 fuse_status
= I915_READ(SKL_FUSE_STATUS
);
597 switch (power_well
->data
) {
599 if (wait_for((I915_READ(SKL_FUSE_STATUS
) &
600 SKL_FUSE_PG0_DIST_STATUS
), 1)) {
601 DRM_ERROR("PG0 not enabled\n");
606 if (!(fuse_status
& SKL_FUSE_PG1_DIST_STATUS
)) {
607 DRM_ERROR("PG1 in disabled state\n");
611 case SKL_DISP_PW_DDI_A_E
:
612 case SKL_DISP_PW_DDI_B
:
613 case SKL_DISP_PW_DDI_C
:
614 case SKL_DISP_PW_DDI_D
:
615 case SKL_DISP_PW_MISC_IO
:
618 WARN(1, "Unknown power well %lu\n", power_well
->data
);
622 req_mask
= SKL_POWER_WELL_REQ(power_well
->data
);
623 enable_requested
= tmp
& req_mask
;
624 state_mask
= SKL_POWER_WELL_STATE(power_well
->data
);
625 is_enabled
= tmp
& state_mask
;
628 if (!enable_requested
) {
629 WARN((tmp
& state_mask
) &&
630 !I915_READ(HSW_PWR_WELL_BIOS
),
631 "Invalid for power well status to be enabled, unless done by the BIOS, \
632 when request is to disable!\n");
633 if ((GEN9_ENABLE_DC5(dev
) || SKL_ENABLE_DC6(dev
)) &&
634 power_well
->data
== SKL_DISP_PW_2
) {
635 if (SKL_ENABLE_DC6(dev
)) {
636 skl_disable_dc6(dev_priv
);
638 * DDI buffer programming unnecessary during driver-load/resume
639 * as it's already done during modeset initialization then.
640 * It's also invalid here as encoder list is still uninitialized.
642 if (!dev_priv
->power_domains
.initializing
)
643 intel_prepare_ddi(dev
);
645 gen9_disable_dc5(dev_priv
);
648 I915_WRITE(HSW_PWR_WELL_DRIVER
, tmp
| req_mask
);
652 DRM_DEBUG_KMS("Enabling %s\n", power_well
->name
);
653 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER
) &
655 DRM_ERROR("%s enable timeout\n",
657 check_fuse_status
= true;
660 if (enable_requested
) {
661 if (IS_SKYLAKE(dev
) &&
662 (power_well
->data
== SKL_DISP_PW_1
) &&
663 (intel_csr_load_status_get(dev_priv
) == FW_LOADED
))
664 DRM_DEBUG_KMS("Not Disabling PW1, dmc will handle\n");
666 I915_WRITE(HSW_PWR_WELL_DRIVER
, tmp
& ~req_mask
);
667 POSTING_READ(HSW_PWR_WELL_DRIVER
);
668 DRM_DEBUG_KMS("Disabling %s\n", power_well
->name
);
671 if ((GEN9_ENABLE_DC5(dev
) || SKL_ENABLE_DC6(dev
)) &&
672 power_well
->data
== SKL_DISP_PW_2
) {
673 enum csr_state state
;
674 /* TODO: wait for a completion event or
675 * similar here instead of busy
676 * waiting using wait_for function.
678 wait_for((state
= intel_csr_load_status_get(dev_priv
)) !=
679 FW_UNINITIALIZED
, 1000);
680 if (state
!= FW_LOADED
)
681 DRM_DEBUG("CSR firmware not ready (%d)\n",
684 if (SKL_ENABLE_DC6(dev
))
685 skl_enable_dc6(dev_priv
);
687 gen9_enable_dc5(dev_priv
);
692 if (check_fuse_status
) {
693 if (power_well
->data
== SKL_DISP_PW_1
) {
694 if (wait_for((I915_READ(SKL_FUSE_STATUS
) &
695 SKL_FUSE_PG1_DIST_STATUS
), 1))
696 DRM_ERROR("PG1 distributing status timeout\n");
697 } else if (power_well
->data
== SKL_DISP_PW_2
) {
698 if (wait_for((I915_READ(SKL_FUSE_STATUS
) &
699 SKL_FUSE_PG2_DIST_STATUS
), 1))
700 DRM_ERROR("PG2 distributing status timeout\n");
704 if (enable
&& !is_enabled
)
705 skl_power_well_post_enable(dev_priv
, power_well
);
708 static void hsw_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
709 struct i915_power_well
*power_well
)
711 hsw_set_power_well(dev_priv
, power_well
, power_well
->count
> 0);
714 * We're taking over the BIOS, so clear any requests made by it since
715 * the driver is in charge now.
717 if (I915_READ(HSW_PWR_WELL_BIOS
) & HSW_PWR_WELL_ENABLE_REQUEST
)
718 I915_WRITE(HSW_PWR_WELL_BIOS
, 0);
721 static void hsw_power_well_enable(struct drm_i915_private
*dev_priv
,
722 struct i915_power_well
*power_well
)
724 hsw_set_power_well(dev_priv
, power_well
, true);
727 static void hsw_power_well_disable(struct drm_i915_private
*dev_priv
,
728 struct i915_power_well
*power_well
)
730 hsw_set_power_well(dev_priv
, power_well
, false);
733 static bool skl_power_well_enabled(struct drm_i915_private
*dev_priv
,
734 struct i915_power_well
*power_well
)
736 uint32_t mask
= SKL_POWER_WELL_REQ(power_well
->data
) |
737 SKL_POWER_WELL_STATE(power_well
->data
);
739 return (I915_READ(HSW_PWR_WELL_DRIVER
) & mask
) == mask
;
742 static void skl_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
743 struct i915_power_well
*power_well
)
745 skl_set_power_well(dev_priv
, power_well
, power_well
->count
> 0);
747 /* Clear any request made by BIOS as driver is taking over */
748 I915_WRITE(HSW_PWR_WELL_BIOS
, 0);
751 static void skl_power_well_enable(struct drm_i915_private
*dev_priv
,
752 struct i915_power_well
*power_well
)
754 skl_set_power_well(dev_priv
, power_well
, true);
757 static void skl_power_well_disable(struct drm_i915_private
*dev_priv
,
758 struct i915_power_well
*power_well
)
760 skl_set_power_well(dev_priv
, power_well
, false);
763 static void i9xx_always_on_power_well_noop(struct drm_i915_private
*dev_priv
,
764 struct i915_power_well
*power_well
)
768 static bool i9xx_always_on_power_well_enabled(struct drm_i915_private
*dev_priv
,
769 struct i915_power_well
*power_well
)
774 static void vlv_set_power_well(struct drm_i915_private
*dev_priv
,
775 struct i915_power_well
*power_well
, bool enable
)
777 enum punit_power_well power_well_id
= power_well
->data
;
782 mask
= PUNIT_PWRGT_MASK(power_well_id
);
783 state
= enable
? PUNIT_PWRGT_PWR_ON(power_well_id
) :
784 PUNIT_PWRGT_PWR_GATE(power_well_id
);
786 mutex_lock(&dev_priv
->rps
.hw_lock
);
789 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
794 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
);
797 vlv_punit_write(dev_priv
, PUNIT_REG_PWRGT_CTRL
, ctrl
);
799 if (wait_for(COND
, 100))
800 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
802 vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
));
807 mutex_unlock(&dev_priv
->rps
.hw_lock
);
810 static void vlv_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
811 struct i915_power_well
*power_well
)
813 vlv_set_power_well(dev_priv
, power_well
, power_well
->count
> 0);
816 static void vlv_power_well_enable(struct drm_i915_private
*dev_priv
,
817 struct i915_power_well
*power_well
)
819 vlv_set_power_well(dev_priv
, power_well
, true);
822 static void vlv_power_well_disable(struct drm_i915_private
*dev_priv
,
823 struct i915_power_well
*power_well
)
825 vlv_set_power_well(dev_priv
, power_well
, false);
828 static bool vlv_power_well_enabled(struct drm_i915_private
*dev_priv
,
829 struct i915_power_well
*power_well
)
831 int power_well_id
= power_well
->data
;
832 bool enabled
= false;
837 mask
= PUNIT_PWRGT_MASK(power_well_id
);
838 ctrl
= PUNIT_PWRGT_PWR_ON(power_well_id
);
840 mutex_lock(&dev_priv
->rps
.hw_lock
);
842 state
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_STATUS
) & mask
;
844 * We only ever set the power-on and power-gate states, anything
845 * else is unexpected.
847 WARN_ON(state
!= PUNIT_PWRGT_PWR_ON(power_well_id
) &&
848 state
!= PUNIT_PWRGT_PWR_GATE(power_well_id
));
853 * A transient state at this point would mean some unexpected party
854 * is poking at the power controls too.
856 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
) & mask
;
857 WARN_ON(ctrl
!= state
);
859 mutex_unlock(&dev_priv
->rps
.hw_lock
);
864 static void vlv_display_power_well_init(struct drm_i915_private
*dev_priv
)
869 * Enable the CRI clock source so we can get at the
870 * display and the reference clock for VGA
871 * hotplug / manual detection. Supposedly DSI also
872 * needs the ref clock up and running.
874 * CHV DPLL B/C have some issues if VGA mode is enabled.
876 for_each_pipe(dev_priv
->dev
, pipe
) {
877 u32 val
= I915_READ(DPLL(pipe
));
879 val
|= DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
881 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
883 I915_WRITE(DPLL(pipe
), val
);
886 spin_lock_irq(&dev_priv
->irq_lock
);
887 valleyview_enable_display_irqs(dev_priv
);
888 spin_unlock_irq(&dev_priv
->irq_lock
);
891 * During driver initialization/resume we can avoid restoring the
892 * part of the HW/SW state that will be inited anyway explicitly.
894 if (dev_priv
->power_domains
.initializing
)
897 intel_hpd_init(dev_priv
);
899 i915_redisable_vga_power_on(dev_priv
->dev
);
902 static void vlv_display_power_well_deinit(struct drm_i915_private
*dev_priv
)
904 spin_lock_irq(&dev_priv
->irq_lock
);
905 valleyview_disable_display_irqs(dev_priv
);
906 spin_unlock_irq(&dev_priv
->irq_lock
);
908 vlv_power_sequencer_reset(dev_priv
);
911 static void vlv_display_power_well_enable(struct drm_i915_private
*dev_priv
,
912 struct i915_power_well
*power_well
)
914 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DISP2D
);
916 vlv_set_power_well(dev_priv
, power_well
, true);
918 vlv_display_power_well_init(dev_priv
);
921 static void vlv_display_power_well_disable(struct drm_i915_private
*dev_priv
,
922 struct i915_power_well
*power_well
)
924 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DISP2D
);
926 vlv_display_power_well_deinit(dev_priv
);
928 vlv_set_power_well(dev_priv
, power_well
, false);
931 static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private
*dev_priv
,
932 struct i915_power_well
*power_well
)
934 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
);
936 /* since ref/cri clock was enabled */
937 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
939 vlv_set_power_well(dev_priv
, power_well
, true);
942 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
943 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
944 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
945 * b. The other bits such as sfr settings / modesel may all
948 * This should only be done on init and resume from S3 with
949 * both PLLs disabled, or we risk losing DPIO and PLL
952 I915_WRITE(DPIO_CTL
, I915_READ(DPIO_CTL
) | DPIO_CMNRST
);
955 static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private
*dev_priv
,
956 struct i915_power_well
*power_well
)
960 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
);
962 for_each_pipe(dev_priv
, pipe
)
963 assert_pll_disabled(dev_priv
, pipe
);
965 /* Assert common reset */
966 I915_WRITE(DPIO_CTL
, I915_READ(DPIO_CTL
) & ~DPIO_CMNRST
);
968 vlv_set_power_well(dev_priv
, power_well
, false);
971 #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
973 static struct i915_power_well
*lookup_power_well(struct drm_i915_private
*dev_priv
,
976 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
977 struct i915_power_well
*power_well
;
980 for_each_power_well(i
, power_well
, POWER_DOMAIN_MASK
, power_domains
) {
981 if (power_well
->data
== power_well_id
)
988 #define BITS_SET(val, bits) (((val) & (bits)) == (bits))
990 static void assert_chv_phy_status(struct drm_i915_private
*dev_priv
)
992 struct i915_power_well
*cmn_bc
=
993 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
);
994 struct i915_power_well
*cmn_d
=
995 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_D
);
996 u32 phy_control
= dev_priv
->chv_phy_control
;
998 u32 phy_status_mask
= 0xffffffff;
1002 * The BIOS can leave the PHY is some weird state
1003 * where it doesn't fully power down some parts.
1004 * Disable the asserts until the PHY has been fully
1005 * reset (ie. the power well has been disabled at
1008 if (!dev_priv
->chv_phy_assert
[DPIO_PHY0
])
1009 phy_status_mask
&= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0
, DPIO_CH0
) |
1010 PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH0
, 0) |
1011 PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH0
, 1) |
1012 PHY_STATUS_CMN_LDO(DPIO_PHY0
, DPIO_CH1
) |
1013 PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH1
, 0) |
1014 PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH1
, 1));
1016 if (!dev_priv
->chv_phy_assert
[DPIO_PHY1
])
1017 phy_status_mask
&= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1
, DPIO_CH0
) |
1018 PHY_STATUS_SPLINE_LDO(DPIO_PHY1
, DPIO_CH0
, 0) |
1019 PHY_STATUS_SPLINE_LDO(DPIO_PHY1
, DPIO_CH0
, 1));
1021 if (cmn_bc
->ops
->is_enabled(dev_priv
, cmn_bc
)) {
1022 phy_status
|= PHY_POWERGOOD(DPIO_PHY0
);
1024 /* this assumes override is only used to enable lanes */
1025 if ((phy_control
& PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0
, DPIO_CH0
)) == 0)
1026 phy_control
|= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0
, DPIO_CH0
);
1028 if ((phy_control
& PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0
, DPIO_CH1
)) == 0)
1029 phy_control
|= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0
, DPIO_CH1
);
1031 /* CL1 is on whenever anything is on in either channel */
1032 if (BITS_SET(phy_control
,
1033 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0
, DPIO_CH0
) |
1034 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0
, DPIO_CH1
)))
1035 phy_status
|= PHY_STATUS_CMN_LDO(DPIO_PHY0
, DPIO_CH0
);
1038 * The DPLLB check accounts for the pipe B + port A usage
1039 * with CL2 powered up but all the lanes in the second channel
1042 if (BITS_SET(phy_control
,
1043 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0
, DPIO_CH1
)) &&
1044 (I915_READ(DPLL(PIPE_B
)) & DPLL_VCO_ENABLE
) == 0)
1045 phy_status
|= PHY_STATUS_CMN_LDO(DPIO_PHY0
, DPIO_CH1
);
1047 if (BITS_SET(phy_control
,
1048 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0
, DPIO_CH0
)))
1049 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH0
, 0);
1050 if (BITS_SET(phy_control
,
1051 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0
, DPIO_CH0
)))
1052 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH0
, 1);
1054 if (BITS_SET(phy_control
,
1055 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0
, DPIO_CH1
)))
1056 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH1
, 0);
1057 if (BITS_SET(phy_control
,
1058 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0
, DPIO_CH1
)))
1059 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH1
, 1);
1062 if (cmn_d
->ops
->is_enabled(dev_priv
, cmn_d
)) {
1063 phy_status
|= PHY_POWERGOOD(DPIO_PHY1
);
1065 /* this assumes override is only used to enable lanes */
1066 if ((phy_control
& PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1
, DPIO_CH0
)) == 0)
1067 phy_control
|= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1
, DPIO_CH0
);
1069 if (BITS_SET(phy_control
,
1070 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1
, DPIO_CH0
)))
1071 phy_status
|= PHY_STATUS_CMN_LDO(DPIO_PHY1
, DPIO_CH0
);
1073 if (BITS_SET(phy_control
,
1074 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1
, DPIO_CH0
)))
1075 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY1
, DPIO_CH0
, 0);
1076 if (BITS_SET(phy_control
,
1077 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1
, DPIO_CH0
)))
1078 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY1
, DPIO_CH0
, 1);
1081 phy_status
&= phy_status_mask
;
1084 * The PHY may be busy with some initial calibration and whatnot,
1085 * so the power state can take a while to actually change.
1087 if (wait_for((tmp
= I915_READ(DISPLAY_PHY_STATUS
) & phy_status_mask
) == phy_status
, 10))
1088 WARN(phy_status
!= tmp
,
1089 "Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1090 tmp
, phy_status
, dev_priv
->chv_phy_control
);
1095 static void chv_dpio_cmn_power_well_enable(struct drm_i915_private
*dev_priv
,
1096 struct i915_power_well
*power_well
)
1102 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
&&
1103 power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_D
);
1105 if (power_well
->data
== PUNIT_POWER_WELL_DPIO_CMN_BC
) {
1113 /* since ref/cri clock was enabled */
1114 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1115 vlv_set_power_well(dev_priv
, power_well
, true);
1117 /* Poll for phypwrgood signal */
1118 if (wait_for(I915_READ(DISPLAY_PHY_STATUS
) & PHY_POWERGOOD(phy
), 1))
1119 DRM_ERROR("Display PHY %d is not power up\n", phy
);
1121 mutex_lock(&dev_priv
->sb_lock
);
1123 /* Enable dynamic power down */
1124 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW28
);
1125 tmp
|= DPIO_DYNPWRDOWNEN_CH0
| DPIO_CL1POWERDOWNEN
|
1126 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ
;
1127 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW28
, tmp
);
1129 if (power_well
->data
== PUNIT_POWER_WELL_DPIO_CMN_BC
) {
1130 tmp
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW6_CH1
);
1131 tmp
|= DPIO_DYNPWRDOWNEN_CH1
;
1132 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW6_CH1
, tmp
);
1135 * Force the non-existing CL2 off. BXT does this
1136 * too, so maybe it saves some power even though
1137 * CL2 doesn't exist?
1139 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW30
);
1140 tmp
|= DPIO_CL2_LDOFUSE_PWRENB
;
1141 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW30
, tmp
);
1144 mutex_unlock(&dev_priv
->sb_lock
);
1146 dev_priv
->chv_phy_control
|= PHY_COM_LANE_RESET_DEASSERT(phy
);
1147 I915_WRITE(DISPLAY_PHY_CONTROL
, dev_priv
->chv_phy_control
);
1149 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1150 phy
, dev_priv
->chv_phy_control
);
1152 assert_chv_phy_status(dev_priv
);
1155 static void chv_dpio_cmn_power_well_disable(struct drm_i915_private
*dev_priv
,
1156 struct i915_power_well
*power_well
)
1160 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
&&
1161 power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_D
);
1163 if (power_well
->data
== PUNIT_POWER_WELL_DPIO_CMN_BC
) {
1165 assert_pll_disabled(dev_priv
, PIPE_A
);
1166 assert_pll_disabled(dev_priv
, PIPE_B
);
1169 assert_pll_disabled(dev_priv
, PIPE_C
);
1172 dev_priv
->chv_phy_control
&= ~PHY_COM_LANE_RESET_DEASSERT(phy
);
1173 I915_WRITE(DISPLAY_PHY_CONTROL
, dev_priv
->chv_phy_control
);
1175 vlv_set_power_well(dev_priv
, power_well
, false);
1177 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1178 phy
, dev_priv
->chv_phy_control
);
1180 /* PHY is fully reset now, so we can enable the PHY state asserts */
1181 dev_priv
->chv_phy_assert
[phy
] = true;
1183 assert_chv_phy_status(dev_priv
);
1186 static void assert_chv_phy_powergate(struct drm_i915_private
*dev_priv
, enum dpio_phy phy
,
1187 enum dpio_channel ch
, bool override
, unsigned int mask
)
1189 enum pipe pipe
= phy
== DPIO_PHY0
? PIPE_A
: PIPE_C
;
1190 u32 reg
, val
, expected
, actual
;
1193 * The BIOS can leave the PHY is some weird state
1194 * where it doesn't fully power down some parts.
1195 * Disable the asserts until the PHY has been fully
1196 * reset (ie. the power well has been disabled at
1199 if (!dev_priv
->chv_phy_assert
[phy
])
1203 reg
= _CHV_CMN_DW0_CH0
;
1205 reg
= _CHV_CMN_DW6_CH1
;
1207 mutex_lock(&dev_priv
->sb_lock
);
1208 val
= vlv_dpio_read(dev_priv
, pipe
, reg
);
1209 mutex_unlock(&dev_priv
->sb_lock
);
1212 * This assumes !override is only used when the port is disabled.
1213 * All lanes should power down even without the override when
1214 * the port is disabled.
1216 if (!override
|| mask
== 0xf) {
1217 expected
= DPIO_ALLDL_POWERDOWN
| DPIO_ANYDL_POWERDOWN
;
1219 * If CH1 common lane is not active anymore
1220 * (eg. for pipe B DPLL) the entire channel will
1221 * shut down, which causes the common lane registers
1222 * to read as 0. That means we can't actually check
1223 * the lane power down status bits, but as the entire
1224 * register reads as 0 it's a good indication that the
1225 * channel is indeed entirely powered down.
1227 if (ch
== DPIO_CH1
&& val
== 0)
1229 } else if (mask
!= 0x0) {
1230 expected
= DPIO_ANYDL_POWERDOWN
;
1236 actual
= val
>> DPIO_ANYDL_POWERDOWN_SHIFT_CH0
;
1238 actual
= val
>> DPIO_ANYDL_POWERDOWN_SHIFT_CH1
;
1239 actual
&= DPIO_ALLDL_POWERDOWN
| DPIO_ANYDL_POWERDOWN
;
1241 WARN(actual
!= expected
,
1242 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1243 !!(actual
& DPIO_ALLDL_POWERDOWN
), !!(actual
& DPIO_ANYDL_POWERDOWN
),
1244 !!(expected
& DPIO_ALLDL_POWERDOWN
), !!(expected
& DPIO_ANYDL_POWERDOWN
),
1248 bool chv_phy_powergate_ch(struct drm_i915_private
*dev_priv
, enum dpio_phy phy
,
1249 enum dpio_channel ch
, bool override
)
1251 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
1254 mutex_lock(&power_domains
->lock
);
1256 was_override
= dev_priv
->chv_phy_control
& PHY_CH_POWER_DOWN_OVRD_EN(phy
, ch
);
1258 if (override
== was_override
)
1262 dev_priv
->chv_phy_control
|= PHY_CH_POWER_DOWN_OVRD_EN(phy
, ch
);
1264 dev_priv
->chv_phy_control
&= ~PHY_CH_POWER_DOWN_OVRD_EN(phy
, ch
);
1266 I915_WRITE(DISPLAY_PHY_CONTROL
, dev_priv
->chv_phy_control
);
1268 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1269 phy
, ch
, dev_priv
->chv_phy_control
);
1271 assert_chv_phy_status(dev_priv
);
1274 mutex_unlock(&power_domains
->lock
);
1276 return was_override
;
1279 void chv_phy_powergate_lanes(struct intel_encoder
*encoder
,
1280 bool override
, unsigned int mask
)
1282 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
1283 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
1284 enum dpio_phy phy
= vlv_dport_to_phy(enc_to_dig_port(&encoder
->base
));
1285 enum dpio_channel ch
= vlv_dport_to_channel(enc_to_dig_port(&encoder
->base
));
1287 mutex_lock(&power_domains
->lock
);
1289 dev_priv
->chv_phy_control
&= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy
, ch
);
1290 dev_priv
->chv_phy_control
|= PHY_CH_POWER_DOWN_OVRD(mask
, phy
, ch
);
1293 dev_priv
->chv_phy_control
|= PHY_CH_POWER_DOWN_OVRD_EN(phy
, ch
);
1295 dev_priv
->chv_phy_control
&= ~PHY_CH_POWER_DOWN_OVRD_EN(phy
, ch
);
1297 I915_WRITE(DISPLAY_PHY_CONTROL
, dev_priv
->chv_phy_control
);
1299 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1300 phy
, ch
, mask
, dev_priv
->chv_phy_control
);
1302 assert_chv_phy_status(dev_priv
);
1304 assert_chv_phy_powergate(dev_priv
, phy
, ch
, override
, mask
);
1306 mutex_unlock(&power_domains
->lock
);
1309 static bool chv_pipe_power_well_enabled(struct drm_i915_private
*dev_priv
,
1310 struct i915_power_well
*power_well
)
1312 enum pipe pipe
= power_well
->data
;
1316 mutex_lock(&dev_priv
->rps
.hw_lock
);
1318 state
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) & DP_SSS_MASK(pipe
);
1320 * We only ever set the power-on and power-gate states, anything
1321 * else is unexpected.
1323 WARN_ON(state
!= DP_SSS_PWR_ON(pipe
) && state
!= DP_SSS_PWR_GATE(pipe
));
1324 enabled
= state
== DP_SSS_PWR_ON(pipe
);
1327 * A transient state at this point would mean some unexpected party
1328 * is poking at the power controls too.
1330 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) & DP_SSC_MASK(pipe
);
1331 WARN_ON(ctrl
<< 16 != state
);
1333 mutex_unlock(&dev_priv
->rps
.hw_lock
);
1338 static void chv_set_pipe_power_well(struct drm_i915_private
*dev_priv
,
1339 struct i915_power_well
*power_well
,
1342 enum pipe pipe
= power_well
->data
;
1346 state
= enable
? DP_SSS_PWR_ON(pipe
) : DP_SSS_PWR_GATE(pipe
);
1348 mutex_lock(&dev_priv
->rps
.hw_lock
);
1351 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1356 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
1357 ctrl
&= ~DP_SSC_MASK(pipe
);
1358 ctrl
|= enable
? DP_SSC_PWR_ON(pipe
) : DP_SSC_PWR_GATE(pipe
);
1359 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, ctrl
);
1361 if (wait_for(COND
, 100))
1362 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
1364 vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
));
1369 mutex_unlock(&dev_priv
->rps
.hw_lock
);
1372 static void chv_pipe_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
1373 struct i915_power_well
*power_well
)
1375 WARN_ON_ONCE(power_well
->data
!= PIPE_A
);
1377 chv_set_pipe_power_well(dev_priv
, power_well
, power_well
->count
> 0);
1380 static void chv_pipe_power_well_enable(struct drm_i915_private
*dev_priv
,
1381 struct i915_power_well
*power_well
)
1383 WARN_ON_ONCE(power_well
->data
!= PIPE_A
);
1385 chv_set_pipe_power_well(dev_priv
, power_well
, true);
1387 vlv_display_power_well_init(dev_priv
);
1390 static void chv_pipe_power_well_disable(struct drm_i915_private
*dev_priv
,
1391 struct i915_power_well
*power_well
)
1393 WARN_ON_ONCE(power_well
->data
!= PIPE_A
);
1395 vlv_display_power_well_deinit(dev_priv
);
1397 chv_set_pipe_power_well(dev_priv
, power_well
, false);
1401 * intel_display_power_get - grab a power domain reference
1402 * @dev_priv: i915 device instance
1403 * @domain: power domain to reference
1405 * This function grabs a power domain reference for @domain and ensures that the
1406 * power domain and all its parents are powered up. Therefore users should only
1407 * grab a reference to the innermost power domain they need.
1409 * Any power domain reference obtained by this function must have a symmetric
1410 * call to intel_display_power_put() to release the reference again.
1412 void intel_display_power_get(struct drm_i915_private
*dev_priv
,
1413 enum intel_display_power_domain domain
)
1415 struct i915_power_domains
*power_domains
;
1416 struct i915_power_well
*power_well
;
1419 intel_runtime_pm_get(dev_priv
);
1421 power_domains
= &dev_priv
->power_domains
;
1423 mutex_lock(&power_domains
->lock
);
1425 for_each_power_well(i
, power_well
, BIT(domain
), power_domains
) {
1426 if (!power_well
->count
++)
1427 intel_power_well_enable(dev_priv
, power_well
);
1430 power_domains
->domain_use_count
[domain
]++;
1432 mutex_unlock(&power_domains
->lock
);
1436 * intel_display_power_put - release a power domain reference
1437 * @dev_priv: i915 device instance
1438 * @domain: power domain to reference
1440 * This function drops the power domain reference obtained by
1441 * intel_display_power_get() and might power down the corresponding hardware
1442 * block right away if this is the last reference.
1444 void intel_display_power_put(struct drm_i915_private
*dev_priv
,
1445 enum intel_display_power_domain domain
)
1447 struct i915_power_domains
*power_domains
;
1448 struct i915_power_well
*power_well
;
1451 power_domains
= &dev_priv
->power_domains
;
1453 mutex_lock(&power_domains
->lock
);
1455 WARN_ON(!power_domains
->domain_use_count
[domain
]);
1456 power_domains
->domain_use_count
[domain
]--;
1458 for_each_power_well_rev(i
, power_well
, BIT(domain
), power_domains
) {
1459 WARN_ON(!power_well
->count
);
1461 if (!--power_well
->count
&& i915
.disable_power_well
)
1462 intel_power_well_disable(dev_priv
, power_well
);
1465 mutex_unlock(&power_domains
->lock
);
1467 intel_runtime_pm_put(dev_priv
);
1470 #define HSW_ALWAYS_ON_POWER_DOMAINS ( \
1471 BIT(POWER_DOMAIN_PIPE_A) | \
1472 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
1473 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
1474 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
1475 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1476 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1477 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1478 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1479 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
1480 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
1481 BIT(POWER_DOMAIN_PORT_CRT) | \
1482 BIT(POWER_DOMAIN_PLLS) | \
1483 BIT(POWER_DOMAIN_AUX_A) | \
1484 BIT(POWER_DOMAIN_AUX_B) | \
1485 BIT(POWER_DOMAIN_AUX_C) | \
1486 BIT(POWER_DOMAIN_AUX_D) | \
1487 BIT(POWER_DOMAIN_GMBUS) | \
1488 BIT(POWER_DOMAIN_INIT))
1489 #define HSW_DISPLAY_POWER_DOMAINS ( \
1490 (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
1491 BIT(POWER_DOMAIN_INIT))
1493 #define BDW_ALWAYS_ON_POWER_DOMAINS ( \
1494 HSW_ALWAYS_ON_POWER_DOMAINS | \
1495 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
1496 #define BDW_DISPLAY_POWER_DOMAINS ( \
1497 (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
1498 BIT(POWER_DOMAIN_INIT))
1500 #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
1501 #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
1503 #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
1504 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1505 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1506 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1507 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1508 BIT(POWER_DOMAIN_PORT_CRT) | \
1509 BIT(POWER_DOMAIN_AUX_B) | \
1510 BIT(POWER_DOMAIN_AUX_C) | \
1511 BIT(POWER_DOMAIN_INIT))
1513 #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
1514 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1515 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1516 BIT(POWER_DOMAIN_AUX_B) | \
1517 BIT(POWER_DOMAIN_INIT))
1519 #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
1520 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1521 BIT(POWER_DOMAIN_AUX_B) | \
1522 BIT(POWER_DOMAIN_INIT))
1524 #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
1525 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1526 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1527 BIT(POWER_DOMAIN_AUX_C) | \
1528 BIT(POWER_DOMAIN_INIT))
1530 #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
1531 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1532 BIT(POWER_DOMAIN_AUX_C) | \
1533 BIT(POWER_DOMAIN_INIT))
1535 #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
1536 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
1537 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
1538 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
1539 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
1540 BIT(POWER_DOMAIN_AUX_B) | \
1541 BIT(POWER_DOMAIN_AUX_C) | \
1542 BIT(POWER_DOMAIN_INIT))
1544 #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
1545 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
1546 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
1547 BIT(POWER_DOMAIN_AUX_D) | \
1548 BIT(POWER_DOMAIN_INIT))
1550 static const struct i915_power_well_ops i9xx_always_on_power_well_ops
= {
1551 .sync_hw
= i9xx_always_on_power_well_noop
,
1552 .enable
= i9xx_always_on_power_well_noop
,
1553 .disable
= i9xx_always_on_power_well_noop
,
1554 .is_enabled
= i9xx_always_on_power_well_enabled
,
1557 static const struct i915_power_well_ops chv_pipe_power_well_ops
= {
1558 .sync_hw
= chv_pipe_power_well_sync_hw
,
1559 .enable
= chv_pipe_power_well_enable
,
1560 .disable
= chv_pipe_power_well_disable
,
1561 .is_enabled
= chv_pipe_power_well_enabled
,
1564 static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops
= {
1565 .sync_hw
= vlv_power_well_sync_hw
,
1566 .enable
= chv_dpio_cmn_power_well_enable
,
1567 .disable
= chv_dpio_cmn_power_well_disable
,
1568 .is_enabled
= vlv_power_well_enabled
,
1571 static struct i915_power_well i9xx_always_on_power_well
[] = {
1573 .name
= "always-on",
1575 .domains
= POWER_DOMAIN_MASK
,
1576 .ops
= &i9xx_always_on_power_well_ops
,
1580 static const struct i915_power_well_ops hsw_power_well_ops
= {
1581 .sync_hw
= hsw_power_well_sync_hw
,
1582 .enable
= hsw_power_well_enable
,
1583 .disable
= hsw_power_well_disable
,
1584 .is_enabled
= hsw_power_well_enabled
,
1587 static const struct i915_power_well_ops skl_power_well_ops
= {
1588 .sync_hw
= skl_power_well_sync_hw
,
1589 .enable
= skl_power_well_enable
,
1590 .disable
= skl_power_well_disable
,
1591 .is_enabled
= skl_power_well_enabled
,
1594 static struct i915_power_well hsw_power_wells
[] = {
1596 .name
= "always-on",
1598 .domains
= HSW_ALWAYS_ON_POWER_DOMAINS
,
1599 .ops
= &i9xx_always_on_power_well_ops
,
1603 .domains
= HSW_DISPLAY_POWER_DOMAINS
,
1604 .ops
= &hsw_power_well_ops
,
1608 static struct i915_power_well bdw_power_wells
[] = {
1610 .name
= "always-on",
1612 .domains
= BDW_ALWAYS_ON_POWER_DOMAINS
,
1613 .ops
= &i9xx_always_on_power_well_ops
,
1617 .domains
= BDW_DISPLAY_POWER_DOMAINS
,
1618 .ops
= &hsw_power_well_ops
,
1622 static const struct i915_power_well_ops vlv_display_power_well_ops
= {
1623 .sync_hw
= vlv_power_well_sync_hw
,
1624 .enable
= vlv_display_power_well_enable
,
1625 .disable
= vlv_display_power_well_disable
,
1626 .is_enabled
= vlv_power_well_enabled
,
1629 static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops
= {
1630 .sync_hw
= vlv_power_well_sync_hw
,
1631 .enable
= vlv_dpio_cmn_power_well_enable
,
1632 .disable
= vlv_dpio_cmn_power_well_disable
,
1633 .is_enabled
= vlv_power_well_enabled
,
1636 static const struct i915_power_well_ops vlv_dpio_power_well_ops
= {
1637 .sync_hw
= vlv_power_well_sync_hw
,
1638 .enable
= vlv_power_well_enable
,
1639 .disable
= vlv_power_well_disable
,
1640 .is_enabled
= vlv_power_well_enabled
,
1643 static struct i915_power_well vlv_power_wells
[] = {
1645 .name
= "always-on",
1647 .domains
= VLV_ALWAYS_ON_POWER_DOMAINS
,
1648 .ops
= &i9xx_always_on_power_well_ops
,
1652 .domains
= VLV_DISPLAY_POWER_DOMAINS
,
1653 .data
= PUNIT_POWER_WELL_DISP2D
,
1654 .ops
= &vlv_display_power_well_ops
,
1657 .name
= "dpio-tx-b-01",
1658 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
1659 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
1660 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
1661 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
1662 .ops
= &vlv_dpio_power_well_ops
,
1663 .data
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_01
,
1666 .name
= "dpio-tx-b-23",
1667 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
1668 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
1669 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
1670 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
1671 .ops
= &vlv_dpio_power_well_ops
,
1672 .data
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_23
,
1675 .name
= "dpio-tx-c-01",
1676 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
1677 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
1678 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
1679 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
1680 .ops
= &vlv_dpio_power_well_ops
,
1681 .data
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_01
,
1684 .name
= "dpio-tx-c-23",
1685 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
1686 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
1687 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
1688 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
1689 .ops
= &vlv_dpio_power_well_ops
,
1690 .data
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_23
,
1693 .name
= "dpio-common",
1694 .domains
= VLV_DPIO_CMN_BC_POWER_DOMAINS
,
1695 .data
= PUNIT_POWER_WELL_DPIO_CMN_BC
,
1696 .ops
= &vlv_dpio_cmn_power_well_ops
,
1700 static struct i915_power_well chv_power_wells
[] = {
1702 .name
= "always-on",
1704 .domains
= VLV_ALWAYS_ON_POWER_DOMAINS
,
1705 .ops
= &i9xx_always_on_power_well_ops
,
1710 * Pipe A power well is the new disp2d well. Pipe B and C
1711 * power wells don't actually exist. Pipe A power well is
1712 * required for any pipe to work.
1714 .domains
= VLV_DISPLAY_POWER_DOMAINS
,
1716 .ops
= &chv_pipe_power_well_ops
,
1719 .name
= "dpio-common-bc",
1720 .domains
= CHV_DPIO_CMN_BC_POWER_DOMAINS
,
1721 .data
= PUNIT_POWER_WELL_DPIO_CMN_BC
,
1722 .ops
= &chv_dpio_cmn_power_well_ops
,
1725 .name
= "dpio-common-d",
1726 .domains
= CHV_DPIO_CMN_D_POWER_DOMAINS
,
1727 .data
= PUNIT_POWER_WELL_DPIO_CMN_D
,
1728 .ops
= &chv_dpio_cmn_power_well_ops
,
1732 bool intel_display_power_well_is_enabled(struct drm_i915_private
*dev_priv
,
1735 struct i915_power_well
*power_well
;
1738 power_well
= lookup_power_well(dev_priv
, power_well_id
);
1739 ret
= power_well
->ops
->is_enabled(dev_priv
, power_well
);
1744 static struct i915_power_well skl_power_wells
[] = {
1746 .name
= "always-on",
1748 .domains
= SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS
,
1749 .ops
= &i9xx_always_on_power_well_ops
,
1752 .name
= "power well 1",
1753 .domains
= SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS
,
1754 .ops
= &skl_power_well_ops
,
1755 .data
= SKL_DISP_PW_1
,
1758 .name
= "MISC IO power well",
1759 .domains
= SKL_DISPLAY_MISC_IO_POWER_DOMAINS
,
1760 .ops
= &skl_power_well_ops
,
1761 .data
= SKL_DISP_PW_MISC_IO
,
1764 .name
= "power well 2",
1765 .domains
= SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS
,
1766 .ops
= &skl_power_well_ops
,
1767 .data
= SKL_DISP_PW_2
,
1770 .name
= "DDI A/E power well",
1771 .domains
= SKL_DISPLAY_DDI_A_E_POWER_DOMAINS
,
1772 .ops
= &skl_power_well_ops
,
1773 .data
= SKL_DISP_PW_DDI_A_E
,
1776 .name
= "DDI B power well",
1777 .domains
= SKL_DISPLAY_DDI_B_POWER_DOMAINS
,
1778 .ops
= &skl_power_well_ops
,
1779 .data
= SKL_DISP_PW_DDI_B
,
1782 .name
= "DDI C power well",
1783 .domains
= SKL_DISPLAY_DDI_C_POWER_DOMAINS
,
1784 .ops
= &skl_power_well_ops
,
1785 .data
= SKL_DISP_PW_DDI_C
,
1788 .name
= "DDI D power well",
1789 .domains
= SKL_DISPLAY_DDI_D_POWER_DOMAINS
,
1790 .ops
= &skl_power_well_ops
,
1791 .data
= SKL_DISP_PW_DDI_D
,
1795 static struct i915_power_well bxt_power_wells
[] = {
1797 .name
= "always-on",
1799 .domains
= BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS
,
1800 .ops
= &i9xx_always_on_power_well_ops
,
1803 .name
= "power well 1",
1804 .domains
= BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS
,
1805 .ops
= &skl_power_well_ops
,
1806 .data
= SKL_DISP_PW_1
,
1809 .name
= "power well 2",
1810 .domains
= BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS
,
1811 .ops
= &skl_power_well_ops
,
1812 .data
= SKL_DISP_PW_2
,
1817 sanitize_disable_power_well_option(const struct drm_i915_private
*dev_priv
,
1818 int disable_power_well
)
1820 if (disable_power_well
>= 0)
1821 return !!disable_power_well
;
1823 if (IS_SKYLAKE(dev_priv
)) {
1824 DRM_DEBUG_KMS("Disabling display power well support\n");
1831 #define set_power_wells(power_domains, __power_wells) ({ \
1832 (power_domains)->power_wells = (__power_wells); \
1833 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
1837 * intel_power_domains_init - initializes the power domain structures
1838 * @dev_priv: i915 device instance
1840 * Initializes the power domain structures for @dev_priv depending upon the
1841 * supported platform.
1843 int intel_power_domains_init(struct drm_i915_private
*dev_priv
)
1845 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
1847 i915
.disable_power_well
= sanitize_disable_power_well_option(dev_priv
,
1848 i915
.disable_power_well
);
1850 BUILD_BUG_ON(POWER_DOMAIN_NUM
> 31);
1852 mutex_init(&power_domains
->lock
);
1855 * The enabling order will be from lower to higher indexed wells,
1856 * the disabling order is reversed.
1858 if (IS_HASWELL(dev_priv
->dev
)) {
1859 set_power_wells(power_domains
, hsw_power_wells
);
1860 } else if (IS_BROADWELL(dev_priv
->dev
)) {
1861 set_power_wells(power_domains
, bdw_power_wells
);
1862 } else if (IS_SKYLAKE(dev_priv
->dev
)) {
1863 set_power_wells(power_domains
, skl_power_wells
);
1864 } else if (IS_BROXTON(dev_priv
->dev
)) {
1865 set_power_wells(power_domains
, bxt_power_wells
);
1866 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
1867 set_power_wells(power_domains
, chv_power_wells
);
1868 } else if (IS_VALLEYVIEW(dev_priv
->dev
)) {
1869 set_power_wells(power_domains
, vlv_power_wells
);
1871 set_power_wells(power_domains
, i9xx_always_on_power_well
);
1877 static void intel_runtime_pm_disable(struct drm_i915_private
*dev_priv
)
1879 struct drm_device
*dev
= dev_priv
->dev
;
1880 struct device
*device
= &dev
->pdev
->dev
;
1882 if (!HAS_RUNTIME_PM(dev
))
1885 if (!intel_enable_rc6(dev
))
1888 /* Make sure we're not suspended first. */
1889 pm_runtime_get_sync(device
);
1893 * intel_power_domains_fini - finalizes the power domain structures
1894 * @dev_priv: i915 device instance
1896 * Finalizes the power domain structures for @dev_priv depending upon the
1897 * supported platform. This function also disables runtime pm and ensures that
1898 * the device stays powered up so that the driver can be reloaded.
1900 void intel_power_domains_fini(struct drm_i915_private
*dev_priv
)
1902 intel_runtime_pm_disable(dev_priv
);
1904 /* The i915.ko module is still not prepared to be loaded when
1905 * the power well is not enabled, so just enable it in case
1906 * we're going to unload/reload. */
1907 intel_display_set_init_power(dev_priv
, true);
1910 static void intel_power_domains_resume(struct drm_i915_private
*dev_priv
)
1912 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
1913 struct i915_power_well
*power_well
;
1916 mutex_lock(&power_domains
->lock
);
1917 for_each_power_well(i
, power_well
, POWER_DOMAIN_MASK
, power_domains
) {
1918 power_well
->ops
->sync_hw(dev_priv
, power_well
);
1919 power_well
->hw_enabled
= power_well
->ops
->is_enabled(dev_priv
,
1922 mutex_unlock(&power_domains
->lock
);
1925 static void chv_phy_control_init(struct drm_i915_private
*dev_priv
)
1927 struct i915_power_well
*cmn_bc
=
1928 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
);
1929 struct i915_power_well
*cmn_d
=
1930 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_D
);
1933 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
1934 * workaround never ever read DISPLAY_PHY_CONTROL, and
1935 * instead maintain a shadow copy ourselves. Use the actual
1936 * power well state and lane status to reconstruct the
1937 * expected initial value.
1939 dev_priv
->chv_phy_control
=
1940 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS
, DPIO_PHY0
) |
1941 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS
, DPIO_PHY1
) |
1942 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR
, DPIO_PHY0
, DPIO_CH0
) |
1943 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR
, DPIO_PHY0
, DPIO_CH1
) |
1944 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR
, DPIO_PHY1
, DPIO_CH0
);
1947 * If all lanes are disabled we leave the override disabled
1948 * with all power down bits cleared to match the state we
1949 * would use after disabling the port. Otherwise enable the
1950 * override and set the lane powerdown bits accding to the
1951 * current lane status.
1953 if (cmn_bc
->ops
->is_enabled(dev_priv
, cmn_bc
)) {
1954 uint32_t status
= I915_READ(DPLL(PIPE_A
));
1957 mask
= status
& DPLL_PORTB_READY_MASK
;
1961 dev_priv
->chv_phy_control
|=
1962 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0
, DPIO_CH0
);
1964 dev_priv
->chv_phy_control
|=
1965 PHY_CH_POWER_DOWN_OVRD(mask
, DPIO_PHY0
, DPIO_CH0
);
1967 mask
= (status
& DPLL_PORTC_READY_MASK
) >> 4;
1971 dev_priv
->chv_phy_control
|=
1972 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0
, DPIO_CH1
);
1974 dev_priv
->chv_phy_control
|=
1975 PHY_CH_POWER_DOWN_OVRD(mask
, DPIO_PHY0
, DPIO_CH1
);
1977 dev_priv
->chv_phy_control
|= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0
);
1979 dev_priv
->chv_phy_assert
[DPIO_PHY0
] = false;
1981 dev_priv
->chv_phy_assert
[DPIO_PHY0
] = true;
1984 if (cmn_d
->ops
->is_enabled(dev_priv
, cmn_d
)) {
1985 uint32_t status
= I915_READ(DPIO_PHY_STATUS
);
1988 mask
= status
& DPLL_PORTD_READY_MASK
;
1993 dev_priv
->chv_phy_control
|=
1994 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1
, DPIO_CH0
);
1996 dev_priv
->chv_phy_control
|=
1997 PHY_CH_POWER_DOWN_OVRD(mask
, DPIO_PHY1
, DPIO_CH0
);
1999 dev_priv
->chv_phy_control
|= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1
);
2001 dev_priv
->chv_phy_assert
[DPIO_PHY1
] = false;
2003 dev_priv
->chv_phy_assert
[DPIO_PHY1
] = true;
2006 I915_WRITE(DISPLAY_PHY_CONTROL
, dev_priv
->chv_phy_control
);
2008 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2009 dev_priv
->chv_phy_control
);
2012 static void vlv_cmnlane_wa(struct drm_i915_private
*dev_priv
)
2014 struct i915_power_well
*cmn
=
2015 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
);
2016 struct i915_power_well
*disp2d
=
2017 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DISP2D
);
2019 /* If the display might be already active skip this */
2020 if (cmn
->ops
->is_enabled(dev_priv
, cmn
) &&
2021 disp2d
->ops
->is_enabled(dev_priv
, disp2d
) &&
2022 I915_READ(DPIO_CTL
) & DPIO_CMNRST
)
2025 DRM_DEBUG_KMS("toggling display PHY side reset\n");
2027 /* cmnlane needs DPLL registers */
2028 disp2d
->ops
->enable(dev_priv
, disp2d
);
2031 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2032 * Need to assert and de-assert PHY SB reset by gating the
2033 * common lane power, then un-gating it.
2034 * Simply ungating isn't enough to reset the PHY enough to get
2035 * ports and lanes running.
2037 cmn
->ops
->disable(dev_priv
, cmn
);
2041 * intel_power_domains_init_hw - initialize hardware power domain state
2042 * @dev_priv: i915 device instance
2044 * This function initializes the hardware power domain state and enables all
2045 * power domains using intel_display_set_init_power().
2047 void intel_power_domains_init_hw(struct drm_i915_private
*dev_priv
)
2049 struct drm_device
*dev
= dev_priv
->dev
;
2050 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
2052 power_domains
->initializing
= true;
2054 if (IS_CHERRYVIEW(dev
)) {
2055 mutex_lock(&power_domains
->lock
);
2056 chv_phy_control_init(dev_priv
);
2057 mutex_unlock(&power_domains
->lock
);
2058 } else if (IS_VALLEYVIEW(dev
)) {
2059 mutex_lock(&power_domains
->lock
);
2060 vlv_cmnlane_wa(dev_priv
);
2061 mutex_unlock(&power_domains
->lock
);
2064 /* For now, we need the power well to be always enabled. */
2065 intel_display_set_init_power(dev_priv
, true);
2066 intel_power_domains_resume(dev_priv
);
2067 power_domains
->initializing
= false;
2071 * intel_runtime_pm_get - grab a runtime pm reference
2072 * @dev_priv: i915 device instance
2074 * This function grabs a device-level runtime pm reference (mostly used for GEM
2075 * code to ensure the GTT or GT is on) and ensures that it is powered up.
2077 * Any runtime pm reference obtained by this function must have a symmetric
2078 * call to intel_runtime_pm_put() to release the reference again.
2080 void intel_runtime_pm_get(struct drm_i915_private
*dev_priv
)
2082 struct drm_device
*dev
= dev_priv
->dev
;
2083 struct device
*device
= &dev
->pdev
->dev
;
2085 if (!HAS_RUNTIME_PM(dev
))
2088 pm_runtime_get_sync(device
);
2089 WARN(dev_priv
->pm
.suspended
, "Device still suspended.\n");
2093 * intel_runtime_pm_get_noresume - grab a runtime pm reference
2094 * @dev_priv: i915 device instance
2096 * This function grabs a device-level runtime pm reference (mostly used for GEM
2097 * code to ensure the GTT or GT is on).
2099 * It will _not_ power up the device but instead only check that it's powered
2100 * on. Therefore it is only valid to call this functions from contexts where
2101 * the device is known to be powered up and where trying to power it up would
2102 * result in hilarity and deadlocks. That pretty much means only the system
2103 * suspend/resume code where this is used to grab runtime pm references for
2104 * delayed setup down in work items.
2106 * Any runtime pm reference obtained by this function must have a symmetric
2107 * call to intel_runtime_pm_put() to release the reference again.
2109 void intel_runtime_pm_get_noresume(struct drm_i915_private
*dev_priv
)
2111 struct drm_device
*dev
= dev_priv
->dev
;
2112 struct device
*device
= &dev
->pdev
->dev
;
2114 if (!HAS_RUNTIME_PM(dev
))
2117 WARN(dev_priv
->pm
.suspended
, "Getting nosync-ref while suspended.\n");
2118 pm_runtime_get_noresume(device
);
2122 * intel_runtime_pm_put - release a runtime pm reference
2123 * @dev_priv: i915 device instance
2125 * This function drops the device-level runtime pm reference obtained by
2126 * intel_runtime_pm_get() and might power down the corresponding
2127 * hardware block right away if this is the last reference.
2129 void intel_runtime_pm_put(struct drm_i915_private
*dev_priv
)
2131 struct drm_device
*dev
= dev_priv
->dev
;
2132 struct device
*device
= &dev
->pdev
->dev
;
2134 if (!HAS_RUNTIME_PM(dev
))
2137 pm_runtime_mark_last_busy(device
);
2138 pm_runtime_put_autosuspend(device
);
2142 * intel_runtime_pm_enable - enable runtime pm
2143 * @dev_priv: i915 device instance
2145 * This function enables runtime pm at the end of the driver load sequence.
2147 * Note that this function does currently not enable runtime pm for the
2148 * subordinate display power domains. That is only done on the first modeset
2149 * using intel_display_set_init_power().
2151 void intel_runtime_pm_enable(struct drm_i915_private
*dev_priv
)
2153 struct drm_device
*dev
= dev_priv
->dev
;
2154 struct device
*device
= &dev
->pdev
->dev
;
2156 if (!HAS_RUNTIME_PM(dev
))
2160 * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
2163 if (!intel_enable_rc6(dev
)) {
2164 DRM_INFO("RC6 disabled, disabling runtime PM support\n");
2168 pm_runtime_set_autosuspend_delay(device
, 10000); /* 10s */
2169 pm_runtime_mark_last_busy(device
);
2170 pm_runtime_use_autosuspend(device
);
2172 pm_runtime_put_autosuspend(device
);