blob: 6153d5be5cf6b56fd9032a1ee81d5971b186d7cb [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
260/*
261 * Starting with Haswell, we have a "Power Down Well" that can be turned off
262 * when not needed anymore. We have 4 registers that can request the power well
263 * to be enabled, and it will only be disabled if none of the registers is
264 * requesting it to be enabled.
265 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300266static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv,
267 u8 irq_pipe_mask, bool has_vga)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200268{
David Weinehall52a05c32016-08-22 13:32:44 +0300269 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200270
271 /*
272 * After we re-enable the power well, if we touch VGA register 0x3d5
273 * we'll get unclaimed register interrupts. This stops after we write
274 * anything to the VGA MSR register. The vgacon module uses this
275 * register all the time, so if we unbind our driver and, as a
276 * consequence, bind vgacon, we'll get stuck in an infinite loop at
277 * console_unlock(). So make here we touch the VGA MSR register, making
278 * sure vgacon can keep working normally without triggering interrupts
279 * and error messages.
280 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300281 if (has_vga) {
282 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
283 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
284 vga_put(pdev, VGA_RSRC_LEGACY_IO);
285 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200286
Imre Deak001bd2c2017-07-12 18:54:13 +0300287 if (irq_pipe_mask)
288 gen8_irq_power_well_post_enable(dev_priv, irq_pipe_mask);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200289}
290
Imre Deak001bd2c2017-07-12 18:54:13 +0300291static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv,
292 u8 irq_pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200293{
Imre Deak001bd2c2017-07-12 18:54:13 +0300294 if (irq_pipe_mask)
295 gen8_irq_power_well_pre_disable(dev_priv, irq_pipe_mask);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200296}
297
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200298
Imre Deak76347c02017-07-06 17:40:36 +0300299static void hsw_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
300 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300301{
Imre Deak75e39682018-08-06 12:58:39 +0300302 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
303 int pw_idx = power_well->desc->hsw.idx;
Imre Deak42d93662017-06-29 18:37:01 +0300304
305 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
306 WARN_ON(intel_wait_for_register(dev_priv,
Imre Deak75e39682018-08-06 12:58:39 +0300307 regs->driver,
308 HSW_PWR_WELL_CTL_STATE(pw_idx),
309 HSW_PWR_WELL_CTL_STATE(pw_idx),
Imre Deak42d93662017-06-29 18:37:01 +0300310 1));
311}
312
Imre Deak76347c02017-07-06 17:40:36 +0300313static u32 hsw_power_well_requesters(struct drm_i915_private *dev_priv,
Imre Deak75e39682018-08-06 12:58:39 +0300314 const struct i915_power_well_regs *regs,
315 int pw_idx)
Imre Deak42d93662017-06-29 18:37:01 +0300316{
Imre Deak75e39682018-08-06 12:58:39 +0300317 u32 req_mask = HSW_PWR_WELL_CTL_REQ(pw_idx);
Imre Deak42d93662017-06-29 18:37:01 +0300318 u32 ret;
319
Imre Deak75e39682018-08-06 12:58:39 +0300320 ret = I915_READ(regs->bios) & req_mask ? 1 : 0;
321 ret |= I915_READ(regs->driver) & req_mask ? 2 : 0;
322 if (regs->kvmr.reg)
323 ret |= I915_READ(regs->kvmr) & req_mask ? 4 : 0;
324 ret |= I915_READ(regs->debug) & req_mask ? 8 : 0;
Imre Deak42d93662017-06-29 18:37:01 +0300325
326 return ret;
327}
328
Imre Deak76347c02017-07-06 17:40:36 +0300329static void hsw_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
330 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300331{
Imre Deak75e39682018-08-06 12:58:39 +0300332 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
333 int pw_idx = power_well->desc->hsw.idx;
Imre Deak42d93662017-06-29 18:37:01 +0300334 bool disabled;
335 u32 reqs;
336
337 /*
338 * Bspec doesn't require waiting for PWs to get disabled, but still do
339 * this for paranoia. The known cases where a PW will be forced on:
340 * - a KVMR request on any power well via the KVMR request register
341 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
342 * DEBUG request registers
343 * Skip the wait in case any of the request bits are set and print a
344 * diagnostic message.
345 */
Imre Deak75e39682018-08-06 12:58:39 +0300346 wait_for((disabled = !(I915_READ(regs->driver) &
347 HSW_PWR_WELL_CTL_STATE(pw_idx))) ||
348 (reqs = hsw_power_well_requesters(dev_priv, regs, pw_idx)), 1);
Imre Deak42d93662017-06-29 18:37:01 +0300349 if (disabled)
350 return;
351
352 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +0300353 power_well->desc->name,
Imre Deak42d93662017-06-29 18:37:01 +0300354 !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
355}
356
Imre Deakb2891eb2017-07-11 23:42:35 +0300357static void gen9_wait_for_power_well_fuses(struct drm_i915_private *dev_priv,
358 enum skl_power_gate pg)
359{
360 /* Timeout 5us for PG#0, for other PGs 1us */
361 WARN_ON(intel_wait_for_register(dev_priv, SKL_FUSE_STATUS,
362 SKL_FUSE_PG_DIST_STATUS(pg),
363 SKL_FUSE_PG_DIST_STATUS(pg), 1));
364}
365
Imre Deakec46d482017-07-06 17:40:33 +0300366static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
367 struct i915_power_well *power_well)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200368{
Imre Deak75e39682018-08-06 12:58:39 +0300369 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
370 int pw_idx = power_well->desc->hsw.idx;
Imre Deakf28ec6f2018-08-06 12:58:37 +0300371 bool wait_fuses = power_well->desc->hsw.has_fuses;
Chris Wilson320671f2017-10-02 11:04:16 +0100372 enum skl_power_gate uninitialized_var(pg);
Imre Deak1af474f2017-07-06 17:40:34 +0300373 u32 val;
374
Imre Deakb2891eb2017-07-11 23:42:35 +0300375 if (wait_fuses) {
Imre Deak75e39682018-08-06 12:58:39 +0300376 pg = INTEL_GEN(dev_priv) >= 11 ? ICL_PW_CTL_IDX_TO_PG(pw_idx) :
377 SKL_PW_CTL_IDX_TO_PG(pw_idx);
Imre Deakb2891eb2017-07-11 23:42:35 +0300378 /*
379 * For PW1 we have to wait both for the PW0/PG0 fuse state
380 * before enabling the power well and PW1/PG1's own fuse
381 * state after the enabling. For all other power wells with
382 * fuses we only have to wait for that PW/PG's fuse state
383 * after the enabling.
384 */
385 if (pg == SKL_PG1)
386 gen9_wait_for_power_well_fuses(dev_priv, SKL_PG0);
387 }
388
Imre Deak75e39682018-08-06 12:58:39 +0300389 val = I915_READ(regs->driver);
390 I915_WRITE(regs->driver, val | HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak76347c02017-07-06 17:40:36 +0300391 hsw_wait_for_power_well_enable(dev_priv, power_well);
Imre Deak001bd2c2017-07-12 18:54:13 +0300392
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800393 /* Display WA #1178: cnl */
394 if (IS_CANNONLAKE(dev_priv) &&
Imre Deak75e39682018-08-06 12:58:39 +0300395 pw_idx >= GLK_PW_CTL_IDX_AUX_B &&
396 pw_idx <= CNL_PW_CTL_IDX_AUX_F) {
397 val = I915_READ(CNL_AUX_ANAOVRD1(pw_idx));
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800398 val |= CNL_AUX_ANAOVRD1_ENABLE | CNL_AUX_ANAOVRD1_LDO_BYPASS;
Imre Deak75e39682018-08-06 12:58:39 +0300399 I915_WRITE(CNL_AUX_ANAOVRD1(pw_idx), val);
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800400 }
401
Imre Deakb2891eb2017-07-11 23:42:35 +0300402 if (wait_fuses)
403 gen9_wait_for_power_well_fuses(dev_priv, pg);
404
Imre Deakf28ec6f2018-08-06 12:58:37 +0300405 hsw_power_well_post_enable(dev_priv,
406 power_well->desc->hsw.irq_pipe_mask,
407 power_well->desc->hsw.has_vga);
Imre Deakec46d482017-07-06 17:40:33 +0300408}
Daniel Vetter9c065a72014-09-30 10:56:38 +0200409
Imre Deakec46d482017-07-06 17:40:33 +0300410static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
411 struct i915_power_well *power_well)
412{
Imre Deak75e39682018-08-06 12:58:39 +0300413 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
414 int pw_idx = power_well->desc->hsw.idx;
Imre Deak1af474f2017-07-06 17:40:34 +0300415 u32 val;
416
Imre Deakf28ec6f2018-08-06 12:58:37 +0300417 hsw_power_well_pre_disable(dev_priv,
418 power_well->desc->hsw.irq_pipe_mask);
Imre Deak001bd2c2017-07-12 18:54:13 +0300419
Imre Deak75e39682018-08-06 12:58:39 +0300420 val = I915_READ(regs->driver);
421 I915_WRITE(regs->driver, val & ~HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak76347c02017-07-06 17:40:36 +0300422 hsw_wait_for_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200423}
424
Imre Deak75e39682018-08-06 12:58:39 +0300425#define ICL_AUX_PW_TO_PORT(pw_idx) ((pw_idx) - ICL_PW_CTL_IDX_AUX_A)
Imre Deak67ca07e2018-06-26 17:22:32 +0300426
427static void
428icl_combo_phy_aux_power_well_enable(struct drm_i915_private *dev_priv,
429 struct i915_power_well *power_well)
430{
Imre Deak75e39682018-08-06 12:58:39 +0300431 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
432 int pw_idx = power_well->desc->hsw.idx;
433 enum port port = ICL_AUX_PW_TO_PORT(pw_idx);
Imre Deak67ca07e2018-06-26 17:22:32 +0300434 u32 val;
435
Imre Deak75e39682018-08-06 12:58:39 +0300436 val = I915_READ(regs->driver);
437 I915_WRITE(regs->driver, val | HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak67ca07e2018-06-26 17:22:32 +0300438
439 val = I915_READ(ICL_PORT_CL_DW12(port));
440 I915_WRITE(ICL_PORT_CL_DW12(port), val | ICL_LANE_ENABLE_AUX);
441
442 hsw_wait_for_power_well_enable(dev_priv, power_well);
443}
444
445static void
446icl_combo_phy_aux_power_well_disable(struct drm_i915_private *dev_priv,
447 struct i915_power_well *power_well)
448{
Imre Deak75e39682018-08-06 12:58:39 +0300449 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
450 int pw_idx = power_well->desc->hsw.idx;
451 enum port port = ICL_AUX_PW_TO_PORT(pw_idx);
Imre Deak67ca07e2018-06-26 17:22:32 +0300452 u32 val;
453
454 val = I915_READ(ICL_PORT_CL_DW12(port));
455 I915_WRITE(ICL_PORT_CL_DW12(port), val & ~ICL_LANE_ENABLE_AUX);
456
Imre Deak75e39682018-08-06 12:58:39 +0300457 val = I915_READ(regs->driver);
458 I915_WRITE(regs->driver, val & ~HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak67ca07e2018-06-26 17:22:32 +0300459
460 hsw_wait_for_power_well_disable(dev_priv, power_well);
461}
462
Imre Deakd42539b2017-07-06 17:40:39 +0300463/*
464 * We should only use the power well if we explicitly asked the hardware to
465 * enable it, so check if it's enabled and also check if we've requested it to
466 * be enabled.
467 */
468static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
469 struct i915_power_well *power_well)
470{
Imre Deak75e39682018-08-06 12:58:39 +0300471 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
472 int pw_idx = power_well->desc->hsw.idx;
473 u32 mask = HSW_PWR_WELL_CTL_REQ(pw_idx) |
474 HSW_PWR_WELL_CTL_STATE(pw_idx);
Imre Deakd42539b2017-07-06 17:40:39 +0300475
Imre Deak75e39682018-08-06 12:58:39 +0300476 return (I915_READ(regs->driver) & mask) == mask;
Imre Deakd42539b2017-07-06 17:40:39 +0300477}
478
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530479static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
480{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300481 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
482 "DC9 already programmed to be enabled.\n");
483 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
484 "DC5 still not disabled to enable DC9.\n");
Imre Deak75e39682018-08-06 12:58:39 +0300485 WARN_ONCE(I915_READ(HSW_PWR_WELL_CTL2) &
486 HSW_PWR_WELL_CTL_REQ(SKL_PW_CTL_IDX_PW_2),
Imre Deake8a3a2a2017-06-29 18:37:00 +0300487 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300488 WARN_ONCE(intel_irqs_enabled(dev_priv),
489 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530490
491 /*
492 * TODO: check for the following to verify the conditions to enter DC9
493 * state are satisfied:
494 * 1] Check relevant display engine registers to verify if mode set
495 * disable sequence was followed.
496 * 2] Check if display uninitialize sequence is initialized.
497 */
498}
499
500static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
501{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300502 WARN_ONCE(intel_irqs_enabled(dev_priv),
503 "Interrupts not disabled yet.\n");
504 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
505 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530506
507 /*
508 * TODO: check for the following to verify DC9 state was indeed
509 * entered before programming to disable it:
510 * 1] Check relevant display engine registers to verify if mode
511 * set disable sequence was followed.
512 * 2] Check if display uninitialize sequence is initialized.
513 */
514}
515
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200516static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
517 u32 state)
518{
519 int rewrites = 0;
520 int rereads = 0;
521 u32 v;
522
523 I915_WRITE(DC_STATE_EN, state);
524
525 /* It has been observed that disabling the dc6 state sometimes
526 * doesn't stick and dmc keeps returning old value. Make sure
527 * the write really sticks enough times and also force rewrite until
528 * we are confident that state is exactly what we want.
529 */
530 do {
531 v = I915_READ(DC_STATE_EN);
532
533 if (v != state) {
534 I915_WRITE(DC_STATE_EN, state);
535 rewrites++;
536 rereads = 0;
537 } else if (rereads++ > 5) {
538 break;
539 }
540
541 } while (rewrites < 100);
542
543 if (v != state)
544 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
545 state, v);
546
547 /* Most of the times we need one retry, avoid spam */
548 if (rewrites > 1)
549 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
550 state, rewrites);
551}
552
Imre Deakda2f41d2016-04-20 20:27:56 +0300553static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530554{
Imre Deakda2f41d2016-04-20 20:27:56 +0300555 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530556
Imre Deak13ae3a02015-11-04 19:24:16 +0200557 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200558 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200559 mask |= DC_STATE_EN_DC9;
560 else
561 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530562
Imre Deakda2f41d2016-04-20 20:27:56 +0300563 return mask;
564}
565
566void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
567{
568 u32 val;
569
570 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
571
572 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
573 dev_priv->csr.dc_state, val);
574 dev_priv->csr.dc_state = val;
575}
576
Imre Deak13e15922018-04-17 14:31:47 +0300577/**
578 * gen9_set_dc_state - set target display C power state
579 * @dev_priv: i915 device instance
580 * @state: target DC power state
581 * - DC_STATE_DISABLE
582 * - DC_STATE_EN_UPTO_DC5
583 * - DC_STATE_EN_UPTO_DC6
584 * - DC_STATE_EN_DC9
585 *
586 * Signal to DMC firmware/HW the target DC power state passed in @state.
587 * DMC/HW can turn off individual display clocks and power rails when entering
588 * a deeper DC power state (higher in number) and turns these back when exiting
589 * that state to a shallower power state (lower in number). The HW will decide
590 * when to actually enter a given state on an on-demand basis, for instance
591 * depending on the active state of display pipes. The state of display
592 * registers backed by affected power rails are saved/restored as needed.
593 *
594 * Based on the above enabling a deeper DC power state is asynchronous wrt.
595 * enabling it. Disabling a deeper power state is synchronous: for instance
596 * setting %DC_STATE_DISABLE won't complete until all HW resources are turned
597 * back on and register state is restored. This is guaranteed by the MMIO write
598 * to DC_STATE_EN blocking until the state is restored.
599 */
Imre Deakda2f41d2016-04-20 20:27:56 +0300600static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
601{
602 uint32_t val;
603 uint32_t mask;
604
Imre Deaka37baf32016-02-29 22:49:03 +0200605 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
606 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100607
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530608 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300609 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200610 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
611 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200612
613 /* Check if DMC is ignoring our DC state requests */
614 if ((val & mask) != dev_priv->csr.dc_state)
615 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
616 dev_priv->csr.dc_state, val & mask);
617
Imre Deak13ae3a02015-11-04 19:24:16 +0200618 val &= ~mask;
619 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200620
621 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200622
623 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530624}
625
Imre Deak13ae3a02015-11-04 19:24:16 +0200626void bxt_enable_dc9(struct drm_i915_private *dev_priv)
627{
628 assert_can_enable_dc9(dev_priv);
629
630 DRM_DEBUG_KMS("Enabling DC9\n");
631
Imre Deak78597992016-06-16 16:37:20 +0300632 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200633 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
634}
635
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530636void bxt_disable_dc9(struct drm_i915_private *dev_priv)
637{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530638 assert_can_disable_dc9(dev_priv);
639
640 DRM_DEBUG_KMS("Disabling DC9\n");
641
Imre Deak13ae3a02015-11-04 19:24:16 +0200642 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300643
644 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530645}
646
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200647static void assert_csr_loaded(struct drm_i915_private *dev_priv)
648{
649 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
650 "CSR program storage start is NULL\n");
651 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
652 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
653}
654
Suketu Shah5aefb232015-04-16 14:22:10 +0530655static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530656{
Suketu Shah5aefb232015-04-16 14:22:10 +0530657 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
658 SKL_DISP_PW_2);
659
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700660 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530661
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700662 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
663 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200664 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530665
666 assert_csr_loaded(dev_priv);
667}
668
Imre Deakf62c79b2016-04-20 20:27:57 +0300669void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530670{
Suketu Shah5aefb232015-04-16 14:22:10 +0530671 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530672
673 DRM_DEBUG_KMS("Enabling DC5\n");
674
Lucas De Marchi53421c22017-12-04 15:22:10 -0800675 /* Wa Display #1183: skl,kbl,cfl */
676 if (IS_GEN9_BC(dev_priv))
677 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
678 SKL_SELECT_ALTERNATE_DC_EXIT);
679
Imre Deak13ae3a02015-11-04 19:24:16 +0200680 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530681}
682
Suketu Shah93c7cb62015-04-16 14:22:13 +0530683static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530684{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700685 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
686 "Backlight is not disabled.\n");
687 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
688 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530689
690 assert_csr_loaded(dev_priv);
691}
692
Daniel Vetterc4c25252018-04-17 12:02:25 +0200693static void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530694{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530695 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530696
697 DRM_DEBUG_KMS("Enabling DC6\n");
698
Imre Deakb49be662018-04-19 18:51:09 +0300699 /* 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);
Imre Deak13ae3a02015-11-04 19:24:16 +0200703
Imre Deakb49be662018-04-19 18:51:09 +0300704 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
Suketu Shahf75a1982015-04-16 14:22:11 +0530705}
706
Daniel Vetter9c065a72014-09-30 10:56:38 +0200707static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
708 struct i915_power_well *power_well)
709{
Imre Deak75e39682018-08-06 12:58:39 +0300710 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
711 int pw_idx = power_well->desc->hsw.idx;
712 u32 mask = HSW_PWR_WELL_CTL_REQ(pw_idx);
713 u32 bios_req = I915_READ(regs->bios);
Imre Deak1af474f2017-07-06 17:40:34 +0300714
Imre Deak16e84912017-02-17 17:39:45 +0200715 /* Take over the request bit if set by BIOS. */
Imre Deak1af474f2017-07-06 17:40:34 +0300716 if (bios_req & mask) {
Imre Deak75e39682018-08-06 12:58:39 +0300717 u32 drv_req = I915_READ(regs->driver);
Imre Deak1af474f2017-07-06 17:40:34 +0300718
719 if (!(drv_req & mask))
Imre Deak75e39682018-08-06 12:58:39 +0300720 I915_WRITE(regs->driver, drv_req | mask);
721 I915_WRITE(regs->bios, bios_req & ~mask);
Imre Deak16e84912017-02-17 17:39:45 +0200722 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200723}
724
Imre Deak9c8d0b82016-06-13 16:44:34 +0300725static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
726 struct i915_power_well *power_well)
727{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300728 bxt_ddi_phy_init(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300729}
730
731static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
732 struct i915_power_well *power_well)
733{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300734 bxt_ddi_phy_uninit(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300735}
736
737static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
738 struct i915_power_well *power_well)
739{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300740 return bxt_ddi_phy_is_enabled(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300741}
742
Imre Deak9c8d0b82016-06-13 16:44:34 +0300743static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
744{
745 struct i915_power_well *power_well;
746
Imre Deak2183b492018-08-06 12:58:41 +0300747 power_well = lookup_power_well(dev_priv, BXT_DISP_PW_DPIO_CMN_A);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300748 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300749 bxt_ddi_phy_verify_state(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300750
Imre Deakd9fcdc82018-08-06 12:58:42 +0300751 power_well = lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300752 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300753 bxt_ddi_phy_verify_state(dev_priv, power_well->desc->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200754
755 if (IS_GEMINILAKE(dev_priv)) {
Imre Deak2183b492018-08-06 12:58:41 +0300756 power_well = lookup_power_well(dev_priv,
757 GLK_DISP_PW_DPIO_CMN_C);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200758 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300759 bxt_ddi_phy_verify_state(dev_priv,
760 power_well->desc->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200761 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300762}
763
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100764static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
765 struct i915_power_well *power_well)
766{
767 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
768}
769
Ville Syrjälä18a80672016-05-16 16:59:40 +0300770static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
771{
772 u32 tmp = I915_READ(DBUF_CTL);
773
774 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
775 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
776 "Unexpected DBuf power power state (0x%08x)\n", tmp);
777}
778
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100779static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
780 struct i915_power_well *power_well)
781{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200782 struct intel_cdclk_state cdclk_state = {};
783
Imre Deak5b773eb2016-02-29 22:49:05 +0200784 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300785
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200786 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
Ville Syrjälä64600bd2017-10-24 12:52:08 +0300787 /* Can't read out voltage_level so can't use intel_cdclk_changed() */
788 WARN_ON(intel_cdclk_needs_modeset(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300789
Ville Syrjälä18a80672016-05-16 16:59:40 +0300790 gen9_assert_dbuf_enabled(dev_priv);
791
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200792 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300793 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100794}
795
796static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
797 struct i915_power_well *power_well)
798{
Imre Deakf74ed082016-04-18 14:48:21 +0300799 if (!dev_priv->csr.dmc_payload)
800 return;
801
Imre Deaka37baf32016-02-29 22:49:03 +0200802 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100803 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200804 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100805 gen9_enable_dc5(dev_priv);
806}
807
Imre Deak3c1b38e2017-02-17 17:39:42 +0200808static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
809 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100810{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100811}
812
Daniel Vetter9c065a72014-09-30 10:56:38 +0200813static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
814 struct i915_power_well *power_well)
815{
816}
817
818static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
819 struct i915_power_well *power_well)
820{
821 return true;
822}
823
Ville Syrjälä2ee0da12017-06-01 17:36:16 +0300824static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
825 struct i915_power_well *power_well)
826{
827 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
828 i830_enable_pipe(dev_priv, PIPE_A);
829 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
830 i830_enable_pipe(dev_priv, PIPE_B);
831}
832
833static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
834 struct i915_power_well *power_well)
835{
836 i830_disable_pipe(dev_priv, PIPE_B);
837 i830_disable_pipe(dev_priv, PIPE_A);
838}
839
840static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
841 struct i915_power_well *power_well)
842{
843 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
844 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
845}
846
847static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
848 struct i915_power_well *power_well)
849{
850 if (power_well->count > 0)
851 i830_pipes_power_well_enable(dev_priv, power_well);
852 else
853 i830_pipes_power_well_disable(dev_priv, power_well);
854}
855
Daniel Vetter9c065a72014-09-30 10:56:38 +0200856static void vlv_set_power_well(struct drm_i915_private *dev_priv,
857 struct i915_power_well *power_well, bool enable)
858{
Imre Deakd13dd052018-08-06 12:58:38 +0300859 int pw_idx = power_well->desc->vlv.idx;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200860 u32 mask;
861 u32 state;
862 u32 ctrl;
863
Imre Deakd13dd052018-08-06 12:58:38 +0300864 mask = PUNIT_PWRGT_MASK(pw_idx);
865 state = enable ? PUNIT_PWRGT_PWR_ON(pw_idx) :
866 PUNIT_PWRGT_PWR_GATE(pw_idx);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200867
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100868 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200869
870#define COND \
871 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
872
873 if (COND)
874 goto out;
875
876 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
877 ctrl &= ~mask;
878 ctrl |= state;
879 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
880
881 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900882 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200883 state,
884 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
885
886#undef COND
887
888out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100889 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200890}
891
Daniel Vetter9c065a72014-09-30 10:56:38 +0200892static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
893 struct i915_power_well *power_well)
894{
895 vlv_set_power_well(dev_priv, power_well, true);
896}
897
898static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
899 struct i915_power_well *power_well)
900{
901 vlv_set_power_well(dev_priv, power_well, false);
902}
903
904static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
905 struct i915_power_well *power_well)
906{
Imre Deakd13dd052018-08-06 12:58:38 +0300907 int pw_idx = power_well->desc->vlv.idx;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200908 bool enabled = false;
909 u32 mask;
910 u32 state;
911 u32 ctrl;
912
Imre Deakd13dd052018-08-06 12:58:38 +0300913 mask = PUNIT_PWRGT_MASK(pw_idx);
914 ctrl = PUNIT_PWRGT_PWR_ON(pw_idx);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200915
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100916 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200917
918 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
919 /*
920 * We only ever set the power-on and power-gate states, anything
921 * else is unexpected.
922 */
Imre Deakd13dd052018-08-06 12:58:38 +0300923 WARN_ON(state != PUNIT_PWRGT_PWR_ON(pw_idx) &&
924 state != PUNIT_PWRGT_PWR_GATE(pw_idx));
Daniel Vetter9c065a72014-09-30 10:56:38 +0200925 if (state == ctrl)
926 enabled = true;
927
928 /*
929 * A transient state at this point would mean some unexpected party
930 * is poking at the power controls too.
931 */
932 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
933 WARN_ON(ctrl != state);
934
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100935 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200936
937 return enabled;
938}
939
Ville Syrjälä766078d2016-04-11 16:56:30 +0300940static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
941{
Hans de Goede721d4842016-12-02 15:29:04 +0100942 u32 val;
943
944 /*
945 * On driver load, a pipe may be active and driving a DSI display.
946 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
947 * (and never recovering) in this case. intel_dsi_post_disable() will
948 * clear it when we turn off the display.
949 */
950 val = I915_READ(DSPCLK_GATE_D);
951 val &= DPOUNIT_CLOCK_GATE_DISABLE;
952 val |= VRHUNIT_CLOCK_GATE_DISABLE;
953 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +0300954
955 /*
956 * Disable trickle feed and enable pnd deadline calculation
957 */
958 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
959 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +0300960
961 WARN_ON(dev_priv->rawclk_freq == 0);
962
963 I915_WRITE(RAWCLK_FREQ_VLV,
964 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +0300965}
966
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300967static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200968{
Lyude9504a892016-06-21 17:03:42 -0400969 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300970 enum pipe pipe;
971
972 /*
973 * Enable the CRI clock source so we can get at the
974 * display and the reference clock for VGA
975 * hotplug / manual detection. Supposedly DSI also
976 * needs the ref clock up and running.
977 *
978 * CHV DPLL B/C have some issues if VGA mode is enabled.
979 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +0000980 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300981 u32 val = I915_READ(DPLL(pipe));
982
983 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
984 if (pipe != PIPE_A)
985 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
986
987 I915_WRITE(DPLL(pipe), val);
988 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200989
Ville Syrjälä766078d2016-04-11 16:56:30 +0300990 vlv_init_display_clock_gating(dev_priv);
991
Daniel Vetter9c065a72014-09-30 10:56:38 +0200992 spin_lock_irq(&dev_priv->irq_lock);
993 valleyview_enable_display_irqs(dev_priv);
994 spin_unlock_irq(&dev_priv->irq_lock);
995
996 /*
997 * During driver initialization/resume we can avoid restoring the
998 * part of the HW/SW state that will be inited anyway explicitly.
999 */
1000 if (dev_priv->power_domains.initializing)
1001 return;
1002
Daniel Vetterb9632912014-09-30 10:56:44 +02001003 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001004
Lyude9504a892016-06-21 17:03:42 -04001005 /* Re-enable the ADPA, if we have one */
1006 for_each_intel_encoder(&dev_priv->drm, encoder) {
1007 if (encoder->type == INTEL_OUTPUT_ANALOG)
1008 intel_crt_reset(&encoder->base);
1009 }
1010
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001011 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001012
1013 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001014}
1015
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001016static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1017{
1018 spin_lock_irq(&dev_priv->irq_lock);
1019 valleyview_disable_display_irqs(dev_priv);
1020 spin_unlock_irq(&dev_priv->irq_lock);
1021
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001022 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001023 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001024
Imre Deak78597992016-06-16 16:37:20 +03001025 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001026
Lyudeb64b5402016-10-26 12:36:09 -04001027 /* Prevent us from re-enabling polling on accident in late suspend */
1028 if (!dev_priv->drm.dev->power.is_suspended)
1029 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001030}
1031
1032static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1033 struct i915_power_well *power_well)
1034{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001035 vlv_set_power_well(dev_priv, power_well, true);
1036
1037 vlv_display_power_well_init(dev_priv);
1038}
1039
Daniel Vetter9c065a72014-09-30 10:56:38 +02001040static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1041 struct i915_power_well *power_well)
1042{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001043 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001044
1045 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001046}
1047
1048static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1049 struct i915_power_well *power_well)
1050{
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001051 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001052 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1053
1054 vlv_set_power_well(dev_priv, power_well, true);
1055
1056 /*
1057 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1058 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1059 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1060 * b. The other bits such as sfr settings / modesel may all
1061 * be set to 0.
1062 *
1063 * This should only be done on init and resume from S3 with
1064 * both PLLs disabled, or we risk losing DPIO and PLL
1065 * synchronization.
1066 */
1067 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1068}
1069
1070static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1071 struct i915_power_well *power_well)
1072{
1073 enum pipe pipe;
1074
Daniel Vetter9c065a72014-09-30 10:56:38 +02001075 for_each_pipe(dev_priv, pipe)
1076 assert_pll_disabled(dev_priv, pipe);
1077
1078 /* Assert common reset */
1079 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1080
1081 vlv_set_power_well(dev_priv, power_well, false);
1082}
1083
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001084#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001085
Imre Deak438b8dc2017-07-11 23:42:30 +03001086static struct i915_power_well *
1087lookup_power_well(struct drm_i915_private *dev_priv,
1088 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001089{
1090 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001091 int i;
1092
Imre Deakfc17f222015-11-04 19:24:11 +02001093 for (i = 0; i < power_domains->power_well_count; i++) {
1094 struct i915_power_well *power_well;
1095
1096 power_well = &power_domains->power_wells[i];
Imre Deakf28ec6f2018-08-06 12:58:37 +03001097 if (power_well->desc->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001098 return power_well;
1099 }
1100
1101 return NULL;
1102}
1103
1104#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1105
1106static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1107{
1108 struct i915_power_well *cmn_bc =
Imre Deak2183b492018-08-06 12:58:41 +03001109 lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
Ville Syrjälä30142272015-07-08 23:46:01 +03001110 struct i915_power_well *cmn_d =
Imre Deak2183b492018-08-06 12:58:41 +03001111 lookup_power_well(dev_priv, CHV_DISP_PW_DPIO_CMN_D);
Ville Syrjälä30142272015-07-08 23:46:01 +03001112 u32 phy_control = dev_priv->chv_phy_control;
1113 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001114 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001115
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001116 /*
1117 * The BIOS can leave the PHY is some weird state
1118 * where it doesn't fully power down some parts.
1119 * Disable the asserts until the PHY has been fully
1120 * reset (ie. the power well has been disabled at
1121 * least once).
1122 */
1123 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1124 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1125 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1126 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1127 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1128 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1129 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1130
1131 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1132 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1133 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1134 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1135
Imre Deakf28ec6f2018-08-06 12:58:37 +03001136 if (cmn_bc->desc->ops->is_enabled(dev_priv, cmn_bc)) {
Ville Syrjälä30142272015-07-08 23:46:01 +03001137 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1138
1139 /* this assumes override is only used to enable lanes */
1140 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1141 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1142
1143 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1144 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1145
1146 /* CL1 is on whenever anything is on in either channel */
1147 if (BITS_SET(phy_control,
1148 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1149 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1150 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1151
1152 /*
1153 * The DPLLB check accounts for the pipe B + port A usage
1154 * with CL2 powered up but all the lanes in the second channel
1155 * powered down.
1156 */
1157 if (BITS_SET(phy_control,
1158 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1159 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1160 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1161
1162 if (BITS_SET(phy_control,
1163 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1164 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1165 if (BITS_SET(phy_control,
1166 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1167 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1168
1169 if (BITS_SET(phy_control,
1170 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1171 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1172 if (BITS_SET(phy_control,
1173 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1174 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1175 }
1176
Imre Deakf28ec6f2018-08-06 12:58:37 +03001177 if (cmn_d->desc->ops->is_enabled(dev_priv, cmn_d)) {
Ville Syrjälä30142272015-07-08 23:46:01 +03001178 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1179
1180 /* this assumes override is only used to enable lanes */
1181 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1182 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1183
1184 if (BITS_SET(phy_control,
1185 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1186 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1187
1188 if (BITS_SET(phy_control,
1189 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1190 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1191 if (BITS_SET(phy_control,
1192 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1193 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1194 }
1195
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001196 phy_status &= phy_status_mask;
1197
Ville Syrjälä30142272015-07-08 23:46:01 +03001198 /*
1199 * The PHY may be busy with some initial calibration and whatnot,
1200 * so the power state can take a while to actually change.
1201 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001202 if (intel_wait_for_register(dev_priv,
1203 DISPLAY_PHY_STATUS,
1204 phy_status_mask,
1205 phy_status,
1206 10))
1207 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1208 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1209 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001210}
1211
1212#undef BITS_SET
1213
Daniel Vetter9c065a72014-09-30 10:56:38 +02001214static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1215 struct i915_power_well *power_well)
1216{
1217 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001218 enum pipe pipe;
1219 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001220
Imre Deak2183b492018-08-06 12:58:41 +03001221 WARN_ON_ONCE(power_well->desc->id != VLV_DISP_PW_DPIO_CMN_BC &&
1222 power_well->desc->id != CHV_DISP_PW_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001223
Imre Deak2183b492018-08-06 12:58:41 +03001224 if (power_well->desc->id == VLV_DISP_PW_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001225 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001226 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001227 } else {
1228 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001229 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001230 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001231
1232 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001233 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1234 vlv_set_power_well(dev_priv, power_well, true);
1235
1236 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001237 if (intel_wait_for_register(dev_priv,
1238 DISPLAY_PHY_STATUS,
1239 PHY_POWERGOOD(phy),
1240 PHY_POWERGOOD(phy),
1241 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001242 DRM_ERROR("Display PHY %d is not power up\n", phy);
1243
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001244 mutex_lock(&dev_priv->sb_lock);
1245
1246 /* Enable dynamic power down */
1247 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001248 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1249 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001250 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1251
Imre Deak2183b492018-08-06 12:58:41 +03001252 if (power_well->desc->id == VLV_DISP_PW_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001253 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1254 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1255 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001256 } else {
1257 /*
1258 * Force the non-existing CL2 off. BXT does this
1259 * too, so maybe it saves some power even though
1260 * CL2 doesn't exist?
1261 */
1262 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1263 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1264 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001265 }
1266
1267 mutex_unlock(&dev_priv->sb_lock);
1268
Ville Syrjälä70722462015-04-10 18:21:28 +03001269 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1270 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001271
1272 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1273 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001274
1275 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001276}
1277
1278static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1279 struct i915_power_well *power_well)
1280{
1281 enum dpio_phy phy;
1282
Imre Deak2183b492018-08-06 12:58:41 +03001283 WARN_ON_ONCE(power_well->desc->id != VLV_DISP_PW_DPIO_CMN_BC &&
1284 power_well->desc->id != CHV_DISP_PW_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001285
Imre Deak2183b492018-08-06 12:58:41 +03001286 if (power_well->desc->id == VLV_DISP_PW_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001287 phy = DPIO_PHY0;
1288 assert_pll_disabled(dev_priv, PIPE_A);
1289 assert_pll_disabled(dev_priv, PIPE_B);
1290 } else {
1291 phy = DPIO_PHY1;
1292 assert_pll_disabled(dev_priv, PIPE_C);
1293 }
1294
Ville Syrjälä70722462015-04-10 18:21:28 +03001295 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1296 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001297
1298 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001299
1300 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1301 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001302
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001303 /* PHY is fully reset now, so we can enable the PHY state asserts */
1304 dev_priv->chv_phy_assert[phy] = true;
1305
Ville Syrjälä30142272015-07-08 23:46:01 +03001306 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001307}
1308
Ville Syrjälä6669e392015-07-08 23:46:00 +03001309static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1310 enum dpio_channel ch, bool override, unsigned int mask)
1311{
1312 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1313 u32 reg, val, expected, actual;
1314
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001315 /*
1316 * The BIOS can leave the PHY is some weird state
1317 * where it doesn't fully power down some parts.
1318 * Disable the asserts until the PHY has been fully
1319 * reset (ie. the power well has been disabled at
1320 * least once).
1321 */
1322 if (!dev_priv->chv_phy_assert[phy])
1323 return;
1324
Ville Syrjälä6669e392015-07-08 23:46:00 +03001325 if (ch == DPIO_CH0)
1326 reg = _CHV_CMN_DW0_CH0;
1327 else
1328 reg = _CHV_CMN_DW6_CH1;
1329
1330 mutex_lock(&dev_priv->sb_lock);
1331 val = vlv_dpio_read(dev_priv, pipe, reg);
1332 mutex_unlock(&dev_priv->sb_lock);
1333
1334 /*
1335 * This assumes !override is only used when the port is disabled.
1336 * All lanes should power down even without the override when
1337 * the port is disabled.
1338 */
1339 if (!override || mask == 0xf) {
1340 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1341 /*
1342 * If CH1 common lane is not active anymore
1343 * (eg. for pipe B DPLL) the entire channel will
1344 * shut down, which causes the common lane registers
1345 * to read as 0. That means we can't actually check
1346 * the lane power down status bits, but as the entire
1347 * register reads as 0 it's a good indication that the
1348 * channel is indeed entirely powered down.
1349 */
1350 if (ch == DPIO_CH1 && val == 0)
1351 expected = 0;
1352 } else if (mask != 0x0) {
1353 expected = DPIO_ANYDL_POWERDOWN;
1354 } else {
1355 expected = 0;
1356 }
1357
1358 if (ch == DPIO_CH0)
1359 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1360 else
1361 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1362 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1363
1364 WARN(actual != expected,
1365 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1366 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1367 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1368 reg, val);
1369}
1370
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001371bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1372 enum dpio_channel ch, bool override)
1373{
1374 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1375 bool was_override;
1376
1377 mutex_lock(&power_domains->lock);
1378
1379 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1380
1381 if (override == was_override)
1382 goto out;
1383
1384 if (override)
1385 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1386 else
1387 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1388
1389 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1390
1391 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1392 phy, ch, dev_priv->chv_phy_control);
1393
Ville Syrjälä30142272015-07-08 23:46:01 +03001394 assert_chv_phy_status(dev_priv);
1395
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001396out:
1397 mutex_unlock(&power_domains->lock);
1398
1399 return was_override;
1400}
1401
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001402void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1403 bool override, unsigned int mask)
1404{
1405 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1406 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1407 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1408 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1409
1410 mutex_lock(&power_domains->lock);
1411
1412 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1413 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1414
1415 if (override)
1416 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1417 else
1418 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1419
1420 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1421
1422 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1423 phy, ch, mask, dev_priv->chv_phy_control);
1424
Ville Syrjälä30142272015-07-08 23:46:01 +03001425 assert_chv_phy_status(dev_priv);
1426
Ville Syrjälä6669e392015-07-08 23:46:00 +03001427 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1428
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001429 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001430}
1431
1432static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1433 struct i915_power_well *power_well)
1434{
Imre Deakf49193c2017-07-06 17:40:23 +03001435 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001436 bool enabled;
1437 u32 state, ctrl;
1438
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001439 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001440
1441 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1442 /*
1443 * We only ever set the power-on and power-gate states, anything
1444 * else is unexpected.
1445 */
1446 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1447 enabled = state == DP_SSS_PWR_ON(pipe);
1448
1449 /*
1450 * A transient state at this point would mean some unexpected party
1451 * is poking at the power controls too.
1452 */
1453 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1454 WARN_ON(ctrl << 16 != state);
1455
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001456 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001457
1458 return enabled;
1459}
1460
1461static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1462 struct i915_power_well *power_well,
1463 bool enable)
1464{
Imre Deakf49193c2017-07-06 17:40:23 +03001465 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001466 u32 state;
1467 u32 ctrl;
1468
1469 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1470
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001471 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001472
1473#define COND \
1474 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1475
1476 if (COND)
1477 goto out;
1478
1479 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1480 ctrl &= ~DP_SSC_MASK(pipe);
1481 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1482 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1483
1484 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001485 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001486 state,
1487 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1488
1489#undef COND
1490
1491out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001492 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001493}
1494
Daniel Vetter9c065a72014-09-30 10:56:38 +02001495static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1496 struct i915_power_well *power_well)
1497{
Daniel Vetter9c065a72014-09-30 10:56:38 +02001498 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001499
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001500 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001501}
1502
1503static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1504 struct i915_power_well *power_well)
1505{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001506 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001507
Daniel Vetter9c065a72014-09-30 10:56:38 +02001508 chv_set_pipe_power_well(dev_priv, power_well, false);
1509}
1510
Imre Deak09731282016-02-17 14:17:42 +02001511static void
1512__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1513 enum intel_display_power_domain domain)
1514{
1515 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1516 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001517
Imre Deak75ccb2e2017-02-17 17:39:43 +02001518 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001519 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001520
1521 power_domains->domain_use_count[domain]++;
1522}
1523
Daniel Vettere4e76842014-09-30 10:56:42 +02001524/**
1525 * intel_display_power_get - grab a power domain reference
1526 * @dev_priv: i915 device instance
1527 * @domain: power domain to reference
1528 *
1529 * This function grabs a power domain reference for @domain and ensures that the
1530 * power domain and all its parents are powered up. Therefore users should only
1531 * grab a reference to the innermost power domain they need.
1532 *
1533 * Any power domain reference obtained by this function must have a symmetric
1534 * call to intel_display_power_put() to release the reference again.
1535 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001536void intel_display_power_get(struct drm_i915_private *dev_priv,
1537 enum intel_display_power_domain domain)
1538{
Imre Deak09731282016-02-17 14:17:42 +02001539 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001540
1541 intel_runtime_pm_get(dev_priv);
1542
Imre Deak09731282016-02-17 14:17:42 +02001543 mutex_lock(&power_domains->lock);
1544
1545 __intel_display_power_get_domain(dev_priv, domain);
1546
1547 mutex_unlock(&power_domains->lock);
1548}
1549
1550/**
1551 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1552 * @dev_priv: i915 device instance
1553 * @domain: power domain to reference
1554 *
1555 * This function grabs a power domain reference for @domain and ensures that the
1556 * power domain and all its parents are powered up. Therefore users should only
1557 * grab a reference to the innermost power domain they need.
1558 *
1559 * Any power domain reference obtained by this function must have a symmetric
1560 * call to intel_display_power_put() to release the reference again.
1561 */
1562bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1563 enum intel_display_power_domain domain)
1564{
1565 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1566 bool is_enabled;
1567
1568 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1569 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001570
1571 mutex_lock(&power_domains->lock);
1572
Imre Deak09731282016-02-17 14:17:42 +02001573 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1574 __intel_display_power_get_domain(dev_priv, domain);
1575 is_enabled = true;
1576 } else {
1577 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001578 }
1579
Daniel Vetter9c065a72014-09-30 10:56:38 +02001580 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001581
1582 if (!is_enabled)
1583 intel_runtime_pm_put(dev_priv);
1584
1585 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001586}
1587
Daniel Vettere4e76842014-09-30 10:56:42 +02001588/**
1589 * intel_display_power_put - release a power domain reference
1590 * @dev_priv: i915 device instance
1591 * @domain: power domain to reference
1592 *
1593 * This function drops the power domain reference obtained by
1594 * intel_display_power_get() and might power down the corresponding hardware
1595 * block right away if this is the last reference.
1596 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001597void intel_display_power_put(struct drm_i915_private *dev_priv,
1598 enum intel_display_power_domain domain)
1599{
1600 struct i915_power_domains *power_domains;
1601 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001602
1603 power_domains = &dev_priv->power_domains;
1604
1605 mutex_lock(&power_domains->lock);
1606
Daniel Stone11c86db2015-11-20 15:55:34 +00001607 WARN(!power_domains->domain_use_count[domain],
1608 "Use count on domain %s is already zero\n",
1609 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001610 power_domains->domain_use_count[domain]--;
1611
Imre Deak75ccb2e2017-02-17 17:39:43 +02001612 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001613 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001614
1615 mutex_unlock(&power_domains->lock);
1616
1617 intel_runtime_pm_put(dev_priv);
1618}
1619
Imre Deak965a79a2017-07-06 17:40:40 +03001620#define I830_PIPES_POWER_DOMAINS ( \
1621 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1622 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1623 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1624 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1625 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1626 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001627 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001628
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001629#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001630 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1631 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1632 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1633 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1634 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1635 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1636 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1637 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1638 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1639 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1640 BIT_ULL(POWER_DOMAIN_VGA) | \
1641 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1642 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1643 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1644 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1645 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001646
1647#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001648 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1649 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1650 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1651 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1652 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1653 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001654
1655#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001656 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1657 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1658 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001659
1660#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001661 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1662 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1663 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001664
1665#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001666 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1667 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1668 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001669
1670#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001671 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1672 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1673 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001674
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001675#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001676 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1677 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1678 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1679 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1680 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1681 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1682 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1683 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1684 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1685 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1686 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1687 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1688 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1689 BIT_ULL(POWER_DOMAIN_VGA) | \
1690 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1691 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1692 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1693 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1694 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1695 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001696
Daniel Vetter9c065a72014-09-30 10:56:38 +02001697#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001698 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1699 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1700 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1701 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1702 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001703
1704#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001705 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1706 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1707 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001708
Imre Deak965a79a2017-07-06 17:40:40 +03001709#define HSW_DISPLAY_POWER_DOMAINS ( \
1710 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1711 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1712 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1713 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1714 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1715 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1716 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1717 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1718 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1719 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1720 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1721 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1722 BIT_ULL(POWER_DOMAIN_VGA) | \
1723 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1724 BIT_ULL(POWER_DOMAIN_INIT))
1725
1726#define BDW_DISPLAY_POWER_DOMAINS ( \
1727 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1728 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1729 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1730 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1731 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1732 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1733 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1734 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1735 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1736 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1737 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1738 BIT_ULL(POWER_DOMAIN_VGA) | \
1739 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1740 BIT_ULL(POWER_DOMAIN_INIT))
1741
1742#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1743 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1744 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1745 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1746 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1747 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1748 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1749 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1750 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1751 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1752 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1753 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1754 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1755 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1756 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1757 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1758 BIT_ULL(POWER_DOMAIN_VGA) | \
1759 BIT_ULL(POWER_DOMAIN_INIT))
1760#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
1761 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
1762 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1763 BIT_ULL(POWER_DOMAIN_INIT))
1764#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1765 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1766 BIT_ULL(POWER_DOMAIN_INIT))
1767#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1768 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1769 BIT_ULL(POWER_DOMAIN_INIT))
1770#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
1771 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1772 BIT_ULL(POWER_DOMAIN_INIT))
1773#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1774 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001775 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001776 BIT_ULL(POWER_DOMAIN_MODESET) | \
1777 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1778 BIT_ULL(POWER_DOMAIN_INIT))
1779
1780#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1781 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1782 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1783 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1784 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1785 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1786 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1787 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1788 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1789 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1790 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1791 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1792 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1793 BIT_ULL(POWER_DOMAIN_VGA) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001794 BIT_ULL(POWER_DOMAIN_INIT))
1795#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1796 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001797 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001798 BIT_ULL(POWER_DOMAIN_MODESET) | \
1799 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä54c105d2017-12-08 23:37:37 +02001800 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001801 BIT_ULL(POWER_DOMAIN_INIT))
1802#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
1803 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1804 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1805 BIT_ULL(POWER_DOMAIN_INIT))
1806#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
1807 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1808 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1809 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1810 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1811 BIT_ULL(POWER_DOMAIN_INIT))
1812
1813#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1814 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1815 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1816 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1817 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1818 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1819 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1820 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1821 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1822 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1823 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1824 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1825 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1826 BIT_ULL(POWER_DOMAIN_VGA) | \
1827 BIT_ULL(POWER_DOMAIN_INIT))
1828#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
1829 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
1830#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1831 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
1832#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1833 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
1834#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
1835 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1836 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1837 BIT_ULL(POWER_DOMAIN_INIT))
1838#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
1839 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1840 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1841 BIT_ULL(POWER_DOMAIN_INIT))
1842#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
1843 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1844 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1845 BIT_ULL(POWER_DOMAIN_INIT))
1846#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
1847 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Imre Deak52528052018-06-21 21:44:49 +03001848 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001849 BIT_ULL(POWER_DOMAIN_INIT))
1850#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
1851 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1852 BIT_ULL(POWER_DOMAIN_INIT))
1853#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
1854 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1855 BIT_ULL(POWER_DOMAIN_INIT))
1856#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1857 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001858 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001859 BIT_ULL(POWER_DOMAIN_MODESET) | \
1860 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä156961a2017-12-08 23:37:36 +02001861 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001862 BIT_ULL(POWER_DOMAIN_INIT))
1863
1864#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1865 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1866 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1867 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1868 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1869 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1870 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1871 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1872 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1873 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1874 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001875 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001876 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1877 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1878 BIT_ULL(POWER_DOMAIN_AUX_D) | \
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001879 BIT_ULL(POWER_DOMAIN_AUX_F) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001880 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1881 BIT_ULL(POWER_DOMAIN_VGA) | \
1882 BIT_ULL(POWER_DOMAIN_INIT))
1883#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
1884 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001885 BIT_ULL(POWER_DOMAIN_INIT))
1886#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
1887 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1888 BIT_ULL(POWER_DOMAIN_INIT))
1889#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
1890 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1891 BIT_ULL(POWER_DOMAIN_INIT))
1892#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
1893 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1894 BIT_ULL(POWER_DOMAIN_INIT))
1895#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
1896 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Dhinakaran Pandiyanb891d5e2018-02-23 14:15:15 -08001897 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001898 BIT_ULL(POWER_DOMAIN_INIT))
1899#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
1900 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1901 BIT_ULL(POWER_DOMAIN_INIT))
1902#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
1903 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1904 BIT_ULL(POWER_DOMAIN_INIT))
1905#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
1906 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1907 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001908#define CNL_DISPLAY_AUX_F_POWER_DOMAINS ( \
1909 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1910 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001911#define CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS ( \
1912 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1913 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak965a79a2017-07-06 17:40:40 +03001914#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1915 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulin6e7a3f52018-01-11 08:24:17 +00001916 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001917 BIT_ULL(POWER_DOMAIN_MODESET) | \
1918 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001919 BIT_ULL(POWER_DOMAIN_INIT))
1920
Imre Deak67ca07e2018-06-26 17:22:32 +03001921/*
1922 * ICL PW_0/PG_0 domains (HW/DMC control):
1923 * - PCI
1924 * - clocks except port PLL
1925 * - central power except FBC
1926 * - shared functions except pipe interrupts, pipe MBUS, DBUF registers
1927 * ICL PW_1/PG_1 domains (HW/DMC control):
1928 * - DBUF function
1929 * - PIPE_A and its planes, except VGA
1930 * - transcoder EDP + PSR
1931 * - transcoder DSI
1932 * - DDI_A
1933 * - FBC
1934 */
1935#define ICL_PW_4_POWER_DOMAINS ( \
1936 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1937 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1938 BIT_ULL(POWER_DOMAIN_INIT))
1939 /* VDSC/joining */
1940#define ICL_PW_3_POWER_DOMAINS ( \
1941 ICL_PW_4_POWER_DOMAINS | \
1942 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1943 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1944 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1945 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1946 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1947 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1948 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1949 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1950 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1951 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1952 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1953 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1954 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1955 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
1956 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1957 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1958 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1959 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1960 BIT_ULL(POWER_DOMAIN_AUX_E) | \
1961 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1962 BIT_ULL(POWER_DOMAIN_AUX_TBT1) | \
1963 BIT_ULL(POWER_DOMAIN_AUX_TBT2) | \
1964 BIT_ULL(POWER_DOMAIN_AUX_TBT3) | \
1965 BIT_ULL(POWER_DOMAIN_AUX_TBT4) | \
1966 BIT_ULL(POWER_DOMAIN_VGA) | \
1967 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1968 BIT_ULL(POWER_DOMAIN_INIT))
1969 /*
1970 * - transcoder WD
1971 * - KVMR (HW control)
1972 */
1973#define ICL_PW_2_POWER_DOMAINS ( \
1974 ICL_PW_3_POWER_DOMAINS | \
1975 BIT_ULL(POWER_DOMAIN_INIT))
1976 /*
1977 * - eDP/DSI VDSC
1978 * - KVMR (HW control)
1979 */
1980#define ICL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1981 ICL_PW_2_POWER_DOMAINS | \
1982 BIT_ULL(POWER_DOMAIN_MODESET) | \
1983 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1984 BIT_ULL(POWER_DOMAIN_INIT))
1985
1986#define ICL_DDI_IO_A_POWER_DOMAINS ( \
1987 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
1988#define ICL_DDI_IO_B_POWER_DOMAINS ( \
1989 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
1990#define ICL_DDI_IO_C_POWER_DOMAINS ( \
1991 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
1992#define ICL_DDI_IO_D_POWER_DOMAINS ( \
1993 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO))
1994#define ICL_DDI_IO_E_POWER_DOMAINS ( \
1995 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO))
1996#define ICL_DDI_IO_F_POWER_DOMAINS ( \
1997 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO))
1998
1999#define ICL_AUX_A_IO_POWER_DOMAINS ( \
2000 BIT_ULL(POWER_DOMAIN_AUX_A))
2001#define ICL_AUX_B_IO_POWER_DOMAINS ( \
2002 BIT_ULL(POWER_DOMAIN_AUX_B))
2003#define ICL_AUX_C_IO_POWER_DOMAINS ( \
2004 BIT_ULL(POWER_DOMAIN_AUX_C))
2005#define ICL_AUX_D_IO_POWER_DOMAINS ( \
2006 BIT_ULL(POWER_DOMAIN_AUX_D))
2007#define ICL_AUX_E_IO_POWER_DOMAINS ( \
2008 BIT_ULL(POWER_DOMAIN_AUX_E))
2009#define ICL_AUX_F_IO_POWER_DOMAINS ( \
2010 BIT_ULL(POWER_DOMAIN_AUX_F))
2011#define ICL_AUX_TBT1_IO_POWER_DOMAINS ( \
2012 BIT_ULL(POWER_DOMAIN_AUX_TBT1))
2013#define ICL_AUX_TBT2_IO_POWER_DOMAINS ( \
2014 BIT_ULL(POWER_DOMAIN_AUX_TBT2))
2015#define ICL_AUX_TBT3_IO_POWER_DOMAINS ( \
2016 BIT_ULL(POWER_DOMAIN_AUX_TBT3))
2017#define ICL_AUX_TBT4_IO_POWER_DOMAINS ( \
2018 BIT_ULL(POWER_DOMAIN_AUX_TBT4))
2019
Daniel Vetter9c065a72014-09-30 10:56:38 +02002020static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002021 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002022 .enable = i9xx_always_on_power_well_noop,
2023 .disable = i9xx_always_on_power_well_noop,
2024 .is_enabled = i9xx_always_on_power_well_enabled,
2025};
2026
2027static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002028 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002029 .enable = chv_pipe_power_well_enable,
2030 .disable = chv_pipe_power_well_disable,
2031 .is_enabled = chv_pipe_power_well_enabled,
2032};
2033
2034static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002035 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002036 .enable = chv_dpio_cmn_power_well_enable,
2037 .disable = chv_dpio_cmn_power_well_disable,
2038 .is_enabled = vlv_power_well_enabled,
2039};
2040
Imre Deakf28ec6f2018-08-06 12:58:37 +03002041static const struct i915_power_well_desc i9xx_always_on_power_well[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002042 {
2043 .name = "always-on",
2044 .always_on = 1,
2045 .domains = POWER_DOMAIN_MASK,
2046 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002047 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002048 },
2049};
2050
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002051static const struct i915_power_well_ops i830_pipes_power_well_ops = {
2052 .sync_hw = i830_pipes_power_well_sync_hw,
2053 .enable = i830_pipes_power_well_enable,
2054 .disable = i830_pipes_power_well_disable,
2055 .is_enabled = i830_pipes_power_well_enabled,
2056};
2057
Imre Deakf28ec6f2018-08-06 12:58:37 +03002058static const struct i915_power_well_desc i830_power_wells[] = {
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002059 {
2060 .name = "always-on",
2061 .always_on = 1,
2062 .domains = POWER_DOMAIN_MASK,
2063 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002064 .id = DISP_PW_ID_NONE,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002065 },
2066 {
2067 .name = "pipes",
2068 .domains = I830_PIPES_POWER_DOMAINS,
2069 .ops = &i830_pipes_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002070 .id = DISP_PW_ID_NONE,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002071 },
2072};
2073
Daniel Vetter9c065a72014-09-30 10:56:38 +02002074static const struct i915_power_well_ops hsw_power_well_ops = {
2075 .sync_hw = hsw_power_well_sync_hw,
2076 .enable = hsw_power_well_enable,
2077 .disable = hsw_power_well_disable,
2078 .is_enabled = hsw_power_well_enabled,
2079};
2080
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002081static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002082 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002083 .enable = gen9_dc_off_power_well_enable,
2084 .disable = gen9_dc_off_power_well_disable,
2085 .is_enabled = gen9_dc_off_power_well_enabled,
2086};
2087
Imre Deak9c8d0b82016-06-13 16:44:34 +03002088static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002089 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002090 .enable = bxt_dpio_cmn_power_well_enable,
2091 .disable = bxt_dpio_cmn_power_well_disable,
2092 .is_enabled = bxt_dpio_cmn_power_well_enabled,
2093};
2094
Imre Deak75e39682018-08-06 12:58:39 +03002095static const struct i915_power_well_regs hsw_power_well_regs = {
2096 .bios = HSW_PWR_WELL_CTL1,
2097 .driver = HSW_PWR_WELL_CTL2,
2098 .kvmr = HSW_PWR_WELL_CTL3,
2099 .debug = HSW_PWR_WELL_CTL4,
2100};
2101
Imre Deakf28ec6f2018-08-06 12:58:37 +03002102static const struct i915_power_well_desc hsw_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002103 {
2104 .name = "always-on",
2105 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002106 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002107 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002108 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002109 },
2110 {
2111 .name = "display",
2112 .domains = HSW_DISPLAY_POWER_DOMAINS,
2113 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002114 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002115 {
Imre Deak75e39682018-08-06 12:58:39 +03002116 .hsw.regs = &hsw_power_well_regs,
2117 .hsw.idx = HSW_PW_CTL_IDX_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002118 .hsw.has_vga = true,
2119 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002120 },
2121};
2122
Imre Deakf28ec6f2018-08-06 12:58:37 +03002123static const struct i915_power_well_desc bdw_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002124 {
2125 .name = "always-on",
2126 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002127 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002128 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002129 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002130 },
2131 {
2132 .name = "display",
2133 .domains = BDW_DISPLAY_POWER_DOMAINS,
2134 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002135 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002136 {
Imre Deak75e39682018-08-06 12:58:39 +03002137 .hsw.regs = &hsw_power_well_regs,
2138 .hsw.idx = HSW_PW_CTL_IDX_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002139 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2140 .hsw.has_vga = true,
2141 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002142 },
2143};
2144
2145static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002146 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002147 .enable = vlv_display_power_well_enable,
2148 .disable = vlv_display_power_well_disable,
2149 .is_enabled = vlv_power_well_enabled,
2150};
2151
2152static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002153 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002154 .enable = vlv_dpio_cmn_power_well_enable,
2155 .disable = vlv_dpio_cmn_power_well_disable,
2156 .is_enabled = vlv_power_well_enabled,
2157};
2158
2159static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002160 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002161 .enable = vlv_power_well_enable,
2162 .disable = vlv_power_well_disable,
2163 .is_enabled = vlv_power_well_enabled,
2164};
2165
Imre Deakf28ec6f2018-08-06 12:58:37 +03002166static const struct i915_power_well_desc vlv_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002167 {
2168 .name = "always-on",
2169 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002170 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002171 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002172 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002173 },
2174 {
2175 .name = "display",
2176 .domains = VLV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002177 .ops = &vlv_display_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002178 .id = VLV_DISP_PW_DISP2D,
Imre Deakd13dd052018-08-06 12:58:38 +03002179 {
2180 .vlv.idx = PUNIT_PWGT_IDX_DISP2D,
2181 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002182 },
2183 {
2184 .name = "dpio-tx-b-01",
2185 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2186 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2187 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2188 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2189 .ops = &vlv_dpio_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002190 .id = DISP_PW_ID_NONE,
Imre Deakd13dd052018-08-06 12:58:38 +03002191 {
2192 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_B_LANES_01,
2193 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002194 },
2195 {
2196 .name = "dpio-tx-b-23",
2197 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2198 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2199 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2200 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2201 .ops = &vlv_dpio_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002202 .id = DISP_PW_ID_NONE,
Imre Deakd13dd052018-08-06 12:58:38 +03002203 {
2204 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_B_LANES_23,
2205 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002206 },
2207 {
2208 .name = "dpio-tx-c-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_C_LANES_01,
2217 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002218 },
2219 {
2220 .name = "dpio-tx-c-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_C_LANES_23,
2229 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002230 },
2231 {
2232 .name = "dpio-common",
2233 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002234 .ops = &vlv_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002235 .id = VLV_DISP_PW_DPIO_CMN_BC,
Imre Deakd13dd052018-08-06 12:58:38 +03002236 {
2237 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_BC,
2238 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002239 },
2240};
2241
Imre Deakf28ec6f2018-08-06 12:58:37 +03002242static const struct i915_power_well_desc chv_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002243 {
2244 .name = "always-on",
2245 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002246 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002247 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002248 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002249 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002250 {
2251 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002252 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002253 * Pipe A power well is the new disp2d well. Pipe B and C
2254 * power wells don't actually exist. Pipe A power well is
2255 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002256 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002257 .domains = CHV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002258 .ops = &chv_pipe_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002259 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002260 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002261 {
2262 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002263 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002264 .ops = &chv_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002265 .id = VLV_DISP_PW_DPIO_CMN_BC,
Imre Deakd13dd052018-08-06 12:58:38 +03002266 {
2267 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_BC,
2268 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002269 },
2270 {
2271 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002272 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002273 .ops = &chv_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002274 .id = CHV_DISP_PW_DPIO_CMN_D,
Imre Deakd13dd052018-08-06 12:58:38 +03002275 {
2276 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_D,
2277 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002278 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002279};
2280
Suketu Shah5aefb232015-04-16 14:22:10 +05302281bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002282 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302283{
2284 struct i915_power_well *power_well;
2285 bool ret;
2286
2287 power_well = lookup_power_well(dev_priv, power_well_id);
Imre Deakf28ec6f2018-08-06 12:58:37 +03002288 ret = power_well->desc->ops->is_enabled(dev_priv, power_well);
Suketu Shah5aefb232015-04-16 14:22:10 +05302289
2290 return ret;
2291}
2292
Imre Deakf28ec6f2018-08-06 12:58:37 +03002293static const struct i915_power_well_desc skl_power_wells[] = {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002294 {
2295 .name = "always-on",
2296 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002297 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002298 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002299 .id = DISP_PW_ID_NONE,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002300 },
2301 {
2302 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002303 /* Handled by the DMC firmware */
2304 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002305 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002306 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002307 {
Imre Deak75e39682018-08-06 12:58:39 +03002308 .hsw.regs = &hsw_power_well_regs,
2309 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002310 .hsw.has_fuses = true,
2311 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002312 },
2313 {
2314 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002315 /* Handled by the DMC firmware */
2316 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002317 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002318 .id = SKL_DISP_PW_MISC_IO,
Imre Deak75e39682018-08-06 12:58:39 +03002319 {
2320 .hsw.regs = &hsw_power_well_regs,
2321 .hsw.idx = SKL_PW_CTL_IDX_MISC_IO,
2322 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002323 },
2324 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002325 .name = "DC off",
2326 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2327 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002328 .id = DISP_PW_ID_NONE,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002329 },
2330 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002331 .name = "power well 2",
2332 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002333 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002334 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002335 {
Imre Deak75e39682018-08-06 12:58:39 +03002336 .hsw.regs = &hsw_power_well_regs,
2337 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002338 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2339 .hsw.has_vga = true,
2340 .hsw.has_fuses = true,
2341 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002342 },
2343 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002344 .name = "DDI A/E IO power well",
2345 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002346 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002347 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002348 {
2349 .hsw.regs = &hsw_power_well_regs,
2350 .hsw.idx = SKL_PW_CTL_IDX_DDI_A_E,
2351 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002352 },
2353 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002354 .name = "DDI B IO power well",
2355 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002356 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002357 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002358 {
2359 .hsw.regs = &hsw_power_well_regs,
2360 .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
2361 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002362 },
2363 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002364 .name = "DDI C IO power well",
2365 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002366 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002367 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002368 {
2369 .hsw.regs = &hsw_power_well_regs,
2370 .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
2371 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002372 },
2373 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002374 .name = "DDI D IO power well",
2375 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002376 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002377 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002378 {
2379 .hsw.regs = &hsw_power_well_regs,
2380 .hsw.idx = SKL_PW_CTL_IDX_DDI_D,
2381 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002382 },
2383};
2384
Imre Deakf28ec6f2018-08-06 12:58:37 +03002385static const struct i915_power_well_desc bxt_power_wells[] = {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302386 {
2387 .name = "always-on",
2388 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002389 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302390 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002391 .id = DISP_PW_ID_NONE,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302392 },
2393 {
2394 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002395 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002396 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002397 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002398 {
Imre Deak75e39682018-08-06 12:58:39 +03002399 .hsw.regs = &hsw_power_well_regs,
2400 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002401 .hsw.has_fuses = true,
2402 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302403 },
2404 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002405 .name = "DC off",
2406 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2407 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002408 .id = DISP_PW_ID_NONE,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002409 },
2410 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302411 .name = "power well 2",
2412 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002413 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002414 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002415 {
Imre Deak75e39682018-08-06 12:58:39 +03002416 .hsw.regs = &hsw_power_well_regs,
2417 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002418 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2419 .hsw.has_vga = true,
2420 .hsw.has_fuses = true,
2421 },
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002422 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002423 {
2424 .name = "dpio-common-a",
2425 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2426 .ops = &bxt_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002427 .id = BXT_DISP_PW_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002428 {
2429 .bxt.phy = DPIO_PHY1,
2430 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002431 },
2432 {
2433 .name = "dpio-common-bc",
2434 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2435 .ops = &bxt_dpio_cmn_power_well_ops,
Imre Deakd9fcdc82018-08-06 12:58:42 +03002436 .id = VLV_DISP_PW_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002437 {
2438 .bxt.phy = DPIO_PHY0,
2439 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002440 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302441};
2442
Imre Deakf28ec6f2018-08-06 12:58:37 +03002443static const struct i915_power_well_desc glk_power_wells[] = {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002444 {
2445 .name = "always-on",
2446 .always_on = 1,
2447 .domains = POWER_DOMAIN_MASK,
2448 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002449 .id = DISP_PW_ID_NONE,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002450 },
2451 {
2452 .name = "power well 1",
2453 /* Handled by the DMC firmware */
2454 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002455 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002456 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002457 {
Imre Deak75e39682018-08-06 12:58:39 +03002458 .hsw.regs = &hsw_power_well_regs,
2459 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002460 .hsw.has_fuses = true,
2461 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002462 },
2463 {
2464 .name = "DC off",
2465 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2466 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002467 .id = DISP_PW_ID_NONE,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002468 },
2469 {
2470 .name = "power well 2",
2471 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002472 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002473 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002474 {
Imre Deak75e39682018-08-06 12:58:39 +03002475 .hsw.regs = &hsw_power_well_regs,
2476 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002477 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2478 .hsw.has_vga = true,
2479 .hsw.has_fuses = true,
2480 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002481 },
2482 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002483 .name = "dpio-common-a",
2484 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2485 .ops = &bxt_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002486 .id = BXT_DISP_PW_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002487 {
2488 .bxt.phy = DPIO_PHY1,
2489 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002490 },
2491 {
2492 .name = "dpio-common-b",
2493 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2494 .ops = &bxt_dpio_cmn_power_well_ops,
Imre Deakd9fcdc82018-08-06 12:58:42 +03002495 .id = VLV_DISP_PW_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002496 {
2497 .bxt.phy = DPIO_PHY0,
2498 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002499 },
2500 {
2501 .name = "dpio-common-c",
2502 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2503 .ops = &bxt_dpio_cmn_power_well_ops,
Imre Deak2183b492018-08-06 12:58:41 +03002504 .id = GLK_DISP_PW_DPIO_CMN_C,
Imre Deak0a445942017-08-14 18:15:29 +03002505 {
2506 .bxt.phy = DPIO_PHY2,
2507 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002508 },
2509 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002510 .name = "AUX A",
2511 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002512 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002513 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002514 {
2515 .hsw.regs = &hsw_power_well_regs,
2516 .hsw.idx = GLK_PW_CTL_IDX_AUX_A,
2517 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002518 },
2519 {
2520 .name = "AUX B",
2521 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002522 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002523 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002524 {
2525 .hsw.regs = &hsw_power_well_regs,
2526 .hsw.idx = GLK_PW_CTL_IDX_AUX_B,
2527 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002528 },
2529 {
2530 .name = "AUX C",
2531 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002532 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002533 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002534 {
2535 .hsw.regs = &hsw_power_well_regs,
2536 .hsw.idx = GLK_PW_CTL_IDX_AUX_C,
2537 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002538 },
2539 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002540 .name = "DDI A IO power well",
2541 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002542 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002543 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002544 {
2545 .hsw.regs = &hsw_power_well_regs,
2546 .hsw.idx = GLK_PW_CTL_IDX_DDI_A,
2547 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002548 },
2549 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002550 .name = "DDI B IO power well",
2551 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002552 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002553 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002554 {
2555 .hsw.regs = &hsw_power_well_regs,
2556 .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
2557 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002558 },
2559 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002560 .name = "DDI C IO power well",
2561 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002562 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002563 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002564 {
2565 .hsw.regs = &hsw_power_well_regs,
2566 .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
2567 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002568 },
2569};
2570
Imre Deakf28ec6f2018-08-06 12:58:37 +03002571static const struct i915_power_well_desc cnl_power_wells[] = {
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002572 {
2573 .name = "always-on",
2574 .always_on = 1,
2575 .domains = POWER_DOMAIN_MASK,
2576 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002577 .id = DISP_PW_ID_NONE,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002578 },
2579 {
2580 .name = "power well 1",
2581 /* Handled by the DMC firmware */
2582 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002583 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002584 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002585 {
Imre Deak75e39682018-08-06 12:58:39 +03002586 .hsw.regs = &hsw_power_well_regs,
2587 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002588 .hsw.has_fuses = true,
2589 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002590 },
2591 {
2592 .name = "AUX A",
2593 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002594 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002595 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002596 {
2597 .hsw.regs = &hsw_power_well_regs,
2598 .hsw.idx = GLK_PW_CTL_IDX_AUX_A,
2599 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002600 },
2601 {
2602 .name = "AUX B",
2603 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002604 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002605 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002606 {
2607 .hsw.regs = &hsw_power_well_regs,
2608 .hsw.idx = GLK_PW_CTL_IDX_AUX_B,
2609 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002610 },
2611 {
2612 .name = "AUX C",
2613 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002614 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002615 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002616 {
2617 .hsw.regs = &hsw_power_well_regs,
2618 .hsw.idx = GLK_PW_CTL_IDX_AUX_C,
2619 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002620 },
2621 {
2622 .name = "AUX D",
2623 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002624 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002625 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002626 {
2627 .hsw.regs = &hsw_power_well_regs,
2628 .hsw.idx = CNL_PW_CTL_IDX_AUX_D,
2629 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002630 },
2631 {
2632 .name = "DC off",
2633 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2634 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002635 .id = DISP_PW_ID_NONE,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002636 },
2637 {
2638 .name = "power well 2",
2639 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002640 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002641 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002642 {
Imre Deak75e39682018-08-06 12:58:39 +03002643 .hsw.regs = &hsw_power_well_regs,
2644 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002645 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2646 .hsw.has_vga = true,
2647 .hsw.has_fuses = true,
2648 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002649 },
2650 {
2651 .name = "DDI A IO power well",
2652 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002653 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002654 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002655 {
2656 .hsw.regs = &hsw_power_well_regs,
2657 .hsw.idx = GLK_PW_CTL_IDX_DDI_A,
2658 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002659 },
2660 {
2661 .name = "DDI B IO power well",
2662 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002663 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002664 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002665 {
2666 .hsw.regs = &hsw_power_well_regs,
2667 .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
2668 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002669 },
2670 {
2671 .name = "DDI C IO power well",
2672 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002673 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002674 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002675 {
2676 .hsw.regs = &hsw_power_well_regs,
2677 .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
2678 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002679 },
2680 {
2681 .name = "DDI D IO power well",
2682 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002683 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002684 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002685 {
2686 .hsw.regs = &hsw_power_well_regs,
2687 .hsw.idx = SKL_PW_CTL_IDX_DDI_D,
2688 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002689 },
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002690 {
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002691 .name = "DDI F IO power well",
2692 .domains = CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS,
2693 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002694 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002695 {
2696 .hsw.regs = &hsw_power_well_regs,
2697 .hsw.idx = CNL_PW_CTL_IDX_DDI_F,
2698 },
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002699 },
2700 {
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002701 .name = "AUX F",
2702 .domains = CNL_DISPLAY_AUX_F_POWER_DOMAINS,
2703 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002704 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002705 {
2706 .hsw.regs = &hsw_power_well_regs,
2707 .hsw.idx = CNL_PW_CTL_IDX_AUX_F,
2708 },
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002709 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002710};
2711
Imre Deak67ca07e2018-06-26 17:22:32 +03002712static const struct i915_power_well_ops icl_combo_phy_aux_power_well_ops = {
2713 .sync_hw = hsw_power_well_sync_hw,
2714 .enable = icl_combo_phy_aux_power_well_enable,
2715 .disable = icl_combo_phy_aux_power_well_disable,
2716 .is_enabled = hsw_power_well_enabled,
2717};
2718
Imre Deak75e39682018-08-06 12:58:39 +03002719static const struct i915_power_well_regs icl_aux_power_well_regs = {
2720 .bios = ICL_PWR_WELL_CTL_AUX1,
2721 .driver = ICL_PWR_WELL_CTL_AUX2,
2722 .debug = ICL_PWR_WELL_CTL_AUX4,
2723};
2724
2725static const struct i915_power_well_regs icl_ddi_power_well_regs = {
2726 .bios = ICL_PWR_WELL_CTL_DDI1,
2727 .driver = ICL_PWR_WELL_CTL_DDI2,
2728 .debug = ICL_PWR_WELL_CTL_DDI4,
2729};
2730
Imre Deakf28ec6f2018-08-06 12:58:37 +03002731static const struct i915_power_well_desc icl_power_wells[] = {
Imre Deak67ca07e2018-06-26 17:22:32 +03002732 {
2733 .name = "always-on",
2734 .always_on = 1,
2735 .domains = POWER_DOMAIN_MASK,
2736 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002737 .id = DISP_PW_ID_NONE,
Imre Deak67ca07e2018-06-26 17:22:32 +03002738 },
2739 {
2740 .name = "power well 1",
2741 /* Handled by the DMC firmware */
2742 .domains = 0,
2743 .ops = &hsw_power_well_ops,
Imre Deakd9fcdc82018-08-06 12:58:42 +03002744 .id = SKL_DISP_PW_1,
Imre Deakae9b06c2018-08-06 12:58:34 +03002745 {
Imre Deak75e39682018-08-06 12:58:39 +03002746 .hsw.regs = &hsw_power_well_regs,
2747 .hsw.idx = ICL_PW_CTL_IDX_PW_1,
Imre Deakae9b06c2018-08-06 12:58:34 +03002748 .hsw.has_fuses = true,
2749 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002750 },
2751 {
2752 .name = "power well 2",
2753 .domains = ICL_PW_2_POWER_DOMAINS,
2754 .ops = &hsw_power_well_ops,
Imre Deakd9fcdc82018-08-06 12:58:42 +03002755 .id = SKL_DISP_PW_2,
Imre Deakae9b06c2018-08-06 12:58:34 +03002756 {
Imre Deak75e39682018-08-06 12:58:39 +03002757 .hsw.regs = &hsw_power_well_regs,
2758 .hsw.idx = ICL_PW_CTL_IDX_PW_2,
Imre Deakae9b06c2018-08-06 12:58:34 +03002759 .hsw.has_fuses = true,
2760 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002761 },
2762 {
2763 .name = "DC off",
2764 .domains = ICL_DISPLAY_DC_OFF_POWER_DOMAINS,
2765 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002766 .id = DISP_PW_ID_NONE,
Imre Deak67ca07e2018-06-26 17:22:32 +03002767 },
2768 {
2769 .name = "power well 3",
2770 .domains = ICL_PW_3_POWER_DOMAINS,
2771 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002772 .id = DISP_PW_ID_NONE,
Imre Deakae9b06c2018-08-06 12:58:34 +03002773 {
Imre Deak75e39682018-08-06 12:58:39 +03002774 .hsw.regs = &hsw_power_well_regs,
2775 .hsw.idx = ICL_PW_CTL_IDX_PW_3,
Imre Deakae9b06c2018-08-06 12:58:34 +03002776 .hsw.irq_pipe_mask = BIT(PIPE_B),
2777 .hsw.has_vga = true,
2778 .hsw.has_fuses = true,
2779 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002780 },
2781 {
2782 .name = "DDI A IO",
2783 .domains = ICL_DDI_IO_A_POWER_DOMAINS,
2784 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002785 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002786 {
2787 .hsw.regs = &icl_ddi_power_well_regs,
2788 .hsw.idx = ICL_PW_CTL_IDX_DDI_A,
2789 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002790 },
2791 {
2792 .name = "DDI B IO",
2793 .domains = ICL_DDI_IO_B_POWER_DOMAINS,
2794 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002795 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002796 {
2797 .hsw.regs = &icl_ddi_power_well_regs,
2798 .hsw.idx = ICL_PW_CTL_IDX_DDI_B,
2799 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002800 },
2801 {
2802 .name = "DDI C IO",
2803 .domains = ICL_DDI_IO_C_POWER_DOMAINS,
2804 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002805 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002806 {
2807 .hsw.regs = &icl_ddi_power_well_regs,
2808 .hsw.idx = ICL_PW_CTL_IDX_DDI_C,
2809 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002810 },
2811 {
2812 .name = "DDI D IO",
2813 .domains = ICL_DDI_IO_D_POWER_DOMAINS,
2814 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002815 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002816 {
2817 .hsw.regs = &icl_ddi_power_well_regs,
2818 .hsw.idx = ICL_PW_CTL_IDX_DDI_D,
2819 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002820 },
2821 {
2822 .name = "DDI E IO",
2823 .domains = ICL_DDI_IO_E_POWER_DOMAINS,
2824 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002825 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002826 {
2827 .hsw.regs = &icl_ddi_power_well_regs,
2828 .hsw.idx = ICL_PW_CTL_IDX_DDI_E,
2829 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002830 },
2831 {
2832 .name = "DDI F IO",
2833 .domains = ICL_DDI_IO_F_POWER_DOMAINS,
2834 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002835 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002836 {
2837 .hsw.regs = &icl_ddi_power_well_regs,
2838 .hsw.idx = ICL_PW_CTL_IDX_DDI_F,
2839 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002840 },
2841 {
2842 .name = "AUX A",
2843 .domains = ICL_AUX_A_IO_POWER_DOMAINS,
2844 .ops = &icl_combo_phy_aux_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002845 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002846 {
2847 .hsw.regs = &icl_aux_power_well_regs,
2848 .hsw.idx = ICL_PW_CTL_IDX_AUX_A,
2849 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002850 },
2851 {
2852 .name = "AUX B",
2853 .domains = ICL_AUX_B_IO_POWER_DOMAINS,
2854 .ops = &icl_combo_phy_aux_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002855 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002856 {
2857 .hsw.regs = &icl_aux_power_well_regs,
2858 .hsw.idx = ICL_PW_CTL_IDX_AUX_B,
2859 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002860 },
2861 {
2862 .name = "AUX C",
2863 .domains = ICL_AUX_C_IO_POWER_DOMAINS,
2864 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002865 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002866 {
2867 .hsw.regs = &icl_aux_power_well_regs,
2868 .hsw.idx = ICL_PW_CTL_IDX_AUX_C,
2869 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002870 },
2871 {
2872 .name = "AUX D",
2873 .domains = ICL_AUX_D_IO_POWER_DOMAINS,
2874 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002875 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002876 {
2877 .hsw.regs = &icl_aux_power_well_regs,
2878 .hsw.idx = ICL_PW_CTL_IDX_AUX_D,
2879 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002880 },
2881 {
2882 .name = "AUX E",
2883 .domains = ICL_AUX_E_IO_POWER_DOMAINS,
2884 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002885 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002886 {
2887 .hsw.regs = &icl_aux_power_well_regs,
2888 .hsw.idx = ICL_PW_CTL_IDX_AUX_E,
2889 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002890 },
2891 {
2892 .name = "AUX F",
2893 .domains = ICL_AUX_F_IO_POWER_DOMAINS,
2894 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002895 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002896 {
2897 .hsw.regs = &icl_aux_power_well_regs,
2898 .hsw.idx = ICL_PW_CTL_IDX_AUX_F,
2899 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002900 },
2901 {
2902 .name = "AUX TBT1",
2903 .domains = ICL_AUX_TBT1_IO_POWER_DOMAINS,
2904 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002905 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002906 {
2907 .hsw.regs = &icl_aux_power_well_regs,
2908 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT1,
2909 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002910 },
2911 {
2912 .name = "AUX TBT2",
2913 .domains = ICL_AUX_TBT2_IO_POWER_DOMAINS,
2914 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002915 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002916 {
2917 .hsw.regs = &icl_aux_power_well_regs,
2918 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT2,
2919 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002920 },
2921 {
2922 .name = "AUX TBT3",
2923 .domains = ICL_AUX_TBT3_IO_POWER_DOMAINS,
2924 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002925 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002926 {
2927 .hsw.regs = &icl_aux_power_well_regs,
2928 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT3,
2929 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002930 },
2931 {
2932 .name = "AUX TBT4",
2933 .domains = ICL_AUX_TBT4_IO_POWER_DOMAINS,
2934 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002935 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002936 {
2937 .hsw.regs = &icl_aux_power_well_regs,
2938 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT4,
2939 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002940 },
2941 {
2942 .name = "power well 4",
2943 .domains = ICL_PW_4_POWER_DOMAINS,
2944 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002945 .id = DISP_PW_ID_NONE,
Imre Deakae9b06c2018-08-06 12:58:34 +03002946 {
Imre Deak75e39682018-08-06 12:58:39 +03002947 .hsw.regs = &hsw_power_well_regs,
2948 .hsw.idx = ICL_PW_CTL_IDX_PW_4,
Imre Deakae9b06c2018-08-06 12:58:34 +03002949 .hsw.has_fuses = true,
2950 .hsw.irq_pipe_mask = BIT(PIPE_C),
2951 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002952 },
2953};
2954
Imre Deak1b0e3a02015-11-05 23:04:11 +02002955static int
2956sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2957 int disable_power_well)
2958{
2959 if (disable_power_well >= 0)
2960 return !!disable_power_well;
2961
Imre Deak1b0e3a02015-11-05 23:04:11 +02002962 return 1;
2963}
2964
Imre Deaka37baf32016-02-29 22:49:03 +02002965static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2966 int enable_dc)
2967{
2968 uint32_t mask;
2969 int requested_dc;
2970 int max_dc;
2971
Imre Deak67ca07e2018-06-26 17:22:32 +03002972 if (IS_GEN9_BC(dev_priv) || INTEL_INFO(dev_priv)->gen >= 10) {
Imre Deaka37baf32016-02-29 22:49:03 +02002973 max_dc = 2;
2974 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002975 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002976 max_dc = 1;
2977 /*
2978 * DC9 has a separate HW flow from the rest of the DC states,
2979 * not depending on the DMC firmware. It's needed by system
2980 * suspend/resume, so allow it unconditionally.
2981 */
2982 mask = DC_STATE_EN_DC9;
2983 } else {
2984 max_dc = 0;
2985 mask = 0;
2986 }
2987
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002988 if (!i915_modparams.disable_power_well)
Imre Deak66e2c4c2016-02-29 22:49:04 +02002989 max_dc = 0;
2990
Imre Deaka37baf32016-02-29 22:49:03 +02002991 if (enable_dc >= 0 && enable_dc <= max_dc) {
2992 requested_dc = enable_dc;
2993 } else if (enable_dc == -1) {
2994 requested_dc = max_dc;
2995 } else if (enable_dc > max_dc && enable_dc <= 2) {
2996 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2997 enable_dc, max_dc);
2998 requested_dc = max_dc;
2999 } else {
3000 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
3001 requested_dc = max_dc;
3002 }
3003
3004 if (requested_dc > 1)
3005 mask |= DC_STATE_EN_UPTO_DC6;
3006 if (requested_dc > 0)
3007 mask |= DC_STATE_EN_UPTO_DC5;
3008
3009 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
3010
3011 return mask;
3012}
3013
Imre Deakf28ec6f2018-08-06 12:58:37 +03003014static int
3015__set_power_wells(struct i915_power_domains *power_domains,
3016 const struct i915_power_well_desc *power_well_descs,
3017 int power_well_count)
Imre Deak21792c62017-07-11 23:42:33 +03003018{
Imre Deakf28ec6f2018-08-06 12:58:37 +03003019 u64 power_well_ids = 0;
Imre Deak21792c62017-07-11 23:42:33 +03003020 int i;
3021
Imre Deakf28ec6f2018-08-06 12:58:37 +03003022 power_domains->power_well_count = power_well_count;
3023 power_domains->power_wells =
3024 kcalloc(power_well_count,
3025 sizeof(*power_domains->power_wells),
3026 GFP_KERNEL);
3027 if (!power_domains->power_wells)
3028 return -ENOMEM;
3029
3030 for (i = 0; i < power_well_count; i++) {
3031 enum i915_power_well_id id = power_well_descs[i].id;
3032
3033 power_domains->power_wells[i].desc = &power_well_descs[i];
Imre Deak21792c62017-07-11 23:42:33 +03003034
Imre Deak4739a9d2018-08-06 12:58:40 +03003035 if (id == DISP_PW_ID_NONE)
3036 continue;
3037
Imre Deak21792c62017-07-11 23:42:33 +03003038 WARN_ON(id >= sizeof(power_well_ids) * 8);
3039 WARN_ON(power_well_ids & BIT_ULL(id));
3040 power_well_ids |= BIT_ULL(id);
3041 }
Imre Deakf28ec6f2018-08-06 12:58:37 +03003042
3043 return 0;
Imre Deak21792c62017-07-11 23:42:33 +03003044}
3045
Imre Deakf28ec6f2018-08-06 12:58:37 +03003046#define set_power_wells(power_domains, __power_well_descs) \
3047 __set_power_wells(power_domains, __power_well_descs, \
3048 ARRAY_SIZE(__power_well_descs))
Daniel Vetter9c065a72014-09-30 10:56:38 +02003049
Daniel Vettere4e76842014-09-30 10:56:42 +02003050/**
3051 * intel_power_domains_init - initializes the power domain structures
3052 * @dev_priv: i915 device instance
3053 *
3054 * Initializes the power domain structures for @dev_priv depending upon the
3055 * supported platform.
3056 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003057int intel_power_domains_init(struct drm_i915_private *dev_priv)
3058{
3059 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deakf28ec6f2018-08-06 12:58:37 +03003060 int err;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003061
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003062 i915_modparams.disable_power_well =
3063 sanitize_disable_power_well_option(dev_priv,
3064 i915_modparams.disable_power_well);
3065 dev_priv->csr.allowed_dc_mask =
3066 get_allowed_dc_mask(dev_priv, i915_modparams.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02003067
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02003068 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01003069
Daniel Vetter9c065a72014-09-30 10:56:38 +02003070 mutex_init(&power_domains->lock);
3071
3072 /*
3073 * The enabling order will be from lower to higher indexed wells,
3074 * the disabling order is reversed.
3075 */
Imre Deak67ca07e2018-06-26 17:22:32 +03003076 if (IS_ICELAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003077 err = set_power_wells(power_domains, icl_power_wells);
Imre Deak67ca07e2018-06-26 17:22:32 +03003078 } else if (IS_HASWELL(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003079 err = set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003080 } else if (IS_BROADWELL(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003081 err = set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08003082 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003083 err = set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07003084 } else if (IS_CANNONLAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003085 err = set_power_wells(power_domains, cnl_power_wells);
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003086
3087 /*
Rodrigo Vivi9787e832018-01-29 15:22:22 -08003088 * DDI and Aux IO are getting enabled for all ports
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003089 * regardless the presence or use. So, in order to avoid
Rodrigo Vivi9787e832018-01-29 15:22:22 -08003090 * timeouts, lets remove them from the list
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003091 * for the SKUs without port F.
3092 */
3093 if (!IS_CNL_WITH_PORT_F(dev_priv))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08003094 power_domains->power_well_count -= 2;
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003095
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003096 } else if (IS_BROXTON(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003097 err = set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02003098 } else if (IS_GEMINILAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003099 err = set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003100 } else if (IS_CHERRYVIEW(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003101 err = set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003102 } else if (IS_VALLEYVIEW(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003103 err = set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03003104 } else if (IS_I830(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003105 err = set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003106 } else {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003107 err = set_power_wells(power_domains, i9xx_always_on_power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003108 }
3109
Imre Deakf28ec6f2018-08-06 12:58:37 +03003110 return err;
3111}
Imre Deak21792c62017-07-11 23:42:33 +03003112
Imre Deakf28ec6f2018-08-06 12:58:37 +03003113/**
3114 * intel_power_domains_cleanup - clean up power domains resources
3115 * @dev_priv: i915 device instance
3116 *
3117 * Release any resources acquired by intel_power_domains_init()
3118 */
3119void intel_power_domains_cleanup(struct drm_i915_private *dev_priv)
3120{
3121 kfree(dev_priv->power_domains.power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003122}
3123
Imre Deak30eade12015-11-04 19:24:13 +02003124static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003125{
3126 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3127 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003128
3129 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02003130 for_each_power_well(dev_priv, power_well) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003131 power_well->desc->ops->sync_hw(dev_priv, power_well);
3132 power_well->hw_enabled =
3133 power_well->desc->ops->is_enabled(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003134 }
3135 mutex_unlock(&power_domains->lock);
3136}
3137
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303138static inline
3139bool intel_dbuf_slice_set(struct drm_i915_private *dev_priv,
3140 i915_reg_t reg, bool enable)
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003141{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303142 u32 val, status;
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003143
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303144 val = I915_READ(reg);
3145 val = enable ? (val | DBUF_POWER_REQUEST) : (val & ~DBUF_POWER_REQUEST);
3146 I915_WRITE(reg, val);
3147 POSTING_READ(reg);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003148 udelay(10);
3149
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303150 status = I915_READ(reg) & DBUF_POWER_STATE;
3151 if ((enable && !status) || (!enable && status)) {
3152 DRM_ERROR("DBus power %s timeout!\n",
3153 enable ? "enable" : "disable");
3154 return false;
3155 }
3156 return true;
3157}
3158
3159static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
3160{
3161 intel_dbuf_slice_set(dev_priv, DBUF_CTL, true);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003162}
3163
3164static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
3165{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303166 intel_dbuf_slice_set(dev_priv, DBUF_CTL, false);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003167}
3168
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303169static u8 intel_dbuf_max_slices(struct drm_i915_private *dev_priv)
3170{
3171 if (INTEL_GEN(dev_priv) < 11)
3172 return 1;
3173 return 2;
3174}
3175
3176void icl_dbuf_slices_update(struct drm_i915_private *dev_priv,
3177 u8 req_slices)
3178{
3179 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
3180 u32 val;
3181 bool ret;
3182
3183 if (req_slices > intel_dbuf_max_slices(dev_priv)) {
3184 DRM_ERROR("Invalid number of dbuf slices requested\n");
3185 return;
3186 }
3187
3188 if (req_slices == hw_enabled_slices || req_slices == 0)
3189 return;
3190
3191 val = I915_READ(DBUF_CTL_S2);
3192 if (req_slices > hw_enabled_slices)
3193 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, true);
3194 else
3195 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, false);
3196
3197 if (ret)
3198 dev_priv->wm.skl_hw.ddb.enabled_slices = req_slices;
3199}
3200
Mahesh Kumar746edf82018-02-05 13:40:44 -02003201static void icl_dbuf_enable(struct drm_i915_private *dev_priv)
3202{
3203 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) | DBUF_POWER_REQUEST);
3204 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) | DBUF_POWER_REQUEST);
3205 POSTING_READ(DBUF_CTL_S2);
3206
3207 udelay(10);
3208
3209 if (!(I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
3210 !(I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
3211 DRM_ERROR("DBuf power enable timeout\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303212 else
3213 dev_priv->wm.skl_hw.ddb.enabled_slices = 2;
Mahesh Kumar746edf82018-02-05 13:40:44 -02003214}
3215
3216static void icl_dbuf_disable(struct drm_i915_private *dev_priv)
3217{
3218 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) & ~DBUF_POWER_REQUEST);
3219 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) & ~DBUF_POWER_REQUEST);
3220 POSTING_READ(DBUF_CTL_S2);
3221
3222 udelay(10);
3223
3224 if ((I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
3225 (I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
3226 DRM_ERROR("DBuf power disable timeout!\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303227 else
3228 dev_priv->wm.skl_hw.ddb.enabled_slices = 0;
Mahesh Kumar746edf82018-02-05 13:40:44 -02003229}
3230
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003231static void icl_mbus_init(struct drm_i915_private *dev_priv)
3232{
3233 uint32_t val;
3234
3235 val = MBUS_ABOX_BT_CREDIT_POOL1(16) |
3236 MBUS_ABOX_BT_CREDIT_POOL2(16) |
3237 MBUS_ABOX_B_CREDIT(1) |
3238 MBUS_ABOX_BW_CREDIT(1);
3239
3240 I915_WRITE(MBUS_ABOX_CTL, val);
3241}
3242
Imre Deak73dfc222015-11-17 17:33:53 +02003243static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03003244 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02003245{
3246 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003247 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003248 uint32_t val;
3249
Imre Deakd26fa1d2015-11-04 19:24:17 +02003250 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3251
Imre Deak73dfc222015-11-17 17:33:53 +02003252 /* enable PCH reset handshake */
3253 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3254 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
3255
3256 /* enable PG1 and Misc I/O */
3257 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003258
3259 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3260 intel_power_well_enable(dev_priv, well);
3261
3262 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
3263 intel_power_well_enable(dev_priv, well);
3264
Imre Deak73dfc222015-11-17 17:33:53 +02003265 mutex_unlock(&power_domains->lock);
3266
Imre Deak73dfc222015-11-17 17:33:53 +02003267 skl_init_cdclk(dev_priv);
3268
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003269 gen9_dbuf_enable(dev_priv);
3270
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03003271 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02003272 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003273}
3274
3275static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
3276{
3277 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003278 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003279
Imre Deakd26fa1d2015-11-04 19:24:17 +02003280 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3281
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003282 gen9_dbuf_disable(dev_priv);
3283
Imre Deak73dfc222015-11-17 17:33:53 +02003284 skl_uninit_cdclk(dev_priv);
3285
3286 /* The spec doesn't call for removing the reset handshake flag */
3287 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03003288
Imre Deak73dfc222015-11-17 17:33:53 +02003289 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003290
Imre Deakedfda8e2017-06-29 18:36:59 +03003291 /*
3292 * BSpec says to keep the MISC IO power well enabled here, only
3293 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03003294 * Note that even though the driver's request is removed power well 1
3295 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03003296 */
Imre Deak443a93a2016-04-04 15:42:57 +03003297 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3298 intel_power_well_disable(dev_priv, well);
3299
Imre Deak73dfc222015-11-17 17:33:53 +02003300 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003301
3302 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02003303}
3304
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003305void bxt_display_core_init(struct drm_i915_private *dev_priv,
3306 bool resume)
3307{
3308 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3309 struct i915_power_well *well;
3310 uint32_t val;
3311
3312 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3313
3314 /*
3315 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
3316 * or else the reset will hang because there is no PCH to respond.
3317 * Move the handshake programming to initialization sequence.
3318 * Previously was left up to BIOS.
3319 */
3320 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3321 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
3322 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3323
3324 /* Enable PG1 */
3325 mutex_lock(&power_domains->lock);
3326
3327 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3328 intel_power_well_enable(dev_priv, well);
3329
3330 mutex_unlock(&power_domains->lock);
3331
Imre Deak324513c2016-06-13 16:44:36 +03003332 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003333
3334 gen9_dbuf_enable(dev_priv);
3335
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003336 if (resume && dev_priv->csr.dmc_payload)
3337 intel_csr_load_program(dev_priv);
3338}
3339
3340void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
3341{
3342 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3343 struct i915_power_well *well;
3344
3345 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3346
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003347 gen9_dbuf_disable(dev_priv);
3348
Imre Deak324513c2016-06-13 16:44:36 +03003349 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003350
3351 /* The spec doesn't call for removing the reset handshake flag */
3352
Imre Deak42d93662017-06-29 18:37:01 +03003353 /*
3354 * Disable PW1 (PG1).
3355 * Note that even though the driver's request is removed power well 1
3356 * may stay enabled after this due to DMC's own request on it.
3357 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003358 mutex_lock(&power_domains->lock);
3359
3360 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3361 intel_power_well_disable(dev_priv, well);
3362
3363 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003364
3365 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003366}
3367
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003368enum {
3369 PROCMON_0_85V_DOT_0,
3370 PROCMON_0_95V_DOT_0,
3371 PROCMON_0_95V_DOT_1,
3372 PROCMON_1_05V_DOT_0,
3373 PROCMON_1_05V_DOT_1,
3374};
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003375
3376static const struct cnl_procmon {
3377 u32 dw1, dw9, dw10;
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003378} cnl_procmon_values[] = {
3379 [PROCMON_0_85V_DOT_0] =
3380 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
3381 [PROCMON_0_95V_DOT_0] =
3382 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
3383 [PROCMON_0_95V_DOT_1] =
3384 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
3385 [PROCMON_1_05V_DOT_0] =
3386 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
3387 [PROCMON_1_05V_DOT_1] =
3388 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003389};
3390
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003391/*
3392 * CNL has just one set of registers, while ICL has two sets: one for port A and
3393 * the other for port B. The CNL registers are equivalent to the ICL port A
3394 * registers, that's why we call the ICL macros even though the function has CNL
3395 * on its name.
3396 */
3397static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
3398 enum port port)
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003399{
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003400 const struct cnl_procmon *procmon;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003401 u32 val;
3402
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003403 val = I915_READ(ICL_PORT_COMP_DW3(port));
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003404 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
3405 default:
3406 MISSING_CASE(val);
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05003407 /* fall through */
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003408 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
3409 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
3410 break;
3411 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
3412 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
3413 break;
3414 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
3415 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
3416 break;
3417 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
3418 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
3419 break;
3420 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
3421 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
3422 break;
3423 }
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003424
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003425 val = I915_READ(ICL_PORT_COMP_DW1(port));
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003426 val &= ~((0xff << 16) | 0xff);
3427 val |= procmon->dw1;
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003428 I915_WRITE(ICL_PORT_COMP_DW1(port), val);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003429
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003430 I915_WRITE(ICL_PORT_COMP_DW9(port), procmon->dw9);
3431 I915_WRITE(ICL_PORT_COMP_DW10(port), procmon->dw10);
Paulo Zanoniade5ee72017-08-21 17:03:56 -07003432}
3433
3434static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
3435{
3436 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3437 struct i915_power_well *well;
3438 u32 val;
3439
3440 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3441
3442 /* 1. Enable PCH Reset Handshake */
3443 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3444 val |= RESET_PCH_HANDSHAKE_ENABLE;
3445 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3446
3447 /* 2. Enable Comp */
3448 val = I915_READ(CHICKEN_MISC_2);
3449 val &= ~CNL_COMP_PWR_DOWN;
3450 I915_WRITE(CHICKEN_MISC_2, val);
3451
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003452 /* Dummy PORT_A to get the correct CNL register from the ICL macro */
3453 cnl_set_procmon_ref_values(dev_priv, PORT_A);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003454
3455 val = I915_READ(CNL_PORT_COMP_DW0);
3456 val |= COMP_INIT;
3457 I915_WRITE(CNL_PORT_COMP_DW0, val);
3458
3459 /* 3. */
3460 val = I915_READ(CNL_PORT_CL1CM_DW5);
3461 val |= CL_POWER_DOWN_ENABLE;
3462 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
3463
Imre Deakb38131f2017-06-29 18:37:02 +03003464 /*
3465 * 4. Enable Power Well 1 (PG1).
3466 * The AUX IO power wells will be enabled on demand.
3467 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003468 mutex_lock(&power_domains->lock);
3469 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3470 intel_power_well_enable(dev_priv, well);
3471 mutex_unlock(&power_domains->lock);
3472
3473 /* 5. Enable CD clock */
3474 cnl_init_cdclk(dev_priv);
3475
3476 /* 6. Enable DBUF */
3477 gen9_dbuf_enable(dev_priv);
Imre Deak57522c42017-10-03 12:51:58 +03003478
3479 if (resume && dev_priv->csr.dmc_payload)
3480 intel_csr_load_program(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003481}
3482
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003483static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
3484{
3485 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3486 struct i915_power_well *well;
3487 u32 val;
3488
3489 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3490
3491 /* 1. Disable all display engine functions -> aready done */
3492
3493 /* 2. Disable DBUF */
3494 gen9_dbuf_disable(dev_priv);
3495
3496 /* 3. Disable CD clock */
3497 cnl_uninit_cdclk(dev_priv);
3498
Imre Deakb38131f2017-06-29 18:37:02 +03003499 /*
3500 * 4. Disable Power Well 1 (PG1).
3501 * The AUX IO power wells are toggled on demand, so they are already
3502 * disabled at this point.
3503 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003504 mutex_lock(&power_domains->lock);
3505 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3506 intel_power_well_disable(dev_priv, well);
3507 mutex_unlock(&power_domains->lock);
3508
Imre Deak846c6b22017-06-29 18:36:58 +03003509 usleep_range(10, 30); /* 10 us delay per Bspec */
3510
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003511 /* 5. Disable Comp */
3512 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03003513 val |= CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003514 I915_WRITE(CHICKEN_MISC_2, val);
3515}
3516
Paulo Zanoniad186f32018-02-05 13:40:43 -02003517static void icl_display_core_init(struct drm_i915_private *dev_priv,
3518 bool resume)
3519{
Imre Deak67ca07e2018-06-26 17:22:32 +03003520 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3521 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003522 enum port port;
3523 u32 val;
3524
3525 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3526
3527 /* 1. Enable PCH reset handshake. */
3528 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3529 val |= RESET_PCH_HANDSHAKE_ENABLE;
3530 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3531
3532 for (port = PORT_A; port <= PORT_B; port++) {
3533 /* 2. Enable DDI combo PHY comp. */
3534 val = I915_READ(ICL_PHY_MISC(port));
3535 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3536 I915_WRITE(ICL_PHY_MISC(port), val);
3537
3538 cnl_set_procmon_ref_values(dev_priv, port);
3539
3540 val = I915_READ(ICL_PORT_COMP_DW0(port));
3541 val |= COMP_INIT;
3542 I915_WRITE(ICL_PORT_COMP_DW0(port), val);
3543
3544 /* 3. Set power down enable. */
3545 val = I915_READ(ICL_PORT_CL_DW5(port));
3546 val |= CL_POWER_DOWN_ENABLE;
3547 I915_WRITE(ICL_PORT_CL_DW5(port), val);
3548 }
3549
Imre Deak67ca07e2018-06-26 17:22:32 +03003550 /*
3551 * 4. Enable Power Well 1 (PG1).
3552 * The AUX IO power wells will be enabled on demand.
3553 */
3554 mutex_lock(&power_domains->lock);
Imre Deakd9fcdc82018-08-06 12:58:42 +03003555 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
Imre Deak67ca07e2018-06-26 17:22:32 +03003556 intel_power_well_enable(dev_priv, well);
3557 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003558
3559 /* 5. Enable CDCLK. */
3560 icl_init_cdclk(dev_priv);
3561
3562 /* 6. Enable DBUF. */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003563 icl_dbuf_enable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003564
3565 /* 7. Setup MBUS. */
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003566 icl_mbus_init(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003567}
3568
3569static void icl_display_core_uninit(struct drm_i915_private *dev_priv)
3570{
Imre Deak67ca07e2018-06-26 17:22:32 +03003571 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3572 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003573 enum port port;
3574 u32 val;
3575
3576 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3577
3578 /* 1. Disable all display engine functions -> aready done */
3579
3580 /* 2. Disable DBUF */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003581 icl_dbuf_disable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003582
3583 /* 3. Disable CD clock */
3584 icl_uninit_cdclk(dev_priv);
3585
Imre Deak67ca07e2018-06-26 17:22:32 +03003586 /*
3587 * 4. Disable Power Well 1 (PG1).
3588 * The AUX IO power wells are toggled on demand, so they are already
3589 * disabled at this point.
3590 */
3591 mutex_lock(&power_domains->lock);
Imre Deakd9fcdc82018-08-06 12:58:42 +03003592 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
Imre Deak67ca07e2018-06-26 17:22:32 +03003593 intel_power_well_disable(dev_priv, well);
3594 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003595
3596 /* 5. Disable Comp */
3597 for (port = PORT_A; port <= PORT_B; port++) {
3598 val = I915_READ(ICL_PHY_MISC(port));
3599 val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3600 I915_WRITE(ICL_PHY_MISC(port), val);
3601 }
3602}
3603
Ville Syrjälä70722462015-04-10 18:21:28 +03003604static void chv_phy_control_init(struct drm_i915_private *dev_priv)
3605{
3606 struct i915_power_well *cmn_bc =
Imre Deak2183b492018-08-06 12:58:41 +03003607 lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
Ville Syrjälä70722462015-04-10 18:21:28 +03003608 struct i915_power_well *cmn_d =
Imre Deak2183b492018-08-06 12:58:41 +03003609 lookup_power_well(dev_priv, CHV_DISP_PW_DPIO_CMN_D);
Ville Syrjälä70722462015-04-10 18:21:28 +03003610
3611 /*
3612 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
3613 * workaround never ever read DISPLAY_PHY_CONTROL, and
3614 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003615 * power well state and lane status to reconstruct the
3616 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03003617 */
3618 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03003619 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
3620 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003621 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
3622 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
3623 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
3624
3625 /*
3626 * If all lanes are disabled we leave the override disabled
3627 * with all power down bits cleared to match the state we
3628 * would use after disabling the port. Otherwise enable the
3629 * override and set the lane powerdown bits accding to the
3630 * current lane status.
3631 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003632 if (cmn_bc->desc->ops->is_enabled(dev_priv, cmn_bc)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003633 uint32_t status = I915_READ(DPLL(PIPE_A));
3634 unsigned int mask;
3635
3636 mask = status & DPLL_PORTB_READY_MASK;
3637 if (mask == 0xf)
3638 mask = 0x0;
3639 else
3640 dev_priv->chv_phy_control |=
3641 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
3642
3643 dev_priv->chv_phy_control |=
3644 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
3645
3646 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
3647 if (mask == 0xf)
3648 mask = 0x0;
3649 else
3650 dev_priv->chv_phy_control |=
3651 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
3652
3653 dev_priv->chv_phy_control |=
3654 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
3655
Ville Syrjälä70722462015-04-10 18:21:28 +03003656 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003657
3658 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
3659 } else {
3660 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003661 }
3662
Imre Deakf28ec6f2018-08-06 12:58:37 +03003663 if (cmn_d->desc->ops->is_enabled(dev_priv, cmn_d)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003664 uint32_t status = I915_READ(DPIO_PHY_STATUS);
3665 unsigned int mask;
3666
3667 mask = status & DPLL_PORTD_READY_MASK;
3668
3669 if (mask == 0xf)
3670 mask = 0x0;
3671 else
3672 dev_priv->chv_phy_control |=
3673 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
3674
3675 dev_priv->chv_phy_control |=
3676 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
3677
Ville Syrjälä70722462015-04-10 18:21:28 +03003678 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003679
3680 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
3681 } else {
3682 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003683 }
3684
3685 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
3686
3687 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
3688 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03003689}
3690
Daniel Vetter9c065a72014-09-30 10:56:38 +02003691static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
3692{
3693 struct i915_power_well *cmn =
Imre Deak2183b492018-08-06 12:58:41 +03003694 lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003695 struct i915_power_well *disp2d =
Imre Deak2183b492018-08-06 12:58:41 +03003696 lookup_power_well(dev_priv, VLV_DISP_PW_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003697
Daniel Vetter9c065a72014-09-30 10:56:38 +02003698 /* If the display might be already active skip this */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003699 if (cmn->desc->ops->is_enabled(dev_priv, cmn) &&
3700 disp2d->desc->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003701 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3702 return;
3703
3704 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3705
3706 /* cmnlane needs DPLL registers */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003707 disp2d->desc->ops->enable(dev_priv, disp2d);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003708
3709 /*
3710 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3711 * Need to assert and de-assert PHY SB reset by gating the
3712 * common lane power, then un-gating it.
3713 * Simply ungating isn't enough to reset the PHY enough to get
3714 * ports and lanes running.
3715 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003716 cmn->desc->ops->disable(dev_priv, cmn);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003717}
3718
Daniel Vettere4e76842014-09-30 10:56:42 +02003719/**
3720 * intel_power_domains_init_hw - initialize hardware power domain state
3721 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003722 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003723 *
3724 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003725 * power wells belonging to the INIT power domain. Power wells in other
3726 * domains (and not in the INIT domain) are referenced or disabled during the
3727 * modeset state HW readout. After that the reference count of each power well
3728 * must match its HW enabled state, see intel_power_domains_verify_state().
Imre Deak2cd9a682018-08-16 15:37:57 +03003729 *
3730 * It will return with power domains disabled (to be enabled later by
3731 * intel_power_domains_enable()) and must be paired with
3732 * intel_power_domains_fini_hw().
Daniel Vettere4e76842014-09-30 10:56:42 +02003733 */
Imre Deak73dfc222015-11-17 17:33:53 +02003734void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003735{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003736 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3737
3738 power_domains->initializing = true;
3739
Paulo Zanoniad186f32018-02-05 13:40:43 -02003740 if (IS_ICELAKE(dev_priv)) {
3741 icl_display_core_init(dev_priv, resume);
3742 } else if (IS_CANNONLAKE(dev_priv)) {
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003743 cnl_display_core_init(dev_priv, resume);
3744 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003745 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003746 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003747 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003748 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003749 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003750 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003751 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003752 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003753 mutex_lock(&power_domains->lock);
3754 vlv_cmnlane_wa(dev_priv);
3755 mutex_unlock(&power_domains->lock);
3756 }
3757
Imre Deak2cd9a682018-08-16 15:37:57 +03003758 /*
3759 * Keep all power wells enabled for any dependent HW access during
3760 * initialization and to make sure we keep BIOS enabled display HW
3761 * resources powered until display HW readout is complete. We drop
3762 * this reference in intel_power_domains_enable().
3763 */
3764 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deakd314cd42015-11-17 17:44:23 +02003765 /* Disable power support if the user asked so. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003766 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003767 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003768 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003769 power_domains->initializing = false;
3770}
3771
Daniel Vettere4e76842014-09-30 10:56:42 +02003772/**
Imre Deak48a287e2018-08-06 12:58:35 +03003773 * intel_power_domains_fini_hw - deinitialize hw power domain state
3774 * @dev_priv: i915 device instance
3775 *
3776 * De-initializes the display power domain HW state. It also ensures that the
3777 * device stays powered up so that the driver can be reloaded.
Imre Deak2cd9a682018-08-16 15:37:57 +03003778 *
3779 * It must be called with power domains already disabled (after a call to
3780 * intel_power_domains_disable()) and must be paired with
3781 * intel_power_domains_init_hw().
Imre Deak48a287e2018-08-06 12:58:35 +03003782 */
3783void intel_power_domains_fini_hw(struct drm_i915_private *dev_priv)
3784{
Chris Wilson07d80572018-08-16 15:37:56 +03003785 /* Keep the power well enabled, but cancel its rpm wakeref. */
3786 intel_runtime_pm_put(dev_priv);
Imre Deak48a287e2018-08-06 12:58:35 +03003787
3788 /* Remove the refcount we took to keep power well support disabled. */
3789 if (!i915_modparams.disable_power_well)
3790 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak48a287e2018-08-06 12:58:35 +03003791}
3792
3793/**
Imre Deak2cd9a682018-08-16 15:37:57 +03003794 * intel_power_domains_enable - enable toggling of display power wells
Imre Deak73dfc222015-11-17 17:33:53 +02003795 * @dev_priv: i915 device instance
3796 *
Imre Deak2cd9a682018-08-16 15:37:57 +03003797 * Enable the ondemand enabling/disabling of the display power wells. Note that
3798 * power wells not belonging to POWER_DOMAIN_INIT are allowed to be toggled
3799 * only at specific points of the display modeset sequence, thus they are not
3800 * affected by the intel_power_domains_enable()/disable() calls. The purpose
3801 * of these function is to keep the rest of power wells enabled until the end
3802 * of display HW readout (which will acquire the power references reflecting
3803 * the current HW state).
Imre Deak73dfc222015-11-17 17:33:53 +02003804 */
Imre Deak2cd9a682018-08-16 15:37:57 +03003805void intel_power_domains_enable(struct drm_i915_private *dev_priv)
Imre Deak73dfc222015-11-17 17:33:53 +02003806{
Imre Deak2cd9a682018-08-16 15:37:57 +03003807 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
3808}
3809
3810/**
3811 * intel_power_domains_disable - disable toggling of display power wells
3812 * @dev_priv: i915 device instance
3813 *
3814 * Disable the ondemand enabling/disabling of the display power wells. See
3815 * intel_power_domains_enable() for which power wells this call controls.
3816 */
3817void intel_power_domains_disable(struct drm_i915_private *dev_priv)
3818{
3819 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
3820}
3821
3822/**
3823 * intel_power_domains_suspend - suspend power domain state
3824 * @dev_priv: i915 device instance
3825 * @suspend_mode: specifies the target suspend state (idle, mem, hibernation)
3826 *
3827 * This function prepares the hardware power domain state before entering
3828 * system suspend.
3829 *
3830 * It must be called with power domains already disabled (after a call to
3831 * intel_power_domains_disable()) and paired with intel_power_domains_resume().
3832 */
3833void intel_power_domains_suspend(struct drm_i915_private *dev_priv,
3834 enum i915_drm_suspend_mode suspend_mode)
3835{
3836 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3837
3838 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
3839
3840 /*
3841 * In case of firmware assisted context save/restore don't manually
3842 * deinit the power domains. This also means the CSR/DMC firmware will
3843 * stay active, it will power down any HW resources as required and
3844 * also enable deeper system power states that would be blocked if the
3845 * firmware was inactive.
3846 */
3847 if (!IS_GEN9_LP(dev_priv) && suspend_mode == I915_DRM_SUSPEND_IDLE &&
3848 dev_priv->csr.dmc_payload != NULL)
3849 return;
3850
Imre Deakd314cd42015-11-17 17:44:23 +02003851 /*
3852 * Even if power well support was disabled we still want to disable
Imre Deak2cd9a682018-08-16 15:37:57 +03003853 * power wells if power domains must be deinitialized for suspend.
Imre Deakd314cd42015-11-17 17:44:23 +02003854 */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003855 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003856 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003857
Paulo Zanoniad186f32018-02-05 13:40:43 -02003858 if (IS_ICELAKE(dev_priv))
3859 icl_display_core_uninit(dev_priv);
3860 else if (IS_CANNONLAKE(dev_priv))
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003861 cnl_display_core_uninit(dev_priv);
3862 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003863 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003864 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003865 bxt_display_core_uninit(dev_priv);
Imre Deak2cd9a682018-08-16 15:37:57 +03003866
3867 power_domains->display_core_suspended = true;
3868}
3869
3870/**
3871 * intel_power_domains_resume - resume power domain state
3872 * @dev_priv: i915 device instance
3873 *
3874 * This function resume the hardware power domain state during system resume.
3875 *
3876 * It will return with power domain support disabled (to be enabled later by
3877 * intel_power_domains_enable()) and must be paired with
3878 * intel_power_domains_suspend().
3879 */
3880void intel_power_domains_resume(struct drm_i915_private *dev_priv)
3881{
3882 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3883
3884 if (power_domains->display_core_suspended) {
3885 intel_power_domains_init_hw(dev_priv, true);
3886 power_domains->display_core_suspended = false;
3887
3888 return;
3889 }
3890
3891 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak73dfc222015-11-17 17:33:53 +02003892}
3893
Imre Deak8d8c3862017-02-17 17:39:46 +02003894static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3895{
3896 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3897 struct i915_power_well *power_well;
3898
3899 for_each_power_well(dev_priv, power_well) {
3900 enum intel_display_power_domain domain;
3901
3902 DRM_DEBUG_DRIVER("%-25s %d\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003903 power_well->desc->name, power_well->count);
Imre Deak8d8c3862017-02-17 17:39:46 +02003904
Imre Deakf28ec6f2018-08-06 12:58:37 +03003905 for_each_power_domain(domain, power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003906 DRM_DEBUG_DRIVER(" %-23s %d\n",
3907 intel_display_power_domain_str(domain),
3908 power_domains->domain_use_count[domain]);
3909 }
3910}
3911
3912/**
3913 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3914 * @dev_priv: i915 device instance
3915 *
3916 * Verify if the reference count of each power well matches its HW enabled
3917 * state and the total refcount of the domains it belongs to. This must be
3918 * called after modeset HW state sanitization, which is responsible for
3919 * acquiring reference counts for any power wells in use and disabling the
3920 * ones left on by BIOS but not required by any active output.
3921 */
3922void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3923{
3924 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3925 struct i915_power_well *power_well;
3926 bool dump_domain_info;
3927
3928 mutex_lock(&power_domains->lock);
3929
3930 dump_domain_info = false;
3931 for_each_power_well(dev_priv, power_well) {
3932 enum intel_display_power_domain domain;
3933 int domains_count;
3934 bool enabled;
3935
3936 /*
3937 * Power wells not belonging to any domain (like the MISC_IO
3938 * and PW1 power wells) are under FW control, so ignore them,
3939 * since their state can change asynchronously.
3940 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003941 if (!power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003942 continue;
3943
Imre Deakf28ec6f2018-08-06 12:58:37 +03003944 enabled = power_well->desc->ops->is_enabled(dev_priv,
3945 power_well);
3946 if ((power_well->count || power_well->desc->always_on) !=
3947 enabled)
Imre Deak8d8c3862017-02-17 17:39:46 +02003948 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003949 power_well->desc->name,
3950 power_well->count, enabled);
Imre Deak8d8c3862017-02-17 17:39:46 +02003951
3952 domains_count = 0;
Imre Deakf28ec6f2018-08-06 12:58:37 +03003953 for_each_power_domain(domain, power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003954 domains_count += power_domains->domain_use_count[domain];
3955
3956 if (power_well->count != domains_count) {
3957 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3958 "(refcount %d/domains refcount %d)\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003959 power_well->desc->name, power_well->count,
Imre Deak8d8c3862017-02-17 17:39:46 +02003960 domains_count);
3961 dump_domain_info = true;
3962 }
3963 }
3964
3965 if (dump_domain_info) {
3966 static bool dumped;
3967
3968 if (!dumped) {
3969 intel_power_domains_dump_info(dev_priv);
3970 dumped = true;
3971 }
3972 }
3973
3974 mutex_unlock(&power_domains->lock);
3975}
3976
Imre Deak73dfc222015-11-17 17:33:53 +02003977/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003978 * intel_runtime_pm_get - grab a runtime pm reference
3979 * @dev_priv: i915 device instance
3980 *
3981 * This function grabs a device-level runtime pm reference (mostly used for GEM
3982 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3983 *
3984 * Any runtime pm reference obtained by this function must have a symmetric
3985 * call to intel_runtime_pm_put() to release the reference again.
3986 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003987void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3988{
David Weinehall52a05c32016-08-22 13:32:44 +03003989 struct pci_dev *pdev = dev_priv->drm.pdev;
3990 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003991 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003992
Imre Deakf5073822017-03-28 12:38:55 +03003993 ret = pm_runtime_get_sync(kdev);
3994 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003995
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003996 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003997 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003998}
3999
Daniel Vettere4e76842014-09-30 10:56:42 +02004000/**
Imre Deak09731282016-02-17 14:17:42 +02004001 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
4002 * @dev_priv: i915 device instance
4003 *
4004 * This function grabs a device-level runtime pm reference if the device is
Chris Wilsonacb79142018-02-19 12:50:46 +00004005 * already in use and ensures that it is powered up. It is illegal to try
4006 * and access the HW should intel_runtime_pm_get_if_in_use() report failure.
Imre Deak09731282016-02-17 14:17:42 +02004007 *
4008 * Any runtime pm reference obtained by this function must have a symmetric
4009 * call to intel_runtime_pm_put() to release the reference again.
Chris Wilsonacb79142018-02-19 12:50:46 +00004010 *
4011 * Returns: True if the wakeref was acquired, or False otherwise.
Imre Deak09731282016-02-17 14:17:42 +02004012 */
4013bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
4014{
Chris Wilson135dc792016-02-25 21:10:28 +00004015 if (IS_ENABLED(CONFIG_PM)) {
Chris Wilsonacb79142018-02-19 12:50:46 +00004016 struct pci_dev *pdev = dev_priv->drm.pdev;
4017 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02004018
Chris Wilson135dc792016-02-25 21:10:28 +00004019 /*
4020 * In cases runtime PM is disabled by the RPM core and we get
4021 * an -EINVAL return value we are not supposed to call this
4022 * function, since the power state is undefined. This applies
4023 * atm to the late/early system suspend/resume handlers.
4024 */
Chris Wilsonacb79142018-02-19 12:50:46 +00004025 if (pm_runtime_get_if_in_use(kdev) <= 0)
Chris Wilson135dc792016-02-25 21:10:28 +00004026 return false;
4027 }
Imre Deak09731282016-02-17 14:17:42 +02004028
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004029 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deak09731282016-02-17 14:17:42 +02004030 assert_rpm_wakelock_held(dev_priv);
4031
4032 return true;
4033}
4034
4035/**
Daniel Vettere4e76842014-09-30 10:56:42 +02004036 * intel_runtime_pm_get_noresume - grab a runtime pm reference
4037 * @dev_priv: i915 device instance
4038 *
4039 * This function grabs a device-level runtime pm reference (mostly used for GEM
4040 * code to ensure the GTT or GT is on).
4041 *
4042 * It will _not_ power up the device but instead only check that it's powered
4043 * on. Therefore it is only valid to call this functions from contexts where
4044 * the device is known to be powered up and where trying to power it up would
4045 * result in hilarity and deadlocks. That pretty much means only the system
4046 * suspend/resume code where this is used to grab runtime pm references for
4047 * delayed setup down in work items.
4048 *
4049 * Any runtime pm reference obtained by this function must have a symmetric
4050 * call to intel_runtime_pm_put() to release the reference again.
4051 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02004052void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
4053{
David Weinehall52a05c32016-08-22 13:32:44 +03004054 struct pci_dev *pdev = dev_priv->drm.pdev;
4055 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02004056
Imre Deakc9b88462015-12-15 20:10:34 +02004057 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03004058 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02004059
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004060 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02004061}
4062
Daniel Vettere4e76842014-09-30 10:56:42 +02004063/**
4064 * intel_runtime_pm_put - release a runtime pm reference
4065 * @dev_priv: i915 device instance
4066 *
4067 * This function drops the device-level runtime pm reference obtained by
4068 * intel_runtime_pm_get() and might power down the corresponding
4069 * hardware block right away if this is the last reference.
4070 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02004071void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
4072{
David Weinehall52a05c32016-08-22 13:32:44 +03004073 struct pci_dev *pdev = dev_priv->drm.pdev;
4074 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02004075
Imre Deak542db3c2015-12-15 20:10:36 +02004076 assert_rpm_wakelock_held(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004077 atomic_dec(&dev_priv->runtime_pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02004078
David Weinehallc49d13e2016-08-22 13:32:42 +03004079 pm_runtime_mark_last_busy(kdev);
4080 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02004081}
4082
Daniel Vettere4e76842014-09-30 10:56:42 +02004083/**
4084 * intel_runtime_pm_enable - enable runtime pm
4085 * @dev_priv: i915 device instance
4086 *
4087 * This function enables runtime pm at the end of the driver load sequence.
4088 *
4089 * Note that this function does currently not enable runtime pm for the
Imre Deak2cd9a682018-08-16 15:37:57 +03004090 * subordinate display power domains. That is done by
4091 * intel_power_domains_enable().
Daniel Vettere4e76842014-09-30 10:56:42 +02004092 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02004093void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02004094{
David Weinehall52a05c32016-08-22 13:32:44 +03004095 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03004096 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02004097
Chris Wilson07d80572018-08-16 15:37:56 +03004098 /*
4099 * Disable the system suspend direct complete optimization, which can
4100 * leave the device suspended skipping the driver's suspend handlers
4101 * if the device was already runtime suspended. This is needed due to
4102 * the difference in our runtime and system suspend sequence and
4103 * becaue the HDA driver may require us to enable the audio power
4104 * domain during system suspend.
4105 */
4106 dev_pm_set_driver_flags(kdev, DPM_FLAG_NEVER_SKIP);
4107
David Weinehallc49d13e2016-08-22 13:32:42 +03004108 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
4109 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02004110
Imre Deak25b181b2015-12-17 13:44:56 +02004111 /*
4112 * Take a permanent reference to disable the RPM functionality and drop
4113 * it only when unloading the driver. Use the low level get/put helpers,
4114 * so the driver's own RPM reference tracking asserts also work on
4115 * platforms without RPM support.
4116 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01004117 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03004118 int ret;
4119
David Weinehallc49d13e2016-08-22 13:32:42 +03004120 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03004121 ret = pm_runtime_get_sync(kdev);
4122 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02004123 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03004124 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02004125 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02004126
Imre Deakaabee1b2015-12-15 20:10:29 +02004127 /*
4128 * The core calls the driver load handler with an RPM reference held.
4129 * We drop that here and will reacquire it during unloading in
4130 * intel_power_domains_fini().
4131 */
David Weinehallc49d13e2016-08-22 13:32:42 +03004132 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02004133}
Chris Wilson07d80572018-08-16 15:37:56 +03004134
4135void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
4136{
4137 struct pci_dev *pdev = dev_priv->drm.pdev;
4138 struct device *kdev = &pdev->dev;
4139
4140 /* Transfer rpm ownership back to core */
4141 WARN(pm_runtime_get_sync(&dev_priv->drm.pdev->dev) < 0,
4142 "Failed to pass rpm ownership back to core\n");
4143
4144 pm_runtime_dont_use_autosuspend(kdev);
4145
4146 if (!HAS_RUNTIME_PM(dev_priv))
4147 pm_runtime_put(kdev);
4148}