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 bool intel_display_power_well_is_enabled(struct drm_i915_private
*dev_priv
,
53 enum i915_power_well_id power_well_id
);
55 static struct i915_power_well
*
56 lookup_power_well(struct drm_i915_private
*dev_priv
,
57 enum i915_power_well_id power_well_id
);
60 intel_display_power_domain_str(enum intel_display_power_domain domain
)
63 case POWER_DOMAIN_PIPE_A
:
65 case POWER_DOMAIN_PIPE_B
:
67 case POWER_DOMAIN_PIPE_C
:
69 case POWER_DOMAIN_PIPE_A_PANEL_FITTER
:
70 return "PIPE_A_PANEL_FITTER";
71 case POWER_DOMAIN_PIPE_B_PANEL_FITTER
:
72 return "PIPE_B_PANEL_FITTER";
73 case POWER_DOMAIN_PIPE_C_PANEL_FITTER
:
74 return "PIPE_C_PANEL_FITTER";
75 case POWER_DOMAIN_TRANSCODER_A
:
76 return "TRANSCODER_A";
77 case POWER_DOMAIN_TRANSCODER_B
:
78 return "TRANSCODER_B";
79 case POWER_DOMAIN_TRANSCODER_C
:
80 return "TRANSCODER_C";
81 case POWER_DOMAIN_TRANSCODER_EDP
:
82 return "TRANSCODER_EDP";
83 case POWER_DOMAIN_TRANSCODER_DSI_A
:
84 return "TRANSCODER_DSI_A";
85 case POWER_DOMAIN_TRANSCODER_DSI_C
:
86 return "TRANSCODER_DSI_C";
87 case POWER_DOMAIN_PORT_DDI_A_LANES
:
88 return "PORT_DDI_A_LANES";
89 case POWER_DOMAIN_PORT_DDI_B_LANES
:
90 return "PORT_DDI_B_LANES";
91 case POWER_DOMAIN_PORT_DDI_C_LANES
:
92 return "PORT_DDI_C_LANES";
93 case POWER_DOMAIN_PORT_DDI_D_LANES
:
94 return "PORT_DDI_D_LANES";
95 case POWER_DOMAIN_PORT_DDI_E_LANES
:
96 return "PORT_DDI_E_LANES";
97 case POWER_DOMAIN_PORT_DDI_A_IO
:
98 return "PORT_DDI_A_IO";
99 case POWER_DOMAIN_PORT_DDI_B_IO
:
100 return "PORT_DDI_B_IO";
101 case POWER_DOMAIN_PORT_DDI_C_IO
:
102 return "PORT_DDI_C_IO";
103 case POWER_DOMAIN_PORT_DDI_D_IO
:
104 return "PORT_DDI_D_IO";
105 case POWER_DOMAIN_PORT_DDI_E_IO
:
106 return "PORT_DDI_E_IO";
107 case POWER_DOMAIN_PORT_DSI
:
109 case POWER_DOMAIN_PORT_CRT
:
111 case POWER_DOMAIN_PORT_OTHER
:
113 case POWER_DOMAIN_VGA
:
115 case POWER_DOMAIN_AUDIO
:
117 case POWER_DOMAIN_PLLS
:
119 case POWER_DOMAIN_AUX_A
:
121 case POWER_DOMAIN_AUX_B
:
123 case POWER_DOMAIN_AUX_C
:
125 case POWER_DOMAIN_AUX_D
:
127 case POWER_DOMAIN_GMBUS
:
129 case POWER_DOMAIN_INIT
:
131 case POWER_DOMAIN_MODESET
:
134 MISSING_CASE(domain
);
139 static void intel_power_well_enable(struct drm_i915_private
*dev_priv
,
140 struct i915_power_well
*power_well
)
142 DRM_DEBUG_KMS("enabling %s\n", power_well
->name
);
143 power_well
->ops
->enable(dev_priv
, power_well
);
144 power_well
->hw_enabled
= true;
147 static void intel_power_well_disable(struct drm_i915_private
*dev_priv
,
148 struct i915_power_well
*power_well
)
150 DRM_DEBUG_KMS("disabling %s\n", power_well
->name
);
151 power_well
->hw_enabled
= false;
152 power_well
->ops
->disable(dev_priv
, power_well
);
155 static void intel_power_well_get(struct drm_i915_private
*dev_priv
,
156 struct i915_power_well
*power_well
)
158 if (!power_well
->count
++)
159 intel_power_well_enable(dev_priv
, power_well
);
162 static void intel_power_well_put(struct drm_i915_private
*dev_priv
,
163 struct i915_power_well
*power_well
)
165 WARN(!power_well
->count
, "Use count on power well %s is already zero",
168 if (!--power_well
->count
)
169 intel_power_well_disable(dev_priv
, power_well
);
173 * We should only use the power well if we explicitly asked the hardware to
174 * enable it, so check if it's enabled and also check if we've requested it to
177 static bool hsw_power_well_enabled(struct drm_i915_private
*dev_priv
,
178 struct i915_power_well
*power_well
)
180 enum i915_power_well_id id
= power_well
->id
;
181 u32 mask
= HSW_PWR_WELL_CTL_REQ(id
) | HSW_PWR_WELL_CTL_STATE(id
);
183 return (I915_READ(HSW_PWR_WELL_DRIVER
) & mask
) == mask
;
187 * __intel_display_power_is_enabled - unlocked check for a power domain
188 * @dev_priv: i915 device instance
189 * @domain: power domain to check
191 * This is the unlocked version of intel_display_power_is_enabled() and should
192 * only be used from error capture and recovery code where deadlocks are
196 * True when the power domain is enabled, false otherwise.
198 bool __intel_display_power_is_enabled(struct drm_i915_private
*dev_priv
,
199 enum intel_display_power_domain domain
)
201 struct i915_power_well
*power_well
;
204 if (dev_priv
->pm
.suspended
)
209 for_each_power_domain_well_rev(dev_priv
, power_well
, BIT_ULL(domain
)) {
210 if (power_well
->always_on
)
213 if (!power_well
->hw_enabled
) {
223 * intel_display_power_is_enabled - check for a power domain
224 * @dev_priv: i915 device instance
225 * @domain: power domain to check
227 * This function can be used to check the hw power domain state. It is mostly
228 * used in hardware state readout functions. Everywhere else code should rely
229 * upon explicit power domain reference counting to ensure that the hardware
230 * block is powered up before accessing it.
232 * Callers must hold the relevant modesetting locks to ensure that concurrent
233 * threads can't disable the power well while the caller tries to read a few
237 * True when the power domain is enabled, false otherwise.
239 bool intel_display_power_is_enabled(struct drm_i915_private
*dev_priv
,
240 enum intel_display_power_domain domain
)
242 struct i915_power_domains
*power_domains
;
245 power_domains
= &dev_priv
->power_domains
;
247 mutex_lock(&power_domains
->lock
);
248 ret
= __intel_display_power_is_enabled(dev_priv
, domain
);
249 mutex_unlock(&power_domains
->lock
);
255 * intel_display_set_init_power - set the initial power domain state
256 * @dev_priv: i915 device instance
257 * @enable: whether to enable or disable the initial power domain state
259 * For simplicity our driver load/unload and system suspend/resume code assumes
260 * that all power domains are always enabled. This functions controls the state
261 * of this little hack. While the initial power domain state is enabled runtime
262 * pm is effectively disabled.
264 void intel_display_set_init_power(struct drm_i915_private
*dev_priv
,
267 if (dev_priv
->power_domains
.init_power_on
== enable
)
271 intel_display_power_get(dev_priv
, POWER_DOMAIN_INIT
);
273 intel_display_power_put(dev_priv
, POWER_DOMAIN_INIT
);
275 dev_priv
->power_domains
.init_power_on
= enable
;
279 * Starting with Haswell, we have a "Power Down Well" that can be turned off
280 * when not needed anymore. We have 4 registers that can request the power well
281 * to be enabled, and it will only be disabled if none of the registers is
282 * requesting it to be enabled.
284 static void hsw_power_well_post_enable(struct drm_i915_private
*dev_priv
,
285 u8 irq_pipe_mask
, bool has_vga
)
287 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
290 * After we re-enable the power well, if we touch VGA register 0x3d5
291 * we'll get unclaimed register interrupts. This stops after we write
292 * anything to the VGA MSR register. The vgacon module uses this
293 * register all the time, so if we unbind our driver and, as a
294 * consequence, bind vgacon, we'll get stuck in an infinite loop at
295 * console_unlock(). So make here we touch the VGA MSR register, making
296 * sure vgacon can keep working normally without triggering interrupts
297 * and error messages.
300 vga_get_uninterruptible(pdev
, VGA_RSRC_LEGACY_IO
);
301 outb(inb(VGA_MSR_READ
), VGA_MSR_WRITE
);
302 vga_put(pdev
, VGA_RSRC_LEGACY_IO
);
306 gen8_irq_power_well_post_enable(dev_priv
, irq_pipe_mask
);
309 static void hsw_power_well_pre_disable(struct drm_i915_private
*dev_priv
,
313 gen8_irq_power_well_pre_disable(dev_priv
, irq_pipe_mask
);
316 static void skl_power_well_post_enable(struct drm_i915_private
*dev_priv
,
317 struct i915_power_well
*power_well
)
319 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
322 * After we re-enable the power well, if we touch VGA register 0x3d5
323 * we'll get unclaimed register interrupts. This stops after we write
324 * anything to the VGA MSR register. The vgacon module uses this
325 * register all the time, so if we unbind our driver and, as a
326 * consequence, bind vgacon, we'll get stuck in an infinite loop at
327 * console_unlock(). So make here we touch the VGA MSR register, making
328 * sure vgacon can keep working normally without triggering interrupts
329 * and error messages.
331 if (power_well
->id
== SKL_DISP_PW_2
) {
332 vga_get_uninterruptible(pdev
, VGA_RSRC_LEGACY_IO
);
333 outb(inb(VGA_MSR_READ
), VGA_MSR_WRITE
);
334 vga_put(pdev
, VGA_RSRC_LEGACY_IO
);
336 gen8_irq_power_well_post_enable(dev_priv
,
337 1 << PIPE_C
| 1 << PIPE_B
);
341 static void skl_power_well_pre_disable(struct drm_i915_private
*dev_priv
,
342 struct i915_power_well
*power_well
)
344 if (power_well
->id
== SKL_DISP_PW_2
)
345 gen8_irq_power_well_pre_disable(dev_priv
,
346 1 << PIPE_C
| 1 << PIPE_B
);
349 static void gen9_wait_for_power_well_enable(struct drm_i915_private
*dev_priv
,
350 struct i915_power_well
*power_well
)
352 enum i915_power_well_id id
= power_well
->id
;
354 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
355 WARN_ON(intel_wait_for_register(dev_priv
,
357 HSW_PWR_WELL_CTL_STATE(id
),
358 HSW_PWR_WELL_CTL_STATE(id
),
362 static u32
gen9_power_well_requesters(struct drm_i915_private
*dev_priv
,
363 enum i915_power_well_id id
)
365 u32 req_mask
= HSW_PWR_WELL_CTL_REQ(id
);
368 ret
= I915_READ(HSW_PWR_WELL_BIOS
) & req_mask
? 1 : 0;
369 ret
|= I915_READ(HSW_PWR_WELL_DRIVER
) & req_mask
? 2 : 0;
370 ret
|= I915_READ(HSW_PWR_WELL_KVMR
) & req_mask
? 4 : 0;
371 ret
|= I915_READ(HSW_PWR_WELL_DEBUG
) & req_mask
? 8 : 0;
376 static void gen9_wait_for_power_well_disable(struct drm_i915_private
*dev_priv
,
377 struct i915_power_well
*power_well
)
379 enum i915_power_well_id id
= power_well
->id
;
384 * Bspec doesn't require waiting for PWs to get disabled, but still do
385 * this for paranoia. The known cases where a PW will be forced on:
386 * - a KVMR request on any power well via the KVMR request register
387 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
388 * DEBUG request registers
389 * Skip the wait in case any of the request bits are set and print a
390 * diagnostic message.
392 wait_for((disabled
= !(I915_READ(HSW_PWR_WELL_DRIVER
) &
393 HSW_PWR_WELL_CTL_STATE(id
))) ||
394 (reqs
= gen9_power_well_requesters(dev_priv
, id
)), 1);
398 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
400 !!(reqs
& 1), !!(reqs
& 2), !!(reqs
& 4), !!(reqs
& 8));
403 static void hsw_power_well_enable(struct drm_i915_private
*dev_priv
,
404 struct i915_power_well
*power_well
)
406 enum i915_power_well_id id
= power_well
->id
;
409 val
= I915_READ(HSW_PWR_WELL_DRIVER
);
410 I915_WRITE(HSW_PWR_WELL_DRIVER
, val
| HSW_PWR_WELL_CTL_REQ(id
));
412 if (intel_wait_for_register(dev_priv
,
414 HSW_PWR_WELL_CTL_STATE(id
),
415 HSW_PWR_WELL_CTL_STATE(id
),
417 DRM_ERROR("Timeout enabling power well\n");
419 hsw_power_well_post_enable(dev_priv
, power_well
->hsw
.irq_pipe_mask
,
420 power_well
->hsw
.has_vga
);
423 static void hsw_power_well_disable(struct drm_i915_private
*dev_priv
,
424 struct i915_power_well
*power_well
)
426 enum i915_power_well_id id
= power_well
->id
;
429 hsw_power_well_pre_disable(dev_priv
, power_well
->hsw
.irq_pipe_mask
);
431 val
= I915_READ(HSW_PWR_WELL_DRIVER
);
432 I915_WRITE(HSW_PWR_WELL_DRIVER
, val
& ~HSW_PWR_WELL_CTL_REQ(id
));
433 POSTING_READ(HSW_PWR_WELL_DRIVER
);
436 #define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
437 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
438 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
439 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
440 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
441 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
442 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
443 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
444 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
445 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
446 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
447 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
448 BIT_ULL(POWER_DOMAIN_AUX_B) | \
449 BIT_ULL(POWER_DOMAIN_AUX_C) | \
450 BIT_ULL(POWER_DOMAIN_AUX_D) | \
451 BIT_ULL(POWER_DOMAIN_AUDIO) | \
452 BIT_ULL(POWER_DOMAIN_VGA) | \
453 BIT_ULL(POWER_DOMAIN_INIT))
454 #define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
455 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
456 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
457 BIT_ULL(POWER_DOMAIN_INIT))
458 #define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
459 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
460 BIT_ULL(POWER_DOMAIN_INIT))
461 #define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
462 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
463 BIT_ULL(POWER_DOMAIN_INIT))
464 #define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
465 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
466 BIT_ULL(POWER_DOMAIN_INIT))
467 #define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
468 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
469 BIT_ULL(POWER_DOMAIN_MODESET) | \
470 BIT_ULL(POWER_DOMAIN_AUX_A) | \
471 BIT_ULL(POWER_DOMAIN_INIT))
473 #define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
474 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
475 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
476 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
477 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
478 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
479 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
480 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
481 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
482 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
483 BIT_ULL(POWER_DOMAIN_AUX_B) | \
484 BIT_ULL(POWER_DOMAIN_AUX_C) | \
485 BIT_ULL(POWER_DOMAIN_AUDIO) | \
486 BIT_ULL(POWER_DOMAIN_VGA) | \
487 BIT_ULL(POWER_DOMAIN_GMBUS) | \
488 BIT_ULL(POWER_DOMAIN_INIT))
489 #define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
490 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
491 BIT_ULL(POWER_DOMAIN_MODESET) | \
492 BIT_ULL(POWER_DOMAIN_AUX_A) | \
493 BIT_ULL(POWER_DOMAIN_INIT))
494 #define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
495 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
496 BIT_ULL(POWER_DOMAIN_AUX_A) | \
497 BIT_ULL(POWER_DOMAIN_INIT))
498 #define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
499 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
500 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
501 BIT_ULL(POWER_DOMAIN_AUX_B) | \
502 BIT_ULL(POWER_DOMAIN_AUX_C) | \
503 BIT_ULL(POWER_DOMAIN_INIT))
505 #define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
506 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
507 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
508 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
509 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
510 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
511 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
512 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
513 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
514 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
515 BIT_ULL(POWER_DOMAIN_AUX_B) | \
516 BIT_ULL(POWER_DOMAIN_AUX_C) | \
517 BIT_ULL(POWER_DOMAIN_AUDIO) | \
518 BIT_ULL(POWER_DOMAIN_VGA) | \
519 BIT_ULL(POWER_DOMAIN_INIT))
520 #define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
521 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
522 #define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
523 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
524 #define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
525 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
526 #define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
527 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
528 BIT_ULL(POWER_DOMAIN_AUX_A) | \
529 BIT_ULL(POWER_DOMAIN_INIT))
530 #define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
531 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
532 BIT_ULL(POWER_DOMAIN_AUX_B) | \
533 BIT_ULL(POWER_DOMAIN_INIT))
534 #define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
535 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
536 BIT_ULL(POWER_DOMAIN_AUX_C) | \
537 BIT_ULL(POWER_DOMAIN_INIT))
538 #define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
539 BIT_ULL(POWER_DOMAIN_AUX_A) | \
540 BIT_ULL(POWER_DOMAIN_INIT))
541 #define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
542 BIT_ULL(POWER_DOMAIN_AUX_B) | \
543 BIT_ULL(POWER_DOMAIN_INIT))
544 #define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
545 BIT_ULL(POWER_DOMAIN_AUX_C) | \
546 BIT_ULL(POWER_DOMAIN_INIT))
547 #define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
548 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
549 BIT_ULL(POWER_DOMAIN_MODESET) | \
550 BIT_ULL(POWER_DOMAIN_AUX_A) | \
551 BIT_ULL(POWER_DOMAIN_INIT))
553 #define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
554 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
555 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
556 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
557 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
558 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
559 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
560 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
561 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
562 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
563 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
564 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
565 BIT_ULL(POWER_DOMAIN_AUX_B) | \
566 BIT_ULL(POWER_DOMAIN_AUX_C) | \
567 BIT_ULL(POWER_DOMAIN_AUX_D) | \
568 BIT_ULL(POWER_DOMAIN_AUDIO) | \
569 BIT_ULL(POWER_DOMAIN_VGA) | \
570 BIT_ULL(POWER_DOMAIN_INIT))
571 #define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
572 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
573 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
574 BIT_ULL(POWER_DOMAIN_INIT))
575 #define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
576 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
577 BIT_ULL(POWER_DOMAIN_INIT))
578 #define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
579 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
580 BIT_ULL(POWER_DOMAIN_INIT))
581 #define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
582 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
583 BIT_ULL(POWER_DOMAIN_INIT))
584 #define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
585 BIT_ULL(POWER_DOMAIN_AUX_A) | \
586 BIT_ULL(POWER_DOMAIN_INIT))
587 #define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
588 BIT_ULL(POWER_DOMAIN_AUX_B) | \
589 BIT_ULL(POWER_DOMAIN_INIT))
590 #define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
591 BIT_ULL(POWER_DOMAIN_AUX_C) | \
592 BIT_ULL(POWER_DOMAIN_INIT))
593 #define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
594 BIT_ULL(POWER_DOMAIN_AUX_D) | \
595 BIT_ULL(POWER_DOMAIN_INIT))
596 #define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
597 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
598 BIT_ULL(POWER_DOMAIN_MODESET) | \
599 BIT_ULL(POWER_DOMAIN_AUX_A) | \
600 BIT_ULL(POWER_DOMAIN_INIT))
602 static void assert_can_enable_dc9(struct drm_i915_private
*dev_priv
)
604 WARN_ONCE((I915_READ(DC_STATE_EN
) & DC_STATE_EN_DC9
),
605 "DC9 already programmed to be enabled.\n");
606 WARN_ONCE(I915_READ(DC_STATE_EN
) & DC_STATE_EN_UPTO_DC5
,
607 "DC5 still not disabled to enable DC9.\n");
608 WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER
) &
609 HSW_PWR_WELL_CTL_REQ(SKL_DISP_PW_2
),
610 "Power well 2 on.\n");
611 WARN_ONCE(intel_irqs_enabled(dev_priv
),
612 "Interrupts not disabled yet.\n");
615 * TODO: check for the following to verify the conditions to enter DC9
616 * state are satisfied:
617 * 1] Check relevant display engine registers to verify if mode set
618 * disable sequence was followed.
619 * 2] Check if display uninitialize sequence is initialized.
623 static void assert_can_disable_dc9(struct drm_i915_private
*dev_priv
)
625 WARN_ONCE(intel_irqs_enabled(dev_priv
),
626 "Interrupts not disabled yet.\n");
627 WARN_ONCE(I915_READ(DC_STATE_EN
) & DC_STATE_EN_UPTO_DC5
,
628 "DC5 still not disabled.\n");
631 * TODO: check for the following to verify DC9 state was indeed
632 * entered before programming to disable it:
633 * 1] Check relevant display engine registers to verify if mode
634 * set disable sequence was followed.
635 * 2] Check if display uninitialize sequence is initialized.
639 static void gen9_write_dc_state(struct drm_i915_private
*dev_priv
,
646 I915_WRITE(DC_STATE_EN
, state
);
648 /* It has been observed that disabling the dc6 state sometimes
649 * doesn't stick and dmc keeps returning old value. Make sure
650 * the write really sticks enough times and also force rewrite until
651 * we are confident that state is exactly what we want.
654 v
= I915_READ(DC_STATE_EN
);
657 I915_WRITE(DC_STATE_EN
, state
);
660 } else if (rereads
++ > 5) {
664 } while (rewrites
< 100);
667 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
670 /* Most of the times we need one retry, avoid spam */
672 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
676 static u32
gen9_dc_mask(struct drm_i915_private
*dev_priv
)
680 mask
= DC_STATE_EN_UPTO_DC5
;
681 if (IS_GEN9_LP(dev_priv
))
682 mask
|= DC_STATE_EN_DC9
;
684 mask
|= DC_STATE_EN_UPTO_DC6
;
689 void gen9_sanitize_dc_state(struct drm_i915_private
*dev_priv
)
693 val
= I915_READ(DC_STATE_EN
) & gen9_dc_mask(dev_priv
);
695 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
696 dev_priv
->csr
.dc_state
, val
);
697 dev_priv
->csr
.dc_state
= val
;
700 static void gen9_set_dc_state(struct drm_i915_private
*dev_priv
, uint32_t state
)
705 if (WARN_ON_ONCE(state
& ~dev_priv
->csr
.allowed_dc_mask
))
706 state
&= dev_priv
->csr
.allowed_dc_mask
;
708 val
= I915_READ(DC_STATE_EN
);
709 mask
= gen9_dc_mask(dev_priv
);
710 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
713 /* Check if DMC is ignoring our DC state requests */
714 if ((val
& mask
) != dev_priv
->csr
.dc_state
)
715 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
716 dev_priv
->csr
.dc_state
, val
& mask
);
721 gen9_write_dc_state(dev_priv
, val
);
723 dev_priv
->csr
.dc_state
= val
& mask
;
726 void bxt_enable_dc9(struct drm_i915_private
*dev_priv
)
728 assert_can_enable_dc9(dev_priv
);
730 DRM_DEBUG_KMS("Enabling DC9\n");
732 intel_power_sequencer_reset(dev_priv
);
733 gen9_set_dc_state(dev_priv
, DC_STATE_EN_DC9
);
736 void bxt_disable_dc9(struct drm_i915_private
*dev_priv
)
738 assert_can_disable_dc9(dev_priv
);
740 DRM_DEBUG_KMS("Disabling DC9\n");
742 gen9_set_dc_state(dev_priv
, DC_STATE_DISABLE
);
744 intel_pps_unlock_regs_wa(dev_priv
);
747 static void assert_csr_loaded(struct drm_i915_private
*dev_priv
)
749 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
750 "CSR program storage start is NULL\n");
751 WARN_ONCE(!I915_READ(CSR_SSP_BASE
), "CSR SSP Base Not fine\n");
752 WARN_ONCE(!I915_READ(CSR_HTP_SKL
), "CSR HTP Not fine\n");
755 static void assert_can_enable_dc5(struct drm_i915_private
*dev_priv
)
757 bool pg2_enabled
= intel_display_power_well_is_enabled(dev_priv
,
760 WARN_ONCE(pg2_enabled
, "PG2 not disabled to enable DC5.\n");
762 WARN_ONCE((I915_READ(DC_STATE_EN
) & DC_STATE_EN_UPTO_DC5
),
763 "DC5 already programmed to be enabled.\n");
764 assert_rpm_wakelock_held(dev_priv
);
766 assert_csr_loaded(dev_priv
);
769 void gen9_enable_dc5(struct drm_i915_private
*dev_priv
)
771 assert_can_enable_dc5(dev_priv
);
773 DRM_DEBUG_KMS("Enabling DC5\n");
775 gen9_set_dc_state(dev_priv
, DC_STATE_EN_UPTO_DC5
);
778 static void assert_can_enable_dc6(struct drm_i915_private
*dev_priv
)
780 WARN_ONCE(I915_READ(UTIL_PIN_CTL
) & UTIL_PIN_ENABLE
,
781 "Backlight is not disabled.\n");
782 WARN_ONCE((I915_READ(DC_STATE_EN
) & DC_STATE_EN_UPTO_DC6
),
783 "DC6 already programmed to be enabled.\n");
785 assert_csr_loaded(dev_priv
);
788 void skl_enable_dc6(struct drm_i915_private
*dev_priv
)
790 assert_can_enable_dc6(dev_priv
);
792 DRM_DEBUG_KMS("Enabling DC6\n");
794 gen9_set_dc_state(dev_priv
, DC_STATE_EN_UPTO_DC6
);
798 void skl_disable_dc6(struct drm_i915_private
*dev_priv
)
800 DRM_DEBUG_KMS("Disabling DC6\n");
802 gen9_set_dc_state(dev_priv
, DC_STATE_DISABLE
);
805 static void skl_set_power_well(struct drm_i915_private
*dev_priv
,
806 struct i915_power_well
*power_well
, bool enable
)
808 uint32_t tmp
, fuse_status
;
809 uint32_t req_mask
, state_mask
;
810 bool check_fuse_status
= false;
812 tmp
= I915_READ(HSW_PWR_WELL_DRIVER
);
813 fuse_status
= I915_READ(SKL_FUSE_STATUS
);
815 switch (power_well
->id
) {
817 if (intel_wait_for_register(dev_priv
,
819 SKL_FUSE_PG0_DIST_STATUS
,
820 SKL_FUSE_PG0_DIST_STATUS
,
822 DRM_ERROR("PG0 not enabled\n");
827 if (!(fuse_status
& SKL_FUSE_PG1_DIST_STATUS
)) {
828 DRM_ERROR("PG1 in disabled state\n");
832 case SKL_DISP_PW_MISC_IO
:
833 case SKL_DISP_PW_DDI_A_E
: /* GLK_DISP_PW_DDI_A, CNL_DISP_PW_DDI_A */
834 case SKL_DISP_PW_DDI_B
:
835 case SKL_DISP_PW_DDI_C
:
836 case SKL_DISP_PW_DDI_D
:
837 case GLK_DISP_PW_AUX_A
: /* CNL_DISP_PW_AUX_A */
838 case GLK_DISP_PW_AUX_B
: /* CNL_DISP_PW_AUX_B */
839 case GLK_DISP_PW_AUX_C
: /* CNL_DISP_PW_AUX_C */
840 case CNL_DISP_PW_AUX_D
:
843 WARN(1, "Unknown power well %u\n", power_well
->id
);
847 req_mask
= HSW_PWR_WELL_CTL_REQ(power_well
->id
);
848 state_mask
= HSW_PWR_WELL_CTL_STATE(power_well
->id
);
851 skl_power_well_pre_disable(dev_priv
, power_well
);
854 I915_WRITE(HSW_PWR_WELL_DRIVER
, tmp
| req_mask
);
856 DRM_DEBUG_KMS("Enabling %s\n", power_well
->name
);
857 check_fuse_status
= true;
859 gen9_wait_for_power_well_enable(dev_priv
, power_well
);
861 I915_WRITE(HSW_PWR_WELL_DRIVER
, tmp
& ~req_mask
);
862 POSTING_READ(HSW_PWR_WELL_DRIVER
);
863 DRM_DEBUG_KMS("Disabling %s\n", power_well
->name
);
865 gen9_wait_for_power_well_disable(dev_priv
, power_well
);
868 if (check_fuse_status
) {
869 if (power_well
->id
== SKL_DISP_PW_1
) {
870 if (intel_wait_for_register(dev_priv
,
872 SKL_FUSE_PG1_DIST_STATUS
,
873 SKL_FUSE_PG1_DIST_STATUS
,
875 DRM_ERROR("PG1 distributing status timeout\n");
876 } else if (power_well
->id
== SKL_DISP_PW_2
) {
877 if (intel_wait_for_register(dev_priv
,
879 SKL_FUSE_PG2_DIST_STATUS
,
880 SKL_FUSE_PG2_DIST_STATUS
,
882 DRM_ERROR("PG2 distributing status timeout\n");
887 skl_power_well_post_enable(dev_priv
, power_well
);
890 static void hsw_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
891 struct i915_power_well
*power_well
)
893 enum i915_power_well_id id
= power_well
->id
;
894 u32 mask
= HSW_PWR_WELL_CTL_REQ(id
);
895 u32 bios_req
= I915_READ(HSW_PWR_WELL_BIOS
);
897 /* Take over the request bit if set by BIOS. */
898 if (bios_req
& mask
) {
899 u32 drv_req
= I915_READ(HSW_PWR_WELL_DRIVER
);
901 if (!(drv_req
& mask
))
902 I915_WRITE(HSW_PWR_WELL_DRIVER
, drv_req
| mask
);
903 I915_WRITE(HSW_PWR_WELL_BIOS
, bios_req
& ~mask
);
907 static bool skl_power_well_enabled(struct drm_i915_private
*dev_priv
,
908 struct i915_power_well
*power_well
)
910 uint32_t mask
= HSW_PWR_WELL_CTL_REQ(power_well
->id
) |
911 HSW_PWR_WELL_CTL_STATE(power_well
->id
);
913 return (I915_READ(HSW_PWR_WELL_DRIVER
) & mask
) == mask
;
916 static void skl_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
917 struct i915_power_well
*power_well
)
919 uint32_t mask
= HSW_PWR_WELL_CTL_REQ(power_well
->id
);
920 uint32_t bios_req
= I915_READ(HSW_PWR_WELL_BIOS
);
922 /* Take over the request bit if set by BIOS. */
923 if (bios_req
& mask
) {
924 uint32_t drv_req
= I915_READ(HSW_PWR_WELL_DRIVER
);
926 if (!(drv_req
& mask
))
927 I915_WRITE(HSW_PWR_WELL_DRIVER
, drv_req
| mask
);
928 I915_WRITE(HSW_PWR_WELL_BIOS
, bios_req
& ~mask
);
932 static void skl_power_well_enable(struct drm_i915_private
*dev_priv
,
933 struct i915_power_well
*power_well
)
935 skl_set_power_well(dev_priv
, power_well
, true);
938 static void skl_power_well_disable(struct drm_i915_private
*dev_priv
,
939 struct i915_power_well
*power_well
)
941 skl_set_power_well(dev_priv
, power_well
, false);
944 static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private
*dev_priv
,
945 struct i915_power_well
*power_well
)
947 bxt_ddi_phy_init(dev_priv
, power_well
->bxt
.phy
);
950 static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private
*dev_priv
,
951 struct i915_power_well
*power_well
)
953 bxt_ddi_phy_uninit(dev_priv
, power_well
->bxt
.phy
);
956 static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private
*dev_priv
,
957 struct i915_power_well
*power_well
)
959 return bxt_ddi_phy_is_enabled(dev_priv
, power_well
->bxt
.phy
);
962 static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private
*dev_priv
)
964 struct i915_power_well
*power_well
;
966 power_well
= lookup_power_well(dev_priv
, BXT_DPIO_CMN_A
);
967 if (power_well
->count
> 0)
968 bxt_ddi_phy_verify_state(dev_priv
, power_well
->bxt
.phy
);
970 power_well
= lookup_power_well(dev_priv
, BXT_DPIO_CMN_BC
);
971 if (power_well
->count
> 0)
972 bxt_ddi_phy_verify_state(dev_priv
, power_well
->bxt
.phy
);
974 if (IS_GEMINILAKE(dev_priv
)) {
975 power_well
= lookup_power_well(dev_priv
, GLK_DPIO_CMN_C
);
976 if (power_well
->count
> 0)
977 bxt_ddi_phy_verify_state(dev_priv
, power_well
->bxt
.phy
);
981 static bool gen9_dc_off_power_well_enabled(struct drm_i915_private
*dev_priv
,
982 struct i915_power_well
*power_well
)
984 return (I915_READ(DC_STATE_EN
) & DC_STATE_EN_UPTO_DC5_DC6_MASK
) == 0;
987 static void gen9_assert_dbuf_enabled(struct drm_i915_private
*dev_priv
)
989 u32 tmp
= I915_READ(DBUF_CTL
);
991 WARN((tmp
& (DBUF_POWER_STATE
| DBUF_POWER_REQUEST
)) !=
992 (DBUF_POWER_STATE
| DBUF_POWER_REQUEST
),
993 "Unexpected DBuf power power state (0x%08x)\n", tmp
);
996 static void gen9_dc_off_power_well_enable(struct drm_i915_private
*dev_priv
,
997 struct i915_power_well
*power_well
)
999 struct intel_cdclk_state cdclk_state
= {};
1001 gen9_set_dc_state(dev_priv
, DC_STATE_DISABLE
);
1003 dev_priv
->display
.get_cdclk(dev_priv
, &cdclk_state
);
1004 WARN_ON(!intel_cdclk_state_compare(&dev_priv
->cdclk
.hw
, &cdclk_state
));
1006 gen9_assert_dbuf_enabled(dev_priv
);
1008 if (IS_GEN9_LP(dev_priv
))
1009 bxt_verify_ddi_phy_power_wells(dev_priv
);
1012 static void gen9_dc_off_power_well_disable(struct drm_i915_private
*dev_priv
,
1013 struct i915_power_well
*power_well
)
1015 if (!dev_priv
->csr
.dmc_payload
)
1018 if (dev_priv
->csr
.allowed_dc_mask
& DC_STATE_EN_UPTO_DC6
)
1019 skl_enable_dc6(dev_priv
);
1020 else if (dev_priv
->csr
.allowed_dc_mask
& DC_STATE_EN_UPTO_DC5
)
1021 gen9_enable_dc5(dev_priv
);
1024 static void i9xx_power_well_sync_hw_noop(struct drm_i915_private
*dev_priv
,
1025 struct i915_power_well
*power_well
)
1029 static void i9xx_always_on_power_well_noop(struct drm_i915_private
*dev_priv
,
1030 struct i915_power_well
*power_well
)
1034 static bool i9xx_always_on_power_well_enabled(struct drm_i915_private
*dev_priv
,
1035 struct i915_power_well
*power_well
)
1040 static void i830_pipes_power_well_enable(struct drm_i915_private
*dev_priv
,
1041 struct i915_power_well
*power_well
)
1043 if ((I915_READ(PIPECONF(PIPE_A
)) & PIPECONF_ENABLE
) == 0)
1044 i830_enable_pipe(dev_priv
, PIPE_A
);
1045 if ((I915_READ(PIPECONF(PIPE_B
)) & PIPECONF_ENABLE
) == 0)
1046 i830_enable_pipe(dev_priv
, PIPE_B
);
1049 static void i830_pipes_power_well_disable(struct drm_i915_private
*dev_priv
,
1050 struct i915_power_well
*power_well
)
1052 i830_disable_pipe(dev_priv
, PIPE_B
);
1053 i830_disable_pipe(dev_priv
, PIPE_A
);
1056 static bool i830_pipes_power_well_enabled(struct drm_i915_private
*dev_priv
,
1057 struct i915_power_well
*power_well
)
1059 return I915_READ(PIPECONF(PIPE_A
)) & PIPECONF_ENABLE
&&
1060 I915_READ(PIPECONF(PIPE_B
)) & PIPECONF_ENABLE
;
1063 static void i830_pipes_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
1064 struct i915_power_well
*power_well
)
1066 if (power_well
->count
> 0)
1067 i830_pipes_power_well_enable(dev_priv
, power_well
);
1069 i830_pipes_power_well_disable(dev_priv
, power_well
);
1072 static void vlv_set_power_well(struct drm_i915_private
*dev_priv
,
1073 struct i915_power_well
*power_well
, bool enable
)
1075 enum i915_power_well_id power_well_id
= power_well
->id
;
1080 mask
= PUNIT_PWRGT_MASK(power_well_id
);
1081 state
= enable
? PUNIT_PWRGT_PWR_ON(power_well_id
) :
1082 PUNIT_PWRGT_PWR_GATE(power_well_id
);
1084 mutex_lock(&dev_priv
->rps
.hw_lock
);
1087 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
1092 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
);
1095 vlv_punit_write(dev_priv
, PUNIT_REG_PWRGT_CTRL
, ctrl
);
1097 if (wait_for(COND
, 100))
1098 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
1100 vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
));
1105 mutex_unlock(&dev_priv
->rps
.hw_lock
);
1108 static void vlv_power_well_enable(struct drm_i915_private
*dev_priv
,
1109 struct i915_power_well
*power_well
)
1111 vlv_set_power_well(dev_priv
, power_well
, true);
1114 static void vlv_power_well_disable(struct drm_i915_private
*dev_priv
,
1115 struct i915_power_well
*power_well
)
1117 vlv_set_power_well(dev_priv
, power_well
, false);
1120 static bool vlv_power_well_enabled(struct drm_i915_private
*dev_priv
,
1121 struct i915_power_well
*power_well
)
1123 enum i915_power_well_id power_well_id
= power_well
->id
;
1124 bool enabled
= false;
1129 mask
= PUNIT_PWRGT_MASK(power_well_id
);
1130 ctrl
= PUNIT_PWRGT_PWR_ON(power_well_id
);
1132 mutex_lock(&dev_priv
->rps
.hw_lock
);
1134 state
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_STATUS
) & mask
;
1136 * We only ever set the power-on and power-gate states, anything
1137 * else is unexpected.
1139 WARN_ON(state
!= PUNIT_PWRGT_PWR_ON(power_well_id
) &&
1140 state
!= PUNIT_PWRGT_PWR_GATE(power_well_id
));
1145 * A transient state at this point would mean some unexpected party
1146 * is poking at the power controls too.
1148 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
) & mask
;
1149 WARN_ON(ctrl
!= state
);
1151 mutex_unlock(&dev_priv
->rps
.hw_lock
);
1156 static void vlv_init_display_clock_gating(struct drm_i915_private
*dev_priv
)
1161 * On driver load, a pipe may be active and driving a DSI display.
1162 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
1163 * (and never recovering) in this case. intel_dsi_post_disable() will
1164 * clear it when we turn off the display.
1166 val
= I915_READ(DSPCLK_GATE_D
);
1167 val
&= DPOUNIT_CLOCK_GATE_DISABLE
;
1168 val
|= VRHUNIT_CLOCK_GATE_DISABLE
;
1169 I915_WRITE(DSPCLK_GATE_D
, val
);
1172 * Disable trickle feed and enable pnd deadline calculation
1174 I915_WRITE(MI_ARB_VLV
, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE
);
1175 I915_WRITE(CBR1_VLV
, 0);
1177 WARN_ON(dev_priv
->rawclk_freq
== 0);
1179 I915_WRITE(RAWCLK_FREQ_VLV
,
1180 DIV_ROUND_CLOSEST(dev_priv
->rawclk_freq
, 1000));
1183 static void vlv_display_power_well_init(struct drm_i915_private
*dev_priv
)
1185 struct intel_encoder
*encoder
;
1189 * Enable the CRI clock source so we can get at the
1190 * display and the reference clock for VGA
1191 * hotplug / manual detection. Supposedly DSI also
1192 * needs the ref clock up and running.
1194 * CHV DPLL B/C have some issues if VGA mode is enabled.
1196 for_each_pipe(dev_priv
, pipe
) {
1197 u32 val
= I915_READ(DPLL(pipe
));
1199 val
|= DPLL_REF_CLK_ENABLE_VLV
| DPLL_VGA_MODE_DIS
;
1201 val
|= DPLL_INTEGRATED_CRI_CLK_VLV
;
1203 I915_WRITE(DPLL(pipe
), val
);
1206 vlv_init_display_clock_gating(dev_priv
);
1208 spin_lock_irq(&dev_priv
->irq_lock
);
1209 valleyview_enable_display_irqs(dev_priv
);
1210 spin_unlock_irq(&dev_priv
->irq_lock
);
1213 * During driver initialization/resume we can avoid restoring the
1214 * part of the HW/SW state that will be inited anyway explicitly.
1216 if (dev_priv
->power_domains
.initializing
)
1219 intel_hpd_init(dev_priv
);
1221 /* Re-enable the ADPA, if we have one */
1222 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
1223 if (encoder
->type
== INTEL_OUTPUT_ANALOG
)
1224 intel_crt_reset(&encoder
->base
);
1227 i915_redisable_vga_power_on(dev_priv
);
1229 intel_pps_unlock_regs_wa(dev_priv
);
1232 static void vlv_display_power_well_deinit(struct drm_i915_private
*dev_priv
)
1234 spin_lock_irq(&dev_priv
->irq_lock
);
1235 valleyview_disable_display_irqs(dev_priv
);
1236 spin_unlock_irq(&dev_priv
->irq_lock
);
1238 /* make sure we're done processing display irqs */
1239 synchronize_irq(dev_priv
->drm
.irq
);
1241 intel_power_sequencer_reset(dev_priv
);
1243 /* Prevent us from re-enabling polling on accident in late suspend */
1244 if (!dev_priv
->drm
.dev
->power
.is_suspended
)
1245 intel_hpd_poll_init(dev_priv
);
1248 static void vlv_display_power_well_enable(struct drm_i915_private
*dev_priv
,
1249 struct i915_power_well
*power_well
)
1251 WARN_ON_ONCE(power_well
->id
!= PUNIT_POWER_WELL_DISP2D
);
1253 vlv_set_power_well(dev_priv
, power_well
, true);
1255 vlv_display_power_well_init(dev_priv
);
1258 static void vlv_display_power_well_disable(struct drm_i915_private
*dev_priv
,
1259 struct i915_power_well
*power_well
)
1261 WARN_ON_ONCE(power_well
->id
!= PUNIT_POWER_WELL_DISP2D
);
1263 vlv_display_power_well_deinit(dev_priv
);
1265 vlv_set_power_well(dev_priv
, power_well
, false);
1268 static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private
*dev_priv
,
1269 struct i915_power_well
*power_well
)
1271 WARN_ON_ONCE(power_well
->id
!= PUNIT_POWER_WELL_DPIO_CMN_BC
);
1273 /* since ref/cri clock was enabled */
1274 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1276 vlv_set_power_well(dev_priv
, power_well
, true);
1279 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1280 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1281 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1282 * b. The other bits such as sfr settings / modesel may all
1285 * This should only be done on init and resume from S3 with
1286 * both PLLs disabled, or we risk losing DPIO and PLL
1289 I915_WRITE(DPIO_CTL
, I915_READ(DPIO_CTL
) | DPIO_CMNRST
);
1292 static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private
*dev_priv
,
1293 struct i915_power_well
*power_well
)
1297 WARN_ON_ONCE(power_well
->id
!= PUNIT_POWER_WELL_DPIO_CMN_BC
);
1299 for_each_pipe(dev_priv
, pipe
)
1300 assert_pll_disabled(dev_priv
, pipe
);
1302 /* Assert common reset */
1303 I915_WRITE(DPIO_CTL
, I915_READ(DPIO_CTL
) & ~DPIO_CMNRST
);
1305 vlv_set_power_well(dev_priv
, power_well
, false);
1308 #define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
1310 static struct i915_power_well
*
1311 lookup_power_well(struct drm_i915_private
*dev_priv
,
1312 enum i915_power_well_id power_well_id
)
1314 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
1317 for (i
= 0; i
< power_domains
->power_well_count
; i
++) {
1318 struct i915_power_well
*power_well
;
1320 power_well
= &power_domains
->power_wells
[i
];
1321 if (power_well
->id
== power_well_id
)
1328 #define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1330 static void assert_chv_phy_status(struct drm_i915_private
*dev_priv
)
1332 struct i915_power_well
*cmn_bc
=
1333 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
);
1334 struct i915_power_well
*cmn_d
=
1335 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_D
);
1336 u32 phy_control
= dev_priv
->chv_phy_control
;
1338 u32 phy_status_mask
= 0xffffffff;
1341 * The BIOS can leave the PHY is some weird state
1342 * where it doesn't fully power down some parts.
1343 * Disable the asserts until the PHY has been fully
1344 * reset (ie. the power well has been disabled at
1347 if (!dev_priv
->chv_phy_assert
[DPIO_PHY0
])
1348 phy_status_mask
&= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0
, DPIO_CH0
) |
1349 PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH0
, 0) |
1350 PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH0
, 1) |
1351 PHY_STATUS_CMN_LDO(DPIO_PHY0
, DPIO_CH1
) |
1352 PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH1
, 0) |
1353 PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH1
, 1));
1355 if (!dev_priv
->chv_phy_assert
[DPIO_PHY1
])
1356 phy_status_mask
&= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1
, DPIO_CH0
) |
1357 PHY_STATUS_SPLINE_LDO(DPIO_PHY1
, DPIO_CH0
, 0) |
1358 PHY_STATUS_SPLINE_LDO(DPIO_PHY1
, DPIO_CH0
, 1));
1360 if (cmn_bc
->ops
->is_enabled(dev_priv
, cmn_bc
)) {
1361 phy_status
|= PHY_POWERGOOD(DPIO_PHY0
);
1363 /* this assumes override is only used to enable lanes */
1364 if ((phy_control
& PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0
, DPIO_CH0
)) == 0)
1365 phy_control
|= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0
, DPIO_CH0
);
1367 if ((phy_control
& PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0
, DPIO_CH1
)) == 0)
1368 phy_control
|= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0
, DPIO_CH1
);
1370 /* CL1 is on whenever anything is on in either channel */
1371 if (BITS_SET(phy_control
,
1372 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0
, DPIO_CH0
) |
1373 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0
, DPIO_CH1
)))
1374 phy_status
|= PHY_STATUS_CMN_LDO(DPIO_PHY0
, DPIO_CH0
);
1377 * The DPLLB check accounts for the pipe B + port A usage
1378 * with CL2 powered up but all the lanes in the second channel
1381 if (BITS_SET(phy_control
,
1382 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0
, DPIO_CH1
)) &&
1383 (I915_READ(DPLL(PIPE_B
)) & DPLL_VCO_ENABLE
) == 0)
1384 phy_status
|= PHY_STATUS_CMN_LDO(DPIO_PHY0
, DPIO_CH1
);
1386 if (BITS_SET(phy_control
,
1387 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0
, DPIO_CH0
)))
1388 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH0
, 0);
1389 if (BITS_SET(phy_control
,
1390 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0
, DPIO_CH0
)))
1391 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH0
, 1);
1393 if (BITS_SET(phy_control
,
1394 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0
, DPIO_CH1
)))
1395 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH1
, 0);
1396 if (BITS_SET(phy_control
,
1397 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0
, DPIO_CH1
)))
1398 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY0
, DPIO_CH1
, 1);
1401 if (cmn_d
->ops
->is_enabled(dev_priv
, cmn_d
)) {
1402 phy_status
|= PHY_POWERGOOD(DPIO_PHY1
);
1404 /* this assumes override is only used to enable lanes */
1405 if ((phy_control
& PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1
, DPIO_CH0
)) == 0)
1406 phy_control
|= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1
, DPIO_CH0
);
1408 if (BITS_SET(phy_control
,
1409 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1
, DPIO_CH0
)))
1410 phy_status
|= PHY_STATUS_CMN_LDO(DPIO_PHY1
, DPIO_CH0
);
1412 if (BITS_SET(phy_control
,
1413 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1
, DPIO_CH0
)))
1414 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY1
, DPIO_CH0
, 0);
1415 if (BITS_SET(phy_control
,
1416 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1
, DPIO_CH0
)))
1417 phy_status
|= PHY_STATUS_SPLINE_LDO(DPIO_PHY1
, DPIO_CH0
, 1);
1420 phy_status
&= phy_status_mask
;
1423 * The PHY may be busy with some initial calibration and whatnot,
1424 * so the power state can take a while to actually change.
1426 if (intel_wait_for_register(dev_priv
,
1431 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1432 I915_READ(DISPLAY_PHY_STATUS
) & phy_status_mask
,
1433 phy_status
, dev_priv
->chv_phy_control
);
1438 static void chv_dpio_cmn_power_well_enable(struct drm_i915_private
*dev_priv
,
1439 struct i915_power_well
*power_well
)
1445 WARN_ON_ONCE(power_well
->id
!= PUNIT_POWER_WELL_DPIO_CMN_BC
&&
1446 power_well
->id
!= PUNIT_POWER_WELL_DPIO_CMN_D
);
1448 if (power_well
->id
== PUNIT_POWER_WELL_DPIO_CMN_BC
) {
1456 /* since ref/cri clock was enabled */
1457 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1458 vlv_set_power_well(dev_priv
, power_well
, true);
1460 /* Poll for phypwrgood signal */
1461 if (intel_wait_for_register(dev_priv
,
1466 DRM_ERROR("Display PHY %d is not power up\n", phy
);
1468 mutex_lock(&dev_priv
->sb_lock
);
1470 /* Enable dynamic power down */
1471 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW28
);
1472 tmp
|= DPIO_DYNPWRDOWNEN_CH0
| DPIO_CL1POWERDOWNEN
|
1473 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ
;
1474 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW28
, tmp
);
1476 if (power_well
->id
== PUNIT_POWER_WELL_DPIO_CMN_BC
) {
1477 tmp
= vlv_dpio_read(dev_priv
, pipe
, _CHV_CMN_DW6_CH1
);
1478 tmp
|= DPIO_DYNPWRDOWNEN_CH1
;
1479 vlv_dpio_write(dev_priv
, pipe
, _CHV_CMN_DW6_CH1
, tmp
);
1482 * Force the non-existing CL2 off. BXT does this
1483 * too, so maybe it saves some power even though
1484 * CL2 doesn't exist?
1486 tmp
= vlv_dpio_read(dev_priv
, pipe
, CHV_CMN_DW30
);
1487 tmp
|= DPIO_CL2_LDOFUSE_PWRENB
;
1488 vlv_dpio_write(dev_priv
, pipe
, CHV_CMN_DW30
, tmp
);
1491 mutex_unlock(&dev_priv
->sb_lock
);
1493 dev_priv
->chv_phy_control
|= PHY_COM_LANE_RESET_DEASSERT(phy
);
1494 I915_WRITE(DISPLAY_PHY_CONTROL
, dev_priv
->chv_phy_control
);
1496 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1497 phy
, dev_priv
->chv_phy_control
);
1499 assert_chv_phy_status(dev_priv
);
1502 static void chv_dpio_cmn_power_well_disable(struct drm_i915_private
*dev_priv
,
1503 struct i915_power_well
*power_well
)
1507 WARN_ON_ONCE(power_well
->id
!= PUNIT_POWER_WELL_DPIO_CMN_BC
&&
1508 power_well
->id
!= PUNIT_POWER_WELL_DPIO_CMN_D
);
1510 if (power_well
->id
== PUNIT_POWER_WELL_DPIO_CMN_BC
) {
1512 assert_pll_disabled(dev_priv
, PIPE_A
);
1513 assert_pll_disabled(dev_priv
, PIPE_B
);
1516 assert_pll_disabled(dev_priv
, PIPE_C
);
1519 dev_priv
->chv_phy_control
&= ~PHY_COM_LANE_RESET_DEASSERT(phy
);
1520 I915_WRITE(DISPLAY_PHY_CONTROL
, dev_priv
->chv_phy_control
);
1522 vlv_set_power_well(dev_priv
, power_well
, false);
1524 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1525 phy
, dev_priv
->chv_phy_control
);
1527 /* PHY is fully reset now, so we can enable the PHY state asserts */
1528 dev_priv
->chv_phy_assert
[phy
] = true;
1530 assert_chv_phy_status(dev_priv
);
1533 static void assert_chv_phy_powergate(struct drm_i915_private
*dev_priv
, enum dpio_phy phy
,
1534 enum dpio_channel ch
, bool override
, unsigned int mask
)
1536 enum pipe pipe
= phy
== DPIO_PHY0
? PIPE_A
: PIPE_C
;
1537 u32 reg
, val
, expected
, actual
;
1540 * The BIOS can leave the PHY is some weird state
1541 * where it doesn't fully power down some parts.
1542 * Disable the asserts until the PHY has been fully
1543 * reset (ie. the power well has been disabled at
1546 if (!dev_priv
->chv_phy_assert
[phy
])
1550 reg
= _CHV_CMN_DW0_CH0
;
1552 reg
= _CHV_CMN_DW6_CH1
;
1554 mutex_lock(&dev_priv
->sb_lock
);
1555 val
= vlv_dpio_read(dev_priv
, pipe
, reg
);
1556 mutex_unlock(&dev_priv
->sb_lock
);
1559 * This assumes !override is only used when the port is disabled.
1560 * All lanes should power down even without the override when
1561 * the port is disabled.
1563 if (!override
|| mask
== 0xf) {
1564 expected
= DPIO_ALLDL_POWERDOWN
| DPIO_ANYDL_POWERDOWN
;
1566 * If CH1 common lane is not active anymore
1567 * (eg. for pipe B DPLL) the entire channel will
1568 * shut down, which causes the common lane registers
1569 * to read as 0. That means we can't actually check
1570 * the lane power down status bits, but as the entire
1571 * register reads as 0 it's a good indication that the
1572 * channel is indeed entirely powered down.
1574 if (ch
== DPIO_CH1
&& val
== 0)
1576 } else if (mask
!= 0x0) {
1577 expected
= DPIO_ANYDL_POWERDOWN
;
1583 actual
= val
>> DPIO_ANYDL_POWERDOWN_SHIFT_CH0
;
1585 actual
= val
>> DPIO_ANYDL_POWERDOWN_SHIFT_CH1
;
1586 actual
&= DPIO_ALLDL_POWERDOWN
| DPIO_ANYDL_POWERDOWN
;
1588 WARN(actual
!= expected
,
1589 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1590 !!(actual
& DPIO_ALLDL_POWERDOWN
), !!(actual
& DPIO_ANYDL_POWERDOWN
),
1591 !!(expected
& DPIO_ALLDL_POWERDOWN
), !!(expected
& DPIO_ANYDL_POWERDOWN
),
1595 bool chv_phy_powergate_ch(struct drm_i915_private
*dev_priv
, enum dpio_phy phy
,
1596 enum dpio_channel ch
, bool override
)
1598 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
1601 mutex_lock(&power_domains
->lock
);
1603 was_override
= dev_priv
->chv_phy_control
& PHY_CH_POWER_DOWN_OVRD_EN(phy
, ch
);
1605 if (override
== was_override
)
1609 dev_priv
->chv_phy_control
|= PHY_CH_POWER_DOWN_OVRD_EN(phy
, ch
);
1611 dev_priv
->chv_phy_control
&= ~PHY_CH_POWER_DOWN_OVRD_EN(phy
, ch
);
1613 I915_WRITE(DISPLAY_PHY_CONTROL
, dev_priv
->chv_phy_control
);
1615 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1616 phy
, ch
, dev_priv
->chv_phy_control
);
1618 assert_chv_phy_status(dev_priv
);
1621 mutex_unlock(&power_domains
->lock
);
1623 return was_override
;
1626 void chv_phy_powergate_lanes(struct intel_encoder
*encoder
,
1627 bool override
, unsigned int mask
)
1629 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
1630 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
1631 enum dpio_phy phy
= vlv_dport_to_phy(enc_to_dig_port(&encoder
->base
));
1632 enum dpio_channel ch
= vlv_dport_to_channel(enc_to_dig_port(&encoder
->base
));
1634 mutex_lock(&power_domains
->lock
);
1636 dev_priv
->chv_phy_control
&= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy
, ch
);
1637 dev_priv
->chv_phy_control
|= PHY_CH_POWER_DOWN_OVRD(mask
, phy
, ch
);
1640 dev_priv
->chv_phy_control
|= PHY_CH_POWER_DOWN_OVRD_EN(phy
, ch
);
1642 dev_priv
->chv_phy_control
&= ~PHY_CH_POWER_DOWN_OVRD_EN(phy
, ch
);
1644 I915_WRITE(DISPLAY_PHY_CONTROL
, dev_priv
->chv_phy_control
);
1646 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1647 phy
, ch
, mask
, dev_priv
->chv_phy_control
);
1649 assert_chv_phy_status(dev_priv
);
1651 assert_chv_phy_powergate(dev_priv
, phy
, ch
, override
, mask
);
1653 mutex_unlock(&power_domains
->lock
);
1656 static bool chv_pipe_power_well_enabled(struct drm_i915_private
*dev_priv
,
1657 struct i915_power_well
*power_well
)
1659 enum pipe pipe
= PIPE_A
;
1663 mutex_lock(&dev_priv
->rps
.hw_lock
);
1665 state
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) & DP_SSS_MASK(pipe
);
1667 * We only ever set the power-on and power-gate states, anything
1668 * else is unexpected.
1670 WARN_ON(state
!= DP_SSS_PWR_ON(pipe
) && state
!= DP_SSS_PWR_GATE(pipe
));
1671 enabled
= state
== DP_SSS_PWR_ON(pipe
);
1674 * A transient state at this point would mean some unexpected party
1675 * is poking at the power controls too.
1677 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) & DP_SSC_MASK(pipe
);
1678 WARN_ON(ctrl
<< 16 != state
);
1680 mutex_unlock(&dev_priv
->rps
.hw_lock
);
1685 static void chv_set_pipe_power_well(struct drm_i915_private
*dev_priv
,
1686 struct i915_power_well
*power_well
,
1689 enum pipe pipe
= PIPE_A
;
1693 state
= enable
? DP_SSS_PWR_ON(pipe
) : DP_SSS_PWR_GATE(pipe
);
1695 mutex_lock(&dev_priv
->rps
.hw_lock
);
1698 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1703 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
1704 ctrl
&= ~DP_SSC_MASK(pipe
);
1705 ctrl
|= enable
? DP_SSC_PWR_ON(pipe
) : DP_SSC_PWR_GATE(pipe
);
1706 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, ctrl
);
1708 if (wait_for(COND
, 100))
1709 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
1711 vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
));
1716 mutex_unlock(&dev_priv
->rps
.hw_lock
);
1719 static void chv_pipe_power_well_enable(struct drm_i915_private
*dev_priv
,
1720 struct i915_power_well
*power_well
)
1722 WARN_ON_ONCE(power_well
->id
!= CHV_DISP_PW_PIPE_A
);
1724 chv_set_pipe_power_well(dev_priv
, power_well
, true);
1726 vlv_display_power_well_init(dev_priv
);
1729 static void chv_pipe_power_well_disable(struct drm_i915_private
*dev_priv
,
1730 struct i915_power_well
*power_well
)
1732 WARN_ON_ONCE(power_well
->id
!= CHV_DISP_PW_PIPE_A
);
1734 vlv_display_power_well_deinit(dev_priv
);
1736 chv_set_pipe_power_well(dev_priv
, power_well
, false);
1740 __intel_display_power_get_domain(struct drm_i915_private
*dev_priv
,
1741 enum intel_display_power_domain domain
)
1743 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
1744 struct i915_power_well
*power_well
;
1746 for_each_power_domain_well(dev_priv
, power_well
, BIT_ULL(domain
))
1747 intel_power_well_get(dev_priv
, power_well
);
1749 power_domains
->domain_use_count
[domain
]++;
1753 * intel_display_power_get - grab a power domain reference
1754 * @dev_priv: i915 device instance
1755 * @domain: power domain to reference
1757 * This function grabs a power domain reference for @domain and ensures that the
1758 * power domain and all its parents are powered up. Therefore users should only
1759 * grab a reference to the innermost power domain they need.
1761 * Any power domain reference obtained by this function must have a symmetric
1762 * call to intel_display_power_put() to release the reference again.
1764 void intel_display_power_get(struct drm_i915_private
*dev_priv
,
1765 enum intel_display_power_domain domain
)
1767 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
1769 intel_runtime_pm_get(dev_priv
);
1771 mutex_lock(&power_domains
->lock
);
1773 __intel_display_power_get_domain(dev_priv
, domain
);
1775 mutex_unlock(&power_domains
->lock
);
1779 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1780 * @dev_priv: i915 device instance
1781 * @domain: power domain to reference
1783 * This function grabs a power domain reference for @domain and ensures that the
1784 * power domain and all its parents are powered up. Therefore users should only
1785 * grab a reference to the innermost power domain they need.
1787 * Any power domain reference obtained by this function must have a symmetric
1788 * call to intel_display_power_put() to release the reference again.
1790 bool intel_display_power_get_if_enabled(struct drm_i915_private
*dev_priv
,
1791 enum intel_display_power_domain domain
)
1793 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
1796 if (!intel_runtime_pm_get_if_in_use(dev_priv
))
1799 mutex_lock(&power_domains
->lock
);
1801 if (__intel_display_power_is_enabled(dev_priv
, domain
)) {
1802 __intel_display_power_get_domain(dev_priv
, domain
);
1808 mutex_unlock(&power_domains
->lock
);
1811 intel_runtime_pm_put(dev_priv
);
1817 * intel_display_power_put - release a power domain reference
1818 * @dev_priv: i915 device instance
1819 * @domain: power domain to reference
1821 * This function drops the power domain reference obtained by
1822 * intel_display_power_get() and might power down the corresponding hardware
1823 * block right away if this is the last reference.
1825 void intel_display_power_put(struct drm_i915_private
*dev_priv
,
1826 enum intel_display_power_domain domain
)
1828 struct i915_power_domains
*power_domains
;
1829 struct i915_power_well
*power_well
;
1831 power_domains
= &dev_priv
->power_domains
;
1833 mutex_lock(&power_domains
->lock
);
1835 WARN(!power_domains
->domain_use_count
[domain
],
1836 "Use count on domain %s is already zero\n",
1837 intel_display_power_domain_str(domain
));
1838 power_domains
->domain_use_count
[domain
]--;
1840 for_each_power_domain_well_rev(dev_priv
, power_well
, BIT_ULL(domain
))
1841 intel_power_well_put(dev_priv
, power_well
);
1843 mutex_unlock(&power_domains
->lock
);
1845 intel_runtime_pm_put(dev_priv
);
1848 #define HSW_DISPLAY_POWER_DOMAINS ( \
1849 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1850 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1851 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1852 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1853 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1854 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1855 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1856 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1857 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1858 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1859 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1860 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1861 BIT_ULL(POWER_DOMAIN_VGA) | \
1862 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1863 BIT_ULL(POWER_DOMAIN_INIT))
1865 #define BDW_DISPLAY_POWER_DOMAINS ( \
1866 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1867 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1868 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1869 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1870 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1871 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1872 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1873 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1874 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1875 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1876 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1877 BIT_ULL(POWER_DOMAIN_VGA) | \
1878 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1879 BIT_ULL(POWER_DOMAIN_INIT))
1881 #define VLV_DISPLAY_POWER_DOMAINS ( \
1882 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1883 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1884 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1885 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1886 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1887 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1888 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1889 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1890 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1891 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1892 BIT_ULL(POWER_DOMAIN_VGA) | \
1893 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1894 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1895 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1896 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1897 BIT_ULL(POWER_DOMAIN_INIT))
1899 #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
1900 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1901 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1902 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1903 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1904 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1905 BIT_ULL(POWER_DOMAIN_INIT))
1907 #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
1908 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1909 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1910 BIT_ULL(POWER_DOMAIN_INIT))
1912 #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
1913 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1914 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1915 BIT_ULL(POWER_DOMAIN_INIT))
1917 #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
1918 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1919 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1920 BIT_ULL(POWER_DOMAIN_INIT))
1922 #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
1923 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1924 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1925 BIT_ULL(POWER_DOMAIN_INIT))
1927 #define CHV_DISPLAY_POWER_DOMAINS ( \
1928 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1929 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1930 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1931 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1932 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1933 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1934 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1935 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1936 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1937 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1938 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1939 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1940 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1941 BIT_ULL(POWER_DOMAIN_VGA) | \
1942 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1943 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1944 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1945 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1946 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1947 BIT_ULL(POWER_DOMAIN_INIT))
1949 #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
1950 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1951 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1952 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1953 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1954 BIT_ULL(POWER_DOMAIN_INIT))
1956 #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
1957 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1958 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1959 BIT_ULL(POWER_DOMAIN_INIT))
1961 #define I830_PIPES_POWER_DOMAINS ( \
1962 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1963 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1964 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1965 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1966 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1967 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1968 BIT_ULL(POWER_DOMAIN_INIT))
1970 static const struct i915_power_well_ops i9xx_always_on_power_well_ops
= {
1971 .sync_hw
= i9xx_power_well_sync_hw_noop
,
1972 .enable
= i9xx_always_on_power_well_noop
,
1973 .disable
= i9xx_always_on_power_well_noop
,
1974 .is_enabled
= i9xx_always_on_power_well_enabled
,
1977 static const struct i915_power_well_ops chv_pipe_power_well_ops
= {
1978 .sync_hw
= i9xx_power_well_sync_hw_noop
,
1979 .enable
= chv_pipe_power_well_enable
,
1980 .disable
= chv_pipe_power_well_disable
,
1981 .is_enabled
= chv_pipe_power_well_enabled
,
1984 static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops
= {
1985 .sync_hw
= i9xx_power_well_sync_hw_noop
,
1986 .enable
= chv_dpio_cmn_power_well_enable
,
1987 .disable
= chv_dpio_cmn_power_well_disable
,
1988 .is_enabled
= vlv_power_well_enabled
,
1991 static struct i915_power_well i9xx_always_on_power_well
[] = {
1993 .name
= "always-on",
1995 .domains
= POWER_DOMAIN_MASK
,
1996 .ops
= &i9xx_always_on_power_well_ops
,
1997 .id
= I915_DISP_PW_ALWAYS_ON
,
2001 static const struct i915_power_well_ops i830_pipes_power_well_ops
= {
2002 .sync_hw
= i830_pipes_power_well_sync_hw
,
2003 .enable
= i830_pipes_power_well_enable
,
2004 .disable
= i830_pipes_power_well_disable
,
2005 .is_enabled
= i830_pipes_power_well_enabled
,
2008 static struct i915_power_well i830_power_wells
[] = {
2010 .name
= "always-on",
2012 .domains
= POWER_DOMAIN_MASK
,
2013 .ops
= &i9xx_always_on_power_well_ops
,
2014 .id
= I915_DISP_PW_ALWAYS_ON
,
2018 .domains
= I830_PIPES_POWER_DOMAINS
,
2019 .ops
= &i830_pipes_power_well_ops
,
2020 .id
= I830_DISP_PW_PIPES
,
2024 static const struct i915_power_well_ops hsw_power_well_ops
= {
2025 .sync_hw
= hsw_power_well_sync_hw
,
2026 .enable
= hsw_power_well_enable
,
2027 .disable
= hsw_power_well_disable
,
2028 .is_enabled
= hsw_power_well_enabled
,
2031 static const struct i915_power_well_ops skl_power_well_ops
= {
2032 .sync_hw
= skl_power_well_sync_hw
,
2033 .enable
= skl_power_well_enable
,
2034 .disable
= skl_power_well_disable
,
2035 .is_enabled
= skl_power_well_enabled
,
2038 static const struct i915_power_well_ops gen9_dc_off_power_well_ops
= {
2039 .sync_hw
= i9xx_power_well_sync_hw_noop
,
2040 .enable
= gen9_dc_off_power_well_enable
,
2041 .disable
= gen9_dc_off_power_well_disable
,
2042 .is_enabled
= gen9_dc_off_power_well_enabled
,
2045 static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops
= {
2046 .sync_hw
= i9xx_power_well_sync_hw_noop
,
2047 .enable
= bxt_dpio_cmn_power_well_enable
,
2048 .disable
= bxt_dpio_cmn_power_well_disable
,
2049 .is_enabled
= bxt_dpio_cmn_power_well_enabled
,
2052 static struct i915_power_well hsw_power_wells
[] = {
2054 .name
= "always-on",
2056 .domains
= POWER_DOMAIN_MASK
,
2057 .ops
= &i9xx_always_on_power_well_ops
,
2058 .id
= I915_DISP_PW_ALWAYS_ON
,
2062 .domains
= HSW_DISPLAY_POWER_DOMAINS
,
2063 .ops
= &hsw_power_well_ops
,
2064 .id
= HSW_DISP_PW_GLOBAL
,
2065 .hsw
.has_vga
= true,
2069 static struct i915_power_well bdw_power_wells
[] = {
2071 .name
= "always-on",
2073 .domains
= POWER_DOMAIN_MASK
,
2074 .ops
= &i9xx_always_on_power_well_ops
,
2075 .id
= I915_DISP_PW_ALWAYS_ON
,
2079 .domains
= BDW_DISPLAY_POWER_DOMAINS
,
2080 .ops
= &hsw_power_well_ops
,
2081 .id
= HSW_DISP_PW_GLOBAL
,
2082 .hsw
.irq_pipe_mask
= BIT(PIPE_B
) | BIT(PIPE_C
),
2083 .hsw
.has_vga
= true,
2087 static const struct i915_power_well_ops vlv_display_power_well_ops
= {
2088 .sync_hw
= i9xx_power_well_sync_hw_noop
,
2089 .enable
= vlv_display_power_well_enable
,
2090 .disable
= vlv_display_power_well_disable
,
2091 .is_enabled
= vlv_power_well_enabled
,
2094 static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops
= {
2095 .sync_hw
= i9xx_power_well_sync_hw_noop
,
2096 .enable
= vlv_dpio_cmn_power_well_enable
,
2097 .disable
= vlv_dpio_cmn_power_well_disable
,
2098 .is_enabled
= vlv_power_well_enabled
,
2101 static const struct i915_power_well_ops vlv_dpio_power_well_ops
= {
2102 .sync_hw
= i9xx_power_well_sync_hw_noop
,
2103 .enable
= vlv_power_well_enable
,
2104 .disable
= vlv_power_well_disable
,
2105 .is_enabled
= vlv_power_well_enabled
,
2108 static struct i915_power_well vlv_power_wells
[] = {
2110 .name
= "always-on",
2112 .domains
= POWER_DOMAIN_MASK
,
2113 .ops
= &i9xx_always_on_power_well_ops
,
2114 .id
= I915_DISP_PW_ALWAYS_ON
,
2118 .domains
= VLV_DISPLAY_POWER_DOMAINS
,
2119 .id
= PUNIT_POWER_WELL_DISP2D
,
2120 .ops
= &vlv_display_power_well_ops
,
2123 .name
= "dpio-tx-b-01",
2124 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
2125 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
2126 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
2127 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
2128 .ops
= &vlv_dpio_power_well_ops
,
2129 .id
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_01
,
2132 .name
= "dpio-tx-b-23",
2133 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
2134 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
2135 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
2136 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
2137 .ops
= &vlv_dpio_power_well_ops
,
2138 .id
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_23
,
2141 .name
= "dpio-tx-c-01",
2142 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
2143 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
2144 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
2145 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
2146 .ops
= &vlv_dpio_power_well_ops
,
2147 .id
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_01
,
2150 .name
= "dpio-tx-c-23",
2151 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
2152 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
2153 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
2154 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
2155 .ops
= &vlv_dpio_power_well_ops
,
2156 .id
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_23
,
2159 .name
= "dpio-common",
2160 .domains
= VLV_DPIO_CMN_BC_POWER_DOMAINS
,
2161 .id
= PUNIT_POWER_WELL_DPIO_CMN_BC
,
2162 .ops
= &vlv_dpio_cmn_power_well_ops
,
2166 static struct i915_power_well chv_power_wells
[] = {
2168 .name
= "always-on",
2170 .domains
= POWER_DOMAIN_MASK
,
2171 .ops
= &i9xx_always_on_power_well_ops
,
2172 .id
= I915_DISP_PW_ALWAYS_ON
,
2177 * Pipe A power well is the new disp2d well. Pipe B and C
2178 * power wells don't actually exist. Pipe A power well is
2179 * required for any pipe to work.
2181 .domains
= CHV_DISPLAY_POWER_DOMAINS
,
2182 .id
= CHV_DISP_PW_PIPE_A
,
2183 .ops
= &chv_pipe_power_well_ops
,
2186 .name
= "dpio-common-bc",
2187 .domains
= CHV_DPIO_CMN_BC_POWER_DOMAINS
,
2188 .id
= PUNIT_POWER_WELL_DPIO_CMN_BC
,
2189 .ops
= &chv_dpio_cmn_power_well_ops
,
2192 .name
= "dpio-common-d",
2193 .domains
= CHV_DPIO_CMN_D_POWER_DOMAINS
,
2194 .id
= PUNIT_POWER_WELL_DPIO_CMN_D
,
2195 .ops
= &chv_dpio_cmn_power_well_ops
,
2199 bool intel_display_power_well_is_enabled(struct drm_i915_private
*dev_priv
,
2200 enum i915_power_well_id power_well_id
)
2202 struct i915_power_well
*power_well
;
2205 power_well
= lookup_power_well(dev_priv
, power_well_id
);
2206 ret
= power_well
->ops
->is_enabled(dev_priv
, power_well
);
2211 static struct i915_power_well skl_power_wells
[] = {
2213 .name
= "always-on",
2215 .domains
= POWER_DOMAIN_MASK
,
2216 .ops
= &i9xx_always_on_power_well_ops
,
2217 .id
= I915_DISP_PW_ALWAYS_ON
,
2220 .name
= "power well 1",
2221 /* Handled by the DMC firmware */
2223 .ops
= &skl_power_well_ops
,
2224 .id
= SKL_DISP_PW_1
,
2227 .name
= "MISC IO power well",
2228 /* Handled by the DMC firmware */
2230 .ops
= &skl_power_well_ops
,
2231 .id
= SKL_DISP_PW_MISC_IO
,
2235 .domains
= SKL_DISPLAY_DC_OFF_POWER_DOMAINS
,
2236 .ops
= &gen9_dc_off_power_well_ops
,
2237 .id
= SKL_DISP_PW_DC_OFF
,
2240 .name
= "power well 2",
2241 .domains
= SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS
,
2242 .ops
= &skl_power_well_ops
,
2243 .id
= SKL_DISP_PW_2
,
2246 .name
= "DDI A/E IO power well",
2247 .domains
= SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS
,
2248 .ops
= &skl_power_well_ops
,
2249 .id
= SKL_DISP_PW_DDI_A_E
,
2252 .name
= "DDI B IO power well",
2253 .domains
= SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS
,
2254 .ops
= &skl_power_well_ops
,
2255 .id
= SKL_DISP_PW_DDI_B
,
2258 .name
= "DDI C IO power well",
2259 .domains
= SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS
,
2260 .ops
= &skl_power_well_ops
,
2261 .id
= SKL_DISP_PW_DDI_C
,
2264 .name
= "DDI D IO power well",
2265 .domains
= SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS
,
2266 .ops
= &skl_power_well_ops
,
2267 .id
= SKL_DISP_PW_DDI_D
,
2271 static struct i915_power_well bxt_power_wells
[] = {
2273 .name
= "always-on",
2275 .domains
= POWER_DOMAIN_MASK
,
2276 .ops
= &i9xx_always_on_power_well_ops
,
2277 .id
= I915_DISP_PW_ALWAYS_ON
,
2280 .name
= "power well 1",
2282 .ops
= &skl_power_well_ops
,
2283 .id
= SKL_DISP_PW_1
,
2287 .domains
= BXT_DISPLAY_DC_OFF_POWER_DOMAINS
,
2288 .ops
= &gen9_dc_off_power_well_ops
,
2289 .id
= SKL_DISP_PW_DC_OFF
,
2292 .name
= "power well 2",
2293 .domains
= BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS
,
2294 .ops
= &skl_power_well_ops
,
2295 .id
= SKL_DISP_PW_2
,
2298 .name
= "dpio-common-a",
2299 .domains
= BXT_DPIO_CMN_A_POWER_DOMAINS
,
2300 .ops
= &bxt_dpio_cmn_power_well_ops
,
2301 .id
= BXT_DPIO_CMN_A
,
2302 .bxt
.phy
= DPIO_PHY1
,
2305 .name
= "dpio-common-bc",
2306 .domains
= BXT_DPIO_CMN_BC_POWER_DOMAINS
,
2307 .ops
= &bxt_dpio_cmn_power_well_ops
,
2308 .id
= BXT_DPIO_CMN_BC
,
2309 .bxt
.phy
= DPIO_PHY0
,
2313 static struct i915_power_well glk_power_wells
[] = {
2315 .name
= "always-on",
2317 .domains
= POWER_DOMAIN_MASK
,
2318 .ops
= &i9xx_always_on_power_well_ops
,
2319 .id
= I915_DISP_PW_ALWAYS_ON
,
2322 .name
= "power well 1",
2323 /* Handled by the DMC firmware */
2325 .ops
= &skl_power_well_ops
,
2326 .id
= SKL_DISP_PW_1
,
2330 .domains
= GLK_DISPLAY_DC_OFF_POWER_DOMAINS
,
2331 .ops
= &gen9_dc_off_power_well_ops
,
2332 .id
= SKL_DISP_PW_DC_OFF
,
2335 .name
= "power well 2",
2336 .domains
= GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS
,
2337 .ops
= &skl_power_well_ops
,
2338 .id
= SKL_DISP_PW_2
,
2341 .name
= "dpio-common-a",
2342 .domains
= GLK_DPIO_CMN_A_POWER_DOMAINS
,
2343 .ops
= &bxt_dpio_cmn_power_well_ops
,
2344 .id
= BXT_DPIO_CMN_A
,
2345 .bxt
.phy
= DPIO_PHY1
,
2348 .name
= "dpio-common-b",
2349 .domains
= GLK_DPIO_CMN_B_POWER_DOMAINS
,
2350 .ops
= &bxt_dpio_cmn_power_well_ops
,
2351 .id
= BXT_DPIO_CMN_BC
,
2352 .bxt
.phy
= DPIO_PHY0
,
2355 .name
= "dpio-common-c",
2356 .domains
= GLK_DPIO_CMN_C_POWER_DOMAINS
,
2357 .ops
= &bxt_dpio_cmn_power_well_ops
,
2358 .id
= GLK_DPIO_CMN_C
,
2359 .bxt
.phy
= DPIO_PHY2
,
2363 .domains
= GLK_DISPLAY_AUX_A_POWER_DOMAINS
,
2364 .ops
= &skl_power_well_ops
,
2365 .id
= GLK_DISP_PW_AUX_A
,
2369 .domains
= GLK_DISPLAY_AUX_B_POWER_DOMAINS
,
2370 .ops
= &skl_power_well_ops
,
2371 .id
= GLK_DISP_PW_AUX_B
,
2375 .domains
= GLK_DISPLAY_AUX_C_POWER_DOMAINS
,
2376 .ops
= &skl_power_well_ops
,
2377 .id
= GLK_DISP_PW_AUX_C
,
2380 .name
= "DDI A IO power well",
2381 .domains
= GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS
,
2382 .ops
= &skl_power_well_ops
,
2383 .id
= GLK_DISP_PW_DDI_A
,
2386 .name
= "DDI B IO power well",
2387 .domains
= GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS
,
2388 .ops
= &skl_power_well_ops
,
2389 .id
= SKL_DISP_PW_DDI_B
,
2392 .name
= "DDI C IO power well",
2393 .domains
= GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS
,
2394 .ops
= &skl_power_well_ops
,
2395 .id
= SKL_DISP_PW_DDI_C
,
2399 static struct i915_power_well cnl_power_wells
[] = {
2401 .name
= "always-on",
2403 .domains
= POWER_DOMAIN_MASK
,
2404 .ops
= &i9xx_always_on_power_well_ops
,
2405 .id
= I915_DISP_PW_ALWAYS_ON
,
2408 .name
= "power well 1",
2409 /* Handled by the DMC firmware */
2411 .ops
= &skl_power_well_ops
,
2412 .id
= SKL_DISP_PW_1
,
2416 .domains
= CNL_DISPLAY_AUX_A_POWER_DOMAINS
,
2417 .ops
= &skl_power_well_ops
,
2418 .id
= CNL_DISP_PW_AUX_A
,
2422 .domains
= CNL_DISPLAY_AUX_B_POWER_DOMAINS
,
2423 .ops
= &skl_power_well_ops
,
2424 .id
= CNL_DISP_PW_AUX_B
,
2428 .domains
= CNL_DISPLAY_AUX_C_POWER_DOMAINS
,
2429 .ops
= &skl_power_well_ops
,
2430 .id
= CNL_DISP_PW_AUX_C
,
2434 .domains
= CNL_DISPLAY_AUX_D_POWER_DOMAINS
,
2435 .ops
= &skl_power_well_ops
,
2436 .id
= CNL_DISP_PW_AUX_D
,
2440 .domains
= CNL_DISPLAY_DC_OFF_POWER_DOMAINS
,
2441 .ops
= &gen9_dc_off_power_well_ops
,
2442 .id
= SKL_DISP_PW_DC_OFF
,
2445 .name
= "power well 2",
2446 .domains
= CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS
,
2447 .ops
= &skl_power_well_ops
,
2448 .id
= SKL_DISP_PW_2
,
2451 .name
= "DDI A IO power well",
2452 .domains
= CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS
,
2453 .ops
= &skl_power_well_ops
,
2454 .id
= CNL_DISP_PW_DDI_A
,
2457 .name
= "DDI B IO power well",
2458 .domains
= CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS
,
2459 .ops
= &skl_power_well_ops
,
2460 .id
= SKL_DISP_PW_DDI_B
,
2463 .name
= "DDI C IO power well",
2464 .domains
= CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS
,
2465 .ops
= &skl_power_well_ops
,
2466 .id
= SKL_DISP_PW_DDI_C
,
2469 .name
= "DDI D IO power well",
2470 .domains
= CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS
,
2471 .ops
= &skl_power_well_ops
,
2472 .id
= SKL_DISP_PW_DDI_D
,
2477 sanitize_disable_power_well_option(const struct drm_i915_private
*dev_priv
,
2478 int disable_power_well
)
2480 if (disable_power_well
>= 0)
2481 return !!disable_power_well
;
2486 static uint32_t get_allowed_dc_mask(const struct drm_i915_private
*dev_priv
,
2493 if (IS_GEN9_BC(dev_priv
) || IS_CANNONLAKE(dev_priv
)) {
2496 } else if (IS_GEN9_LP(dev_priv
)) {
2499 * DC9 has a separate HW flow from the rest of the DC states,
2500 * not depending on the DMC firmware. It's needed by system
2501 * suspend/resume, so allow it unconditionally.
2503 mask
= DC_STATE_EN_DC9
;
2509 if (!i915
.disable_power_well
)
2512 if (enable_dc
>= 0 && enable_dc
<= max_dc
) {
2513 requested_dc
= enable_dc
;
2514 } else if (enable_dc
== -1) {
2515 requested_dc
= max_dc
;
2516 } else if (enable_dc
> max_dc
&& enable_dc
<= 2) {
2517 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2519 requested_dc
= max_dc
;
2521 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc
);
2522 requested_dc
= max_dc
;
2525 if (requested_dc
> 1)
2526 mask
|= DC_STATE_EN_UPTO_DC6
;
2527 if (requested_dc
> 0)
2528 mask
|= DC_STATE_EN_UPTO_DC5
;
2530 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask
);
2535 static void assert_power_well_ids_unique(struct drm_i915_private
*dev_priv
)
2537 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
2542 for (i
= 0; i
< power_domains
->power_well_count
; i
++) {
2543 enum i915_power_well_id id
= power_domains
->power_wells
[i
].id
;
2545 WARN_ON(id
>= sizeof(power_well_ids
) * 8);
2546 WARN_ON(power_well_ids
& BIT_ULL(id
));
2547 power_well_ids
|= BIT_ULL(id
);
2551 #define set_power_wells(power_domains, __power_wells) ({ \
2552 (power_domains)->power_wells = (__power_wells); \
2553 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2557 * intel_power_domains_init - initializes the power domain structures
2558 * @dev_priv: i915 device instance
2560 * Initializes the power domain structures for @dev_priv depending upon the
2561 * supported platform.
2563 int intel_power_domains_init(struct drm_i915_private
*dev_priv
)
2565 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
2567 i915
.disable_power_well
= sanitize_disable_power_well_option(dev_priv
,
2568 i915
.disable_power_well
);
2569 dev_priv
->csr
.allowed_dc_mask
= get_allowed_dc_mask(dev_priv
,
2572 BUILD_BUG_ON(POWER_DOMAIN_NUM
> 64);
2574 mutex_init(&power_domains
->lock
);
2577 * The enabling order will be from lower to higher indexed wells,
2578 * the disabling order is reversed.
2580 if (IS_HASWELL(dev_priv
)) {
2581 set_power_wells(power_domains
, hsw_power_wells
);
2582 } else if (IS_BROADWELL(dev_priv
)) {
2583 set_power_wells(power_domains
, bdw_power_wells
);
2584 } else if (IS_GEN9_BC(dev_priv
)) {
2585 set_power_wells(power_domains
, skl_power_wells
);
2586 } else if (IS_CANNONLAKE(dev_priv
)) {
2587 set_power_wells(power_domains
, cnl_power_wells
);
2588 } else if (IS_BROXTON(dev_priv
)) {
2589 set_power_wells(power_domains
, bxt_power_wells
);
2590 } else if (IS_GEMINILAKE(dev_priv
)) {
2591 set_power_wells(power_domains
, glk_power_wells
);
2592 } else if (IS_CHERRYVIEW(dev_priv
)) {
2593 set_power_wells(power_domains
, chv_power_wells
);
2594 } else if (IS_VALLEYVIEW(dev_priv
)) {
2595 set_power_wells(power_domains
, vlv_power_wells
);
2596 } else if (IS_I830(dev_priv
)) {
2597 set_power_wells(power_domains
, i830_power_wells
);
2599 set_power_wells(power_domains
, i9xx_always_on_power_well
);
2602 assert_power_well_ids_unique(dev_priv
);
2608 * intel_power_domains_fini - finalizes the power domain structures
2609 * @dev_priv: i915 device instance
2611 * Finalizes the power domain structures for @dev_priv depending upon the
2612 * supported platform. This function also disables runtime pm and ensures that
2613 * the device stays powered up so that the driver can be reloaded.
2615 void intel_power_domains_fini(struct drm_i915_private
*dev_priv
)
2617 struct device
*kdev
= &dev_priv
->drm
.pdev
->dev
;
2620 * The i915.ko module is still not prepared to be loaded when
2621 * the power well is not enabled, so just enable it in case
2622 * we're going to unload/reload.
2623 * The following also reacquires the RPM reference the core passed
2624 * to the driver during loading, which is dropped in
2625 * intel_runtime_pm_enable(). We have to hand back the control of the
2626 * device to the core with this reference held.
2628 intel_display_set_init_power(dev_priv
, true);
2630 /* Remove the refcount we took to keep power well support disabled. */
2631 if (!i915
.disable_power_well
)
2632 intel_display_power_put(dev_priv
, POWER_DOMAIN_INIT
);
2635 * Remove the refcount we took in intel_runtime_pm_enable() in case
2636 * the platform doesn't support runtime PM.
2638 if (!HAS_RUNTIME_PM(dev_priv
))
2639 pm_runtime_put(kdev
);
2642 static void intel_power_domains_sync_hw(struct drm_i915_private
*dev_priv
)
2644 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
2645 struct i915_power_well
*power_well
;
2647 mutex_lock(&power_domains
->lock
);
2648 for_each_power_well(dev_priv
, power_well
) {
2649 power_well
->ops
->sync_hw(dev_priv
, power_well
);
2650 power_well
->hw_enabled
= power_well
->ops
->is_enabled(dev_priv
,
2653 mutex_unlock(&power_domains
->lock
);
2656 static void gen9_dbuf_enable(struct drm_i915_private
*dev_priv
)
2658 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) | DBUF_POWER_REQUEST
);
2659 POSTING_READ(DBUF_CTL
);
2663 if (!(I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
))
2664 DRM_ERROR("DBuf power enable timeout\n");
2667 static void gen9_dbuf_disable(struct drm_i915_private
*dev_priv
)
2669 I915_WRITE(DBUF_CTL
, I915_READ(DBUF_CTL
) & ~DBUF_POWER_REQUEST
);
2670 POSTING_READ(DBUF_CTL
);
2674 if (I915_READ(DBUF_CTL
) & DBUF_POWER_STATE
)
2675 DRM_ERROR("DBuf power disable timeout!\n");
2678 static void skl_display_core_init(struct drm_i915_private
*dev_priv
,
2681 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
2682 struct i915_power_well
*well
;
2685 gen9_set_dc_state(dev_priv
, DC_STATE_DISABLE
);
2687 /* enable PCH reset handshake */
2688 val
= I915_READ(HSW_NDE_RSTWRN_OPT
);
2689 I915_WRITE(HSW_NDE_RSTWRN_OPT
, val
| RESET_PCH_HANDSHAKE_ENABLE
);
2691 /* enable PG1 and Misc I/O */
2692 mutex_lock(&power_domains
->lock
);
2694 well
= lookup_power_well(dev_priv
, SKL_DISP_PW_1
);
2695 intel_power_well_enable(dev_priv
, well
);
2697 well
= lookup_power_well(dev_priv
, SKL_DISP_PW_MISC_IO
);
2698 intel_power_well_enable(dev_priv
, well
);
2700 mutex_unlock(&power_domains
->lock
);
2702 skl_init_cdclk(dev_priv
);
2704 gen9_dbuf_enable(dev_priv
);
2706 if (resume
&& dev_priv
->csr
.dmc_payload
)
2707 intel_csr_load_program(dev_priv
);
2710 static void skl_display_core_uninit(struct drm_i915_private
*dev_priv
)
2712 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
2713 struct i915_power_well
*well
;
2715 gen9_set_dc_state(dev_priv
, DC_STATE_DISABLE
);
2717 gen9_dbuf_disable(dev_priv
);
2719 skl_uninit_cdclk(dev_priv
);
2721 /* The spec doesn't call for removing the reset handshake flag */
2722 /* disable PG1 and Misc I/O */
2724 mutex_lock(&power_domains
->lock
);
2727 * BSpec says to keep the MISC IO power well enabled here, only
2728 * remove our request for power well 1.
2729 * Note that even though the driver's request is removed power well 1
2730 * may stay enabled after this due to DMC's own request on it.
2732 well
= lookup_power_well(dev_priv
, SKL_DISP_PW_1
);
2733 intel_power_well_disable(dev_priv
, well
);
2735 mutex_unlock(&power_domains
->lock
);
2737 usleep_range(10, 30); /* 10 us delay per Bspec */
2740 void bxt_display_core_init(struct drm_i915_private
*dev_priv
,
2743 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
2744 struct i915_power_well
*well
;
2747 gen9_set_dc_state(dev_priv
, DC_STATE_DISABLE
);
2750 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2751 * or else the reset will hang because there is no PCH to respond.
2752 * Move the handshake programming to initialization sequence.
2753 * Previously was left up to BIOS.
2755 val
= I915_READ(HSW_NDE_RSTWRN_OPT
);
2756 val
&= ~RESET_PCH_HANDSHAKE_ENABLE
;
2757 I915_WRITE(HSW_NDE_RSTWRN_OPT
, val
);
2760 mutex_lock(&power_domains
->lock
);
2762 well
= lookup_power_well(dev_priv
, SKL_DISP_PW_1
);
2763 intel_power_well_enable(dev_priv
, well
);
2765 mutex_unlock(&power_domains
->lock
);
2767 bxt_init_cdclk(dev_priv
);
2769 gen9_dbuf_enable(dev_priv
);
2771 if (resume
&& dev_priv
->csr
.dmc_payload
)
2772 intel_csr_load_program(dev_priv
);
2775 void bxt_display_core_uninit(struct drm_i915_private
*dev_priv
)
2777 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
2778 struct i915_power_well
*well
;
2780 gen9_set_dc_state(dev_priv
, DC_STATE_DISABLE
);
2782 gen9_dbuf_disable(dev_priv
);
2784 bxt_uninit_cdclk(dev_priv
);
2786 /* The spec doesn't call for removing the reset handshake flag */
2789 * Disable PW1 (PG1).
2790 * Note that even though the driver's request is removed power well 1
2791 * may stay enabled after this due to DMC's own request on it.
2793 mutex_lock(&power_domains
->lock
);
2795 well
= lookup_power_well(dev_priv
, SKL_DISP_PW_1
);
2796 intel_power_well_disable(dev_priv
, well
);
2798 mutex_unlock(&power_domains
->lock
);
2800 usleep_range(10, 30); /* 10 us delay per Bspec */
2803 #define CNL_PROCMON_IDX(val) \
2804 (((val) & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) >> VOLTAGE_INFO_SHIFT)
2805 #define NUM_CNL_PROCMON \
2806 (CNL_PROCMON_IDX(VOLTAGE_INFO_MASK | PROCESS_INFO_MASK) + 1)
2808 static const struct cnl_procmon
{
2810 } cnl_procmon_values
[NUM_CNL_PROCMON
] = {
2811 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_85V
| PROCESS_INFO_DOT_0
)] =
2812 { .dw1
= 0x00 << 16, .dw9
= 0x62AB67BB, .dw10
= 0x51914F96, },
2813 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V
| PROCESS_INFO_DOT_0
)] =
2814 { .dw1
= 0x00 << 16, .dw9
= 0x86E172C7, .dw10
= 0x77CA5EAB, },
2815 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V
| PROCESS_INFO_DOT_1
)] =
2816 { .dw1
= 0x00 << 16, .dw9
= 0x93F87FE1, .dw10
= 0x8AE871C5, },
2817 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V
| PROCESS_INFO_DOT_0
)] =
2818 { .dw1
= 0x00 << 16, .dw9
= 0x98FA82DD, .dw10
= 0x89E46DC1, },
2819 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V
| PROCESS_INFO_DOT_1
)] =
2820 { .dw1
= 0x44 << 16, .dw9
= 0x9A00AB25, .dw10
= 0x8AE38FF1, },
2823 static void cnl_display_core_init(struct drm_i915_private
*dev_priv
, bool resume
)
2825 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
2826 const struct cnl_procmon
*procmon
;
2827 struct i915_power_well
*well
;
2830 gen9_set_dc_state(dev_priv
, DC_STATE_DISABLE
);
2832 /* 1. Enable PCH Reset Handshake */
2833 val
= I915_READ(HSW_NDE_RSTWRN_OPT
);
2834 val
|= RESET_PCH_HANDSHAKE_ENABLE
;
2835 I915_WRITE(HSW_NDE_RSTWRN_OPT
, val
);
2837 /* 2. Enable Comp */
2838 val
= I915_READ(CHICKEN_MISC_2
);
2839 val
&= ~COMP_PWR_DOWN
;
2840 I915_WRITE(CHICKEN_MISC_2
, val
);
2842 val
= I915_READ(CNL_PORT_COMP_DW3
);
2843 procmon
= &cnl_procmon_values
[CNL_PROCMON_IDX(val
)];
2845 WARN_ON(procmon
->dw10
== 0);
2847 val
= I915_READ(CNL_PORT_COMP_DW1
);
2848 val
&= ~((0xff << 16) | 0xff);
2849 val
|= procmon
->dw1
;
2850 I915_WRITE(CNL_PORT_COMP_DW1
, val
);
2852 I915_WRITE(CNL_PORT_COMP_DW9
, procmon
->dw9
);
2853 I915_WRITE(CNL_PORT_COMP_DW10
, procmon
->dw10
);
2855 val
= I915_READ(CNL_PORT_COMP_DW0
);
2857 I915_WRITE(CNL_PORT_COMP_DW0
, val
);
2860 val
= I915_READ(CNL_PORT_CL1CM_DW5
);
2861 val
|= CL_POWER_DOWN_ENABLE
;
2862 I915_WRITE(CNL_PORT_CL1CM_DW5
, val
);
2865 * 4. Enable Power Well 1 (PG1).
2866 * The AUX IO power wells will be enabled on demand.
2868 mutex_lock(&power_domains
->lock
);
2869 well
= lookup_power_well(dev_priv
, SKL_DISP_PW_1
);
2870 intel_power_well_enable(dev_priv
, well
);
2871 mutex_unlock(&power_domains
->lock
);
2873 /* 5. Enable CD clock */
2874 cnl_init_cdclk(dev_priv
);
2876 /* 6. Enable DBUF */
2877 gen9_dbuf_enable(dev_priv
);
2880 #undef CNL_PROCMON_IDX
2881 #undef NUM_CNL_PROCMON
2883 static void cnl_display_core_uninit(struct drm_i915_private
*dev_priv
)
2885 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
2886 struct i915_power_well
*well
;
2889 gen9_set_dc_state(dev_priv
, DC_STATE_DISABLE
);
2891 /* 1. Disable all display engine functions -> aready done */
2893 /* 2. Disable DBUF */
2894 gen9_dbuf_disable(dev_priv
);
2896 /* 3. Disable CD clock */
2897 cnl_uninit_cdclk(dev_priv
);
2900 * 4. Disable Power Well 1 (PG1).
2901 * The AUX IO power wells are toggled on demand, so they are already
2902 * disabled at this point.
2904 mutex_lock(&power_domains
->lock
);
2905 well
= lookup_power_well(dev_priv
, SKL_DISP_PW_1
);
2906 intel_power_well_disable(dev_priv
, well
);
2907 mutex_unlock(&power_domains
->lock
);
2909 usleep_range(10, 30); /* 10 us delay per Bspec */
2911 /* 5. Disable Comp */
2912 val
= I915_READ(CHICKEN_MISC_2
);
2913 val
|= COMP_PWR_DOWN
;
2914 I915_WRITE(CHICKEN_MISC_2
, val
);
2917 static void chv_phy_control_init(struct drm_i915_private
*dev_priv
)
2919 struct i915_power_well
*cmn_bc
=
2920 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
);
2921 struct i915_power_well
*cmn_d
=
2922 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_D
);
2925 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2926 * workaround never ever read DISPLAY_PHY_CONTROL, and
2927 * instead maintain a shadow copy ourselves. Use the actual
2928 * power well state and lane status to reconstruct the
2929 * expected initial value.
2931 dev_priv
->chv_phy_control
=
2932 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS
, DPIO_PHY0
) |
2933 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS
, DPIO_PHY1
) |
2934 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR
, DPIO_PHY0
, DPIO_CH0
) |
2935 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR
, DPIO_PHY0
, DPIO_CH1
) |
2936 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR
, DPIO_PHY1
, DPIO_CH0
);
2939 * If all lanes are disabled we leave the override disabled
2940 * with all power down bits cleared to match the state we
2941 * would use after disabling the port. Otherwise enable the
2942 * override and set the lane powerdown bits accding to the
2943 * current lane status.
2945 if (cmn_bc
->ops
->is_enabled(dev_priv
, cmn_bc
)) {
2946 uint32_t status
= I915_READ(DPLL(PIPE_A
));
2949 mask
= status
& DPLL_PORTB_READY_MASK
;
2953 dev_priv
->chv_phy_control
|=
2954 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0
, DPIO_CH0
);
2956 dev_priv
->chv_phy_control
|=
2957 PHY_CH_POWER_DOWN_OVRD(mask
, DPIO_PHY0
, DPIO_CH0
);
2959 mask
= (status
& DPLL_PORTC_READY_MASK
) >> 4;
2963 dev_priv
->chv_phy_control
|=
2964 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0
, DPIO_CH1
);
2966 dev_priv
->chv_phy_control
|=
2967 PHY_CH_POWER_DOWN_OVRD(mask
, DPIO_PHY0
, DPIO_CH1
);
2969 dev_priv
->chv_phy_control
|= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0
);
2971 dev_priv
->chv_phy_assert
[DPIO_PHY0
] = false;
2973 dev_priv
->chv_phy_assert
[DPIO_PHY0
] = true;
2976 if (cmn_d
->ops
->is_enabled(dev_priv
, cmn_d
)) {
2977 uint32_t status
= I915_READ(DPIO_PHY_STATUS
);
2980 mask
= status
& DPLL_PORTD_READY_MASK
;
2985 dev_priv
->chv_phy_control
|=
2986 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1
, DPIO_CH0
);
2988 dev_priv
->chv_phy_control
|=
2989 PHY_CH_POWER_DOWN_OVRD(mask
, DPIO_PHY1
, DPIO_CH0
);
2991 dev_priv
->chv_phy_control
|= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1
);
2993 dev_priv
->chv_phy_assert
[DPIO_PHY1
] = false;
2995 dev_priv
->chv_phy_assert
[DPIO_PHY1
] = true;
2998 I915_WRITE(DISPLAY_PHY_CONTROL
, dev_priv
->chv_phy_control
);
3000 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
3001 dev_priv
->chv_phy_control
);
3004 static void vlv_cmnlane_wa(struct drm_i915_private
*dev_priv
)
3006 struct i915_power_well
*cmn
=
3007 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
);
3008 struct i915_power_well
*disp2d
=
3009 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DISP2D
);
3011 /* If the display might be already active skip this */
3012 if (cmn
->ops
->is_enabled(dev_priv
, cmn
) &&
3013 disp2d
->ops
->is_enabled(dev_priv
, disp2d
) &&
3014 I915_READ(DPIO_CTL
) & DPIO_CMNRST
)
3017 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3019 /* cmnlane needs DPLL registers */
3020 disp2d
->ops
->enable(dev_priv
, disp2d
);
3023 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3024 * Need to assert and de-assert PHY SB reset by gating the
3025 * common lane power, then un-gating it.
3026 * Simply ungating isn't enough to reset the PHY enough to get
3027 * ports and lanes running.
3029 cmn
->ops
->disable(dev_priv
, cmn
);
3033 * intel_power_domains_init_hw - initialize hardware power domain state
3034 * @dev_priv: i915 device instance
3035 * @resume: Called from resume code paths or not
3037 * This function initializes the hardware power domain state and enables all
3038 * power wells belonging to the INIT power domain. Power wells in other
3039 * domains (and not in the INIT domain) are referenced or disabled during the
3040 * modeset state HW readout. After that the reference count of each power well
3041 * must match its HW enabled state, see intel_power_domains_verify_state().
3043 void intel_power_domains_init_hw(struct drm_i915_private
*dev_priv
, bool resume
)
3045 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
3047 power_domains
->initializing
= true;
3049 if (IS_CANNONLAKE(dev_priv
)) {
3050 cnl_display_core_init(dev_priv
, resume
);
3051 } else if (IS_GEN9_BC(dev_priv
)) {
3052 skl_display_core_init(dev_priv
, resume
);
3053 } else if (IS_GEN9_LP(dev_priv
)) {
3054 bxt_display_core_init(dev_priv
, resume
);
3055 } else if (IS_CHERRYVIEW(dev_priv
)) {
3056 mutex_lock(&power_domains
->lock
);
3057 chv_phy_control_init(dev_priv
);
3058 mutex_unlock(&power_domains
->lock
);
3059 } else if (IS_VALLEYVIEW(dev_priv
)) {
3060 mutex_lock(&power_domains
->lock
);
3061 vlv_cmnlane_wa(dev_priv
);
3062 mutex_unlock(&power_domains
->lock
);
3065 /* For now, we need the power well to be always enabled. */
3066 intel_display_set_init_power(dev_priv
, true);
3067 /* Disable power support if the user asked so. */
3068 if (!i915
.disable_power_well
)
3069 intel_display_power_get(dev_priv
, POWER_DOMAIN_INIT
);
3070 intel_power_domains_sync_hw(dev_priv
);
3071 power_domains
->initializing
= false;
3075 * intel_power_domains_suspend - suspend power domain state
3076 * @dev_priv: i915 device instance
3078 * This function prepares the hardware power domain state before entering
3079 * system suspend. It must be paired with intel_power_domains_init_hw().
3081 void intel_power_domains_suspend(struct drm_i915_private
*dev_priv
)
3084 * Even if power well support was disabled we still want to disable
3085 * power wells while we are system suspended.
3087 if (!i915
.disable_power_well
)
3088 intel_display_power_put(dev_priv
, POWER_DOMAIN_INIT
);
3090 if (IS_CANNONLAKE(dev_priv
))
3091 cnl_display_core_uninit(dev_priv
);
3092 else if (IS_GEN9_BC(dev_priv
))
3093 skl_display_core_uninit(dev_priv
);
3094 else if (IS_GEN9_LP(dev_priv
))
3095 bxt_display_core_uninit(dev_priv
);
3098 static void intel_power_domains_dump_info(struct drm_i915_private
*dev_priv
)
3100 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
3101 struct i915_power_well
*power_well
;
3103 for_each_power_well(dev_priv
, power_well
) {
3104 enum intel_display_power_domain domain
;
3106 DRM_DEBUG_DRIVER("%-25s %d\n",
3107 power_well
->name
, power_well
->count
);
3109 for_each_power_domain(domain
, power_well
->domains
)
3110 DRM_DEBUG_DRIVER(" %-23s %d\n",
3111 intel_display_power_domain_str(domain
),
3112 power_domains
->domain_use_count
[domain
]);
3117 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3118 * @dev_priv: i915 device instance
3120 * Verify if the reference count of each power well matches its HW enabled
3121 * state and the total refcount of the domains it belongs to. This must be
3122 * called after modeset HW state sanitization, which is responsible for
3123 * acquiring reference counts for any power wells in use and disabling the
3124 * ones left on by BIOS but not required by any active output.
3126 void intel_power_domains_verify_state(struct drm_i915_private
*dev_priv
)
3128 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
3129 struct i915_power_well
*power_well
;
3130 bool dump_domain_info
;
3132 mutex_lock(&power_domains
->lock
);
3134 dump_domain_info
= false;
3135 for_each_power_well(dev_priv
, power_well
) {
3136 enum intel_display_power_domain domain
;
3141 * Power wells not belonging to any domain (like the MISC_IO
3142 * and PW1 power wells) are under FW control, so ignore them,
3143 * since their state can change asynchronously.
3145 if (!power_well
->domains
)
3148 enabled
= power_well
->ops
->is_enabled(dev_priv
, power_well
);
3149 if ((power_well
->count
|| power_well
->always_on
) != enabled
)
3150 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3151 power_well
->name
, power_well
->count
, enabled
);
3154 for_each_power_domain(domain
, power_well
->domains
)
3155 domains_count
+= power_domains
->domain_use_count
[domain
];
3157 if (power_well
->count
!= domains_count
) {
3158 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3159 "(refcount %d/domains refcount %d)\n",
3160 power_well
->name
, power_well
->count
,
3162 dump_domain_info
= true;
3166 if (dump_domain_info
) {
3170 intel_power_domains_dump_info(dev_priv
);
3175 mutex_unlock(&power_domains
->lock
);
3179 * intel_runtime_pm_get - grab a runtime pm reference
3180 * @dev_priv: i915 device instance
3182 * This function grabs a device-level runtime pm reference (mostly used for GEM
3183 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3185 * Any runtime pm reference obtained by this function must have a symmetric
3186 * call to intel_runtime_pm_put() to release the reference again.
3188 void intel_runtime_pm_get(struct drm_i915_private
*dev_priv
)
3190 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
3191 struct device
*kdev
= &pdev
->dev
;
3194 ret
= pm_runtime_get_sync(kdev
);
3195 WARN_ONCE(ret
< 0, "pm_runtime_get_sync() failed: %d\n", ret
);
3197 atomic_inc(&dev_priv
->pm
.wakeref_count
);
3198 assert_rpm_wakelock_held(dev_priv
);
3202 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3203 * @dev_priv: i915 device instance
3205 * This function grabs a device-level runtime pm reference if the device is
3206 * already in use and ensures that it is powered up.
3208 * Any runtime pm reference obtained by this function must have a symmetric
3209 * call to intel_runtime_pm_put() to release the reference again.
3211 bool intel_runtime_pm_get_if_in_use(struct drm_i915_private
*dev_priv
)
3213 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
3214 struct device
*kdev
= &pdev
->dev
;
3216 if (IS_ENABLED(CONFIG_PM
)) {
3217 int ret
= pm_runtime_get_if_in_use(kdev
);
3220 * In cases runtime PM is disabled by the RPM core and we get
3221 * an -EINVAL return value we are not supposed to call this
3222 * function, since the power state is undefined. This applies
3223 * atm to the late/early system suspend/resume handlers.
3226 "pm_runtime_get_if_in_use() failed: %d\n", ret
);
3231 atomic_inc(&dev_priv
->pm
.wakeref_count
);
3232 assert_rpm_wakelock_held(dev_priv
);
3238 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3239 * @dev_priv: i915 device instance
3241 * This function grabs a device-level runtime pm reference (mostly used for GEM
3242 * code to ensure the GTT or GT is on).
3244 * It will _not_ power up the device but instead only check that it's powered
3245 * on. Therefore it is only valid to call this functions from contexts where
3246 * the device is known to be powered up and where trying to power it up would
3247 * result in hilarity and deadlocks. That pretty much means only the system
3248 * suspend/resume code where this is used to grab runtime pm references for
3249 * delayed setup down in work items.
3251 * Any runtime pm reference obtained by this function must have a symmetric
3252 * call to intel_runtime_pm_put() to release the reference again.
3254 void intel_runtime_pm_get_noresume(struct drm_i915_private
*dev_priv
)
3256 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
3257 struct device
*kdev
= &pdev
->dev
;
3259 assert_rpm_wakelock_held(dev_priv
);
3260 pm_runtime_get_noresume(kdev
);
3262 atomic_inc(&dev_priv
->pm
.wakeref_count
);
3266 * intel_runtime_pm_put - release a runtime pm reference
3267 * @dev_priv: i915 device instance
3269 * This function drops the device-level runtime pm reference obtained by
3270 * intel_runtime_pm_get() and might power down the corresponding
3271 * hardware block right away if this is the last reference.
3273 void intel_runtime_pm_put(struct drm_i915_private
*dev_priv
)
3275 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
3276 struct device
*kdev
= &pdev
->dev
;
3278 assert_rpm_wakelock_held(dev_priv
);
3279 atomic_dec(&dev_priv
->pm
.wakeref_count
);
3281 pm_runtime_mark_last_busy(kdev
);
3282 pm_runtime_put_autosuspend(kdev
);
3286 * intel_runtime_pm_enable - enable runtime pm
3287 * @dev_priv: i915 device instance
3289 * This function enables runtime pm at the end of the driver load sequence.
3291 * Note that this function does currently not enable runtime pm for the
3292 * subordinate display power domains. That is only done on the first modeset
3293 * using intel_display_set_init_power().
3295 void intel_runtime_pm_enable(struct drm_i915_private
*dev_priv
)
3297 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
3298 struct device
*kdev
= &pdev
->dev
;
3300 pm_runtime_set_autosuspend_delay(kdev
, 10000); /* 10s */
3301 pm_runtime_mark_last_busy(kdev
);
3304 * Take a permanent reference to disable the RPM functionality and drop
3305 * it only when unloading the driver. Use the low level get/put helpers,
3306 * so the driver's own RPM reference tracking asserts also work on
3307 * platforms without RPM support.
3309 if (!HAS_RUNTIME_PM(dev_priv
)) {
3312 pm_runtime_dont_use_autosuspend(kdev
);
3313 ret
= pm_runtime_get_sync(kdev
);
3314 WARN(ret
< 0, "pm_runtime_get_sync() failed: %d\n", ret
);
3316 pm_runtime_use_autosuspend(kdev
);
3320 * The core calls the driver load handler with an RPM reference held.
3321 * We drop that here and will reacquire it during unloading in
3322 * intel_power_domains_fini().
3324 pm_runtime_put_autosuspend(kdev
);