blob: c0983f0e46ac6fc1ee590b967ef10a1d1dd62ded [file] [log] [blame]
Daniel Vetter9c065a72014-09-30 10:56:38 +02001/*
2 * Copyright © 2012-2014 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29#include <linux/pm_runtime.h>
30#include <linux/vgaarb.h>
31
32#include "i915_drv.h"
33#include "intel_drv.h"
Daniel Vetter9c065a72014-09-30 10:56:38 +020034
Daniel Vettere4e76842014-09-30 10:56:42 +020035/**
36 * DOC: runtime pm
37 *
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.
43 *
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.
50 */
51
Suketu Shah5aefb232015-04-16 14:22:10 +053052bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +030053 enum i915_power_well_id power_well_id);
Suketu Shah5aefb232015-04-16 14:22:10 +053054
Imre Deak9c8d0b82016-06-13 16:44:34 +030055static struct i915_power_well *
Imre Deak438b8dc2017-07-11 23:42:30 +030056lookup_power_well(struct drm_i915_private *dev_priv,
57 enum i915_power_well_id power_well_id);
Imre Deak9c8d0b82016-06-13 16:44:34 +030058
Daniel Stone9895ad02015-11-20 15:55:33 +000059const char *
60intel_display_power_domain_str(enum intel_display_power_domain domain)
61{
62 switch (domain) {
63 case POWER_DOMAIN_PIPE_A:
64 return "PIPE_A";
65 case POWER_DOMAIN_PIPE_B:
66 return "PIPE_B";
67 case POWER_DOMAIN_PIPE_C:
68 return "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";
Jani Nikula4d1de972016-03-18 17:05:42 +020083 case POWER_DOMAIN_TRANSCODER_DSI_A:
84 return "TRANSCODER_DSI_A";
85 case POWER_DOMAIN_TRANSCODER_DSI_C:
86 return "TRANSCODER_DSI_C";
Daniel Stone9895ad02015-11-20 15:55:33 +000087 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";
Rodrigo Vivi9787e832018-01-29 15:22:22 -080097 case POWER_DOMAIN_PORT_DDI_F_LANES:
98 return "PORT_DDI_F_LANES";
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020099 case POWER_DOMAIN_PORT_DDI_A_IO:
100 return "PORT_DDI_A_IO";
101 case POWER_DOMAIN_PORT_DDI_B_IO:
102 return "PORT_DDI_B_IO";
103 case POWER_DOMAIN_PORT_DDI_C_IO:
104 return "PORT_DDI_C_IO";
105 case POWER_DOMAIN_PORT_DDI_D_IO:
106 return "PORT_DDI_D_IO";
107 case POWER_DOMAIN_PORT_DDI_E_IO:
108 return "PORT_DDI_E_IO";
Rodrigo Vivi9787e832018-01-29 15:22:22 -0800109 case POWER_DOMAIN_PORT_DDI_F_IO:
110 return "PORT_DDI_F_IO";
Daniel Stone9895ad02015-11-20 15:55:33 +0000111 case POWER_DOMAIN_PORT_DSI:
112 return "PORT_DSI";
113 case POWER_DOMAIN_PORT_CRT:
114 return "PORT_CRT";
115 case POWER_DOMAIN_PORT_OTHER:
116 return "PORT_OTHER";
117 case POWER_DOMAIN_VGA:
118 return "VGA";
119 case POWER_DOMAIN_AUDIO:
120 return "AUDIO";
121 case POWER_DOMAIN_PLLS:
122 return "PLLS";
123 case POWER_DOMAIN_AUX_A:
124 return "AUX_A";
125 case POWER_DOMAIN_AUX_B:
126 return "AUX_B";
127 case POWER_DOMAIN_AUX_C:
128 return "AUX_C";
129 case POWER_DOMAIN_AUX_D:
130 return "AUX_D";
James Ausmusbb187e92018-06-11 17:25:12 -0700131 case POWER_DOMAIN_AUX_E:
132 return "AUX_E";
Rodrigo Vivia324fca2018-01-29 15:22:15 -0800133 case POWER_DOMAIN_AUX_F:
134 return "AUX_F";
Dhinakaran Pandiyanb891d5e2018-02-23 14:15:15 -0800135 case POWER_DOMAIN_AUX_IO_A:
136 return "AUX_IO_A";
Imre Deak67ca07e2018-06-26 17:22:32 +0300137 case POWER_DOMAIN_AUX_TBT1:
138 return "AUX_TBT1";
139 case POWER_DOMAIN_AUX_TBT2:
140 return "AUX_TBT2";
141 case POWER_DOMAIN_AUX_TBT3:
142 return "AUX_TBT3";
143 case POWER_DOMAIN_AUX_TBT4:
144 return "AUX_TBT4";
Daniel Stone9895ad02015-11-20 15:55:33 +0000145 case POWER_DOMAIN_GMBUS:
146 return "GMBUS";
147 case POWER_DOMAIN_INIT:
148 return "INIT";
149 case POWER_DOMAIN_MODESET:
150 return "MODESET";
Tvrtko Ursulinb6876372017-12-05 13:28:54 +0000151 case POWER_DOMAIN_GT_IRQ:
152 return "GT_IRQ";
Daniel Stone9895ad02015-11-20 15:55:33 +0000153 default:
154 MISSING_CASE(domain);
155 return "?";
156 }
157}
158
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300159static void intel_power_well_enable(struct drm_i915_private *dev_priv,
160 struct i915_power_well *power_well)
161{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300162 DRM_DEBUG_KMS("enabling %s\n", power_well->desc->name);
163 power_well->desc->ops->enable(dev_priv, power_well);
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300164 power_well->hw_enabled = true;
165}
166
Damien Lespiaudcddab32015-07-30 18:20:27 -0300167static void intel_power_well_disable(struct drm_i915_private *dev_priv,
168 struct i915_power_well *power_well)
169{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300170 DRM_DEBUG_KMS("disabling %s\n", power_well->desc->name);
Damien Lespiaudcddab32015-07-30 18:20:27 -0300171 power_well->hw_enabled = false;
Imre Deakf28ec6f2018-08-06 12:58:37 +0300172 power_well->desc->ops->disable(dev_priv, power_well);
Damien Lespiaudcddab32015-07-30 18:20:27 -0300173}
174
Imre Deakb409ca92016-06-13 16:44:33 +0300175static void intel_power_well_get(struct drm_i915_private *dev_priv,
176 struct i915_power_well *power_well)
177{
178 if (!power_well->count++)
179 intel_power_well_enable(dev_priv, power_well);
180}
181
182static void intel_power_well_put(struct drm_i915_private *dev_priv,
183 struct i915_power_well *power_well)
184{
185 WARN(!power_well->count, "Use count on power well %s is already zero",
Imre Deakf28ec6f2018-08-06 12:58:37 +0300186 power_well->desc->name);
Imre Deakb409ca92016-06-13 16:44:33 +0300187
188 if (!--power_well->count)
189 intel_power_well_disable(dev_priv, power_well);
190}
191
Daniel Vettere4e76842014-09-30 10:56:42 +0200192/**
193 * __intel_display_power_is_enabled - unlocked check for a power domain
194 * @dev_priv: i915 device instance
195 * @domain: power domain to check
196 *
197 * This is the unlocked version of intel_display_power_is_enabled() and should
198 * only be used from error capture and recovery code where deadlocks are
199 * possible.
200 *
201 * Returns:
202 * True when the power domain is enabled, false otherwise.
203 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200204bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
205 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200206{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200207 struct i915_power_well *power_well;
208 bool is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200209
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +0100210 if (dev_priv->runtime_pm.suspended)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200211 return false;
212
Daniel Vetter9c065a72014-09-30 10:56:38 +0200213 is_enabled = true;
214
Imre Deak75ccb2e2017-02-17 17:39:43 +0200215 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +0300216 if (power_well->desc->always_on)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200217 continue;
218
219 if (!power_well->hw_enabled) {
220 is_enabled = false;
221 break;
222 }
223 }
224
225 return is_enabled;
226}
227
Daniel Vettere4e76842014-09-30 10:56:42 +0200228/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000229 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200230 * @dev_priv: i915 device instance
231 * @domain: power domain to check
232 *
233 * This function can be used to check the hw power domain state. It is mostly
234 * used in hardware state readout functions. Everywhere else code should rely
235 * upon explicit power domain reference counting to ensure that the hardware
236 * block is powered up before accessing it.
237 *
238 * Callers must hold the relevant modesetting locks to ensure that concurrent
239 * threads can't disable the power well while the caller tries to read a few
240 * registers.
241 *
242 * Returns:
243 * True when the power domain is enabled, false otherwise.
244 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200245bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
246 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200247{
248 struct i915_power_domains *power_domains;
249 bool ret;
250
251 power_domains = &dev_priv->power_domains;
252
253 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200254 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200255 mutex_unlock(&power_domains->lock);
256
257 return ret;
258}
259
Daniel Vettere4e76842014-09-30 10:56:42 +0200260/**
261 * intel_display_set_init_power - set the initial power domain state
262 * @dev_priv: i915 device instance
263 * @enable: whether to enable or disable the initial power domain state
264 *
265 * For simplicity our driver load/unload and system suspend/resume code assumes
266 * that all power domains are always enabled. This functions controls the state
267 * of this little hack. While the initial power domain state is enabled runtime
268 * pm is effectively disabled.
269 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200270void intel_display_set_init_power(struct drm_i915_private *dev_priv,
271 bool enable)
272{
273 if (dev_priv->power_domains.init_power_on == enable)
274 return;
275
276 if (enable)
277 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
278 else
279 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
280
281 dev_priv->power_domains.init_power_on = enable;
282}
283
Daniel Vetter9c065a72014-09-30 10:56:38 +0200284/*
285 * Starting with Haswell, we have a "Power Down Well" that can be turned off
286 * when not needed anymore. We have 4 registers that can request the power well
287 * to be enabled, and it will only be disabled if none of the registers is
288 * requesting it to be enabled.
289 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300290static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv,
291 u8 irq_pipe_mask, bool has_vga)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200292{
David Weinehall52a05c32016-08-22 13:32:44 +0300293 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200294
295 /*
296 * After we re-enable the power well, if we touch VGA register 0x3d5
297 * we'll get unclaimed register interrupts. This stops after we write
298 * anything to the VGA MSR register. The vgacon module uses this
299 * register all the time, so if we unbind our driver and, as a
300 * consequence, bind vgacon, we'll get stuck in an infinite loop at
301 * console_unlock(). So make here we touch the VGA MSR register, making
302 * sure vgacon can keep working normally without triggering interrupts
303 * and error messages.
304 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300305 if (has_vga) {
306 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
307 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
308 vga_put(pdev, VGA_RSRC_LEGACY_IO);
309 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200310
Imre Deak001bd2c2017-07-12 18:54:13 +0300311 if (irq_pipe_mask)
312 gen8_irq_power_well_post_enable(dev_priv, irq_pipe_mask);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200313}
314
Imre Deak001bd2c2017-07-12 18:54:13 +0300315static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv,
316 u8 irq_pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200317{
Imre Deak001bd2c2017-07-12 18:54:13 +0300318 if (irq_pipe_mask)
319 gen8_irq_power_well_pre_disable(dev_priv, irq_pipe_mask);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200320}
321
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200322
Imre Deak76347c02017-07-06 17:40:36 +0300323static void hsw_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
324 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300325{
Imre Deak75e39682018-08-06 12:58:39 +0300326 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
327 int pw_idx = power_well->desc->hsw.idx;
Imre Deak42d93662017-06-29 18:37:01 +0300328
329 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
330 WARN_ON(intel_wait_for_register(dev_priv,
Imre Deak75e39682018-08-06 12:58:39 +0300331 regs->driver,
332 HSW_PWR_WELL_CTL_STATE(pw_idx),
333 HSW_PWR_WELL_CTL_STATE(pw_idx),
Imre Deak42d93662017-06-29 18:37:01 +0300334 1));
335}
336
Imre Deak76347c02017-07-06 17:40:36 +0300337static u32 hsw_power_well_requesters(struct drm_i915_private *dev_priv,
Imre Deak75e39682018-08-06 12:58:39 +0300338 const struct i915_power_well_regs *regs,
339 int pw_idx)
Imre Deak42d93662017-06-29 18:37:01 +0300340{
Imre Deak75e39682018-08-06 12:58:39 +0300341 u32 req_mask = HSW_PWR_WELL_CTL_REQ(pw_idx);
Imre Deak42d93662017-06-29 18:37:01 +0300342 u32 ret;
343
Imre Deak75e39682018-08-06 12:58:39 +0300344 ret = I915_READ(regs->bios) & req_mask ? 1 : 0;
345 ret |= I915_READ(regs->driver) & req_mask ? 2 : 0;
346 if (regs->kvmr.reg)
347 ret |= I915_READ(regs->kvmr) & req_mask ? 4 : 0;
348 ret |= I915_READ(regs->debug) & req_mask ? 8 : 0;
Imre Deak42d93662017-06-29 18:37:01 +0300349
350 return ret;
351}
352
Imre Deak76347c02017-07-06 17:40:36 +0300353static void hsw_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
354 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300355{
Imre Deak75e39682018-08-06 12:58:39 +0300356 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
357 int pw_idx = power_well->desc->hsw.idx;
Imre Deak42d93662017-06-29 18:37:01 +0300358 bool disabled;
359 u32 reqs;
360
361 /*
362 * Bspec doesn't require waiting for PWs to get disabled, but still do
363 * this for paranoia. The known cases where a PW will be forced on:
364 * - a KVMR request on any power well via the KVMR request register
365 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
366 * DEBUG request registers
367 * Skip the wait in case any of the request bits are set and print a
368 * diagnostic message.
369 */
Imre Deak75e39682018-08-06 12:58:39 +0300370 wait_for((disabled = !(I915_READ(regs->driver) &
371 HSW_PWR_WELL_CTL_STATE(pw_idx))) ||
372 (reqs = hsw_power_well_requesters(dev_priv, regs, pw_idx)), 1);
Imre Deak42d93662017-06-29 18:37:01 +0300373 if (disabled)
374 return;
375
376 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +0300377 power_well->desc->name,
Imre Deak42d93662017-06-29 18:37:01 +0300378 !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
379}
380
Imre Deakb2891eb2017-07-11 23:42:35 +0300381static void gen9_wait_for_power_well_fuses(struct drm_i915_private *dev_priv,
382 enum skl_power_gate pg)
383{
384 /* Timeout 5us for PG#0, for other PGs 1us */
385 WARN_ON(intel_wait_for_register(dev_priv, SKL_FUSE_STATUS,
386 SKL_FUSE_PG_DIST_STATUS(pg),
387 SKL_FUSE_PG_DIST_STATUS(pg), 1));
388}
389
Imre Deakec46d482017-07-06 17:40:33 +0300390static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
391 struct i915_power_well *power_well)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200392{
Imre Deak75e39682018-08-06 12:58:39 +0300393 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
394 int pw_idx = power_well->desc->hsw.idx;
Imre Deakf28ec6f2018-08-06 12:58:37 +0300395 bool wait_fuses = power_well->desc->hsw.has_fuses;
Chris Wilson320671f2017-10-02 11:04:16 +0100396 enum skl_power_gate uninitialized_var(pg);
Imre Deak1af474f2017-07-06 17:40:34 +0300397 u32 val;
398
Imre Deakb2891eb2017-07-11 23:42:35 +0300399 if (wait_fuses) {
Imre Deak75e39682018-08-06 12:58:39 +0300400 pg = INTEL_GEN(dev_priv) >= 11 ? ICL_PW_CTL_IDX_TO_PG(pw_idx) :
401 SKL_PW_CTL_IDX_TO_PG(pw_idx);
Imre Deakb2891eb2017-07-11 23:42:35 +0300402 /*
403 * For PW1 we have to wait both for the PW0/PG0 fuse state
404 * before enabling the power well and PW1/PG1's own fuse
405 * state after the enabling. For all other power wells with
406 * fuses we only have to wait for that PW/PG's fuse state
407 * after the enabling.
408 */
409 if (pg == SKL_PG1)
410 gen9_wait_for_power_well_fuses(dev_priv, SKL_PG0);
411 }
412
Imre Deak75e39682018-08-06 12:58:39 +0300413 val = I915_READ(regs->driver);
414 I915_WRITE(regs->driver, val | HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak76347c02017-07-06 17:40:36 +0300415 hsw_wait_for_power_well_enable(dev_priv, power_well);
Imre Deak001bd2c2017-07-12 18:54:13 +0300416
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800417 /* Display WA #1178: cnl */
418 if (IS_CANNONLAKE(dev_priv) &&
Imre Deak75e39682018-08-06 12:58:39 +0300419 pw_idx >= GLK_PW_CTL_IDX_AUX_B &&
420 pw_idx <= CNL_PW_CTL_IDX_AUX_F) {
421 val = I915_READ(CNL_AUX_ANAOVRD1(pw_idx));
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800422 val |= CNL_AUX_ANAOVRD1_ENABLE | CNL_AUX_ANAOVRD1_LDO_BYPASS;
Imre Deak75e39682018-08-06 12:58:39 +0300423 I915_WRITE(CNL_AUX_ANAOVRD1(pw_idx), val);
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800424 }
425
Imre Deakb2891eb2017-07-11 23:42:35 +0300426 if (wait_fuses)
427 gen9_wait_for_power_well_fuses(dev_priv, pg);
428
Imre Deakf28ec6f2018-08-06 12:58:37 +0300429 hsw_power_well_post_enable(dev_priv,
430 power_well->desc->hsw.irq_pipe_mask,
431 power_well->desc->hsw.has_vga);
Imre Deakec46d482017-07-06 17:40:33 +0300432}
Daniel Vetter9c065a72014-09-30 10:56:38 +0200433
Imre Deakec46d482017-07-06 17:40:33 +0300434static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
435 struct i915_power_well *power_well)
436{
Imre Deak75e39682018-08-06 12:58:39 +0300437 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
438 int pw_idx = power_well->desc->hsw.idx;
Imre Deak1af474f2017-07-06 17:40:34 +0300439 u32 val;
440
Imre Deakf28ec6f2018-08-06 12:58:37 +0300441 hsw_power_well_pre_disable(dev_priv,
442 power_well->desc->hsw.irq_pipe_mask);
Imre Deak001bd2c2017-07-12 18:54:13 +0300443
Imre Deak75e39682018-08-06 12:58:39 +0300444 val = I915_READ(regs->driver);
445 I915_WRITE(regs->driver, val & ~HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak76347c02017-07-06 17:40:36 +0300446 hsw_wait_for_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200447}
448
Imre Deak75e39682018-08-06 12:58:39 +0300449#define ICL_AUX_PW_TO_PORT(pw_idx) ((pw_idx) - ICL_PW_CTL_IDX_AUX_A)
Imre Deak67ca07e2018-06-26 17:22:32 +0300450
451static void
452icl_combo_phy_aux_power_well_enable(struct drm_i915_private *dev_priv,
453 struct i915_power_well *power_well)
454{
Imre Deak75e39682018-08-06 12:58:39 +0300455 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
456 int pw_idx = power_well->desc->hsw.idx;
457 enum port port = ICL_AUX_PW_TO_PORT(pw_idx);
Imre Deak67ca07e2018-06-26 17:22:32 +0300458 u32 val;
459
Imre Deak75e39682018-08-06 12:58:39 +0300460 val = I915_READ(regs->driver);
461 I915_WRITE(regs->driver, val | HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak67ca07e2018-06-26 17:22:32 +0300462
463 val = I915_READ(ICL_PORT_CL_DW12(port));
464 I915_WRITE(ICL_PORT_CL_DW12(port), val | ICL_LANE_ENABLE_AUX);
465
466 hsw_wait_for_power_well_enable(dev_priv, power_well);
467}
468
469static void
470icl_combo_phy_aux_power_well_disable(struct drm_i915_private *dev_priv,
471 struct i915_power_well *power_well)
472{
Imre Deak75e39682018-08-06 12:58:39 +0300473 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
474 int pw_idx = power_well->desc->hsw.idx;
475 enum port port = ICL_AUX_PW_TO_PORT(pw_idx);
Imre Deak67ca07e2018-06-26 17:22:32 +0300476 u32 val;
477
478 val = I915_READ(ICL_PORT_CL_DW12(port));
479 I915_WRITE(ICL_PORT_CL_DW12(port), val & ~ICL_LANE_ENABLE_AUX);
480
Imre Deak75e39682018-08-06 12:58:39 +0300481 val = I915_READ(regs->driver);
482 I915_WRITE(regs->driver, val & ~HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak67ca07e2018-06-26 17:22:32 +0300483
484 hsw_wait_for_power_well_disable(dev_priv, power_well);
485}
486
Imre Deakd42539b2017-07-06 17:40:39 +0300487/*
488 * We should only use the power well if we explicitly asked the hardware to
489 * enable it, so check if it's enabled and also check if we've requested it to
490 * be enabled.
491 */
492static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
493 struct i915_power_well *power_well)
494{
Imre Deak75e39682018-08-06 12:58:39 +0300495 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
496 int pw_idx = power_well->desc->hsw.idx;
497 u32 mask = HSW_PWR_WELL_CTL_REQ(pw_idx) |
498 HSW_PWR_WELL_CTL_STATE(pw_idx);
Imre Deakd42539b2017-07-06 17:40:39 +0300499
Imre Deak75e39682018-08-06 12:58:39 +0300500 return (I915_READ(regs->driver) & mask) == mask;
Imre Deakd42539b2017-07-06 17:40:39 +0300501}
502
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530503static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
504{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300505 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
506 "DC9 already programmed to be enabled.\n");
507 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
508 "DC5 still not disabled to enable DC9.\n");
Imre Deak75e39682018-08-06 12:58:39 +0300509 WARN_ONCE(I915_READ(HSW_PWR_WELL_CTL2) &
510 HSW_PWR_WELL_CTL_REQ(SKL_PW_CTL_IDX_PW_2),
Imre Deake8a3a2a2017-06-29 18:37:00 +0300511 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300512 WARN_ONCE(intel_irqs_enabled(dev_priv),
513 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530514
515 /*
516 * TODO: check for the following to verify the conditions to enter DC9
517 * state are satisfied:
518 * 1] Check relevant display engine registers to verify if mode set
519 * disable sequence was followed.
520 * 2] Check if display uninitialize sequence is initialized.
521 */
522}
523
524static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
525{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300526 WARN_ONCE(intel_irqs_enabled(dev_priv),
527 "Interrupts not disabled yet.\n");
528 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
529 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530530
531 /*
532 * TODO: check for the following to verify DC9 state was indeed
533 * entered before programming to disable it:
534 * 1] Check relevant display engine registers to verify if mode
535 * set disable sequence was followed.
536 * 2] Check if display uninitialize sequence is initialized.
537 */
538}
539
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200540static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
541 u32 state)
542{
543 int rewrites = 0;
544 int rereads = 0;
545 u32 v;
546
547 I915_WRITE(DC_STATE_EN, state);
548
549 /* It has been observed that disabling the dc6 state sometimes
550 * doesn't stick and dmc keeps returning old value. Make sure
551 * the write really sticks enough times and also force rewrite until
552 * we are confident that state is exactly what we want.
553 */
554 do {
555 v = I915_READ(DC_STATE_EN);
556
557 if (v != state) {
558 I915_WRITE(DC_STATE_EN, state);
559 rewrites++;
560 rereads = 0;
561 } else if (rereads++ > 5) {
562 break;
563 }
564
565 } while (rewrites < 100);
566
567 if (v != state)
568 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
569 state, v);
570
571 /* Most of the times we need one retry, avoid spam */
572 if (rewrites > 1)
573 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
574 state, rewrites);
575}
576
Imre Deakda2f41d2016-04-20 20:27:56 +0300577static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530578{
Imre Deakda2f41d2016-04-20 20:27:56 +0300579 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530580
Imre Deak13ae3a02015-11-04 19:24:16 +0200581 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200582 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200583 mask |= DC_STATE_EN_DC9;
584 else
585 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530586
Imre Deakda2f41d2016-04-20 20:27:56 +0300587 return mask;
588}
589
590void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
591{
592 u32 val;
593
594 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
595
596 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
597 dev_priv->csr.dc_state, val);
598 dev_priv->csr.dc_state = val;
599}
600
Imre Deak13e15922018-04-17 14:31:47 +0300601/**
602 * gen9_set_dc_state - set target display C power state
603 * @dev_priv: i915 device instance
604 * @state: target DC power state
605 * - DC_STATE_DISABLE
606 * - DC_STATE_EN_UPTO_DC5
607 * - DC_STATE_EN_UPTO_DC6
608 * - DC_STATE_EN_DC9
609 *
610 * Signal to DMC firmware/HW the target DC power state passed in @state.
611 * DMC/HW can turn off individual display clocks and power rails when entering
612 * a deeper DC power state (higher in number) and turns these back when exiting
613 * that state to a shallower power state (lower in number). The HW will decide
614 * when to actually enter a given state on an on-demand basis, for instance
615 * depending on the active state of display pipes. The state of display
616 * registers backed by affected power rails are saved/restored as needed.
617 *
618 * Based on the above enabling a deeper DC power state is asynchronous wrt.
619 * enabling it. Disabling a deeper power state is synchronous: for instance
620 * setting %DC_STATE_DISABLE won't complete until all HW resources are turned
621 * back on and register state is restored. This is guaranteed by the MMIO write
622 * to DC_STATE_EN blocking until the state is restored.
623 */
Imre Deakda2f41d2016-04-20 20:27:56 +0300624static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
625{
626 uint32_t val;
627 uint32_t mask;
628
Imre Deaka37baf32016-02-29 22:49:03 +0200629 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
630 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100631
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530632 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300633 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200634 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
635 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200636
637 /* Check if DMC is ignoring our DC state requests */
638 if ((val & mask) != dev_priv->csr.dc_state)
639 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
640 dev_priv->csr.dc_state, val & mask);
641
Imre Deak13ae3a02015-11-04 19:24:16 +0200642 val &= ~mask;
643 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200644
645 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200646
647 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530648}
649
Imre Deak13ae3a02015-11-04 19:24:16 +0200650void bxt_enable_dc9(struct drm_i915_private *dev_priv)
651{
652 assert_can_enable_dc9(dev_priv);
653
654 DRM_DEBUG_KMS("Enabling DC9\n");
655
Imre Deak78597992016-06-16 16:37:20 +0300656 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200657 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
658}
659
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530660void bxt_disable_dc9(struct drm_i915_private *dev_priv)
661{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530662 assert_can_disable_dc9(dev_priv);
663
664 DRM_DEBUG_KMS("Disabling DC9\n");
665
Imre Deak13ae3a02015-11-04 19:24:16 +0200666 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300667
668 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530669}
670
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200671static void assert_csr_loaded(struct drm_i915_private *dev_priv)
672{
673 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
674 "CSR program storage start is NULL\n");
675 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
676 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
677}
678
Suketu Shah5aefb232015-04-16 14:22:10 +0530679static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530680{
Suketu Shah5aefb232015-04-16 14:22:10 +0530681 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
682 SKL_DISP_PW_2);
683
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700684 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530685
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700686 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
687 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200688 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530689
690 assert_csr_loaded(dev_priv);
691}
692
Imre Deakf62c79b2016-04-20 20:27:57 +0300693void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530694{
Suketu Shah5aefb232015-04-16 14:22:10 +0530695 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530696
697 DRM_DEBUG_KMS("Enabling DC5\n");
698
Lucas De Marchi53421c22017-12-04 15:22:10 -0800699 /* Wa Display #1183: skl,kbl,cfl */
700 if (IS_GEN9_BC(dev_priv))
701 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
702 SKL_SELECT_ALTERNATE_DC_EXIT);
703
Imre Deak13ae3a02015-11-04 19:24:16 +0200704 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530705}
706
Suketu Shah93c7cb62015-04-16 14:22:13 +0530707static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530708{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700709 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
710 "Backlight is not disabled.\n");
711 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
712 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530713
714 assert_csr_loaded(dev_priv);
715}
716
Daniel Vetterc4c25252018-04-17 12:02:25 +0200717static void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530718{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530719 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530720
721 DRM_DEBUG_KMS("Enabling DC6\n");
722
Imre Deakb49be662018-04-19 18:51:09 +0300723 /* Wa Display #1183: skl,kbl,cfl */
724 if (IS_GEN9_BC(dev_priv))
725 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
726 SKL_SELECT_ALTERNATE_DC_EXIT);
Imre Deak13ae3a02015-11-04 19:24:16 +0200727
Imre Deakb49be662018-04-19 18:51:09 +0300728 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
Suketu Shahf75a1982015-04-16 14:22:11 +0530729}
730
Daniel Vetter9c065a72014-09-30 10:56:38 +0200731static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
732 struct i915_power_well *power_well)
733{
Imre Deak75e39682018-08-06 12:58:39 +0300734 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
735 int pw_idx = power_well->desc->hsw.idx;
736 u32 mask = HSW_PWR_WELL_CTL_REQ(pw_idx);
737 u32 bios_req = I915_READ(regs->bios);
Imre Deak1af474f2017-07-06 17:40:34 +0300738
Imre Deak16e84912017-02-17 17:39:45 +0200739 /* Take over the request bit if set by BIOS. */
Imre Deak1af474f2017-07-06 17:40:34 +0300740 if (bios_req & mask) {
Imre Deak75e39682018-08-06 12:58:39 +0300741 u32 drv_req = I915_READ(regs->driver);
Imre Deak1af474f2017-07-06 17:40:34 +0300742
743 if (!(drv_req & mask))
Imre Deak75e39682018-08-06 12:58:39 +0300744 I915_WRITE(regs->driver, drv_req | mask);
745 I915_WRITE(regs->bios, bios_req & ~mask);
Imre Deak16e84912017-02-17 17:39:45 +0200746 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200747}
748
Imre Deak9c8d0b82016-06-13 16:44:34 +0300749static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
750 struct i915_power_well *power_well)
751{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300752 bxt_ddi_phy_init(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300753}
754
755static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
756 struct i915_power_well *power_well)
757{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300758 bxt_ddi_phy_uninit(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300759}
760
761static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
762 struct i915_power_well *power_well)
763{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300764 return bxt_ddi_phy_is_enabled(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300765}
766
Imre Deak9c8d0b82016-06-13 16:44:34 +0300767static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
768{
769 struct i915_power_well *power_well;
770
Imre Deak2183b492018-08-06 12:58:41 +0300771 power_well = lookup_power_well(dev_priv, BXT_DISP_PW_DPIO_CMN_A);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300772 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300773 bxt_ddi_phy_verify_state(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300774
Imre Deakd9fcdc82018-08-06 12:58:42 +0300775 power_well = lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300776 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300777 bxt_ddi_phy_verify_state(dev_priv, power_well->desc->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200778
779 if (IS_GEMINILAKE(dev_priv)) {
Imre Deak2183b492018-08-06 12:58:41 +0300780 power_well = lookup_power_well(dev_priv,
781 GLK_DISP_PW_DPIO_CMN_C);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200782 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300783 bxt_ddi_phy_verify_state(dev_priv,
784 power_well->desc->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200785 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300786}
787
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100788static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
789 struct i915_power_well *power_well)
790{
791 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
792}
793
Ville Syrjälä18a80672016-05-16 16:59:40 +0300794static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
795{
796 u32 tmp = I915_READ(DBUF_CTL);
797
798 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
799 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
800 "Unexpected DBuf power power state (0x%08x)\n", tmp);
801}
802
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100803static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
804 struct i915_power_well *power_well)
805{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200806 struct intel_cdclk_state cdclk_state = {};
807
Imre Deak5b773eb2016-02-29 22:49:05 +0200808 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300809
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200810 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
Ville Syrjälä64600bd2017-10-24 12:52:08 +0300811 /* Can't read out voltage_level so can't use intel_cdclk_changed() */
812 WARN_ON(intel_cdclk_needs_modeset(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300813
Ville Syrjälä18a80672016-05-16 16:59:40 +0300814 gen9_assert_dbuf_enabled(dev_priv);
815
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200816 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300817 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100818}
819
820static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
821 struct i915_power_well *power_well)
822{
Imre Deakf74ed082016-04-18 14:48:21 +0300823 if (!dev_priv->csr.dmc_payload)
824 return;
825
Imre Deaka37baf32016-02-29 22:49:03 +0200826 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100827 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200828 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100829 gen9_enable_dc5(dev_priv);
830}
831
Imre Deak3c1b38e2017-02-17 17:39:42 +0200832static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
833 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100834{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100835}
836
Daniel Vetter9c065a72014-09-30 10:56:38 +0200837static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
838 struct i915_power_well *power_well)
839{
840}
841
842static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
843 struct i915_power_well *power_well)
844{
845 return true;
846}
847
Ville Syrjälä2ee0da12017-06-01 17:36:16 +0300848static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
849 struct i915_power_well *power_well)
850{
851 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
852 i830_enable_pipe(dev_priv, PIPE_A);
853 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
854 i830_enable_pipe(dev_priv, PIPE_B);
855}
856
857static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
858 struct i915_power_well *power_well)
859{
860 i830_disable_pipe(dev_priv, PIPE_B);
861 i830_disable_pipe(dev_priv, PIPE_A);
862}
863
864static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
865 struct i915_power_well *power_well)
866{
867 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
868 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
869}
870
871static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
872 struct i915_power_well *power_well)
873{
874 if (power_well->count > 0)
875 i830_pipes_power_well_enable(dev_priv, power_well);
876 else
877 i830_pipes_power_well_disable(dev_priv, power_well);
878}
879
Daniel Vetter9c065a72014-09-30 10:56:38 +0200880static void vlv_set_power_well(struct drm_i915_private *dev_priv,
881 struct i915_power_well *power_well, bool enable)
882{
Imre Deakd13dd052018-08-06 12:58:38 +0300883 int pw_idx = power_well->desc->vlv.idx;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200884 u32 mask;
885 u32 state;
886 u32 ctrl;
887
Imre Deakd13dd052018-08-06 12:58:38 +0300888 mask = PUNIT_PWRGT_MASK(pw_idx);
889 state = enable ? PUNIT_PWRGT_PWR_ON(pw_idx) :
890 PUNIT_PWRGT_PWR_GATE(pw_idx);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200891
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100892 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200893
894#define COND \
895 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
896
897 if (COND)
898 goto out;
899
900 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
901 ctrl &= ~mask;
902 ctrl |= state;
903 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
904
905 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900906 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200907 state,
908 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
909
910#undef COND
911
912out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100913 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200914}
915
Daniel Vetter9c065a72014-09-30 10:56:38 +0200916static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
917 struct i915_power_well *power_well)
918{
919 vlv_set_power_well(dev_priv, power_well, true);
920}
921
922static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
923 struct i915_power_well *power_well)
924{
925 vlv_set_power_well(dev_priv, power_well, false);
926}
927
928static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
929 struct i915_power_well *power_well)
930{
Imre Deakd13dd052018-08-06 12:58:38 +0300931 int pw_idx = power_well->desc->vlv.idx;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200932 bool enabled = false;
933 u32 mask;
934 u32 state;
935 u32 ctrl;
936
Imre Deakd13dd052018-08-06 12:58:38 +0300937 mask = PUNIT_PWRGT_MASK(pw_idx);
938 ctrl = PUNIT_PWRGT_PWR_ON(pw_idx);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200939
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100940 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200941
942 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
943 /*
944 * We only ever set the power-on and power-gate states, anything
945 * else is unexpected.
946 */
Imre Deakd13dd052018-08-06 12:58:38 +0300947 WARN_ON(state != PUNIT_PWRGT_PWR_ON(pw_idx) &&
948 state != PUNIT_PWRGT_PWR_GATE(pw_idx));
Daniel Vetter9c065a72014-09-30 10:56:38 +0200949 if (state == ctrl)
950 enabled = true;
951
952 /*
953 * A transient state at this point would mean some unexpected party
954 * is poking at the power controls too.
955 */
956 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
957 WARN_ON(ctrl != state);
958
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100959 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200960
961 return enabled;
962}
963
Ville Syrjälä766078d2016-04-11 16:56:30 +0300964static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
965{
Hans de Goede721d4842016-12-02 15:29:04 +0100966 u32 val;
967
968 /*
969 * On driver load, a pipe may be active and driving a DSI display.
970 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
971 * (and never recovering) in this case. intel_dsi_post_disable() will
972 * clear it when we turn off the display.
973 */
974 val = I915_READ(DSPCLK_GATE_D);
975 val &= DPOUNIT_CLOCK_GATE_DISABLE;
976 val |= VRHUNIT_CLOCK_GATE_DISABLE;
977 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +0300978
979 /*
980 * Disable trickle feed and enable pnd deadline calculation
981 */
982 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
983 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +0300984
985 WARN_ON(dev_priv->rawclk_freq == 0);
986
987 I915_WRITE(RAWCLK_FREQ_VLV,
988 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +0300989}
990
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300991static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200992{
Lyude9504a892016-06-21 17:03:42 -0400993 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300994 enum pipe pipe;
995
996 /*
997 * Enable the CRI clock source so we can get at the
998 * display and the reference clock for VGA
999 * hotplug / manual detection. Supposedly DSI also
1000 * needs the ref clock up and running.
1001 *
1002 * CHV DPLL B/C have some issues if VGA mode is enabled.
1003 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +00001004 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001005 u32 val = I915_READ(DPLL(pipe));
1006
1007 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1008 if (pipe != PIPE_A)
1009 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1010
1011 I915_WRITE(DPLL(pipe), val);
1012 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001013
Ville Syrjälä766078d2016-04-11 16:56:30 +03001014 vlv_init_display_clock_gating(dev_priv);
1015
Daniel Vetter9c065a72014-09-30 10:56:38 +02001016 spin_lock_irq(&dev_priv->irq_lock);
1017 valleyview_enable_display_irqs(dev_priv);
1018 spin_unlock_irq(&dev_priv->irq_lock);
1019
1020 /*
1021 * During driver initialization/resume we can avoid restoring the
1022 * part of the HW/SW state that will be inited anyway explicitly.
1023 */
1024 if (dev_priv->power_domains.initializing)
1025 return;
1026
Daniel Vetterb9632912014-09-30 10:56:44 +02001027 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001028
Lyude9504a892016-06-21 17:03:42 -04001029 /* Re-enable the ADPA, if we have one */
1030 for_each_intel_encoder(&dev_priv->drm, encoder) {
1031 if (encoder->type == INTEL_OUTPUT_ANALOG)
1032 intel_crt_reset(&encoder->base);
1033 }
1034
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001035 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001036
1037 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001038}
1039
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001040static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1041{
1042 spin_lock_irq(&dev_priv->irq_lock);
1043 valleyview_disable_display_irqs(dev_priv);
1044 spin_unlock_irq(&dev_priv->irq_lock);
1045
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001046 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001047 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001048
Imre Deak78597992016-06-16 16:37:20 +03001049 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001050
Lyudeb64b5402016-10-26 12:36:09 -04001051 /* Prevent us from re-enabling polling on accident in late suspend */
1052 if (!dev_priv->drm.dev->power.is_suspended)
1053 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001054}
1055
1056static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1057 struct i915_power_well *power_well)
1058{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001059 vlv_set_power_well(dev_priv, power_well, true);
1060
1061 vlv_display_power_well_init(dev_priv);
1062}
1063
Daniel Vetter9c065a72014-09-30 10:56:38 +02001064static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1065 struct i915_power_well *power_well)
1066{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001067 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001068
1069 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001070}
1071
1072static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1073 struct i915_power_well *power_well)
1074{
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001075 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001076 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1077
1078 vlv_set_power_well(dev_priv, power_well, true);
1079
1080 /*
1081 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1082 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1083 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1084 * b. The other bits such as sfr settings / modesel may all
1085 * be set to 0.
1086 *
1087 * This should only be done on init and resume from S3 with
1088 * both PLLs disabled, or we risk losing DPIO and PLL
1089 * synchronization.
1090 */
1091 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1092}
1093
1094static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1095 struct i915_power_well *power_well)
1096{
1097 enum pipe pipe;
1098
Daniel Vetter9c065a72014-09-30 10:56:38 +02001099 for_each_pipe(dev_priv, pipe)
1100 assert_pll_disabled(dev_priv, pipe);
1101
1102 /* Assert common reset */
1103 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1104
1105 vlv_set_power_well(dev_priv, power_well, false);
1106}
1107
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001108#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001109
Imre Deak438b8dc2017-07-11 23:42:30 +03001110static struct i915_power_well *
1111lookup_power_well(struct drm_i915_private *dev_priv,
1112 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001113{
1114 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001115 int i;
1116
Imre Deakfc17f222015-11-04 19:24:11 +02001117 for (i = 0; i < power_domains->power_well_count; i++) {
1118 struct i915_power_well *power_well;
1119
1120 power_well = &power_domains->power_wells[i];
Imre Deakf28ec6f2018-08-06 12:58:37 +03001121 if (power_well->desc->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001122 return power_well;
1123 }
1124
1125 return NULL;
1126}
1127
1128#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1129
1130static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1131{
1132 struct i915_power_well *cmn_bc =
Imre Deak2183b492018-08-06 12:58:41 +03001133 lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
Ville Syrjälä30142272015-07-08 23:46:01 +03001134 struct i915_power_well *cmn_d =
Imre Deak2183b492018-08-06 12:58:41 +03001135 lookup_power_well(dev_priv, CHV_DISP_PW_DPIO_CMN_D);
Ville Syrjälä30142272015-07-08 23:46:01 +03001136 u32 phy_control = dev_priv->chv_phy_control;
1137 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001138 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001139
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001140 /*
1141 * The BIOS can leave the PHY is some weird state
1142 * where it doesn't fully power down some parts.
1143 * Disable the asserts until the PHY has been fully
1144 * reset (ie. the power well has been disabled at
1145 * least once).
1146 */
1147 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1148 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1149 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1150 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1151 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1152 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1153 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1154
1155 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1156 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1157 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1158 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1159
Imre Deakf28ec6f2018-08-06 12:58:37 +03001160 if (cmn_bc->desc->ops->is_enabled(dev_priv, cmn_bc)) {
Ville Syrjälä30142272015-07-08 23:46:01 +03001161 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1162
1163 /* this assumes override is only used to enable lanes */
1164 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1165 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1166
1167 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1168 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1169
1170 /* CL1 is on whenever anything is on in either channel */
1171 if (BITS_SET(phy_control,
1172 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1173 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1174 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1175
1176 /*
1177 * The DPLLB check accounts for the pipe B + port A usage
1178 * with CL2 powered up but all the lanes in the second channel
1179 * powered down.
1180 */
1181 if (BITS_SET(phy_control,
1182 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1183 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1184 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1185
1186 if (BITS_SET(phy_control,
1187 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1188 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1189 if (BITS_SET(phy_control,
1190 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1191 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1192
1193 if (BITS_SET(phy_control,
1194 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1195 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1196 if (BITS_SET(phy_control,
1197 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1198 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1199 }
1200
Imre Deakf28ec6f2018-08-06 12:58:37 +03001201 if (cmn_d->desc->ops->is_enabled(dev_priv, cmn_d)) {
Ville Syrjälä30142272015-07-08 23:46:01 +03001202 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1203
1204 /* this assumes override is only used to enable lanes */
1205 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1206 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1207
1208 if (BITS_SET(phy_control,
1209 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1210 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1211
1212 if (BITS_SET(phy_control,
1213 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1214 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1215 if (BITS_SET(phy_control,
1216 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1217 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1218 }
1219
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001220 phy_status &= phy_status_mask;
1221
Ville Syrjälä30142272015-07-08 23:46:01 +03001222 /*
1223 * The PHY may be busy with some initial calibration and whatnot,
1224 * so the power state can take a while to actually change.
1225 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001226 if (intel_wait_for_register(dev_priv,
1227 DISPLAY_PHY_STATUS,
1228 phy_status_mask,
1229 phy_status,
1230 10))
1231 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1232 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1233 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001234}
1235
1236#undef BITS_SET
1237
Daniel Vetter9c065a72014-09-30 10:56:38 +02001238static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1239 struct i915_power_well *power_well)
1240{
1241 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001242 enum pipe pipe;
1243 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001244
Imre Deak2183b492018-08-06 12:58:41 +03001245 WARN_ON_ONCE(power_well->desc->id != VLV_DISP_PW_DPIO_CMN_BC &&
1246 power_well->desc->id != CHV_DISP_PW_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001247
Imre Deak2183b492018-08-06 12:58:41 +03001248 if (power_well->desc->id == VLV_DISP_PW_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001249 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001250 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001251 } else {
1252 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001253 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001254 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001255
1256 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001257 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1258 vlv_set_power_well(dev_priv, power_well, true);
1259
1260 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001261 if (intel_wait_for_register(dev_priv,
1262 DISPLAY_PHY_STATUS,
1263 PHY_POWERGOOD(phy),
1264 PHY_POWERGOOD(phy),
1265 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001266 DRM_ERROR("Display PHY %d is not power up\n", phy);
1267
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001268 mutex_lock(&dev_priv->sb_lock);
1269
1270 /* Enable dynamic power down */
1271 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001272 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1273 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001274 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1275
Imre Deak2183b492018-08-06 12:58:41 +03001276 if (power_well->desc->id == VLV_DISP_PW_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001277 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1278 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1279 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001280 } else {
1281 /*
1282 * Force the non-existing CL2 off. BXT does this
1283 * too, so maybe it saves some power even though
1284 * CL2 doesn't exist?
1285 */
1286 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1287 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1288 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001289 }
1290
1291 mutex_unlock(&dev_priv->sb_lock);
1292
Ville Syrjälä70722462015-04-10 18:21:28 +03001293 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1294 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001295
1296 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1297 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001298
1299 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001300}
1301
1302static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1303 struct i915_power_well *power_well)
1304{
1305 enum dpio_phy phy;
1306
Imre Deak2183b492018-08-06 12:58:41 +03001307 WARN_ON_ONCE(power_well->desc->id != VLV_DISP_PW_DPIO_CMN_BC &&
1308 power_well->desc->id != CHV_DISP_PW_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001309
Imre Deak2183b492018-08-06 12:58:41 +03001310 if (power_well->desc->id == VLV_DISP_PW_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001311 phy = DPIO_PHY0;
1312 assert_pll_disabled(dev_priv, PIPE_A);
1313 assert_pll_disabled(dev_priv, PIPE_B);
1314 } else {
1315 phy = DPIO_PHY1;
1316 assert_pll_disabled(dev_priv, PIPE_C);
1317 }
1318
Ville Syrjälä70722462015-04-10 18:21:28 +03001319 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1320 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001321
1322 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001323
1324 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1325 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001326
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001327 /* PHY is fully reset now, so we can enable the PHY state asserts */
1328 dev_priv->chv_phy_assert[phy] = true;
1329
Ville Syrjälä30142272015-07-08 23:46:01 +03001330 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001331}
1332
Ville Syrjälä6669e392015-07-08 23:46:00 +03001333static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1334 enum dpio_channel ch, bool override, unsigned int mask)
1335{
1336 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1337 u32 reg, val, expected, actual;
1338
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001339 /*
1340 * The BIOS can leave the PHY is some weird state
1341 * where it doesn't fully power down some parts.
1342 * Disable the asserts until the PHY has been fully
1343 * reset (ie. the power well has been disabled at
1344 * least once).
1345 */
1346 if (!dev_priv->chv_phy_assert[phy])
1347 return;
1348
Ville Syrjälä6669e392015-07-08 23:46:00 +03001349 if (ch == DPIO_CH0)
1350 reg = _CHV_CMN_DW0_CH0;
1351 else
1352 reg = _CHV_CMN_DW6_CH1;
1353
1354 mutex_lock(&dev_priv->sb_lock);
1355 val = vlv_dpio_read(dev_priv, pipe, reg);
1356 mutex_unlock(&dev_priv->sb_lock);
1357
1358 /*
1359 * This assumes !override is only used when the port is disabled.
1360 * All lanes should power down even without the override when
1361 * the port is disabled.
1362 */
1363 if (!override || mask == 0xf) {
1364 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1365 /*
1366 * If CH1 common lane is not active anymore
1367 * (eg. for pipe B DPLL) the entire channel will
1368 * shut down, which causes the common lane registers
1369 * to read as 0. That means we can't actually check
1370 * the lane power down status bits, but as the entire
1371 * register reads as 0 it's a good indication that the
1372 * channel is indeed entirely powered down.
1373 */
1374 if (ch == DPIO_CH1 && val == 0)
1375 expected = 0;
1376 } else if (mask != 0x0) {
1377 expected = DPIO_ANYDL_POWERDOWN;
1378 } else {
1379 expected = 0;
1380 }
1381
1382 if (ch == DPIO_CH0)
1383 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1384 else
1385 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1386 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1387
1388 WARN(actual != expected,
1389 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1390 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1391 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1392 reg, val);
1393}
1394
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001395bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1396 enum dpio_channel ch, bool override)
1397{
1398 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1399 bool was_override;
1400
1401 mutex_lock(&power_domains->lock);
1402
1403 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1404
1405 if (override == was_override)
1406 goto out;
1407
1408 if (override)
1409 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1410 else
1411 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1412
1413 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1414
1415 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1416 phy, ch, dev_priv->chv_phy_control);
1417
Ville Syrjälä30142272015-07-08 23:46:01 +03001418 assert_chv_phy_status(dev_priv);
1419
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001420out:
1421 mutex_unlock(&power_domains->lock);
1422
1423 return was_override;
1424}
1425
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001426void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1427 bool override, unsigned int mask)
1428{
1429 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1430 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1431 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1432 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1433
1434 mutex_lock(&power_domains->lock);
1435
1436 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1437 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1438
1439 if (override)
1440 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1441 else
1442 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1443
1444 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1445
1446 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1447 phy, ch, mask, dev_priv->chv_phy_control);
1448
Ville Syrjälä30142272015-07-08 23:46:01 +03001449 assert_chv_phy_status(dev_priv);
1450
Ville Syrjälä6669e392015-07-08 23:46:00 +03001451 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1452
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001453 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001454}
1455
1456static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1457 struct i915_power_well *power_well)
1458{
Imre Deakf49193c2017-07-06 17:40:23 +03001459 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001460 bool enabled;
1461 u32 state, ctrl;
1462
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001463 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001464
1465 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1466 /*
1467 * We only ever set the power-on and power-gate states, anything
1468 * else is unexpected.
1469 */
1470 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1471 enabled = state == DP_SSS_PWR_ON(pipe);
1472
1473 /*
1474 * A transient state at this point would mean some unexpected party
1475 * is poking at the power controls too.
1476 */
1477 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1478 WARN_ON(ctrl << 16 != state);
1479
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001480 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001481
1482 return enabled;
1483}
1484
1485static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1486 struct i915_power_well *power_well,
1487 bool enable)
1488{
Imre Deakf49193c2017-07-06 17:40:23 +03001489 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001490 u32 state;
1491 u32 ctrl;
1492
1493 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1494
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001495 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001496
1497#define COND \
1498 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1499
1500 if (COND)
1501 goto out;
1502
1503 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1504 ctrl &= ~DP_SSC_MASK(pipe);
1505 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1506 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1507
1508 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001509 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001510 state,
1511 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1512
1513#undef COND
1514
1515out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001516 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001517}
1518
Daniel Vetter9c065a72014-09-30 10:56:38 +02001519static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1520 struct i915_power_well *power_well)
1521{
Daniel Vetter9c065a72014-09-30 10:56:38 +02001522 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001523
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001524 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001525}
1526
1527static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1528 struct i915_power_well *power_well)
1529{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001530 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001531
Daniel Vetter9c065a72014-09-30 10:56:38 +02001532 chv_set_pipe_power_well(dev_priv, power_well, false);
1533}
1534
Imre Deak09731282016-02-17 14:17:42 +02001535static void
1536__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1537 enum intel_display_power_domain domain)
1538{
1539 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1540 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001541
Imre Deak75ccb2e2017-02-17 17:39:43 +02001542 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001543 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001544
1545 power_domains->domain_use_count[domain]++;
1546}
1547
Daniel Vettere4e76842014-09-30 10:56:42 +02001548/**
1549 * intel_display_power_get - grab a power domain reference
1550 * @dev_priv: i915 device instance
1551 * @domain: power domain to reference
1552 *
1553 * This function grabs a power domain reference for @domain and ensures that the
1554 * power domain and all its parents are powered up. Therefore users should only
1555 * grab a reference to the innermost power domain they need.
1556 *
1557 * Any power domain reference obtained by this function must have a symmetric
1558 * call to intel_display_power_put() to release the reference again.
1559 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001560void intel_display_power_get(struct drm_i915_private *dev_priv,
1561 enum intel_display_power_domain domain)
1562{
Imre Deak09731282016-02-17 14:17:42 +02001563 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001564
1565 intel_runtime_pm_get(dev_priv);
1566
Imre Deak09731282016-02-17 14:17:42 +02001567 mutex_lock(&power_domains->lock);
1568
1569 __intel_display_power_get_domain(dev_priv, domain);
1570
1571 mutex_unlock(&power_domains->lock);
1572}
1573
1574/**
1575 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1576 * @dev_priv: i915 device instance
1577 * @domain: power domain to reference
1578 *
1579 * This function grabs a power domain reference for @domain and ensures that the
1580 * power domain and all its parents are powered up. Therefore users should only
1581 * grab a reference to the innermost power domain they need.
1582 *
1583 * Any power domain reference obtained by this function must have a symmetric
1584 * call to intel_display_power_put() to release the reference again.
1585 */
1586bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1587 enum intel_display_power_domain domain)
1588{
1589 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1590 bool is_enabled;
1591
1592 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1593 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001594
1595 mutex_lock(&power_domains->lock);
1596
Imre Deak09731282016-02-17 14:17:42 +02001597 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1598 __intel_display_power_get_domain(dev_priv, domain);
1599 is_enabled = true;
1600 } else {
1601 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001602 }
1603
Daniel Vetter9c065a72014-09-30 10:56:38 +02001604 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001605
1606 if (!is_enabled)
1607 intel_runtime_pm_put(dev_priv);
1608
1609 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001610}
1611
Daniel Vettere4e76842014-09-30 10:56:42 +02001612/**
1613 * intel_display_power_put - release a power domain reference
1614 * @dev_priv: i915 device instance
1615 * @domain: power domain to reference
1616 *
1617 * This function drops the power domain reference obtained by
1618 * intel_display_power_get() and might power down the corresponding hardware
1619 * block right away if this is the last reference.
1620 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001621void intel_display_power_put(struct drm_i915_private *dev_priv,
1622 enum intel_display_power_domain domain)
1623{
1624 struct i915_power_domains *power_domains;
1625 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001626
1627 power_domains = &dev_priv->power_domains;
1628
1629 mutex_lock(&power_domains->lock);
1630
Daniel Stone11c86db2015-11-20 15:55:34 +00001631 WARN(!power_domains->domain_use_count[domain],
1632 "Use count on domain %s is already zero\n",
1633 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001634 power_domains->domain_use_count[domain]--;
1635
Imre Deak75ccb2e2017-02-17 17:39:43 +02001636 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001637 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001638
1639 mutex_unlock(&power_domains->lock);
1640
1641 intel_runtime_pm_put(dev_priv);
1642}
1643
Imre Deak965a79a2017-07-06 17:40:40 +03001644#define I830_PIPES_POWER_DOMAINS ( \
1645 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1646 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1647 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1648 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1649 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1650 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001651 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001652
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001653#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001654 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1655 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1656 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1657 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1658 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1659 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1660 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1661 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1662 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1663 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1664 BIT_ULL(POWER_DOMAIN_VGA) | \
1665 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1666 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1667 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1668 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1669 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001670
1671#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001672 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1673 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1674 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1675 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1676 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1677 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001678
1679#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001680 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1681 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1682 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001683
1684#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001685 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1686 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1687 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001688
1689#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001690 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1691 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1692 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001693
1694#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001695 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1696 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1697 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001698
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001699#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001700 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1701 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1702 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1703 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1704 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1705 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1706 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1707 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1708 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1709 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1710 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1711 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1712 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1713 BIT_ULL(POWER_DOMAIN_VGA) | \
1714 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1715 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1716 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1717 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1718 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1719 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001720
Daniel Vetter9c065a72014-09-30 10:56:38 +02001721#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001722 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1723 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1724 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1725 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1726 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001727
1728#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001729 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1730 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1731 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001732
Imre Deak965a79a2017-07-06 17:40:40 +03001733#define HSW_DISPLAY_POWER_DOMAINS ( \
1734 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1735 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1736 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1737 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1738 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1739 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1740 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1741 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1742 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1743 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1744 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1745 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1746 BIT_ULL(POWER_DOMAIN_VGA) | \
1747 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1748 BIT_ULL(POWER_DOMAIN_INIT))
1749
1750#define BDW_DISPLAY_POWER_DOMAINS ( \
1751 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1752 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1753 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1754 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1755 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1756 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1757 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1758 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1759 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1760 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1761 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1762 BIT_ULL(POWER_DOMAIN_VGA) | \
1763 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1764 BIT_ULL(POWER_DOMAIN_INIT))
1765
1766#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1767 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1768 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1769 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1770 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1771 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1772 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1773 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1774 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1775 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1776 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1777 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1778 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1779 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1780 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1781 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1782 BIT_ULL(POWER_DOMAIN_VGA) | \
1783 BIT_ULL(POWER_DOMAIN_INIT))
1784#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
1785 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
1786 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1787 BIT_ULL(POWER_DOMAIN_INIT))
1788#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1789 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1790 BIT_ULL(POWER_DOMAIN_INIT))
1791#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1792 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1793 BIT_ULL(POWER_DOMAIN_INIT))
1794#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
1795 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1796 BIT_ULL(POWER_DOMAIN_INIT))
1797#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1798 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001799 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001800 BIT_ULL(POWER_DOMAIN_MODESET) | \
1801 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1802 BIT_ULL(POWER_DOMAIN_INIT))
1803
1804#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1805 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1806 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1807 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1808 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1809 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1810 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1811 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1812 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1813 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1814 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1815 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1816 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1817 BIT_ULL(POWER_DOMAIN_VGA) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001818 BIT_ULL(POWER_DOMAIN_INIT))
1819#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1820 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001821 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001822 BIT_ULL(POWER_DOMAIN_MODESET) | \
1823 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä54c105d2017-12-08 23:37:37 +02001824 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001825 BIT_ULL(POWER_DOMAIN_INIT))
1826#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
1827 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1828 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1829 BIT_ULL(POWER_DOMAIN_INIT))
1830#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
1831 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1832 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1833 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1834 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1835 BIT_ULL(POWER_DOMAIN_INIT))
1836
1837#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1838 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1839 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1840 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1841 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1842 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1843 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1844 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1845 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1846 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1847 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1848 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1849 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1850 BIT_ULL(POWER_DOMAIN_VGA) | \
1851 BIT_ULL(POWER_DOMAIN_INIT))
1852#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
1853 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
1854#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1855 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
1856#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1857 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
1858#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
1859 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1860 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1861 BIT_ULL(POWER_DOMAIN_INIT))
1862#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
1863 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1864 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1865 BIT_ULL(POWER_DOMAIN_INIT))
1866#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
1867 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1868 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1869 BIT_ULL(POWER_DOMAIN_INIT))
1870#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
1871 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Imre Deak52528052018-06-21 21:44:49 +03001872 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001873 BIT_ULL(POWER_DOMAIN_INIT))
1874#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
1875 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1876 BIT_ULL(POWER_DOMAIN_INIT))
1877#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
1878 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1879 BIT_ULL(POWER_DOMAIN_INIT))
1880#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1881 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001882 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001883 BIT_ULL(POWER_DOMAIN_MODESET) | \
1884 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä156961a2017-12-08 23:37:36 +02001885 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001886 BIT_ULL(POWER_DOMAIN_INIT))
1887
1888#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1889 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1890 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1891 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1892 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1893 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1894 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1895 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1896 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1897 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1898 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001899 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001900 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1901 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1902 BIT_ULL(POWER_DOMAIN_AUX_D) | \
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001903 BIT_ULL(POWER_DOMAIN_AUX_F) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001904 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1905 BIT_ULL(POWER_DOMAIN_VGA) | \
1906 BIT_ULL(POWER_DOMAIN_INIT))
1907#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
1908 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001909 BIT_ULL(POWER_DOMAIN_INIT))
1910#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
1911 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1912 BIT_ULL(POWER_DOMAIN_INIT))
1913#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
1914 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1915 BIT_ULL(POWER_DOMAIN_INIT))
1916#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
1917 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1918 BIT_ULL(POWER_DOMAIN_INIT))
1919#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
1920 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Dhinakaran Pandiyanb891d5e2018-02-23 14:15:15 -08001921 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001922 BIT_ULL(POWER_DOMAIN_INIT))
1923#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
1924 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1925 BIT_ULL(POWER_DOMAIN_INIT))
1926#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
1927 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1928 BIT_ULL(POWER_DOMAIN_INIT))
1929#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
1930 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1931 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001932#define CNL_DISPLAY_AUX_F_POWER_DOMAINS ( \
1933 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1934 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001935#define CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS ( \
1936 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1937 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak965a79a2017-07-06 17:40:40 +03001938#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1939 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulin6e7a3f52018-01-11 08:24:17 +00001940 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001941 BIT_ULL(POWER_DOMAIN_MODESET) | \
1942 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001943 BIT_ULL(POWER_DOMAIN_INIT))
1944
Imre Deak67ca07e2018-06-26 17:22:32 +03001945/*
1946 * ICL PW_0/PG_0 domains (HW/DMC control):
1947 * - PCI
1948 * - clocks except port PLL
1949 * - central power except FBC
1950 * - shared functions except pipe interrupts, pipe MBUS, DBUF registers
1951 * ICL PW_1/PG_1 domains (HW/DMC control):
1952 * - DBUF function
1953 * - PIPE_A and its planes, except VGA
1954 * - transcoder EDP + PSR
1955 * - transcoder DSI
1956 * - DDI_A
1957 * - FBC
1958 */
1959#define ICL_PW_4_POWER_DOMAINS ( \
1960 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1961 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1962 BIT_ULL(POWER_DOMAIN_INIT))
1963 /* VDSC/joining */
1964#define ICL_PW_3_POWER_DOMAINS ( \
1965 ICL_PW_4_POWER_DOMAINS | \
1966 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1967 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1968 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1969 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1970 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1971 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1972 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1973 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1974 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1975 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1976 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1977 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1978 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1979 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
1980 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1981 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1982 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1983 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1984 BIT_ULL(POWER_DOMAIN_AUX_E) | \
1985 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1986 BIT_ULL(POWER_DOMAIN_AUX_TBT1) | \
1987 BIT_ULL(POWER_DOMAIN_AUX_TBT2) | \
1988 BIT_ULL(POWER_DOMAIN_AUX_TBT3) | \
1989 BIT_ULL(POWER_DOMAIN_AUX_TBT4) | \
1990 BIT_ULL(POWER_DOMAIN_VGA) | \
1991 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1992 BIT_ULL(POWER_DOMAIN_INIT))
1993 /*
1994 * - transcoder WD
1995 * - KVMR (HW control)
1996 */
1997#define ICL_PW_2_POWER_DOMAINS ( \
1998 ICL_PW_3_POWER_DOMAINS | \
1999 BIT_ULL(POWER_DOMAIN_INIT))
2000 /*
2001 * - eDP/DSI VDSC
2002 * - KVMR (HW control)
2003 */
2004#define ICL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
2005 ICL_PW_2_POWER_DOMAINS | \
2006 BIT_ULL(POWER_DOMAIN_MODESET) | \
2007 BIT_ULL(POWER_DOMAIN_AUX_A) | \
2008 BIT_ULL(POWER_DOMAIN_INIT))
2009
2010#define ICL_DDI_IO_A_POWER_DOMAINS ( \
2011 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
2012#define ICL_DDI_IO_B_POWER_DOMAINS ( \
2013 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
2014#define ICL_DDI_IO_C_POWER_DOMAINS ( \
2015 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
2016#define ICL_DDI_IO_D_POWER_DOMAINS ( \
2017 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO))
2018#define ICL_DDI_IO_E_POWER_DOMAINS ( \
2019 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO))
2020#define ICL_DDI_IO_F_POWER_DOMAINS ( \
2021 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO))
2022
2023#define ICL_AUX_A_IO_POWER_DOMAINS ( \
2024 BIT_ULL(POWER_DOMAIN_AUX_A))
2025#define ICL_AUX_B_IO_POWER_DOMAINS ( \
2026 BIT_ULL(POWER_DOMAIN_AUX_B))
2027#define ICL_AUX_C_IO_POWER_DOMAINS ( \
2028 BIT_ULL(POWER_DOMAIN_AUX_C))
2029#define ICL_AUX_D_IO_POWER_DOMAINS ( \
2030 BIT_ULL(POWER_DOMAIN_AUX_D))
2031#define ICL_AUX_E_IO_POWER_DOMAINS ( \
2032 BIT_ULL(POWER_DOMAIN_AUX_E))
2033#define ICL_AUX_F_IO_POWER_DOMAINS ( \
2034 BIT_ULL(POWER_DOMAIN_AUX_F))
2035#define ICL_AUX_TBT1_IO_POWER_DOMAINS ( \
2036 BIT_ULL(POWER_DOMAIN_AUX_TBT1))
2037#define ICL_AUX_TBT2_IO_POWER_DOMAINS ( \
2038 BIT_ULL(POWER_DOMAIN_AUX_TBT2))
2039#define ICL_AUX_TBT3_IO_POWER_DOMAINS ( \
2040 BIT_ULL(POWER_DOMAIN_AUX_TBT3))
2041#define ICL_AUX_TBT4_IO_POWER_DOMAINS ( \
2042 BIT_ULL(POWER_DOMAIN_AUX_TBT4))
2043
Daniel Vetter9c065a72014-09-30 10:56:38 +02002044static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002045 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002046 .enable = i9xx_always_on_power_well_noop,
2047 .disable = i9xx_always_on_power_well_noop,
2048 .is_enabled = i9xx_always_on_power_well_enabled,
2049};
2050
2051static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002052 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002053 .enable = chv_pipe_power_well_enable,
2054 .disable = chv_pipe_power_well_disable,
2055 .is_enabled = chv_pipe_power_well_enabled,
2056};
2057
2058static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002059 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002060 .enable = chv_dpio_cmn_power_well_enable,
2061 .disable = chv_dpio_cmn_power_well_disable,
2062 .is_enabled = vlv_power_well_enabled,
2063};
2064
Imre Deakf28ec6f2018-08-06 12:58:37 +03002065static const struct i915_power_well_desc i9xx_always_on_power_well[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002066 {
2067 .name = "always-on",
2068 .always_on = 1,
2069 .domains = POWER_DOMAIN_MASK,
2070 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002071 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002072 },
2073};
2074
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002075static const struct i915_power_well_ops i830_pipes_power_well_ops = {
2076 .sync_hw = i830_pipes_power_well_sync_hw,
2077 .enable = i830_pipes_power_well_enable,
2078 .disable = i830_pipes_power_well_disable,
2079 .is_enabled = i830_pipes_power_well_enabled,
2080};
2081
Imre Deakf28ec6f2018-08-06 12:58:37 +03002082static const struct i915_power_well_desc i830_power_wells[] = {
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002083 {
2084 .name = "always-on",
2085 .always_on = 1,
2086 .domains = POWER_DOMAIN_MASK,
2087 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002088 .id = DISP_PW_ID_NONE,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002089 },
2090 {
2091 .name = "pipes",
2092 .domains = I830_PIPES_POWER_DOMAINS,
2093 .ops = &i830_pipes_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002094 .id = DISP_PW_ID_NONE,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002095 },
2096};
2097
Daniel Vetter9c065a72014-09-30 10:56:38 +02002098static const struct i915_power_well_ops hsw_power_well_ops = {
2099 .sync_hw = hsw_power_well_sync_hw,
2100 .enable = hsw_power_well_enable,
2101 .disable = hsw_power_well_disable,
2102 .is_enabled = hsw_power_well_enabled,
2103};
2104
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002105static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002106 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002107 .enable = gen9_dc_off_power_well_enable,
2108 .disable = gen9_dc_off_power_well_disable,
2109 .is_enabled = gen9_dc_off_power_well_enabled,
2110};
2111
Imre Deak9c8d0b82016-06-13 16:44:34 +03002112static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002113 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002114 .enable = bxt_dpio_cmn_power_well_enable,
2115 .disable = bxt_dpio_cmn_power_well_disable,
2116 .is_enabled = bxt_dpio_cmn_power_well_enabled,
2117};
2118
Imre Deak75e39682018-08-06 12:58:39 +03002119static const struct i915_power_well_regs hsw_power_well_regs = {
2120 .bios = HSW_PWR_WELL_CTL1,
2121 .driver = HSW_PWR_WELL_CTL2,
2122 .kvmr = HSW_PWR_WELL_CTL3,
2123 .debug = HSW_PWR_WELL_CTL4,
2124};
2125
Imre Deakf28ec6f2018-08-06 12:58:37 +03002126static const struct i915_power_well_desc hsw_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002127 {
2128 .name = "always-on",
2129 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002130 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002131 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002132 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002133 },
2134 {
2135 .name = "display",
2136 .domains = HSW_DISPLAY_POWER_DOMAINS,
2137 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002138 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002139 {
Imre Deak75e39682018-08-06 12:58:39 +03002140 .hsw.regs = &hsw_power_well_regs,
2141 .hsw.idx = HSW_PW_CTL_IDX_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002142 .hsw.has_vga = true,
2143 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002144 },
2145};
2146
Imre Deakf28ec6f2018-08-06 12:58:37 +03002147static const struct i915_power_well_desc bdw_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002148 {
2149 .name = "always-on",
2150 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002151 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002152 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002153 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002154 },
2155 {
2156 .name = "display",
2157 .domains = BDW_DISPLAY_POWER_DOMAINS,
2158 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002159 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002160 {
Imre Deak75e39682018-08-06 12:58:39 +03002161 .hsw.regs = &hsw_power_well_regs,
2162 .hsw.idx = HSW_PW_CTL_IDX_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002163 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2164 .hsw.has_vga = true,
2165 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002166 },
2167};
2168
2169static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002170 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002171 .enable = vlv_display_power_well_enable,
2172 .disable = vlv_display_power_well_disable,
2173 .is_enabled = vlv_power_well_enabled,
2174};
2175
2176static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002177 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002178 .enable = vlv_dpio_cmn_power_well_enable,
2179 .disable = vlv_dpio_cmn_power_well_disable,
2180 .is_enabled = vlv_power_well_enabled,
2181};
2182
2183static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002184 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002185 .enable = vlv_power_well_enable,
2186 .disable = vlv_power_well_disable,
2187 .is_enabled = vlv_power_well_enabled,
2188};
2189
Imre Deakf28ec6f2018-08-06 12:58:37 +03002190static const struct i915_power_well_desc vlv_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002191 {
2192 .name = "always-on",
2193 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002194 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002195 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002196 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002197 },
2198 {
2199 .name = "display",
2200 .domains = VLV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002201 .ops = &vlv_display_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002202 .id = VLV_DISP_PW_DISP2D,
Imre Deakd13dd052018-08-06 12:58:38 +03002203 {
2204 .vlv.idx = PUNIT_PWGT_IDX_DISP2D,
2205 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002206 },
2207 {
2208 .name = "dpio-tx-b-01",
2209 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2210 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2211 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2212 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2213 .ops = &vlv_dpio_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002214 .id = DISP_PW_ID_NONE,
Imre Deakd13dd052018-08-06 12:58:38 +03002215 {
2216 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_B_LANES_01,
2217 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002218 },
2219 {
2220 .name = "dpio-tx-b-23",
2221 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2222 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2223 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2224 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2225 .ops = &vlv_dpio_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002226 .id = DISP_PW_ID_NONE,
Imre Deakd13dd052018-08-06 12:58:38 +03002227 {
2228 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_B_LANES_23,
2229 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002230 },
2231 {
2232 .name = "dpio-tx-c-01",
2233 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2234 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2235 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2236 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2237 .ops = &vlv_dpio_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002238 .id = DISP_PW_ID_NONE,
Imre Deakd13dd052018-08-06 12:58:38 +03002239 {
2240 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_C_LANES_01,
2241 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002242 },
2243 {
2244 .name = "dpio-tx-c-23",
2245 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2246 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2247 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2248 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2249 .ops = &vlv_dpio_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002250 .id = DISP_PW_ID_NONE,
Imre Deakd13dd052018-08-06 12:58:38 +03002251 {
2252 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_C_LANES_23,
2253 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002254 },
2255 {
2256 .name = "dpio-common",
2257 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002258 .ops = &vlv_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002259 .id = VLV_DISP_PW_DPIO_CMN_BC,
Imre Deakd13dd052018-08-06 12:58:38 +03002260 {
2261 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_BC,
2262 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002263 },
2264};
2265
Imre Deakf28ec6f2018-08-06 12:58:37 +03002266static const struct i915_power_well_desc chv_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002267 {
2268 .name = "always-on",
2269 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002270 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002271 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002272 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002273 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002274 {
2275 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002276 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002277 * Pipe A power well is the new disp2d well. Pipe B and C
2278 * power wells don't actually exist. Pipe A power well is
2279 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002280 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002281 .domains = CHV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002282 .ops = &chv_pipe_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002283 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002284 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002285 {
2286 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002287 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002288 .ops = &chv_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002289 .id = VLV_DISP_PW_DPIO_CMN_BC,
Imre Deakd13dd052018-08-06 12:58:38 +03002290 {
2291 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_BC,
2292 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002293 },
2294 {
2295 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002296 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002297 .ops = &chv_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002298 .id = CHV_DISP_PW_DPIO_CMN_D,
Imre Deakd13dd052018-08-06 12:58:38 +03002299 {
2300 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_D,
2301 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002302 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002303};
2304
Suketu Shah5aefb232015-04-16 14:22:10 +05302305bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002306 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302307{
2308 struct i915_power_well *power_well;
2309 bool ret;
2310
2311 power_well = lookup_power_well(dev_priv, power_well_id);
Imre Deakf28ec6f2018-08-06 12:58:37 +03002312 ret = power_well->desc->ops->is_enabled(dev_priv, power_well);
Suketu Shah5aefb232015-04-16 14:22:10 +05302313
2314 return ret;
2315}
2316
Imre Deakf28ec6f2018-08-06 12:58:37 +03002317static const struct i915_power_well_desc skl_power_wells[] = {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002318 {
2319 .name = "always-on",
2320 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002321 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002322 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002323 .id = DISP_PW_ID_NONE,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002324 },
2325 {
2326 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002327 /* Handled by the DMC firmware */
2328 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002329 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002330 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002331 {
Imre Deak75e39682018-08-06 12:58:39 +03002332 .hsw.regs = &hsw_power_well_regs,
2333 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002334 .hsw.has_fuses = true,
2335 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002336 },
2337 {
2338 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002339 /* Handled by the DMC firmware */
2340 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002341 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002342 .id = SKL_DISP_PW_MISC_IO,
Imre Deak75e39682018-08-06 12:58:39 +03002343 {
2344 .hsw.regs = &hsw_power_well_regs,
2345 .hsw.idx = SKL_PW_CTL_IDX_MISC_IO,
2346 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002347 },
2348 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002349 .name = "DC off",
2350 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2351 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002352 .id = DISP_PW_ID_NONE,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002353 },
2354 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002355 .name = "power well 2",
2356 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002357 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002358 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002359 {
Imre Deak75e39682018-08-06 12:58:39 +03002360 .hsw.regs = &hsw_power_well_regs,
2361 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002362 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2363 .hsw.has_vga = true,
2364 .hsw.has_fuses = true,
2365 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002366 },
2367 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002368 .name = "DDI A/E IO power well",
2369 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002370 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002371 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002372 {
2373 .hsw.regs = &hsw_power_well_regs,
2374 .hsw.idx = SKL_PW_CTL_IDX_DDI_A_E,
2375 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002376 },
2377 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002378 .name = "DDI B IO power well",
2379 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002380 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002381 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002382 {
2383 .hsw.regs = &hsw_power_well_regs,
2384 .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
2385 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002386 },
2387 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002388 .name = "DDI C IO power well",
2389 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002390 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002391 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002392 {
2393 .hsw.regs = &hsw_power_well_regs,
2394 .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
2395 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002396 },
2397 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002398 .name = "DDI D IO power well",
2399 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002400 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002401 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002402 {
2403 .hsw.regs = &hsw_power_well_regs,
2404 .hsw.idx = SKL_PW_CTL_IDX_DDI_D,
2405 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002406 },
2407};
2408
Imre Deakf28ec6f2018-08-06 12:58:37 +03002409static const struct i915_power_well_desc bxt_power_wells[] = {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302410 {
2411 .name = "always-on",
2412 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002413 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302414 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002415 .id = DISP_PW_ID_NONE,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302416 },
2417 {
2418 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002419 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002420 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002421 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002422 {
Imre Deak75e39682018-08-06 12:58:39 +03002423 .hsw.regs = &hsw_power_well_regs,
2424 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002425 .hsw.has_fuses = true,
2426 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302427 },
2428 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002429 .name = "DC off",
2430 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2431 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002432 .id = DISP_PW_ID_NONE,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002433 },
2434 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302435 .name = "power well 2",
2436 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002437 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002438 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002439 {
Imre Deak75e39682018-08-06 12:58:39 +03002440 .hsw.regs = &hsw_power_well_regs,
2441 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002442 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2443 .hsw.has_vga = true,
2444 .hsw.has_fuses = true,
2445 },
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002446 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002447 {
2448 .name = "dpio-common-a",
2449 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2450 .ops = &bxt_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002451 .id = BXT_DISP_PW_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002452 {
2453 .bxt.phy = DPIO_PHY1,
2454 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002455 },
2456 {
2457 .name = "dpio-common-bc",
2458 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2459 .ops = &bxt_dpio_cmn_power_well_ops,
Imre Deakd9fcdc82018-08-06 12:58:42 +03002460 .id = VLV_DISP_PW_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002461 {
2462 .bxt.phy = DPIO_PHY0,
2463 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002464 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302465};
2466
Imre Deakf28ec6f2018-08-06 12:58:37 +03002467static const struct i915_power_well_desc glk_power_wells[] = {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002468 {
2469 .name = "always-on",
2470 .always_on = 1,
2471 .domains = POWER_DOMAIN_MASK,
2472 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002473 .id = DISP_PW_ID_NONE,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002474 },
2475 {
2476 .name = "power well 1",
2477 /* Handled by the DMC firmware */
2478 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002479 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002480 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002481 {
Imre Deak75e39682018-08-06 12:58:39 +03002482 .hsw.regs = &hsw_power_well_regs,
2483 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002484 .hsw.has_fuses = true,
2485 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002486 },
2487 {
2488 .name = "DC off",
2489 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2490 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002491 .id = DISP_PW_ID_NONE,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002492 },
2493 {
2494 .name = "power well 2",
2495 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002496 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002497 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002498 {
Imre Deak75e39682018-08-06 12:58:39 +03002499 .hsw.regs = &hsw_power_well_regs,
2500 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002501 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2502 .hsw.has_vga = true,
2503 .hsw.has_fuses = true,
2504 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002505 },
2506 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002507 .name = "dpio-common-a",
2508 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2509 .ops = &bxt_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002510 .id = BXT_DISP_PW_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002511 {
2512 .bxt.phy = DPIO_PHY1,
2513 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002514 },
2515 {
2516 .name = "dpio-common-b",
2517 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2518 .ops = &bxt_dpio_cmn_power_well_ops,
Imre Deakd9fcdc82018-08-06 12:58:42 +03002519 .id = VLV_DISP_PW_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002520 {
2521 .bxt.phy = DPIO_PHY0,
2522 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002523 },
2524 {
2525 .name = "dpio-common-c",
2526 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2527 .ops = &bxt_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002528 .id = GLK_DISP_PW_DPIO_CMN_C,
Imre Deak0a445942017-08-14 18:15:29 +03002529 {
2530 .bxt.phy = DPIO_PHY2,
2531 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002532 },
2533 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002534 .name = "AUX A",
2535 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002536 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002537 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002538 {
2539 .hsw.regs = &hsw_power_well_regs,
2540 .hsw.idx = GLK_PW_CTL_IDX_AUX_A,
2541 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002542 },
2543 {
2544 .name = "AUX B",
2545 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002546 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002547 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002548 {
2549 .hsw.regs = &hsw_power_well_regs,
2550 .hsw.idx = GLK_PW_CTL_IDX_AUX_B,
2551 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002552 },
2553 {
2554 .name = "AUX C",
2555 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002556 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002557 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002558 {
2559 .hsw.regs = &hsw_power_well_regs,
2560 .hsw.idx = GLK_PW_CTL_IDX_AUX_C,
2561 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002562 },
2563 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002564 .name = "DDI A IO power well",
2565 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002566 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002567 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002568 {
2569 .hsw.regs = &hsw_power_well_regs,
2570 .hsw.idx = GLK_PW_CTL_IDX_DDI_A,
2571 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002572 },
2573 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002574 .name = "DDI B IO power well",
2575 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002576 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002577 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002578 {
2579 .hsw.regs = &hsw_power_well_regs,
2580 .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
2581 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002582 },
2583 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002584 .name = "DDI C IO power well",
2585 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002586 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002587 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002588 {
2589 .hsw.regs = &hsw_power_well_regs,
2590 .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
2591 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002592 },
2593};
2594
Imre Deakf28ec6f2018-08-06 12:58:37 +03002595static const struct i915_power_well_desc cnl_power_wells[] = {
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002596 {
2597 .name = "always-on",
2598 .always_on = 1,
2599 .domains = POWER_DOMAIN_MASK,
2600 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002601 .id = DISP_PW_ID_NONE,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002602 },
2603 {
2604 .name = "power well 1",
2605 /* Handled by the DMC firmware */
2606 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002607 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002608 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002609 {
Imre Deak75e39682018-08-06 12:58:39 +03002610 .hsw.regs = &hsw_power_well_regs,
2611 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002612 .hsw.has_fuses = true,
2613 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002614 },
2615 {
2616 .name = "AUX A",
2617 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002618 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002619 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002620 {
2621 .hsw.regs = &hsw_power_well_regs,
2622 .hsw.idx = GLK_PW_CTL_IDX_AUX_A,
2623 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002624 },
2625 {
2626 .name = "AUX B",
2627 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002628 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002629 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002630 {
2631 .hsw.regs = &hsw_power_well_regs,
2632 .hsw.idx = GLK_PW_CTL_IDX_AUX_B,
2633 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002634 },
2635 {
2636 .name = "AUX C",
2637 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002638 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002639 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002640 {
2641 .hsw.regs = &hsw_power_well_regs,
2642 .hsw.idx = GLK_PW_CTL_IDX_AUX_C,
2643 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002644 },
2645 {
2646 .name = "AUX D",
2647 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002648 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002649 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002650 {
2651 .hsw.regs = &hsw_power_well_regs,
2652 .hsw.idx = CNL_PW_CTL_IDX_AUX_D,
2653 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002654 },
2655 {
2656 .name = "DC off",
2657 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2658 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002659 .id = DISP_PW_ID_NONE,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002660 },
2661 {
2662 .name = "power well 2",
2663 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002664 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002665 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002666 {
Imre Deak75e39682018-08-06 12:58:39 +03002667 .hsw.regs = &hsw_power_well_regs,
2668 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002669 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2670 .hsw.has_vga = true,
2671 .hsw.has_fuses = true,
2672 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002673 },
2674 {
2675 .name = "DDI A IO power well",
2676 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002677 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002678 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002679 {
2680 .hsw.regs = &hsw_power_well_regs,
2681 .hsw.idx = GLK_PW_CTL_IDX_DDI_A,
2682 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002683 },
2684 {
2685 .name = "DDI B IO power well",
2686 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002687 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002688 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002689 {
2690 .hsw.regs = &hsw_power_well_regs,
2691 .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
2692 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002693 },
2694 {
2695 .name = "DDI C IO power well",
2696 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002697 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002698 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002699 {
2700 .hsw.regs = &hsw_power_well_regs,
2701 .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
2702 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002703 },
2704 {
2705 .name = "DDI D IO power well",
2706 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002707 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002708 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002709 {
2710 .hsw.regs = &hsw_power_well_regs,
2711 .hsw.idx = SKL_PW_CTL_IDX_DDI_D,
2712 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002713 },
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002714 {
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002715 .name = "DDI F IO power well",
2716 .domains = CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS,
2717 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002718 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002719 {
2720 .hsw.regs = &hsw_power_well_regs,
2721 .hsw.idx = CNL_PW_CTL_IDX_DDI_F,
2722 },
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002723 },
2724 {
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002725 .name = "AUX F",
2726 .domains = CNL_DISPLAY_AUX_F_POWER_DOMAINS,
2727 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002728 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002729 {
2730 .hsw.regs = &hsw_power_well_regs,
2731 .hsw.idx = CNL_PW_CTL_IDX_AUX_F,
2732 },
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002733 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002734};
2735
Imre Deak67ca07e2018-06-26 17:22:32 +03002736static const struct i915_power_well_ops icl_combo_phy_aux_power_well_ops = {
2737 .sync_hw = hsw_power_well_sync_hw,
2738 .enable = icl_combo_phy_aux_power_well_enable,
2739 .disable = icl_combo_phy_aux_power_well_disable,
2740 .is_enabled = hsw_power_well_enabled,
2741};
2742
Imre Deak75e39682018-08-06 12:58:39 +03002743static const struct i915_power_well_regs icl_aux_power_well_regs = {
2744 .bios = ICL_PWR_WELL_CTL_AUX1,
2745 .driver = ICL_PWR_WELL_CTL_AUX2,
2746 .debug = ICL_PWR_WELL_CTL_AUX4,
2747};
2748
2749static const struct i915_power_well_regs icl_ddi_power_well_regs = {
2750 .bios = ICL_PWR_WELL_CTL_DDI1,
2751 .driver = ICL_PWR_WELL_CTL_DDI2,
2752 .debug = ICL_PWR_WELL_CTL_DDI4,
2753};
2754
Imre Deakf28ec6f2018-08-06 12:58:37 +03002755static const struct i915_power_well_desc icl_power_wells[] = {
Imre Deak67ca07e2018-06-26 17:22:32 +03002756 {
2757 .name = "always-on",
2758 .always_on = 1,
2759 .domains = POWER_DOMAIN_MASK,
2760 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002761 .id = DISP_PW_ID_NONE,
Imre Deak67ca07e2018-06-26 17:22:32 +03002762 },
2763 {
2764 .name = "power well 1",
2765 /* Handled by the DMC firmware */
2766 .domains = 0,
2767 .ops = &hsw_power_well_ops,
Imre Deakd9fcdc82018-08-06 12:58:42 +03002768 .id = SKL_DISP_PW_1,
Imre Deakae9b06c2018-08-06 12:58:34 +03002769 {
Imre Deak75e39682018-08-06 12:58:39 +03002770 .hsw.regs = &hsw_power_well_regs,
2771 .hsw.idx = ICL_PW_CTL_IDX_PW_1,
Imre Deakae9b06c2018-08-06 12:58:34 +03002772 .hsw.has_fuses = true,
2773 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002774 },
2775 {
2776 .name = "power well 2",
2777 .domains = ICL_PW_2_POWER_DOMAINS,
2778 .ops = &hsw_power_well_ops,
Imre Deakd9fcdc82018-08-06 12:58:42 +03002779 .id = SKL_DISP_PW_2,
Imre Deakae9b06c2018-08-06 12:58:34 +03002780 {
Imre Deak75e39682018-08-06 12:58:39 +03002781 .hsw.regs = &hsw_power_well_regs,
2782 .hsw.idx = ICL_PW_CTL_IDX_PW_2,
Imre Deakae9b06c2018-08-06 12:58:34 +03002783 .hsw.has_fuses = true,
2784 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002785 },
2786 {
2787 .name = "DC off",
2788 .domains = ICL_DISPLAY_DC_OFF_POWER_DOMAINS,
2789 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002790 .id = DISP_PW_ID_NONE,
Imre Deak67ca07e2018-06-26 17:22:32 +03002791 },
2792 {
2793 .name = "power well 3",
2794 .domains = ICL_PW_3_POWER_DOMAINS,
2795 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002796 .id = DISP_PW_ID_NONE,
Imre Deakae9b06c2018-08-06 12:58:34 +03002797 {
Imre Deak75e39682018-08-06 12:58:39 +03002798 .hsw.regs = &hsw_power_well_regs,
2799 .hsw.idx = ICL_PW_CTL_IDX_PW_3,
Imre Deakae9b06c2018-08-06 12:58:34 +03002800 .hsw.irq_pipe_mask = BIT(PIPE_B),
2801 .hsw.has_vga = true,
2802 .hsw.has_fuses = true,
2803 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002804 },
2805 {
2806 .name = "DDI A IO",
2807 .domains = ICL_DDI_IO_A_POWER_DOMAINS,
2808 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002809 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002810 {
2811 .hsw.regs = &icl_ddi_power_well_regs,
2812 .hsw.idx = ICL_PW_CTL_IDX_DDI_A,
2813 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002814 },
2815 {
2816 .name = "DDI B IO",
2817 .domains = ICL_DDI_IO_B_POWER_DOMAINS,
2818 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002819 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002820 {
2821 .hsw.regs = &icl_ddi_power_well_regs,
2822 .hsw.idx = ICL_PW_CTL_IDX_DDI_B,
2823 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002824 },
2825 {
2826 .name = "DDI C IO",
2827 .domains = ICL_DDI_IO_C_POWER_DOMAINS,
2828 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002829 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002830 {
2831 .hsw.regs = &icl_ddi_power_well_regs,
2832 .hsw.idx = ICL_PW_CTL_IDX_DDI_C,
2833 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002834 },
2835 {
2836 .name = "DDI D IO",
2837 .domains = ICL_DDI_IO_D_POWER_DOMAINS,
2838 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002839 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002840 {
2841 .hsw.regs = &icl_ddi_power_well_regs,
2842 .hsw.idx = ICL_PW_CTL_IDX_DDI_D,
2843 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002844 },
2845 {
2846 .name = "DDI E IO",
2847 .domains = ICL_DDI_IO_E_POWER_DOMAINS,
2848 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002849 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002850 {
2851 .hsw.regs = &icl_ddi_power_well_regs,
2852 .hsw.idx = ICL_PW_CTL_IDX_DDI_E,
2853 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002854 },
2855 {
2856 .name = "DDI F IO",
2857 .domains = ICL_DDI_IO_F_POWER_DOMAINS,
2858 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002859 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002860 {
2861 .hsw.regs = &icl_ddi_power_well_regs,
2862 .hsw.idx = ICL_PW_CTL_IDX_DDI_F,
2863 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002864 },
2865 {
2866 .name = "AUX A",
2867 .domains = ICL_AUX_A_IO_POWER_DOMAINS,
2868 .ops = &icl_combo_phy_aux_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002869 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002870 {
2871 .hsw.regs = &icl_aux_power_well_regs,
2872 .hsw.idx = ICL_PW_CTL_IDX_AUX_A,
2873 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002874 },
2875 {
2876 .name = "AUX B",
2877 .domains = ICL_AUX_B_IO_POWER_DOMAINS,
2878 .ops = &icl_combo_phy_aux_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002879 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002880 {
2881 .hsw.regs = &icl_aux_power_well_regs,
2882 .hsw.idx = ICL_PW_CTL_IDX_AUX_B,
2883 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002884 },
2885 {
2886 .name = "AUX C",
2887 .domains = ICL_AUX_C_IO_POWER_DOMAINS,
2888 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002889 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002890 {
2891 .hsw.regs = &icl_aux_power_well_regs,
2892 .hsw.idx = ICL_PW_CTL_IDX_AUX_C,
2893 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002894 },
2895 {
2896 .name = "AUX D",
2897 .domains = ICL_AUX_D_IO_POWER_DOMAINS,
2898 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002899 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002900 {
2901 .hsw.regs = &icl_aux_power_well_regs,
2902 .hsw.idx = ICL_PW_CTL_IDX_AUX_D,
2903 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002904 },
2905 {
2906 .name = "AUX E",
2907 .domains = ICL_AUX_E_IO_POWER_DOMAINS,
2908 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002909 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002910 {
2911 .hsw.regs = &icl_aux_power_well_regs,
2912 .hsw.idx = ICL_PW_CTL_IDX_AUX_E,
2913 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002914 },
2915 {
2916 .name = "AUX F",
2917 .domains = ICL_AUX_F_IO_POWER_DOMAINS,
2918 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002919 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002920 {
2921 .hsw.regs = &icl_aux_power_well_regs,
2922 .hsw.idx = ICL_PW_CTL_IDX_AUX_F,
2923 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002924 },
2925 {
2926 .name = "AUX TBT1",
2927 .domains = ICL_AUX_TBT1_IO_POWER_DOMAINS,
2928 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002929 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002930 {
2931 .hsw.regs = &icl_aux_power_well_regs,
2932 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT1,
2933 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002934 },
2935 {
2936 .name = "AUX TBT2",
2937 .domains = ICL_AUX_TBT2_IO_POWER_DOMAINS,
2938 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002939 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002940 {
2941 .hsw.regs = &icl_aux_power_well_regs,
2942 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT2,
2943 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002944 },
2945 {
2946 .name = "AUX TBT3",
2947 .domains = ICL_AUX_TBT3_IO_POWER_DOMAINS,
2948 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002949 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002950 {
2951 .hsw.regs = &icl_aux_power_well_regs,
2952 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT3,
2953 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002954 },
2955 {
2956 .name = "AUX TBT4",
2957 .domains = ICL_AUX_TBT4_IO_POWER_DOMAINS,
2958 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002959 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002960 {
2961 .hsw.regs = &icl_aux_power_well_regs,
2962 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT4,
2963 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002964 },
2965 {
2966 .name = "power well 4",
2967 .domains = ICL_PW_4_POWER_DOMAINS,
2968 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002969 .id = DISP_PW_ID_NONE,
Imre Deakae9b06c2018-08-06 12:58:34 +03002970 {
Imre Deak75e39682018-08-06 12:58:39 +03002971 .hsw.regs = &hsw_power_well_regs,
2972 .hsw.idx = ICL_PW_CTL_IDX_PW_4,
Imre Deakae9b06c2018-08-06 12:58:34 +03002973 .hsw.has_fuses = true,
2974 .hsw.irq_pipe_mask = BIT(PIPE_C),
2975 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002976 },
2977};
2978
Imre Deak1b0e3a02015-11-05 23:04:11 +02002979static int
2980sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2981 int disable_power_well)
2982{
2983 if (disable_power_well >= 0)
2984 return !!disable_power_well;
2985
Imre Deak1b0e3a02015-11-05 23:04:11 +02002986 return 1;
2987}
2988
Imre Deaka37baf32016-02-29 22:49:03 +02002989static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2990 int enable_dc)
2991{
2992 uint32_t mask;
2993 int requested_dc;
2994 int max_dc;
2995
Imre Deak67ca07e2018-06-26 17:22:32 +03002996 if (IS_GEN9_BC(dev_priv) || INTEL_INFO(dev_priv)->gen >= 10) {
Imre Deaka37baf32016-02-29 22:49:03 +02002997 max_dc = 2;
2998 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002999 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02003000 max_dc = 1;
3001 /*
3002 * DC9 has a separate HW flow from the rest of the DC states,
3003 * not depending on the DMC firmware. It's needed by system
3004 * suspend/resume, so allow it unconditionally.
3005 */
3006 mask = DC_STATE_EN_DC9;
3007 } else {
3008 max_dc = 0;
3009 mask = 0;
3010 }
3011
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003012 if (!i915_modparams.disable_power_well)
Imre Deak66e2c4c2016-02-29 22:49:04 +02003013 max_dc = 0;
3014
Imre Deaka37baf32016-02-29 22:49:03 +02003015 if (enable_dc >= 0 && enable_dc <= max_dc) {
3016 requested_dc = enable_dc;
3017 } else if (enable_dc == -1) {
3018 requested_dc = max_dc;
3019 } else if (enable_dc > max_dc && enable_dc <= 2) {
3020 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
3021 enable_dc, max_dc);
3022 requested_dc = max_dc;
3023 } else {
3024 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
3025 requested_dc = max_dc;
3026 }
3027
3028 if (requested_dc > 1)
3029 mask |= DC_STATE_EN_UPTO_DC6;
3030 if (requested_dc > 0)
3031 mask |= DC_STATE_EN_UPTO_DC5;
3032
3033 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
3034
3035 return mask;
3036}
3037
Imre Deakf28ec6f2018-08-06 12:58:37 +03003038static int
3039__set_power_wells(struct i915_power_domains *power_domains,
3040 const struct i915_power_well_desc *power_well_descs,
3041 int power_well_count)
Imre Deak21792c62017-07-11 23:42:33 +03003042{
Imre Deakf28ec6f2018-08-06 12:58:37 +03003043 u64 power_well_ids = 0;
Imre Deak21792c62017-07-11 23:42:33 +03003044 int i;
3045
Imre Deakf28ec6f2018-08-06 12:58:37 +03003046 power_domains->power_well_count = power_well_count;
3047 power_domains->power_wells =
3048 kcalloc(power_well_count,
3049 sizeof(*power_domains->power_wells),
3050 GFP_KERNEL);
3051 if (!power_domains->power_wells)
3052 return -ENOMEM;
3053
3054 for (i = 0; i < power_well_count; i++) {
3055 enum i915_power_well_id id = power_well_descs[i].id;
3056
3057 power_domains->power_wells[i].desc = &power_well_descs[i];
Imre Deak21792c62017-07-11 23:42:33 +03003058
Imre Deak4739a9d2018-08-06 12:58:40 +03003059 if (id == DISP_PW_ID_NONE)
3060 continue;
3061
Imre Deak21792c62017-07-11 23:42:33 +03003062 WARN_ON(id >= sizeof(power_well_ids) * 8);
3063 WARN_ON(power_well_ids & BIT_ULL(id));
3064 power_well_ids |= BIT_ULL(id);
3065 }
Imre Deakf28ec6f2018-08-06 12:58:37 +03003066
3067 return 0;
Imre Deak21792c62017-07-11 23:42:33 +03003068}
3069
Imre Deakf28ec6f2018-08-06 12:58:37 +03003070#define set_power_wells(power_domains, __power_well_descs) \
3071 __set_power_wells(power_domains, __power_well_descs, \
3072 ARRAY_SIZE(__power_well_descs))
Daniel Vetter9c065a72014-09-30 10:56:38 +02003073
Daniel Vettere4e76842014-09-30 10:56:42 +02003074/**
3075 * intel_power_domains_init - initializes the power domain structures
3076 * @dev_priv: i915 device instance
3077 *
3078 * Initializes the power domain structures for @dev_priv depending upon the
3079 * supported platform.
3080 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003081int intel_power_domains_init(struct drm_i915_private *dev_priv)
3082{
3083 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deakf28ec6f2018-08-06 12:58:37 +03003084 int err;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003085
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003086 i915_modparams.disable_power_well =
3087 sanitize_disable_power_well_option(dev_priv,
3088 i915_modparams.disable_power_well);
3089 dev_priv->csr.allowed_dc_mask =
3090 get_allowed_dc_mask(dev_priv, i915_modparams.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02003091
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02003092 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01003093
Daniel Vetter9c065a72014-09-30 10:56:38 +02003094 mutex_init(&power_domains->lock);
3095
3096 /*
3097 * The enabling order will be from lower to higher indexed wells,
3098 * the disabling order is reversed.
3099 */
Imre Deak67ca07e2018-06-26 17:22:32 +03003100 if (IS_ICELAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003101 err = set_power_wells(power_domains, icl_power_wells);
Imre Deak67ca07e2018-06-26 17:22:32 +03003102 } else if (IS_HASWELL(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003103 err = set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003104 } else if (IS_BROADWELL(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003105 err = set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08003106 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003107 err = set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07003108 } else if (IS_CANNONLAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003109 err = set_power_wells(power_domains, cnl_power_wells);
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003110
3111 /*
Rodrigo Vivi9787e832018-01-29 15:22:22 -08003112 * DDI and Aux IO are getting enabled for all ports
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003113 * regardless the presence or use. So, in order to avoid
Rodrigo Vivi9787e832018-01-29 15:22:22 -08003114 * timeouts, lets remove them from the list
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003115 * for the SKUs without port F.
3116 */
3117 if (!IS_CNL_WITH_PORT_F(dev_priv))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08003118 power_domains->power_well_count -= 2;
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003119
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003120 } else if (IS_BROXTON(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003121 err = set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02003122 } else if (IS_GEMINILAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003123 err = set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003124 } else if (IS_CHERRYVIEW(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003125 err = set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003126 } else if (IS_VALLEYVIEW(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003127 err = set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03003128 } else if (IS_I830(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003129 err = set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003130 } else {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003131 err = set_power_wells(power_domains, i9xx_always_on_power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003132 }
3133
Imre Deakf28ec6f2018-08-06 12:58:37 +03003134 return err;
3135}
Imre Deak21792c62017-07-11 23:42:33 +03003136
Imre Deakf28ec6f2018-08-06 12:58:37 +03003137/**
3138 * intel_power_domains_cleanup - clean up power domains resources
3139 * @dev_priv: i915 device instance
3140 *
3141 * Release any resources acquired by intel_power_domains_init()
3142 */
3143void intel_power_domains_cleanup(struct drm_i915_private *dev_priv)
3144{
3145 kfree(dev_priv->power_domains.power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003146}
3147
Imre Deak30eade12015-11-04 19:24:13 +02003148static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003149{
3150 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3151 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003152
3153 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02003154 for_each_power_well(dev_priv, power_well) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003155 power_well->desc->ops->sync_hw(dev_priv, power_well);
3156 power_well->hw_enabled =
3157 power_well->desc->ops->is_enabled(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003158 }
3159 mutex_unlock(&power_domains->lock);
3160}
3161
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303162static inline
3163bool intel_dbuf_slice_set(struct drm_i915_private *dev_priv,
3164 i915_reg_t reg, bool enable)
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003165{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303166 u32 val, status;
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003167
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303168 val = I915_READ(reg);
3169 val = enable ? (val | DBUF_POWER_REQUEST) : (val & ~DBUF_POWER_REQUEST);
3170 I915_WRITE(reg, val);
3171 POSTING_READ(reg);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003172 udelay(10);
3173
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303174 status = I915_READ(reg) & DBUF_POWER_STATE;
3175 if ((enable && !status) || (!enable && status)) {
3176 DRM_ERROR("DBus power %s timeout!\n",
3177 enable ? "enable" : "disable");
3178 return false;
3179 }
3180 return true;
3181}
3182
3183static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
3184{
3185 intel_dbuf_slice_set(dev_priv, DBUF_CTL, true);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003186}
3187
3188static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
3189{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303190 intel_dbuf_slice_set(dev_priv, DBUF_CTL, false);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003191}
3192
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303193static u8 intel_dbuf_max_slices(struct drm_i915_private *dev_priv)
3194{
3195 if (INTEL_GEN(dev_priv) < 11)
3196 return 1;
3197 return 2;
3198}
3199
3200void icl_dbuf_slices_update(struct drm_i915_private *dev_priv,
3201 u8 req_slices)
3202{
3203 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
3204 u32 val;
3205 bool ret;
3206
3207 if (req_slices > intel_dbuf_max_slices(dev_priv)) {
3208 DRM_ERROR("Invalid number of dbuf slices requested\n");
3209 return;
3210 }
3211
3212 if (req_slices == hw_enabled_slices || req_slices == 0)
3213 return;
3214
3215 val = I915_READ(DBUF_CTL_S2);
3216 if (req_slices > hw_enabled_slices)
3217 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, true);
3218 else
3219 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, false);
3220
3221 if (ret)
3222 dev_priv->wm.skl_hw.ddb.enabled_slices = req_slices;
3223}
3224
Mahesh Kumar746edf82018-02-05 13:40:44 -02003225static void icl_dbuf_enable(struct drm_i915_private *dev_priv)
3226{
3227 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) | DBUF_POWER_REQUEST);
3228 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) | DBUF_POWER_REQUEST);
3229 POSTING_READ(DBUF_CTL_S2);
3230
3231 udelay(10);
3232
3233 if (!(I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
3234 !(I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
3235 DRM_ERROR("DBuf power enable timeout\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303236 else
3237 dev_priv->wm.skl_hw.ddb.enabled_slices = 2;
Mahesh Kumar746edf82018-02-05 13:40:44 -02003238}
3239
3240static void icl_dbuf_disable(struct drm_i915_private *dev_priv)
3241{
3242 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) & ~DBUF_POWER_REQUEST);
3243 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) & ~DBUF_POWER_REQUEST);
3244 POSTING_READ(DBUF_CTL_S2);
3245
3246 udelay(10);
3247
3248 if ((I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
3249 (I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
3250 DRM_ERROR("DBuf power disable timeout!\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303251 else
3252 dev_priv->wm.skl_hw.ddb.enabled_slices = 0;
Mahesh Kumar746edf82018-02-05 13:40:44 -02003253}
3254
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003255static void icl_mbus_init(struct drm_i915_private *dev_priv)
3256{
3257 uint32_t val;
3258
3259 val = MBUS_ABOX_BT_CREDIT_POOL1(16) |
3260 MBUS_ABOX_BT_CREDIT_POOL2(16) |
3261 MBUS_ABOX_B_CREDIT(1) |
3262 MBUS_ABOX_BW_CREDIT(1);
3263
3264 I915_WRITE(MBUS_ABOX_CTL, val);
3265}
3266
Imre Deak73dfc222015-11-17 17:33:53 +02003267static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03003268 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02003269{
3270 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003271 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003272 uint32_t val;
3273
Imre Deakd26fa1d2015-11-04 19:24:17 +02003274 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3275
Imre Deak73dfc222015-11-17 17:33:53 +02003276 /* enable PCH reset handshake */
3277 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3278 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
3279
3280 /* enable PG1 and Misc I/O */
3281 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003282
3283 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3284 intel_power_well_enable(dev_priv, well);
3285
3286 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
3287 intel_power_well_enable(dev_priv, well);
3288
Imre Deak73dfc222015-11-17 17:33:53 +02003289 mutex_unlock(&power_domains->lock);
3290
Imre Deak73dfc222015-11-17 17:33:53 +02003291 skl_init_cdclk(dev_priv);
3292
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003293 gen9_dbuf_enable(dev_priv);
3294
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03003295 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02003296 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003297}
3298
3299static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
3300{
3301 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003302 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003303
Imre Deakd26fa1d2015-11-04 19:24:17 +02003304 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3305
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003306 gen9_dbuf_disable(dev_priv);
3307
Imre Deak73dfc222015-11-17 17:33:53 +02003308 skl_uninit_cdclk(dev_priv);
3309
3310 /* The spec doesn't call for removing the reset handshake flag */
3311 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03003312
Imre Deak73dfc222015-11-17 17:33:53 +02003313 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003314
Imre Deakedfda8e2017-06-29 18:36:59 +03003315 /*
3316 * BSpec says to keep the MISC IO power well enabled here, only
3317 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03003318 * Note that even though the driver's request is removed power well 1
3319 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03003320 */
Imre Deak443a93a2016-04-04 15:42:57 +03003321 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3322 intel_power_well_disable(dev_priv, well);
3323
Imre Deak73dfc222015-11-17 17:33:53 +02003324 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003325
3326 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02003327}
3328
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003329void bxt_display_core_init(struct drm_i915_private *dev_priv,
3330 bool resume)
3331{
3332 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3333 struct i915_power_well *well;
3334 uint32_t val;
3335
3336 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3337
3338 /*
3339 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
3340 * or else the reset will hang because there is no PCH to respond.
3341 * Move the handshake programming to initialization sequence.
3342 * Previously was left up to BIOS.
3343 */
3344 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3345 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
3346 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3347
3348 /* Enable PG1 */
3349 mutex_lock(&power_domains->lock);
3350
3351 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3352 intel_power_well_enable(dev_priv, well);
3353
3354 mutex_unlock(&power_domains->lock);
3355
Imre Deak324513c2016-06-13 16:44:36 +03003356 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003357
3358 gen9_dbuf_enable(dev_priv);
3359
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003360 if (resume && dev_priv->csr.dmc_payload)
3361 intel_csr_load_program(dev_priv);
3362}
3363
3364void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
3365{
3366 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3367 struct i915_power_well *well;
3368
3369 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3370
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003371 gen9_dbuf_disable(dev_priv);
3372
Imre Deak324513c2016-06-13 16:44:36 +03003373 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003374
3375 /* The spec doesn't call for removing the reset handshake flag */
3376
Imre Deak42d93662017-06-29 18:37:01 +03003377 /*
3378 * Disable PW1 (PG1).
3379 * Note that even though the driver's request is removed power well 1
3380 * may stay enabled after this due to DMC's own request on it.
3381 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003382 mutex_lock(&power_domains->lock);
3383
3384 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3385 intel_power_well_disable(dev_priv, well);
3386
3387 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003388
3389 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003390}
3391
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003392enum {
3393 PROCMON_0_85V_DOT_0,
3394 PROCMON_0_95V_DOT_0,
3395 PROCMON_0_95V_DOT_1,
3396 PROCMON_1_05V_DOT_0,
3397 PROCMON_1_05V_DOT_1,
3398};
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003399
3400static const struct cnl_procmon {
3401 u32 dw1, dw9, dw10;
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003402} cnl_procmon_values[] = {
3403 [PROCMON_0_85V_DOT_0] =
3404 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
3405 [PROCMON_0_95V_DOT_0] =
3406 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
3407 [PROCMON_0_95V_DOT_1] =
3408 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
3409 [PROCMON_1_05V_DOT_0] =
3410 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
3411 [PROCMON_1_05V_DOT_1] =
3412 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003413};
3414
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003415/*
3416 * CNL has just one set of registers, while ICL has two sets: one for port A and
3417 * the other for port B. The CNL registers are equivalent to the ICL port A
3418 * registers, that's why we call the ICL macros even though the function has CNL
3419 * on its name.
3420 */
3421static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
3422 enum port port)
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003423{
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003424 const struct cnl_procmon *procmon;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003425 u32 val;
3426
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003427 val = I915_READ(ICL_PORT_COMP_DW3(port));
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003428 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
3429 default:
3430 MISSING_CASE(val);
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05003431 /* fall through */
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003432 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
3433 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
3434 break;
3435 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
3436 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
3437 break;
3438 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
3439 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
3440 break;
3441 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
3442 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
3443 break;
3444 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
3445 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
3446 break;
3447 }
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003448
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003449 val = I915_READ(ICL_PORT_COMP_DW1(port));
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003450 val &= ~((0xff << 16) | 0xff);
3451 val |= procmon->dw1;
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003452 I915_WRITE(ICL_PORT_COMP_DW1(port), val);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003453
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003454 I915_WRITE(ICL_PORT_COMP_DW9(port), procmon->dw9);
3455 I915_WRITE(ICL_PORT_COMP_DW10(port), procmon->dw10);
Paulo Zanoniade5ee72017-08-21 17:03:56 -07003456}
3457
3458static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
3459{
3460 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3461 struct i915_power_well *well;
3462 u32 val;
3463
3464 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3465
3466 /* 1. Enable PCH Reset Handshake */
3467 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3468 val |= RESET_PCH_HANDSHAKE_ENABLE;
3469 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3470
3471 /* 2. Enable Comp */
3472 val = I915_READ(CHICKEN_MISC_2);
3473 val &= ~CNL_COMP_PWR_DOWN;
3474 I915_WRITE(CHICKEN_MISC_2, val);
3475
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003476 /* Dummy PORT_A to get the correct CNL register from the ICL macro */
3477 cnl_set_procmon_ref_values(dev_priv, PORT_A);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003478
3479 val = I915_READ(CNL_PORT_COMP_DW0);
3480 val |= COMP_INIT;
3481 I915_WRITE(CNL_PORT_COMP_DW0, val);
3482
3483 /* 3. */
3484 val = I915_READ(CNL_PORT_CL1CM_DW5);
3485 val |= CL_POWER_DOWN_ENABLE;
3486 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
3487
Imre Deakb38131f2017-06-29 18:37:02 +03003488 /*
3489 * 4. Enable Power Well 1 (PG1).
3490 * The AUX IO power wells will be enabled on demand.
3491 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003492 mutex_lock(&power_domains->lock);
3493 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3494 intel_power_well_enable(dev_priv, well);
3495 mutex_unlock(&power_domains->lock);
3496
3497 /* 5. Enable CD clock */
3498 cnl_init_cdclk(dev_priv);
3499
3500 /* 6. Enable DBUF */
3501 gen9_dbuf_enable(dev_priv);
Imre Deak57522c42017-10-03 12:51:58 +03003502
3503 if (resume && dev_priv->csr.dmc_payload)
3504 intel_csr_load_program(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003505}
3506
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003507static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
3508{
3509 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3510 struct i915_power_well *well;
3511 u32 val;
3512
3513 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3514
3515 /* 1. Disable all display engine functions -> aready done */
3516
3517 /* 2. Disable DBUF */
3518 gen9_dbuf_disable(dev_priv);
3519
3520 /* 3. Disable CD clock */
3521 cnl_uninit_cdclk(dev_priv);
3522
Imre Deakb38131f2017-06-29 18:37:02 +03003523 /*
3524 * 4. Disable Power Well 1 (PG1).
3525 * The AUX IO power wells are toggled on demand, so they are already
3526 * disabled at this point.
3527 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003528 mutex_lock(&power_domains->lock);
3529 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3530 intel_power_well_disable(dev_priv, well);
3531 mutex_unlock(&power_domains->lock);
3532
Imre Deak846c6b22017-06-29 18:36:58 +03003533 usleep_range(10, 30); /* 10 us delay per Bspec */
3534
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003535 /* 5. Disable Comp */
3536 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03003537 val |= CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003538 I915_WRITE(CHICKEN_MISC_2, val);
3539}
3540
Paulo Zanoniad186f32018-02-05 13:40:43 -02003541static void icl_display_core_init(struct drm_i915_private *dev_priv,
3542 bool resume)
3543{
Imre Deak67ca07e2018-06-26 17:22:32 +03003544 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3545 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003546 enum port port;
3547 u32 val;
3548
3549 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3550
3551 /* 1. Enable PCH reset handshake. */
3552 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3553 val |= RESET_PCH_HANDSHAKE_ENABLE;
3554 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3555
3556 for (port = PORT_A; port <= PORT_B; port++) {
3557 /* 2. Enable DDI combo PHY comp. */
3558 val = I915_READ(ICL_PHY_MISC(port));
3559 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3560 I915_WRITE(ICL_PHY_MISC(port), val);
3561
3562 cnl_set_procmon_ref_values(dev_priv, port);
3563
3564 val = I915_READ(ICL_PORT_COMP_DW0(port));
3565 val |= COMP_INIT;
3566 I915_WRITE(ICL_PORT_COMP_DW0(port), val);
3567
3568 /* 3. Set power down enable. */
3569 val = I915_READ(ICL_PORT_CL_DW5(port));
3570 val |= CL_POWER_DOWN_ENABLE;
3571 I915_WRITE(ICL_PORT_CL_DW5(port), val);
3572 }
3573
Imre Deak67ca07e2018-06-26 17:22:32 +03003574 /*
3575 * 4. Enable Power Well 1 (PG1).
3576 * The AUX IO power wells will be enabled on demand.
3577 */
3578 mutex_lock(&power_domains->lock);
Imre Deakd9fcdc82018-08-06 12:58:42 +03003579 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
Imre Deak67ca07e2018-06-26 17:22:32 +03003580 intel_power_well_enable(dev_priv, well);
3581 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003582
3583 /* 5. Enable CDCLK. */
3584 icl_init_cdclk(dev_priv);
3585
3586 /* 6. Enable DBUF. */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003587 icl_dbuf_enable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003588
3589 /* 7. Setup MBUS. */
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003590 icl_mbus_init(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003591}
3592
3593static void icl_display_core_uninit(struct drm_i915_private *dev_priv)
3594{
Imre Deak67ca07e2018-06-26 17:22:32 +03003595 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3596 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003597 enum port port;
3598 u32 val;
3599
3600 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3601
3602 /* 1. Disable all display engine functions -> aready done */
3603
3604 /* 2. Disable DBUF */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003605 icl_dbuf_disable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003606
3607 /* 3. Disable CD clock */
3608 icl_uninit_cdclk(dev_priv);
3609
Imre Deak67ca07e2018-06-26 17:22:32 +03003610 /*
3611 * 4. Disable Power Well 1 (PG1).
3612 * The AUX IO power wells are toggled on demand, so they are already
3613 * disabled at this point.
3614 */
3615 mutex_lock(&power_domains->lock);
Imre Deakd9fcdc82018-08-06 12:58:42 +03003616 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
Imre Deak67ca07e2018-06-26 17:22:32 +03003617 intel_power_well_disable(dev_priv, well);
3618 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003619
3620 /* 5. Disable Comp */
3621 for (port = PORT_A; port <= PORT_B; port++) {
3622 val = I915_READ(ICL_PHY_MISC(port));
3623 val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3624 I915_WRITE(ICL_PHY_MISC(port), val);
3625 }
3626}
3627
Ville Syrjälä70722462015-04-10 18:21:28 +03003628static void chv_phy_control_init(struct drm_i915_private *dev_priv)
3629{
3630 struct i915_power_well *cmn_bc =
Imre Deak2183b492018-08-06 12:58:41 +03003631 lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
Ville Syrjälä70722462015-04-10 18:21:28 +03003632 struct i915_power_well *cmn_d =
Imre Deak2183b492018-08-06 12:58:41 +03003633 lookup_power_well(dev_priv, CHV_DISP_PW_DPIO_CMN_D);
Ville Syrjälä70722462015-04-10 18:21:28 +03003634
3635 /*
3636 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
3637 * workaround never ever read DISPLAY_PHY_CONTROL, and
3638 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003639 * power well state and lane status to reconstruct the
3640 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03003641 */
3642 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03003643 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
3644 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003645 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
3646 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
3647 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
3648
3649 /*
3650 * If all lanes are disabled we leave the override disabled
3651 * with all power down bits cleared to match the state we
3652 * would use after disabling the port. Otherwise enable the
3653 * override and set the lane powerdown bits accding to the
3654 * current lane status.
3655 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003656 if (cmn_bc->desc->ops->is_enabled(dev_priv, cmn_bc)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003657 uint32_t status = I915_READ(DPLL(PIPE_A));
3658 unsigned int mask;
3659
3660 mask = status & DPLL_PORTB_READY_MASK;
3661 if (mask == 0xf)
3662 mask = 0x0;
3663 else
3664 dev_priv->chv_phy_control |=
3665 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
3666
3667 dev_priv->chv_phy_control |=
3668 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
3669
3670 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
3671 if (mask == 0xf)
3672 mask = 0x0;
3673 else
3674 dev_priv->chv_phy_control |=
3675 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
3676
3677 dev_priv->chv_phy_control |=
3678 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
3679
Ville Syrjälä70722462015-04-10 18:21:28 +03003680 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003681
3682 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
3683 } else {
3684 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003685 }
3686
Imre Deakf28ec6f2018-08-06 12:58:37 +03003687 if (cmn_d->desc->ops->is_enabled(dev_priv, cmn_d)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003688 uint32_t status = I915_READ(DPIO_PHY_STATUS);
3689 unsigned int mask;
3690
3691 mask = status & DPLL_PORTD_READY_MASK;
3692
3693 if (mask == 0xf)
3694 mask = 0x0;
3695 else
3696 dev_priv->chv_phy_control |=
3697 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
3698
3699 dev_priv->chv_phy_control |=
3700 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
3701
Ville Syrjälä70722462015-04-10 18:21:28 +03003702 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003703
3704 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
3705 } else {
3706 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003707 }
3708
3709 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
3710
3711 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
3712 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03003713}
3714
Daniel Vetter9c065a72014-09-30 10:56:38 +02003715static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
3716{
3717 struct i915_power_well *cmn =
Imre Deak2183b492018-08-06 12:58:41 +03003718 lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003719 struct i915_power_well *disp2d =
Imre Deak2183b492018-08-06 12:58:41 +03003720 lookup_power_well(dev_priv, VLV_DISP_PW_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003721
Daniel Vetter9c065a72014-09-30 10:56:38 +02003722 /* If the display might be already active skip this */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003723 if (cmn->desc->ops->is_enabled(dev_priv, cmn) &&
3724 disp2d->desc->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003725 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3726 return;
3727
3728 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3729
3730 /* cmnlane needs DPLL registers */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003731 disp2d->desc->ops->enable(dev_priv, disp2d);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003732
3733 /*
3734 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3735 * Need to assert and de-assert PHY SB reset by gating the
3736 * common lane power, then un-gating it.
3737 * Simply ungating isn't enough to reset the PHY enough to get
3738 * ports and lanes running.
3739 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003740 cmn->desc->ops->disable(dev_priv, cmn);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003741}
3742
Daniel Vettere4e76842014-09-30 10:56:42 +02003743/**
3744 * intel_power_domains_init_hw - initialize hardware power domain state
3745 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003746 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003747 *
3748 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003749 * power wells belonging to the INIT power domain. Power wells in other
3750 * domains (and not in the INIT domain) are referenced or disabled during the
3751 * modeset state HW readout. After that the reference count of each power well
3752 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003753 */
Imre Deak73dfc222015-11-17 17:33:53 +02003754void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003755{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003756 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3757
3758 power_domains->initializing = true;
3759
Paulo Zanoniad186f32018-02-05 13:40:43 -02003760 if (IS_ICELAKE(dev_priv)) {
3761 icl_display_core_init(dev_priv, resume);
3762 } else if (IS_CANNONLAKE(dev_priv)) {
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003763 cnl_display_core_init(dev_priv, resume);
3764 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003765 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003766 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003767 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003768 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003769 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003770 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003771 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003772 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003773 mutex_lock(&power_domains->lock);
3774 vlv_cmnlane_wa(dev_priv);
3775 mutex_unlock(&power_domains->lock);
3776 }
3777
3778 /* For now, we need the power well to be always enabled. */
3779 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003780 /* Disable power support if the user asked so. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003781 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003782 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003783 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003784 power_domains->initializing = false;
3785}
3786
Daniel Vettere4e76842014-09-30 10:56:42 +02003787/**
Imre Deak48a287e2018-08-06 12:58:35 +03003788 * intel_power_domains_fini_hw - deinitialize hw power domain state
3789 * @dev_priv: i915 device instance
3790 *
3791 * De-initializes the display power domain HW state. It also ensures that the
3792 * device stays powered up so that the driver can be reloaded.
3793 */
3794void intel_power_domains_fini_hw(struct drm_i915_private *dev_priv)
3795{
Imre Deak48a287e2018-08-06 12:58:35 +03003796 /*
3797 * The i915.ko module is still not prepared to be loaded when
3798 * the power well is not enabled, so just enable it in case
3799 * we're going to unload/reload.
Imre Deak48a287e2018-08-06 12:58:35 +03003800 */
Chris Wilson07d80572018-08-16 15:37:56 +03003801 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
3802
3803 /* Keep the power well enabled, but cancel its rpm wakeref. */
3804 intel_runtime_pm_put(dev_priv);
Imre Deak48a287e2018-08-06 12:58:35 +03003805
3806 /* Remove the refcount we took to keep power well support disabled. */
3807 if (!i915_modparams.disable_power_well)
3808 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak48a287e2018-08-06 12:58:35 +03003809}
3810
3811/**
Imre Deak73dfc222015-11-17 17:33:53 +02003812 * intel_power_domains_suspend - suspend power domain state
3813 * @dev_priv: i915 device instance
3814 *
3815 * This function prepares the hardware power domain state before entering
3816 * system suspend. It must be paired with intel_power_domains_init_hw().
3817 */
3818void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3819{
Imre Deakd314cd42015-11-17 17:44:23 +02003820 /*
3821 * Even if power well support was disabled we still want to disable
3822 * power wells while we are system suspended.
3823 */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003824 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003825 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003826
Paulo Zanoniad186f32018-02-05 13:40:43 -02003827 if (IS_ICELAKE(dev_priv))
3828 icl_display_core_uninit(dev_priv);
3829 else if (IS_CANNONLAKE(dev_priv))
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003830 cnl_display_core_uninit(dev_priv);
3831 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003832 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003833 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003834 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003835}
3836
Imre Deak8d8c3862017-02-17 17:39:46 +02003837static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3838{
3839 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3840 struct i915_power_well *power_well;
3841
3842 for_each_power_well(dev_priv, power_well) {
3843 enum intel_display_power_domain domain;
3844
3845 DRM_DEBUG_DRIVER("%-25s %d\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003846 power_well->desc->name, power_well->count);
Imre Deak8d8c3862017-02-17 17:39:46 +02003847
Imre Deakf28ec6f2018-08-06 12:58:37 +03003848 for_each_power_domain(domain, power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003849 DRM_DEBUG_DRIVER(" %-23s %d\n",
3850 intel_display_power_domain_str(domain),
3851 power_domains->domain_use_count[domain]);
3852 }
3853}
3854
3855/**
3856 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3857 * @dev_priv: i915 device instance
3858 *
3859 * Verify if the reference count of each power well matches its HW enabled
3860 * state and the total refcount of the domains it belongs to. This must be
3861 * called after modeset HW state sanitization, which is responsible for
3862 * acquiring reference counts for any power wells in use and disabling the
3863 * ones left on by BIOS but not required by any active output.
3864 */
3865void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3866{
3867 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3868 struct i915_power_well *power_well;
3869 bool dump_domain_info;
3870
3871 mutex_lock(&power_domains->lock);
3872
3873 dump_domain_info = false;
3874 for_each_power_well(dev_priv, power_well) {
3875 enum intel_display_power_domain domain;
3876 int domains_count;
3877 bool enabled;
3878
3879 /*
3880 * Power wells not belonging to any domain (like the MISC_IO
3881 * and PW1 power wells) are under FW control, so ignore them,
3882 * since their state can change asynchronously.
3883 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003884 if (!power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003885 continue;
3886
Imre Deakf28ec6f2018-08-06 12:58:37 +03003887 enabled = power_well->desc->ops->is_enabled(dev_priv,
3888 power_well);
3889 if ((power_well->count || power_well->desc->always_on) !=
3890 enabled)
Imre Deak8d8c3862017-02-17 17:39:46 +02003891 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003892 power_well->desc->name,
3893 power_well->count, enabled);
Imre Deak8d8c3862017-02-17 17:39:46 +02003894
3895 domains_count = 0;
Imre Deakf28ec6f2018-08-06 12:58:37 +03003896 for_each_power_domain(domain, power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003897 domains_count += power_domains->domain_use_count[domain];
3898
3899 if (power_well->count != domains_count) {
3900 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3901 "(refcount %d/domains refcount %d)\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003902 power_well->desc->name, power_well->count,
Imre Deak8d8c3862017-02-17 17:39:46 +02003903 domains_count);
3904 dump_domain_info = true;
3905 }
3906 }
3907
3908 if (dump_domain_info) {
3909 static bool dumped;
3910
3911 if (!dumped) {
3912 intel_power_domains_dump_info(dev_priv);
3913 dumped = true;
3914 }
3915 }
3916
3917 mutex_unlock(&power_domains->lock);
3918}
3919
Imre Deak73dfc222015-11-17 17:33:53 +02003920/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003921 * intel_runtime_pm_get - grab a runtime pm reference
3922 * @dev_priv: i915 device instance
3923 *
3924 * This function grabs a device-level runtime pm reference (mostly used for GEM
3925 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3926 *
3927 * Any runtime pm reference obtained by this function must have a symmetric
3928 * call to intel_runtime_pm_put() to release the reference again.
3929 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003930void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3931{
David Weinehall52a05c32016-08-22 13:32:44 +03003932 struct pci_dev *pdev = dev_priv->drm.pdev;
3933 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003934 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003935
Imre Deakf5073822017-03-28 12:38:55 +03003936 ret = pm_runtime_get_sync(kdev);
3937 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003938
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003939 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003940 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003941}
3942
Daniel Vettere4e76842014-09-30 10:56:42 +02003943/**
Imre Deak09731282016-02-17 14:17:42 +02003944 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3945 * @dev_priv: i915 device instance
3946 *
3947 * This function grabs a device-level runtime pm reference if the device is
Chris Wilsonacb79142018-02-19 12:50:46 +00003948 * already in use and ensures that it is powered up. It is illegal to try
3949 * and access the HW should intel_runtime_pm_get_if_in_use() report failure.
Imre Deak09731282016-02-17 14:17:42 +02003950 *
3951 * Any runtime pm reference obtained by this function must have a symmetric
3952 * call to intel_runtime_pm_put() to release the reference again.
Chris Wilsonacb79142018-02-19 12:50:46 +00003953 *
3954 * Returns: True if the wakeref was acquired, or False otherwise.
Imre Deak09731282016-02-17 14:17:42 +02003955 */
3956bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3957{
Chris Wilson135dc792016-02-25 21:10:28 +00003958 if (IS_ENABLED(CONFIG_PM)) {
Chris Wilsonacb79142018-02-19 12:50:46 +00003959 struct pci_dev *pdev = dev_priv->drm.pdev;
3960 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003961
Chris Wilson135dc792016-02-25 21:10:28 +00003962 /*
3963 * In cases runtime PM is disabled by the RPM core and we get
3964 * an -EINVAL return value we are not supposed to call this
3965 * function, since the power state is undefined. This applies
3966 * atm to the late/early system suspend/resume handlers.
3967 */
Chris Wilsonacb79142018-02-19 12:50:46 +00003968 if (pm_runtime_get_if_in_use(kdev) <= 0)
Chris Wilson135dc792016-02-25 21:10:28 +00003969 return false;
3970 }
Imre Deak09731282016-02-17 14:17:42 +02003971
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003972 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deak09731282016-02-17 14:17:42 +02003973 assert_rpm_wakelock_held(dev_priv);
3974
3975 return true;
3976}
3977
3978/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003979 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3980 * @dev_priv: i915 device instance
3981 *
3982 * This function grabs a device-level runtime pm reference (mostly used for GEM
3983 * code to ensure the GTT or GT is on).
3984 *
3985 * It will _not_ power up the device but instead only check that it's powered
3986 * on. Therefore it is only valid to call this functions from contexts where
3987 * the device is known to be powered up and where trying to power it up would
3988 * result in hilarity and deadlocks. That pretty much means only the system
3989 * suspend/resume code where this is used to grab runtime pm references for
3990 * delayed setup down in work items.
3991 *
3992 * Any runtime pm reference obtained by this function must have a symmetric
3993 * call to intel_runtime_pm_put() to release the reference again.
3994 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003995void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3996{
David Weinehall52a05c32016-08-22 13:32:44 +03003997 struct pci_dev *pdev = dev_priv->drm.pdev;
3998 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003999
Imre Deakc9b88462015-12-15 20:10:34 +02004000 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03004001 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02004002
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004003 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02004004}
4005
Daniel Vettere4e76842014-09-30 10:56:42 +02004006/**
4007 * intel_runtime_pm_put - release a runtime pm reference
4008 * @dev_priv: i915 device instance
4009 *
4010 * This function drops the device-level runtime pm reference obtained by
4011 * intel_runtime_pm_get() and might power down the corresponding
4012 * hardware block right away if this is the last reference.
4013 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02004014void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
4015{
David Weinehall52a05c32016-08-22 13:32:44 +03004016 struct pci_dev *pdev = dev_priv->drm.pdev;
4017 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02004018
Imre Deak542db3c2015-12-15 20:10:36 +02004019 assert_rpm_wakelock_held(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004020 atomic_dec(&dev_priv->runtime_pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02004021
David Weinehallc49d13e2016-08-22 13:32:42 +03004022 pm_runtime_mark_last_busy(kdev);
4023 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02004024}
4025
Daniel Vettere4e76842014-09-30 10:56:42 +02004026/**
4027 * intel_runtime_pm_enable - enable runtime pm
4028 * @dev_priv: i915 device instance
4029 *
4030 * This function enables runtime pm at the end of the driver load sequence.
4031 *
4032 * Note that this function does currently not enable runtime pm for the
4033 * subordinate display power domains. That is only done on the first modeset
4034 * using intel_display_set_init_power().
4035 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02004036void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02004037{
David Weinehall52a05c32016-08-22 13:32:44 +03004038 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03004039 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02004040
Chris Wilson07d80572018-08-16 15:37:56 +03004041 /*
4042 * Disable the system suspend direct complete optimization, which can
4043 * leave the device suspended skipping the driver's suspend handlers
4044 * if the device was already runtime suspended. This is needed due to
4045 * the difference in our runtime and system suspend sequence and
4046 * becaue the HDA driver may require us to enable the audio power
4047 * domain during system suspend.
4048 */
4049 dev_pm_set_driver_flags(kdev, DPM_FLAG_NEVER_SKIP);
4050
David Weinehallc49d13e2016-08-22 13:32:42 +03004051 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
4052 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02004053
Imre Deak25b181b2015-12-17 13:44:56 +02004054 /*
4055 * Take a permanent reference to disable the RPM functionality and drop
4056 * it only when unloading the driver. Use the low level get/put helpers,
4057 * so the driver's own RPM reference tracking asserts also work on
4058 * platforms without RPM support.
4059 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01004060 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03004061 int ret;
4062
David Weinehallc49d13e2016-08-22 13:32:42 +03004063 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03004064 ret = pm_runtime_get_sync(kdev);
4065 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02004066 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03004067 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02004068 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02004069
Imre Deakaabee1b2015-12-15 20:10:29 +02004070 /*
4071 * The core calls the driver load handler with an RPM reference held.
4072 * We drop that here and will reacquire it during unloading in
4073 * intel_power_domains_fini().
4074 */
David Weinehallc49d13e2016-08-22 13:32:42 +03004075 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02004076}
Chris Wilson07d80572018-08-16 15:37:56 +03004077
4078void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
4079{
4080 struct pci_dev *pdev = dev_priv->drm.pdev;
4081 struct device *kdev = &pdev->dev;
4082
4083 /* Transfer rpm ownership back to core */
4084 WARN(pm_runtime_get_sync(&dev_priv->drm.pdev->dev) < 0,
4085 "Failed to pass rpm ownership back to core\n");
4086
4087 pm_runtime_dont_use_autosuspend(kdev);
4088
4089 if (!HAS_RUNTIME_PM(dev_priv))
4090 pm_runtime_put(kdev);
4091}