blob: 9f44a2b0113aeae3cbc0eedf060196d1b6d185b1 [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 Deakf28ec6f2018-08-06 12:58:37 +0300326 enum i915_power_well_id id = power_well->desc->id;
Imre Deak42d93662017-06-29 18:37:01 +0300327
328 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
329 WARN_ON(intel_wait_for_register(dev_priv,
Imre Deak9c3a16c2017-08-14 18:15:30 +0300330 HSW_PWR_WELL_CTL_DRIVER(id),
Imre Deak1af474f2017-07-06 17:40:34 +0300331 HSW_PWR_WELL_CTL_STATE(id),
332 HSW_PWR_WELL_CTL_STATE(id),
Imre Deak42d93662017-06-29 18:37:01 +0300333 1));
334}
335
Imre Deak76347c02017-07-06 17:40:36 +0300336static u32 hsw_power_well_requesters(struct drm_i915_private *dev_priv,
337 enum i915_power_well_id id)
Imre Deak42d93662017-06-29 18:37:01 +0300338{
Imre Deak1af474f2017-07-06 17:40:34 +0300339 u32 req_mask = HSW_PWR_WELL_CTL_REQ(id);
Imre Deak42d93662017-06-29 18:37:01 +0300340 u32 ret;
341
Imre Deak9c3a16c2017-08-14 18:15:30 +0300342 ret = I915_READ(HSW_PWR_WELL_CTL_BIOS(id)) & req_mask ? 1 : 0;
343 ret |= I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & req_mask ? 2 : 0;
344 ret |= I915_READ(HSW_PWR_WELL_CTL_KVMR) & req_mask ? 4 : 0;
345 ret |= I915_READ(HSW_PWR_WELL_CTL_DEBUG(id)) & req_mask ? 8 : 0;
Imre Deak42d93662017-06-29 18:37:01 +0300346
347 return ret;
348}
349
Imre Deak76347c02017-07-06 17:40:36 +0300350static void hsw_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
351 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300352{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300353 enum i915_power_well_id id = power_well->desc->id;
Imre Deak42d93662017-06-29 18:37:01 +0300354 bool disabled;
355 u32 reqs;
356
357 /*
358 * Bspec doesn't require waiting for PWs to get disabled, but still do
359 * this for paranoia. The known cases where a PW will be forced on:
360 * - a KVMR request on any power well via the KVMR request register
361 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
362 * DEBUG request registers
363 * Skip the wait in case any of the request bits are set and print a
364 * diagnostic message.
365 */
Imre Deak9c3a16c2017-08-14 18:15:30 +0300366 wait_for((disabled = !(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
Imre Deak1af474f2017-07-06 17:40:34 +0300367 HSW_PWR_WELL_CTL_STATE(id))) ||
Imre Deak76347c02017-07-06 17:40:36 +0300368 (reqs = hsw_power_well_requesters(dev_priv, id)), 1);
Imre Deak42d93662017-06-29 18:37:01 +0300369 if (disabled)
370 return;
371
372 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +0300373 power_well->desc->name,
Imre Deak42d93662017-06-29 18:37:01 +0300374 !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
375}
376
Imre Deakb2891eb2017-07-11 23:42:35 +0300377static void gen9_wait_for_power_well_fuses(struct drm_i915_private *dev_priv,
378 enum skl_power_gate pg)
379{
380 /* Timeout 5us for PG#0, for other PGs 1us */
381 WARN_ON(intel_wait_for_register(dev_priv, SKL_FUSE_STATUS,
382 SKL_FUSE_PG_DIST_STATUS(pg),
383 SKL_FUSE_PG_DIST_STATUS(pg), 1));
384}
385
Imre Deakec46d482017-07-06 17:40:33 +0300386static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
387 struct i915_power_well *power_well)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200388{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300389 enum i915_power_well_id id = power_well->desc->id;
390 bool wait_fuses = power_well->desc->hsw.has_fuses;
Chris Wilson320671f2017-10-02 11:04:16 +0100391 enum skl_power_gate uninitialized_var(pg);
Imre Deak1af474f2017-07-06 17:40:34 +0300392 u32 val;
393
Imre Deakb2891eb2017-07-11 23:42:35 +0300394 if (wait_fuses) {
Imre Deak67ca07e2018-06-26 17:22:32 +0300395 pg = INTEL_GEN(dev_priv) >= 11 ? ICL_PW_TO_PG(id) :
396 SKL_PW_TO_PG(id);
Imre Deakb2891eb2017-07-11 23:42:35 +0300397 /*
398 * For PW1 we have to wait both for the PW0/PG0 fuse state
399 * before enabling the power well and PW1/PG1's own fuse
400 * state after the enabling. For all other power wells with
401 * fuses we only have to wait for that PW/PG's fuse state
402 * after the enabling.
403 */
404 if (pg == SKL_PG1)
405 gen9_wait_for_power_well_fuses(dev_priv, SKL_PG0);
406 }
407
Imre Deak9c3a16c2017-08-14 18:15:30 +0300408 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
409 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), val | HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300410 hsw_wait_for_power_well_enable(dev_priv, power_well);
Imre Deak001bd2c2017-07-12 18:54:13 +0300411
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800412 /* Display WA #1178: cnl */
413 if (IS_CANNONLAKE(dev_priv) &&
414 (id == CNL_DISP_PW_AUX_B || id == CNL_DISP_PW_AUX_C ||
Rodrigo Vivib1ae6a82018-01-29 15:22:16 -0800415 id == CNL_DISP_PW_AUX_D || id == CNL_DISP_PW_AUX_F)) {
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800416 val = I915_READ(CNL_AUX_ANAOVRD1(id));
417 val |= CNL_AUX_ANAOVRD1_ENABLE | CNL_AUX_ANAOVRD1_LDO_BYPASS;
418 I915_WRITE(CNL_AUX_ANAOVRD1(id), val);
419 }
420
Imre Deakb2891eb2017-07-11 23:42:35 +0300421 if (wait_fuses)
422 gen9_wait_for_power_well_fuses(dev_priv, pg);
423
Imre Deakf28ec6f2018-08-06 12:58:37 +0300424 hsw_power_well_post_enable(dev_priv,
425 power_well->desc->hsw.irq_pipe_mask,
426 power_well->desc->hsw.has_vga);
Imre Deakec46d482017-07-06 17:40:33 +0300427}
Daniel Vetter9c065a72014-09-30 10:56:38 +0200428
Imre Deakec46d482017-07-06 17:40:33 +0300429static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
430 struct i915_power_well *power_well)
431{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300432 enum i915_power_well_id id = power_well->desc->id;
Imre Deak1af474f2017-07-06 17:40:34 +0300433 u32 val;
434
Imre Deakf28ec6f2018-08-06 12:58:37 +0300435 hsw_power_well_pre_disable(dev_priv,
436 power_well->desc->hsw.irq_pipe_mask);
Imre Deak001bd2c2017-07-12 18:54:13 +0300437
Imre Deak9c3a16c2017-08-14 18:15:30 +0300438 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
439 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id),
440 val & ~HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300441 hsw_wait_for_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200442}
443
Imre Deak67ca07e2018-06-26 17:22:32 +0300444#define ICL_AUX_PW_TO_PORT(pw) ((pw) - ICL_DISP_PW_AUX_A)
445
446static void
447icl_combo_phy_aux_power_well_enable(struct drm_i915_private *dev_priv,
448 struct i915_power_well *power_well)
449{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300450 enum i915_power_well_id id = power_well->desc->id;
Imre Deak67ca07e2018-06-26 17:22:32 +0300451 enum port port = ICL_AUX_PW_TO_PORT(id);
452 u32 val;
453
454 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
455 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), val | HSW_PWR_WELL_CTL_REQ(id));
456
457 val = I915_READ(ICL_PORT_CL_DW12(port));
458 I915_WRITE(ICL_PORT_CL_DW12(port), val | ICL_LANE_ENABLE_AUX);
459
460 hsw_wait_for_power_well_enable(dev_priv, power_well);
461}
462
463static void
464icl_combo_phy_aux_power_well_disable(struct drm_i915_private *dev_priv,
465 struct i915_power_well *power_well)
466{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300467 enum i915_power_well_id id = power_well->desc->id;
Imre Deak67ca07e2018-06-26 17:22:32 +0300468 enum port port = ICL_AUX_PW_TO_PORT(id);
469 u32 val;
470
471 val = I915_READ(ICL_PORT_CL_DW12(port));
472 I915_WRITE(ICL_PORT_CL_DW12(port), val & ~ICL_LANE_ENABLE_AUX);
473
474 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
475 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id),
476 val & ~HSW_PWR_WELL_CTL_REQ(id));
477
478 hsw_wait_for_power_well_disable(dev_priv, power_well);
479}
480
Imre Deakd42539b2017-07-06 17:40:39 +0300481/*
482 * We should only use the power well if we explicitly asked the hardware to
483 * enable it, so check if it's enabled and also check if we've requested it to
484 * be enabled.
485 */
486static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
487 struct i915_power_well *power_well)
488{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300489 enum i915_power_well_id id = power_well->desc->id;
Imre Deakd42539b2017-07-06 17:40:39 +0300490 u32 mask = HSW_PWR_WELL_CTL_REQ(id) | HSW_PWR_WELL_CTL_STATE(id);
491
Imre Deak9c3a16c2017-08-14 18:15:30 +0300492 return (I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & mask) == mask;
Imre Deakd42539b2017-07-06 17:40:39 +0300493}
494
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530495static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
496{
Imre Deak9c3a16c2017-08-14 18:15:30 +0300497 enum i915_power_well_id id = SKL_DISP_PW_2;
498
Imre Deakbfcdabe2016-04-01 16:02:37 +0300499 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
500 "DC9 already programmed to be enabled.\n");
501 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
502 "DC5 still not disabled to enable DC9.\n");
Imre Deak9c3a16c2017-08-14 18:15:30 +0300503 WARN_ONCE(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
504 HSW_PWR_WELL_CTL_REQ(id),
Imre Deake8a3a2a2017-06-29 18:37:00 +0300505 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300506 WARN_ONCE(intel_irqs_enabled(dev_priv),
507 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530508
509 /*
510 * TODO: check for the following to verify the conditions to enter DC9
511 * state are satisfied:
512 * 1] Check relevant display engine registers to verify if mode set
513 * disable sequence was followed.
514 * 2] Check if display uninitialize sequence is initialized.
515 */
516}
517
518static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
519{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300520 WARN_ONCE(intel_irqs_enabled(dev_priv),
521 "Interrupts not disabled yet.\n");
522 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
523 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530524
525 /*
526 * TODO: check for the following to verify DC9 state was indeed
527 * entered before programming to disable it:
528 * 1] Check relevant display engine registers to verify if mode
529 * set disable sequence was followed.
530 * 2] Check if display uninitialize sequence is initialized.
531 */
532}
533
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200534static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
535 u32 state)
536{
537 int rewrites = 0;
538 int rereads = 0;
539 u32 v;
540
541 I915_WRITE(DC_STATE_EN, state);
542
543 /* It has been observed that disabling the dc6 state sometimes
544 * doesn't stick and dmc keeps returning old value. Make sure
545 * the write really sticks enough times and also force rewrite until
546 * we are confident that state is exactly what we want.
547 */
548 do {
549 v = I915_READ(DC_STATE_EN);
550
551 if (v != state) {
552 I915_WRITE(DC_STATE_EN, state);
553 rewrites++;
554 rereads = 0;
555 } else if (rereads++ > 5) {
556 break;
557 }
558
559 } while (rewrites < 100);
560
561 if (v != state)
562 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
563 state, v);
564
565 /* Most of the times we need one retry, avoid spam */
566 if (rewrites > 1)
567 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
568 state, rewrites);
569}
570
Imre Deakda2f41d2016-04-20 20:27:56 +0300571static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530572{
Imre Deakda2f41d2016-04-20 20:27:56 +0300573 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530574
Imre Deak13ae3a02015-11-04 19:24:16 +0200575 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200576 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200577 mask |= DC_STATE_EN_DC9;
578 else
579 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530580
Imre Deakda2f41d2016-04-20 20:27:56 +0300581 return mask;
582}
583
584void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
585{
586 u32 val;
587
588 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
589
590 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
591 dev_priv->csr.dc_state, val);
592 dev_priv->csr.dc_state = val;
593}
594
Imre Deak13e15922018-04-17 14:31:47 +0300595/**
596 * gen9_set_dc_state - set target display C power state
597 * @dev_priv: i915 device instance
598 * @state: target DC power state
599 * - DC_STATE_DISABLE
600 * - DC_STATE_EN_UPTO_DC5
601 * - DC_STATE_EN_UPTO_DC6
602 * - DC_STATE_EN_DC9
603 *
604 * Signal to DMC firmware/HW the target DC power state passed in @state.
605 * DMC/HW can turn off individual display clocks and power rails when entering
606 * a deeper DC power state (higher in number) and turns these back when exiting
607 * that state to a shallower power state (lower in number). The HW will decide
608 * when to actually enter a given state on an on-demand basis, for instance
609 * depending on the active state of display pipes. The state of display
610 * registers backed by affected power rails are saved/restored as needed.
611 *
612 * Based on the above enabling a deeper DC power state is asynchronous wrt.
613 * enabling it. Disabling a deeper power state is synchronous: for instance
614 * setting %DC_STATE_DISABLE won't complete until all HW resources are turned
615 * back on and register state is restored. This is guaranteed by the MMIO write
616 * to DC_STATE_EN blocking until the state is restored.
617 */
Imre Deakda2f41d2016-04-20 20:27:56 +0300618static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
619{
620 uint32_t val;
621 uint32_t mask;
622
Imre Deaka37baf32016-02-29 22:49:03 +0200623 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
624 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100625
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530626 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300627 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200628 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
629 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200630
631 /* Check if DMC is ignoring our DC state requests */
632 if ((val & mask) != dev_priv->csr.dc_state)
633 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
634 dev_priv->csr.dc_state, val & mask);
635
Imre Deak13ae3a02015-11-04 19:24:16 +0200636 val &= ~mask;
637 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200638
639 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200640
641 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530642}
643
Imre Deak13ae3a02015-11-04 19:24:16 +0200644void bxt_enable_dc9(struct drm_i915_private *dev_priv)
645{
646 assert_can_enable_dc9(dev_priv);
647
648 DRM_DEBUG_KMS("Enabling DC9\n");
649
Imre Deak78597992016-06-16 16:37:20 +0300650 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200651 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
652}
653
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530654void bxt_disable_dc9(struct drm_i915_private *dev_priv)
655{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530656 assert_can_disable_dc9(dev_priv);
657
658 DRM_DEBUG_KMS("Disabling DC9\n");
659
Imre Deak13ae3a02015-11-04 19:24:16 +0200660 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300661
662 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530663}
664
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200665static void assert_csr_loaded(struct drm_i915_private *dev_priv)
666{
667 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
668 "CSR program storage start is NULL\n");
669 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
670 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
671}
672
Suketu Shah5aefb232015-04-16 14:22:10 +0530673static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530674{
Suketu Shah5aefb232015-04-16 14:22:10 +0530675 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
676 SKL_DISP_PW_2);
677
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700678 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530679
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700680 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
681 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200682 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530683
684 assert_csr_loaded(dev_priv);
685}
686
Imre Deakf62c79b2016-04-20 20:27:57 +0300687void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530688{
Suketu Shah5aefb232015-04-16 14:22:10 +0530689 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530690
691 DRM_DEBUG_KMS("Enabling DC5\n");
692
Lucas De Marchi53421c22017-12-04 15:22:10 -0800693 /* Wa Display #1183: skl,kbl,cfl */
694 if (IS_GEN9_BC(dev_priv))
695 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
696 SKL_SELECT_ALTERNATE_DC_EXIT);
697
Imre Deak13ae3a02015-11-04 19:24:16 +0200698 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530699}
700
Suketu Shah93c7cb62015-04-16 14:22:13 +0530701static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530702{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700703 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
704 "Backlight is not disabled.\n");
705 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
706 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530707
708 assert_csr_loaded(dev_priv);
709}
710
Daniel Vetterc4c25252018-04-17 12:02:25 +0200711static void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530712{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530713 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530714
715 DRM_DEBUG_KMS("Enabling DC6\n");
716
Imre Deakb49be662018-04-19 18:51:09 +0300717 /* Wa Display #1183: skl,kbl,cfl */
718 if (IS_GEN9_BC(dev_priv))
719 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
720 SKL_SELECT_ALTERNATE_DC_EXIT);
Imre Deak13ae3a02015-11-04 19:24:16 +0200721
Imre Deakb49be662018-04-19 18:51:09 +0300722 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
Suketu Shahf75a1982015-04-16 14:22:11 +0530723}
724
Daniel Vetter9c065a72014-09-30 10:56:38 +0200725static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
726 struct i915_power_well *power_well)
727{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300728 enum i915_power_well_id id = power_well->desc->id;
Imre Deak1af474f2017-07-06 17:40:34 +0300729 u32 mask = HSW_PWR_WELL_CTL_REQ(id);
Imre Deak9c3a16c2017-08-14 18:15:30 +0300730 u32 bios_req = I915_READ(HSW_PWR_WELL_CTL_BIOS(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300731
Imre Deak16e84912017-02-17 17:39:45 +0200732 /* Take over the request bit if set by BIOS. */
Imre Deak1af474f2017-07-06 17:40:34 +0300733 if (bios_req & mask) {
Imre Deak9c3a16c2017-08-14 18:15:30 +0300734 u32 drv_req = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300735
736 if (!(drv_req & mask))
Imre Deak9c3a16c2017-08-14 18:15:30 +0300737 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), drv_req | mask);
738 I915_WRITE(HSW_PWR_WELL_CTL_BIOS(id), bios_req & ~mask);
Imre Deak16e84912017-02-17 17:39:45 +0200739 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200740}
741
Imre Deak9c8d0b82016-06-13 16:44:34 +0300742static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
743 struct i915_power_well *power_well)
744{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300745 bxt_ddi_phy_init(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300746}
747
748static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
749 struct i915_power_well *power_well)
750{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300751 bxt_ddi_phy_uninit(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300752}
753
754static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
755 struct i915_power_well *power_well)
756{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300757 return bxt_ddi_phy_is_enabled(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300758}
759
Imre Deak9c8d0b82016-06-13 16:44:34 +0300760static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
761{
762 struct i915_power_well *power_well;
763
764 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
765 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300766 bxt_ddi_phy_verify_state(dev_priv, power_well->desc->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300767
768 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
769 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300770 bxt_ddi_phy_verify_state(dev_priv, power_well->desc->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200771
772 if (IS_GEMINILAKE(dev_priv)) {
773 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
774 if (power_well->count > 0)
Imre Deakf28ec6f2018-08-06 12:58:37 +0300775 bxt_ddi_phy_verify_state(dev_priv,
776 power_well->desc->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200777 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300778}
779
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100780static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
781 struct i915_power_well *power_well)
782{
783 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
784}
785
Ville Syrjälä18a80672016-05-16 16:59:40 +0300786static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
787{
788 u32 tmp = I915_READ(DBUF_CTL);
789
790 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
791 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
792 "Unexpected DBuf power power state (0x%08x)\n", tmp);
793}
794
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100795static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
796 struct i915_power_well *power_well)
797{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200798 struct intel_cdclk_state cdclk_state = {};
799
Imre Deak5b773eb2016-02-29 22:49:05 +0200800 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300801
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200802 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
Ville Syrjälä64600bd2017-10-24 12:52:08 +0300803 /* Can't read out voltage_level so can't use intel_cdclk_changed() */
804 WARN_ON(intel_cdclk_needs_modeset(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300805
Ville Syrjälä18a80672016-05-16 16:59:40 +0300806 gen9_assert_dbuf_enabled(dev_priv);
807
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200808 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300809 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100810}
811
812static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
813 struct i915_power_well *power_well)
814{
Imre Deakf74ed082016-04-18 14:48:21 +0300815 if (!dev_priv->csr.dmc_payload)
816 return;
817
Imre Deaka37baf32016-02-29 22:49:03 +0200818 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100819 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200820 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100821 gen9_enable_dc5(dev_priv);
822}
823
Imre Deak3c1b38e2017-02-17 17:39:42 +0200824static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
825 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100826{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100827}
828
Daniel Vetter9c065a72014-09-30 10:56:38 +0200829static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
830 struct i915_power_well *power_well)
831{
832}
833
834static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
835 struct i915_power_well *power_well)
836{
837 return true;
838}
839
Ville Syrjälä2ee0da12017-06-01 17:36:16 +0300840static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
841 struct i915_power_well *power_well)
842{
843 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
844 i830_enable_pipe(dev_priv, PIPE_A);
845 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
846 i830_enable_pipe(dev_priv, PIPE_B);
847}
848
849static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
850 struct i915_power_well *power_well)
851{
852 i830_disable_pipe(dev_priv, PIPE_B);
853 i830_disable_pipe(dev_priv, PIPE_A);
854}
855
856static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
857 struct i915_power_well *power_well)
858{
859 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
860 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
861}
862
863static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
864 struct i915_power_well *power_well)
865{
866 if (power_well->count > 0)
867 i830_pipes_power_well_enable(dev_priv, power_well);
868 else
869 i830_pipes_power_well_disable(dev_priv, power_well);
870}
871
Daniel Vetter9c065a72014-09-30 10:56:38 +0200872static void vlv_set_power_well(struct drm_i915_private *dev_priv,
873 struct i915_power_well *power_well, bool enable)
874{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300875 enum i915_power_well_id power_well_id = power_well->desc->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200876 u32 mask;
877 u32 state;
878 u32 ctrl;
879
880 mask = PUNIT_PWRGT_MASK(power_well_id);
881 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
882 PUNIT_PWRGT_PWR_GATE(power_well_id);
883
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100884 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200885
886#define COND \
887 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
888
889 if (COND)
890 goto out;
891
892 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
893 ctrl &= ~mask;
894 ctrl |= state;
895 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
896
897 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900898 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200899 state,
900 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
901
902#undef COND
903
904out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100905 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200906}
907
Daniel Vetter9c065a72014-09-30 10:56:38 +0200908static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
909 struct i915_power_well *power_well)
910{
911 vlv_set_power_well(dev_priv, power_well, true);
912}
913
914static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
915 struct i915_power_well *power_well)
916{
917 vlv_set_power_well(dev_priv, power_well, false);
918}
919
920static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
921 struct i915_power_well *power_well)
922{
Imre Deakf28ec6f2018-08-06 12:58:37 +0300923 enum i915_power_well_id power_well_id = power_well->desc->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200924 bool enabled = false;
925 u32 mask;
926 u32 state;
927 u32 ctrl;
928
929 mask = PUNIT_PWRGT_MASK(power_well_id);
930 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
931
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100932 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200933
934 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
935 /*
936 * We only ever set the power-on and power-gate states, anything
937 * else is unexpected.
938 */
939 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
940 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
941 if (state == ctrl)
942 enabled = true;
943
944 /*
945 * A transient state at this point would mean some unexpected party
946 * is poking at the power controls too.
947 */
948 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
949 WARN_ON(ctrl != state);
950
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100951 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200952
953 return enabled;
954}
955
Ville Syrjälä766078d2016-04-11 16:56:30 +0300956static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
957{
Hans de Goede721d4842016-12-02 15:29:04 +0100958 u32 val;
959
960 /*
961 * On driver load, a pipe may be active and driving a DSI display.
962 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
963 * (and never recovering) in this case. intel_dsi_post_disable() will
964 * clear it when we turn off the display.
965 */
966 val = I915_READ(DSPCLK_GATE_D);
967 val &= DPOUNIT_CLOCK_GATE_DISABLE;
968 val |= VRHUNIT_CLOCK_GATE_DISABLE;
969 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +0300970
971 /*
972 * Disable trickle feed and enable pnd deadline calculation
973 */
974 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
975 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +0300976
977 WARN_ON(dev_priv->rawclk_freq == 0);
978
979 I915_WRITE(RAWCLK_FREQ_VLV,
980 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +0300981}
982
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300983static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200984{
Lyude9504a892016-06-21 17:03:42 -0400985 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300986 enum pipe pipe;
987
988 /*
989 * Enable the CRI clock source so we can get at the
990 * display and the reference clock for VGA
991 * hotplug / manual detection. Supposedly DSI also
992 * needs the ref clock up and running.
993 *
994 * CHV DPLL B/C have some issues if VGA mode is enabled.
995 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +0000996 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300997 u32 val = I915_READ(DPLL(pipe));
998
999 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1000 if (pipe != PIPE_A)
1001 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1002
1003 I915_WRITE(DPLL(pipe), val);
1004 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001005
Ville Syrjälä766078d2016-04-11 16:56:30 +03001006 vlv_init_display_clock_gating(dev_priv);
1007
Daniel Vetter9c065a72014-09-30 10:56:38 +02001008 spin_lock_irq(&dev_priv->irq_lock);
1009 valleyview_enable_display_irqs(dev_priv);
1010 spin_unlock_irq(&dev_priv->irq_lock);
1011
1012 /*
1013 * During driver initialization/resume we can avoid restoring the
1014 * part of the HW/SW state that will be inited anyway explicitly.
1015 */
1016 if (dev_priv->power_domains.initializing)
1017 return;
1018
Daniel Vetterb9632912014-09-30 10:56:44 +02001019 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001020
Lyude9504a892016-06-21 17:03:42 -04001021 /* Re-enable the ADPA, if we have one */
1022 for_each_intel_encoder(&dev_priv->drm, encoder) {
1023 if (encoder->type == INTEL_OUTPUT_ANALOG)
1024 intel_crt_reset(&encoder->base);
1025 }
1026
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001027 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001028
1029 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001030}
1031
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001032static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1033{
1034 spin_lock_irq(&dev_priv->irq_lock);
1035 valleyview_disable_display_irqs(dev_priv);
1036 spin_unlock_irq(&dev_priv->irq_lock);
1037
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001038 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001039 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001040
Imre Deak78597992016-06-16 16:37:20 +03001041 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001042
Lyudeb64b5402016-10-26 12:36:09 -04001043 /* Prevent us from re-enabling polling on accident in late suspend */
1044 if (!dev_priv->drm.dev->power.is_suspended)
1045 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001046}
1047
1048static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1049 struct i915_power_well *power_well)
1050{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001051 vlv_set_power_well(dev_priv, power_well, true);
1052
1053 vlv_display_power_well_init(dev_priv);
1054}
1055
Daniel Vetter9c065a72014-09-30 10:56:38 +02001056static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1057 struct i915_power_well *power_well)
1058{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001059 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001060
1061 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001062}
1063
1064static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1065 struct i915_power_well *power_well)
1066{
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001067 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001068 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1069
1070 vlv_set_power_well(dev_priv, power_well, true);
1071
1072 /*
1073 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1074 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1075 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1076 * b. The other bits such as sfr settings / modesel may all
1077 * be set to 0.
1078 *
1079 * This should only be done on init and resume from S3 with
1080 * both PLLs disabled, or we risk losing DPIO and PLL
1081 * synchronization.
1082 */
1083 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1084}
1085
1086static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1087 struct i915_power_well *power_well)
1088{
1089 enum pipe pipe;
1090
Daniel Vetter9c065a72014-09-30 10:56:38 +02001091 for_each_pipe(dev_priv, pipe)
1092 assert_pll_disabled(dev_priv, pipe);
1093
1094 /* Assert common reset */
1095 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1096
1097 vlv_set_power_well(dev_priv, power_well, false);
1098}
1099
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001100#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001101
Imre Deak438b8dc2017-07-11 23:42:30 +03001102static struct i915_power_well *
1103lookup_power_well(struct drm_i915_private *dev_priv,
1104 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001105{
1106 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001107 int i;
1108
Imre Deakfc17f222015-11-04 19:24:11 +02001109 for (i = 0; i < power_domains->power_well_count; i++) {
1110 struct i915_power_well *power_well;
1111
1112 power_well = &power_domains->power_wells[i];
Imre Deakf28ec6f2018-08-06 12:58:37 +03001113 if (power_well->desc->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001114 return power_well;
1115 }
1116
1117 return NULL;
1118}
1119
1120#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1121
1122static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1123{
1124 struct i915_power_well *cmn_bc =
1125 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1126 struct i915_power_well *cmn_d =
1127 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1128 u32 phy_control = dev_priv->chv_phy_control;
1129 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001130 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001131
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001132 /*
1133 * The BIOS can leave the PHY is some weird state
1134 * where it doesn't fully power down some parts.
1135 * Disable the asserts until the PHY has been fully
1136 * reset (ie. the power well has been disabled at
1137 * least once).
1138 */
1139 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1140 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1141 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1142 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1143 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1144 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1145 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1146
1147 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1148 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1149 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1150 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1151
Imre Deakf28ec6f2018-08-06 12:58:37 +03001152 if (cmn_bc->desc->ops->is_enabled(dev_priv, cmn_bc)) {
Ville Syrjälä30142272015-07-08 23:46:01 +03001153 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1154
1155 /* this assumes override is only used to enable lanes */
1156 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1157 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1158
1159 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1160 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1161
1162 /* CL1 is on whenever anything is on in either channel */
1163 if (BITS_SET(phy_control,
1164 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1165 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1166 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1167
1168 /*
1169 * The DPLLB check accounts for the pipe B + port A usage
1170 * with CL2 powered up but all the lanes in the second channel
1171 * powered down.
1172 */
1173 if (BITS_SET(phy_control,
1174 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1175 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1176 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1177
1178 if (BITS_SET(phy_control,
1179 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1180 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1181 if (BITS_SET(phy_control,
1182 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1183 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1184
1185 if (BITS_SET(phy_control,
1186 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1187 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1188 if (BITS_SET(phy_control,
1189 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1190 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1191 }
1192
Imre Deakf28ec6f2018-08-06 12:58:37 +03001193 if (cmn_d->desc->ops->is_enabled(dev_priv, cmn_d)) {
Ville Syrjälä30142272015-07-08 23:46:01 +03001194 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1195
1196 /* this assumes override is only used to enable lanes */
1197 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1198 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1199
1200 if (BITS_SET(phy_control,
1201 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1202 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1203
1204 if (BITS_SET(phy_control,
1205 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1206 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1207 if (BITS_SET(phy_control,
1208 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1209 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1210 }
1211
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001212 phy_status &= phy_status_mask;
1213
Ville Syrjälä30142272015-07-08 23:46:01 +03001214 /*
1215 * The PHY may be busy with some initial calibration and whatnot,
1216 * so the power state can take a while to actually change.
1217 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001218 if (intel_wait_for_register(dev_priv,
1219 DISPLAY_PHY_STATUS,
1220 phy_status_mask,
1221 phy_status,
1222 10))
1223 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1224 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1225 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001226}
1227
1228#undef BITS_SET
1229
Daniel Vetter9c065a72014-09-30 10:56:38 +02001230static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1231 struct i915_power_well *power_well)
1232{
1233 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001234 enum pipe pipe;
1235 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001236
Imre Deakf28ec6f2018-08-06 12:58:37 +03001237 WARN_ON_ONCE(power_well->desc->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1238 power_well->desc->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001239
Imre Deakf28ec6f2018-08-06 12:58:37 +03001240 if (power_well->desc->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001241 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001242 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001243 } else {
1244 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001245 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001246 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001247
1248 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001249 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1250 vlv_set_power_well(dev_priv, power_well, true);
1251
1252 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001253 if (intel_wait_for_register(dev_priv,
1254 DISPLAY_PHY_STATUS,
1255 PHY_POWERGOOD(phy),
1256 PHY_POWERGOOD(phy),
1257 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001258 DRM_ERROR("Display PHY %d is not power up\n", phy);
1259
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001260 mutex_lock(&dev_priv->sb_lock);
1261
1262 /* Enable dynamic power down */
1263 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001264 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1265 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001266 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1267
Imre Deakf28ec6f2018-08-06 12:58:37 +03001268 if (power_well->desc->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001269 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1270 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1271 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001272 } else {
1273 /*
1274 * Force the non-existing CL2 off. BXT does this
1275 * too, so maybe it saves some power even though
1276 * CL2 doesn't exist?
1277 */
1278 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1279 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1280 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001281 }
1282
1283 mutex_unlock(&dev_priv->sb_lock);
1284
Ville Syrjälä70722462015-04-10 18:21:28 +03001285 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1286 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001287
1288 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1289 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001290
1291 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001292}
1293
1294static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1295 struct i915_power_well *power_well)
1296{
1297 enum dpio_phy phy;
1298
Imre Deakf28ec6f2018-08-06 12:58:37 +03001299 WARN_ON_ONCE(power_well->desc->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1300 power_well->desc->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001301
Imre Deakf28ec6f2018-08-06 12:58:37 +03001302 if (power_well->desc->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001303 phy = DPIO_PHY0;
1304 assert_pll_disabled(dev_priv, PIPE_A);
1305 assert_pll_disabled(dev_priv, PIPE_B);
1306 } else {
1307 phy = DPIO_PHY1;
1308 assert_pll_disabled(dev_priv, PIPE_C);
1309 }
1310
Ville Syrjälä70722462015-04-10 18:21:28 +03001311 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1312 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001313
1314 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001315
1316 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1317 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001318
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001319 /* PHY is fully reset now, so we can enable the PHY state asserts */
1320 dev_priv->chv_phy_assert[phy] = true;
1321
Ville Syrjälä30142272015-07-08 23:46:01 +03001322 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001323}
1324
Ville Syrjälä6669e392015-07-08 23:46:00 +03001325static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1326 enum dpio_channel ch, bool override, unsigned int mask)
1327{
1328 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1329 u32 reg, val, expected, actual;
1330
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001331 /*
1332 * The BIOS can leave the PHY is some weird state
1333 * where it doesn't fully power down some parts.
1334 * Disable the asserts until the PHY has been fully
1335 * reset (ie. the power well has been disabled at
1336 * least once).
1337 */
1338 if (!dev_priv->chv_phy_assert[phy])
1339 return;
1340
Ville Syrjälä6669e392015-07-08 23:46:00 +03001341 if (ch == DPIO_CH0)
1342 reg = _CHV_CMN_DW0_CH0;
1343 else
1344 reg = _CHV_CMN_DW6_CH1;
1345
1346 mutex_lock(&dev_priv->sb_lock);
1347 val = vlv_dpio_read(dev_priv, pipe, reg);
1348 mutex_unlock(&dev_priv->sb_lock);
1349
1350 /*
1351 * This assumes !override is only used when the port is disabled.
1352 * All lanes should power down even without the override when
1353 * the port is disabled.
1354 */
1355 if (!override || mask == 0xf) {
1356 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1357 /*
1358 * If CH1 common lane is not active anymore
1359 * (eg. for pipe B DPLL) the entire channel will
1360 * shut down, which causes the common lane registers
1361 * to read as 0. That means we can't actually check
1362 * the lane power down status bits, but as the entire
1363 * register reads as 0 it's a good indication that the
1364 * channel is indeed entirely powered down.
1365 */
1366 if (ch == DPIO_CH1 && val == 0)
1367 expected = 0;
1368 } else if (mask != 0x0) {
1369 expected = DPIO_ANYDL_POWERDOWN;
1370 } else {
1371 expected = 0;
1372 }
1373
1374 if (ch == DPIO_CH0)
1375 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1376 else
1377 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1378 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1379
1380 WARN(actual != expected,
1381 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1382 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1383 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1384 reg, val);
1385}
1386
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001387bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1388 enum dpio_channel ch, bool override)
1389{
1390 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1391 bool was_override;
1392
1393 mutex_lock(&power_domains->lock);
1394
1395 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1396
1397 if (override == was_override)
1398 goto out;
1399
1400 if (override)
1401 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1402 else
1403 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1404
1405 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1406
1407 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1408 phy, ch, dev_priv->chv_phy_control);
1409
Ville Syrjälä30142272015-07-08 23:46:01 +03001410 assert_chv_phy_status(dev_priv);
1411
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001412out:
1413 mutex_unlock(&power_domains->lock);
1414
1415 return was_override;
1416}
1417
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001418void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1419 bool override, unsigned int mask)
1420{
1421 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1422 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1423 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1424 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1425
1426 mutex_lock(&power_domains->lock);
1427
1428 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1429 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1430
1431 if (override)
1432 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1433 else
1434 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1435
1436 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1437
1438 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1439 phy, ch, mask, dev_priv->chv_phy_control);
1440
Ville Syrjälä30142272015-07-08 23:46:01 +03001441 assert_chv_phy_status(dev_priv);
1442
Ville Syrjälä6669e392015-07-08 23:46:00 +03001443 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1444
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001445 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001446}
1447
1448static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1449 struct i915_power_well *power_well)
1450{
Imre Deakf49193c2017-07-06 17:40:23 +03001451 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001452 bool enabled;
1453 u32 state, ctrl;
1454
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001455 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001456
1457 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1458 /*
1459 * We only ever set the power-on and power-gate states, anything
1460 * else is unexpected.
1461 */
1462 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1463 enabled = state == DP_SSS_PWR_ON(pipe);
1464
1465 /*
1466 * A transient state at this point would mean some unexpected party
1467 * is poking at the power controls too.
1468 */
1469 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1470 WARN_ON(ctrl << 16 != state);
1471
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001472 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001473
1474 return enabled;
1475}
1476
1477static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1478 struct i915_power_well *power_well,
1479 bool enable)
1480{
Imre Deakf49193c2017-07-06 17:40:23 +03001481 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001482 u32 state;
1483 u32 ctrl;
1484
1485 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1486
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001487 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001488
1489#define COND \
1490 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1491
1492 if (COND)
1493 goto out;
1494
1495 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1496 ctrl &= ~DP_SSC_MASK(pipe);
1497 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1498 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1499
1500 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001501 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001502 state,
1503 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1504
1505#undef COND
1506
1507out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001508 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001509}
1510
Daniel Vetter9c065a72014-09-30 10:56:38 +02001511static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1512 struct i915_power_well *power_well)
1513{
Daniel Vetter9c065a72014-09-30 10:56:38 +02001514 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001515
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001516 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001517}
1518
1519static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1520 struct i915_power_well *power_well)
1521{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001522 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001523
Daniel Vetter9c065a72014-09-30 10:56:38 +02001524 chv_set_pipe_power_well(dev_priv, power_well, false);
1525}
1526
Imre Deak09731282016-02-17 14:17:42 +02001527static void
1528__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1529 enum intel_display_power_domain domain)
1530{
1531 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1532 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001533
Imre Deak75ccb2e2017-02-17 17:39:43 +02001534 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001535 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001536
1537 power_domains->domain_use_count[domain]++;
1538}
1539
Daniel Vettere4e76842014-09-30 10:56:42 +02001540/**
1541 * intel_display_power_get - grab a power domain reference
1542 * @dev_priv: i915 device instance
1543 * @domain: power domain to reference
1544 *
1545 * This function grabs a power domain reference for @domain and ensures that the
1546 * power domain and all its parents are powered up. Therefore users should only
1547 * grab a reference to the innermost power domain they need.
1548 *
1549 * Any power domain reference obtained by this function must have a symmetric
1550 * call to intel_display_power_put() to release the reference again.
1551 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001552void intel_display_power_get(struct drm_i915_private *dev_priv,
1553 enum intel_display_power_domain domain)
1554{
Imre Deak09731282016-02-17 14:17:42 +02001555 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001556
1557 intel_runtime_pm_get(dev_priv);
1558
Imre Deak09731282016-02-17 14:17:42 +02001559 mutex_lock(&power_domains->lock);
1560
1561 __intel_display_power_get_domain(dev_priv, domain);
1562
1563 mutex_unlock(&power_domains->lock);
1564}
1565
1566/**
1567 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1568 * @dev_priv: i915 device instance
1569 * @domain: power domain to reference
1570 *
1571 * This function grabs a power domain reference for @domain and ensures that the
1572 * power domain and all its parents are powered up. Therefore users should only
1573 * grab a reference to the innermost power domain they need.
1574 *
1575 * Any power domain reference obtained by this function must have a symmetric
1576 * call to intel_display_power_put() to release the reference again.
1577 */
1578bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1579 enum intel_display_power_domain domain)
1580{
1581 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1582 bool is_enabled;
1583
1584 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1585 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001586
1587 mutex_lock(&power_domains->lock);
1588
Imre Deak09731282016-02-17 14:17:42 +02001589 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1590 __intel_display_power_get_domain(dev_priv, domain);
1591 is_enabled = true;
1592 } else {
1593 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001594 }
1595
Daniel Vetter9c065a72014-09-30 10:56:38 +02001596 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001597
1598 if (!is_enabled)
1599 intel_runtime_pm_put(dev_priv);
1600
1601 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001602}
1603
Daniel Vettere4e76842014-09-30 10:56:42 +02001604/**
1605 * intel_display_power_put - release a power domain reference
1606 * @dev_priv: i915 device instance
1607 * @domain: power domain to reference
1608 *
1609 * This function drops the power domain reference obtained by
1610 * intel_display_power_get() and might power down the corresponding hardware
1611 * block right away if this is the last reference.
1612 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001613void intel_display_power_put(struct drm_i915_private *dev_priv,
1614 enum intel_display_power_domain domain)
1615{
1616 struct i915_power_domains *power_domains;
1617 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001618
1619 power_domains = &dev_priv->power_domains;
1620
1621 mutex_lock(&power_domains->lock);
1622
Daniel Stone11c86db2015-11-20 15:55:34 +00001623 WARN(!power_domains->domain_use_count[domain],
1624 "Use count on domain %s is already zero\n",
1625 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001626 power_domains->domain_use_count[domain]--;
1627
Imre Deak75ccb2e2017-02-17 17:39:43 +02001628 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001629 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001630
1631 mutex_unlock(&power_domains->lock);
1632
1633 intel_runtime_pm_put(dev_priv);
1634}
1635
Imre Deak965a79a2017-07-06 17:40:40 +03001636#define I830_PIPES_POWER_DOMAINS ( \
1637 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1638 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1639 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1640 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1641 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1642 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001643 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001644
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001645#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001646 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1647 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1648 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1649 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1650 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1651 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1652 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1653 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1654 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1655 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1656 BIT_ULL(POWER_DOMAIN_VGA) | \
1657 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1658 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1659 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1660 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1661 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001662
1663#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001664 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1665 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1666 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1667 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1668 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1669 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001670
1671#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001672 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1673 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1674 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001675
1676#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001677 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1678 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1679 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001680
1681#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001682 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1683 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1684 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001685
1686#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001687 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1688 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1689 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001690
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001691#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001692 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1693 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1694 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1695 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1696 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1697 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1698 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1699 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1700 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1701 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1702 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1703 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1704 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1705 BIT_ULL(POWER_DOMAIN_VGA) | \
1706 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1707 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1708 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1709 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1710 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1711 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001712
Daniel Vetter9c065a72014-09-30 10:56:38 +02001713#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001714 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1715 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1716 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1717 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1718 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001719
1720#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001721 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1722 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1723 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001724
Imre Deak965a79a2017-07-06 17:40:40 +03001725#define HSW_DISPLAY_POWER_DOMAINS ( \
1726 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1727 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1728 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1729 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1730 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1731 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1732 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1733 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1734 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1735 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1736 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1737 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1738 BIT_ULL(POWER_DOMAIN_VGA) | \
1739 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1740 BIT_ULL(POWER_DOMAIN_INIT))
1741
1742#define BDW_DISPLAY_POWER_DOMAINS ( \
1743 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1744 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1745 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1746 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1747 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1748 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1749 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1750 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1751 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1752 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1753 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1754 BIT_ULL(POWER_DOMAIN_VGA) | \
1755 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1756 BIT_ULL(POWER_DOMAIN_INIT))
1757
1758#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1759 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1760 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1761 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1762 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1763 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1764 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1765 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1766 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1767 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1768 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1769 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1770 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1771 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1772 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1773 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1774 BIT_ULL(POWER_DOMAIN_VGA) | \
1775 BIT_ULL(POWER_DOMAIN_INIT))
1776#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
1777 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
1778 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1779 BIT_ULL(POWER_DOMAIN_INIT))
1780#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1781 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1782 BIT_ULL(POWER_DOMAIN_INIT))
1783#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1784 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1785 BIT_ULL(POWER_DOMAIN_INIT))
1786#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
1787 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1788 BIT_ULL(POWER_DOMAIN_INIT))
1789#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1790 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001791 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001792 BIT_ULL(POWER_DOMAIN_MODESET) | \
1793 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1794 BIT_ULL(POWER_DOMAIN_INIT))
1795
1796#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1797 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1798 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1799 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1800 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1801 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1802 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1803 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1804 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1805 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1806 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1807 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1808 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1809 BIT_ULL(POWER_DOMAIN_VGA) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001810 BIT_ULL(POWER_DOMAIN_INIT))
1811#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1812 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001813 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001814 BIT_ULL(POWER_DOMAIN_MODESET) | \
1815 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä54c105d2017-12-08 23:37:37 +02001816 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001817 BIT_ULL(POWER_DOMAIN_INIT))
1818#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
1819 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1820 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1821 BIT_ULL(POWER_DOMAIN_INIT))
1822#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
1823 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1824 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1825 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1826 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1827 BIT_ULL(POWER_DOMAIN_INIT))
1828
1829#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1830 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1831 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1832 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1833 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1834 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1835 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1836 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1837 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1838 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1839 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1840 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1841 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1842 BIT_ULL(POWER_DOMAIN_VGA) | \
1843 BIT_ULL(POWER_DOMAIN_INIT))
1844#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
1845 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
1846#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1847 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
1848#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1849 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
1850#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
1851 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1852 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1853 BIT_ULL(POWER_DOMAIN_INIT))
1854#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
1855 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1856 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1857 BIT_ULL(POWER_DOMAIN_INIT))
1858#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
1859 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1860 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1861 BIT_ULL(POWER_DOMAIN_INIT))
1862#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
1863 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Imre Deak52528052018-06-21 21:44:49 +03001864 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001865 BIT_ULL(POWER_DOMAIN_INIT))
1866#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
1867 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1868 BIT_ULL(POWER_DOMAIN_INIT))
1869#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
1870 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1871 BIT_ULL(POWER_DOMAIN_INIT))
1872#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1873 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001874 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001875 BIT_ULL(POWER_DOMAIN_MODESET) | \
1876 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä156961a2017-12-08 23:37:36 +02001877 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001878 BIT_ULL(POWER_DOMAIN_INIT))
1879
1880#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1881 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1882 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1883 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1884 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1885 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1886 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1887 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1888 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1889 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1890 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001891 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001892 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1893 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1894 BIT_ULL(POWER_DOMAIN_AUX_D) | \
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001895 BIT_ULL(POWER_DOMAIN_AUX_F) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001896 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1897 BIT_ULL(POWER_DOMAIN_VGA) | \
1898 BIT_ULL(POWER_DOMAIN_INIT))
1899#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
1900 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001901 BIT_ULL(POWER_DOMAIN_INIT))
1902#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
1903 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1904 BIT_ULL(POWER_DOMAIN_INIT))
1905#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
1906 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1907 BIT_ULL(POWER_DOMAIN_INIT))
1908#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
1909 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1910 BIT_ULL(POWER_DOMAIN_INIT))
1911#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
1912 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Dhinakaran Pandiyanb891d5e2018-02-23 14:15:15 -08001913 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001914 BIT_ULL(POWER_DOMAIN_INIT))
1915#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
1916 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1917 BIT_ULL(POWER_DOMAIN_INIT))
1918#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
1919 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1920 BIT_ULL(POWER_DOMAIN_INIT))
1921#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
1922 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1923 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001924#define CNL_DISPLAY_AUX_F_POWER_DOMAINS ( \
1925 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1926 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001927#define CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS ( \
1928 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1929 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak965a79a2017-07-06 17:40:40 +03001930#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1931 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulin6e7a3f52018-01-11 08:24:17 +00001932 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001933 BIT_ULL(POWER_DOMAIN_MODESET) | \
1934 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001935 BIT_ULL(POWER_DOMAIN_INIT))
1936
Imre Deak67ca07e2018-06-26 17:22:32 +03001937/*
1938 * ICL PW_0/PG_0 domains (HW/DMC control):
1939 * - PCI
1940 * - clocks except port PLL
1941 * - central power except FBC
1942 * - shared functions except pipe interrupts, pipe MBUS, DBUF registers
1943 * ICL PW_1/PG_1 domains (HW/DMC control):
1944 * - DBUF function
1945 * - PIPE_A and its planes, except VGA
1946 * - transcoder EDP + PSR
1947 * - transcoder DSI
1948 * - DDI_A
1949 * - FBC
1950 */
1951#define ICL_PW_4_POWER_DOMAINS ( \
1952 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1953 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1954 BIT_ULL(POWER_DOMAIN_INIT))
1955 /* VDSC/joining */
1956#define ICL_PW_3_POWER_DOMAINS ( \
1957 ICL_PW_4_POWER_DOMAINS | \
1958 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1959 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1960 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1961 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1962 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1963 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1964 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1965 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1966 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1967 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1968 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1969 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1970 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1971 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
1972 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1973 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1974 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1975 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1976 BIT_ULL(POWER_DOMAIN_AUX_E) | \
1977 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1978 BIT_ULL(POWER_DOMAIN_AUX_TBT1) | \
1979 BIT_ULL(POWER_DOMAIN_AUX_TBT2) | \
1980 BIT_ULL(POWER_DOMAIN_AUX_TBT3) | \
1981 BIT_ULL(POWER_DOMAIN_AUX_TBT4) | \
1982 BIT_ULL(POWER_DOMAIN_VGA) | \
1983 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1984 BIT_ULL(POWER_DOMAIN_INIT))
1985 /*
1986 * - transcoder WD
1987 * - KVMR (HW control)
1988 */
1989#define ICL_PW_2_POWER_DOMAINS ( \
1990 ICL_PW_3_POWER_DOMAINS | \
1991 BIT_ULL(POWER_DOMAIN_INIT))
1992 /*
1993 * - eDP/DSI VDSC
1994 * - KVMR (HW control)
1995 */
1996#define ICL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1997 ICL_PW_2_POWER_DOMAINS | \
1998 BIT_ULL(POWER_DOMAIN_MODESET) | \
1999 BIT_ULL(POWER_DOMAIN_AUX_A) | \
2000 BIT_ULL(POWER_DOMAIN_INIT))
2001
2002#define ICL_DDI_IO_A_POWER_DOMAINS ( \
2003 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
2004#define ICL_DDI_IO_B_POWER_DOMAINS ( \
2005 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
2006#define ICL_DDI_IO_C_POWER_DOMAINS ( \
2007 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
2008#define ICL_DDI_IO_D_POWER_DOMAINS ( \
2009 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO))
2010#define ICL_DDI_IO_E_POWER_DOMAINS ( \
2011 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO))
2012#define ICL_DDI_IO_F_POWER_DOMAINS ( \
2013 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO))
2014
2015#define ICL_AUX_A_IO_POWER_DOMAINS ( \
2016 BIT_ULL(POWER_DOMAIN_AUX_A))
2017#define ICL_AUX_B_IO_POWER_DOMAINS ( \
2018 BIT_ULL(POWER_DOMAIN_AUX_B))
2019#define ICL_AUX_C_IO_POWER_DOMAINS ( \
2020 BIT_ULL(POWER_DOMAIN_AUX_C))
2021#define ICL_AUX_D_IO_POWER_DOMAINS ( \
2022 BIT_ULL(POWER_DOMAIN_AUX_D))
2023#define ICL_AUX_E_IO_POWER_DOMAINS ( \
2024 BIT_ULL(POWER_DOMAIN_AUX_E))
2025#define ICL_AUX_F_IO_POWER_DOMAINS ( \
2026 BIT_ULL(POWER_DOMAIN_AUX_F))
2027#define ICL_AUX_TBT1_IO_POWER_DOMAINS ( \
2028 BIT_ULL(POWER_DOMAIN_AUX_TBT1))
2029#define ICL_AUX_TBT2_IO_POWER_DOMAINS ( \
2030 BIT_ULL(POWER_DOMAIN_AUX_TBT2))
2031#define ICL_AUX_TBT3_IO_POWER_DOMAINS ( \
2032 BIT_ULL(POWER_DOMAIN_AUX_TBT3))
2033#define ICL_AUX_TBT4_IO_POWER_DOMAINS ( \
2034 BIT_ULL(POWER_DOMAIN_AUX_TBT4))
2035
Daniel Vetter9c065a72014-09-30 10:56:38 +02002036static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002037 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002038 .enable = i9xx_always_on_power_well_noop,
2039 .disable = i9xx_always_on_power_well_noop,
2040 .is_enabled = i9xx_always_on_power_well_enabled,
2041};
2042
2043static const struct i915_power_well_ops chv_pipe_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 = chv_pipe_power_well_enable,
2046 .disable = chv_pipe_power_well_disable,
2047 .is_enabled = chv_pipe_power_well_enabled,
2048};
2049
2050static const struct i915_power_well_ops chv_dpio_cmn_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_dpio_cmn_power_well_enable,
2053 .disable = chv_dpio_cmn_power_well_disable,
2054 .is_enabled = vlv_power_well_enabled,
2055};
2056
Imre Deakf28ec6f2018-08-06 12:58:37 +03002057static const struct i915_power_well_desc i9xx_always_on_power_well[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002058 {
2059 .name = "always-on",
2060 .always_on = 1,
2061 .domains = POWER_DOMAIN_MASK,
2062 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002063 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002064 },
2065};
2066
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002067static const struct i915_power_well_ops i830_pipes_power_well_ops = {
2068 .sync_hw = i830_pipes_power_well_sync_hw,
2069 .enable = i830_pipes_power_well_enable,
2070 .disable = i830_pipes_power_well_disable,
2071 .is_enabled = i830_pipes_power_well_enabled,
2072};
2073
Imre Deakf28ec6f2018-08-06 12:58:37 +03002074static const struct i915_power_well_desc i830_power_wells[] = {
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002075 {
2076 .name = "always-on",
2077 .always_on = 1,
2078 .domains = POWER_DOMAIN_MASK,
2079 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002080 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002081 },
2082 {
2083 .name = "pipes",
2084 .domains = I830_PIPES_POWER_DOMAINS,
2085 .ops = &i830_pipes_power_well_ops,
Imre Deak120b56a2017-07-11 23:42:31 +03002086 .id = I830_DISP_PW_PIPES,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002087 },
2088};
2089
Daniel Vetter9c065a72014-09-30 10:56:38 +02002090static const struct i915_power_well_ops hsw_power_well_ops = {
2091 .sync_hw = hsw_power_well_sync_hw,
2092 .enable = hsw_power_well_enable,
2093 .disable = hsw_power_well_disable,
2094 .is_enabled = hsw_power_well_enabled,
2095};
2096
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002097static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002098 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002099 .enable = gen9_dc_off_power_well_enable,
2100 .disable = gen9_dc_off_power_well_disable,
2101 .is_enabled = gen9_dc_off_power_well_enabled,
2102};
2103
Imre Deak9c8d0b82016-06-13 16:44:34 +03002104static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002105 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002106 .enable = bxt_dpio_cmn_power_well_enable,
2107 .disable = bxt_dpio_cmn_power_well_disable,
2108 .is_enabled = bxt_dpio_cmn_power_well_enabled,
2109};
2110
Imre Deakf28ec6f2018-08-06 12:58:37 +03002111static const struct i915_power_well_desc hsw_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002112 {
2113 .name = "always-on",
2114 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002115 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002116 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002117 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002118 },
2119 {
2120 .name = "display",
2121 .domains = HSW_DISPLAY_POWER_DOMAINS,
2122 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002123 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002124 {
2125 .hsw.has_vga = true,
2126 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002127 },
2128};
2129
Imre Deakf28ec6f2018-08-06 12:58:37 +03002130static const struct i915_power_well_desc bdw_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002131 {
2132 .name = "always-on",
2133 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002134 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002135 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002136 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002137 },
2138 {
2139 .name = "display",
2140 .domains = BDW_DISPLAY_POWER_DOMAINS,
2141 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002142 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002143 {
2144 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2145 .hsw.has_vga = true,
2146 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002147 },
2148};
2149
2150static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002151 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002152 .enable = vlv_display_power_well_enable,
2153 .disable = vlv_display_power_well_disable,
2154 .is_enabled = vlv_power_well_enabled,
2155};
2156
2157static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002158 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002159 .enable = vlv_dpio_cmn_power_well_enable,
2160 .disable = vlv_dpio_cmn_power_well_disable,
2161 .is_enabled = vlv_power_well_enabled,
2162};
2163
2164static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002165 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002166 .enable = vlv_power_well_enable,
2167 .disable = vlv_power_well_disable,
2168 .is_enabled = vlv_power_well_enabled,
2169};
2170
Imre Deakf28ec6f2018-08-06 12:58:37 +03002171static const struct i915_power_well_desc vlv_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002172 {
2173 .name = "always-on",
2174 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002175 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002176 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002177 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002178 },
2179 {
2180 .name = "display",
2181 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002182 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002183 .ops = &vlv_display_power_well_ops,
2184 },
2185 {
2186 .name = "dpio-tx-b-01",
2187 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2188 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2189 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2190 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2191 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002192 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002193 },
2194 {
2195 .name = "dpio-tx-b-23",
2196 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2197 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2198 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2199 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2200 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002201 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002202 },
2203 {
2204 .name = "dpio-tx-c-01",
2205 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2206 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2207 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2208 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2209 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002210 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002211 },
2212 {
2213 .name = "dpio-tx-c-23",
2214 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2215 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2216 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2217 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2218 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002219 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002220 },
2221 {
2222 .name = "dpio-common",
2223 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002224 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002225 .ops = &vlv_dpio_cmn_power_well_ops,
2226 },
2227};
2228
Imre Deakf28ec6f2018-08-06 12:58:37 +03002229static const struct i915_power_well_desc chv_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002230 {
2231 .name = "always-on",
2232 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002233 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002234 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002235 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002236 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002237 {
2238 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002239 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002240 * Pipe A power well is the new disp2d well. Pipe B and C
2241 * power wells don't actually exist. Pipe A power well is
2242 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002243 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002244 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002245 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002246 .ops = &chv_pipe_power_well_ops,
2247 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002248 {
2249 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002250 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002251 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002252 .ops = &chv_dpio_cmn_power_well_ops,
2253 },
2254 {
2255 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002256 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002257 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002258 .ops = &chv_dpio_cmn_power_well_ops,
2259 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002260};
2261
Suketu Shah5aefb232015-04-16 14:22:10 +05302262bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002263 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302264{
2265 struct i915_power_well *power_well;
2266 bool ret;
2267
2268 power_well = lookup_power_well(dev_priv, power_well_id);
Imre Deakf28ec6f2018-08-06 12:58:37 +03002269 ret = power_well->desc->ops->is_enabled(dev_priv, power_well);
Suketu Shah5aefb232015-04-16 14:22:10 +05302270
2271 return ret;
2272}
2273
Imre Deakf28ec6f2018-08-06 12:58:37 +03002274static const struct i915_power_well_desc skl_power_wells[] = {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002275 {
2276 .name = "always-on",
2277 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002278 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002279 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002280 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002281 },
2282 {
2283 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002284 /* Handled by the DMC firmware */
2285 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002286 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002287 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002288 {
2289 .hsw.has_fuses = true,
2290 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002291 },
2292 {
2293 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002294 /* Handled by the DMC firmware */
2295 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002296 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002297 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002298 },
2299 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002300 .name = "DC off",
2301 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2302 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002303 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002304 },
2305 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002306 .name = "power well 2",
2307 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002308 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002309 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002310 {
2311 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2312 .hsw.has_vga = true,
2313 .hsw.has_fuses = true,
2314 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002315 },
2316 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002317 .name = "DDI A/E IO power well",
2318 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002319 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002320 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002321 },
2322 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002323 .name = "DDI B IO power well",
2324 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002325 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002326 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002327 },
2328 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002329 .name = "DDI C IO power well",
2330 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002331 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002332 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002333 },
2334 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002335 .name = "DDI D IO power well",
2336 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002337 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002338 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002339 },
2340};
2341
Imre Deakf28ec6f2018-08-06 12:58:37 +03002342static const struct i915_power_well_desc bxt_power_wells[] = {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302343 {
2344 .name = "always-on",
2345 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002346 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302347 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002348 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302349 },
2350 {
2351 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002352 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002353 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002354 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002355 {
2356 .hsw.has_fuses = true,
2357 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302358 },
2359 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002360 .name = "DC off",
2361 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2362 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002363 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002364 },
2365 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302366 .name = "power well 2",
2367 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002368 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002369 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002370 {
2371 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2372 .hsw.has_vga = true,
2373 .hsw.has_fuses = true,
2374 },
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002375 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002376 {
2377 .name = "dpio-common-a",
2378 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2379 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002380 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002381 {
2382 .bxt.phy = DPIO_PHY1,
2383 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002384 },
2385 {
2386 .name = "dpio-common-bc",
2387 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2388 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002389 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002390 {
2391 .bxt.phy = DPIO_PHY0,
2392 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002393 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302394};
2395
Imre Deakf28ec6f2018-08-06 12:58:37 +03002396static const struct i915_power_well_desc glk_power_wells[] = {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002397 {
2398 .name = "always-on",
2399 .always_on = 1,
2400 .domains = POWER_DOMAIN_MASK,
2401 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002402 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002403 },
2404 {
2405 .name = "power well 1",
2406 /* Handled by the DMC firmware */
2407 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002408 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002409 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002410 {
2411 .hsw.has_fuses = true,
2412 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002413 },
2414 {
2415 .name = "DC off",
2416 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2417 .ops = &gen9_dc_off_power_well_ops,
2418 .id = SKL_DISP_PW_DC_OFF,
2419 },
2420 {
2421 .name = "power well 2",
2422 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002423 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002424 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002425 {
2426 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2427 .hsw.has_vga = true,
2428 .hsw.has_fuses = true,
2429 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002430 },
2431 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002432 .name = "dpio-common-a",
2433 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2434 .ops = &bxt_dpio_cmn_power_well_ops,
2435 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002436 {
2437 .bxt.phy = DPIO_PHY1,
2438 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002439 },
2440 {
2441 .name = "dpio-common-b",
2442 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2443 .ops = &bxt_dpio_cmn_power_well_ops,
2444 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002445 {
2446 .bxt.phy = DPIO_PHY0,
2447 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002448 },
2449 {
2450 .name = "dpio-common-c",
2451 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2452 .ops = &bxt_dpio_cmn_power_well_ops,
2453 .id = GLK_DPIO_CMN_C,
Imre Deak0a445942017-08-14 18:15:29 +03002454 {
2455 .bxt.phy = DPIO_PHY2,
2456 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002457 },
2458 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002459 .name = "AUX A",
2460 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002461 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002462 .id = GLK_DISP_PW_AUX_A,
2463 },
2464 {
2465 .name = "AUX B",
2466 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002467 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002468 .id = GLK_DISP_PW_AUX_B,
2469 },
2470 {
2471 .name = "AUX C",
2472 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002473 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002474 .id = GLK_DISP_PW_AUX_C,
2475 },
2476 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002477 .name = "DDI A IO power well",
2478 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002479 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002480 .id = GLK_DISP_PW_DDI_A,
2481 },
2482 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002483 .name = "DDI B IO power well",
2484 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002485 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002486 .id = SKL_DISP_PW_DDI_B,
2487 },
2488 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002489 .name = "DDI C IO power well",
2490 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002491 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002492 .id = SKL_DISP_PW_DDI_C,
2493 },
2494};
2495
Imre Deakf28ec6f2018-08-06 12:58:37 +03002496static const struct i915_power_well_desc cnl_power_wells[] = {
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002497 {
2498 .name = "always-on",
2499 .always_on = 1,
2500 .domains = POWER_DOMAIN_MASK,
2501 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002502 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002503 },
2504 {
2505 .name = "power well 1",
2506 /* Handled by the DMC firmware */
2507 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002508 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002509 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002510 {
2511 .hsw.has_fuses = true,
2512 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002513 },
2514 {
2515 .name = "AUX A",
2516 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002517 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002518 .id = CNL_DISP_PW_AUX_A,
2519 },
2520 {
2521 .name = "AUX B",
2522 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002523 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002524 .id = CNL_DISP_PW_AUX_B,
2525 },
2526 {
2527 .name = "AUX C",
2528 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002529 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002530 .id = CNL_DISP_PW_AUX_C,
2531 },
2532 {
2533 .name = "AUX D",
2534 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002535 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002536 .id = CNL_DISP_PW_AUX_D,
2537 },
2538 {
2539 .name = "DC off",
2540 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2541 .ops = &gen9_dc_off_power_well_ops,
2542 .id = SKL_DISP_PW_DC_OFF,
2543 },
2544 {
2545 .name = "power well 2",
2546 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002547 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002548 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002549 {
2550 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2551 .hsw.has_vga = true,
2552 .hsw.has_fuses = true,
2553 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002554 },
2555 {
2556 .name = "DDI A IO power well",
2557 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002558 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002559 .id = CNL_DISP_PW_DDI_A,
2560 },
2561 {
2562 .name = "DDI B IO power well",
2563 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002564 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002565 .id = SKL_DISP_PW_DDI_B,
2566 },
2567 {
2568 .name = "DDI C IO power well",
2569 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002570 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002571 .id = SKL_DISP_PW_DDI_C,
2572 },
2573 {
2574 .name = "DDI D IO power well",
2575 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002576 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002577 .id = SKL_DISP_PW_DDI_D,
2578 },
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002579 {
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002580 .name = "DDI F IO power well",
2581 .domains = CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS,
2582 .ops = &hsw_power_well_ops,
2583 .id = CNL_DISP_PW_DDI_F,
2584 },
2585 {
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002586 .name = "AUX F",
2587 .domains = CNL_DISPLAY_AUX_F_POWER_DOMAINS,
2588 .ops = &hsw_power_well_ops,
2589 .id = CNL_DISP_PW_AUX_F,
2590 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002591};
2592
Imre Deak67ca07e2018-06-26 17:22:32 +03002593static const struct i915_power_well_ops icl_combo_phy_aux_power_well_ops = {
2594 .sync_hw = hsw_power_well_sync_hw,
2595 .enable = icl_combo_phy_aux_power_well_enable,
2596 .disable = icl_combo_phy_aux_power_well_disable,
2597 .is_enabled = hsw_power_well_enabled,
2598};
2599
Imre Deakf28ec6f2018-08-06 12:58:37 +03002600static const struct i915_power_well_desc icl_power_wells[] = {
Imre Deak67ca07e2018-06-26 17:22:32 +03002601 {
2602 .name = "always-on",
2603 .always_on = 1,
2604 .domains = POWER_DOMAIN_MASK,
2605 .ops = &i9xx_always_on_power_well_ops,
2606 .id = I915_DISP_PW_ALWAYS_ON,
2607 },
2608 {
2609 .name = "power well 1",
2610 /* Handled by the DMC firmware */
2611 .domains = 0,
2612 .ops = &hsw_power_well_ops,
2613 .id = ICL_DISP_PW_1,
Imre Deakae9b06c2018-08-06 12:58:34 +03002614 {
2615 .hsw.has_fuses = true,
2616 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002617 },
2618 {
2619 .name = "power well 2",
2620 .domains = ICL_PW_2_POWER_DOMAINS,
2621 .ops = &hsw_power_well_ops,
2622 .id = ICL_DISP_PW_2,
Imre Deakae9b06c2018-08-06 12:58:34 +03002623 {
2624 .hsw.has_fuses = true,
2625 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002626 },
2627 {
2628 .name = "DC off",
2629 .domains = ICL_DISPLAY_DC_OFF_POWER_DOMAINS,
2630 .ops = &gen9_dc_off_power_well_ops,
2631 .id = SKL_DISP_PW_DC_OFF,
2632 },
2633 {
2634 .name = "power well 3",
2635 .domains = ICL_PW_3_POWER_DOMAINS,
2636 .ops = &hsw_power_well_ops,
2637 .id = ICL_DISP_PW_3,
Imre Deakae9b06c2018-08-06 12:58:34 +03002638 {
2639 .hsw.irq_pipe_mask = BIT(PIPE_B),
2640 .hsw.has_vga = true,
2641 .hsw.has_fuses = true,
2642 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002643 },
2644 {
2645 .name = "DDI A IO",
2646 .domains = ICL_DDI_IO_A_POWER_DOMAINS,
2647 .ops = &hsw_power_well_ops,
2648 .id = ICL_DISP_PW_DDI_A,
2649 },
2650 {
2651 .name = "DDI B IO",
2652 .domains = ICL_DDI_IO_B_POWER_DOMAINS,
2653 .ops = &hsw_power_well_ops,
2654 .id = ICL_DISP_PW_DDI_B,
2655 },
2656 {
2657 .name = "DDI C IO",
2658 .domains = ICL_DDI_IO_C_POWER_DOMAINS,
2659 .ops = &hsw_power_well_ops,
2660 .id = ICL_DISP_PW_DDI_C,
2661 },
2662 {
2663 .name = "DDI D IO",
2664 .domains = ICL_DDI_IO_D_POWER_DOMAINS,
2665 .ops = &hsw_power_well_ops,
2666 .id = ICL_DISP_PW_DDI_D,
2667 },
2668 {
2669 .name = "DDI E IO",
2670 .domains = ICL_DDI_IO_E_POWER_DOMAINS,
2671 .ops = &hsw_power_well_ops,
2672 .id = ICL_DISP_PW_DDI_E,
2673 },
2674 {
2675 .name = "DDI F IO",
2676 .domains = ICL_DDI_IO_F_POWER_DOMAINS,
2677 .ops = &hsw_power_well_ops,
2678 .id = ICL_DISP_PW_DDI_F,
2679 },
2680 {
2681 .name = "AUX A",
2682 .domains = ICL_AUX_A_IO_POWER_DOMAINS,
2683 .ops = &icl_combo_phy_aux_power_well_ops,
2684 .id = ICL_DISP_PW_AUX_A,
2685 },
2686 {
2687 .name = "AUX B",
2688 .domains = ICL_AUX_B_IO_POWER_DOMAINS,
2689 .ops = &icl_combo_phy_aux_power_well_ops,
2690 .id = ICL_DISP_PW_AUX_B,
2691 },
2692 {
2693 .name = "AUX C",
2694 .domains = ICL_AUX_C_IO_POWER_DOMAINS,
2695 .ops = &hsw_power_well_ops,
2696 .id = ICL_DISP_PW_AUX_C,
2697 },
2698 {
2699 .name = "AUX D",
2700 .domains = ICL_AUX_D_IO_POWER_DOMAINS,
2701 .ops = &hsw_power_well_ops,
2702 .id = ICL_DISP_PW_AUX_D,
2703 },
2704 {
2705 .name = "AUX E",
2706 .domains = ICL_AUX_E_IO_POWER_DOMAINS,
2707 .ops = &hsw_power_well_ops,
2708 .id = ICL_DISP_PW_AUX_E,
2709 },
2710 {
2711 .name = "AUX F",
2712 .domains = ICL_AUX_F_IO_POWER_DOMAINS,
2713 .ops = &hsw_power_well_ops,
2714 .id = ICL_DISP_PW_AUX_F,
2715 },
2716 {
2717 .name = "AUX TBT1",
2718 .domains = ICL_AUX_TBT1_IO_POWER_DOMAINS,
2719 .ops = &hsw_power_well_ops,
2720 .id = ICL_DISP_PW_AUX_TBT1,
2721 },
2722 {
2723 .name = "AUX TBT2",
2724 .domains = ICL_AUX_TBT2_IO_POWER_DOMAINS,
2725 .ops = &hsw_power_well_ops,
2726 .id = ICL_DISP_PW_AUX_TBT2,
2727 },
2728 {
2729 .name = "AUX TBT3",
2730 .domains = ICL_AUX_TBT3_IO_POWER_DOMAINS,
2731 .ops = &hsw_power_well_ops,
2732 .id = ICL_DISP_PW_AUX_TBT3,
2733 },
2734 {
2735 .name = "AUX TBT4",
2736 .domains = ICL_AUX_TBT4_IO_POWER_DOMAINS,
2737 .ops = &hsw_power_well_ops,
2738 .id = ICL_DISP_PW_AUX_TBT4,
2739 },
2740 {
2741 .name = "power well 4",
2742 .domains = ICL_PW_4_POWER_DOMAINS,
2743 .ops = &hsw_power_well_ops,
2744 .id = ICL_DISP_PW_4,
Imre Deakae9b06c2018-08-06 12:58:34 +03002745 {
2746 .hsw.has_fuses = true,
2747 .hsw.irq_pipe_mask = BIT(PIPE_C),
2748 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002749 },
2750};
2751
Imre Deak1b0e3a02015-11-05 23:04:11 +02002752static int
2753sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2754 int disable_power_well)
2755{
2756 if (disable_power_well >= 0)
2757 return !!disable_power_well;
2758
Imre Deak1b0e3a02015-11-05 23:04:11 +02002759 return 1;
2760}
2761
Imre Deaka37baf32016-02-29 22:49:03 +02002762static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2763 int enable_dc)
2764{
2765 uint32_t mask;
2766 int requested_dc;
2767 int max_dc;
2768
Imre Deak67ca07e2018-06-26 17:22:32 +03002769 if (IS_GEN9_BC(dev_priv) || INTEL_INFO(dev_priv)->gen >= 10) {
Imre Deaka37baf32016-02-29 22:49:03 +02002770 max_dc = 2;
2771 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002772 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002773 max_dc = 1;
2774 /*
2775 * DC9 has a separate HW flow from the rest of the DC states,
2776 * not depending on the DMC firmware. It's needed by system
2777 * suspend/resume, so allow it unconditionally.
2778 */
2779 mask = DC_STATE_EN_DC9;
2780 } else {
2781 max_dc = 0;
2782 mask = 0;
2783 }
2784
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002785 if (!i915_modparams.disable_power_well)
Imre Deak66e2c4c2016-02-29 22:49:04 +02002786 max_dc = 0;
2787
Imre Deaka37baf32016-02-29 22:49:03 +02002788 if (enable_dc >= 0 && enable_dc <= max_dc) {
2789 requested_dc = enable_dc;
2790 } else if (enable_dc == -1) {
2791 requested_dc = max_dc;
2792 } else if (enable_dc > max_dc && enable_dc <= 2) {
2793 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2794 enable_dc, max_dc);
2795 requested_dc = max_dc;
2796 } else {
2797 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2798 requested_dc = max_dc;
2799 }
2800
2801 if (requested_dc > 1)
2802 mask |= DC_STATE_EN_UPTO_DC6;
2803 if (requested_dc > 0)
2804 mask |= DC_STATE_EN_UPTO_DC5;
2805
2806 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2807
2808 return mask;
2809}
2810
Imre Deakf28ec6f2018-08-06 12:58:37 +03002811static int
2812__set_power_wells(struct i915_power_domains *power_domains,
2813 const struct i915_power_well_desc *power_well_descs,
2814 int power_well_count)
Imre Deak21792c62017-07-11 23:42:33 +03002815{
Imre Deakf28ec6f2018-08-06 12:58:37 +03002816 u64 power_well_ids = 0;
Imre Deak21792c62017-07-11 23:42:33 +03002817 int i;
2818
Imre Deakf28ec6f2018-08-06 12:58:37 +03002819 power_domains->power_well_count = power_well_count;
2820 power_domains->power_wells =
2821 kcalloc(power_well_count,
2822 sizeof(*power_domains->power_wells),
2823 GFP_KERNEL);
2824 if (!power_domains->power_wells)
2825 return -ENOMEM;
2826
2827 for (i = 0; i < power_well_count; i++) {
2828 enum i915_power_well_id id = power_well_descs[i].id;
2829
2830 power_domains->power_wells[i].desc = &power_well_descs[i];
Imre Deak21792c62017-07-11 23:42:33 +03002831
2832 WARN_ON(id >= sizeof(power_well_ids) * 8);
2833 WARN_ON(power_well_ids & BIT_ULL(id));
2834 power_well_ids |= BIT_ULL(id);
2835 }
Imre Deakf28ec6f2018-08-06 12:58:37 +03002836
2837 return 0;
Imre Deak21792c62017-07-11 23:42:33 +03002838}
2839
Imre Deakf28ec6f2018-08-06 12:58:37 +03002840#define set_power_wells(power_domains, __power_well_descs) \
2841 __set_power_wells(power_domains, __power_well_descs, \
2842 ARRAY_SIZE(__power_well_descs))
Daniel Vetter9c065a72014-09-30 10:56:38 +02002843
Daniel Vettere4e76842014-09-30 10:56:42 +02002844/**
2845 * intel_power_domains_init - initializes the power domain structures
2846 * @dev_priv: i915 device instance
2847 *
2848 * Initializes the power domain structures for @dev_priv depending upon the
2849 * supported platform.
2850 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002851int intel_power_domains_init(struct drm_i915_private *dev_priv)
2852{
2853 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deakf28ec6f2018-08-06 12:58:37 +03002854 int err;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002855
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002856 i915_modparams.disable_power_well =
2857 sanitize_disable_power_well_option(dev_priv,
2858 i915_modparams.disable_power_well);
2859 dev_priv->csr.allowed_dc_mask =
2860 get_allowed_dc_mask(dev_priv, i915_modparams.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002861
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002862 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002863
Daniel Vetter9c065a72014-09-30 10:56:38 +02002864 mutex_init(&power_domains->lock);
2865
2866 /*
2867 * The enabling order will be from lower to higher indexed wells,
2868 * the disabling order is reversed.
2869 */
Imre Deak67ca07e2018-06-26 17:22:32 +03002870 if (IS_ICELAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002871 err = set_power_wells(power_domains, icl_power_wells);
Imre Deak67ca07e2018-06-26 17:22:32 +03002872 } else if (IS_HASWELL(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002873 err = set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002874 } else if (IS_BROADWELL(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002875 err = set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002876 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002877 err = set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002878 } else if (IS_CANNONLAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002879 err = set_power_wells(power_domains, cnl_power_wells);
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002880
2881 /*
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002882 * DDI and Aux IO are getting enabled for all ports
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002883 * regardless the presence or use. So, in order to avoid
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002884 * timeouts, lets remove them from the list
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002885 * for the SKUs without port F.
2886 */
2887 if (!IS_CNL_WITH_PORT_F(dev_priv))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002888 power_domains->power_well_count -= 2;
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002889
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002890 } else if (IS_BROXTON(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002891 err = set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002892 } else if (IS_GEMINILAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002893 err = set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002894 } else if (IS_CHERRYVIEW(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002895 err = set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002896 } else if (IS_VALLEYVIEW(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002897 err = set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002898 } else if (IS_I830(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002899 err = set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002900 } else {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002901 err = set_power_wells(power_domains, i9xx_always_on_power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002902 }
2903
Imre Deakf28ec6f2018-08-06 12:58:37 +03002904 return err;
2905}
Imre Deak21792c62017-07-11 23:42:33 +03002906
Imre Deakf28ec6f2018-08-06 12:58:37 +03002907/**
2908 * intel_power_domains_cleanup - clean up power domains resources
2909 * @dev_priv: i915 device instance
2910 *
2911 * Release any resources acquired by intel_power_domains_init()
2912 */
2913void intel_power_domains_cleanup(struct drm_i915_private *dev_priv)
2914{
2915 kfree(dev_priv->power_domains.power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002916}
2917
Imre Deak30eade12015-11-04 19:24:13 +02002918static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002919{
2920 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2921 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002922
2923 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002924 for_each_power_well(dev_priv, power_well) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002925 power_well->desc->ops->sync_hw(dev_priv, power_well);
2926 power_well->hw_enabled =
2927 power_well->desc->ops->is_enabled(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002928 }
2929 mutex_unlock(&power_domains->lock);
2930}
2931
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302932static inline
2933bool intel_dbuf_slice_set(struct drm_i915_private *dev_priv,
2934 i915_reg_t reg, bool enable)
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002935{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302936 u32 val, status;
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002937
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302938 val = I915_READ(reg);
2939 val = enable ? (val | DBUF_POWER_REQUEST) : (val & ~DBUF_POWER_REQUEST);
2940 I915_WRITE(reg, val);
2941 POSTING_READ(reg);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002942 udelay(10);
2943
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302944 status = I915_READ(reg) & DBUF_POWER_STATE;
2945 if ((enable && !status) || (!enable && status)) {
2946 DRM_ERROR("DBus power %s timeout!\n",
2947 enable ? "enable" : "disable");
2948 return false;
2949 }
2950 return true;
2951}
2952
2953static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2954{
2955 intel_dbuf_slice_set(dev_priv, DBUF_CTL, true);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002956}
2957
2958static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2959{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302960 intel_dbuf_slice_set(dev_priv, DBUF_CTL, false);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002961}
2962
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302963static u8 intel_dbuf_max_slices(struct drm_i915_private *dev_priv)
2964{
2965 if (INTEL_GEN(dev_priv) < 11)
2966 return 1;
2967 return 2;
2968}
2969
2970void icl_dbuf_slices_update(struct drm_i915_private *dev_priv,
2971 u8 req_slices)
2972{
2973 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
2974 u32 val;
2975 bool ret;
2976
2977 if (req_slices > intel_dbuf_max_slices(dev_priv)) {
2978 DRM_ERROR("Invalid number of dbuf slices requested\n");
2979 return;
2980 }
2981
2982 if (req_slices == hw_enabled_slices || req_slices == 0)
2983 return;
2984
2985 val = I915_READ(DBUF_CTL_S2);
2986 if (req_slices > hw_enabled_slices)
2987 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, true);
2988 else
2989 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, false);
2990
2991 if (ret)
2992 dev_priv->wm.skl_hw.ddb.enabled_slices = req_slices;
2993}
2994
Mahesh Kumar746edf82018-02-05 13:40:44 -02002995static void icl_dbuf_enable(struct drm_i915_private *dev_priv)
2996{
2997 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) | DBUF_POWER_REQUEST);
2998 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) | DBUF_POWER_REQUEST);
2999 POSTING_READ(DBUF_CTL_S2);
3000
3001 udelay(10);
3002
3003 if (!(I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
3004 !(I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
3005 DRM_ERROR("DBuf power enable timeout\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303006 else
3007 dev_priv->wm.skl_hw.ddb.enabled_slices = 2;
Mahesh Kumar746edf82018-02-05 13:40:44 -02003008}
3009
3010static void icl_dbuf_disable(struct drm_i915_private *dev_priv)
3011{
3012 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) & ~DBUF_POWER_REQUEST);
3013 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) & ~DBUF_POWER_REQUEST);
3014 POSTING_READ(DBUF_CTL_S2);
3015
3016 udelay(10);
3017
3018 if ((I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
3019 (I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
3020 DRM_ERROR("DBuf power disable timeout!\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303021 else
3022 dev_priv->wm.skl_hw.ddb.enabled_slices = 0;
Mahesh Kumar746edf82018-02-05 13:40:44 -02003023}
3024
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003025static void icl_mbus_init(struct drm_i915_private *dev_priv)
3026{
3027 uint32_t val;
3028
3029 val = MBUS_ABOX_BT_CREDIT_POOL1(16) |
3030 MBUS_ABOX_BT_CREDIT_POOL2(16) |
3031 MBUS_ABOX_B_CREDIT(1) |
3032 MBUS_ABOX_BW_CREDIT(1);
3033
3034 I915_WRITE(MBUS_ABOX_CTL, val);
3035}
3036
Imre Deak73dfc222015-11-17 17:33:53 +02003037static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03003038 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02003039{
3040 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003041 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003042 uint32_t val;
3043
Imre Deakd26fa1d2015-11-04 19:24:17 +02003044 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3045
Imre Deak73dfc222015-11-17 17:33:53 +02003046 /* enable PCH reset handshake */
3047 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3048 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
3049
3050 /* enable PG1 and Misc I/O */
3051 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003052
3053 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3054 intel_power_well_enable(dev_priv, well);
3055
3056 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
3057 intel_power_well_enable(dev_priv, well);
3058
Imre Deak73dfc222015-11-17 17:33:53 +02003059 mutex_unlock(&power_domains->lock);
3060
Imre Deak73dfc222015-11-17 17:33:53 +02003061 skl_init_cdclk(dev_priv);
3062
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003063 gen9_dbuf_enable(dev_priv);
3064
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03003065 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02003066 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003067}
3068
3069static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
3070{
3071 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003072 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003073
Imre Deakd26fa1d2015-11-04 19:24:17 +02003074 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3075
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003076 gen9_dbuf_disable(dev_priv);
3077
Imre Deak73dfc222015-11-17 17:33:53 +02003078 skl_uninit_cdclk(dev_priv);
3079
3080 /* The spec doesn't call for removing the reset handshake flag */
3081 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03003082
Imre Deak73dfc222015-11-17 17:33:53 +02003083 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003084
Imre Deakedfda8e2017-06-29 18:36:59 +03003085 /*
3086 * BSpec says to keep the MISC IO power well enabled here, only
3087 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03003088 * Note that even though the driver's request is removed power well 1
3089 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03003090 */
Imre Deak443a93a2016-04-04 15:42:57 +03003091 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3092 intel_power_well_disable(dev_priv, well);
3093
Imre Deak73dfc222015-11-17 17:33:53 +02003094 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003095
3096 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02003097}
3098
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003099void bxt_display_core_init(struct drm_i915_private *dev_priv,
3100 bool resume)
3101{
3102 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3103 struct i915_power_well *well;
3104 uint32_t val;
3105
3106 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3107
3108 /*
3109 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
3110 * or else the reset will hang because there is no PCH to respond.
3111 * Move the handshake programming to initialization sequence.
3112 * Previously was left up to BIOS.
3113 */
3114 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3115 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
3116 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3117
3118 /* Enable PG1 */
3119 mutex_lock(&power_domains->lock);
3120
3121 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3122 intel_power_well_enable(dev_priv, well);
3123
3124 mutex_unlock(&power_domains->lock);
3125
Imre Deak324513c2016-06-13 16:44:36 +03003126 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003127
3128 gen9_dbuf_enable(dev_priv);
3129
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003130 if (resume && dev_priv->csr.dmc_payload)
3131 intel_csr_load_program(dev_priv);
3132}
3133
3134void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
3135{
3136 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3137 struct i915_power_well *well;
3138
3139 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3140
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003141 gen9_dbuf_disable(dev_priv);
3142
Imre Deak324513c2016-06-13 16:44:36 +03003143 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003144
3145 /* The spec doesn't call for removing the reset handshake flag */
3146
Imre Deak42d93662017-06-29 18:37:01 +03003147 /*
3148 * Disable PW1 (PG1).
3149 * Note that even though the driver's request is removed power well 1
3150 * may stay enabled after this due to DMC's own request on it.
3151 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003152 mutex_lock(&power_domains->lock);
3153
3154 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3155 intel_power_well_disable(dev_priv, well);
3156
3157 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003158
3159 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003160}
3161
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003162enum {
3163 PROCMON_0_85V_DOT_0,
3164 PROCMON_0_95V_DOT_0,
3165 PROCMON_0_95V_DOT_1,
3166 PROCMON_1_05V_DOT_0,
3167 PROCMON_1_05V_DOT_1,
3168};
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003169
3170static const struct cnl_procmon {
3171 u32 dw1, dw9, dw10;
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003172} cnl_procmon_values[] = {
3173 [PROCMON_0_85V_DOT_0] =
3174 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
3175 [PROCMON_0_95V_DOT_0] =
3176 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
3177 [PROCMON_0_95V_DOT_1] =
3178 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
3179 [PROCMON_1_05V_DOT_0] =
3180 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
3181 [PROCMON_1_05V_DOT_1] =
3182 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003183};
3184
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003185/*
3186 * CNL has just one set of registers, while ICL has two sets: one for port A and
3187 * the other for port B. The CNL registers are equivalent to the ICL port A
3188 * registers, that's why we call the ICL macros even though the function has CNL
3189 * on its name.
3190 */
3191static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
3192 enum port port)
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003193{
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003194 const struct cnl_procmon *procmon;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003195 u32 val;
3196
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003197 val = I915_READ(ICL_PORT_COMP_DW3(port));
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003198 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
3199 default:
3200 MISSING_CASE(val);
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05003201 /* fall through */
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003202 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
3203 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
3204 break;
3205 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
3206 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
3207 break;
3208 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
3209 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
3210 break;
3211 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
3212 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
3213 break;
3214 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
3215 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
3216 break;
3217 }
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003218
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003219 val = I915_READ(ICL_PORT_COMP_DW1(port));
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003220 val &= ~((0xff << 16) | 0xff);
3221 val |= procmon->dw1;
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003222 I915_WRITE(ICL_PORT_COMP_DW1(port), val);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003223
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003224 I915_WRITE(ICL_PORT_COMP_DW9(port), procmon->dw9);
3225 I915_WRITE(ICL_PORT_COMP_DW10(port), procmon->dw10);
Paulo Zanoniade5ee72017-08-21 17:03:56 -07003226}
3227
3228static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
3229{
3230 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3231 struct i915_power_well *well;
3232 u32 val;
3233
3234 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3235
3236 /* 1. Enable PCH Reset Handshake */
3237 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3238 val |= RESET_PCH_HANDSHAKE_ENABLE;
3239 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3240
3241 /* 2. Enable Comp */
3242 val = I915_READ(CHICKEN_MISC_2);
3243 val &= ~CNL_COMP_PWR_DOWN;
3244 I915_WRITE(CHICKEN_MISC_2, val);
3245
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003246 /* Dummy PORT_A to get the correct CNL register from the ICL macro */
3247 cnl_set_procmon_ref_values(dev_priv, PORT_A);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003248
3249 val = I915_READ(CNL_PORT_COMP_DW0);
3250 val |= COMP_INIT;
3251 I915_WRITE(CNL_PORT_COMP_DW0, val);
3252
3253 /* 3. */
3254 val = I915_READ(CNL_PORT_CL1CM_DW5);
3255 val |= CL_POWER_DOWN_ENABLE;
3256 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
3257
Imre Deakb38131f2017-06-29 18:37:02 +03003258 /*
3259 * 4. Enable Power Well 1 (PG1).
3260 * The AUX IO power wells will be enabled on demand.
3261 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003262 mutex_lock(&power_domains->lock);
3263 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3264 intel_power_well_enable(dev_priv, well);
3265 mutex_unlock(&power_domains->lock);
3266
3267 /* 5. Enable CD clock */
3268 cnl_init_cdclk(dev_priv);
3269
3270 /* 6. Enable DBUF */
3271 gen9_dbuf_enable(dev_priv);
Imre Deak57522c42017-10-03 12:51:58 +03003272
3273 if (resume && dev_priv->csr.dmc_payload)
3274 intel_csr_load_program(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003275}
3276
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003277static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
3278{
3279 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3280 struct i915_power_well *well;
3281 u32 val;
3282
3283 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3284
3285 /* 1. Disable all display engine functions -> aready done */
3286
3287 /* 2. Disable DBUF */
3288 gen9_dbuf_disable(dev_priv);
3289
3290 /* 3. Disable CD clock */
3291 cnl_uninit_cdclk(dev_priv);
3292
Imre Deakb38131f2017-06-29 18:37:02 +03003293 /*
3294 * 4. Disable Power Well 1 (PG1).
3295 * The AUX IO power wells are toggled on demand, so they are already
3296 * disabled at this point.
3297 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003298 mutex_lock(&power_domains->lock);
3299 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3300 intel_power_well_disable(dev_priv, well);
3301 mutex_unlock(&power_domains->lock);
3302
Imre Deak846c6b22017-06-29 18:36:58 +03003303 usleep_range(10, 30); /* 10 us delay per Bspec */
3304
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003305 /* 5. Disable Comp */
3306 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03003307 val |= CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003308 I915_WRITE(CHICKEN_MISC_2, val);
3309}
3310
Paulo Zanoniad186f32018-02-05 13:40:43 -02003311static void icl_display_core_init(struct drm_i915_private *dev_priv,
3312 bool resume)
3313{
Imre Deak67ca07e2018-06-26 17:22:32 +03003314 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3315 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003316 enum port port;
3317 u32 val;
3318
3319 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3320
3321 /* 1. Enable PCH reset handshake. */
3322 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3323 val |= RESET_PCH_HANDSHAKE_ENABLE;
3324 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3325
3326 for (port = PORT_A; port <= PORT_B; port++) {
3327 /* 2. Enable DDI combo PHY comp. */
3328 val = I915_READ(ICL_PHY_MISC(port));
3329 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3330 I915_WRITE(ICL_PHY_MISC(port), val);
3331
3332 cnl_set_procmon_ref_values(dev_priv, port);
3333
3334 val = I915_READ(ICL_PORT_COMP_DW0(port));
3335 val |= COMP_INIT;
3336 I915_WRITE(ICL_PORT_COMP_DW0(port), val);
3337
3338 /* 3. Set power down enable. */
3339 val = I915_READ(ICL_PORT_CL_DW5(port));
3340 val |= CL_POWER_DOWN_ENABLE;
3341 I915_WRITE(ICL_PORT_CL_DW5(port), val);
3342 }
3343
Imre Deak67ca07e2018-06-26 17:22:32 +03003344 /*
3345 * 4. Enable Power Well 1 (PG1).
3346 * The AUX IO power wells will be enabled on demand.
3347 */
3348 mutex_lock(&power_domains->lock);
3349 well = lookup_power_well(dev_priv, ICL_DISP_PW_1);
3350 intel_power_well_enable(dev_priv, well);
3351 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003352
3353 /* 5. Enable CDCLK. */
3354 icl_init_cdclk(dev_priv);
3355
3356 /* 6. Enable DBUF. */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003357 icl_dbuf_enable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003358
3359 /* 7. Setup MBUS. */
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003360 icl_mbus_init(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003361}
3362
3363static void icl_display_core_uninit(struct drm_i915_private *dev_priv)
3364{
Imre Deak67ca07e2018-06-26 17:22:32 +03003365 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3366 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003367 enum port port;
3368 u32 val;
3369
3370 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3371
3372 /* 1. Disable all display engine functions -> aready done */
3373
3374 /* 2. Disable DBUF */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003375 icl_dbuf_disable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003376
3377 /* 3. Disable CD clock */
3378 icl_uninit_cdclk(dev_priv);
3379
Imre Deak67ca07e2018-06-26 17:22:32 +03003380 /*
3381 * 4. Disable Power Well 1 (PG1).
3382 * The AUX IO power wells are toggled on demand, so they are already
3383 * disabled at this point.
3384 */
3385 mutex_lock(&power_domains->lock);
3386 well = lookup_power_well(dev_priv, ICL_DISP_PW_1);
3387 intel_power_well_disable(dev_priv, well);
3388 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003389
3390 /* 5. Disable Comp */
3391 for (port = PORT_A; port <= PORT_B; port++) {
3392 val = I915_READ(ICL_PHY_MISC(port));
3393 val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3394 I915_WRITE(ICL_PHY_MISC(port), val);
3395 }
3396}
3397
Ville Syrjälä70722462015-04-10 18:21:28 +03003398static void chv_phy_control_init(struct drm_i915_private *dev_priv)
3399{
3400 struct i915_power_well *cmn_bc =
3401 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3402 struct i915_power_well *cmn_d =
3403 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
3404
3405 /*
3406 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
3407 * workaround never ever read DISPLAY_PHY_CONTROL, and
3408 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003409 * power well state and lane status to reconstruct the
3410 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03003411 */
3412 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03003413 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
3414 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003415 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
3416 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
3417 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
3418
3419 /*
3420 * If all lanes are disabled we leave the override disabled
3421 * with all power down bits cleared to match the state we
3422 * would use after disabling the port. Otherwise enable the
3423 * override and set the lane powerdown bits accding to the
3424 * current lane status.
3425 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003426 if (cmn_bc->desc->ops->is_enabled(dev_priv, cmn_bc)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003427 uint32_t status = I915_READ(DPLL(PIPE_A));
3428 unsigned int mask;
3429
3430 mask = status & DPLL_PORTB_READY_MASK;
3431 if (mask == 0xf)
3432 mask = 0x0;
3433 else
3434 dev_priv->chv_phy_control |=
3435 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
3436
3437 dev_priv->chv_phy_control |=
3438 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
3439
3440 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
3441 if (mask == 0xf)
3442 mask = 0x0;
3443 else
3444 dev_priv->chv_phy_control |=
3445 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
3446
3447 dev_priv->chv_phy_control |=
3448 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
3449
Ville Syrjälä70722462015-04-10 18:21:28 +03003450 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003451
3452 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
3453 } else {
3454 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003455 }
3456
Imre Deakf28ec6f2018-08-06 12:58:37 +03003457 if (cmn_d->desc->ops->is_enabled(dev_priv, cmn_d)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003458 uint32_t status = I915_READ(DPIO_PHY_STATUS);
3459 unsigned int mask;
3460
3461 mask = status & DPLL_PORTD_READY_MASK;
3462
3463 if (mask == 0xf)
3464 mask = 0x0;
3465 else
3466 dev_priv->chv_phy_control |=
3467 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
3468
3469 dev_priv->chv_phy_control |=
3470 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
3471
Ville Syrjälä70722462015-04-10 18:21:28 +03003472 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003473
3474 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
3475 } else {
3476 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003477 }
3478
3479 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
3480
3481 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
3482 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03003483}
3484
Daniel Vetter9c065a72014-09-30 10:56:38 +02003485static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
3486{
3487 struct i915_power_well *cmn =
3488 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3489 struct i915_power_well *disp2d =
3490 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
3491
Daniel Vetter9c065a72014-09-30 10:56:38 +02003492 /* If the display might be already active skip this */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003493 if (cmn->desc->ops->is_enabled(dev_priv, cmn) &&
3494 disp2d->desc->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003495 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3496 return;
3497
3498 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3499
3500 /* cmnlane needs DPLL registers */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003501 disp2d->desc->ops->enable(dev_priv, disp2d);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003502
3503 /*
3504 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3505 * Need to assert and de-assert PHY SB reset by gating the
3506 * common lane power, then un-gating it.
3507 * Simply ungating isn't enough to reset the PHY enough to get
3508 * ports and lanes running.
3509 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003510 cmn->desc->ops->disable(dev_priv, cmn);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003511}
3512
Daniel Vettere4e76842014-09-30 10:56:42 +02003513/**
3514 * intel_power_domains_init_hw - initialize hardware power domain state
3515 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003516 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003517 *
3518 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003519 * power wells belonging to the INIT power domain. Power wells in other
3520 * domains (and not in the INIT domain) are referenced or disabled during the
3521 * modeset state HW readout. After that the reference count of each power well
3522 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003523 */
Imre Deak73dfc222015-11-17 17:33:53 +02003524void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003525{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003526 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3527
3528 power_domains->initializing = true;
3529
Paulo Zanoniad186f32018-02-05 13:40:43 -02003530 if (IS_ICELAKE(dev_priv)) {
3531 icl_display_core_init(dev_priv, resume);
3532 } else if (IS_CANNONLAKE(dev_priv)) {
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003533 cnl_display_core_init(dev_priv, resume);
3534 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003535 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003536 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003537 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003538 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003539 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003540 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003541 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003542 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003543 mutex_lock(&power_domains->lock);
3544 vlv_cmnlane_wa(dev_priv);
3545 mutex_unlock(&power_domains->lock);
3546 }
3547
3548 /* For now, we need the power well to be always enabled. */
3549 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003550 /* Disable power support if the user asked so. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003551 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003552 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003553 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003554 power_domains->initializing = false;
3555}
3556
Daniel Vettere4e76842014-09-30 10:56:42 +02003557/**
Imre Deak48a287e2018-08-06 12:58:35 +03003558 * intel_power_domains_fini_hw - deinitialize hw power domain state
3559 * @dev_priv: i915 device instance
3560 *
3561 * De-initializes the display power domain HW state. It also ensures that the
3562 * device stays powered up so that the driver can be reloaded.
3563 */
3564void intel_power_domains_fini_hw(struct drm_i915_private *dev_priv)
3565{
3566 struct device *kdev = &dev_priv->drm.pdev->dev;
3567
3568 /*
3569 * The i915.ko module is still not prepared to be loaded when
3570 * the power well is not enabled, so just enable it in case
3571 * we're going to unload/reload.
3572 * The following also reacquires the RPM reference the core passed
3573 * to the driver during loading, which is dropped in
3574 * intel_runtime_pm_enable(). We have to hand back the control of the
3575 * device to the core with this reference held.
3576 */
3577 intel_display_set_init_power(dev_priv, true);
3578
3579 /* Remove the refcount we took to keep power well support disabled. */
3580 if (!i915_modparams.disable_power_well)
3581 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
3582
3583 /*
3584 * Remove the refcount we took in intel_runtime_pm_enable() in case
3585 * the platform doesn't support runtime PM.
3586 */
3587 if (!HAS_RUNTIME_PM(dev_priv))
3588 pm_runtime_put(kdev);
3589}
3590
3591/**
Imre Deak73dfc222015-11-17 17:33:53 +02003592 * intel_power_domains_suspend - suspend power domain state
3593 * @dev_priv: i915 device instance
3594 *
3595 * This function prepares the hardware power domain state before entering
3596 * system suspend. It must be paired with intel_power_domains_init_hw().
3597 */
3598void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3599{
Imre Deakd314cd42015-11-17 17:44:23 +02003600 /*
3601 * Even if power well support was disabled we still want to disable
3602 * power wells while we are system suspended.
3603 */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003604 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003605 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003606
Paulo Zanoniad186f32018-02-05 13:40:43 -02003607 if (IS_ICELAKE(dev_priv))
3608 icl_display_core_uninit(dev_priv);
3609 else if (IS_CANNONLAKE(dev_priv))
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003610 cnl_display_core_uninit(dev_priv);
3611 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003612 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003613 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003614 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003615}
3616
Imre Deak8d8c3862017-02-17 17:39:46 +02003617static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3618{
3619 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3620 struct i915_power_well *power_well;
3621
3622 for_each_power_well(dev_priv, power_well) {
3623 enum intel_display_power_domain domain;
3624
3625 DRM_DEBUG_DRIVER("%-25s %d\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003626 power_well->desc->name, power_well->count);
Imre Deak8d8c3862017-02-17 17:39:46 +02003627
Imre Deakf28ec6f2018-08-06 12:58:37 +03003628 for_each_power_domain(domain, power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003629 DRM_DEBUG_DRIVER(" %-23s %d\n",
3630 intel_display_power_domain_str(domain),
3631 power_domains->domain_use_count[domain]);
3632 }
3633}
3634
3635/**
3636 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3637 * @dev_priv: i915 device instance
3638 *
3639 * Verify if the reference count of each power well matches its HW enabled
3640 * state and the total refcount of the domains it belongs to. This must be
3641 * called after modeset HW state sanitization, which is responsible for
3642 * acquiring reference counts for any power wells in use and disabling the
3643 * ones left on by BIOS but not required by any active output.
3644 */
3645void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3646{
3647 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3648 struct i915_power_well *power_well;
3649 bool dump_domain_info;
3650
3651 mutex_lock(&power_domains->lock);
3652
3653 dump_domain_info = false;
3654 for_each_power_well(dev_priv, power_well) {
3655 enum intel_display_power_domain domain;
3656 int domains_count;
3657 bool enabled;
3658
3659 /*
3660 * Power wells not belonging to any domain (like the MISC_IO
3661 * and PW1 power wells) are under FW control, so ignore them,
3662 * since their state can change asynchronously.
3663 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003664 if (!power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003665 continue;
3666
Imre Deakf28ec6f2018-08-06 12:58:37 +03003667 enabled = power_well->desc->ops->is_enabled(dev_priv,
3668 power_well);
3669 if ((power_well->count || power_well->desc->always_on) !=
3670 enabled)
Imre Deak8d8c3862017-02-17 17:39:46 +02003671 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003672 power_well->desc->name,
3673 power_well->count, enabled);
Imre Deak8d8c3862017-02-17 17:39:46 +02003674
3675 domains_count = 0;
Imre Deakf28ec6f2018-08-06 12:58:37 +03003676 for_each_power_domain(domain, power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003677 domains_count += power_domains->domain_use_count[domain];
3678
3679 if (power_well->count != domains_count) {
3680 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3681 "(refcount %d/domains refcount %d)\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003682 power_well->desc->name, power_well->count,
Imre Deak8d8c3862017-02-17 17:39:46 +02003683 domains_count);
3684 dump_domain_info = true;
3685 }
3686 }
3687
3688 if (dump_domain_info) {
3689 static bool dumped;
3690
3691 if (!dumped) {
3692 intel_power_domains_dump_info(dev_priv);
3693 dumped = true;
3694 }
3695 }
3696
3697 mutex_unlock(&power_domains->lock);
3698}
3699
Imre Deak73dfc222015-11-17 17:33:53 +02003700/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003701 * intel_runtime_pm_get - grab a runtime pm reference
3702 * @dev_priv: i915 device instance
3703 *
3704 * This function grabs a device-level runtime pm reference (mostly used for GEM
3705 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3706 *
3707 * Any runtime pm reference obtained by this function must have a symmetric
3708 * call to intel_runtime_pm_put() to release the reference again.
3709 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003710void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3711{
David Weinehall52a05c32016-08-22 13:32:44 +03003712 struct pci_dev *pdev = dev_priv->drm.pdev;
3713 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003714 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003715
Imre Deakf5073822017-03-28 12:38:55 +03003716 ret = pm_runtime_get_sync(kdev);
3717 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003718
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003719 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003720 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003721}
3722
Daniel Vettere4e76842014-09-30 10:56:42 +02003723/**
Imre Deak09731282016-02-17 14:17:42 +02003724 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3725 * @dev_priv: i915 device instance
3726 *
3727 * This function grabs a device-level runtime pm reference if the device is
Chris Wilsonacb79142018-02-19 12:50:46 +00003728 * already in use and ensures that it is powered up. It is illegal to try
3729 * and access the HW should intel_runtime_pm_get_if_in_use() report failure.
Imre Deak09731282016-02-17 14:17:42 +02003730 *
3731 * Any runtime pm reference obtained by this function must have a symmetric
3732 * call to intel_runtime_pm_put() to release the reference again.
Chris Wilsonacb79142018-02-19 12:50:46 +00003733 *
3734 * Returns: True if the wakeref was acquired, or False otherwise.
Imre Deak09731282016-02-17 14:17:42 +02003735 */
3736bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3737{
Chris Wilson135dc792016-02-25 21:10:28 +00003738 if (IS_ENABLED(CONFIG_PM)) {
Chris Wilsonacb79142018-02-19 12:50:46 +00003739 struct pci_dev *pdev = dev_priv->drm.pdev;
3740 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003741
Chris Wilson135dc792016-02-25 21:10:28 +00003742 /*
3743 * In cases runtime PM is disabled by the RPM core and we get
3744 * an -EINVAL return value we are not supposed to call this
3745 * function, since the power state is undefined. This applies
3746 * atm to the late/early system suspend/resume handlers.
3747 */
Chris Wilsonacb79142018-02-19 12:50:46 +00003748 if (pm_runtime_get_if_in_use(kdev) <= 0)
Chris Wilson135dc792016-02-25 21:10:28 +00003749 return false;
3750 }
Imre Deak09731282016-02-17 14:17:42 +02003751
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003752 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deak09731282016-02-17 14:17:42 +02003753 assert_rpm_wakelock_held(dev_priv);
3754
3755 return true;
3756}
3757
3758/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003759 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3760 * @dev_priv: i915 device instance
3761 *
3762 * This function grabs a device-level runtime pm reference (mostly used for GEM
3763 * code to ensure the GTT or GT is on).
3764 *
3765 * It will _not_ power up the device but instead only check that it's powered
3766 * on. Therefore it is only valid to call this functions from contexts where
3767 * the device is known to be powered up and where trying to power it up would
3768 * result in hilarity and deadlocks. That pretty much means only the system
3769 * suspend/resume code where this is used to grab runtime pm references for
3770 * delayed setup down in work items.
3771 *
3772 * Any runtime pm reference obtained by this function must have a symmetric
3773 * call to intel_runtime_pm_put() to release the reference again.
3774 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003775void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3776{
David Weinehall52a05c32016-08-22 13:32:44 +03003777 struct pci_dev *pdev = dev_priv->drm.pdev;
3778 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003779
Imre Deakc9b88462015-12-15 20:10:34 +02003780 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003781 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003782
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003783 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003784}
3785
Daniel Vettere4e76842014-09-30 10:56:42 +02003786/**
3787 * intel_runtime_pm_put - release a runtime pm reference
3788 * @dev_priv: i915 device instance
3789 *
3790 * This function drops the device-level runtime pm reference obtained by
3791 * intel_runtime_pm_get() and might power down the corresponding
3792 * hardware block right away if this is the last reference.
3793 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003794void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3795{
David Weinehall52a05c32016-08-22 13:32:44 +03003796 struct pci_dev *pdev = dev_priv->drm.pdev;
3797 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003798
Imre Deak542db3c2015-12-15 20:10:36 +02003799 assert_rpm_wakelock_held(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003800 atomic_dec(&dev_priv->runtime_pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003801
David Weinehallc49d13e2016-08-22 13:32:42 +03003802 pm_runtime_mark_last_busy(kdev);
3803 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003804}
3805
Daniel Vettere4e76842014-09-30 10:56:42 +02003806/**
3807 * intel_runtime_pm_enable - enable runtime pm
3808 * @dev_priv: i915 device instance
3809 *
3810 * This function enables runtime pm at the end of the driver load sequence.
3811 *
3812 * Note that this function does currently not enable runtime pm for the
3813 * subordinate display power domains. That is only done on the first modeset
3814 * using intel_display_set_init_power().
3815 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003816void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003817{
David Weinehall52a05c32016-08-22 13:32:44 +03003818 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003819 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003820
David Weinehallc49d13e2016-08-22 13:32:42 +03003821 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3822 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003823
Imre Deak25b181b2015-12-17 13:44:56 +02003824 /*
3825 * Take a permanent reference to disable the RPM functionality and drop
3826 * it only when unloading the driver. Use the low level get/put helpers,
3827 * so the driver's own RPM reference tracking asserts also work on
3828 * platforms without RPM support.
3829 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003830 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003831 int ret;
3832
David Weinehallc49d13e2016-08-22 13:32:42 +03003833 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003834 ret = pm_runtime_get_sync(kdev);
3835 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003836 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003837 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003838 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003839
Imre Deakaabee1b2015-12-15 20:10:29 +02003840 /*
3841 * The core calls the driver load handler with an RPM reference held.
3842 * We drop that here and will reacquire it during unloading in
3843 * intel_power_domains_fini().
3844 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003845 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003846}