blob: bcdf04847b49e7923cb3af392a5a9d4372c48427 [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 Deakd13dd052018-08-06 12:58:38 +0300875 int pw_idx = power_well->desc->vlv.idx;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200876 u32 mask;
877 u32 state;
878 u32 ctrl;
879
Imre Deakd13dd052018-08-06 12:58:38 +0300880 mask = PUNIT_PWRGT_MASK(pw_idx);
881 state = enable ? PUNIT_PWRGT_PWR_ON(pw_idx) :
882 PUNIT_PWRGT_PWR_GATE(pw_idx);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200883
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 Deakd13dd052018-08-06 12:58:38 +0300923 int pw_idx = power_well->desc->vlv.idx;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200924 bool enabled = false;
925 u32 mask;
926 u32 state;
927 u32 ctrl;
928
Imre Deakd13dd052018-08-06 12:58:38 +0300929 mask = PUNIT_PWRGT_MASK(pw_idx);
930 ctrl = PUNIT_PWRGT_PWR_ON(pw_idx);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200931
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 */
Imre Deakd13dd052018-08-06 12:58:38 +0300939 WARN_ON(state != PUNIT_PWRGT_PWR_ON(pw_idx) &&
940 state != PUNIT_PWRGT_PWR_GATE(pw_idx));
Daniel Vetter9c065a72014-09-30 10:56:38 +0200941 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,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002182 .ops = &vlv_display_power_well_ops,
Imre Deakd13dd052018-08-06 12:58:38 +03002183 .id = PUNIT_POWER_WELL_DISP2D,
2184 {
2185 .vlv.idx = PUNIT_PWGT_IDX_DISP2D,
2186 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002187 },
2188 {
2189 .name = "dpio-tx-b-01",
2190 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2191 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2192 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2193 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2194 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002195 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Imre Deakd13dd052018-08-06 12:58:38 +03002196 {
2197 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_B_LANES_01,
2198 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002199 },
2200 {
2201 .name = "dpio-tx-b-23",
2202 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2203 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2204 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2205 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2206 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002207 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Imre Deakd13dd052018-08-06 12:58:38 +03002208 {
2209 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_B_LANES_23,
2210 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002211 },
2212 {
2213 .name = "dpio-tx-c-01",
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_01,
Imre Deakd13dd052018-08-06 12:58:38 +03002220 {
2221 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_C_LANES_01,
2222 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002223 },
2224 {
2225 .name = "dpio-tx-c-23",
2226 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2227 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2228 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2229 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2230 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002231 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Imre Deakd13dd052018-08-06 12:58:38 +03002232 {
2233 .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_C_LANES_23,
2234 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002235 },
2236 {
2237 .name = "dpio-common",
2238 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002239 .ops = &vlv_dpio_cmn_power_well_ops,
Imre Deakd13dd052018-08-06 12:58:38 +03002240 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
2241 {
2242 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_BC,
2243 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002244 },
2245};
2246
Imre Deakf28ec6f2018-08-06 12:58:37 +03002247static const struct i915_power_well_desc chv_power_wells[] = {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002248 {
2249 .name = "always-on",
2250 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002251 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002252 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002253 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002254 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002255 {
2256 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002257 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002258 * Pipe A power well is the new disp2d well. Pipe B and C
2259 * power wells don't actually exist. Pipe A power well is
2260 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002261 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002262 .domains = CHV_DISPLAY_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002263 .ops = &chv_pipe_power_well_ops,
Imre Deakd13dd052018-08-06 12:58:38 +03002264 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002265 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002266 {
2267 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002268 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002269 .ops = &chv_dpio_cmn_power_well_ops,
Imre Deakd13dd052018-08-06 12:58:38 +03002270 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
2271 {
2272 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_BC,
2273 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002274 },
2275 {
2276 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002277 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002278 .ops = &chv_dpio_cmn_power_well_ops,
Imre Deakd13dd052018-08-06 12:58:38 +03002279 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
2280 {
2281 .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_D,
2282 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002283 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002284};
2285
Suketu Shah5aefb232015-04-16 14:22:10 +05302286bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002287 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302288{
2289 struct i915_power_well *power_well;
2290 bool ret;
2291
2292 power_well = lookup_power_well(dev_priv, power_well_id);
Imre Deakf28ec6f2018-08-06 12:58:37 +03002293 ret = power_well->desc->ops->is_enabled(dev_priv, power_well);
Suketu Shah5aefb232015-04-16 14:22:10 +05302294
2295 return ret;
2296}
2297
Imre Deakf28ec6f2018-08-06 12:58:37 +03002298static const struct i915_power_well_desc skl_power_wells[] = {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002299 {
2300 .name = "always-on",
2301 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002302 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002303 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002304 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002305 },
2306 {
2307 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002308 /* Handled by the DMC firmware */
2309 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002310 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002311 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002312 {
2313 .hsw.has_fuses = true,
2314 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002315 },
2316 {
2317 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002318 /* Handled by the DMC firmware */
2319 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002320 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002321 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002322 },
2323 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002324 .name = "DC off",
2325 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2326 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002327 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002328 },
2329 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002330 .name = "power well 2",
2331 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002332 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002333 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002334 {
2335 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2336 .hsw.has_vga = true,
2337 .hsw.has_fuses = true,
2338 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002339 },
2340 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002341 .name = "DDI A/E IO power well",
2342 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002343 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002344 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002345 },
2346 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002347 .name = "DDI B IO power well",
2348 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002349 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002350 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002351 },
2352 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002353 .name = "DDI C IO power well",
2354 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002355 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002356 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002357 },
2358 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002359 .name = "DDI D IO power well",
2360 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002361 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002362 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002363 },
2364};
2365
Imre Deakf28ec6f2018-08-06 12:58:37 +03002366static const struct i915_power_well_desc bxt_power_wells[] = {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302367 {
2368 .name = "always-on",
2369 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002370 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302371 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002372 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302373 },
2374 {
2375 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002376 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002377 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002378 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002379 {
2380 .hsw.has_fuses = true,
2381 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302382 },
2383 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002384 .name = "DC off",
2385 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2386 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002387 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002388 },
2389 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302390 .name = "power well 2",
2391 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002392 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002393 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002394 {
2395 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2396 .hsw.has_vga = true,
2397 .hsw.has_fuses = true,
2398 },
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002399 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002400 {
2401 .name = "dpio-common-a",
2402 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2403 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002404 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002405 {
2406 .bxt.phy = DPIO_PHY1,
2407 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002408 },
2409 {
2410 .name = "dpio-common-bc",
2411 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2412 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002413 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002414 {
2415 .bxt.phy = DPIO_PHY0,
2416 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002417 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302418};
2419
Imre Deakf28ec6f2018-08-06 12:58:37 +03002420static const struct i915_power_well_desc glk_power_wells[] = {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002421 {
2422 .name = "always-on",
2423 .always_on = 1,
2424 .domains = POWER_DOMAIN_MASK,
2425 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002426 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002427 },
2428 {
2429 .name = "power well 1",
2430 /* Handled by the DMC firmware */
2431 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002432 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002433 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002434 {
2435 .hsw.has_fuses = true,
2436 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002437 },
2438 {
2439 .name = "DC off",
2440 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2441 .ops = &gen9_dc_off_power_well_ops,
2442 .id = SKL_DISP_PW_DC_OFF,
2443 },
2444 {
2445 .name = "power well 2",
2446 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002447 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002448 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002449 {
2450 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2451 .hsw.has_vga = true,
2452 .hsw.has_fuses = true,
2453 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002454 },
2455 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002456 .name = "dpio-common-a",
2457 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2458 .ops = &bxt_dpio_cmn_power_well_ops,
2459 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002460 {
2461 .bxt.phy = DPIO_PHY1,
2462 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002463 },
2464 {
2465 .name = "dpio-common-b",
2466 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2467 .ops = &bxt_dpio_cmn_power_well_ops,
2468 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002469 {
2470 .bxt.phy = DPIO_PHY0,
2471 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002472 },
2473 {
2474 .name = "dpio-common-c",
2475 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2476 .ops = &bxt_dpio_cmn_power_well_ops,
2477 .id = GLK_DPIO_CMN_C,
Imre Deak0a445942017-08-14 18:15:29 +03002478 {
2479 .bxt.phy = DPIO_PHY2,
2480 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002481 },
2482 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002483 .name = "AUX A",
2484 .domains = GLK_DISPLAY_AUX_A_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 = GLK_DISP_PW_AUX_A,
2487 },
2488 {
2489 .name = "AUX B",
2490 .domains = GLK_DISPLAY_AUX_B_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 = GLK_DISP_PW_AUX_B,
2493 },
2494 {
2495 .name = "AUX C",
2496 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002497 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002498 .id = GLK_DISP_PW_AUX_C,
2499 },
2500 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002501 .name = "DDI A IO power well",
2502 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002503 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002504 .id = GLK_DISP_PW_DDI_A,
2505 },
2506 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002507 .name = "DDI B IO power well",
2508 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002509 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002510 .id = SKL_DISP_PW_DDI_B,
2511 },
2512 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002513 .name = "DDI C IO power well",
2514 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002515 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002516 .id = SKL_DISP_PW_DDI_C,
2517 },
2518};
2519
Imre Deakf28ec6f2018-08-06 12:58:37 +03002520static const struct i915_power_well_desc cnl_power_wells[] = {
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002521 {
2522 .name = "always-on",
2523 .always_on = 1,
2524 .domains = POWER_DOMAIN_MASK,
2525 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002526 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002527 },
2528 {
2529 .name = "power well 1",
2530 /* Handled by the DMC firmware */
2531 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002532 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002533 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002534 {
2535 .hsw.has_fuses = true,
2536 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002537 },
2538 {
2539 .name = "AUX A",
2540 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002541 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002542 .id = CNL_DISP_PW_AUX_A,
2543 },
2544 {
2545 .name = "AUX B",
2546 .domains = CNL_DISPLAY_AUX_B_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 = CNL_DISP_PW_AUX_B,
2549 },
2550 {
2551 .name = "AUX C",
2552 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002553 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002554 .id = CNL_DISP_PW_AUX_C,
2555 },
2556 {
2557 .name = "AUX D",
2558 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002559 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002560 .id = CNL_DISP_PW_AUX_D,
2561 },
2562 {
2563 .name = "DC off",
2564 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2565 .ops = &gen9_dc_off_power_well_ops,
2566 .id = SKL_DISP_PW_DC_OFF,
2567 },
2568 {
2569 .name = "power well 2",
2570 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002571 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002572 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002573 {
2574 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2575 .hsw.has_vga = true,
2576 .hsw.has_fuses = true,
2577 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002578 },
2579 {
2580 .name = "DDI A IO power well",
2581 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002582 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002583 .id = CNL_DISP_PW_DDI_A,
2584 },
2585 {
2586 .name = "DDI B IO power well",
2587 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002588 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002589 .id = SKL_DISP_PW_DDI_B,
2590 },
2591 {
2592 .name = "DDI C IO power well",
2593 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002594 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002595 .id = SKL_DISP_PW_DDI_C,
2596 },
2597 {
2598 .name = "DDI D IO power well",
2599 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002600 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002601 .id = SKL_DISP_PW_DDI_D,
2602 },
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002603 {
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002604 .name = "DDI F IO power well",
2605 .domains = CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS,
2606 .ops = &hsw_power_well_ops,
2607 .id = CNL_DISP_PW_DDI_F,
2608 },
2609 {
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002610 .name = "AUX F",
2611 .domains = CNL_DISPLAY_AUX_F_POWER_DOMAINS,
2612 .ops = &hsw_power_well_ops,
2613 .id = CNL_DISP_PW_AUX_F,
2614 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002615};
2616
Imre Deak67ca07e2018-06-26 17:22:32 +03002617static const struct i915_power_well_ops icl_combo_phy_aux_power_well_ops = {
2618 .sync_hw = hsw_power_well_sync_hw,
2619 .enable = icl_combo_phy_aux_power_well_enable,
2620 .disable = icl_combo_phy_aux_power_well_disable,
2621 .is_enabled = hsw_power_well_enabled,
2622};
2623
Imre Deakf28ec6f2018-08-06 12:58:37 +03002624static const struct i915_power_well_desc icl_power_wells[] = {
Imre Deak67ca07e2018-06-26 17:22:32 +03002625 {
2626 .name = "always-on",
2627 .always_on = 1,
2628 .domains = POWER_DOMAIN_MASK,
2629 .ops = &i9xx_always_on_power_well_ops,
2630 .id = I915_DISP_PW_ALWAYS_ON,
2631 },
2632 {
2633 .name = "power well 1",
2634 /* Handled by the DMC firmware */
2635 .domains = 0,
2636 .ops = &hsw_power_well_ops,
2637 .id = ICL_DISP_PW_1,
Imre Deakae9b06c2018-08-06 12:58:34 +03002638 {
2639 .hsw.has_fuses = true,
2640 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002641 },
2642 {
2643 .name = "power well 2",
2644 .domains = ICL_PW_2_POWER_DOMAINS,
2645 .ops = &hsw_power_well_ops,
2646 .id = ICL_DISP_PW_2,
Imre Deakae9b06c2018-08-06 12:58:34 +03002647 {
2648 .hsw.has_fuses = true,
2649 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002650 },
2651 {
2652 .name = "DC off",
2653 .domains = ICL_DISPLAY_DC_OFF_POWER_DOMAINS,
2654 .ops = &gen9_dc_off_power_well_ops,
2655 .id = SKL_DISP_PW_DC_OFF,
2656 },
2657 {
2658 .name = "power well 3",
2659 .domains = ICL_PW_3_POWER_DOMAINS,
2660 .ops = &hsw_power_well_ops,
2661 .id = ICL_DISP_PW_3,
Imre Deakae9b06c2018-08-06 12:58:34 +03002662 {
2663 .hsw.irq_pipe_mask = BIT(PIPE_B),
2664 .hsw.has_vga = true,
2665 .hsw.has_fuses = true,
2666 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002667 },
2668 {
2669 .name = "DDI A IO",
2670 .domains = ICL_DDI_IO_A_POWER_DOMAINS,
2671 .ops = &hsw_power_well_ops,
2672 .id = ICL_DISP_PW_DDI_A,
2673 },
2674 {
2675 .name = "DDI B IO",
2676 .domains = ICL_DDI_IO_B_POWER_DOMAINS,
2677 .ops = &hsw_power_well_ops,
2678 .id = ICL_DISP_PW_DDI_B,
2679 },
2680 {
2681 .name = "DDI C IO",
2682 .domains = ICL_DDI_IO_C_POWER_DOMAINS,
2683 .ops = &hsw_power_well_ops,
2684 .id = ICL_DISP_PW_DDI_C,
2685 },
2686 {
2687 .name = "DDI D IO",
2688 .domains = ICL_DDI_IO_D_POWER_DOMAINS,
2689 .ops = &hsw_power_well_ops,
2690 .id = ICL_DISP_PW_DDI_D,
2691 },
2692 {
2693 .name = "DDI E IO",
2694 .domains = ICL_DDI_IO_E_POWER_DOMAINS,
2695 .ops = &hsw_power_well_ops,
2696 .id = ICL_DISP_PW_DDI_E,
2697 },
2698 {
2699 .name = "DDI F IO",
2700 .domains = ICL_DDI_IO_F_POWER_DOMAINS,
2701 .ops = &hsw_power_well_ops,
2702 .id = ICL_DISP_PW_DDI_F,
2703 },
2704 {
2705 .name = "AUX A",
2706 .domains = ICL_AUX_A_IO_POWER_DOMAINS,
2707 .ops = &icl_combo_phy_aux_power_well_ops,
2708 .id = ICL_DISP_PW_AUX_A,
2709 },
2710 {
2711 .name = "AUX B",
2712 .domains = ICL_AUX_B_IO_POWER_DOMAINS,
2713 .ops = &icl_combo_phy_aux_power_well_ops,
2714 .id = ICL_DISP_PW_AUX_B,
2715 },
2716 {
2717 .name = "AUX C",
2718 .domains = ICL_AUX_C_IO_POWER_DOMAINS,
2719 .ops = &hsw_power_well_ops,
2720 .id = ICL_DISP_PW_AUX_C,
2721 },
2722 {
2723 .name = "AUX D",
2724 .domains = ICL_AUX_D_IO_POWER_DOMAINS,
2725 .ops = &hsw_power_well_ops,
2726 .id = ICL_DISP_PW_AUX_D,
2727 },
2728 {
2729 .name = "AUX E",
2730 .domains = ICL_AUX_E_IO_POWER_DOMAINS,
2731 .ops = &hsw_power_well_ops,
2732 .id = ICL_DISP_PW_AUX_E,
2733 },
2734 {
2735 .name = "AUX F",
2736 .domains = ICL_AUX_F_IO_POWER_DOMAINS,
2737 .ops = &hsw_power_well_ops,
2738 .id = ICL_DISP_PW_AUX_F,
2739 },
2740 {
2741 .name = "AUX TBT1",
2742 .domains = ICL_AUX_TBT1_IO_POWER_DOMAINS,
2743 .ops = &hsw_power_well_ops,
2744 .id = ICL_DISP_PW_AUX_TBT1,
2745 },
2746 {
2747 .name = "AUX TBT2",
2748 .domains = ICL_AUX_TBT2_IO_POWER_DOMAINS,
2749 .ops = &hsw_power_well_ops,
2750 .id = ICL_DISP_PW_AUX_TBT2,
2751 },
2752 {
2753 .name = "AUX TBT3",
2754 .domains = ICL_AUX_TBT3_IO_POWER_DOMAINS,
2755 .ops = &hsw_power_well_ops,
2756 .id = ICL_DISP_PW_AUX_TBT3,
2757 },
2758 {
2759 .name = "AUX TBT4",
2760 .domains = ICL_AUX_TBT4_IO_POWER_DOMAINS,
2761 .ops = &hsw_power_well_ops,
2762 .id = ICL_DISP_PW_AUX_TBT4,
2763 },
2764 {
2765 .name = "power well 4",
2766 .domains = ICL_PW_4_POWER_DOMAINS,
2767 .ops = &hsw_power_well_ops,
2768 .id = ICL_DISP_PW_4,
Imre Deakae9b06c2018-08-06 12:58:34 +03002769 {
2770 .hsw.has_fuses = true,
2771 .hsw.irq_pipe_mask = BIT(PIPE_C),
2772 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002773 },
2774};
2775
Imre Deak1b0e3a02015-11-05 23:04:11 +02002776static int
2777sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2778 int disable_power_well)
2779{
2780 if (disable_power_well >= 0)
2781 return !!disable_power_well;
2782
Imre Deak1b0e3a02015-11-05 23:04:11 +02002783 return 1;
2784}
2785
Imre Deaka37baf32016-02-29 22:49:03 +02002786static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2787 int enable_dc)
2788{
2789 uint32_t mask;
2790 int requested_dc;
2791 int max_dc;
2792
Imre Deak67ca07e2018-06-26 17:22:32 +03002793 if (IS_GEN9_BC(dev_priv) || INTEL_INFO(dev_priv)->gen >= 10) {
Imre Deaka37baf32016-02-29 22:49:03 +02002794 max_dc = 2;
2795 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002796 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002797 max_dc = 1;
2798 /*
2799 * DC9 has a separate HW flow from the rest of the DC states,
2800 * not depending on the DMC firmware. It's needed by system
2801 * suspend/resume, so allow it unconditionally.
2802 */
2803 mask = DC_STATE_EN_DC9;
2804 } else {
2805 max_dc = 0;
2806 mask = 0;
2807 }
2808
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002809 if (!i915_modparams.disable_power_well)
Imre Deak66e2c4c2016-02-29 22:49:04 +02002810 max_dc = 0;
2811
Imre Deaka37baf32016-02-29 22:49:03 +02002812 if (enable_dc >= 0 && enable_dc <= max_dc) {
2813 requested_dc = enable_dc;
2814 } else if (enable_dc == -1) {
2815 requested_dc = max_dc;
2816 } else if (enable_dc > max_dc && enable_dc <= 2) {
2817 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2818 enable_dc, max_dc);
2819 requested_dc = max_dc;
2820 } else {
2821 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2822 requested_dc = max_dc;
2823 }
2824
2825 if (requested_dc > 1)
2826 mask |= DC_STATE_EN_UPTO_DC6;
2827 if (requested_dc > 0)
2828 mask |= DC_STATE_EN_UPTO_DC5;
2829
2830 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2831
2832 return mask;
2833}
2834
Imre Deakf28ec6f2018-08-06 12:58:37 +03002835static int
2836__set_power_wells(struct i915_power_domains *power_domains,
2837 const struct i915_power_well_desc *power_well_descs,
2838 int power_well_count)
Imre Deak21792c62017-07-11 23:42:33 +03002839{
Imre Deakf28ec6f2018-08-06 12:58:37 +03002840 u64 power_well_ids = 0;
Imre Deak21792c62017-07-11 23:42:33 +03002841 int i;
2842
Imre Deakf28ec6f2018-08-06 12:58:37 +03002843 power_domains->power_well_count = power_well_count;
2844 power_domains->power_wells =
2845 kcalloc(power_well_count,
2846 sizeof(*power_domains->power_wells),
2847 GFP_KERNEL);
2848 if (!power_domains->power_wells)
2849 return -ENOMEM;
2850
2851 for (i = 0; i < power_well_count; i++) {
2852 enum i915_power_well_id id = power_well_descs[i].id;
2853
2854 power_domains->power_wells[i].desc = &power_well_descs[i];
Imre Deak21792c62017-07-11 23:42:33 +03002855
2856 WARN_ON(id >= sizeof(power_well_ids) * 8);
2857 WARN_ON(power_well_ids & BIT_ULL(id));
2858 power_well_ids |= BIT_ULL(id);
2859 }
Imre Deakf28ec6f2018-08-06 12:58:37 +03002860
2861 return 0;
Imre Deak21792c62017-07-11 23:42:33 +03002862}
2863
Imre Deakf28ec6f2018-08-06 12:58:37 +03002864#define set_power_wells(power_domains, __power_well_descs) \
2865 __set_power_wells(power_domains, __power_well_descs, \
2866 ARRAY_SIZE(__power_well_descs))
Daniel Vetter9c065a72014-09-30 10:56:38 +02002867
Daniel Vettere4e76842014-09-30 10:56:42 +02002868/**
2869 * intel_power_domains_init - initializes the power domain structures
2870 * @dev_priv: i915 device instance
2871 *
2872 * Initializes the power domain structures for @dev_priv depending upon the
2873 * supported platform.
2874 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002875int intel_power_domains_init(struct drm_i915_private *dev_priv)
2876{
2877 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deakf28ec6f2018-08-06 12:58:37 +03002878 int err;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002879
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002880 i915_modparams.disable_power_well =
2881 sanitize_disable_power_well_option(dev_priv,
2882 i915_modparams.disable_power_well);
2883 dev_priv->csr.allowed_dc_mask =
2884 get_allowed_dc_mask(dev_priv, i915_modparams.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002885
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002886 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002887
Daniel Vetter9c065a72014-09-30 10:56:38 +02002888 mutex_init(&power_domains->lock);
2889
2890 /*
2891 * The enabling order will be from lower to higher indexed wells,
2892 * the disabling order is reversed.
2893 */
Imre Deak67ca07e2018-06-26 17:22:32 +03002894 if (IS_ICELAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002895 err = set_power_wells(power_domains, icl_power_wells);
Imre Deak67ca07e2018-06-26 17:22:32 +03002896 } else if (IS_HASWELL(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002897 err = set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002898 } else if (IS_BROADWELL(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002899 err = set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002900 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002901 err = set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002902 } else if (IS_CANNONLAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002903 err = set_power_wells(power_domains, cnl_power_wells);
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002904
2905 /*
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002906 * DDI and Aux IO are getting enabled for all ports
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002907 * regardless the presence or use. So, in order to avoid
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002908 * timeouts, lets remove them from the list
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002909 * for the SKUs without port F.
2910 */
2911 if (!IS_CNL_WITH_PORT_F(dev_priv))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002912 power_domains->power_well_count -= 2;
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002913
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002914 } else if (IS_BROXTON(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002915 err = set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002916 } else if (IS_GEMINILAKE(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002917 err = set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002918 } else if (IS_CHERRYVIEW(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002919 err = set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002920 } else if (IS_VALLEYVIEW(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002921 err = set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002922 } else if (IS_I830(dev_priv)) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002923 err = set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002924 } else {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002925 err = set_power_wells(power_domains, i9xx_always_on_power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002926 }
2927
Imre Deakf28ec6f2018-08-06 12:58:37 +03002928 return err;
2929}
Imre Deak21792c62017-07-11 23:42:33 +03002930
Imre Deakf28ec6f2018-08-06 12:58:37 +03002931/**
2932 * intel_power_domains_cleanup - clean up power domains resources
2933 * @dev_priv: i915 device instance
2934 *
2935 * Release any resources acquired by intel_power_domains_init()
2936 */
2937void intel_power_domains_cleanup(struct drm_i915_private *dev_priv)
2938{
2939 kfree(dev_priv->power_domains.power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002940}
2941
Imre Deak30eade12015-11-04 19:24:13 +02002942static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002943{
2944 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2945 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002946
2947 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002948 for_each_power_well(dev_priv, power_well) {
Imre Deakf28ec6f2018-08-06 12:58:37 +03002949 power_well->desc->ops->sync_hw(dev_priv, power_well);
2950 power_well->hw_enabled =
2951 power_well->desc->ops->is_enabled(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002952 }
2953 mutex_unlock(&power_domains->lock);
2954}
2955
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302956static inline
2957bool intel_dbuf_slice_set(struct drm_i915_private *dev_priv,
2958 i915_reg_t reg, bool enable)
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002959{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302960 u32 val, status;
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002961
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302962 val = I915_READ(reg);
2963 val = enable ? (val | DBUF_POWER_REQUEST) : (val & ~DBUF_POWER_REQUEST);
2964 I915_WRITE(reg, val);
2965 POSTING_READ(reg);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002966 udelay(10);
2967
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302968 status = I915_READ(reg) & DBUF_POWER_STATE;
2969 if ((enable && !status) || (!enable && status)) {
2970 DRM_ERROR("DBus power %s timeout!\n",
2971 enable ? "enable" : "disable");
2972 return false;
2973 }
2974 return true;
2975}
2976
2977static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2978{
2979 intel_dbuf_slice_set(dev_priv, DBUF_CTL, true);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002980}
2981
2982static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2983{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302984 intel_dbuf_slice_set(dev_priv, DBUF_CTL, false);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002985}
2986
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302987static u8 intel_dbuf_max_slices(struct drm_i915_private *dev_priv)
2988{
2989 if (INTEL_GEN(dev_priv) < 11)
2990 return 1;
2991 return 2;
2992}
2993
2994void icl_dbuf_slices_update(struct drm_i915_private *dev_priv,
2995 u8 req_slices)
2996{
2997 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
2998 u32 val;
2999 bool ret;
3000
3001 if (req_slices > intel_dbuf_max_slices(dev_priv)) {
3002 DRM_ERROR("Invalid number of dbuf slices requested\n");
3003 return;
3004 }
3005
3006 if (req_slices == hw_enabled_slices || req_slices == 0)
3007 return;
3008
3009 val = I915_READ(DBUF_CTL_S2);
3010 if (req_slices > hw_enabled_slices)
3011 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, true);
3012 else
3013 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, false);
3014
3015 if (ret)
3016 dev_priv->wm.skl_hw.ddb.enabled_slices = req_slices;
3017}
3018
Mahesh Kumar746edf82018-02-05 13:40:44 -02003019static void icl_dbuf_enable(struct drm_i915_private *dev_priv)
3020{
3021 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) | DBUF_POWER_REQUEST);
3022 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) | DBUF_POWER_REQUEST);
3023 POSTING_READ(DBUF_CTL_S2);
3024
3025 udelay(10);
3026
3027 if (!(I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
3028 !(I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
3029 DRM_ERROR("DBuf power enable timeout\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303030 else
3031 dev_priv->wm.skl_hw.ddb.enabled_slices = 2;
Mahesh Kumar746edf82018-02-05 13:40:44 -02003032}
3033
3034static void icl_dbuf_disable(struct drm_i915_private *dev_priv)
3035{
3036 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) & ~DBUF_POWER_REQUEST);
3037 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) & ~DBUF_POWER_REQUEST);
3038 POSTING_READ(DBUF_CTL_S2);
3039
3040 udelay(10);
3041
3042 if ((I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
3043 (I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
3044 DRM_ERROR("DBuf power disable timeout!\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303045 else
3046 dev_priv->wm.skl_hw.ddb.enabled_slices = 0;
Mahesh Kumar746edf82018-02-05 13:40:44 -02003047}
3048
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003049static void icl_mbus_init(struct drm_i915_private *dev_priv)
3050{
3051 uint32_t val;
3052
3053 val = MBUS_ABOX_BT_CREDIT_POOL1(16) |
3054 MBUS_ABOX_BT_CREDIT_POOL2(16) |
3055 MBUS_ABOX_B_CREDIT(1) |
3056 MBUS_ABOX_BW_CREDIT(1);
3057
3058 I915_WRITE(MBUS_ABOX_CTL, val);
3059}
3060
Imre Deak73dfc222015-11-17 17:33:53 +02003061static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03003062 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02003063{
3064 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003065 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003066 uint32_t val;
3067
Imre Deakd26fa1d2015-11-04 19:24:17 +02003068 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3069
Imre Deak73dfc222015-11-17 17:33:53 +02003070 /* enable PCH reset handshake */
3071 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3072 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
3073
3074 /* enable PG1 and Misc I/O */
3075 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003076
3077 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3078 intel_power_well_enable(dev_priv, well);
3079
3080 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
3081 intel_power_well_enable(dev_priv, well);
3082
Imre Deak73dfc222015-11-17 17:33:53 +02003083 mutex_unlock(&power_domains->lock);
3084
Imre Deak73dfc222015-11-17 17:33:53 +02003085 skl_init_cdclk(dev_priv);
3086
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003087 gen9_dbuf_enable(dev_priv);
3088
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03003089 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02003090 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003091}
3092
3093static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
3094{
3095 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003096 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003097
Imre Deakd26fa1d2015-11-04 19:24:17 +02003098 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3099
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003100 gen9_dbuf_disable(dev_priv);
3101
Imre Deak73dfc222015-11-17 17:33:53 +02003102 skl_uninit_cdclk(dev_priv);
3103
3104 /* The spec doesn't call for removing the reset handshake flag */
3105 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03003106
Imre Deak73dfc222015-11-17 17:33:53 +02003107 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003108
Imre Deakedfda8e2017-06-29 18:36:59 +03003109 /*
3110 * BSpec says to keep the MISC IO power well enabled here, only
3111 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03003112 * Note that even though the driver's request is removed power well 1
3113 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03003114 */
Imre Deak443a93a2016-04-04 15:42:57 +03003115 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3116 intel_power_well_disable(dev_priv, well);
3117
Imre Deak73dfc222015-11-17 17:33:53 +02003118 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003119
3120 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02003121}
3122
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003123void bxt_display_core_init(struct drm_i915_private *dev_priv,
3124 bool resume)
3125{
3126 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3127 struct i915_power_well *well;
3128 uint32_t val;
3129
3130 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3131
3132 /*
3133 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
3134 * or else the reset will hang because there is no PCH to respond.
3135 * Move the handshake programming to initialization sequence.
3136 * Previously was left up to BIOS.
3137 */
3138 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3139 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
3140 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3141
3142 /* Enable PG1 */
3143 mutex_lock(&power_domains->lock);
3144
3145 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3146 intel_power_well_enable(dev_priv, well);
3147
3148 mutex_unlock(&power_domains->lock);
3149
Imre Deak324513c2016-06-13 16:44:36 +03003150 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003151
3152 gen9_dbuf_enable(dev_priv);
3153
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003154 if (resume && dev_priv->csr.dmc_payload)
3155 intel_csr_load_program(dev_priv);
3156}
3157
3158void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
3159{
3160 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3161 struct i915_power_well *well;
3162
3163 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3164
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003165 gen9_dbuf_disable(dev_priv);
3166
Imre Deak324513c2016-06-13 16:44:36 +03003167 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003168
3169 /* The spec doesn't call for removing the reset handshake flag */
3170
Imre Deak42d93662017-06-29 18:37:01 +03003171 /*
3172 * Disable PW1 (PG1).
3173 * Note that even though the driver's request is removed power well 1
3174 * may stay enabled after this due to DMC's own request on it.
3175 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003176 mutex_lock(&power_domains->lock);
3177
3178 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3179 intel_power_well_disable(dev_priv, well);
3180
3181 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003182
3183 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003184}
3185
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003186enum {
3187 PROCMON_0_85V_DOT_0,
3188 PROCMON_0_95V_DOT_0,
3189 PROCMON_0_95V_DOT_1,
3190 PROCMON_1_05V_DOT_0,
3191 PROCMON_1_05V_DOT_1,
3192};
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003193
3194static const struct cnl_procmon {
3195 u32 dw1, dw9, dw10;
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003196} cnl_procmon_values[] = {
3197 [PROCMON_0_85V_DOT_0] =
3198 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
3199 [PROCMON_0_95V_DOT_0] =
3200 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
3201 [PROCMON_0_95V_DOT_1] =
3202 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
3203 [PROCMON_1_05V_DOT_0] =
3204 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
3205 [PROCMON_1_05V_DOT_1] =
3206 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003207};
3208
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003209/*
3210 * CNL has just one set of registers, while ICL has two sets: one for port A and
3211 * the other for port B. The CNL registers are equivalent to the ICL port A
3212 * registers, that's why we call the ICL macros even though the function has CNL
3213 * on its name.
3214 */
3215static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
3216 enum port port)
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003217{
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003218 const struct cnl_procmon *procmon;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003219 u32 val;
3220
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003221 val = I915_READ(ICL_PORT_COMP_DW3(port));
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003222 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
3223 default:
3224 MISSING_CASE(val);
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05003225 /* fall through */
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003226 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
3227 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
3228 break;
3229 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
3230 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
3231 break;
3232 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
3233 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
3234 break;
3235 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
3236 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
3237 break;
3238 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
3239 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
3240 break;
3241 }
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003242
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003243 val = I915_READ(ICL_PORT_COMP_DW1(port));
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003244 val &= ~((0xff << 16) | 0xff);
3245 val |= procmon->dw1;
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003246 I915_WRITE(ICL_PORT_COMP_DW1(port), val);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003247
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003248 I915_WRITE(ICL_PORT_COMP_DW9(port), procmon->dw9);
3249 I915_WRITE(ICL_PORT_COMP_DW10(port), procmon->dw10);
Paulo Zanoniade5ee72017-08-21 17:03:56 -07003250}
3251
3252static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
3253{
3254 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3255 struct i915_power_well *well;
3256 u32 val;
3257
3258 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3259
3260 /* 1. Enable PCH Reset Handshake */
3261 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3262 val |= RESET_PCH_HANDSHAKE_ENABLE;
3263 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3264
3265 /* 2. Enable Comp */
3266 val = I915_READ(CHICKEN_MISC_2);
3267 val &= ~CNL_COMP_PWR_DOWN;
3268 I915_WRITE(CHICKEN_MISC_2, val);
3269
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003270 /* Dummy PORT_A to get the correct CNL register from the ICL macro */
3271 cnl_set_procmon_ref_values(dev_priv, PORT_A);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003272
3273 val = I915_READ(CNL_PORT_COMP_DW0);
3274 val |= COMP_INIT;
3275 I915_WRITE(CNL_PORT_COMP_DW0, val);
3276
3277 /* 3. */
3278 val = I915_READ(CNL_PORT_CL1CM_DW5);
3279 val |= CL_POWER_DOWN_ENABLE;
3280 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
3281
Imre Deakb38131f2017-06-29 18:37:02 +03003282 /*
3283 * 4. Enable Power Well 1 (PG1).
3284 * The AUX IO power wells will be enabled on demand.
3285 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003286 mutex_lock(&power_domains->lock);
3287 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3288 intel_power_well_enable(dev_priv, well);
3289 mutex_unlock(&power_domains->lock);
3290
3291 /* 5. Enable CD clock */
3292 cnl_init_cdclk(dev_priv);
3293
3294 /* 6. Enable DBUF */
3295 gen9_dbuf_enable(dev_priv);
Imre Deak57522c42017-10-03 12:51:58 +03003296
3297 if (resume && dev_priv->csr.dmc_payload)
3298 intel_csr_load_program(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003299}
3300
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003301static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
3302{
3303 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3304 struct i915_power_well *well;
3305 u32 val;
3306
3307 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3308
3309 /* 1. Disable all display engine functions -> aready done */
3310
3311 /* 2. Disable DBUF */
3312 gen9_dbuf_disable(dev_priv);
3313
3314 /* 3. Disable CD clock */
3315 cnl_uninit_cdclk(dev_priv);
3316
Imre Deakb38131f2017-06-29 18:37:02 +03003317 /*
3318 * 4. Disable Power Well 1 (PG1).
3319 * The AUX IO power wells are toggled on demand, so they are already
3320 * disabled at this point.
3321 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003322 mutex_lock(&power_domains->lock);
3323 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3324 intel_power_well_disable(dev_priv, well);
3325 mutex_unlock(&power_domains->lock);
3326
Imre Deak846c6b22017-06-29 18:36:58 +03003327 usleep_range(10, 30); /* 10 us delay per Bspec */
3328
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003329 /* 5. Disable Comp */
3330 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03003331 val |= CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003332 I915_WRITE(CHICKEN_MISC_2, val);
3333}
3334
Paulo Zanoniad186f32018-02-05 13:40:43 -02003335static void icl_display_core_init(struct drm_i915_private *dev_priv,
3336 bool resume)
3337{
Imre Deak67ca07e2018-06-26 17:22:32 +03003338 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3339 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003340 enum port port;
3341 u32 val;
3342
3343 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3344
3345 /* 1. Enable PCH reset handshake. */
3346 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3347 val |= RESET_PCH_HANDSHAKE_ENABLE;
3348 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3349
3350 for (port = PORT_A; port <= PORT_B; port++) {
3351 /* 2. Enable DDI combo PHY comp. */
3352 val = I915_READ(ICL_PHY_MISC(port));
3353 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3354 I915_WRITE(ICL_PHY_MISC(port), val);
3355
3356 cnl_set_procmon_ref_values(dev_priv, port);
3357
3358 val = I915_READ(ICL_PORT_COMP_DW0(port));
3359 val |= COMP_INIT;
3360 I915_WRITE(ICL_PORT_COMP_DW0(port), val);
3361
3362 /* 3. Set power down enable. */
3363 val = I915_READ(ICL_PORT_CL_DW5(port));
3364 val |= CL_POWER_DOWN_ENABLE;
3365 I915_WRITE(ICL_PORT_CL_DW5(port), val);
3366 }
3367
Imre Deak67ca07e2018-06-26 17:22:32 +03003368 /*
3369 * 4. Enable Power Well 1 (PG1).
3370 * The AUX IO power wells will be enabled on demand.
3371 */
3372 mutex_lock(&power_domains->lock);
3373 well = lookup_power_well(dev_priv, ICL_DISP_PW_1);
3374 intel_power_well_enable(dev_priv, well);
3375 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003376
3377 /* 5. Enable CDCLK. */
3378 icl_init_cdclk(dev_priv);
3379
3380 /* 6. Enable DBUF. */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003381 icl_dbuf_enable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003382
3383 /* 7. Setup MBUS. */
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003384 icl_mbus_init(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003385}
3386
3387static void icl_display_core_uninit(struct drm_i915_private *dev_priv)
3388{
Imre Deak67ca07e2018-06-26 17:22:32 +03003389 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3390 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003391 enum port port;
3392 u32 val;
3393
3394 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3395
3396 /* 1. Disable all display engine functions -> aready done */
3397
3398 /* 2. Disable DBUF */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003399 icl_dbuf_disable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003400
3401 /* 3. Disable CD clock */
3402 icl_uninit_cdclk(dev_priv);
3403
Imre Deak67ca07e2018-06-26 17:22:32 +03003404 /*
3405 * 4. Disable Power Well 1 (PG1).
3406 * The AUX IO power wells are toggled on demand, so they are already
3407 * disabled at this point.
3408 */
3409 mutex_lock(&power_domains->lock);
3410 well = lookup_power_well(dev_priv, ICL_DISP_PW_1);
3411 intel_power_well_disable(dev_priv, well);
3412 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003413
3414 /* 5. Disable Comp */
3415 for (port = PORT_A; port <= PORT_B; port++) {
3416 val = I915_READ(ICL_PHY_MISC(port));
3417 val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3418 I915_WRITE(ICL_PHY_MISC(port), val);
3419 }
3420}
3421
Ville Syrjälä70722462015-04-10 18:21:28 +03003422static void chv_phy_control_init(struct drm_i915_private *dev_priv)
3423{
3424 struct i915_power_well *cmn_bc =
3425 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3426 struct i915_power_well *cmn_d =
3427 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
3428
3429 /*
3430 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
3431 * workaround never ever read DISPLAY_PHY_CONTROL, and
3432 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003433 * power well state and lane status to reconstruct the
3434 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03003435 */
3436 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03003437 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
3438 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003439 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
3440 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
3441 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
3442
3443 /*
3444 * If all lanes are disabled we leave the override disabled
3445 * with all power down bits cleared to match the state we
3446 * would use after disabling the port. Otherwise enable the
3447 * override and set the lane powerdown bits accding to the
3448 * current lane status.
3449 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003450 if (cmn_bc->desc->ops->is_enabled(dev_priv, cmn_bc)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003451 uint32_t status = I915_READ(DPLL(PIPE_A));
3452 unsigned int mask;
3453
3454 mask = status & DPLL_PORTB_READY_MASK;
3455 if (mask == 0xf)
3456 mask = 0x0;
3457 else
3458 dev_priv->chv_phy_control |=
3459 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
3460
3461 dev_priv->chv_phy_control |=
3462 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
3463
3464 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
3465 if (mask == 0xf)
3466 mask = 0x0;
3467 else
3468 dev_priv->chv_phy_control |=
3469 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
3470
3471 dev_priv->chv_phy_control |=
3472 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
3473
Ville Syrjälä70722462015-04-10 18:21:28 +03003474 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003475
3476 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
3477 } else {
3478 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003479 }
3480
Imre Deakf28ec6f2018-08-06 12:58:37 +03003481 if (cmn_d->desc->ops->is_enabled(dev_priv, cmn_d)) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003482 uint32_t status = I915_READ(DPIO_PHY_STATUS);
3483 unsigned int mask;
3484
3485 mask = status & DPLL_PORTD_READY_MASK;
3486
3487 if (mask == 0xf)
3488 mask = 0x0;
3489 else
3490 dev_priv->chv_phy_control |=
3491 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
3492
3493 dev_priv->chv_phy_control |=
3494 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
3495
Ville Syrjälä70722462015-04-10 18:21:28 +03003496 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003497
3498 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
3499 } else {
3500 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003501 }
3502
3503 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
3504
3505 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
3506 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03003507}
3508
Daniel Vetter9c065a72014-09-30 10:56:38 +02003509static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
3510{
3511 struct i915_power_well *cmn =
3512 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3513 struct i915_power_well *disp2d =
3514 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
3515
Daniel Vetter9c065a72014-09-30 10:56:38 +02003516 /* If the display might be already active skip this */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003517 if (cmn->desc->ops->is_enabled(dev_priv, cmn) &&
3518 disp2d->desc->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003519 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3520 return;
3521
3522 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3523
3524 /* cmnlane needs DPLL registers */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003525 disp2d->desc->ops->enable(dev_priv, disp2d);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003526
3527 /*
3528 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3529 * Need to assert and de-assert PHY SB reset by gating the
3530 * common lane power, then un-gating it.
3531 * Simply ungating isn't enough to reset the PHY enough to get
3532 * ports and lanes running.
3533 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003534 cmn->desc->ops->disable(dev_priv, cmn);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003535}
3536
Daniel Vettere4e76842014-09-30 10:56:42 +02003537/**
3538 * intel_power_domains_init_hw - initialize hardware power domain state
3539 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003540 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003541 *
3542 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003543 * power wells belonging to the INIT power domain. Power wells in other
3544 * domains (and not in the INIT domain) are referenced or disabled during the
3545 * modeset state HW readout. After that the reference count of each power well
3546 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003547 */
Imre Deak73dfc222015-11-17 17:33:53 +02003548void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003549{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003550 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3551
3552 power_domains->initializing = true;
3553
Paulo Zanoniad186f32018-02-05 13:40:43 -02003554 if (IS_ICELAKE(dev_priv)) {
3555 icl_display_core_init(dev_priv, resume);
3556 } else if (IS_CANNONLAKE(dev_priv)) {
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003557 cnl_display_core_init(dev_priv, resume);
3558 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003559 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003560 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003561 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003562 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003563 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003564 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003565 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003566 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003567 mutex_lock(&power_domains->lock);
3568 vlv_cmnlane_wa(dev_priv);
3569 mutex_unlock(&power_domains->lock);
3570 }
3571
3572 /* For now, we need the power well to be always enabled. */
3573 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003574 /* Disable power support if the user asked so. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003575 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003576 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003577 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003578 power_domains->initializing = false;
3579}
3580
Daniel Vettere4e76842014-09-30 10:56:42 +02003581/**
Imre Deak48a287e2018-08-06 12:58:35 +03003582 * intel_power_domains_fini_hw - deinitialize hw power domain state
3583 * @dev_priv: i915 device instance
3584 *
3585 * De-initializes the display power domain HW state. It also ensures that the
3586 * device stays powered up so that the driver can be reloaded.
3587 */
3588void intel_power_domains_fini_hw(struct drm_i915_private *dev_priv)
3589{
3590 struct device *kdev = &dev_priv->drm.pdev->dev;
3591
3592 /*
3593 * The i915.ko module is still not prepared to be loaded when
3594 * the power well is not enabled, so just enable it in case
3595 * we're going to unload/reload.
3596 * The following also reacquires the RPM reference the core passed
3597 * to the driver during loading, which is dropped in
3598 * intel_runtime_pm_enable(). We have to hand back the control of the
3599 * device to the core with this reference held.
3600 */
3601 intel_display_set_init_power(dev_priv, true);
3602
3603 /* Remove the refcount we took to keep power well support disabled. */
3604 if (!i915_modparams.disable_power_well)
3605 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
3606
3607 /*
3608 * Remove the refcount we took in intel_runtime_pm_enable() in case
3609 * the platform doesn't support runtime PM.
3610 */
3611 if (!HAS_RUNTIME_PM(dev_priv))
3612 pm_runtime_put(kdev);
3613}
3614
3615/**
Imre Deak73dfc222015-11-17 17:33:53 +02003616 * intel_power_domains_suspend - suspend power domain state
3617 * @dev_priv: i915 device instance
3618 *
3619 * This function prepares the hardware power domain state before entering
3620 * system suspend. It must be paired with intel_power_domains_init_hw().
3621 */
3622void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3623{
Imre Deakd314cd42015-11-17 17:44:23 +02003624 /*
3625 * Even if power well support was disabled we still want to disable
3626 * power wells while we are system suspended.
3627 */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003628 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003629 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003630
Paulo Zanoniad186f32018-02-05 13:40:43 -02003631 if (IS_ICELAKE(dev_priv))
3632 icl_display_core_uninit(dev_priv);
3633 else if (IS_CANNONLAKE(dev_priv))
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003634 cnl_display_core_uninit(dev_priv);
3635 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003636 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003637 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003638 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003639}
3640
Imre Deak8d8c3862017-02-17 17:39:46 +02003641static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3642{
3643 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3644 struct i915_power_well *power_well;
3645
3646 for_each_power_well(dev_priv, power_well) {
3647 enum intel_display_power_domain domain;
3648
3649 DRM_DEBUG_DRIVER("%-25s %d\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003650 power_well->desc->name, power_well->count);
Imre Deak8d8c3862017-02-17 17:39:46 +02003651
Imre Deakf28ec6f2018-08-06 12:58:37 +03003652 for_each_power_domain(domain, power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003653 DRM_DEBUG_DRIVER(" %-23s %d\n",
3654 intel_display_power_domain_str(domain),
3655 power_domains->domain_use_count[domain]);
3656 }
3657}
3658
3659/**
3660 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3661 * @dev_priv: i915 device instance
3662 *
3663 * Verify if the reference count of each power well matches its HW enabled
3664 * state and the total refcount of the domains it belongs to. This must be
3665 * called after modeset HW state sanitization, which is responsible for
3666 * acquiring reference counts for any power wells in use and disabling the
3667 * ones left on by BIOS but not required by any active output.
3668 */
3669void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3670{
3671 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3672 struct i915_power_well *power_well;
3673 bool dump_domain_info;
3674
3675 mutex_lock(&power_domains->lock);
3676
3677 dump_domain_info = false;
3678 for_each_power_well(dev_priv, power_well) {
3679 enum intel_display_power_domain domain;
3680 int domains_count;
3681 bool enabled;
3682
3683 /*
3684 * Power wells not belonging to any domain (like the MISC_IO
3685 * and PW1 power wells) are under FW control, so ignore them,
3686 * since their state can change asynchronously.
3687 */
Imre Deakf28ec6f2018-08-06 12:58:37 +03003688 if (!power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003689 continue;
3690
Imre Deakf28ec6f2018-08-06 12:58:37 +03003691 enabled = power_well->desc->ops->is_enabled(dev_priv,
3692 power_well);
3693 if ((power_well->count || power_well->desc->always_on) !=
3694 enabled)
Imre Deak8d8c3862017-02-17 17:39:46 +02003695 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003696 power_well->desc->name,
3697 power_well->count, enabled);
Imre Deak8d8c3862017-02-17 17:39:46 +02003698
3699 domains_count = 0;
Imre Deakf28ec6f2018-08-06 12:58:37 +03003700 for_each_power_domain(domain, power_well->desc->domains)
Imre Deak8d8c3862017-02-17 17:39:46 +02003701 domains_count += power_domains->domain_use_count[domain];
3702
3703 if (power_well->count != domains_count) {
3704 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3705 "(refcount %d/domains refcount %d)\n",
Imre Deakf28ec6f2018-08-06 12:58:37 +03003706 power_well->desc->name, power_well->count,
Imre Deak8d8c3862017-02-17 17:39:46 +02003707 domains_count);
3708 dump_domain_info = true;
3709 }
3710 }
3711
3712 if (dump_domain_info) {
3713 static bool dumped;
3714
3715 if (!dumped) {
3716 intel_power_domains_dump_info(dev_priv);
3717 dumped = true;
3718 }
3719 }
3720
3721 mutex_unlock(&power_domains->lock);
3722}
3723
Imre Deak73dfc222015-11-17 17:33:53 +02003724/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003725 * intel_runtime_pm_get - grab a runtime pm reference
3726 * @dev_priv: i915 device instance
3727 *
3728 * This function grabs a device-level runtime pm reference (mostly used for GEM
3729 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3730 *
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.
3733 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003734void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3735{
David Weinehall52a05c32016-08-22 13:32:44 +03003736 struct pci_dev *pdev = dev_priv->drm.pdev;
3737 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003738 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003739
Imre Deakf5073822017-03-28 12:38:55 +03003740 ret = pm_runtime_get_sync(kdev);
3741 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003742
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003743 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003744 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003745}
3746
Daniel Vettere4e76842014-09-30 10:56:42 +02003747/**
Imre Deak09731282016-02-17 14:17:42 +02003748 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3749 * @dev_priv: i915 device instance
3750 *
3751 * This function grabs a device-level runtime pm reference if the device is
Chris Wilsonacb79142018-02-19 12:50:46 +00003752 * already in use and ensures that it is powered up. It is illegal to try
3753 * and access the HW should intel_runtime_pm_get_if_in_use() report failure.
Imre Deak09731282016-02-17 14:17:42 +02003754 *
3755 * Any runtime pm reference obtained by this function must have a symmetric
3756 * call to intel_runtime_pm_put() to release the reference again.
Chris Wilsonacb79142018-02-19 12:50:46 +00003757 *
3758 * Returns: True if the wakeref was acquired, or False otherwise.
Imre Deak09731282016-02-17 14:17:42 +02003759 */
3760bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3761{
Chris Wilson135dc792016-02-25 21:10:28 +00003762 if (IS_ENABLED(CONFIG_PM)) {
Chris Wilsonacb79142018-02-19 12:50:46 +00003763 struct pci_dev *pdev = dev_priv->drm.pdev;
3764 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003765
Chris Wilson135dc792016-02-25 21:10:28 +00003766 /*
3767 * In cases runtime PM is disabled by the RPM core and we get
3768 * an -EINVAL return value we are not supposed to call this
3769 * function, since the power state is undefined. This applies
3770 * atm to the late/early system suspend/resume handlers.
3771 */
Chris Wilsonacb79142018-02-19 12:50:46 +00003772 if (pm_runtime_get_if_in_use(kdev) <= 0)
Chris Wilson135dc792016-02-25 21:10:28 +00003773 return false;
3774 }
Imre Deak09731282016-02-17 14:17:42 +02003775
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003776 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deak09731282016-02-17 14:17:42 +02003777 assert_rpm_wakelock_held(dev_priv);
3778
3779 return true;
3780}
3781
3782/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003783 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3784 * @dev_priv: i915 device instance
3785 *
3786 * This function grabs a device-level runtime pm reference (mostly used for GEM
3787 * code to ensure the GTT or GT is on).
3788 *
3789 * It will _not_ power up the device but instead only check that it's powered
3790 * on. Therefore it is only valid to call this functions from contexts where
3791 * the device is known to be powered up and where trying to power it up would
3792 * result in hilarity and deadlocks. That pretty much means only the system
3793 * suspend/resume code where this is used to grab runtime pm references for
3794 * delayed setup down in work items.
3795 *
3796 * Any runtime pm reference obtained by this function must have a symmetric
3797 * call to intel_runtime_pm_put() to release the reference again.
3798 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003799void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3800{
David Weinehall52a05c32016-08-22 13:32:44 +03003801 struct pci_dev *pdev = dev_priv->drm.pdev;
3802 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003803
Imre Deakc9b88462015-12-15 20:10:34 +02003804 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003805 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003806
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003807 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003808}
3809
Daniel Vettere4e76842014-09-30 10:56:42 +02003810/**
3811 * intel_runtime_pm_put - release a runtime pm reference
3812 * @dev_priv: i915 device instance
3813 *
3814 * This function drops the device-level runtime pm reference obtained by
3815 * intel_runtime_pm_get() and might power down the corresponding
3816 * hardware block right away if this is the last reference.
3817 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003818void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3819{
David Weinehall52a05c32016-08-22 13:32:44 +03003820 struct pci_dev *pdev = dev_priv->drm.pdev;
3821 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003822
Imre Deak542db3c2015-12-15 20:10:36 +02003823 assert_rpm_wakelock_held(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003824 atomic_dec(&dev_priv->runtime_pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003825
David Weinehallc49d13e2016-08-22 13:32:42 +03003826 pm_runtime_mark_last_busy(kdev);
3827 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003828}
3829
Daniel Vettere4e76842014-09-30 10:56:42 +02003830/**
3831 * intel_runtime_pm_enable - enable runtime pm
3832 * @dev_priv: i915 device instance
3833 *
3834 * This function enables runtime pm at the end of the driver load sequence.
3835 *
3836 * Note that this function does currently not enable runtime pm for the
3837 * subordinate display power domains. That is only done on the first modeset
3838 * using intel_display_set_init_power().
3839 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003840void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003841{
David Weinehall52a05c32016-08-22 13:32:44 +03003842 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003843 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003844
David Weinehallc49d13e2016-08-22 13:32:42 +03003845 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3846 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003847
Imre Deak25b181b2015-12-17 13:44:56 +02003848 /*
3849 * Take a permanent reference to disable the RPM functionality and drop
3850 * it only when unloading the driver. Use the low level get/put helpers,
3851 * so the driver's own RPM reference tracking asserts also work on
3852 * platforms without RPM support.
3853 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003854 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003855 int ret;
3856
David Weinehallc49d13e2016-08-22 13:32:42 +03003857 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003858 ret = pm_runtime_get_sync(kdev);
3859 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003860 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003861 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003862 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003863
Imre Deakaabee1b2015-12-15 20:10:29 +02003864 /*
3865 * The core calls the driver load handler with an RPM reference held.
3866 * We drop that here and will reacquire it during unloading in
3867 * intel_power_domains_fini().
3868 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003869 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003870}