blob: d98f19e02580caddd613b4bdd948832037a16d50 [file] [log] [blame]
Daniel Vetter9c065a72014-09-30 10:56:38 +02001/*
2 * Copyright © 2012-2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29#include <linux/pm_runtime.h>
30#include <linux/vgaarb.h>
31
32#include "i915_drv.h"
33#include "intel_drv.h"
Daniel Vetter9c065a72014-09-30 10:56:38 +020034
Daniel Vettere4e76842014-09-30 10:56:42 +020035/**
36 * DOC: runtime pm
37 *
38 * The i915 driver supports dynamic enabling and disabling of entire hardware
39 * blocks at runtime. This is especially important on the display side where
40 * software is supposed to control many power gates manually on recent hardware,
41 * since on the GT side a lot of the power management is done by the hardware.
42 * But even there some manual control at the device level is required.
43 *
44 * Since i915 supports a diverse set of platforms with a unified codebase and
45 * hardware engineers just love to shuffle functionality around between power
46 * domains there's a sizeable amount of indirection required. This file provides
47 * generic functions to the driver for grabbing and releasing references for
48 * abstract power domains. It then maps those to the actual power wells
49 * present for a given platform.
50 */
51
Suketu Shah5aefb232015-04-16 14:22:10 +053052bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +030053 enum i915_power_well_id power_well_id);
Suketu Shah5aefb232015-04-16 14:22:10 +053054
Imre Deak9c8d0b82016-06-13 16:44:34 +030055static struct i915_power_well *
Imre Deak438b8dc2017-07-11 23:42:30 +030056lookup_power_well(struct drm_i915_private *dev_priv,
57 enum i915_power_well_id power_well_id);
Imre Deak9c8d0b82016-06-13 16:44:34 +030058
Daniel Stone9895ad02015-11-20 15:55:33 +000059const char *
60intel_display_power_domain_str(enum intel_display_power_domain domain)
61{
62 switch (domain) {
63 case POWER_DOMAIN_PIPE_A:
64 return "PIPE_A";
65 case POWER_DOMAIN_PIPE_B:
66 return "PIPE_B";
67 case POWER_DOMAIN_PIPE_C:
68 return "PIPE_C";
69 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
70 return "PIPE_A_PANEL_FITTER";
71 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
72 return "PIPE_B_PANEL_FITTER";
73 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
74 return "PIPE_C_PANEL_FITTER";
75 case POWER_DOMAIN_TRANSCODER_A:
76 return "TRANSCODER_A";
77 case POWER_DOMAIN_TRANSCODER_B:
78 return "TRANSCODER_B";
79 case POWER_DOMAIN_TRANSCODER_C:
80 return "TRANSCODER_C";
81 case POWER_DOMAIN_TRANSCODER_EDP:
82 return "TRANSCODER_EDP";
Jani Nikula4d1de972016-03-18 17:05:42 +020083 case POWER_DOMAIN_TRANSCODER_DSI_A:
84 return "TRANSCODER_DSI_A";
85 case POWER_DOMAIN_TRANSCODER_DSI_C:
86 return "TRANSCODER_DSI_C";
Daniel Stone9895ad02015-11-20 15:55:33 +000087 case POWER_DOMAIN_PORT_DDI_A_LANES:
88 return "PORT_DDI_A_LANES";
89 case POWER_DOMAIN_PORT_DDI_B_LANES:
90 return "PORT_DDI_B_LANES";
91 case POWER_DOMAIN_PORT_DDI_C_LANES:
92 return "PORT_DDI_C_LANES";
93 case POWER_DOMAIN_PORT_DDI_D_LANES:
94 return "PORT_DDI_D_LANES";
95 case POWER_DOMAIN_PORT_DDI_E_LANES:
96 return "PORT_DDI_E_LANES";
Rodrigo Vivi9787e832018-01-29 15:22:22 -080097 case POWER_DOMAIN_PORT_DDI_F_LANES:
98 return "PORT_DDI_F_LANES";
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020099 case POWER_DOMAIN_PORT_DDI_A_IO:
100 return "PORT_DDI_A_IO";
101 case POWER_DOMAIN_PORT_DDI_B_IO:
102 return "PORT_DDI_B_IO";
103 case POWER_DOMAIN_PORT_DDI_C_IO:
104 return "PORT_DDI_C_IO";
105 case POWER_DOMAIN_PORT_DDI_D_IO:
106 return "PORT_DDI_D_IO";
107 case POWER_DOMAIN_PORT_DDI_E_IO:
108 return "PORT_DDI_E_IO";
Rodrigo Vivi9787e832018-01-29 15:22:22 -0800109 case POWER_DOMAIN_PORT_DDI_F_IO:
110 return "PORT_DDI_F_IO";
Daniel Stone9895ad02015-11-20 15:55:33 +0000111 case POWER_DOMAIN_PORT_DSI:
112 return "PORT_DSI";
113 case POWER_DOMAIN_PORT_CRT:
114 return "PORT_CRT";
115 case POWER_DOMAIN_PORT_OTHER:
116 return "PORT_OTHER";
117 case POWER_DOMAIN_VGA:
118 return "VGA";
119 case POWER_DOMAIN_AUDIO:
120 return "AUDIO";
121 case POWER_DOMAIN_PLLS:
122 return "PLLS";
123 case POWER_DOMAIN_AUX_A:
124 return "AUX_A";
125 case POWER_DOMAIN_AUX_B:
126 return "AUX_B";
127 case POWER_DOMAIN_AUX_C:
128 return "AUX_C";
129 case POWER_DOMAIN_AUX_D:
130 return "AUX_D";
James Ausmusbb187e92018-06-11 17:25:12 -0700131 case POWER_DOMAIN_AUX_E:
132 return "AUX_E";
Rodrigo Vivia324fca2018-01-29 15:22:15 -0800133 case POWER_DOMAIN_AUX_F:
134 return "AUX_F";
Dhinakaran Pandiyanb891d5e2018-02-23 14:15:15 -0800135 case POWER_DOMAIN_AUX_IO_A:
136 return "AUX_IO_A";
Imre Deak67ca07e2018-06-26 17:22:32 +0300137 case POWER_DOMAIN_AUX_TBT1:
138 return "AUX_TBT1";
139 case POWER_DOMAIN_AUX_TBT2:
140 return "AUX_TBT2";
141 case POWER_DOMAIN_AUX_TBT3:
142 return "AUX_TBT3";
143 case POWER_DOMAIN_AUX_TBT4:
144 return "AUX_TBT4";
Daniel Stone9895ad02015-11-20 15:55:33 +0000145 case POWER_DOMAIN_GMBUS:
146 return "GMBUS";
147 case POWER_DOMAIN_INIT:
148 return "INIT";
149 case POWER_DOMAIN_MODESET:
150 return "MODESET";
Tvrtko Ursulinb6876372017-12-05 13:28:54 +0000151 case POWER_DOMAIN_GT_IRQ:
152 return "GT_IRQ";
Daniel Stone9895ad02015-11-20 15:55:33 +0000153 default:
154 MISSING_CASE(domain);
155 return "?";
156 }
157}
158
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300159static void intel_power_well_enable(struct drm_i915_private *dev_priv,
160 struct i915_power_well *power_well)
161{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300162 DRM_DEBUG_KMS("enabling %s\n", power_well->desc->name);
163 power_well->desc->ops->enable(dev_priv, power_well);
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300164 power_well->hw_enabled = true;
165}
166
Damien Lespiaudcddab32015-07-30 18:20:27 -0300167static void intel_power_well_disable(struct drm_i915_private *dev_priv,
168 struct i915_power_well *power_well)
169{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300170 DRM_DEBUG_KMS("disabling %s\n", power_well->desc->name);
Damien Lespiaudcddab32015-07-30 18:20:27 -0300171 power_well->hw_enabled = false;
Imre Deakf28ec6f2018-08-06 12:58:37 +0300172 power_well->desc->ops->disable(dev_priv, power_well);
Damien Lespiaudcddab32015-07-30 18:20:27 -0300173}
174
Imre Deakb409ca92016-06-13 16:44:33 +0300175static void intel_power_well_get(struct drm_i915_private *dev_priv,
176 struct i915_power_well *power_well)
177{
178 if (!power_well->count++)
179 intel_power_well_enable(dev_priv, power_well);
180}
181
182static void intel_power_well_put(struct drm_i915_private *dev_priv,
183 struct i915_power_well *power_well)
184{
185 WARN(!power_well->count, "Use count on power well %s is already zero",
Imre Deakf28ec6f2018-08-06 12:58:37 +0300186 power_well->desc->name);
Imre Deakb409ca92016-06-13 16:44:33 +0300187
188 if (!--power_well->count)
189 intel_power_well_disable(dev_priv, power_well);
190}
191
Daniel Vettere4e76842014-09-30 10:56:42 +0200192/**
193 * __intel_display_power_is_enabled - unlocked check for a power domain
194 * @dev_priv: i915 device instance
195 * @domain: power domain to check
196 *
197 * This is the unlocked version of intel_display_power_is_enabled() and should
198 * only be used from error capture and recovery code where deadlocks are
199 * possible.
200 *
201 * Returns:
202 * True when the power domain is enabled, false otherwise.
203 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200204bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
205 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200206{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200207 struct i915_power_well *power_well;
208 bool is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200209
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +0100210 if (dev_priv->runtime_pm.suspended)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200211 return false;
212
Daniel Vetter9c065a72014-09-30 10:56:38 +0200213 is_enabled = true;
214
Imre Deak75ccb2e2017-02-17 17:39:43 +0200215 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +0300216 if (power_well->desc->always_on)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200217 continue;
218
219 if (!power_well->hw_enabled) {
220 is_enabled = false;
221 break;
222 }
223 }
224
225 return is_enabled;
226}
227
Daniel Vettere4e76842014-09-30 10:56:42 +0200228/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000229 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200230 * @dev_priv: i915 device instance
231 * @domain: power domain to check
232 *
233 * This function can be used to check the hw power domain state. It is mostly
234 * used in hardware state readout functions. Everywhere else code should rely
235 * upon explicit power domain reference counting to ensure that the hardware
236 * block is powered up before accessing it.
237 *
238 * Callers must hold the relevant modesetting locks to ensure that concurrent
239 * threads can't disable the power well while the caller tries to read a few
240 * registers.
241 *
242 * Returns:
243 * True when the power domain is enabled, false otherwise.
244 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200245bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
246 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200247{
248 struct i915_power_domains *power_domains;
249 bool ret;
250
251 power_domains = &dev_priv->power_domains;
252
253 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200254 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200255 mutex_unlock(&power_domains->lock);
256
257 return ret;
258}
259
Daniel Vettere4e76842014-09-30 10:56:42 +0200260/**
261 * intel_display_set_init_power - set the initial power domain state
262 * @dev_priv: i915 device instance
263 * @enable: whether to enable or disable the initial power domain state
264 *
265 * For simplicity our driver load/unload and system suspend/resume code assumes
266 * that all power domains are always enabled. This functions controls the state
267 * of this little hack. While the initial power domain state is enabled runtime
268 * pm is effectively disabled.
269 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200270void intel_display_set_init_power(struct drm_i915_private *dev_priv,
271 bool enable)
272{
273 if (dev_priv->power_domains.init_power_on == enable)
274 return;
275
276 if (enable)
277 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
278 else
279 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
280
281 dev_priv->power_domains.init_power_on = enable;
282}
283
Daniel Vetter9c065a72014-09-30 10:56:38 +0200284/*
285 * Starting with Haswell, we have a "Power Down Well" that can be turned off
286 * when not needed anymore. We have 4 registers that can request the power well
287 * to be enabled, and it will only be disabled if none of the registers is
288 * requesting it to be enabled.
289 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300290static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv,
291 u8 irq_pipe_mask, bool has_vga)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200292{
David Weinehall52a05c32016-08-22 13:32:44 +0300293 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200294
295 /*
296 * After we re-enable the power well, if we touch VGA register 0x3d5
297 * we'll get unclaimed register interrupts. This stops after we write
298 * anything to the VGA MSR register. The vgacon module uses this
299 * register all the time, so if we unbind our driver and, as a
300 * consequence, bind vgacon, we'll get stuck in an infinite loop at
301 * console_unlock(). So make here we touch the VGA MSR register, making
302 * sure vgacon can keep working normally without triggering interrupts
303 * and error messages.
304 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300305 if (has_vga) {
306 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
307 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
308 vga_put(pdev, VGA_RSRC_LEGACY_IO);
309 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200310
Imre Deak001bd2c2017-07-12 18:54:13 +0300311 if (irq_pipe_mask)
312 gen8_irq_power_well_post_enable(dev_priv, irq_pipe_mask);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200313}
314
Imre Deak001bd2c2017-07-12 18:54:13 +0300315static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv,
316 u8 irq_pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200317{
Imre Deak001bd2c2017-07-12 18:54:13 +0300318 if (irq_pipe_mask)
319 gen8_irq_power_well_pre_disable(dev_priv, irq_pipe_mask);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200320}
321
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200322
Imre Deak76347c02017-07-06 17:40:36 +0300323static void hsw_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
324 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300325{
Imre Deak75e39682018-08-06 12:58:39 +0300326 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
327 int pw_idx = power_well->desc->hsw.idx;
Imre Deak42d93662017-06-29 18:37:01 +0300328
329 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
330 WARN_ON(intel_wait_for_register(dev_priv,
Imre Deak75e39682018-08-06 12:58:39 +0300331 regs->driver,
332 HSW_PWR_WELL_CTL_STATE(pw_idx),
333 HSW_PWR_WELL_CTL_STATE(pw_idx),
Imre Deak42d93662017-06-29 18:37:01 +0300334 1));
335}
336
Imre Deak76347c02017-07-06 17:40:36 +0300337static u32 hsw_power_well_requesters(struct drm_i915_private *dev_priv,
Imre Deak75e39682018-08-06 12:58:39 +0300338 const struct i915_power_well_regs *regs,
339 int pw_idx)
Imre Deak42d93662017-06-29 18:37:01 +0300340{
Imre Deak75e39682018-08-06 12:58:39 +0300341 u32 req_mask = HSW_PWR_WELL_CTL_REQ(pw_idx);
Imre Deak42d93662017-06-29 18:37:01 +0300342 u32 ret;
343
Imre Deak75e39682018-08-06 12:58:39 +0300344 ret = I915_READ(regs->bios) & req_mask ? 1 : 0;
345 ret |= I915_READ(regs->driver) & req_mask ? 2 : 0;
346 if (regs->kvmr.reg)
347 ret |= I915_READ(regs->kvmr) & req_mask ? 4 : 0;
348 ret |= I915_READ(regs->debug) & req_mask ? 8 : 0;
Imre Deak42d93662017-06-29 18:37:01 +0300349
350 return ret;
351}
352
Imre Deak76347c02017-07-06 17:40:36 +0300353static void hsw_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
354 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300355{
Imre Deak75e39682018-08-06 12:58:39 +0300356 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
357 int pw_idx = power_well->desc->hsw.idx;
Imre Deak42d93662017-06-29 18:37:01 +0300358 bool disabled;
359 u32 reqs;
360
361 /*
362 * Bspec doesn't require waiting for PWs to get disabled, but still do
363 * this for paranoia. The known cases where a PW will be forced on:
364 * - a KVMR request on any power well via the KVMR request register
365 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
366 * DEBUG request registers
367 * Skip the wait in case any of the request bits are set and print a
368 * diagnostic message.
369 */
Imre Deak75e39682018-08-06 12:58:39 +0300370 wait_for((disabled = !(I915_READ(regs->driver) &
371 HSW_PWR_WELL_CTL_STATE(pw_idx))) ||
372 (reqs = hsw_power_well_requesters(dev_priv, regs, pw_idx)), 1);
Imre Deak42d93662017-06-29 18:37:01 +0300373 if (disabled)
374 return;
375
376 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +0300377 power_well->desc->name,
Imre Deak42d93662017-06-29 18:37:01 +0300378 !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
379}
380
Imre Deakb2891eb2017-07-11 23:42:35 +0300381static void gen9_wait_for_power_well_fuses(struct drm_i915_private *dev_priv,
382 enum skl_power_gate pg)
383{
384 /* Timeout 5us for PG#0, for other PGs 1us */
385 WARN_ON(intel_wait_for_register(dev_priv, SKL_FUSE_STATUS,
386 SKL_FUSE_PG_DIST_STATUS(pg),
387 SKL_FUSE_PG_DIST_STATUS(pg), 1));
388}
389
Imre Deakec46d482017-07-06 17:40:33 +0300390static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
391 struct i915_power_well *power_well)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200392{
Imre Deak75e39682018-08-06 12:58:39 +0300393 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
394 int pw_idx = power_well->desc->hsw.idx;
Imre Deakf28ec6f2018-08-06 12:58:37 +0300395 bool wait_fuses = power_well->desc->hsw.has_fuses;
Chris Wilson320671f2017-10-02 11:04:16 +0100396 enum skl_power_gate uninitialized_var(pg);
Imre Deak1af474f2017-07-06 17:40:34 +0300397 u32 val;
398
Imre Deakb2891eb2017-07-11 23:42:35 +0300399 if (wait_fuses) {
Imre Deak75e39682018-08-06 12:58:39 +0300400 pg = INTEL_GEN(dev_priv) >= 11 ? ICL_PW_CTL_IDX_TO_PG(pw_idx) :
401 SKL_PW_CTL_IDX_TO_PG(pw_idx);
Imre Deakb2891eb2017-07-11 23:42:35 +0300402 /*
403 * For PW1 we have to wait both for the PW0/PG0 fuse state
404 * before enabling the power well and PW1/PG1's own fuse
405 * state after the enabling. For all other power wells with
406 * fuses we only have to wait for that PW/PG's fuse state
407 * after the enabling.
408 */
409 if (pg == SKL_PG1)
410 gen9_wait_for_power_well_fuses(dev_priv, SKL_PG0);
411 }
412
Imre Deak75e39682018-08-06 12:58:39 +0300413 val = I915_READ(regs->driver);
414 I915_WRITE(regs->driver, val | HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak76347c02017-07-06 17:40:36 +0300415 hsw_wait_for_power_well_enable(dev_priv, power_well);
Imre Deak001bd2c2017-07-12 18:54:13 +0300416
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800417 /* Display WA #1178: cnl */
418 if (IS_CANNONLAKE(dev_priv) &&
Imre Deak75e39682018-08-06 12:58:39 +0300419 pw_idx >= GLK_PW_CTL_IDX_AUX_B &&
420 pw_idx <= CNL_PW_CTL_IDX_AUX_F) {
421 val = I915_READ(CNL_AUX_ANAOVRD1(pw_idx));
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800422 val |= CNL_AUX_ANAOVRD1_ENABLE | CNL_AUX_ANAOVRD1_LDO_BYPASS;
Imre Deak75e39682018-08-06 12:58:39 +0300423 I915_WRITE(CNL_AUX_ANAOVRD1(pw_idx), val);
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800424 }
425
Imre Deakb2891eb2017-07-11 23:42:35 +0300426 if (wait_fuses)
427 gen9_wait_for_power_well_fuses(dev_priv, pg);
428
Imre Deakf28ec6f2018-08-06 12:58:37 +0300429 hsw_power_well_post_enable(dev_priv,
430 power_well->desc->hsw.irq_pipe_mask,
431 power_well->desc->hsw.has_vga);
Imre Deakec46d482017-07-06 17:40:33 +0300432}
Daniel Vetter9c065a72014-09-30 10:56:38 +0200433
Imre Deakec46d482017-07-06 17:40:33 +0300434static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
435 struct i915_power_well *power_well)
436{
Imre Deak75e39682018-08-06 12:58:39 +0300437 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
438 int pw_idx = power_well->desc->hsw.idx;
Imre Deak1af474f2017-07-06 17:40:34 +0300439 u32 val;
440
Imre Deakf28ec6f2018-08-06 12:58:37 +0300441 hsw_power_well_pre_disable(dev_priv,
442 power_well->desc->hsw.irq_pipe_mask);
Imre Deak001bd2c2017-07-12 18:54:13 +0300443
Imre Deak75e39682018-08-06 12:58:39 +0300444 val = I915_READ(regs->driver);
445 I915_WRITE(regs->driver, val & ~HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak76347c02017-07-06 17:40:36 +0300446 hsw_wait_for_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200447}
448
Imre Deak75e39682018-08-06 12:58:39 +0300449#define ICL_AUX_PW_TO_PORT(pw_idx) ((pw_idx) - ICL_PW_CTL_IDX_AUX_A)
Imre Deak67ca07e2018-06-26 17:22:32 +0300450
451static void
452icl_combo_phy_aux_power_well_enable(struct drm_i915_private *dev_priv,
453 struct i915_power_well *power_well)
454{
Imre Deak75e39682018-08-06 12:58:39 +0300455 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
456 int pw_idx = power_well->desc->hsw.idx;
457 enum port port = ICL_AUX_PW_TO_PORT(pw_idx);
Imre Deak67ca07e2018-06-26 17:22:32 +0300458 u32 val;
459
Imre Deak75e39682018-08-06 12:58:39 +0300460 val = I915_READ(regs->driver);
461 I915_WRITE(regs->driver, val | HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak67ca07e2018-06-26 17:22:32 +0300462
463 val = I915_READ(ICL_PORT_CL_DW12(port));
464 I915_WRITE(ICL_PORT_CL_DW12(port), val | ICL_LANE_ENABLE_AUX);
465
466 hsw_wait_for_power_well_enable(dev_priv, power_well);
467}
468
469static void
470icl_combo_phy_aux_power_well_disable(struct drm_i915_private *dev_priv,
471 struct i915_power_well *power_well)
472{
Imre Deak75e39682018-08-06 12:58:39 +0300473 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
474 int pw_idx = power_well->desc->hsw.idx;
475 enum port port = ICL_AUX_PW_TO_PORT(pw_idx);
Imre Deak67ca07e2018-06-26 17:22:32 +0300476 u32 val;
477
478 val = I915_READ(ICL_PORT_CL_DW12(port));
479 I915_WRITE(ICL_PORT_CL_DW12(port), val & ~ICL_LANE_ENABLE_AUX);
480
Imre Deak75e39682018-08-06 12:58:39 +0300481 val = I915_READ(regs->driver);
482 I915_WRITE(regs->driver, val & ~HSW_PWR_WELL_CTL_REQ(pw_idx));
Imre Deak67ca07e2018-06-26 17:22:32 +0300483
484 hsw_wait_for_power_well_disable(dev_priv, power_well);
485}
486
Imre Deakd42539b2017-07-06 17:40:39 +0300487/*
488 * We should only use the power well if we explicitly asked the hardware to
489 * enable it, so check if it's enabled and also check if we've requested it to
490 * be enabled.
491 */
492static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
493 struct i915_power_well *power_well)
494{
Imre Deak75e39682018-08-06 12:58:39 +0300495 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
496 int pw_idx = power_well->desc->hsw.idx;
497 u32 mask = HSW_PWR_WELL_CTL_REQ(pw_idx) |
498 HSW_PWR_WELL_CTL_STATE(pw_idx);
Imre Deakd42539b2017-07-06 17:40:39 +0300499
Imre Deak75e39682018-08-06 12:58:39 +0300500 return (I915_READ(regs->driver) & mask) == mask;
Imre Deakd42539b2017-07-06 17:40:39 +0300501}
502
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530503static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
504{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300505 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
506 "DC9 already programmed to be enabled.\n");
507 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
508 "DC5 still not disabled to enable DC9.\n");
Imre Deak75e39682018-08-06 12:58:39 +0300509 WARN_ONCE(I915_READ(HSW_PWR_WELL_CTL2) &
510 HSW_PWR_WELL_CTL_REQ(SKL_PW_CTL_IDX_PW_2),
Imre Deake8a3a2a2017-06-29 18:37:00 +0300511 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300512 WARN_ONCE(intel_irqs_enabled(dev_priv),
513 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530514
515 /*
516 * TODO: check for the following to verify the conditions to enter DC9
517 * state are satisfied:
518 * 1] Check relevant display engine registers to verify if mode set
519 * disable sequence was followed.
520 * 2] Check if display uninitialize sequence is initialized.
521 */
522}
523
524static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
525{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300526 WARN_ONCE(intel_irqs_enabled(dev_priv),
527 "Interrupts not disabled yet.\n");
528 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
529 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530530
531 /*
532 * TODO: check for the following to verify DC9 state was indeed
533 * entered before programming to disable it:
534 * 1] Check relevant display engine registers to verify if mode
535 * set disable sequence was followed.
536 * 2] Check if display uninitialize sequence is initialized.
537 */
538}
539
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200540static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
541 u32 state)
542{
543 int rewrites = 0;
544 int rereads = 0;
545 u32 v;
546
547 I915_WRITE(DC_STATE_EN, state);
548
549 /* It has been observed that disabling the dc6 state sometimes
550 * doesn't stick and dmc keeps returning old value. Make sure
551 * the write really sticks enough times and also force rewrite until
552 * we are confident that state is exactly what we want.
553 */
554 do {
555 v = I915_READ(DC_STATE_EN);
556
557 if (v != state) {
558 I915_WRITE(DC_STATE_EN, state);
559 rewrites++;
560 rereads = 0;
561 } else if (rereads++ > 5) {
562 break;
563 }
564
565 } while (rewrites < 100);
566
567 if (v != state)
568 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
569 state, v);
570
571 /* Most of the times we need one retry, avoid spam */
572 if (rewrites > 1)
573 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
574 state, rewrites);
575}
576
Imre Deakda2f41d2016-04-20 20:27:56 +0300577static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530578{
Imre Deakda2f41d2016-04-20 20:27:56 +0300579 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530580
Imre Deak13ae3a02015-11-04 19:24:16 +0200581 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200582 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200583 mask |= DC_STATE_EN_DC9;
584 else
585 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530586
Imre Deakda2f41d2016-04-20 20:27:56 +0300587 return mask;
588}
589
590void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
591{
592 u32 val;
593
594 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
595
596 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
597 dev_priv->csr.dc_state, val);
598 dev_priv->csr.dc_state = val;
599}
600
Imre Deak13e15922018-04-17 14:31:47 +0300601/**
602 * gen9_set_dc_state - set target display C power state
603 * @dev_priv: i915 device instance
604 * @state: target DC power state
605 * - DC_STATE_DISABLE
606 * - DC_STATE_EN_UPTO_DC5
607 * - DC_STATE_EN_UPTO_DC6
608 * - DC_STATE_EN_DC9
609 *
610 * Signal to DMC firmware/HW the target DC power state passed in @state.
611 * DMC/HW can turn off individual display clocks and power rails when entering
612 * a deeper DC power state (higher in number) and turns these back when exiting
613 * that state to a shallower power state (lower in number). The HW will decide
614 * when to actually enter a given state on an on-demand basis, for instance
615 * depending on the active state of display pipes. The state of display
616 * registers backed by affected power rails are saved/restored as needed.
617 *
618 * Based on the above enabling a deeper DC power state is asynchronous wrt.
619 * enabling it. Disabling a deeper power state is synchronous: for instance
620 * setting %DC_STATE_DISABLE won't complete until all HW resources are turned
621 * back on and register state is restored. This is guaranteed by the MMIO write
622 * to DC_STATE_EN blocking until the state is restored.
623 */
Imre Deakda2f41d2016-04-20 20:27:56 +0300624static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
625{
626 uint32_t val;
627 uint32_t mask;
628
Imre Deaka37baf32016-02-29 22:49:03 +0200629 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
630 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100631
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530632 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300633 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200634 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
635 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200636
637 /* Check if DMC is ignoring our DC state requests */
638 if ((val & mask) != dev_priv->csr.dc_state)
639 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
640 dev_priv->csr.dc_state, val & mask);
641
Imre Deak13ae3a02015-11-04 19:24:16 +0200642 val &= ~mask;
643 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200644
645 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200646
647 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530648}
649
Imre Deak13ae3a02015-11-04 19:24:16 +0200650void bxt_enable_dc9(struct drm_i915_private *dev_priv)
651{
652 assert_can_enable_dc9(dev_priv);
653
654 DRM_DEBUG_KMS("Enabling DC9\n");
655
Imre Deak78597992016-06-16 16:37:20 +0300656 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200657 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
658}
659
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530660void bxt_disable_dc9(struct drm_i915_private *dev_priv)
661{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530662 assert_can_disable_dc9(dev_priv);
663
664 DRM_DEBUG_KMS("Disabling DC9\n");
665
Imre Deak13ae3a02015-11-04 19:24:16 +0200666 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300667
668 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530669}
670
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200671static void assert_csr_loaded(struct drm_i915_private *dev_priv)
672{
673 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
674 "CSR program storage start is NULL\n");
675 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
676 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
677}
678
Suketu Shah5aefb232015-04-16 14:22:10 +0530679static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530680{
Suketu Shah5aefb232015-04-16 14:22:10 +0530681 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
682 SKL_DISP_PW_2);
683
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700684 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530685
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700686 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
687 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200688 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530689
690 assert_csr_loaded(dev_priv);
691}
692
Imre Deakf62c79b2016-04-20 20:27:57 +0300693void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530694{
Suketu Shah5aefb232015-04-16 14:22:10 +0530695 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530696
697 DRM_DEBUG_KMS("Enabling DC5\n");
698
Lucas De Marchi53421c22017-12-04 15:22:10 -0800699 /* Wa Display #1183: skl,kbl,cfl */
700 if (IS_GEN9_BC(dev_priv))
701 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
702 SKL_SELECT_ALTERNATE_DC_EXIT);
703
Imre Deak13ae3a02015-11-04 19:24:16 +0200704 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530705}
706
Suketu Shah93c7cb62015-04-16 14:22:13 +0530707static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530708{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700709 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
710 "Backlight is not disabled.\n");
711 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
712 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530713
714 assert_csr_loaded(dev_priv);
715}
716
Daniel Vetterc4c25252018-04-17 12:02:25 +0200717static void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530718{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530719 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530720
721 DRM_DEBUG_KMS("Enabling DC6\n");
722
Imre Deakb49be662018-04-19 18:51:09 +0300723 /* Wa Display #1183: skl,kbl,cfl */
724 if (IS_GEN9_BC(dev_priv))
725 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
726 SKL_SELECT_ALTERNATE_DC_EXIT);
Imre Deak13ae3a02015-11-04 19:24:16 +0200727
Imre Deakb49be662018-04-19 18:51:09 +0300728 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
Suketu Shahf75a1982015-04-16 14:22:11 +0530729}
730
Daniel Vetter9c065a72014-09-30 10:56:38 +0200731static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
732 struct i915_power_well *power_well)
733{
Imre Deak75e39682018-08-06 12:58:39 +0300734 const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
735 int pw_idx = power_well->desc->hsw.idx;
736 u32 mask = HSW_PWR_WELL_CTL_REQ(pw_idx);
737 u32 bios_req = I915_READ(regs->bios);
Imre Deak1af474f2017-07-06 17:40:34 +0300738
Imre Deak16e84912017-02-17 17:39:45 +0200739 /* Take over the request bit if set by BIOS. */
Imre Deak1af474f2017-07-06 17:40:34 +0300740 if (bios_req & mask) {
Imre Deak75e39682018-08-06 12:58:39 +0300741 u32 drv_req = I915_READ(regs->driver);
Imre Deak1af474f2017-07-06 17:40:34 +0300742
743 if (!(drv_req & mask))
Imre Deak75e39682018-08-06 12:58:39 +0300744 I915_WRITE(regs->driver, drv_req | mask);
745 I915_WRITE(regs->bios, bios_req & ~mask);
Imre Deak16e84912017-02-17 17:39:45 +0200746 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200747}
748
Imre Deak9c8d0b82016-06-13 16:44:34 +0300749static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
750 struct i915_power_well *power_well)
751{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300752 bxt_ddi_phy_init(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300753}
754
755static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
756 struct i915_power_well *power_well)
757{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300758 bxt_ddi_phy_uninit(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300759}
760
761static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
762 struct i915_power_well *power_well)
763{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300764 return bxt_ddi_phy_is_enabled(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300765}
766
Imre Deak9c8d0b82016-06-13 16:44:34 +0300767static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
768{
769 struct i915_power_well *power_well;
770
771 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
772 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300773 bxt_ddi_phy_verify_state(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300774
775 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
776 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300777 bxt_ddi_phy_verify_state(dev_priv, power_well->desc->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200778
779 if (IS_GEMINILAKE(dev_priv)) {
780 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
781 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300782 bxt_ddi_phy_verify_state(dev_priv,
783 power_well->desc->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200784 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300785}
786
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100787static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
788 struct i915_power_well *power_well)
789{
790 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
791}
792
Ville Syrjälä18a80672016-05-16 16:59:40 +0300793static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
794{
795 u32 tmp = I915_READ(DBUF_CTL);
796
797 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
798 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
799 "Unexpected DBuf power power state (0x%08x)\n", tmp);
800}
801
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100802static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
803 struct i915_power_well *power_well)
804{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200805 struct intel_cdclk_state cdclk_state = {};
806
Imre Deak5b773eb2016-02-29 22:49:05 +0200807 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300808
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200809 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
Ville Syrjälä64600bd2017-10-24 12:52:08 +0300810 /* Can't read out voltage_level so can't use intel_cdclk_changed() */
811 WARN_ON(intel_cdclk_needs_modeset(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300812
Ville Syrjälä18a80672016-05-16 16:59:40 +0300813 gen9_assert_dbuf_enabled(dev_priv);
814
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200815 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300816 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100817}
818
819static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
820 struct i915_power_well *power_well)
821{
Imre Deakf74ed082016-04-18 14:48:21 +0300822 if (!dev_priv->csr.dmc_payload)
823 return;
824
Imre Deaka37baf32016-02-29 22:49:03 +0200825 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100826 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200827 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100828 gen9_enable_dc5(dev_priv);
829}
830
Imre Deak3c1b38e2017-02-17 17:39:42 +0200831static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
832 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100833{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100834}
835
Daniel Vetter9c065a72014-09-30 10:56:38 +0200836static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
837 struct i915_power_well *power_well)
838{
839}
840
841static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
842 struct i915_power_well *power_well)
843{
844 return true;
845}
846
Ville Syrjälä2ee0da12017-06-01 17:36:16 +0300847static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
848 struct i915_power_well *power_well)
849{
850 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
851 i830_enable_pipe(dev_priv, PIPE_A);
852 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
853 i830_enable_pipe(dev_priv, PIPE_B);
854}
855
856static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
857 struct i915_power_well *power_well)
858{
859 i830_disable_pipe(dev_priv, PIPE_B);
860 i830_disable_pipe(dev_priv, PIPE_A);
861}
862
863static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
864 struct i915_power_well *power_well)
865{
866 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
867 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
868}
869
870static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
871 struct i915_power_well *power_well)
872{
873 if (power_well->count > 0)
874 i830_pipes_power_well_enable(dev_priv, power_well);
875 else
876 i830_pipes_power_well_disable(dev_priv, power_well);
877}
878
Daniel Vetter9c065a72014-09-30 10:56:38 +0200879static void vlv_set_power_well(struct drm_i915_private *dev_priv,
880 struct i915_power_well *power_well, bool enable)
881{
Imre Deakd13dd052018-08-06 12:58:38 +0300882 int pw_idx = power_well->desc->vlv.idx;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200883 u32 mask;
884 u32 state;
885 u32 ctrl;
886
Imre Deakd13dd052018-08-06 12:58:38 +0300887 mask = PUNIT_PWRGT_MASK(pw_idx);
888 state = enable ? PUNIT_PWRGT_PWR_ON(pw_idx) :
889 PUNIT_PWRGT_PWR_GATE(pw_idx);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200890
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100891 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200892
893#define COND \
894 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
895
896 if (COND)
897 goto out;
898
899 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
900 ctrl &= ~mask;
901 ctrl |= state;
902 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
903
904 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900905 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200906 state,
907 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
908
909#undef COND
910
911out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100912 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200913}
914
Daniel Vetter9c065a72014-09-30 10:56:38 +0200915static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
916 struct i915_power_well *power_well)
917{
918 vlv_set_power_well(dev_priv, power_well, true);
919}
920
921static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
922 struct i915_power_well *power_well)
923{
924 vlv_set_power_well(dev_priv, power_well, false);
925}
926
927static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
928 struct i915_power_well *power_well)
929{
Imre Deakd13dd052018-08-06 12:58:38 +0300930 int pw_idx = power_well->desc->vlv.idx;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200931 bool enabled = false;
932 u32 mask;
933 u32 state;
934 u32 ctrl;
935
Imre Deakd13dd052018-08-06 12:58:38 +0300936 mask = PUNIT_PWRGT_MASK(pw_idx);
937 ctrl = PUNIT_PWRGT_PWR_ON(pw_idx);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200938
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100939 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200940
941 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
942 /*
943 * We only ever set the power-on and power-gate states, anything
944 * else is unexpected.
945 */
Imre Deakd13dd052018-08-06 12:58:38 +0300946 WARN_ON(state != PUNIT_PWRGT_PWR_ON(pw_idx) &&
947 state != PUNIT_PWRGT_PWR_GATE(pw_idx));
Daniel Vetter9c065a72014-09-30 10:56:38 +0200948 if (state == ctrl)
949 enabled = true;
950
951 /*
952 * A transient state at this point would mean some unexpected party
953 * is poking at the power controls too.
954 */
955 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
956 WARN_ON(ctrl != state);
957
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100958 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200959
960 return enabled;
961}
962
Ville Syrjälä766078d2016-04-11 16:56:30 +0300963static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
964{
Hans de Goede721d4842016-12-02 15:29:04 +0100965 u32 val;
966
967 /*
968 * On driver load, a pipe may be active and driving a DSI display.
969 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
970 * (and never recovering) in this case. intel_dsi_post_disable() will
971 * clear it when we turn off the display.
972 */
973 val = I915_READ(DSPCLK_GATE_D);
974 val &= DPOUNIT_CLOCK_GATE_DISABLE;
975 val |= VRHUNIT_CLOCK_GATE_DISABLE;
976 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +0300977
978 /*
979 * Disable trickle feed and enable pnd deadline calculation
980 */
981 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
982 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +0300983
984 WARN_ON(dev_priv->rawclk_freq == 0);
985
986 I915_WRITE(RAWCLK_FREQ_VLV,
987 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +0300988}
989
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300990static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200991{
Lyude9504a892016-06-21 17:03:42 -0400992 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300993 enum pipe pipe;
994
995 /*
996 * Enable the CRI clock source so we can get at the
997 * display and the reference clock for VGA
998 * hotplug / manual detection. Supposedly DSI also
999 * needs the ref clock up and running.
1000 *
1001 * CHV DPLL B/C have some issues if VGA mode is enabled.
1002 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +00001003 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001004 u32 val = I915_READ(DPLL(pipe));
1005
1006 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1007 if (pipe != PIPE_A)
1008 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1009
1010 I915_WRITE(DPLL(pipe), val);
1011 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001012
Ville Syrjälä766078d2016-04-11 16:56:30 +03001013 vlv_init_display_clock_gating(dev_priv);
1014
Daniel Vetter9c065a72014-09-30 10:56:38 +02001015 spin_lock_irq(&dev_priv->irq_lock);
1016 valleyview_enable_display_irqs(dev_priv);
1017 spin_unlock_irq(&dev_priv->irq_lock);
1018
1019 /*
1020 * During driver initialization/resume we can avoid restoring the
1021 * part of the HW/SW state that will be inited anyway explicitly.
1022 */
1023 if (dev_priv->power_domains.initializing)
1024 return;
1025
Daniel Vetterb9632912014-09-30 10:56:44 +02001026 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001027
Lyude9504a892016-06-21 17:03:42 -04001028 /* Re-enable the ADPA, if we have one */
1029 for_each_intel_encoder(&dev_priv->drm, encoder) {
1030 if (encoder->type == INTEL_OUTPUT_ANALOG)
1031 intel_crt_reset(&encoder->base);
1032 }
1033
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001034 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001035
1036 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001037}
1038
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001039static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1040{
1041 spin_lock_irq(&dev_priv->irq_lock);
1042 valleyview_disable_display_irqs(dev_priv);
1043 spin_unlock_irq(&dev_priv->irq_lock);
1044
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001045 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001046 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001047
Imre Deak78597992016-06-16 16:37:20 +03001048 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001049
Lyudeb64b5402016-10-26 12:36:09 -04001050 /* Prevent us from re-enabling polling on accident in late suspend */
1051 if (!dev_priv->drm.dev->power.is_suspended)
1052 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001053}
1054
1055static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1056 struct i915_power_well *power_well)
1057{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001058 vlv_set_power_well(dev_priv, power_well, true);
1059
1060 vlv_display_power_well_init(dev_priv);
1061}
1062
Daniel Vetter9c065a72014-09-30 10:56:38 +02001063static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1064 struct i915_power_well *power_well)
1065{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001066 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001067
1068 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001069}
1070
1071static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1072 struct i915_power_well *power_well)
1073{
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001074 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001075 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1076
1077 vlv_set_power_well(dev_priv, power_well, true);
1078
1079 /*
1080 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1081 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1082 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1083 * b. The other bits such as sfr settings / modesel may all
1084 * be set to 0.
1085 *
1086 * This should only be done on init and resume from S3 with
1087 * both PLLs disabled, or we risk losing DPIO and PLL
1088 * synchronization.
1089 */
1090 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1091}
1092
1093static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1094 struct i915_power_well *power_well)
1095{
1096 enum pipe pipe;
1097
Daniel Vetter9c065a72014-09-30 10:56:38 +02001098 for_each_pipe(dev_priv, pipe)
1099 assert_pll_disabled(dev_priv, pipe);
1100
1101 /* Assert common reset */
1102 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1103
1104 vlv_set_power_well(dev_priv, power_well, false);
1105}
1106
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001107#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001108
Imre Deak438b8dc2017-07-11 23:42:30 +03001109static struct i915_power_well *
1110lookup_power_well(struct drm_i915_private *dev_priv,
1111 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001112{
1113 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001114 int i;
1115
Imre Deakfc17f222015-11-04 19:24:11 +02001116 for (i = 0; i < power_domains->power_well_count; i++) {
1117 struct i915_power_well *power_well;
1118
1119 power_well = &power_domains->power_wells[i];
Imre Deakf28ec6f2018-08-06 12:58:37 +03001120 if (power_well->desc->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001121 return power_well;
1122 }
1123
1124 return NULL;
1125}
1126
1127#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1128
1129static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1130{
1131 struct i915_power_well *cmn_bc =
1132 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1133 struct i915_power_well *cmn_d =
1134 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1135 u32 phy_control = dev_priv->chv_phy_control;
1136 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001137 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001138
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001139 /*
1140 * The BIOS can leave the PHY is some weird state
1141 * where it doesn't fully power down some parts.
1142 * Disable the asserts until the PHY has been fully
1143 * reset (ie. the power well has been disabled at
1144 * least once).
1145 */
1146 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1147 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1148 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1149 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1150 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1151 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1152 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1153
1154 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1155 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1156 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1157 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1158
Imre Deakf28ec6f2018-08-06 12:58:37 +03001159 if (cmn_bc->desc->ops->is_enabled(dev_priv, cmn_bc)) {
Ville Syrjälä30142272015-07-08 23:46:01 +03001160 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1161
1162 /* this assumes override is only used to enable lanes */
1163 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1164 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1165
1166 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1167 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1168
1169 /* CL1 is on whenever anything is on in either channel */
1170 if (BITS_SET(phy_control,
1171 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1172 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1173 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1174
1175 /*
1176 * The DPLLB check accounts for the pipe B + port A usage
1177 * with CL2 powered up but all the lanes in the second channel
1178 * powered down.
1179 */
1180 if (BITS_SET(phy_control,
1181 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1182 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1183 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1184
1185 if (BITS_SET(phy_control,
1186 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1187 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1188 if (BITS_SET(phy_control,
1189 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1190 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1191
1192 if (BITS_SET(phy_control,
1193 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1194 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1195 if (BITS_SET(phy_control,
1196 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1197 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1198 }
1199
Imre Deakf28ec6f2018-08-06 12:58:37 +03001200 if (cmn_d->desc->ops->is_enabled(dev_priv, cmn_d)) {
Ville Syrjälä30142272015-07-08 23:46:01 +03001201 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1202
1203 /* this assumes override is only used to enable lanes */
1204 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1205 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1206
1207 if (BITS_SET(phy_control,
1208 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1209 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1210
1211 if (BITS_SET(phy_control,
1212 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1213 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1214 if (BITS_SET(phy_control,
1215 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1216 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1217 }
1218
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001219 phy_status &= phy_status_mask;
1220
Ville Syrjälä30142272015-07-08 23:46:01 +03001221 /*
1222 * The PHY may be busy with some initial calibration and whatnot,
1223 * so the power state can take a while to actually change.
1224 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001225 if (intel_wait_for_register(dev_priv,
1226 DISPLAY_PHY_STATUS,
1227 phy_status_mask,
1228 phy_status,
1229 10))
1230 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1231 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1232 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001233}
1234
1235#undef BITS_SET
1236
Daniel Vetter9c065a72014-09-30 10:56:38 +02001237static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1238 struct i915_power_well *power_well)
1239{
1240 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001241 enum pipe pipe;
1242 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001243
Imre Deakf28ec6f2018-08-06 12:58:37 +03001244 WARN_ON_ONCE(power_well->desc->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1245 power_well->desc->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001246
Imre Deakf28ec6f2018-08-06 12:58:37 +03001247 if (power_well->desc->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001248 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001249 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001250 } else {
1251 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001252 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001253 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001254
1255 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001256 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1257 vlv_set_power_well(dev_priv, power_well, true);
1258
1259 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001260 if (intel_wait_for_register(dev_priv,
1261 DISPLAY_PHY_STATUS,
1262 PHY_POWERGOOD(phy),
1263 PHY_POWERGOOD(phy),
1264 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001265 DRM_ERROR("Display PHY %d is not power up\n", phy);
1266
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001267 mutex_lock(&dev_priv->sb_lock);
1268
1269 /* Enable dynamic power down */
1270 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001271 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1272 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001273 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1274
Imre Deakf28ec6f2018-08-06 12:58:37 +03001275 if (power_well->desc->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001276 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1277 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1278 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001279 } else {
1280 /*
1281 * Force the non-existing CL2 off. BXT does this
1282 * too, so maybe it saves some power even though
1283 * CL2 doesn't exist?
1284 */
1285 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1286 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1287 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001288 }
1289
1290 mutex_unlock(&dev_priv->sb_lock);
1291
Ville Syrjälä70722462015-04-10 18:21:28 +03001292 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1293 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001294
1295 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1296 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001297
1298 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001299}
1300
1301static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1302 struct i915_power_well *power_well)
1303{
1304 enum dpio_phy phy;
1305
Imre Deakf28ec6f2018-08-06 12:58:37 +03001306 WARN_ON_ONCE(power_well->desc->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1307 power_well->desc->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001308
Imre Deakf28ec6f2018-08-06 12:58:37 +03001309 if (power_well->desc->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001310 phy = DPIO_PHY0;
1311 assert_pll_disabled(dev_priv, PIPE_A);
1312 assert_pll_disabled(dev_priv, PIPE_B);
1313 } else {
1314 phy = DPIO_PHY1;
1315 assert_pll_disabled(dev_priv, PIPE_C);
1316 }
1317
Ville Syrjälä70722462015-04-10 18:21:28 +03001318 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1319 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001320
1321 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001322
1323 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1324 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001325
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001326 /* PHY is fully reset now, so we can enable the PHY state asserts */
1327 dev_priv->chv_phy_assert[phy] = true;
1328
Ville Syrjälä30142272015-07-08 23:46:01 +03001329 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001330}
1331
Ville Syrjälä6669e392015-07-08 23:46:00 +03001332static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1333 enum dpio_channel ch, bool override, unsigned int mask)
1334{
1335 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1336 u32 reg, val, expected, actual;
1337
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001338 /*
1339 * The BIOS can leave the PHY is some weird state
1340 * where it doesn't fully power down some parts.
1341 * Disable the asserts until the PHY has been fully
1342 * reset (ie. the power well has been disabled at
1343 * least once).
1344 */
1345 if (!dev_priv->chv_phy_assert[phy])
1346 return;
1347
Ville Syrjälä6669e392015-07-08 23:46:00 +03001348 if (ch == DPIO_CH0)
1349 reg = _CHV_CMN_DW0_CH0;
1350 else
1351 reg = _CHV_CMN_DW6_CH1;
1352
1353 mutex_lock(&dev_priv->sb_lock);
1354 val = vlv_dpio_read(dev_priv, pipe, reg);
1355 mutex_unlock(&dev_priv->sb_lock);
1356
1357 /*
1358 * This assumes !override is only used when the port is disabled.
1359 * All lanes should power down even without the override when
1360 * the port is disabled.
1361 */
1362 if (!override || mask == 0xf) {
1363 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1364 /*
1365 * If CH1 common lane is not active anymore
1366 * (eg. for pipe B DPLL) the entire channel will
1367 * shut down, which causes the common lane registers
1368 * to read as 0. That means we can't actually check
1369 * the lane power down status bits, but as the entire
1370 * register reads as 0 it's a good indication that the
1371 * channel is indeed entirely powered down.
1372 */
1373 if (ch == DPIO_CH1 && val == 0)
1374 expected = 0;
1375 } else if (mask != 0x0) {
1376 expected = DPIO_ANYDL_POWERDOWN;
1377 } else {
1378 expected = 0;
1379 }
1380
1381 if (ch == DPIO_CH0)
1382 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1383 else
1384 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1385 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1386
1387 WARN(actual != expected,
1388 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1389 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1390 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1391 reg, val);
1392}
1393
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001394bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1395 enum dpio_channel ch, bool override)
1396{
1397 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1398 bool was_override;
1399
1400 mutex_lock(&power_domains->lock);
1401
1402 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1403
1404 if (override == was_override)
1405 goto out;
1406
1407 if (override)
1408 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1409 else
1410 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1411
1412 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1413
1414 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1415 phy, ch, dev_priv->chv_phy_control);
1416
Ville Syrjälä30142272015-07-08 23:46:01 +03001417 assert_chv_phy_status(dev_priv);
1418
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001419out:
1420 mutex_unlock(&power_domains->lock);
1421
1422 return was_override;
1423}
1424
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001425void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1426 bool override, unsigned int mask)
1427{
1428 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1429 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1430 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1431 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1432
1433 mutex_lock(&power_domains->lock);
1434
1435 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1436 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1437
1438 if (override)
1439 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1440 else
1441 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1442
1443 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1444
1445 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1446 phy, ch, mask, dev_priv->chv_phy_control);
1447
Ville Syrjälä30142272015-07-08 23:46:01 +03001448 assert_chv_phy_status(dev_priv);
1449
Ville Syrjälä6669e392015-07-08 23:46:00 +03001450 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1451
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001452 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001453}
1454
1455static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1456 struct i915_power_well *power_well)
1457{
Imre Deakf49193c2017-07-06 17:40:23 +03001458 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001459 bool enabled;
1460 u32 state, ctrl;
1461
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001462 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001463
1464 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1465 /*
1466 * We only ever set the power-on and power-gate states, anything
1467 * else is unexpected.
1468 */
1469 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1470 enabled = state == DP_SSS_PWR_ON(pipe);
1471
1472 /*
1473 * A transient state at this point would mean some unexpected party
1474 * is poking at the power controls too.
1475 */
1476 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1477 WARN_ON(ctrl << 16 != state);
1478
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001479 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001480
1481 return enabled;
1482}
1483
1484static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1485 struct i915_power_well *power_well,
1486 bool enable)
1487{
Imre Deakf49193c2017-07-06 17:40:23 +03001488 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001489 u32 state;
1490 u32 ctrl;
1491
1492 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1493
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001494 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001495
1496#define COND \
1497 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1498
1499 if (COND)
1500 goto out;
1501
1502 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1503 ctrl &= ~DP_SSC_MASK(pipe);
1504 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1505 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1506
1507 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001508 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001509 state,
1510 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1511
1512#undef COND
1513
1514out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001515 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001516}
1517
Daniel Vetter9c065a72014-09-30 10:56:38 +02001518static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1519 struct i915_power_well *power_well)
1520{
Daniel Vetter9c065a72014-09-30 10:56:38 +02001521 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001522
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001523 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001524}
1525
1526static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1527 struct i915_power_well *power_well)
1528{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001529 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001530
Daniel Vetter9c065a72014-09-30 10:56:38 +02001531 chv_set_pipe_power_well(dev_priv, power_well, false);
1532}
1533
Imre Deak09731282016-02-17 14:17:42 +02001534static void
1535__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1536 enum intel_display_power_domain domain)
1537{
1538 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1539 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001540
Imre Deak75ccb2e2017-02-17 17:39:43 +02001541 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001542 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001543
1544 power_domains->domain_use_count[domain]++;
1545}
1546
Daniel Vettere4e76842014-09-30 10:56:42 +02001547/**
1548 * intel_display_power_get - grab a power domain reference
1549 * @dev_priv: i915 device instance
1550 * @domain: power domain to reference
1551 *
1552 * This function grabs a power domain reference for @domain and ensures that the
1553 * power domain and all its parents are powered up. Therefore users should only
1554 * grab a reference to the innermost power domain they need.
1555 *
1556 * Any power domain reference obtained by this function must have a symmetric
1557 * call to intel_display_power_put() to release the reference again.
1558 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001559void intel_display_power_get(struct drm_i915_private *dev_priv,
1560 enum intel_display_power_domain domain)
1561{
Imre Deak09731282016-02-17 14:17:42 +02001562 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001563
1564 intel_runtime_pm_get(dev_priv);
1565
Imre Deak09731282016-02-17 14:17:42 +02001566 mutex_lock(&power_domains->lock);
1567
1568 __intel_display_power_get_domain(dev_priv, domain);
1569
1570 mutex_unlock(&power_domains->lock);
1571}
1572
1573/**
1574 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1575 * @dev_priv: i915 device instance
1576 * @domain: power domain to reference
1577 *
1578 * This function grabs a power domain reference for @domain and ensures that the
1579 * power domain and all its parents are powered up. Therefore users should only
1580 * grab a reference to the innermost power domain they need.
1581 *
1582 * Any power domain reference obtained by this function must have a symmetric
1583 * call to intel_display_power_put() to release the reference again.
1584 */
1585bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1586 enum intel_display_power_domain domain)
1587{
1588 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1589 bool is_enabled;
1590
1591 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1592 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001593
1594 mutex_lock(&power_domains->lock);
1595
Imre Deak09731282016-02-17 14:17:42 +02001596 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1597 __intel_display_power_get_domain(dev_priv, domain);
1598 is_enabled = true;
1599 } else {
1600 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001601 }
1602
Daniel Vetter9c065a72014-09-30 10:56:38 +02001603 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001604
1605 if (!is_enabled)
1606 intel_runtime_pm_put(dev_priv);
1607
1608 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001609}
1610
Daniel Vettere4e76842014-09-30 10:56:42 +02001611/**
1612 * intel_display_power_put - release a power domain reference
1613 * @dev_priv: i915 device instance
1614 * @domain: power domain to reference
1615 *
1616 * This function drops the power domain reference obtained by
1617 * intel_display_power_get() and might power down the corresponding hardware
1618 * block right away if this is the last reference.
1619 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001620void intel_display_power_put(struct drm_i915_private *dev_priv,
1621 enum intel_display_power_domain domain)
1622{
1623 struct i915_power_domains *power_domains;
1624 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001625
1626 power_domains = &dev_priv->power_domains;
1627
1628 mutex_lock(&power_domains->lock);
1629
Daniel Stone11c86db2015-11-20 15:55:34 +00001630 WARN(!power_domains->domain_use_count[domain],
1631 "Use count on domain %s is already zero\n",
1632 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001633 power_domains->domain_use_count[domain]--;
1634
Imre Deak75ccb2e2017-02-17 17:39:43 +02001635 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001636 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001637
1638 mutex_unlock(&power_domains->lock);
1639
1640 intel_runtime_pm_put(dev_priv);
1641}
1642
Imre Deak965a79a2017-07-06 17:40:40 +03001643#define I830_PIPES_POWER_DOMAINS ( \
1644 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1645 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1646 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1647 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1648 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1649 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001650 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001651
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001652#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001653 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1654 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1655 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1656 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1657 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1658 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1659 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1660 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1661 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1662 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1663 BIT_ULL(POWER_DOMAIN_VGA) | \
1664 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1665 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1666 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1667 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1668 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001669
1670#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001671 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1672 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1673 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1674 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1675 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1676 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001677
1678#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001679 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1680 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1681 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001682
1683#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001684 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1685 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1686 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001687
1688#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001689 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1690 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1691 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001692
1693#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001694 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1695 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1696 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001697
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001698#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001699 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1700 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1701 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1702 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1703 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1704 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1705 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1706 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1707 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1708 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1709 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1710 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1711 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1712 BIT_ULL(POWER_DOMAIN_VGA) | \
1713 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1714 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1715 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1716 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1717 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1718 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001719
Daniel Vetter9c065a72014-09-30 10:56:38 +02001720#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001721 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1722 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1723 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1724 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1725 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001726
1727#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001728 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1729 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1730 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001731
Imre Deak965a79a2017-07-06 17:40:40 +03001732#define HSW_DISPLAY_POWER_DOMAINS ( \
1733 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1734 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1735 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1736 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1737 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1738 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1739 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1740 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1741 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1742 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1743 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1744 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1745 BIT_ULL(POWER_DOMAIN_VGA) | \
1746 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1747 BIT_ULL(POWER_DOMAIN_INIT))
1748
1749#define BDW_DISPLAY_POWER_DOMAINS ( \
1750 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1751 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1752 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1753 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1754 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1755 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1756 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1757 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1758 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1759 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1760 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1761 BIT_ULL(POWER_DOMAIN_VGA) | \
1762 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1763 BIT_ULL(POWER_DOMAIN_INIT))
1764
1765#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1766 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1767 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1768 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1769 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1770 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1771 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1772 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1773 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1774 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1775 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1776 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1777 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1778 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1779 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1780 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1781 BIT_ULL(POWER_DOMAIN_VGA) | \
1782 BIT_ULL(POWER_DOMAIN_INIT))
1783#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
1784 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
1785 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1786 BIT_ULL(POWER_DOMAIN_INIT))
1787#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1788 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1789 BIT_ULL(POWER_DOMAIN_INIT))
1790#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1791 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1792 BIT_ULL(POWER_DOMAIN_INIT))
1793#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
1794 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1795 BIT_ULL(POWER_DOMAIN_INIT))
1796#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1797 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001798 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001799 BIT_ULL(POWER_DOMAIN_MODESET) | \
1800 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1801 BIT_ULL(POWER_DOMAIN_INIT))
1802
1803#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1804 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1805 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1806 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1807 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1808 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1809 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1810 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1811 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1812 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1813 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1814 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1815 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1816 BIT_ULL(POWER_DOMAIN_VGA) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001817 BIT_ULL(POWER_DOMAIN_INIT))
1818#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1819 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001820 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001821 BIT_ULL(POWER_DOMAIN_MODESET) | \
1822 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä54c105d2017-12-08 23:37:37 +02001823 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001824 BIT_ULL(POWER_DOMAIN_INIT))
1825#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
1826 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1827 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1828 BIT_ULL(POWER_DOMAIN_INIT))
1829#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
1830 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1831 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1832 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1833 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1834 BIT_ULL(POWER_DOMAIN_INIT))
1835
1836#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1837 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1838 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1839 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1840 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1841 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1842 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1843 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1844 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1845 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1846 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1847 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1848 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1849 BIT_ULL(POWER_DOMAIN_VGA) | \
1850 BIT_ULL(POWER_DOMAIN_INIT))
1851#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
1852 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
1853#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1854 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
1855#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1856 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
1857#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
1858 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1859 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1860 BIT_ULL(POWER_DOMAIN_INIT))
1861#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
1862 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1863 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1864 BIT_ULL(POWER_DOMAIN_INIT))
1865#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
1866 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1867 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1868 BIT_ULL(POWER_DOMAIN_INIT))
1869#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
1870 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Imre Deak52528052018-06-21 21:44:49 +03001871 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001872 BIT_ULL(POWER_DOMAIN_INIT))
1873#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
1874 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1875 BIT_ULL(POWER_DOMAIN_INIT))
1876#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
1877 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1878 BIT_ULL(POWER_DOMAIN_INIT))
1879#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1880 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001881 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001882 BIT_ULL(POWER_DOMAIN_MODESET) | \
1883 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä156961a2017-12-08 23:37:36 +02001884 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001885 BIT_ULL(POWER_DOMAIN_INIT))
1886
1887#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1888 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1889 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1890 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1891 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1892 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1893 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1894 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1895 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1896 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1897 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001898 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001899 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1900 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1901 BIT_ULL(POWER_DOMAIN_AUX_D) | \
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001902 BIT_ULL(POWER_DOMAIN_AUX_F) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001903 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1904 BIT_ULL(POWER_DOMAIN_VGA) | \
1905 BIT_ULL(POWER_DOMAIN_INIT))
1906#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
1907 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001908 BIT_ULL(POWER_DOMAIN_INIT))
1909#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
1910 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1911 BIT_ULL(POWER_DOMAIN_INIT))
1912#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
1913 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1914 BIT_ULL(POWER_DOMAIN_INIT))
1915#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
1916 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1917 BIT_ULL(POWER_DOMAIN_INIT))
1918#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
1919 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Dhinakaran Pandiyanb891d5e2018-02-23 14:15:15 -08001920 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001921 BIT_ULL(POWER_DOMAIN_INIT))
1922#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
1923 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1924 BIT_ULL(POWER_DOMAIN_INIT))
1925#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
1926 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1927 BIT_ULL(POWER_DOMAIN_INIT))
1928#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
1929 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1930 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001931#define CNL_DISPLAY_AUX_F_POWER_DOMAINS ( \
1932 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1933 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001934#define CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS ( \
1935 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1936 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak965a79a2017-07-06 17:40:40 +03001937#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1938 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulin6e7a3f52018-01-11 08:24:17 +00001939 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001940 BIT_ULL(POWER_DOMAIN_MODESET) | \
1941 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001942 BIT_ULL(POWER_DOMAIN_INIT))
1943
Imre Deak67ca07e2018-06-26 17:22:32 +03001944/*
1945 * ICL PW_0/PG_0 domains (HW/DMC control):
1946 * - PCI
1947 * - clocks except port PLL
1948 * - central power except FBC
1949 * - shared functions except pipe interrupts, pipe MBUS, DBUF registers
1950 * ICL PW_1/PG_1 domains (HW/DMC control):
1951 * - DBUF function
1952 * - PIPE_A and its planes, except VGA
1953 * - transcoder EDP + PSR
1954 * - transcoder DSI
1955 * - DDI_A
1956 * - FBC
1957 */
1958#define ICL_PW_4_POWER_DOMAINS ( \
1959 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1960 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1961 BIT_ULL(POWER_DOMAIN_INIT))
1962 /* VDSC/joining */
1963#define ICL_PW_3_POWER_DOMAINS ( \
1964 ICL_PW_4_POWER_DOMAINS | \
1965 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1966 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1967 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1968 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1969 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1970 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1971 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1972 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1973 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1974 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1975 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1976 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1977 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1978 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
1979 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1980 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1981 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1982 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1983 BIT_ULL(POWER_DOMAIN_AUX_E) | \
1984 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1985 BIT_ULL(POWER_DOMAIN_AUX_TBT1) | \
1986 BIT_ULL(POWER_DOMAIN_AUX_TBT2) | \
1987 BIT_ULL(POWER_DOMAIN_AUX_TBT3) | \
1988 BIT_ULL(POWER_DOMAIN_AUX_TBT4) | \
1989 BIT_ULL(POWER_DOMAIN_VGA) | \
1990 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1991 BIT_ULL(POWER_DOMAIN_INIT))
1992 /*
1993 * - transcoder WD
1994 * - KVMR (HW control)
1995 */
1996#define ICL_PW_2_POWER_DOMAINS ( \
1997 ICL_PW_3_POWER_DOMAINS | \
1998 BIT_ULL(POWER_DOMAIN_INIT))
1999 /*
2000 * - eDP/DSI VDSC
2001 * - KVMR (HW control)
2002 */
2003#define ICL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
2004 ICL_PW_2_POWER_DOMAINS | \
2005 BIT_ULL(POWER_DOMAIN_MODESET) | \
2006 BIT_ULL(POWER_DOMAIN_AUX_A) | \
2007 BIT_ULL(POWER_DOMAIN_INIT))
2008
2009#define ICL_DDI_IO_A_POWER_DOMAINS ( \
2010 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
2011#define ICL_DDI_IO_B_POWER_DOMAINS ( \
2012 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
2013#define ICL_DDI_IO_C_POWER_DOMAINS ( \
2014 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
2015#define ICL_DDI_IO_D_POWER_DOMAINS ( \
2016 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO))
2017#define ICL_DDI_IO_E_POWER_DOMAINS ( \
2018 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO))
2019#define ICL_DDI_IO_F_POWER_DOMAINS ( \
2020 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO))
2021
2022#define ICL_AUX_A_IO_POWER_DOMAINS ( \
2023 BIT_ULL(POWER_DOMAIN_AUX_A))
2024#define ICL_AUX_B_IO_POWER_DOMAINS ( \
2025 BIT_ULL(POWER_DOMAIN_AUX_B))
2026#define ICL_AUX_C_IO_POWER_DOMAINS ( \
2027 BIT_ULL(POWER_DOMAIN_AUX_C))
2028#define ICL_AUX_D_IO_POWER_DOMAINS ( \
2029 BIT_ULL(POWER_DOMAIN_AUX_D))
2030#define ICL_AUX_E_IO_POWER_DOMAINS ( \
2031 BIT_ULL(POWER_DOMAIN_AUX_E))
2032#define ICL_AUX_F_IO_POWER_DOMAINS ( \
2033 BIT_ULL(POWER_DOMAIN_AUX_F))
2034#define ICL_AUX_TBT1_IO_POWER_DOMAINS ( \
2035 BIT_ULL(POWER_DOMAIN_AUX_TBT1))
2036#define ICL_AUX_TBT2_IO_POWER_DOMAINS ( \
2037 BIT_ULL(POWER_DOMAIN_AUX_TBT2))
2038#define ICL_AUX_TBT3_IO_POWER_DOMAINS ( \
2039 BIT_ULL(POWER_DOMAIN_AUX_TBT3))
2040#define ICL_AUX_TBT4_IO_POWER_DOMAINS ( \
2041 BIT_ULL(POWER_DOMAIN_AUX_TBT4))
2042
Daniel Vetter9c065a72014-09-30 10:56:38 +02002043static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002044 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002045 .enable = i9xx_always_on_power_well_noop,
2046 .disable = i9xx_always_on_power_well_noop,
2047 .is_enabled = i9xx_always_on_power_well_enabled,
2048};
2049
2050static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002051 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002052 .enable = chv_pipe_power_well_enable,
2053 .disable = chv_pipe_power_well_disable,
2054 .is_enabled = chv_pipe_power_well_enabled,
2055};
2056
2057static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002058 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002059 .enable = chv_dpio_cmn_power_well_enable,
2060 .disable = chv_dpio_cmn_power_well_disable,
2061 .is_enabled = vlv_power_well_enabled,
2062};
2063
Imre Deakf28ec6f2018-08-06 12:58:37 +03002064static const struct i915_power_well_desc i9xx_always_on_power_well[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002065 {
2066 .name = "always-on",
2067 .always_on = 1,
2068 .domains = POWER_DOMAIN_MASK,
2069 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002070 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002071 },
2072};
2073
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002074static const struct i915_power_well_ops i830_pipes_power_well_ops = {
2075 .sync_hw = i830_pipes_power_well_sync_hw,
2076 .enable = i830_pipes_power_well_enable,
2077 .disable = i830_pipes_power_well_disable,
2078 .is_enabled = i830_pipes_power_well_enabled,
2079};
2080
Imre Deakf28ec6f2018-08-06 12:58:37 +03002081static const struct i915_power_well_desc i830_power_wells[] = {
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002082 {
2083 .name = "always-on",
2084 .always_on = 1,
2085 .domains = POWER_DOMAIN_MASK,
2086 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002087 .id = DISP_PW_ID_NONE,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002088 },
2089 {
2090 .name = "pipes",
2091 .domains = I830_PIPES_POWER_DOMAINS,
2092 .ops = &i830_pipes_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002093 .id = DISP_PW_ID_NONE,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002094 },
2095};
2096
Daniel Vetter9c065a72014-09-30 10:56:38 +02002097static const struct i915_power_well_ops hsw_power_well_ops = {
2098 .sync_hw = hsw_power_well_sync_hw,
2099 .enable = hsw_power_well_enable,
2100 .disable = hsw_power_well_disable,
2101 .is_enabled = hsw_power_well_enabled,
2102};
2103
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002104static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002105 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002106 .enable = gen9_dc_off_power_well_enable,
2107 .disable = gen9_dc_off_power_well_disable,
2108 .is_enabled = gen9_dc_off_power_well_enabled,
2109};
2110
Imre Deak9c8d0b82016-06-13 16:44:34 +03002111static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002112 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002113 .enable = bxt_dpio_cmn_power_well_enable,
2114 .disable = bxt_dpio_cmn_power_well_disable,
2115 .is_enabled = bxt_dpio_cmn_power_well_enabled,
2116};
2117
Imre Deak75e39682018-08-06 12:58:39 +03002118static const struct i915_power_well_regs hsw_power_well_regs = {
2119 .bios = HSW_PWR_WELL_CTL1,
2120 .driver = HSW_PWR_WELL_CTL2,
2121 .kvmr = HSW_PWR_WELL_CTL3,
2122 .debug = HSW_PWR_WELL_CTL4,
2123};
2124
Imre Deakf28ec6f2018-08-06 12:58:37 +03002125static const struct i915_power_well_desc hsw_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002126 {
2127 .name = "always-on",
2128 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002129 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002130 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002131 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002132 },
2133 {
2134 .name = "display",
2135 .domains = HSW_DISPLAY_POWER_DOMAINS,
2136 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002137 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002138 {
Imre Deak75e39682018-08-06 12:58:39 +03002139 .hsw.regs = &hsw_power_well_regs,
2140 .hsw.idx = HSW_PW_CTL_IDX_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002141 .hsw.has_vga = true,
2142 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002143 },
2144};
2145
Imre Deakf28ec6f2018-08-06 12:58:37 +03002146static const struct i915_power_well_desc bdw_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002147 {
2148 .name = "always-on",
2149 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002150 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002151 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002152 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002153 },
2154 {
2155 .name = "display",
2156 .domains = BDW_DISPLAY_POWER_DOMAINS,
2157 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002158 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002159 {
Imre Deak75e39682018-08-06 12:58:39 +03002160 .hsw.regs = &hsw_power_well_regs,
2161 .hsw.idx = HSW_PW_CTL_IDX_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002162 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2163 .hsw.has_vga = true,
2164 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002165 },
2166};
2167
2168static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002169 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002170 .enable = vlv_display_power_well_enable,
2171 .disable = vlv_display_power_well_disable,
2172 .is_enabled = vlv_power_well_enabled,
2173};
2174
2175static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002176 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002177 .enable = vlv_dpio_cmn_power_well_enable,
2178 .disable = vlv_dpio_cmn_power_well_disable,
2179 .is_enabled = vlv_power_well_enabled,
2180};
2181
2182static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002183 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002184 .enable = vlv_power_well_enable,
2185 .disable = vlv_power_well_disable,
2186 .is_enabled = vlv_power_well_enabled,
2187};
2188
Imre Deakf28ec6f2018-08-06 12:58:37 +03002189static const struct i915_power_well_desc vlv_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002190 {
2191 .name = "always-on",
2192 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002193 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002194 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002195 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002196 },
2197 {
2198 .name = "display",
2199 .domains = VLV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002200 .ops = &vlv_display_power_well_ops,
Imre Deakd13dd052018-08-06 12:58:38 +03002201 .id = PUNIT_POWER_WELL_DISP2D,
2202 {
2203 .vlv.idx = PUNIT_PWGT_IDX_DISP2D,
2204 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002205 },
2206 {
2207 .name = "dpio-tx-b-01",
2208 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2209 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2210 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2211 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2212 .ops = &vlv_dpio_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002213 .id = DISP_PW_ID_NONE,
Imre Deakd13dd052018-08-06 12:58:38 +03002214 {
2215 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_B_LANES_01,
2216 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002217 },
2218 {
2219 .name = "dpio-tx-b-23",
2220 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2221 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2222 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2223 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2224 .ops = &vlv_dpio_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002225 .id = DISP_PW_ID_NONE,
Imre Deakd13dd052018-08-06 12:58:38 +03002226 {
2227 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_B_LANES_23,
2228 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002229 },
2230 {
2231 .name = "dpio-tx-c-01",
2232 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2233 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2234 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2235 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2236 .ops = &vlv_dpio_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002237 .id = DISP_PW_ID_NONE,
Imre Deakd13dd052018-08-06 12:58:38 +03002238 {
2239 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_C_LANES_01,
2240 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002241 },
2242 {
2243 .name = "dpio-tx-c-23",
2244 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2245 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2246 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2247 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2248 .ops = &vlv_dpio_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002249 .id = DISP_PW_ID_NONE,
Imre Deakd13dd052018-08-06 12:58:38 +03002250 {
2251 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_C_LANES_23,
2252 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002253 },
2254 {
2255 .name = "dpio-common",
2256 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002257 .ops = &vlv_dpio_cmn_power_well_ops,
Imre Deakd13dd052018-08-06 12:58:38 +03002258 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
2259 {
2260 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_BC,
2261 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002262 },
2263};
2264
Imre Deakf28ec6f2018-08-06 12:58:37 +03002265static const struct i915_power_well_desc chv_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002266 {
2267 .name = "always-on",
2268 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002269 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002270 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002271 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002272 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002273 {
2274 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002275 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002276 * Pipe A power well is the new disp2d well. Pipe B and C
2277 * power wells don't actually exist. Pipe A power well is
2278 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002279 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002280 .domains = CHV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002281 .ops = &chv_pipe_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002282 .id = DISP_PW_ID_NONE,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002283 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002284 {
2285 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002286 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002287 .ops = &chv_dpio_cmn_power_well_ops,
Imre Deakd13dd052018-08-06 12:58:38 +03002288 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
2289 {
2290 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_BC,
2291 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002292 },
2293 {
2294 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002295 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002296 .ops = &chv_dpio_cmn_power_well_ops,
Imre Deakd13dd052018-08-06 12:58:38 +03002297 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
2298 {
2299 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_D,
2300 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002301 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002302};
2303
Suketu Shah5aefb232015-04-16 14:22:10 +05302304bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002305 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302306{
2307 struct i915_power_well *power_well;
2308 bool ret;
2309
2310 power_well = lookup_power_well(dev_priv, power_well_id);
Imre Deakf28ec6f2018-08-06 12:58:37 +03002311 ret = power_well->desc->ops->is_enabled(dev_priv, power_well);
Suketu Shah5aefb232015-04-16 14:22:10 +05302312
2313 return ret;
2314}
2315
Imre Deakf28ec6f2018-08-06 12:58:37 +03002316static const struct i915_power_well_desc skl_power_wells[] = {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002317 {
2318 .name = "always-on",
2319 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002320 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002321 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002322 .id = DISP_PW_ID_NONE,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002323 },
2324 {
2325 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002326 /* Handled by the DMC firmware */
2327 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002328 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002329 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002330 {
Imre Deak75e39682018-08-06 12:58:39 +03002331 .hsw.regs = &hsw_power_well_regs,
2332 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002333 .hsw.has_fuses = true,
2334 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002335 },
2336 {
2337 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002338 /* Handled by the DMC firmware */
2339 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002340 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002341 .id = SKL_DISP_PW_MISC_IO,
Imre Deak75e39682018-08-06 12:58:39 +03002342 {
2343 .hsw.regs = &hsw_power_well_regs,
2344 .hsw.idx = SKL_PW_CTL_IDX_MISC_IO,
2345 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002346 },
2347 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002348 .name = "DC off",
2349 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2350 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002351 .id = DISP_PW_ID_NONE,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002352 },
2353 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002354 .name = "power well 2",
2355 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002356 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002357 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002358 {
Imre Deak75e39682018-08-06 12:58:39 +03002359 .hsw.regs = &hsw_power_well_regs,
2360 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002361 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2362 .hsw.has_vga = true,
2363 .hsw.has_fuses = true,
2364 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002365 },
2366 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002367 .name = "DDI A/E IO power well",
2368 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002369 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002370 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002371 {
2372 .hsw.regs = &hsw_power_well_regs,
2373 .hsw.idx = SKL_PW_CTL_IDX_DDI_A_E,
2374 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002375 },
2376 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002377 .name = "DDI B IO power well",
2378 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002379 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002380 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002381 {
2382 .hsw.regs = &hsw_power_well_regs,
2383 .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
2384 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002385 },
2386 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002387 .name = "DDI C IO power well",
2388 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002389 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002390 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002391 {
2392 .hsw.regs = &hsw_power_well_regs,
2393 .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
2394 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002395 },
2396 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002397 .name = "DDI D IO power well",
2398 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002399 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002400 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002401 {
2402 .hsw.regs = &hsw_power_well_regs,
2403 .hsw.idx = SKL_PW_CTL_IDX_DDI_D,
2404 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002405 },
2406};
2407
Imre Deakf28ec6f2018-08-06 12:58:37 +03002408static const struct i915_power_well_desc bxt_power_wells[] = {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302409 {
2410 .name = "always-on",
2411 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002412 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302413 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002414 .id = DISP_PW_ID_NONE,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302415 },
2416 {
2417 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002418 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002419 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002420 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002421 {
Imre Deak75e39682018-08-06 12:58:39 +03002422 .hsw.regs = &hsw_power_well_regs,
2423 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002424 .hsw.has_fuses = true,
2425 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302426 },
2427 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002428 .name = "DC off",
2429 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2430 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002431 .id = DISP_PW_ID_NONE,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002432 },
2433 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302434 .name = "power well 2",
2435 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002436 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002437 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002438 {
Imre Deak75e39682018-08-06 12:58:39 +03002439 .hsw.regs = &hsw_power_well_regs,
2440 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002441 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2442 .hsw.has_vga = true,
2443 .hsw.has_fuses = true,
2444 },
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002445 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002446 {
2447 .name = "dpio-common-a",
2448 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2449 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002450 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002451 {
2452 .bxt.phy = DPIO_PHY1,
2453 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002454 },
2455 {
2456 .name = "dpio-common-bc",
2457 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2458 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002459 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002460 {
2461 .bxt.phy = DPIO_PHY0,
2462 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002463 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302464};
2465
Imre Deakf28ec6f2018-08-06 12:58:37 +03002466static const struct i915_power_well_desc glk_power_wells[] = {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002467 {
2468 .name = "always-on",
2469 .always_on = 1,
2470 .domains = POWER_DOMAIN_MASK,
2471 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002472 .id = DISP_PW_ID_NONE,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002473 },
2474 {
2475 .name = "power well 1",
2476 /* Handled by the DMC firmware */
2477 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002478 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002479 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002480 {
Imre Deak75e39682018-08-06 12:58:39 +03002481 .hsw.regs = &hsw_power_well_regs,
2482 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002483 .hsw.has_fuses = true,
2484 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002485 },
2486 {
2487 .name = "DC off",
2488 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2489 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002490 .id = DISP_PW_ID_NONE,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002491 },
2492 {
2493 .name = "power well 2",
2494 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002495 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002496 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002497 {
Imre Deak75e39682018-08-06 12:58:39 +03002498 .hsw.regs = &hsw_power_well_regs,
2499 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002500 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2501 .hsw.has_vga = true,
2502 .hsw.has_fuses = true,
2503 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002504 },
2505 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002506 .name = "dpio-common-a",
2507 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2508 .ops = &bxt_dpio_cmn_power_well_ops,
2509 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002510 {
2511 .bxt.phy = DPIO_PHY1,
2512 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002513 },
2514 {
2515 .name = "dpio-common-b",
2516 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2517 .ops = &bxt_dpio_cmn_power_well_ops,
2518 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002519 {
2520 .bxt.phy = DPIO_PHY0,
2521 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002522 },
2523 {
2524 .name = "dpio-common-c",
2525 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2526 .ops = &bxt_dpio_cmn_power_well_ops,
2527 .id = GLK_DPIO_CMN_C,
Imre Deak0a445942017-08-14 18:15:29 +03002528 {
2529 .bxt.phy = DPIO_PHY2,
2530 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002531 },
2532 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002533 .name = "AUX A",
2534 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002535 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002536 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002537 {
2538 .hsw.regs = &hsw_power_well_regs,
2539 .hsw.idx = GLK_PW_CTL_IDX_AUX_A,
2540 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002541 },
2542 {
2543 .name = "AUX B",
2544 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002545 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002546 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002547 {
2548 .hsw.regs = &hsw_power_well_regs,
2549 .hsw.idx = GLK_PW_CTL_IDX_AUX_B,
2550 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002551 },
2552 {
2553 .name = "AUX C",
2554 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002555 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002556 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002557 {
2558 .hsw.regs = &hsw_power_well_regs,
2559 .hsw.idx = GLK_PW_CTL_IDX_AUX_C,
2560 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002561 },
2562 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002563 .name = "DDI A IO power well",
2564 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002565 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002566 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002567 {
2568 .hsw.regs = &hsw_power_well_regs,
2569 .hsw.idx = GLK_PW_CTL_IDX_DDI_A,
2570 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002571 },
2572 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002573 .name = "DDI B IO power well",
2574 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002575 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002576 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002577 {
2578 .hsw.regs = &hsw_power_well_regs,
2579 .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
2580 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002581 },
2582 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002583 .name = "DDI C IO power well",
2584 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002585 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002586 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002587 {
2588 .hsw.regs = &hsw_power_well_regs,
2589 .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
2590 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002591 },
2592};
2593
Imre Deakf28ec6f2018-08-06 12:58:37 +03002594static const struct i915_power_well_desc cnl_power_wells[] = {
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002595 {
2596 .name = "always-on",
2597 .always_on = 1,
2598 .domains = POWER_DOMAIN_MASK,
2599 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002600 .id = DISP_PW_ID_NONE,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002601 },
2602 {
2603 .name = "power well 1",
2604 /* Handled by the DMC firmware */
2605 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002606 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002607 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002608 {
Imre Deak75e39682018-08-06 12:58:39 +03002609 .hsw.regs = &hsw_power_well_regs,
2610 .hsw.idx = SKL_PW_CTL_IDX_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002611 .hsw.has_fuses = true,
2612 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002613 },
2614 {
2615 .name = "AUX A",
2616 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002617 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002618 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002619 {
2620 .hsw.regs = &hsw_power_well_regs,
2621 .hsw.idx = GLK_PW_CTL_IDX_AUX_A,
2622 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002623 },
2624 {
2625 .name = "AUX B",
2626 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002627 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002628 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002629 {
2630 .hsw.regs = &hsw_power_well_regs,
2631 .hsw.idx = GLK_PW_CTL_IDX_AUX_B,
2632 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002633 },
2634 {
2635 .name = "AUX C",
2636 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002637 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002638 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002639 {
2640 .hsw.regs = &hsw_power_well_regs,
2641 .hsw.idx = GLK_PW_CTL_IDX_AUX_C,
2642 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002643 },
2644 {
2645 .name = "AUX D",
2646 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002647 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002648 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002649 {
2650 .hsw.regs = &hsw_power_well_regs,
2651 .hsw.idx = CNL_PW_CTL_IDX_AUX_D,
2652 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002653 },
2654 {
2655 .name = "DC off",
2656 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2657 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002658 .id = DISP_PW_ID_NONE,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002659 },
2660 {
2661 .name = "power well 2",
2662 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002663 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002664 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002665 {
Imre Deak75e39682018-08-06 12:58:39 +03002666 .hsw.regs = &hsw_power_well_regs,
2667 .hsw.idx = SKL_PW_CTL_IDX_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002668 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2669 .hsw.has_vga = true,
2670 .hsw.has_fuses = true,
2671 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002672 },
2673 {
2674 .name = "DDI A IO power well",
2675 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002676 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002677 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002678 {
2679 .hsw.regs = &hsw_power_well_regs,
2680 .hsw.idx = GLK_PW_CTL_IDX_DDI_A,
2681 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002682 },
2683 {
2684 .name = "DDI B IO power well",
2685 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002686 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002687 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002688 {
2689 .hsw.regs = &hsw_power_well_regs,
2690 .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
2691 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002692 },
2693 {
2694 .name = "DDI C IO power well",
2695 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002696 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002697 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002698 {
2699 .hsw.regs = &hsw_power_well_regs,
2700 .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
2701 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002702 },
2703 {
2704 .name = "DDI D IO power well",
2705 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002706 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002707 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002708 {
2709 .hsw.regs = &hsw_power_well_regs,
2710 .hsw.idx = SKL_PW_CTL_IDX_DDI_D,
2711 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002712 },
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002713 {
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002714 .name = "DDI F IO power well",
2715 .domains = CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS,
2716 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002717 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002718 {
2719 .hsw.regs = &hsw_power_well_regs,
2720 .hsw.idx = CNL_PW_CTL_IDX_DDI_F,
2721 },
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002722 },
2723 {
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002724 .name = "AUX F",
2725 .domains = CNL_DISPLAY_AUX_F_POWER_DOMAINS,
2726 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002727 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002728 {
2729 .hsw.regs = &hsw_power_well_regs,
2730 .hsw.idx = CNL_PW_CTL_IDX_AUX_F,
2731 },
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002732 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002733};
2734
Imre Deak67ca07e2018-06-26 17:22:32 +03002735static const struct i915_power_well_ops icl_combo_phy_aux_power_well_ops = {
2736 .sync_hw = hsw_power_well_sync_hw,
2737 .enable = icl_combo_phy_aux_power_well_enable,
2738 .disable = icl_combo_phy_aux_power_well_disable,
2739 .is_enabled = hsw_power_well_enabled,
2740};
2741
Imre Deak75e39682018-08-06 12:58:39 +03002742static const struct i915_power_well_regs icl_aux_power_well_regs = {
2743 .bios = ICL_PWR_WELL_CTL_AUX1,
2744 .driver = ICL_PWR_WELL_CTL_AUX2,
2745 .debug = ICL_PWR_WELL_CTL_AUX4,
2746};
2747
2748static const struct i915_power_well_regs icl_ddi_power_well_regs = {
2749 .bios = ICL_PWR_WELL_CTL_DDI1,
2750 .driver = ICL_PWR_WELL_CTL_DDI2,
2751 .debug = ICL_PWR_WELL_CTL_DDI4,
2752};
2753
Imre Deakf28ec6f2018-08-06 12:58:37 +03002754static const struct i915_power_well_desc icl_power_wells[] = {
Imre Deak67ca07e2018-06-26 17:22:32 +03002755 {
2756 .name = "always-on",
2757 .always_on = 1,
2758 .domains = POWER_DOMAIN_MASK,
2759 .ops = &i9xx_always_on_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002760 .id = DISP_PW_ID_NONE,
Imre Deak67ca07e2018-06-26 17:22:32 +03002761 },
2762 {
2763 .name = "power well 1",
2764 /* Handled by the DMC firmware */
2765 .domains = 0,
2766 .ops = &hsw_power_well_ops,
2767 .id = ICL_DISP_PW_1,
Imre Deakae9b06c2018-08-06 12:58:34 +03002768 {
Imre Deak75e39682018-08-06 12:58:39 +03002769 .hsw.regs = &hsw_power_well_regs,
2770 .hsw.idx = ICL_PW_CTL_IDX_PW_1,
Imre Deakae9b06c2018-08-06 12:58:34 +03002771 .hsw.has_fuses = true,
2772 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002773 },
2774 {
2775 .name = "power well 2",
2776 .domains = ICL_PW_2_POWER_DOMAINS,
2777 .ops = &hsw_power_well_ops,
2778 .id = ICL_DISP_PW_2,
Imre Deakae9b06c2018-08-06 12:58:34 +03002779 {
Imre Deak75e39682018-08-06 12:58:39 +03002780 .hsw.regs = &hsw_power_well_regs,
2781 .hsw.idx = ICL_PW_CTL_IDX_PW_2,
Imre Deakae9b06c2018-08-06 12:58:34 +03002782 .hsw.has_fuses = true,
2783 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002784 },
2785 {
2786 .name = "DC off",
2787 .domains = ICL_DISPLAY_DC_OFF_POWER_DOMAINS,
2788 .ops = &gen9_dc_off_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002789 .id = DISP_PW_ID_NONE,
Imre Deak67ca07e2018-06-26 17:22:32 +03002790 },
2791 {
2792 .name = "power well 3",
2793 .domains = ICL_PW_3_POWER_DOMAINS,
2794 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002795 .id = DISP_PW_ID_NONE,
Imre Deakae9b06c2018-08-06 12:58:34 +03002796 {
Imre Deak75e39682018-08-06 12:58:39 +03002797 .hsw.regs = &hsw_power_well_regs,
2798 .hsw.idx = ICL_PW_CTL_IDX_PW_3,
Imre Deakae9b06c2018-08-06 12:58:34 +03002799 .hsw.irq_pipe_mask = BIT(PIPE_B),
2800 .hsw.has_vga = true,
2801 .hsw.has_fuses = true,
2802 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002803 },
2804 {
2805 .name = "DDI A IO",
2806 .domains = ICL_DDI_IO_A_POWER_DOMAINS,
2807 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002808 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002809 {
2810 .hsw.regs = &icl_ddi_power_well_regs,
2811 .hsw.idx = ICL_PW_CTL_IDX_DDI_A,
2812 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002813 },
2814 {
2815 .name = "DDI B IO",
2816 .domains = ICL_DDI_IO_B_POWER_DOMAINS,
2817 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002818 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002819 {
2820 .hsw.regs = &icl_ddi_power_well_regs,
2821 .hsw.idx = ICL_PW_CTL_IDX_DDI_B,
2822 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002823 },
2824 {
2825 .name = "DDI C IO",
2826 .domains = ICL_DDI_IO_C_POWER_DOMAINS,
2827 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002828 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002829 {
2830 .hsw.regs = &icl_ddi_power_well_regs,
2831 .hsw.idx = ICL_PW_CTL_IDX_DDI_C,
2832 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002833 },
2834 {
2835 .name = "DDI D IO",
2836 .domains = ICL_DDI_IO_D_POWER_DOMAINS,
2837 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002838 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002839 {
2840 .hsw.regs = &icl_ddi_power_well_regs,
2841 .hsw.idx = ICL_PW_CTL_IDX_DDI_D,
2842 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002843 },
2844 {
2845 .name = "DDI E IO",
2846 .domains = ICL_DDI_IO_E_POWER_DOMAINS,
2847 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002848 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002849 {
2850 .hsw.regs = &icl_ddi_power_well_regs,
2851 .hsw.idx = ICL_PW_CTL_IDX_DDI_E,
2852 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002853 },
2854 {
2855 .name = "DDI F IO",
2856 .domains = ICL_DDI_IO_F_POWER_DOMAINS,
2857 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002858 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002859 {
2860 .hsw.regs = &icl_ddi_power_well_regs,
2861 .hsw.idx = ICL_PW_CTL_IDX_DDI_F,
2862 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002863 },
2864 {
2865 .name = "AUX A",
2866 .domains = ICL_AUX_A_IO_POWER_DOMAINS,
2867 .ops = &icl_combo_phy_aux_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002868 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002869 {
2870 .hsw.regs = &icl_aux_power_well_regs,
2871 .hsw.idx = ICL_PW_CTL_IDX_AUX_A,
2872 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002873 },
2874 {
2875 .name = "AUX B",
2876 .domains = ICL_AUX_B_IO_POWER_DOMAINS,
2877 .ops = &icl_combo_phy_aux_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002878 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002879 {
2880 .hsw.regs = &icl_aux_power_well_regs,
2881 .hsw.idx = ICL_PW_CTL_IDX_AUX_B,
2882 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002883 },
2884 {
2885 .name = "AUX C",
2886 .domains = ICL_AUX_C_IO_POWER_DOMAINS,
2887 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002888 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002889 {
2890 .hsw.regs = &icl_aux_power_well_regs,
2891 .hsw.idx = ICL_PW_CTL_IDX_AUX_C,
2892 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002893 },
2894 {
2895 .name = "AUX D",
2896 .domains = ICL_AUX_D_IO_POWER_DOMAINS,
2897 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002898 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002899 {
2900 .hsw.regs = &icl_aux_power_well_regs,
2901 .hsw.idx = ICL_PW_CTL_IDX_AUX_D,
2902 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002903 },
2904 {
2905 .name = "AUX E",
2906 .domains = ICL_AUX_E_IO_POWER_DOMAINS,
2907 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002908 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002909 {
2910 .hsw.regs = &icl_aux_power_well_regs,
2911 .hsw.idx = ICL_PW_CTL_IDX_AUX_E,
2912 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002913 },
2914 {
2915 .name = "AUX F",
2916 .domains = ICL_AUX_F_IO_POWER_DOMAINS,
2917 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002918 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002919 {
2920 .hsw.regs = &icl_aux_power_well_regs,
2921 .hsw.idx = ICL_PW_CTL_IDX_AUX_F,
2922 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002923 },
2924 {
2925 .name = "AUX TBT1",
2926 .domains = ICL_AUX_TBT1_IO_POWER_DOMAINS,
2927 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002928 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002929 {
2930 .hsw.regs = &icl_aux_power_well_regs,
2931 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT1,
2932 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002933 },
2934 {
2935 .name = "AUX TBT2",
2936 .domains = ICL_AUX_TBT2_IO_POWER_DOMAINS,
2937 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002938 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002939 {
2940 .hsw.regs = &icl_aux_power_well_regs,
2941 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT2,
2942 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002943 },
2944 {
2945 .name = "AUX TBT3",
2946 .domains = ICL_AUX_TBT3_IO_POWER_DOMAINS,
2947 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002948 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002949 {
2950 .hsw.regs = &icl_aux_power_well_regs,
2951 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT3,
2952 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002953 },
2954 {
2955 .name = "AUX TBT4",
2956 .domains = ICL_AUX_TBT4_IO_POWER_DOMAINS,
2957 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002958 .id = DISP_PW_ID_NONE,
Imre Deak75e39682018-08-06 12:58:39 +03002959 {
2960 .hsw.regs = &icl_aux_power_well_regs,
2961 .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT4,
2962 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002963 },
2964 {
2965 .name = "power well 4",
2966 .domains = ICL_PW_4_POWER_DOMAINS,
2967 .ops = &hsw_power_well_ops,
Imre Deak4739a9d2018-08-06 12:58:40 +03002968 .id = DISP_PW_ID_NONE,
Imre Deakae9b06c2018-08-06 12:58:34 +03002969 {
Imre Deak75e39682018-08-06 12:58:39 +03002970 .hsw.regs = &hsw_power_well_regs,
2971 .hsw.idx = ICL_PW_CTL_IDX_PW_4,
Imre Deakae9b06c2018-08-06 12:58:34 +03002972 .hsw.has_fuses = true,
2973 .hsw.irq_pipe_mask = BIT(PIPE_C),
2974 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002975 },
2976};
2977
Imre Deak1b0e3a02015-11-05 23:04:11 +02002978static int
2979sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2980 int disable_power_well)
2981{
2982 if (disable_power_well >= 0)
2983 return !!disable_power_well;
2984
Imre Deak1b0e3a02015-11-05 23:04:11 +02002985 return 1;
2986}
2987
Imre Deaka37baf32016-02-29 22:49:03 +02002988static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2989 int enable_dc)
2990{
2991 uint32_t mask;
2992 int requested_dc;
2993 int max_dc;
2994
Imre Deak67ca07e2018-06-26 17:22:32 +03002995 if (IS_GEN9_BC(dev_priv) || INTEL_INFO(dev_priv)->gen >= 10) {
Imre Deaka37baf32016-02-29 22:49:03 +02002996 max_dc = 2;
2997 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002998 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002999 max_dc = 1;
3000 /*
3001 * DC9 has a separate HW flow from the rest of the DC states,
3002 * not depending on the DMC firmware. It's needed by system
3003 * suspend/resume, so allow it unconditionally.
3004 */
3005 mask = DC_STATE_EN_DC9;
3006 } else {
3007 max_dc = 0;
3008 mask = 0;
3009 }
3010
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003011 if (!i915_modparams.disable_power_well)
Imre Deak66e2c4c2016-02-29 22:49:04 +02003012 max_dc = 0;
3013
Imre Deaka37baf32016-02-29 22:49:03 +02003014 if (enable_dc >= 0 && enable_dc <= max_dc) {
3015 requested_dc = enable_dc;
3016 } else if (enable_dc == -1) {
3017 requested_dc = max_dc;
3018 } else if (enable_dc > max_dc && enable_dc <= 2) {
3019 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
3020 enable_dc, max_dc);
3021 requested_dc = max_dc;
3022 } else {
3023 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
3024 requested_dc = max_dc;
3025 }
3026
3027 if (requested_dc > 1)
3028 mask |= DC_STATE_EN_UPTO_DC6;
3029 if (requested_dc > 0)
3030 mask |= DC_STATE_EN_UPTO_DC5;
3031
3032 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
3033
3034 return mask;
3035}
3036
Imre Deakf28ec6f2018-08-06 12:58:37 +03003037static int
3038__set_power_wells(struct i915_power_domains *power_domains,
3039 const struct i915_power_well_desc *power_well_descs,
3040 int power_well_count)
Imre Deak21792c62017-07-11 23:42:33 +03003041{
Imre Deakf28ec6f2018-08-06 12:58:37 +03003042 u64 power_well_ids = 0;
Imre Deak21792c62017-07-11 23:42:33 +03003043 int i;
3044
Imre Deakf28ec6f2018-08-06 12:58:37 +03003045 power_domains->power_well_count = power_well_count;
3046 power_domains->power_wells =
3047 kcalloc(power_well_count,
3048 sizeof(*power_domains->power_wells),
3049 GFP_KERNEL);
3050 if (!power_domains->power_wells)
3051 return -ENOMEM;
3052
3053 for (i = 0; i < power_well_count; i++) {
3054 enum i915_power_well_id id = power_well_descs[i].id;
3055
3056 power_domains->power_wells[i].desc = &power_well_descs[i];
Imre Deak21792c62017-07-11 23:42:33 +03003057
Imre Deak4739a9d2018-08-06 12:58:40 +03003058 if (id == DISP_PW_ID_NONE)
3059 continue;
3060
Imre Deak21792c62017-07-11 23:42:33 +03003061 WARN_ON(id >= sizeof(power_well_ids) * 8);
3062 WARN_ON(power_well_ids & BIT_ULL(id));
3063 power_well_ids |= BIT_ULL(id);
3064 }
Imre Deakf28ec6f2018-08-06 12:58:37 +03003065
3066 return 0;
Imre Deak21792c62017-07-11 23:42:33 +03003067}
3068
Imre Deakf28ec6f2018-08-06 12:58:37 +03003069#define set_power_wells(power_domains, __power_well_descs) \
3070 __set_power_wells(power_domains, __power_well_descs, \
3071 ARRAY_SIZE(__power_well_descs))
Daniel Vetter9c065a72014-09-30 10:56:38 +02003072
Daniel Vettere4e76842014-09-30 10:56:42 +02003073/**
3074 * intel_power_domains_init - initializes the power domain structures
3075 * @dev_priv: i915 device instance
3076 *
3077 * Initializes the power domain structures for @dev_priv depending upon the
3078 * supported platform.
3079 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003080int intel_power_domains_init(struct drm_i915_private *dev_priv)
3081{
3082 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deakf28ec6f2018-08-06 12:58:37 +03003083 int err;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003084
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003085 i915_modparams.disable_power_well =
3086 sanitize_disable_power_well_option(dev_priv,
3087 i915_modparams.disable_power_well);
3088 dev_priv->csr.allowed_dc_mask =
3089 get_allowed_dc_mask(dev_priv, i915_modparams.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02003090
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02003091 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01003092
Daniel Vetter9c065a72014-09-30 10:56:38 +02003093 mutex_init(&power_domains->lock);
3094
3095 /*
3096 * The enabling order will be from lower to higher indexed wells,
3097 * the disabling order is reversed.
3098 */
Imre Deak67ca07e2018-06-26 17:22:32 +03003099 if (IS_ICELAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003100 err = set_power_wells(power_domains, icl_power_wells);
Imre Deak67ca07e2018-06-26 17:22:32 +03003101 } else if (IS_HASWELL(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003102 err = set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003103 } else if (IS_BROADWELL(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003104 err = set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08003105 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003106 err = set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07003107 } else if (IS_CANNONLAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003108 err = set_power_wells(power_domains, cnl_power_wells);
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003109
3110 /*
Rodrigo Vivi9787e832018-01-29 15:22:22 -08003111 * DDI and Aux IO are getting enabled for all ports
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003112 * regardless the presence or use. So, in order to avoid
Rodrigo Vivi9787e832018-01-29 15:22:22 -08003113 * timeouts, lets remove them from the list
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003114 * for the SKUs without port F.
3115 */
3116 if (!IS_CNL_WITH_PORT_F(dev_priv))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08003117 power_domains->power_well_count -= 2;
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003118
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003119 } else if (IS_BROXTON(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003120 err = set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02003121 } else if (IS_GEMINILAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003122 err = set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003123 } else if (IS_CHERRYVIEW(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003124 err = set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03003125 } else if (IS_VALLEYVIEW(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003126 err = set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03003127 } else if (IS_I830(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003128 err = set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003129 } else {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003130 err = set_power_wells(power_domains, i9xx_always_on_power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003131 }
3132
Imre Deakf28ec6f2018-08-06 12:58:37 +03003133 return err;
3134}
Imre Deak21792c62017-07-11 23:42:33 +03003135
Imre Deakf28ec6f2018-08-06 12:58:37 +03003136/**
3137 * intel_power_domains_cleanup - clean up power domains resources
3138 * @dev_priv: i915 device instance
3139 *
3140 * Release any resources acquired by intel_power_domains_init()
3141 */
3142void intel_power_domains_cleanup(struct drm_i915_private *dev_priv)
3143{
3144 kfree(dev_priv->power_domains.power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003145}
3146
Imre Deak30eade12015-11-04 19:24:13 +02003147static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003148{
3149 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3150 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003151
3152 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02003153 for_each_power_well(dev_priv, power_well) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03003154 power_well->desc->ops->sync_hw(dev_priv, power_well);
3155 power_well->hw_enabled =
3156 power_well->desc->ops->is_enabled(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003157 }
3158 mutex_unlock(&power_domains->lock);
3159}
3160
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303161static inline
3162bool intel_dbuf_slice_set(struct drm_i915_private *dev_priv,
3163 i915_reg_t reg, bool enable)
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003164{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303165 u32 val, status;
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003166
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303167 val = I915_READ(reg);
3168 val = enable ? (val | DBUF_POWER_REQUEST) : (val & ~DBUF_POWER_REQUEST);
3169 I915_WRITE(reg, val);
3170 POSTING_READ(reg);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003171 udelay(10);
3172
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303173 status = I915_READ(reg) & DBUF_POWER_STATE;
3174 if ((enable && !status) || (!enable && status)) {
3175 DRM_ERROR("DBus power %s timeout!\n",
3176 enable ? "enable" : "disable");
3177 return false;
3178 }
3179 return true;
3180}
3181
3182static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
3183{
3184 intel_dbuf_slice_set(dev_priv, DBUF_CTL, true);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003185}
3186
3187static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
3188{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303189 intel_dbuf_slice_set(dev_priv, DBUF_CTL, false);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003190}
3191
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303192static u8 intel_dbuf_max_slices(struct drm_i915_private *dev_priv)
3193{
3194 if (INTEL_GEN(dev_priv) < 11)
3195 return 1;
3196 return 2;
3197}
3198
3199void icl_dbuf_slices_update(struct drm_i915_private *dev_priv,
3200 u8 req_slices)
3201{
3202 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
3203 u32 val;
3204 bool ret;
3205
3206 if (req_slices > intel_dbuf_max_slices(dev_priv)) {
3207 DRM_ERROR("Invalid number of dbuf slices requested\n");
3208 return;
3209 }
3210
3211 if (req_slices == hw_enabled_slices || req_slices == 0)
3212 return;
3213
3214 val = I915_READ(DBUF_CTL_S2);
3215 if (req_slices > hw_enabled_slices)
3216 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, true);
3217 else
3218 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, false);
3219
3220 if (ret)
3221 dev_priv->wm.skl_hw.ddb.enabled_slices = req_slices;
3222}
3223
Mahesh Kumar746edf82018-02-05 13:40:44 -02003224static void icl_dbuf_enable(struct drm_i915_private *dev_priv)
3225{
3226 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) | DBUF_POWER_REQUEST);
3227 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) | DBUF_POWER_REQUEST);
3228 POSTING_READ(DBUF_CTL_S2);
3229
3230 udelay(10);
3231
3232 if (!(I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
3233 !(I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
3234 DRM_ERROR("DBuf power enable timeout\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303235 else
3236 dev_priv->wm.skl_hw.ddb.enabled_slices = 2;
Mahesh Kumar746edf82018-02-05 13:40:44 -02003237}
3238
3239static void icl_dbuf_disable(struct drm_i915_private *dev_priv)
3240{
3241 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) & ~DBUF_POWER_REQUEST);
3242 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) & ~DBUF_POWER_REQUEST);
3243 POSTING_READ(DBUF_CTL_S2);
3244
3245 udelay(10);
3246
3247 if ((I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
3248 (I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
3249 DRM_ERROR("DBuf power disable timeout!\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303250 else
3251 dev_priv->wm.skl_hw.ddb.enabled_slices = 0;
Mahesh Kumar746edf82018-02-05 13:40:44 -02003252}
3253
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003254static void icl_mbus_init(struct drm_i915_private *dev_priv)
3255{
3256 uint32_t val;
3257
3258 val = MBUS_ABOX_BT_CREDIT_POOL1(16) |
3259 MBUS_ABOX_BT_CREDIT_POOL2(16) |
3260 MBUS_ABOX_B_CREDIT(1) |
3261 MBUS_ABOX_BW_CREDIT(1);
3262
3263 I915_WRITE(MBUS_ABOX_CTL, val);
3264}
3265
Imre Deak73dfc222015-11-17 17:33:53 +02003266static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03003267 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02003268{
3269 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003270 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003271 uint32_t val;
3272
Imre Deakd26fa1d2015-11-04 19:24:17 +02003273 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3274
Imre Deak73dfc222015-11-17 17:33:53 +02003275 /* enable PCH reset handshake */
3276 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3277 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
3278
3279 /* enable PG1 and Misc I/O */
3280 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003281
3282 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3283 intel_power_well_enable(dev_priv, well);
3284
3285 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
3286 intel_power_well_enable(dev_priv, well);
3287
Imre Deak73dfc222015-11-17 17:33:53 +02003288 mutex_unlock(&power_domains->lock);
3289
Imre Deak73dfc222015-11-17 17:33:53 +02003290 skl_init_cdclk(dev_priv);
3291
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003292 gen9_dbuf_enable(dev_priv);
3293
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03003294 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02003295 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003296}
3297
3298static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
3299{
3300 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003301 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003302
Imre Deakd26fa1d2015-11-04 19:24:17 +02003303 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3304
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003305 gen9_dbuf_disable(dev_priv);
3306
Imre Deak73dfc222015-11-17 17:33:53 +02003307 skl_uninit_cdclk(dev_priv);
3308
3309 /* The spec doesn't call for removing the reset handshake flag */
3310 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03003311
Imre Deak73dfc222015-11-17 17:33:53 +02003312 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003313
Imre Deakedfda8e2017-06-29 18:36:59 +03003314 /*
3315 * BSpec says to keep the MISC IO power well enabled here, only
3316 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03003317 * Note that even though the driver's request is removed power well 1
3318 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03003319 */
Imre Deak443a93a2016-04-04 15:42:57 +03003320 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3321 intel_power_well_disable(dev_priv, well);
3322
Imre Deak73dfc222015-11-17 17:33:53 +02003323 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003324
3325 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02003326}
3327
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003328void bxt_display_core_init(struct drm_i915_private *dev_priv,
3329 bool resume)
3330{
3331 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3332 struct i915_power_well *well;
3333 uint32_t val;
3334
3335 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3336
3337 /*
3338 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
3339 * or else the reset will hang because there is no PCH to respond.
3340 * Move the handshake programming to initialization sequence.
3341 * Previously was left up to BIOS.
3342 */
3343 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3344 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
3345 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3346
3347 /* Enable PG1 */
3348 mutex_lock(&power_domains->lock);
3349
3350 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3351 intel_power_well_enable(dev_priv, well);
3352
3353 mutex_unlock(&power_domains->lock);
3354
Imre Deak324513c2016-06-13 16:44:36 +03003355 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003356
3357 gen9_dbuf_enable(dev_priv);
3358
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003359 if (resume && dev_priv->csr.dmc_payload)
3360 intel_csr_load_program(dev_priv);
3361}
3362
3363void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
3364{
3365 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3366 struct i915_power_well *well;
3367
3368 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3369
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003370 gen9_dbuf_disable(dev_priv);
3371
Imre Deak324513c2016-06-13 16:44:36 +03003372 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003373
3374 /* The spec doesn't call for removing the reset handshake flag */
3375
Imre Deak42d93662017-06-29 18:37:01 +03003376 /*
3377 * Disable PW1 (PG1).
3378 * Note that even though the driver's request is removed power well 1
3379 * may stay enabled after this due to DMC's own request on it.
3380 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003381 mutex_lock(&power_domains->lock);
3382
3383 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3384 intel_power_well_disable(dev_priv, well);
3385
3386 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003387
3388 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003389}
3390
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003391enum {
3392 PROCMON_0_85V_DOT_0,
3393 PROCMON_0_95V_DOT_0,
3394 PROCMON_0_95V_DOT_1,
3395 PROCMON_1_05V_DOT_0,
3396 PROCMON_1_05V_DOT_1,
3397};
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003398
3399static const struct cnl_procmon {
3400 u32 dw1, dw9, dw10;
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003401} cnl_procmon_values[] = {
3402 [PROCMON_0_85V_DOT_0] =
3403 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
3404 [PROCMON_0_95V_DOT_0] =
3405 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
3406 [PROCMON_0_95V_DOT_1] =
3407 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
3408 [PROCMON_1_05V_DOT_0] =
3409 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
3410 [PROCMON_1_05V_DOT_1] =
3411 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003412};
3413
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003414/*
3415 * CNL has just one set of registers, while ICL has two sets: one for port A and
3416 * the other for port B. The CNL registers are equivalent to the ICL port A
3417 * registers, that's why we call the ICL macros even though the function has CNL
3418 * on its name.
3419 */
3420static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
3421 enum port port)
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003422{
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003423 const struct cnl_procmon *procmon;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003424 u32 val;
3425
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003426 val = I915_READ(ICL_PORT_COMP_DW3(port));
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003427 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
3428 default:
3429 MISSING_CASE(val);
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05003430 /* fall through */
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003431 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
3432 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
3433 break;
3434 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
3435 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
3436 break;
3437 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
3438 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
3439 break;
3440 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
3441 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
3442 break;
3443 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
3444 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
3445 break;
3446 }
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003447
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003448 val = I915_READ(ICL_PORT_COMP_DW1(port));
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003449 val &= ~((0xff << 16) | 0xff);
3450 val |= procmon->dw1;
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003451 I915_WRITE(ICL_PORT_COMP_DW1(port), val);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003452
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003453 I915_WRITE(ICL_PORT_COMP_DW9(port), procmon->dw9);
3454 I915_WRITE(ICL_PORT_COMP_DW10(port), procmon->dw10);
Paulo Zanoniade5ee72017-08-21 17:03:56 -07003455}
3456
3457static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
3458{
3459 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3460 struct i915_power_well *well;
3461 u32 val;
3462
3463 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3464
3465 /* 1. Enable PCH Reset Handshake */
3466 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3467 val |= RESET_PCH_HANDSHAKE_ENABLE;
3468 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3469
3470 /* 2. Enable Comp */
3471 val = I915_READ(CHICKEN_MISC_2);
3472 val &= ~CNL_COMP_PWR_DOWN;
3473 I915_WRITE(CHICKEN_MISC_2, val);
3474
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003475 /* Dummy PORT_A to get the correct CNL register from the ICL macro */
3476 cnl_set_procmon_ref_values(dev_priv, PORT_A);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003477
3478 val = I915_READ(CNL_PORT_COMP_DW0);
3479 val |= COMP_INIT;
3480 I915_WRITE(CNL_PORT_COMP_DW0, val);
3481
3482 /* 3. */
3483 val = I915_READ(CNL_PORT_CL1CM_DW5);
3484 val |= CL_POWER_DOWN_ENABLE;
3485 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
3486
Imre Deakb38131f2017-06-29 18:37:02 +03003487 /*
3488 * 4. Enable Power Well 1 (PG1).
3489 * The AUX IO power wells will be enabled on demand.
3490 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003491 mutex_lock(&power_domains->lock);
3492 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3493 intel_power_well_enable(dev_priv, well);
3494 mutex_unlock(&power_domains->lock);
3495
3496 /* 5. Enable CD clock */
3497 cnl_init_cdclk(dev_priv);
3498
3499 /* 6. Enable DBUF */
3500 gen9_dbuf_enable(dev_priv);
Imre Deak57522c42017-10-03 12:51:58 +03003501
3502 if (resume && dev_priv->csr.dmc_payload)
3503 intel_csr_load_program(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003504}
3505
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003506static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
3507{
3508 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3509 struct i915_power_well *well;
3510 u32 val;
3511
3512 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3513
3514 /* 1. Disable all display engine functions -> aready done */
3515
3516 /* 2. Disable DBUF */
3517 gen9_dbuf_disable(dev_priv);
3518
3519 /* 3. Disable CD clock */
3520 cnl_uninit_cdclk(dev_priv);
3521
Imre Deakb38131f2017-06-29 18:37:02 +03003522 /*
3523 * 4. Disable Power Well 1 (PG1).
3524 * The AUX IO power wells are toggled on demand, so they are already
3525 * disabled at this point.
3526 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003527 mutex_lock(&power_domains->lock);
3528 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3529 intel_power_well_disable(dev_priv, well);
3530 mutex_unlock(&power_domains->lock);
3531
Imre Deak846c6b22017-06-29 18:36:58 +03003532 usleep_range(10, 30); /* 10 us delay per Bspec */
3533
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003534 /* 5. Disable Comp */
3535 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03003536 val |= CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003537 I915_WRITE(CHICKEN_MISC_2, val);
3538}
3539
Paulo Zanoniad186f32018-02-05 13:40:43 -02003540static void icl_display_core_init(struct drm_i915_private *dev_priv,
3541 bool resume)
3542{
Imre Deak67ca07e2018-06-26 17:22:32 +03003543 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3544 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003545 enum port port;
3546 u32 val;
3547
3548 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3549
3550 /* 1. Enable PCH reset handshake. */
3551 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3552 val |= RESET_PCH_HANDSHAKE_ENABLE;
3553 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3554
3555 for (port = PORT_A; port <= PORT_B; port++) {
3556 /* 2. Enable DDI combo PHY comp. */
3557 val = I915_READ(ICL_PHY_MISC(port));
3558 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3559 I915_WRITE(ICL_PHY_MISC(port), val);
3560
3561 cnl_set_procmon_ref_values(dev_priv, port);
3562
3563 val = I915_READ(ICL_PORT_COMP_DW0(port));
3564 val |= COMP_INIT;
3565 I915_WRITE(ICL_PORT_COMP_DW0(port), val);
3566
3567 /* 3. Set power down enable. */
3568 val = I915_READ(ICL_PORT_CL_DW5(port));
3569 val |= CL_POWER_DOWN_ENABLE;
3570 I915_WRITE(ICL_PORT_CL_DW5(port), val);
3571 }
3572
Imre Deak67ca07e2018-06-26 17:22:32 +03003573 /*
3574 * 4. Enable Power Well 1 (PG1).
3575 * The AUX IO power wells will be enabled on demand.
3576 */
3577 mutex_lock(&power_domains->lock);
3578 well = lookup_power_well(dev_priv, ICL_DISP_PW_1);
3579 intel_power_well_enable(dev_priv, well);
3580 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003581
3582 /* 5. Enable CDCLK. */
3583 icl_init_cdclk(dev_priv);
3584
3585 /* 6. Enable DBUF. */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003586 icl_dbuf_enable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003587
3588 /* 7. Setup MBUS. */
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003589 icl_mbus_init(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003590}
3591
3592static void icl_display_core_uninit(struct drm_i915_private *dev_priv)
3593{
Imre Deak67ca07e2018-06-26 17:22:32 +03003594 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3595 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003596 enum port port;
3597 u32 val;
3598
3599 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3600
3601 /* 1. Disable all display engine functions -> aready done */
3602
3603 /* 2. Disable DBUF */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003604 icl_dbuf_disable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003605
3606 /* 3. Disable CD clock */
3607 icl_uninit_cdclk(dev_priv);
3608
Imre Deak67ca07e2018-06-26 17:22:32 +03003609 /*
3610 * 4. Disable Power Well 1 (PG1).
3611 * The AUX IO power wells are toggled on demand, so they are already
3612 * disabled at this point.
3613 */
3614 mutex_lock(&power_domains->lock);
3615 well = lookup_power_well(dev_priv, ICL_DISP_PW_1);
3616 intel_power_well_disable(dev_priv, well);
3617 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003618
3619 /* 5. Disable Comp */
3620 for (port = PORT_A; port <= PORT_B; port++) {
3621 val = I915_READ(ICL_PHY_MISC(port));
3622 val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3623 I915_WRITE(ICL_PHY_MISC(port), val);
3624 }
3625}
3626
Ville Syrjälä70722462015-04-10 18:21:28 +03003627static void chv_phy_control_init(struct drm_i915_private *dev_priv)
3628{
3629 struct i915_power_well *cmn_bc =
3630 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3631 struct i915_power_well *cmn_d =
3632 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
3633
3634 /*
3635 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
3636 * workaround never ever read DISPLAY_PHY_CONTROL, and
3637 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003638 * power well state and lane status to reconstruct the
3639 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03003640 */
3641 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03003642 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
3643 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003644 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
3645 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
3646 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
3647
3648 /*
3649 * If all lanes are disabled we leave the override disabled
3650 * with all power down bits cleared to match the state we
3651 * would use after disabling the port. Otherwise enable the
3652 * override and set the lane powerdown bits accding to the
3653 * current lane status.
3654 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003655 if (cmn_bc->desc->ops->is_enabled(dev_priv, cmn_bc)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003656 uint32_t status = I915_READ(DPLL(PIPE_A));
3657 unsigned int mask;
3658
3659 mask = status & DPLL_PORTB_READY_MASK;
3660 if (mask == 0xf)
3661 mask = 0x0;
3662 else
3663 dev_priv->chv_phy_control |=
3664 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
3665
3666 dev_priv->chv_phy_control |=
3667 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
3668
3669 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
3670 if (mask == 0xf)
3671 mask = 0x0;
3672 else
3673 dev_priv->chv_phy_control |=
3674 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
3675
3676 dev_priv->chv_phy_control |=
3677 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
3678
Ville Syrjälä70722462015-04-10 18:21:28 +03003679 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003680
3681 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
3682 } else {
3683 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003684 }
3685
Imre Deakf28ec6f2018-08-06 12:58:37 +03003686 if (cmn_d->desc->ops->is_enabled(dev_priv, cmn_d)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003687 uint32_t status = I915_READ(DPIO_PHY_STATUS);
3688 unsigned int mask;
3689
3690 mask = status & DPLL_PORTD_READY_MASK;
3691
3692 if (mask == 0xf)
3693 mask = 0x0;
3694 else
3695 dev_priv->chv_phy_control |=
3696 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
3697
3698 dev_priv->chv_phy_control |=
3699 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
3700
Ville Syrjälä70722462015-04-10 18:21:28 +03003701 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003702
3703 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
3704 } else {
3705 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003706 }
3707
3708 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
3709
3710 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
3711 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03003712}
3713
Daniel Vetter9c065a72014-09-30 10:56:38 +02003714static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
3715{
3716 struct i915_power_well *cmn =
3717 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3718 struct i915_power_well *disp2d =
3719 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
3720
Daniel Vetter9c065a72014-09-30 10:56:38 +02003721 /* If the display might be already active skip this */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003722 if (cmn->desc->ops->is_enabled(dev_priv, cmn) &&
3723 disp2d->desc->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003724 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3725 return;
3726
3727 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3728
3729 /* cmnlane needs DPLL registers */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003730 disp2d->desc->ops->enable(dev_priv, disp2d);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003731
3732 /*
3733 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3734 * Need to assert and de-assert PHY SB reset by gating the
3735 * common lane power, then un-gating it.
3736 * Simply ungating isn't enough to reset the PHY enough to get
3737 * ports and lanes running.
3738 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003739 cmn->desc->ops->disable(dev_priv, cmn);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003740}
3741
Daniel Vettere4e76842014-09-30 10:56:42 +02003742/**
3743 * intel_power_domains_init_hw - initialize hardware power domain state
3744 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003745 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003746 *
3747 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003748 * power wells belonging to the INIT power domain. Power wells in other
3749 * domains (and not in the INIT domain) are referenced or disabled during the
3750 * modeset state HW readout. After that the reference count of each power well
3751 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003752 */
Imre Deak73dfc222015-11-17 17:33:53 +02003753void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003754{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003755 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3756
3757 power_domains->initializing = true;
3758
Paulo Zanoniad186f32018-02-05 13:40:43 -02003759 if (IS_ICELAKE(dev_priv)) {
3760 icl_display_core_init(dev_priv, resume);
3761 } else if (IS_CANNONLAKE(dev_priv)) {
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003762 cnl_display_core_init(dev_priv, resume);
3763 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003764 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003765 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003766 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003767 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003768 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003769 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003770 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003771 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003772 mutex_lock(&power_domains->lock);
3773 vlv_cmnlane_wa(dev_priv);
3774 mutex_unlock(&power_domains->lock);
3775 }
3776
3777 /* For now, we need the power well to be always enabled. */
3778 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003779 /* Disable power support if the user asked so. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003780 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003781 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003782 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003783 power_domains->initializing = false;
3784}
3785
Daniel Vettere4e76842014-09-30 10:56:42 +02003786/**
Imre Deak48a287e2018-08-06 12:58:35 +03003787 * intel_power_domains_fini_hw - deinitialize hw power domain state
3788 * @dev_priv: i915 device instance
3789 *
3790 * De-initializes the display power domain HW state. It also ensures that the
3791 * device stays powered up so that the driver can be reloaded.
3792 */
3793void intel_power_domains_fini_hw(struct drm_i915_private *dev_priv)
3794{
3795 struct device *kdev = &dev_priv->drm.pdev->dev;
3796
3797 /*
3798 * The i915.ko module is still not prepared to be loaded when
3799 * the power well is not enabled, so just enable it in case
3800 * we're going to unload/reload.
3801 * The following also reacquires the RPM reference the core passed
3802 * to the driver during loading, which is dropped in
3803 * intel_runtime_pm_enable(). We have to hand back the control of the
3804 * device to the core with this reference held.
3805 */
3806 intel_display_set_init_power(dev_priv, true);
3807
3808 /* Remove the refcount we took to keep power well support disabled. */
3809 if (!i915_modparams.disable_power_well)
3810 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
3811
3812 /*
3813 * Remove the refcount we took in intel_runtime_pm_enable() in case
3814 * the platform doesn't support runtime PM.
3815 */
3816 if (!HAS_RUNTIME_PM(dev_priv))
3817 pm_runtime_put(kdev);
3818}
3819
3820/**
Imre Deak73dfc222015-11-17 17:33:53 +02003821 * intel_power_domains_suspend - suspend power domain state
3822 * @dev_priv: i915 device instance
3823 *
3824 * This function prepares the hardware power domain state before entering
3825 * system suspend. It must be paired with intel_power_domains_init_hw().
3826 */
3827void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3828{
Imre Deakd314cd42015-11-17 17:44:23 +02003829 /*
3830 * Even if power well support was disabled we still want to disable
3831 * power wells while we are system suspended.
3832 */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003833 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003834 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003835
Paulo Zanoniad186f32018-02-05 13:40:43 -02003836 if (IS_ICELAKE(dev_priv))
3837 icl_display_core_uninit(dev_priv);
3838 else if (IS_CANNONLAKE(dev_priv))
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003839 cnl_display_core_uninit(dev_priv);
3840 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003841 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003842 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003843 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003844}
3845
Imre Deak8d8c3862017-02-17 17:39:46 +02003846static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3847{
3848 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3849 struct i915_power_well *power_well;
3850
3851 for_each_power_well(dev_priv, power_well) {
3852 enum intel_display_power_domain domain;
3853
3854 DRM_DEBUG_DRIVER("%-25s %d\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003855 power_well->desc->name, power_well->count);
Imre Deak8d8c3862017-02-17 17:39:46 +02003856
Imre Deakf28ec6f2018-08-06 12:58:37 +03003857 for_each_power_domain(domain, power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003858 DRM_DEBUG_DRIVER(" %-23s %d\n",
3859 intel_display_power_domain_str(domain),
3860 power_domains->domain_use_count[domain]);
3861 }
3862}
3863
3864/**
3865 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3866 * @dev_priv: i915 device instance
3867 *
3868 * Verify if the reference count of each power well matches its HW enabled
3869 * state and the total refcount of the domains it belongs to. This must be
3870 * called after modeset HW state sanitization, which is responsible for
3871 * acquiring reference counts for any power wells in use and disabling the
3872 * ones left on by BIOS but not required by any active output.
3873 */
3874void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3875{
3876 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3877 struct i915_power_well *power_well;
3878 bool dump_domain_info;
3879
3880 mutex_lock(&power_domains->lock);
3881
3882 dump_domain_info = false;
3883 for_each_power_well(dev_priv, power_well) {
3884 enum intel_display_power_domain domain;
3885 int domains_count;
3886 bool enabled;
3887
3888 /*
3889 * Power wells not belonging to any domain (like the MISC_IO
3890 * and PW1 power wells) are under FW control, so ignore them,
3891 * since their state can change asynchronously.
3892 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003893 if (!power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003894 continue;
3895
Imre Deakf28ec6f2018-08-06 12:58:37 +03003896 enabled = power_well->desc->ops->is_enabled(dev_priv,
3897 power_well);
3898 if ((power_well->count || power_well->desc->always_on) !=
3899 enabled)
Imre Deak8d8c3862017-02-17 17:39:46 +02003900 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003901 power_well->desc->name,
3902 power_well->count, enabled);
Imre Deak8d8c3862017-02-17 17:39:46 +02003903
3904 domains_count = 0;
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 domains_count += power_domains->domain_use_count[domain];
3907
3908 if (power_well->count != domains_count) {
3909 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3910 "(refcount %d/domains refcount %d)\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003911 power_well->desc->name, power_well->count,
Imre Deak8d8c3862017-02-17 17:39:46 +02003912 domains_count);
3913 dump_domain_info = true;
3914 }
3915 }
3916
3917 if (dump_domain_info) {
3918 static bool dumped;
3919
3920 if (!dumped) {
3921 intel_power_domains_dump_info(dev_priv);
3922 dumped = true;
3923 }
3924 }
3925
3926 mutex_unlock(&power_domains->lock);
3927}
3928
Imre Deak73dfc222015-11-17 17:33:53 +02003929/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003930 * intel_runtime_pm_get - grab a runtime pm reference
3931 * @dev_priv: i915 device instance
3932 *
3933 * This function grabs a device-level runtime pm reference (mostly used for GEM
3934 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3935 *
3936 * Any runtime pm reference obtained by this function must have a symmetric
3937 * call to intel_runtime_pm_put() to release the reference again.
3938 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003939void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3940{
David Weinehall52a05c32016-08-22 13:32:44 +03003941 struct pci_dev *pdev = dev_priv->drm.pdev;
3942 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003943 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003944
Imre Deakf5073822017-03-28 12:38:55 +03003945 ret = pm_runtime_get_sync(kdev);
3946 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003947
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003948 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003949 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003950}
3951
Daniel Vettere4e76842014-09-30 10:56:42 +02003952/**
Imre Deak09731282016-02-17 14:17:42 +02003953 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3954 * @dev_priv: i915 device instance
3955 *
3956 * This function grabs a device-level runtime pm reference if the device is
Chris Wilsonacb79142018-02-19 12:50:46 +00003957 * already in use and ensures that it is powered up. It is illegal to try
3958 * and access the HW should intel_runtime_pm_get_if_in_use() report failure.
Imre Deak09731282016-02-17 14:17:42 +02003959 *
3960 * Any runtime pm reference obtained by this function must have a symmetric
3961 * call to intel_runtime_pm_put() to release the reference again.
Chris Wilsonacb79142018-02-19 12:50:46 +00003962 *
3963 * Returns: True if the wakeref was acquired, or False otherwise.
Imre Deak09731282016-02-17 14:17:42 +02003964 */
3965bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3966{
Chris Wilson135dc792016-02-25 21:10:28 +00003967 if (IS_ENABLED(CONFIG_PM)) {
Chris Wilsonacb79142018-02-19 12:50:46 +00003968 struct pci_dev *pdev = dev_priv->drm.pdev;
3969 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003970
Chris Wilson135dc792016-02-25 21:10:28 +00003971 /*
3972 * In cases runtime PM is disabled by the RPM core and we get
3973 * an -EINVAL return value we are not supposed to call this
3974 * function, since the power state is undefined. This applies
3975 * atm to the late/early system suspend/resume handlers.
3976 */
Chris Wilsonacb79142018-02-19 12:50:46 +00003977 if (pm_runtime_get_if_in_use(kdev) <= 0)
Chris Wilson135dc792016-02-25 21:10:28 +00003978 return false;
3979 }
Imre Deak09731282016-02-17 14:17:42 +02003980
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003981 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deak09731282016-02-17 14:17:42 +02003982 assert_rpm_wakelock_held(dev_priv);
3983
3984 return true;
3985}
3986
3987/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003988 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3989 * @dev_priv: i915 device instance
3990 *
3991 * This function grabs a device-level runtime pm reference (mostly used for GEM
3992 * code to ensure the GTT or GT is on).
3993 *
3994 * It will _not_ power up the device but instead only check that it's powered
3995 * on. Therefore it is only valid to call this functions from contexts where
3996 * the device is known to be powered up and where trying to power it up would
3997 * result in hilarity and deadlocks. That pretty much means only the system
3998 * suspend/resume code where this is used to grab runtime pm references for
3999 * delayed setup down in work items.
4000 *
4001 * Any runtime pm reference obtained by this function must have a symmetric
4002 * call to intel_runtime_pm_put() to release the reference again.
4003 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02004004void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
4005{
David Weinehall52a05c32016-08-22 13:32:44 +03004006 struct pci_dev *pdev = dev_priv->drm.pdev;
4007 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02004008
Imre Deakc9b88462015-12-15 20:10:34 +02004009 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03004010 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02004011
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004012 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02004013}
4014
Daniel Vettere4e76842014-09-30 10:56:42 +02004015/**
4016 * intel_runtime_pm_put - release a runtime pm reference
4017 * @dev_priv: i915 device instance
4018 *
4019 * This function drops the device-level runtime pm reference obtained by
4020 * intel_runtime_pm_get() and might power down the corresponding
4021 * hardware block right away if this is the last reference.
4022 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02004023void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
4024{
David Weinehall52a05c32016-08-22 13:32:44 +03004025 struct pci_dev *pdev = dev_priv->drm.pdev;
4026 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02004027
Imre Deak542db3c2015-12-15 20:10:36 +02004028 assert_rpm_wakelock_held(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004029 atomic_dec(&dev_priv->runtime_pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02004030
David Weinehallc49d13e2016-08-22 13:32:42 +03004031 pm_runtime_mark_last_busy(kdev);
4032 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02004033}
4034
Daniel Vettere4e76842014-09-30 10:56:42 +02004035/**
4036 * intel_runtime_pm_enable - enable runtime pm
4037 * @dev_priv: i915 device instance
4038 *
4039 * This function enables runtime pm at the end of the driver load sequence.
4040 *
4041 * Note that this function does currently not enable runtime pm for the
4042 * subordinate display power domains. That is only done on the first modeset
4043 * using intel_display_set_init_power().
4044 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02004045void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02004046{
David Weinehall52a05c32016-08-22 13:32:44 +03004047 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03004048 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02004049
David Weinehallc49d13e2016-08-22 13:32:42 +03004050 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
4051 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02004052
Imre Deak25b181b2015-12-17 13:44:56 +02004053 /*
4054 * Take a permanent reference to disable the RPM functionality and drop
4055 * it only when unloading the driver. Use the low level get/put helpers,
4056 * so the driver's own RPM reference tracking asserts also work on
4057 * platforms without RPM support.
4058 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01004059 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03004060 int ret;
4061
David Weinehallc49d13e2016-08-22 13:32:42 +03004062 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03004063 ret = pm_runtime_get_sync(kdev);
4064 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02004065 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03004066 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02004067 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02004068
Imre Deakaabee1b2015-12-15 20:10:29 +02004069 /*
4070 * The core calls the driver load handler with an RPM reference held.
4071 * We drop that here and will reacquire it during unloading in
4072 * intel_power_domains_fini().
4073 */
David Weinehallc49d13e2016-08-22 13:32:42 +03004074 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02004075}