blob: b2d182cc3319e190801c167b1a0bbc7d2fb5c8eb [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{
162 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
163 power_well->ops->enable(dev_priv, power_well);
164 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{
170 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
171 power_well->hw_enabled = false;
172 power_well->ops->disable(dev_priv, power_well);
173}
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",
186 power_well->name);
187
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)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +0200216 if (power_well->always_on)
217 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 Deak438b8dc2017-07-11 23:42:30 +0300326 enum i915_power_well_id id = power_well->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 Deak438b8dc2017-07-11 23:42:30 +0300353 enum i915_power_well_id id = power_well->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",
373 power_well->name,
374 !!(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 Deak1af474f2017-07-06 17:40:34 +0300389 enum i915_power_well_id id = power_well->id;
Imre Deakb2891eb2017-07-11 23:42:35 +0300390 bool wait_fuses = power_well->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 Deak001bd2c2017-07-12 18:54:13 +0300424 hsw_power_well_post_enable(dev_priv, power_well->hsw.irq_pipe_mask,
425 power_well->hsw.has_vga);
Imre Deakec46d482017-07-06 17:40:33 +0300426}
Daniel Vetter9c065a72014-09-30 10:56:38 +0200427
Imre Deakec46d482017-07-06 17:40:33 +0300428static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
429 struct i915_power_well *power_well)
430{
Imre Deak1af474f2017-07-06 17:40:34 +0300431 enum i915_power_well_id id = power_well->id;
432 u32 val;
433
Imre Deak001bd2c2017-07-12 18:54:13 +0300434 hsw_power_well_pre_disable(dev_priv, power_well->hsw.irq_pipe_mask);
435
Imre Deak9c3a16c2017-08-14 18:15:30 +0300436 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
437 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id),
438 val & ~HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300439 hsw_wait_for_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200440}
441
Imre Deak67ca07e2018-06-26 17:22:32 +0300442#define ICL_AUX_PW_TO_PORT(pw) ((pw) - ICL_DISP_PW_AUX_A)
443
444static void
445icl_combo_phy_aux_power_well_enable(struct drm_i915_private *dev_priv,
446 struct i915_power_well *power_well)
447{
448 enum i915_power_well_id id = power_well->id;
449 enum port port = ICL_AUX_PW_TO_PORT(id);
450 u32 val;
451
452 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
453 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), val | HSW_PWR_WELL_CTL_REQ(id));
454
455 val = I915_READ(ICL_PORT_CL_DW12(port));
456 I915_WRITE(ICL_PORT_CL_DW12(port), val | ICL_LANE_ENABLE_AUX);
457
458 hsw_wait_for_power_well_enable(dev_priv, power_well);
459}
460
461static void
462icl_combo_phy_aux_power_well_disable(struct drm_i915_private *dev_priv,
463 struct i915_power_well *power_well)
464{
465 enum i915_power_well_id id = power_well->id;
466 enum port port = ICL_AUX_PW_TO_PORT(id);
467 u32 val;
468
469 val = I915_READ(ICL_PORT_CL_DW12(port));
470 I915_WRITE(ICL_PORT_CL_DW12(port), val & ~ICL_LANE_ENABLE_AUX);
471
472 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
473 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id),
474 val & ~HSW_PWR_WELL_CTL_REQ(id));
475
476 hsw_wait_for_power_well_disable(dev_priv, power_well);
477}
478
Imre Deakd42539b2017-07-06 17:40:39 +0300479/*
480 * We should only use the power well if we explicitly asked the hardware to
481 * enable it, so check if it's enabled and also check if we've requested it to
482 * be enabled.
483 */
484static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
485 struct i915_power_well *power_well)
486{
487 enum i915_power_well_id id = power_well->id;
488 u32 mask = HSW_PWR_WELL_CTL_REQ(id) | HSW_PWR_WELL_CTL_STATE(id);
489
Imre Deak9c3a16c2017-08-14 18:15:30 +0300490 return (I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & mask) == mask;
Imre Deakd42539b2017-07-06 17:40:39 +0300491}
492
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530493static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
494{
Imre Deak9c3a16c2017-08-14 18:15:30 +0300495 enum i915_power_well_id id = SKL_DISP_PW_2;
496
Imre Deakbfcdabe2016-04-01 16:02:37 +0300497 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
498 "DC9 already programmed to be enabled.\n");
499 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
500 "DC5 still not disabled to enable DC9.\n");
Imre Deak9c3a16c2017-08-14 18:15:30 +0300501 WARN_ONCE(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
502 HSW_PWR_WELL_CTL_REQ(id),
Imre Deake8a3a2a2017-06-29 18:37:00 +0300503 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300504 WARN_ONCE(intel_irqs_enabled(dev_priv),
505 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530506
507 /*
508 * TODO: check for the following to verify the conditions to enter DC9
509 * state are satisfied:
510 * 1] Check relevant display engine registers to verify if mode set
511 * disable sequence was followed.
512 * 2] Check if display uninitialize sequence is initialized.
513 */
514}
515
516static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
517{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300518 WARN_ONCE(intel_irqs_enabled(dev_priv),
519 "Interrupts not disabled yet.\n");
520 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
521 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530522
523 /*
524 * TODO: check for the following to verify DC9 state was indeed
525 * entered before programming to disable it:
526 * 1] Check relevant display engine registers to verify if mode
527 * set disable sequence was followed.
528 * 2] Check if display uninitialize sequence is initialized.
529 */
530}
531
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200532static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
533 u32 state)
534{
535 int rewrites = 0;
536 int rereads = 0;
537 u32 v;
538
539 I915_WRITE(DC_STATE_EN, state);
540
541 /* It has been observed that disabling the dc6 state sometimes
542 * doesn't stick and dmc keeps returning old value. Make sure
543 * the write really sticks enough times and also force rewrite until
544 * we are confident that state is exactly what we want.
545 */
546 do {
547 v = I915_READ(DC_STATE_EN);
548
549 if (v != state) {
550 I915_WRITE(DC_STATE_EN, state);
551 rewrites++;
552 rereads = 0;
553 } else if (rereads++ > 5) {
554 break;
555 }
556
557 } while (rewrites < 100);
558
559 if (v != state)
560 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
561 state, v);
562
563 /* Most of the times we need one retry, avoid spam */
564 if (rewrites > 1)
565 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
566 state, rewrites);
567}
568
Imre Deakda2f41d2016-04-20 20:27:56 +0300569static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530570{
Imre Deakda2f41d2016-04-20 20:27:56 +0300571 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530572
Imre Deak13ae3a02015-11-04 19:24:16 +0200573 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200574 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200575 mask |= DC_STATE_EN_DC9;
576 else
577 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530578
Imre Deakda2f41d2016-04-20 20:27:56 +0300579 return mask;
580}
581
582void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
583{
584 u32 val;
585
586 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
587
588 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
589 dev_priv->csr.dc_state, val);
590 dev_priv->csr.dc_state = val;
591}
592
Imre Deak13e15922018-04-17 14:31:47 +0300593/**
594 * gen9_set_dc_state - set target display C power state
595 * @dev_priv: i915 device instance
596 * @state: target DC power state
597 * - DC_STATE_DISABLE
598 * - DC_STATE_EN_UPTO_DC5
599 * - DC_STATE_EN_UPTO_DC6
600 * - DC_STATE_EN_DC9
601 *
602 * Signal to DMC firmware/HW the target DC power state passed in @state.
603 * DMC/HW can turn off individual display clocks and power rails when entering
604 * a deeper DC power state (higher in number) and turns these back when exiting
605 * that state to a shallower power state (lower in number). The HW will decide
606 * when to actually enter a given state on an on-demand basis, for instance
607 * depending on the active state of display pipes. The state of display
608 * registers backed by affected power rails are saved/restored as needed.
609 *
610 * Based on the above enabling a deeper DC power state is asynchronous wrt.
611 * enabling it. Disabling a deeper power state is synchronous: for instance
612 * setting %DC_STATE_DISABLE won't complete until all HW resources are turned
613 * back on and register state is restored. This is guaranteed by the MMIO write
614 * to DC_STATE_EN blocking until the state is restored.
615 */
Imre Deakda2f41d2016-04-20 20:27:56 +0300616static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
617{
618 uint32_t val;
619 uint32_t mask;
620
Imre Deaka37baf32016-02-29 22:49:03 +0200621 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
622 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100623
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530624 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300625 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200626 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
627 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200628
629 /* Check if DMC is ignoring our DC state requests */
630 if ((val & mask) != dev_priv->csr.dc_state)
631 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
632 dev_priv->csr.dc_state, val & mask);
633
Imre Deak13ae3a02015-11-04 19:24:16 +0200634 val &= ~mask;
635 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200636
637 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200638
639 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530640}
641
Imre Deak13ae3a02015-11-04 19:24:16 +0200642void bxt_enable_dc9(struct drm_i915_private *dev_priv)
643{
644 assert_can_enable_dc9(dev_priv);
645
646 DRM_DEBUG_KMS("Enabling DC9\n");
647
Imre Deak78597992016-06-16 16:37:20 +0300648 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200649 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
650}
651
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530652void bxt_disable_dc9(struct drm_i915_private *dev_priv)
653{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530654 assert_can_disable_dc9(dev_priv);
655
656 DRM_DEBUG_KMS("Disabling DC9\n");
657
Imre Deak13ae3a02015-11-04 19:24:16 +0200658 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300659
660 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530661}
662
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200663static void assert_csr_loaded(struct drm_i915_private *dev_priv)
664{
665 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
666 "CSR program storage start is NULL\n");
667 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
668 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
669}
670
Suketu Shah5aefb232015-04-16 14:22:10 +0530671static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530672{
Suketu Shah5aefb232015-04-16 14:22:10 +0530673 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
674 SKL_DISP_PW_2);
675
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700676 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530677
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700678 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
679 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200680 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530681
682 assert_csr_loaded(dev_priv);
683}
684
Imre Deakf62c79b2016-04-20 20:27:57 +0300685void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530686{
Suketu Shah5aefb232015-04-16 14:22:10 +0530687 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530688
689 DRM_DEBUG_KMS("Enabling DC5\n");
690
Lucas De Marchi53421c22017-12-04 15:22:10 -0800691 /* Wa Display #1183: skl,kbl,cfl */
692 if (IS_GEN9_BC(dev_priv))
693 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
694 SKL_SELECT_ALTERNATE_DC_EXIT);
695
Imre Deak13ae3a02015-11-04 19:24:16 +0200696 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530697}
698
Suketu Shah93c7cb62015-04-16 14:22:13 +0530699static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530700{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700701 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
702 "Backlight is not disabled.\n");
703 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
704 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530705
706 assert_csr_loaded(dev_priv);
707}
708
Daniel Vetterc4c25252018-04-17 12:02:25 +0200709static void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530710{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530711 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530712
713 DRM_DEBUG_KMS("Enabling DC6\n");
714
Imre Deakb49be662018-04-19 18:51:09 +0300715 /* Wa Display #1183: skl,kbl,cfl */
716 if (IS_GEN9_BC(dev_priv))
717 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
718 SKL_SELECT_ALTERNATE_DC_EXIT);
Imre Deak13ae3a02015-11-04 19:24:16 +0200719
Imre Deakb49be662018-04-19 18:51:09 +0300720 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
Suketu Shahf75a1982015-04-16 14:22:11 +0530721}
722
Daniel Vetter9c065a72014-09-30 10:56:38 +0200723static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
724 struct i915_power_well *power_well)
725{
Imre Deak1af474f2017-07-06 17:40:34 +0300726 enum i915_power_well_id id = power_well->id;
727 u32 mask = HSW_PWR_WELL_CTL_REQ(id);
Imre Deak9c3a16c2017-08-14 18:15:30 +0300728 u32 bios_req = I915_READ(HSW_PWR_WELL_CTL_BIOS(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300729
Imre Deak16e84912017-02-17 17:39:45 +0200730 /* Take over the request bit if set by BIOS. */
Imre Deak1af474f2017-07-06 17:40:34 +0300731 if (bios_req & mask) {
Imre Deak9c3a16c2017-08-14 18:15:30 +0300732 u32 drv_req = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300733
734 if (!(drv_req & mask))
Imre Deak9c3a16c2017-08-14 18:15:30 +0300735 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), drv_req | mask);
736 I915_WRITE(HSW_PWR_WELL_CTL_BIOS(id), bios_req & ~mask);
Imre Deak16e84912017-02-17 17:39:45 +0200737 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200738}
739
Imre Deak9c8d0b82016-06-13 16:44:34 +0300740static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
741 struct i915_power_well *power_well)
742{
Imre Deakb5565a22017-07-06 17:40:29 +0300743 bxt_ddi_phy_init(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300744}
745
746static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
747 struct i915_power_well *power_well)
748{
Imre Deakb5565a22017-07-06 17:40:29 +0300749 bxt_ddi_phy_uninit(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300750}
751
752static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
753 struct i915_power_well *power_well)
754{
Imre Deakb5565a22017-07-06 17:40:29 +0300755 return bxt_ddi_phy_is_enabled(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300756}
757
Imre Deak9c8d0b82016-06-13 16:44:34 +0300758static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
759{
760 struct i915_power_well *power_well;
761
762 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
763 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300764 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300765
766 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
767 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300768 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200769
770 if (IS_GEMINILAKE(dev_priv)) {
771 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
772 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300773 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200774 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300775}
776
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100777static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
778 struct i915_power_well *power_well)
779{
780 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
781}
782
Ville Syrjälä18a80672016-05-16 16:59:40 +0300783static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
784{
785 u32 tmp = I915_READ(DBUF_CTL);
786
787 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
788 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
789 "Unexpected DBuf power power state (0x%08x)\n", tmp);
790}
791
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100792static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
793 struct i915_power_well *power_well)
794{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200795 struct intel_cdclk_state cdclk_state = {};
796
Imre Deak5b773eb2016-02-29 22:49:05 +0200797 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300798
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200799 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
Ville Syrjälä64600bd2017-10-24 12:52:08 +0300800 /* Can't read out voltage_level so can't use intel_cdclk_changed() */
801 WARN_ON(intel_cdclk_needs_modeset(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300802
Ville Syrjälä18a80672016-05-16 16:59:40 +0300803 gen9_assert_dbuf_enabled(dev_priv);
804
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200805 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300806 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100807}
808
809static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
810 struct i915_power_well *power_well)
811{
Imre Deakf74ed082016-04-18 14:48:21 +0300812 if (!dev_priv->csr.dmc_payload)
813 return;
814
Imre Deaka37baf32016-02-29 22:49:03 +0200815 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100816 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200817 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100818 gen9_enable_dc5(dev_priv);
819}
820
Imre Deak3c1b38e2017-02-17 17:39:42 +0200821static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
822 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100823{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100824}
825
Daniel Vetter9c065a72014-09-30 10:56:38 +0200826static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
827 struct i915_power_well *power_well)
828{
829}
830
831static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
832 struct i915_power_well *power_well)
833{
834 return true;
835}
836
Ville Syrjälä2ee0da12017-06-01 17:36:16 +0300837static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
838 struct i915_power_well *power_well)
839{
840 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
841 i830_enable_pipe(dev_priv, PIPE_A);
842 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
843 i830_enable_pipe(dev_priv, PIPE_B);
844}
845
846static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
847 struct i915_power_well *power_well)
848{
849 i830_disable_pipe(dev_priv, PIPE_B);
850 i830_disable_pipe(dev_priv, PIPE_A);
851}
852
853static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
854 struct i915_power_well *power_well)
855{
856 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
857 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
858}
859
860static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
861 struct i915_power_well *power_well)
862{
863 if (power_well->count > 0)
864 i830_pipes_power_well_enable(dev_priv, power_well);
865 else
866 i830_pipes_power_well_disable(dev_priv, power_well);
867}
868
Daniel Vetter9c065a72014-09-30 10:56:38 +0200869static void vlv_set_power_well(struct drm_i915_private *dev_priv,
870 struct i915_power_well *power_well, bool enable)
871{
Imre Deak438b8dc2017-07-11 23:42:30 +0300872 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200873 u32 mask;
874 u32 state;
875 u32 ctrl;
876
877 mask = PUNIT_PWRGT_MASK(power_well_id);
878 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
879 PUNIT_PWRGT_PWR_GATE(power_well_id);
880
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100881 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200882
883#define COND \
884 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
885
886 if (COND)
887 goto out;
888
889 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
890 ctrl &= ~mask;
891 ctrl |= state;
892 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
893
894 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900895 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200896 state,
897 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
898
899#undef COND
900
901out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100902 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200903}
904
Daniel Vetter9c065a72014-09-30 10:56:38 +0200905static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
906 struct i915_power_well *power_well)
907{
908 vlv_set_power_well(dev_priv, power_well, true);
909}
910
911static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
912 struct i915_power_well *power_well)
913{
914 vlv_set_power_well(dev_priv, power_well, false);
915}
916
917static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
918 struct i915_power_well *power_well)
919{
Imre Deak438b8dc2017-07-11 23:42:30 +0300920 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200921 bool enabled = false;
922 u32 mask;
923 u32 state;
924 u32 ctrl;
925
926 mask = PUNIT_PWRGT_MASK(power_well_id);
927 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
928
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100929 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200930
931 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
932 /*
933 * We only ever set the power-on and power-gate states, anything
934 * else is unexpected.
935 */
936 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
937 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
938 if (state == ctrl)
939 enabled = true;
940
941 /*
942 * A transient state at this point would mean some unexpected party
943 * is poking at the power controls too.
944 */
945 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
946 WARN_ON(ctrl != state);
947
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100948 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200949
950 return enabled;
951}
952
Ville Syrjälä766078d2016-04-11 16:56:30 +0300953static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
954{
Hans de Goede721d4842016-12-02 15:29:04 +0100955 u32 val;
956
957 /*
958 * On driver load, a pipe may be active and driving a DSI display.
959 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
960 * (and never recovering) in this case. intel_dsi_post_disable() will
961 * clear it when we turn off the display.
962 */
963 val = I915_READ(DSPCLK_GATE_D);
964 val &= DPOUNIT_CLOCK_GATE_DISABLE;
965 val |= VRHUNIT_CLOCK_GATE_DISABLE;
966 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +0300967
968 /*
969 * Disable trickle feed and enable pnd deadline calculation
970 */
971 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
972 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +0300973
974 WARN_ON(dev_priv->rawclk_freq == 0);
975
976 I915_WRITE(RAWCLK_FREQ_VLV,
977 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +0300978}
979
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300980static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200981{
Lyude9504a892016-06-21 17:03:42 -0400982 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300983 enum pipe pipe;
984
985 /*
986 * Enable the CRI clock source so we can get at the
987 * display and the reference clock for VGA
988 * hotplug / manual detection. Supposedly DSI also
989 * needs the ref clock up and running.
990 *
991 * CHV DPLL B/C have some issues if VGA mode is enabled.
992 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +0000993 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300994 u32 val = I915_READ(DPLL(pipe));
995
996 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
997 if (pipe != PIPE_A)
998 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
999
1000 I915_WRITE(DPLL(pipe), val);
1001 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001002
Ville Syrjälä766078d2016-04-11 16:56:30 +03001003 vlv_init_display_clock_gating(dev_priv);
1004
Daniel Vetter9c065a72014-09-30 10:56:38 +02001005 spin_lock_irq(&dev_priv->irq_lock);
1006 valleyview_enable_display_irqs(dev_priv);
1007 spin_unlock_irq(&dev_priv->irq_lock);
1008
1009 /*
1010 * During driver initialization/resume we can avoid restoring the
1011 * part of the HW/SW state that will be inited anyway explicitly.
1012 */
1013 if (dev_priv->power_domains.initializing)
1014 return;
1015
Daniel Vetterb9632912014-09-30 10:56:44 +02001016 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001017
Lyude9504a892016-06-21 17:03:42 -04001018 /* Re-enable the ADPA, if we have one */
1019 for_each_intel_encoder(&dev_priv->drm, encoder) {
1020 if (encoder->type == INTEL_OUTPUT_ANALOG)
1021 intel_crt_reset(&encoder->base);
1022 }
1023
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001024 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001025
1026 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001027}
1028
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001029static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1030{
1031 spin_lock_irq(&dev_priv->irq_lock);
1032 valleyview_disable_display_irqs(dev_priv);
1033 spin_unlock_irq(&dev_priv->irq_lock);
1034
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001035 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001036 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001037
Imre Deak78597992016-06-16 16:37:20 +03001038 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001039
Lyudeb64b5402016-10-26 12:36:09 -04001040 /* Prevent us from re-enabling polling on accident in late suspend */
1041 if (!dev_priv->drm.dev->power.is_suspended)
1042 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001043}
1044
1045static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1046 struct i915_power_well *power_well)
1047{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001048 vlv_set_power_well(dev_priv, power_well, true);
1049
1050 vlv_display_power_well_init(dev_priv);
1051}
1052
Daniel Vetter9c065a72014-09-30 10:56:38 +02001053static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1054 struct i915_power_well *power_well)
1055{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001056 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001057
1058 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001059}
1060
1061static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1062 struct i915_power_well *power_well)
1063{
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001064 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001065 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1066
1067 vlv_set_power_well(dev_priv, power_well, true);
1068
1069 /*
1070 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1071 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1072 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1073 * b. The other bits such as sfr settings / modesel may all
1074 * be set to 0.
1075 *
1076 * This should only be done on init and resume from S3 with
1077 * both PLLs disabled, or we risk losing DPIO and PLL
1078 * synchronization.
1079 */
1080 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1081}
1082
1083static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1084 struct i915_power_well *power_well)
1085{
1086 enum pipe pipe;
1087
Daniel Vetter9c065a72014-09-30 10:56:38 +02001088 for_each_pipe(dev_priv, pipe)
1089 assert_pll_disabled(dev_priv, pipe);
1090
1091 /* Assert common reset */
1092 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1093
1094 vlv_set_power_well(dev_priv, power_well, false);
1095}
1096
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001097#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001098
Imre Deak438b8dc2017-07-11 23:42:30 +03001099static struct i915_power_well *
1100lookup_power_well(struct drm_i915_private *dev_priv,
1101 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001102{
1103 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001104 int i;
1105
Imre Deakfc17f222015-11-04 19:24:11 +02001106 for (i = 0; i < power_domains->power_well_count; i++) {
1107 struct i915_power_well *power_well;
1108
1109 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001110 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001111 return power_well;
1112 }
1113
1114 return NULL;
1115}
1116
1117#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1118
1119static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1120{
1121 struct i915_power_well *cmn_bc =
1122 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1123 struct i915_power_well *cmn_d =
1124 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1125 u32 phy_control = dev_priv->chv_phy_control;
1126 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001127 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001128
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001129 /*
1130 * The BIOS can leave the PHY is some weird state
1131 * where it doesn't fully power down some parts.
1132 * Disable the asserts until the PHY has been fully
1133 * reset (ie. the power well has been disabled at
1134 * least once).
1135 */
1136 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1137 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1138 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1139 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1140 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1141 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1142 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1143
1144 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1145 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1146 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1147 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1148
Ville Syrjälä30142272015-07-08 23:46:01 +03001149 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1150 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1151
1152 /* this assumes override is only used to enable lanes */
1153 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1154 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1155
1156 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1157 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1158
1159 /* CL1 is on whenever anything is on in either channel */
1160 if (BITS_SET(phy_control,
1161 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1162 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1163 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1164
1165 /*
1166 * The DPLLB check accounts for the pipe B + port A usage
1167 * with CL2 powered up but all the lanes in the second channel
1168 * powered down.
1169 */
1170 if (BITS_SET(phy_control,
1171 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1172 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1173 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1174
1175 if (BITS_SET(phy_control,
1176 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1177 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1178 if (BITS_SET(phy_control,
1179 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1180 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1181
1182 if (BITS_SET(phy_control,
1183 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1184 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1185 if (BITS_SET(phy_control,
1186 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1187 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1188 }
1189
1190 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1191 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1192
1193 /* this assumes override is only used to enable lanes */
1194 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1195 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1196
1197 if (BITS_SET(phy_control,
1198 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1199 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1200
1201 if (BITS_SET(phy_control,
1202 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1203 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1204 if (BITS_SET(phy_control,
1205 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1206 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1207 }
1208
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001209 phy_status &= phy_status_mask;
1210
Ville Syrjälä30142272015-07-08 23:46:01 +03001211 /*
1212 * The PHY may be busy with some initial calibration and whatnot,
1213 * so the power state can take a while to actually change.
1214 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001215 if (intel_wait_for_register(dev_priv,
1216 DISPLAY_PHY_STATUS,
1217 phy_status_mask,
1218 phy_status,
1219 10))
1220 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1221 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1222 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001223}
1224
1225#undef BITS_SET
1226
Daniel Vetter9c065a72014-09-30 10:56:38 +02001227static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1228 struct i915_power_well *power_well)
1229{
1230 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001231 enum pipe pipe;
1232 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001233
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001234 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1235 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001236
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001237 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001238 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001239 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001240 } else {
1241 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001242 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001243 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001244
1245 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001246 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1247 vlv_set_power_well(dev_priv, power_well, true);
1248
1249 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001250 if (intel_wait_for_register(dev_priv,
1251 DISPLAY_PHY_STATUS,
1252 PHY_POWERGOOD(phy),
1253 PHY_POWERGOOD(phy),
1254 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001255 DRM_ERROR("Display PHY %d is not power up\n", phy);
1256
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001257 mutex_lock(&dev_priv->sb_lock);
1258
1259 /* Enable dynamic power down */
1260 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001261 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1262 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001263 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1264
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001265 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001266 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1267 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1268 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001269 } else {
1270 /*
1271 * Force the non-existing CL2 off. BXT does this
1272 * too, so maybe it saves some power even though
1273 * CL2 doesn't exist?
1274 */
1275 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1276 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1277 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001278 }
1279
1280 mutex_unlock(&dev_priv->sb_lock);
1281
Ville Syrjälä70722462015-04-10 18:21:28 +03001282 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1283 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001284
1285 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1286 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001287
1288 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001289}
1290
1291static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1292 struct i915_power_well *power_well)
1293{
1294 enum dpio_phy phy;
1295
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001296 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1297 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001298
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001299 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001300 phy = DPIO_PHY0;
1301 assert_pll_disabled(dev_priv, PIPE_A);
1302 assert_pll_disabled(dev_priv, PIPE_B);
1303 } else {
1304 phy = DPIO_PHY1;
1305 assert_pll_disabled(dev_priv, PIPE_C);
1306 }
1307
Ville Syrjälä70722462015-04-10 18:21:28 +03001308 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1309 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001310
1311 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001312
1313 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1314 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001315
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001316 /* PHY is fully reset now, so we can enable the PHY state asserts */
1317 dev_priv->chv_phy_assert[phy] = true;
1318
Ville Syrjälä30142272015-07-08 23:46:01 +03001319 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001320}
1321
Ville Syrjälä6669e392015-07-08 23:46:00 +03001322static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1323 enum dpio_channel ch, bool override, unsigned int mask)
1324{
1325 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1326 u32 reg, val, expected, actual;
1327
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001328 /*
1329 * The BIOS can leave the PHY is some weird state
1330 * where it doesn't fully power down some parts.
1331 * Disable the asserts until the PHY has been fully
1332 * reset (ie. the power well has been disabled at
1333 * least once).
1334 */
1335 if (!dev_priv->chv_phy_assert[phy])
1336 return;
1337
Ville Syrjälä6669e392015-07-08 23:46:00 +03001338 if (ch == DPIO_CH0)
1339 reg = _CHV_CMN_DW0_CH0;
1340 else
1341 reg = _CHV_CMN_DW6_CH1;
1342
1343 mutex_lock(&dev_priv->sb_lock);
1344 val = vlv_dpio_read(dev_priv, pipe, reg);
1345 mutex_unlock(&dev_priv->sb_lock);
1346
1347 /*
1348 * This assumes !override is only used when the port is disabled.
1349 * All lanes should power down even without the override when
1350 * the port is disabled.
1351 */
1352 if (!override || mask == 0xf) {
1353 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1354 /*
1355 * If CH1 common lane is not active anymore
1356 * (eg. for pipe B DPLL) the entire channel will
1357 * shut down, which causes the common lane registers
1358 * to read as 0. That means we can't actually check
1359 * the lane power down status bits, but as the entire
1360 * register reads as 0 it's a good indication that the
1361 * channel is indeed entirely powered down.
1362 */
1363 if (ch == DPIO_CH1 && val == 0)
1364 expected = 0;
1365 } else if (mask != 0x0) {
1366 expected = DPIO_ANYDL_POWERDOWN;
1367 } else {
1368 expected = 0;
1369 }
1370
1371 if (ch == DPIO_CH0)
1372 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1373 else
1374 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1375 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1376
1377 WARN(actual != expected,
1378 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1379 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1380 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1381 reg, val);
1382}
1383
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001384bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1385 enum dpio_channel ch, bool override)
1386{
1387 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1388 bool was_override;
1389
1390 mutex_lock(&power_domains->lock);
1391
1392 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1393
1394 if (override == was_override)
1395 goto out;
1396
1397 if (override)
1398 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1399 else
1400 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1401
1402 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1403
1404 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1405 phy, ch, dev_priv->chv_phy_control);
1406
Ville Syrjälä30142272015-07-08 23:46:01 +03001407 assert_chv_phy_status(dev_priv);
1408
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001409out:
1410 mutex_unlock(&power_domains->lock);
1411
1412 return was_override;
1413}
1414
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001415void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1416 bool override, unsigned int mask)
1417{
1418 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1419 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1420 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1421 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1422
1423 mutex_lock(&power_domains->lock);
1424
1425 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1426 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1427
1428 if (override)
1429 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1430 else
1431 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1432
1433 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1434
1435 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1436 phy, ch, mask, dev_priv->chv_phy_control);
1437
Ville Syrjälä30142272015-07-08 23:46:01 +03001438 assert_chv_phy_status(dev_priv);
1439
Ville Syrjälä6669e392015-07-08 23:46:00 +03001440 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1441
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001442 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001443}
1444
1445static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1446 struct i915_power_well *power_well)
1447{
Imre Deakf49193c2017-07-06 17:40:23 +03001448 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001449 bool enabled;
1450 u32 state, ctrl;
1451
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001452 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001453
1454 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1455 /*
1456 * We only ever set the power-on and power-gate states, anything
1457 * else is unexpected.
1458 */
1459 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1460 enabled = state == DP_SSS_PWR_ON(pipe);
1461
1462 /*
1463 * A transient state at this point would mean some unexpected party
1464 * is poking at the power controls too.
1465 */
1466 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1467 WARN_ON(ctrl << 16 != state);
1468
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001469 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001470
1471 return enabled;
1472}
1473
1474static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1475 struct i915_power_well *power_well,
1476 bool enable)
1477{
Imre Deakf49193c2017-07-06 17:40:23 +03001478 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001479 u32 state;
1480 u32 ctrl;
1481
1482 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1483
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001484 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001485
1486#define COND \
1487 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1488
1489 if (COND)
1490 goto out;
1491
1492 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1493 ctrl &= ~DP_SSC_MASK(pipe);
1494 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1495 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1496
1497 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001498 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001499 state,
1500 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1501
1502#undef COND
1503
1504out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001505 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001506}
1507
Daniel Vetter9c065a72014-09-30 10:56:38 +02001508static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1509 struct i915_power_well *power_well)
1510{
Daniel Vetter9c065a72014-09-30 10:56:38 +02001511 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001512
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001513 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001514}
1515
1516static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1517 struct i915_power_well *power_well)
1518{
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001519 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001520
Daniel Vetter9c065a72014-09-30 10:56:38 +02001521 chv_set_pipe_power_well(dev_priv, power_well, false);
1522}
1523
Imre Deak09731282016-02-17 14:17:42 +02001524static void
1525__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1526 enum intel_display_power_domain domain)
1527{
1528 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1529 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001530
Imre Deak75ccb2e2017-02-17 17:39:43 +02001531 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001532 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001533
1534 power_domains->domain_use_count[domain]++;
1535}
1536
Daniel Vettere4e76842014-09-30 10:56:42 +02001537/**
1538 * intel_display_power_get - grab a power domain reference
1539 * @dev_priv: i915 device instance
1540 * @domain: power domain to reference
1541 *
1542 * This function grabs a power domain reference for @domain and ensures that the
1543 * power domain and all its parents are powered up. Therefore users should only
1544 * grab a reference to the innermost power domain they need.
1545 *
1546 * Any power domain reference obtained by this function must have a symmetric
1547 * call to intel_display_power_put() to release the reference again.
1548 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001549void intel_display_power_get(struct drm_i915_private *dev_priv,
1550 enum intel_display_power_domain domain)
1551{
Imre Deak09731282016-02-17 14:17:42 +02001552 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001553
1554 intel_runtime_pm_get(dev_priv);
1555
Imre Deak09731282016-02-17 14:17:42 +02001556 mutex_lock(&power_domains->lock);
1557
1558 __intel_display_power_get_domain(dev_priv, domain);
1559
1560 mutex_unlock(&power_domains->lock);
1561}
1562
1563/**
1564 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1565 * @dev_priv: i915 device instance
1566 * @domain: power domain to reference
1567 *
1568 * This function grabs a power domain reference for @domain and ensures that the
1569 * power domain and all its parents are powered up. Therefore users should only
1570 * grab a reference to the innermost power domain they need.
1571 *
1572 * Any power domain reference obtained by this function must have a symmetric
1573 * call to intel_display_power_put() to release the reference again.
1574 */
1575bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1576 enum intel_display_power_domain domain)
1577{
1578 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1579 bool is_enabled;
1580
1581 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1582 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001583
1584 mutex_lock(&power_domains->lock);
1585
Imre Deak09731282016-02-17 14:17:42 +02001586 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1587 __intel_display_power_get_domain(dev_priv, domain);
1588 is_enabled = true;
1589 } else {
1590 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001591 }
1592
Daniel Vetter9c065a72014-09-30 10:56:38 +02001593 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001594
1595 if (!is_enabled)
1596 intel_runtime_pm_put(dev_priv);
1597
1598 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001599}
1600
Daniel Vettere4e76842014-09-30 10:56:42 +02001601/**
1602 * intel_display_power_put - release a power domain reference
1603 * @dev_priv: i915 device instance
1604 * @domain: power domain to reference
1605 *
1606 * This function drops the power domain reference obtained by
1607 * intel_display_power_get() and might power down the corresponding hardware
1608 * block right away if this is the last reference.
1609 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001610void intel_display_power_put(struct drm_i915_private *dev_priv,
1611 enum intel_display_power_domain domain)
1612{
1613 struct i915_power_domains *power_domains;
1614 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001615
1616 power_domains = &dev_priv->power_domains;
1617
1618 mutex_lock(&power_domains->lock);
1619
Daniel Stone11c86db2015-11-20 15:55:34 +00001620 WARN(!power_domains->domain_use_count[domain],
1621 "Use count on domain %s is already zero\n",
1622 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001623 power_domains->domain_use_count[domain]--;
1624
Imre Deak75ccb2e2017-02-17 17:39:43 +02001625 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001626 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001627
1628 mutex_unlock(&power_domains->lock);
1629
1630 intel_runtime_pm_put(dev_priv);
1631}
1632
Imre Deak965a79a2017-07-06 17:40:40 +03001633#define I830_PIPES_POWER_DOMAINS ( \
1634 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1635 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1636 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1637 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1638 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1639 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001640 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001641
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001642#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001643 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1644 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1645 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1646 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1647 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1648 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1649 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1650 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1651 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1652 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1653 BIT_ULL(POWER_DOMAIN_VGA) | \
1654 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1655 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1656 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1657 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1658 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001659
1660#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001661 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1662 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1663 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1664 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1665 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1666 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001667
1668#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001669 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1670 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1671 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001672
1673#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001674 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1675 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1676 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001677
1678#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001679 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1680 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1681 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001682
1683#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001684 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1685 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1686 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001687
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001688#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001689 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1690 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1691 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1692 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1693 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1694 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1695 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1696 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1697 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1698 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1699 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1700 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1701 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1702 BIT_ULL(POWER_DOMAIN_VGA) | \
1703 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1704 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1705 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1706 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1707 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1708 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001709
Daniel Vetter9c065a72014-09-30 10:56:38 +02001710#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001711 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1712 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1713 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1714 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1715 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001716
1717#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001718 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1719 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1720 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001721
Imre Deak965a79a2017-07-06 17:40:40 +03001722#define HSW_DISPLAY_POWER_DOMAINS ( \
1723 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1724 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1725 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1726 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1727 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1728 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1729 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1730 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1731 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1732 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1733 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1734 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1735 BIT_ULL(POWER_DOMAIN_VGA) | \
1736 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1737 BIT_ULL(POWER_DOMAIN_INIT))
1738
1739#define BDW_DISPLAY_POWER_DOMAINS ( \
1740 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1741 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1742 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1743 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1744 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1745 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1746 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1747 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1748 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1749 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1750 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1751 BIT_ULL(POWER_DOMAIN_VGA) | \
1752 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1753 BIT_ULL(POWER_DOMAIN_INIT))
1754
1755#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1756 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1757 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1758 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1759 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1760 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1761 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1762 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1763 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1764 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1765 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1766 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1767 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1768 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1769 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1770 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1771 BIT_ULL(POWER_DOMAIN_VGA) | \
1772 BIT_ULL(POWER_DOMAIN_INIT))
1773#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
1774 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
1775 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1776 BIT_ULL(POWER_DOMAIN_INIT))
1777#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1778 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1779 BIT_ULL(POWER_DOMAIN_INIT))
1780#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1781 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1782 BIT_ULL(POWER_DOMAIN_INIT))
1783#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
1784 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1785 BIT_ULL(POWER_DOMAIN_INIT))
1786#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1787 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001788 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001789 BIT_ULL(POWER_DOMAIN_MODESET) | \
1790 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1791 BIT_ULL(POWER_DOMAIN_INIT))
1792
1793#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1794 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1795 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1796 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1797 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1798 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1799 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1800 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1801 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1802 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1803 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1804 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1805 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1806 BIT_ULL(POWER_DOMAIN_VGA) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001807 BIT_ULL(POWER_DOMAIN_INIT))
1808#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1809 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001810 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001811 BIT_ULL(POWER_DOMAIN_MODESET) | \
1812 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä54c105d2017-12-08 23:37:37 +02001813 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001814 BIT_ULL(POWER_DOMAIN_INIT))
1815#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
1816 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1817 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1818 BIT_ULL(POWER_DOMAIN_INIT))
1819#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
1820 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1821 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1822 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1823 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1824 BIT_ULL(POWER_DOMAIN_INIT))
1825
1826#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1827 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1828 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1829 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1830 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1831 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1832 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1833 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1834 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1835 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1836 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1837 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1838 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1839 BIT_ULL(POWER_DOMAIN_VGA) | \
1840 BIT_ULL(POWER_DOMAIN_INIT))
1841#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
1842 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
1843#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1844 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
1845#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1846 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
1847#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
1848 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1849 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1850 BIT_ULL(POWER_DOMAIN_INIT))
1851#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
1852 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1853 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1854 BIT_ULL(POWER_DOMAIN_INIT))
1855#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
1856 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1857 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1858 BIT_ULL(POWER_DOMAIN_INIT))
1859#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
1860 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Imre Deak52528052018-06-21 21:44:49 +03001861 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001862 BIT_ULL(POWER_DOMAIN_INIT))
1863#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
1864 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1865 BIT_ULL(POWER_DOMAIN_INIT))
1866#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
1867 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1868 BIT_ULL(POWER_DOMAIN_INIT))
1869#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1870 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001871 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001872 BIT_ULL(POWER_DOMAIN_MODESET) | \
1873 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä156961a2017-12-08 23:37:36 +02001874 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001875 BIT_ULL(POWER_DOMAIN_INIT))
1876
1877#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1878 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1879 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1880 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1881 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1882 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1883 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1884 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1885 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1886 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1887 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001888 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001889 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1890 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1891 BIT_ULL(POWER_DOMAIN_AUX_D) | \
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001892 BIT_ULL(POWER_DOMAIN_AUX_F) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001893 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1894 BIT_ULL(POWER_DOMAIN_VGA) | \
1895 BIT_ULL(POWER_DOMAIN_INIT))
1896#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
1897 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001898 BIT_ULL(POWER_DOMAIN_INIT))
1899#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
1900 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1901 BIT_ULL(POWER_DOMAIN_INIT))
1902#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
1903 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1904 BIT_ULL(POWER_DOMAIN_INIT))
1905#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
1906 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1907 BIT_ULL(POWER_DOMAIN_INIT))
1908#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
1909 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Dhinakaran Pandiyanb891d5e2018-02-23 14:15:15 -08001910 BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001911 BIT_ULL(POWER_DOMAIN_INIT))
1912#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
1913 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1914 BIT_ULL(POWER_DOMAIN_INIT))
1915#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
1916 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1917 BIT_ULL(POWER_DOMAIN_INIT))
1918#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
1919 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1920 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivia324fca2018-01-29 15:22:15 -08001921#define CNL_DISPLAY_AUX_F_POWER_DOMAINS ( \
1922 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1923 BIT_ULL(POWER_DOMAIN_INIT))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08001924#define CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS ( \
1925 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1926 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak965a79a2017-07-06 17:40:40 +03001927#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1928 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulin6e7a3f52018-01-11 08:24:17 +00001929 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001930 BIT_ULL(POWER_DOMAIN_MODESET) | \
1931 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001932 BIT_ULL(POWER_DOMAIN_INIT))
1933
Imre Deak67ca07e2018-06-26 17:22:32 +03001934/*
1935 * ICL PW_0/PG_0 domains (HW/DMC control):
1936 * - PCI
1937 * - clocks except port PLL
1938 * - central power except FBC
1939 * - shared functions except pipe interrupts, pipe MBUS, DBUF registers
1940 * ICL PW_1/PG_1 domains (HW/DMC control):
1941 * - DBUF function
1942 * - PIPE_A and its planes, except VGA
1943 * - transcoder EDP + PSR
1944 * - transcoder DSI
1945 * - DDI_A
1946 * - FBC
1947 */
1948#define ICL_PW_4_POWER_DOMAINS ( \
1949 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1950 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1951 BIT_ULL(POWER_DOMAIN_INIT))
1952 /* VDSC/joining */
1953#define ICL_PW_3_POWER_DOMAINS ( \
1954 ICL_PW_4_POWER_DOMAINS | \
1955 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1956 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1957 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1958 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1959 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1960 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1961 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1962 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1963 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1964 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1965 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1966 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1967 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1968 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
1969 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
1970 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1971 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1972 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1973 BIT_ULL(POWER_DOMAIN_AUX_E) | \
1974 BIT_ULL(POWER_DOMAIN_AUX_F) | \
1975 BIT_ULL(POWER_DOMAIN_AUX_TBT1) | \
1976 BIT_ULL(POWER_DOMAIN_AUX_TBT2) | \
1977 BIT_ULL(POWER_DOMAIN_AUX_TBT3) | \
1978 BIT_ULL(POWER_DOMAIN_AUX_TBT4) | \
1979 BIT_ULL(POWER_DOMAIN_VGA) | \
1980 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1981 BIT_ULL(POWER_DOMAIN_INIT))
1982 /*
1983 * - transcoder WD
1984 * - KVMR (HW control)
1985 */
1986#define ICL_PW_2_POWER_DOMAINS ( \
1987 ICL_PW_3_POWER_DOMAINS | \
1988 BIT_ULL(POWER_DOMAIN_INIT))
1989 /*
1990 * - eDP/DSI VDSC
1991 * - KVMR (HW control)
1992 */
1993#define ICL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1994 ICL_PW_2_POWER_DOMAINS | \
1995 BIT_ULL(POWER_DOMAIN_MODESET) | \
1996 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1997 BIT_ULL(POWER_DOMAIN_INIT))
1998
1999#define ICL_DDI_IO_A_POWER_DOMAINS ( \
2000 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
2001#define ICL_DDI_IO_B_POWER_DOMAINS ( \
2002 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
2003#define ICL_DDI_IO_C_POWER_DOMAINS ( \
2004 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
2005#define ICL_DDI_IO_D_POWER_DOMAINS ( \
2006 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO))
2007#define ICL_DDI_IO_E_POWER_DOMAINS ( \
2008 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO))
2009#define ICL_DDI_IO_F_POWER_DOMAINS ( \
2010 BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO))
2011
2012#define ICL_AUX_A_IO_POWER_DOMAINS ( \
2013 BIT_ULL(POWER_DOMAIN_AUX_A))
2014#define ICL_AUX_B_IO_POWER_DOMAINS ( \
2015 BIT_ULL(POWER_DOMAIN_AUX_B))
2016#define ICL_AUX_C_IO_POWER_DOMAINS ( \
2017 BIT_ULL(POWER_DOMAIN_AUX_C))
2018#define ICL_AUX_D_IO_POWER_DOMAINS ( \
2019 BIT_ULL(POWER_DOMAIN_AUX_D))
2020#define ICL_AUX_E_IO_POWER_DOMAINS ( \
2021 BIT_ULL(POWER_DOMAIN_AUX_E))
2022#define ICL_AUX_F_IO_POWER_DOMAINS ( \
2023 BIT_ULL(POWER_DOMAIN_AUX_F))
2024#define ICL_AUX_TBT1_IO_POWER_DOMAINS ( \
2025 BIT_ULL(POWER_DOMAIN_AUX_TBT1))
2026#define ICL_AUX_TBT2_IO_POWER_DOMAINS ( \
2027 BIT_ULL(POWER_DOMAIN_AUX_TBT2))
2028#define ICL_AUX_TBT3_IO_POWER_DOMAINS ( \
2029 BIT_ULL(POWER_DOMAIN_AUX_TBT3))
2030#define ICL_AUX_TBT4_IO_POWER_DOMAINS ( \
2031 BIT_ULL(POWER_DOMAIN_AUX_TBT4))
2032
Daniel Vetter9c065a72014-09-30 10:56:38 +02002033static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002034 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002035 .enable = i9xx_always_on_power_well_noop,
2036 .disable = i9xx_always_on_power_well_noop,
2037 .is_enabled = i9xx_always_on_power_well_enabled,
2038};
2039
2040static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002041 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002042 .enable = chv_pipe_power_well_enable,
2043 .disable = chv_pipe_power_well_disable,
2044 .is_enabled = chv_pipe_power_well_enabled,
2045};
2046
2047static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002048 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002049 .enable = chv_dpio_cmn_power_well_enable,
2050 .disable = chv_dpio_cmn_power_well_disable,
2051 .is_enabled = vlv_power_well_enabled,
2052};
2053
2054static struct i915_power_well i9xx_always_on_power_well[] = {
2055 {
2056 .name = "always-on",
2057 .always_on = 1,
2058 .domains = POWER_DOMAIN_MASK,
2059 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002060 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002061 },
2062};
2063
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002064static const struct i915_power_well_ops i830_pipes_power_well_ops = {
2065 .sync_hw = i830_pipes_power_well_sync_hw,
2066 .enable = i830_pipes_power_well_enable,
2067 .disable = i830_pipes_power_well_disable,
2068 .is_enabled = i830_pipes_power_well_enabled,
2069};
2070
2071static struct i915_power_well i830_power_wells[] = {
2072 {
2073 .name = "always-on",
2074 .always_on = 1,
2075 .domains = POWER_DOMAIN_MASK,
2076 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002077 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002078 },
2079 {
2080 .name = "pipes",
2081 .domains = I830_PIPES_POWER_DOMAINS,
2082 .ops = &i830_pipes_power_well_ops,
Imre Deak120b56a2017-07-11 23:42:31 +03002083 .id = I830_DISP_PW_PIPES,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002084 },
2085};
2086
Daniel Vetter9c065a72014-09-30 10:56:38 +02002087static const struct i915_power_well_ops hsw_power_well_ops = {
2088 .sync_hw = hsw_power_well_sync_hw,
2089 .enable = hsw_power_well_enable,
2090 .disable = hsw_power_well_disable,
2091 .is_enabled = hsw_power_well_enabled,
2092};
2093
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002094static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002095 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002096 .enable = gen9_dc_off_power_well_enable,
2097 .disable = gen9_dc_off_power_well_disable,
2098 .is_enabled = gen9_dc_off_power_well_enabled,
2099};
2100
Imre Deak9c8d0b82016-06-13 16:44:34 +03002101static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002102 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002103 .enable = bxt_dpio_cmn_power_well_enable,
2104 .disable = bxt_dpio_cmn_power_well_disable,
2105 .is_enabled = bxt_dpio_cmn_power_well_enabled,
2106};
2107
Daniel Vetter9c065a72014-09-30 10:56:38 +02002108static struct i915_power_well hsw_power_wells[] = {
2109 {
2110 .name = "always-on",
2111 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002112 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002113 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002114 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002115 },
2116 {
2117 .name = "display",
2118 .domains = HSW_DISPLAY_POWER_DOMAINS,
2119 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002120 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002121 {
2122 .hsw.has_vga = true,
2123 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002124 },
2125};
2126
2127static struct i915_power_well bdw_power_wells[] = {
2128 {
2129 .name = "always-on",
2130 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002131 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002132 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002133 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002134 },
2135 {
2136 .name = "display",
2137 .domains = BDW_DISPLAY_POWER_DOMAINS,
2138 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03002139 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03002140 {
2141 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2142 .hsw.has_vga = true,
2143 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002144 },
2145};
2146
2147static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002148 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002149 .enable = vlv_display_power_well_enable,
2150 .disable = vlv_display_power_well_disable,
2151 .is_enabled = vlv_power_well_enabled,
2152};
2153
2154static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002155 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002156 .enable = vlv_dpio_cmn_power_well_enable,
2157 .disable = vlv_dpio_cmn_power_well_disable,
2158 .is_enabled = vlv_power_well_enabled,
2159};
2160
2161static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02002162 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002163 .enable = vlv_power_well_enable,
2164 .disable = vlv_power_well_disable,
2165 .is_enabled = vlv_power_well_enabled,
2166};
2167
2168static struct i915_power_well vlv_power_wells[] = {
2169 {
2170 .name = "always-on",
2171 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002172 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002173 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002174 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002175 },
2176 {
2177 .name = "display",
2178 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002179 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002180 .ops = &vlv_display_power_well_ops,
2181 },
2182 {
2183 .name = "dpio-tx-b-01",
2184 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2185 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2186 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2187 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2188 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002189 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002190 },
2191 {
2192 .name = "dpio-tx-b-23",
2193 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2194 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2195 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2196 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2197 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002198 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002199 },
2200 {
2201 .name = "dpio-tx-c-01",
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_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002208 },
2209 {
2210 .name = "dpio-tx-c-23",
2211 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2212 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2213 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2214 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2215 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002216 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002217 },
2218 {
2219 .name = "dpio-common",
2220 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002221 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002222 .ops = &vlv_dpio_cmn_power_well_ops,
2223 },
2224};
2225
2226static struct i915_power_well chv_power_wells[] = {
2227 {
2228 .name = "always-on",
2229 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002230 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002231 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002232 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002233 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002234 {
2235 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002236 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002237 * Pipe A power well is the new disp2d well. Pipe B and C
2238 * power wells don't actually exist. Pipe A power well is
2239 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002240 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002241 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002242 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002243 .ops = &chv_pipe_power_well_ops,
2244 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002245 {
2246 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002247 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002248 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002249 .ops = &chv_dpio_cmn_power_well_ops,
2250 },
2251 {
2252 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002253 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002254 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002255 .ops = &chv_dpio_cmn_power_well_ops,
2256 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002257};
2258
Suketu Shah5aefb232015-04-16 14:22:10 +05302259bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002260 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302261{
2262 struct i915_power_well *power_well;
2263 bool ret;
2264
2265 power_well = lookup_power_well(dev_priv, power_well_id);
2266 ret = power_well->ops->is_enabled(dev_priv, power_well);
2267
2268 return ret;
2269}
2270
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002271static struct i915_power_well skl_power_wells[] = {
2272 {
2273 .name = "always-on",
2274 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002275 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002276 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002277 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002278 },
2279 {
2280 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002281 /* Handled by the DMC firmware */
2282 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002283 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002284 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002285 {
2286 .hsw.has_fuses = true,
2287 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002288 },
2289 {
2290 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002291 /* Handled by the DMC firmware */
2292 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002293 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002294 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002295 },
2296 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002297 .name = "DC off",
2298 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2299 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002300 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002301 },
2302 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002303 .name = "power well 2",
2304 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002305 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002306 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002307 {
2308 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2309 .hsw.has_vga = true,
2310 .hsw.has_fuses = true,
2311 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002312 },
2313 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002314 .name = "DDI A/E IO power well",
2315 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002316 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002317 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002318 },
2319 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002320 .name = "DDI B IO power well",
2321 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002322 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002323 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002324 },
2325 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002326 .name = "DDI C IO power well",
2327 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002328 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002329 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002330 },
2331 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002332 .name = "DDI D IO power well",
2333 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002334 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002335 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002336 },
2337};
2338
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302339static struct i915_power_well bxt_power_wells[] = {
2340 {
2341 .name = "always-on",
2342 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002343 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302344 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002345 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302346 },
2347 {
2348 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002349 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002350 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002351 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002352 {
2353 .hsw.has_fuses = true,
2354 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302355 },
2356 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002357 .name = "DC off",
2358 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2359 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002360 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002361 },
2362 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302363 .name = "power well 2",
2364 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002365 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002366 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002367 {
2368 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2369 .hsw.has_vga = true,
2370 .hsw.has_fuses = true,
2371 },
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002372 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002373 {
2374 .name = "dpio-common-a",
2375 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2376 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002377 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002378 {
2379 .bxt.phy = DPIO_PHY1,
2380 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002381 },
2382 {
2383 .name = "dpio-common-bc",
2384 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2385 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002386 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002387 {
2388 .bxt.phy = DPIO_PHY0,
2389 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002390 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302391};
2392
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002393static struct i915_power_well glk_power_wells[] = {
2394 {
2395 .name = "always-on",
2396 .always_on = 1,
2397 .domains = POWER_DOMAIN_MASK,
2398 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002399 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002400 },
2401 {
2402 .name = "power well 1",
2403 /* Handled by the DMC firmware */
2404 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002405 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002406 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002407 {
2408 .hsw.has_fuses = true,
2409 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002410 },
2411 {
2412 .name = "DC off",
2413 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2414 .ops = &gen9_dc_off_power_well_ops,
2415 .id = SKL_DISP_PW_DC_OFF,
2416 },
2417 {
2418 .name = "power well 2",
2419 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002420 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002421 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002422 {
2423 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2424 .hsw.has_vga = true,
2425 .hsw.has_fuses = true,
2426 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002427 },
2428 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002429 .name = "dpio-common-a",
2430 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2431 .ops = &bxt_dpio_cmn_power_well_ops,
2432 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002433 {
2434 .bxt.phy = DPIO_PHY1,
2435 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002436 },
2437 {
2438 .name = "dpio-common-b",
2439 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2440 .ops = &bxt_dpio_cmn_power_well_ops,
2441 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002442 {
2443 .bxt.phy = DPIO_PHY0,
2444 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002445 },
2446 {
2447 .name = "dpio-common-c",
2448 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2449 .ops = &bxt_dpio_cmn_power_well_ops,
2450 .id = GLK_DPIO_CMN_C,
Imre Deak0a445942017-08-14 18:15:29 +03002451 {
2452 .bxt.phy = DPIO_PHY2,
2453 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002454 },
2455 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002456 .name = "AUX A",
2457 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002458 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002459 .id = GLK_DISP_PW_AUX_A,
2460 },
2461 {
2462 .name = "AUX B",
2463 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002464 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002465 .id = GLK_DISP_PW_AUX_B,
2466 },
2467 {
2468 .name = "AUX C",
2469 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002470 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002471 .id = GLK_DISP_PW_AUX_C,
2472 },
2473 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002474 .name = "DDI A IO power well",
2475 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002476 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002477 .id = GLK_DISP_PW_DDI_A,
2478 },
2479 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002480 .name = "DDI B IO power well",
2481 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002482 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002483 .id = SKL_DISP_PW_DDI_B,
2484 },
2485 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002486 .name = "DDI C IO power well",
2487 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002488 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002489 .id = SKL_DISP_PW_DDI_C,
2490 },
2491};
2492
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002493static struct i915_power_well cnl_power_wells[] = {
2494 {
2495 .name = "always-on",
2496 .always_on = 1,
2497 .domains = POWER_DOMAIN_MASK,
2498 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002499 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002500 },
2501 {
2502 .name = "power well 1",
2503 /* Handled by the DMC firmware */
2504 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002505 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002506 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002507 {
2508 .hsw.has_fuses = true,
2509 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002510 },
2511 {
2512 .name = "AUX A",
2513 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002514 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002515 .id = CNL_DISP_PW_AUX_A,
2516 },
2517 {
2518 .name = "AUX B",
2519 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002520 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002521 .id = CNL_DISP_PW_AUX_B,
2522 },
2523 {
2524 .name = "AUX C",
2525 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002526 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002527 .id = CNL_DISP_PW_AUX_C,
2528 },
2529 {
2530 .name = "AUX D",
2531 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002532 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002533 .id = CNL_DISP_PW_AUX_D,
2534 },
2535 {
2536 .name = "DC off",
2537 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2538 .ops = &gen9_dc_off_power_well_ops,
2539 .id = SKL_DISP_PW_DC_OFF,
2540 },
2541 {
2542 .name = "power well 2",
2543 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002544 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002545 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002546 {
2547 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2548 .hsw.has_vga = true,
2549 .hsw.has_fuses = true,
2550 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002551 },
2552 {
2553 .name = "DDI A IO power well",
2554 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002555 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002556 .id = CNL_DISP_PW_DDI_A,
2557 },
2558 {
2559 .name = "DDI B IO power well",
2560 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002561 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002562 .id = SKL_DISP_PW_DDI_B,
2563 },
2564 {
2565 .name = "DDI C IO power well",
2566 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002567 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002568 .id = SKL_DISP_PW_DDI_C,
2569 },
2570 {
2571 .name = "DDI D IO power well",
2572 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002573 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002574 .id = SKL_DISP_PW_DDI_D,
2575 },
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002576 {
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002577 .name = "DDI F IO power well",
2578 .domains = CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS,
2579 .ops = &hsw_power_well_ops,
2580 .id = CNL_DISP_PW_DDI_F,
2581 },
2582 {
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002583 .name = "AUX F",
2584 .domains = CNL_DISPLAY_AUX_F_POWER_DOMAINS,
2585 .ops = &hsw_power_well_ops,
2586 .id = CNL_DISP_PW_AUX_F,
2587 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002588};
2589
Imre Deak67ca07e2018-06-26 17:22:32 +03002590static const struct i915_power_well_ops icl_combo_phy_aux_power_well_ops = {
2591 .sync_hw = hsw_power_well_sync_hw,
2592 .enable = icl_combo_phy_aux_power_well_enable,
2593 .disable = icl_combo_phy_aux_power_well_disable,
2594 .is_enabled = hsw_power_well_enabled,
2595};
2596
2597static struct i915_power_well icl_power_wells[] = {
2598 {
2599 .name = "always-on",
2600 .always_on = 1,
2601 .domains = POWER_DOMAIN_MASK,
2602 .ops = &i9xx_always_on_power_well_ops,
2603 .id = I915_DISP_PW_ALWAYS_ON,
2604 },
2605 {
2606 .name = "power well 1",
2607 /* Handled by the DMC firmware */
2608 .domains = 0,
2609 .ops = &hsw_power_well_ops,
2610 .id = ICL_DISP_PW_1,
Imre Deakae9b06c2018-08-06 12:58:34 +03002611 {
2612 .hsw.has_fuses = true,
2613 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002614 },
2615 {
2616 .name = "power well 2",
2617 .domains = ICL_PW_2_POWER_DOMAINS,
2618 .ops = &hsw_power_well_ops,
2619 .id = ICL_DISP_PW_2,
Imre Deakae9b06c2018-08-06 12:58:34 +03002620 {
2621 .hsw.has_fuses = true,
2622 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002623 },
2624 {
2625 .name = "DC off",
2626 .domains = ICL_DISPLAY_DC_OFF_POWER_DOMAINS,
2627 .ops = &gen9_dc_off_power_well_ops,
2628 .id = SKL_DISP_PW_DC_OFF,
2629 },
2630 {
2631 .name = "power well 3",
2632 .domains = ICL_PW_3_POWER_DOMAINS,
2633 .ops = &hsw_power_well_ops,
2634 .id = ICL_DISP_PW_3,
Imre Deakae9b06c2018-08-06 12:58:34 +03002635 {
2636 .hsw.irq_pipe_mask = BIT(PIPE_B),
2637 .hsw.has_vga = true,
2638 .hsw.has_fuses = true,
2639 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002640 },
2641 {
2642 .name = "DDI A IO",
2643 .domains = ICL_DDI_IO_A_POWER_DOMAINS,
2644 .ops = &hsw_power_well_ops,
2645 .id = ICL_DISP_PW_DDI_A,
2646 },
2647 {
2648 .name = "DDI B IO",
2649 .domains = ICL_DDI_IO_B_POWER_DOMAINS,
2650 .ops = &hsw_power_well_ops,
2651 .id = ICL_DISP_PW_DDI_B,
2652 },
2653 {
2654 .name = "DDI C IO",
2655 .domains = ICL_DDI_IO_C_POWER_DOMAINS,
2656 .ops = &hsw_power_well_ops,
2657 .id = ICL_DISP_PW_DDI_C,
2658 },
2659 {
2660 .name = "DDI D IO",
2661 .domains = ICL_DDI_IO_D_POWER_DOMAINS,
2662 .ops = &hsw_power_well_ops,
2663 .id = ICL_DISP_PW_DDI_D,
2664 },
2665 {
2666 .name = "DDI E IO",
2667 .domains = ICL_DDI_IO_E_POWER_DOMAINS,
2668 .ops = &hsw_power_well_ops,
2669 .id = ICL_DISP_PW_DDI_E,
2670 },
2671 {
2672 .name = "DDI F IO",
2673 .domains = ICL_DDI_IO_F_POWER_DOMAINS,
2674 .ops = &hsw_power_well_ops,
2675 .id = ICL_DISP_PW_DDI_F,
2676 },
2677 {
2678 .name = "AUX A",
2679 .domains = ICL_AUX_A_IO_POWER_DOMAINS,
2680 .ops = &icl_combo_phy_aux_power_well_ops,
2681 .id = ICL_DISP_PW_AUX_A,
2682 },
2683 {
2684 .name = "AUX B",
2685 .domains = ICL_AUX_B_IO_POWER_DOMAINS,
2686 .ops = &icl_combo_phy_aux_power_well_ops,
2687 .id = ICL_DISP_PW_AUX_B,
2688 },
2689 {
2690 .name = "AUX C",
2691 .domains = ICL_AUX_C_IO_POWER_DOMAINS,
2692 .ops = &hsw_power_well_ops,
2693 .id = ICL_DISP_PW_AUX_C,
2694 },
2695 {
2696 .name = "AUX D",
2697 .domains = ICL_AUX_D_IO_POWER_DOMAINS,
2698 .ops = &hsw_power_well_ops,
2699 .id = ICL_DISP_PW_AUX_D,
2700 },
2701 {
2702 .name = "AUX E",
2703 .domains = ICL_AUX_E_IO_POWER_DOMAINS,
2704 .ops = &hsw_power_well_ops,
2705 .id = ICL_DISP_PW_AUX_E,
2706 },
2707 {
2708 .name = "AUX F",
2709 .domains = ICL_AUX_F_IO_POWER_DOMAINS,
2710 .ops = &hsw_power_well_ops,
2711 .id = ICL_DISP_PW_AUX_F,
2712 },
2713 {
2714 .name = "AUX TBT1",
2715 .domains = ICL_AUX_TBT1_IO_POWER_DOMAINS,
2716 .ops = &hsw_power_well_ops,
2717 .id = ICL_DISP_PW_AUX_TBT1,
2718 },
2719 {
2720 .name = "AUX TBT2",
2721 .domains = ICL_AUX_TBT2_IO_POWER_DOMAINS,
2722 .ops = &hsw_power_well_ops,
2723 .id = ICL_DISP_PW_AUX_TBT2,
2724 },
2725 {
2726 .name = "AUX TBT3",
2727 .domains = ICL_AUX_TBT3_IO_POWER_DOMAINS,
2728 .ops = &hsw_power_well_ops,
2729 .id = ICL_DISP_PW_AUX_TBT3,
2730 },
2731 {
2732 .name = "AUX TBT4",
2733 .domains = ICL_AUX_TBT4_IO_POWER_DOMAINS,
2734 .ops = &hsw_power_well_ops,
2735 .id = ICL_DISP_PW_AUX_TBT4,
2736 },
2737 {
2738 .name = "power well 4",
2739 .domains = ICL_PW_4_POWER_DOMAINS,
2740 .ops = &hsw_power_well_ops,
2741 .id = ICL_DISP_PW_4,
Imre Deakae9b06c2018-08-06 12:58:34 +03002742 {
2743 .hsw.has_fuses = true,
2744 .hsw.irq_pipe_mask = BIT(PIPE_C),
2745 },
Imre Deak67ca07e2018-06-26 17:22:32 +03002746 },
2747};
2748
Imre Deak1b0e3a02015-11-05 23:04:11 +02002749static int
2750sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2751 int disable_power_well)
2752{
2753 if (disable_power_well >= 0)
2754 return !!disable_power_well;
2755
Imre Deak1b0e3a02015-11-05 23:04:11 +02002756 return 1;
2757}
2758
Imre Deaka37baf32016-02-29 22:49:03 +02002759static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2760 int enable_dc)
2761{
2762 uint32_t mask;
2763 int requested_dc;
2764 int max_dc;
2765
Imre Deak67ca07e2018-06-26 17:22:32 +03002766 if (IS_GEN9_BC(dev_priv) || INTEL_INFO(dev_priv)->gen >= 10) {
Imre Deaka37baf32016-02-29 22:49:03 +02002767 max_dc = 2;
2768 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002769 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002770 max_dc = 1;
2771 /*
2772 * DC9 has a separate HW flow from the rest of the DC states,
2773 * not depending on the DMC firmware. It's needed by system
2774 * suspend/resume, so allow it unconditionally.
2775 */
2776 mask = DC_STATE_EN_DC9;
2777 } else {
2778 max_dc = 0;
2779 mask = 0;
2780 }
2781
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002782 if (!i915_modparams.disable_power_well)
Imre Deak66e2c4c2016-02-29 22:49:04 +02002783 max_dc = 0;
2784
Imre Deaka37baf32016-02-29 22:49:03 +02002785 if (enable_dc >= 0 && enable_dc <= max_dc) {
2786 requested_dc = enable_dc;
2787 } else if (enable_dc == -1) {
2788 requested_dc = max_dc;
2789 } else if (enable_dc > max_dc && enable_dc <= 2) {
2790 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2791 enable_dc, max_dc);
2792 requested_dc = max_dc;
2793 } else {
2794 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2795 requested_dc = max_dc;
2796 }
2797
2798 if (requested_dc > 1)
2799 mask |= DC_STATE_EN_UPTO_DC6;
2800 if (requested_dc > 0)
2801 mask |= DC_STATE_EN_UPTO_DC5;
2802
2803 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2804
2805 return mask;
2806}
2807
Imre Deak21792c62017-07-11 23:42:33 +03002808static void assert_power_well_ids_unique(struct drm_i915_private *dev_priv)
2809{
2810 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2811 u64 power_well_ids;
2812 int i;
2813
2814 power_well_ids = 0;
2815 for (i = 0; i < power_domains->power_well_count; i++) {
2816 enum i915_power_well_id id = power_domains->power_wells[i].id;
2817
2818 WARN_ON(id >= sizeof(power_well_ids) * 8);
2819 WARN_ON(power_well_ids & BIT_ULL(id));
2820 power_well_ids |= BIT_ULL(id);
2821 }
2822}
2823
Daniel Vetter9c065a72014-09-30 10:56:38 +02002824#define set_power_wells(power_domains, __power_wells) ({ \
2825 (power_domains)->power_wells = (__power_wells); \
2826 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2827})
2828
Daniel Vettere4e76842014-09-30 10:56:42 +02002829/**
2830 * intel_power_domains_init - initializes the power domain structures
2831 * @dev_priv: i915 device instance
2832 *
2833 * Initializes the power domain structures for @dev_priv depending upon the
2834 * supported platform.
2835 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002836int intel_power_domains_init(struct drm_i915_private *dev_priv)
2837{
2838 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2839
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002840 i915_modparams.disable_power_well =
2841 sanitize_disable_power_well_option(dev_priv,
2842 i915_modparams.disable_power_well);
2843 dev_priv->csr.allowed_dc_mask =
2844 get_allowed_dc_mask(dev_priv, i915_modparams.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002845
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002846 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002847
Daniel Vetter9c065a72014-09-30 10:56:38 +02002848 mutex_init(&power_domains->lock);
2849
2850 /*
2851 * The enabling order will be from lower to higher indexed wells,
2852 * the disabling order is reversed.
2853 */
Imre Deak67ca07e2018-06-26 17:22:32 +03002854 if (IS_ICELAKE(dev_priv)) {
2855 set_power_wells(power_domains, icl_power_wells);
2856 } else if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002857 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002858 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002859 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002860 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002861 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002862 } else if (IS_CANNONLAKE(dev_priv)) {
2863 set_power_wells(power_domains, cnl_power_wells);
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002864
2865 /*
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002866 * DDI and Aux IO are getting enabled for all ports
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002867 * regardless the presence or use. So, in order to avoid
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002868 * timeouts, lets remove them from the list
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002869 * for the SKUs without port F.
2870 */
2871 if (!IS_CNL_WITH_PORT_F(dev_priv))
Rodrigo Vivi9787e832018-01-29 15:22:22 -08002872 power_domains->power_well_count -= 2;
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002873
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002874 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302875 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002876 } else if (IS_GEMINILAKE(dev_priv)) {
2877 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002878 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002879 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002880 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002881 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002882 } else if (IS_I830(dev_priv)) {
2883 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002884 } else {
2885 set_power_wells(power_domains, i9xx_always_on_power_well);
2886 }
2887
Imre Deak21792c62017-07-11 23:42:33 +03002888 assert_power_well_ids_unique(dev_priv);
2889
Daniel Vetter9c065a72014-09-30 10:56:38 +02002890 return 0;
2891}
2892
Imre Deak30eade12015-11-04 19:24:13 +02002893static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002894{
2895 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2896 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002897
2898 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002899 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002900 power_well->ops->sync_hw(dev_priv, power_well);
2901 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2902 power_well);
2903 }
2904 mutex_unlock(&power_domains->lock);
2905}
2906
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302907static inline
2908bool intel_dbuf_slice_set(struct drm_i915_private *dev_priv,
2909 i915_reg_t reg, bool enable)
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002910{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302911 u32 val, status;
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002912
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302913 val = I915_READ(reg);
2914 val = enable ? (val | DBUF_POWER_REQUEST) : (val & ~DBUF_POWER_REQUEST);
2915 I915_WRITE(reg, val);
2916 POSTING_READ(reg);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002917 udelay(10);
2918
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302919 status = I915_READ(reg) & DBUF_POWER_STATE;
2920 if ((enable && !status) || (!enable && status)) {
2921 DRM_ERROR("DBus power %s timeout!\n",
2922 enable ? "enable" : "disable");
2923 return false;
2924 }
2925 return true;
2926}
2927
2928static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2929{
2930 intel_dbuf_slice_set(dev_priv, DBUF_CTL, true);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002931}
2932
2933static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2934{
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302935 intel_dbuf_slice_set(dev_priv, DBUF_CTL, false);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002936}
2937
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05302938static u8 intel_dbuf_max_slices(struct drm_i915_private *dev_priv)
2939{
2940 if (INTEL_GEN(dev_priv) < 11)
2941 return 1;
2942 return 2;
2943}
2944
2945void icl_dbuf_slices_update(struct drm_i915_private *dev_priv,
2946 u8 req_slices)
2947{
2948 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
2949 u32 val;
2950 bool ret;
2951
2952 if (req_slices > intel_dbuf_max_slices(dev_priv)) {
2953 DRM_ERROR("Invalid number of dbuf slices requested\n");
2954 return;
2955 }
2956
2957 if (req_slices == hw_enabled_slices || req_slices == 0)
2958 return;
2959
2960 val = I915_READ(DBUF_CTL_S2);
2961 if (req_slices > hw_enabled_slices)
2962 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, true);
2963 else
2964 ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, false);
2965
2966 if (ret)
2967 dev_priv->wm.skl_hw.ddb.enabled_slices = req_slices;
2968}
2969
Mahesh Kumar746edf82018-02-05 13:40:44 -02002970static void icl_dbuf_enable(struct drm_i915_private *dev_priv)
2971{
2972 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) | DBUF_POWER_REQUEST);
2973 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) | DBUF_POWER_REQUEST);
2974 POSTING_READ(DBUF_CTL_S2);
2975
2976 udelay(10);
2977
2978 if (!(I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
2979 !(I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
2980 DRM_ERROR("DBuf power enable timeout\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05302981 else
2982 dev_priv->wm.skl_hw.ddb.enabled_slices = 2;
Mahesh Kumar746edf82018-02-05 13:40:44 -02002983}
2984
2985static void icl_dbuf_disable(struct drm_i915_private *dev_priv)
2986{
2987 I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) & ~DBUF_POWER_REQUEST);
2988 I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) & ~DBUF_POWER_REQUEST);
2989 POSTING_READ(DBUF_CTL_S2);
2990
2991 udelay(10);
2992
2993 if ((I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
2994 (I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
2995 DRM_ERROR("DBuf power disable timeout!\n");
Mahesh Kumar74bd8002018-04-26 19:55:15 +05302996 else
2997 dev_priv->wm.skl_hw.ddb.enabled_slices = 0;
Mahesh Kumar746edf82018-02-05 13:40:44 -02002998}
2999
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003000static void icl_mbus_init(struct drm_i915_private *dev_priv)
3001{
3002 uint32_t val;
3003
3004 val = MBUS_ABOX_BT_CREDIT_POOL1(16) |
3005 MBUS_ABOX_BT_CREDIT_POOL2(16) |
3006 MBUS_ABOX_B_CREDIT(1) |
3007 MBUS_ABOX_BW_CREDIT(1);
3008
3009 I915_WRITE(MBUS_ABOX_CTL, val);
3010}
3011
Imre Deak73dfc222015-11-17 17:33:53 +02003012static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03003013 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02003014{
3015 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003016 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003017 uint32_t val;
3018
Imre Deakd26fa1d2015-11-04 19:24:17 +02003019 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3020
Imre Deak73dfc222015-11-17 17:33:53 +02003021 /* enable PCH reset handshake */
3022 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3023 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
3024
3025 /* enable PG1 and Misc I/O */
3026 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003027
3028 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3029 intel_power_well_enable(dev_priv, well);
3030
3031 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
3032 intel_power_well_enable(dev_priv, well);
3033
Imre Deak73dfc222015-11-17 17:33:53 +02003034 mutex_unlock(&power_domains->lock);
3035
Imre Deak73dfc222015-11-17 17:33:53 +02003036 skl_init_cdclk(dev_priv);
3037
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003038 gen9_dbuf_enable(dev_priv);
3039
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03003040 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02003041 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003042}
3043
3044static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
3045{
3046 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03003047 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02003048
Imre Deakd26fa1d2015-11-04 19:24:17 +02003049 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3050
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003051 gen9_dbuf_disable(dev_priv);
3052
Imre Deak73dfc222015-11-17 17:33:53 +02003053 skl_uninit_cdclk(dev_priv);
3054
3055 /* The spec doesn't call for removing the reset handshake flag */
3056 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03003057
Imre Deak73dfc222015-11-17 17:33:53 +02003058 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03003059
Imre Deakedfda8e2017-06-29 18:36:59 +03003060 /*
3061 * BSpec says to keep the MISC IO power well enabled here, only
3062 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03003063 * Note that even though the driver's request is removed power well 1
3064 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03003065 */
Imre Deak443a93a2016-04-04 15:42:57 +03003066 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3067 intel_power_well_disable(dev_priv, well);
3068
Imre Deak73dfc222015-11-17 17:33:53 +02003069 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003070
3071 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02003072}
3073
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003074void bxt_display_core_init(struct drm_i915_private *dev_priv,
3075 bool resume)
3076{
3077 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3078 struct i915_power_well *well;
3079 uint32_t val;
3080
3081 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3082
3083 /*
3084 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
3085 * or else the reset will hang because there is no PCH to respond.
3086 * Move the handshake programming to initialization sequence.
3087 * Previously was left up to BIOS.
3088 */
3089 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3090 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
3091 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3092
3093 /* Enable PG1 */
3094 mutex_lock(&power_domains->lock);
3095
3096 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3097 intel_power_well_enable(dev_priv, well);
3098
3099 mutex_unlock(&power_domains->lock);
3100
Imre Deak324513c2016-06-13 16:44:36 +03003101 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003102
3103 gen9_dbuf_enable(dev_priv);
3104
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003105 if (resume && dev_priv->csr.dmc_payload)
3106 intel_csr_load_program(dev_priv);
3107}
3108
3109void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
3110{
3111 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3112 struct i915_power_well *well;
3113
3114 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3115
Ville Syrjälä70c2c182016-05-13 23:41:30 +03003116 gen9_dbuf_disable(dev_priv);
3117
Imre Deak324513c2016-06-13 16:44:36 +03003118 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003119
3120 /* The spec doesn't call for removing the reset handshake flag */
3121
Imre Deak42d93662017-06-29 18:37:01 +03003122 /*
3123 * Disable PW1 (PG1).
3124 * Note that even though the driver's request is removed power well 1
3125 * may stay enabled after this due to DMC's own request on it.
3126 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003127 mutex_lock(&power_domains->lock);
3128
3129 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3130 intel_power_well_disable(dev_priv, well);
3131
3132 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03003133
3134 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003135}
3136
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003137enum {
3138 PROCMON_0_85V_DOT_0,
3139 PROCMON_0_95V_DOT_0,
3140 PROCMON_0_95V_DOT_1,
3141 PROCMON_1_05V_DOT_0,
3142 PROCMON_1_05V_DOT_1,
3143};
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003144
3145static const struct cnl_procmon {
3146 u32 dw1, dw9, dw10;
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003147} cnl_procmon_values[] = {
3148 [PROCMON_0_85V_DOT_0] =
3149 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
3150 [PROCMON_0_95V_DOT_0] =
3151 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
3152 [PROCMON_0_95V_DOT_1] =
3153 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
3154 [PROCMON_1_05V_DOT_0] =
3155 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
3156 [PROCMON_1_05V_DOT_1] =
3157 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003158};
3159
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003160/*
3161 * CNL has just one set of registers, while ICL has two sets: one for port A and
3162 * the other for port B. The CNL registers are equivalent to the ICL port A
3163 * registers, that's why we call the ICL macros even though the function has CNL
3164 * on its name.
3165 */
3166static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
3167 enum port port)
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003168{
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003169 const struct cnl_procmon *procmon;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003170 u32 val;
3171
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003172 val = I915_READ(ICL_PORT_COMP_DW3(port));
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003173 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
3174 default:
3175 MISSING_CASE(val);
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05003176 /* fall through */
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07003177 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
3178 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
3179 break;
3180 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
3181 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
3182 break;
3183 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
3184 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
3185 break;
3186 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
3187 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
3188 break;
3189 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
3190 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
3191 break;
3192 }
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003193
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003194 val = I915_READ(ICL_PORT_COMP_DW1(port));
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003195 val &= ~((0xff << 16) | 0xff);
3196 val |= procmon->dw1;
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003197 I915_WRITE(ICL_PORT_COMP_DW1(port), val);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003198
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003199 I915_WRITE(ICL_PORT_COMP_DW9(port), procmon->dw9);
3200 I915_WRITE(ICL_PORT_COMP_DW10(port), procmon->dw10);
Paulo Zanoniade5ee72017-08-21 17:03:56 -07003201}
3202
3203static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
3204{
3205 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3206 struct i915_power_well *well;
3207 u32 val;
3208
3209 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3210
3211 /* 1. Enable PCH Reset Handshake */
3212 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3213 val |= RESET_PCH_HANDSHAKE_ENABLE;
3214 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3215
3216 /* 2. Enable Comp */
3217 val = I915_READ(CHICKEN_MISC_2);
3218 val &= ~CNL_COMP_PWR_DOWN;
3219 I915_WRITE(CHICKEN_MISC_2, val);
3220
Paulo Zanoni62d4a5e2018-02-05 13:40:41 -02003221 /* Dummy PORT_A to get the correct CNL register from the ICL macro */
3222 cnl_set_procmon_ref_values(dev_priv, PORT_A);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003223
3224 val = I915_READ(CNL_PORT_COMP_DW0);
3225 val |= COMP_INIT;
3226 I915_WRITE(CNL_PORT_COMP_DW0, val);
3227
3228 /* 3. */
3229 val = I915_READ(CNL_PORT_CL1CM_DW5);
3230 val |= CL_POWER_DOWN_ENABLE;
3231 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
3232
Imre Deakb38131f2017-06-29 18:37:02 +03003233 /*
3234 * 4. Enable Power Well 1 (PG1).
3235 * The AUX IO power wells will be enabled on demand.
3236 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003237 mutex_lock(&power_domains->lock);
3238 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3239 intel_power_well_enable(dev_priv, well);
3240 mutex_unlock(&power_domains->lock);
3241
3242 /* 5. Enable CD clock */
3243 cnl_init_cdclk(dev_priv);
3244
3245 /* 6. Enable DBUF */
3246 gen9_dbuf_enable(dev_priv);
Imre Deak57522c42017-10-03 12:51:58 +03003247
3248 if (resume && dev_priv->csr.dmc_payload)
3249 intel_csr_load_program(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003250}
3251
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003252static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
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. Disable all display engine functions -> aready done */
3261
3262 /* 2. Disable DBUF */
3263 gen9_dbuf_disable(dev_priv);
3264
3265 /* 3. Disable CD clock */
3266 cnl_uninit_cdclk(dev_priv);
3267
Imre Deakb38131f2017-06-29 18:37:02 +03003268 /*
3269 * 4. Disable Power Well 1 (PG1).
3270 * The AUX IO power wells are toggled on demand, so they are already
3271 * disabled at this point.
3272 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003273 mutex_lock(&power_domains->lock);
3274 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
3275 intel_power_well_disable(dev_priv, well);
3276 mutex_unlock(&power_domains->lock);
3277
Imre Deak846c6b22017-06-29 18:36:58 +03003278 usleep_range(10, 30); /* 10 us delay per Bspec */
3279
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003280 /* 5. Disable Comp */
3281 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03003282 val |= CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003283 I915_WRITE(CHICKEN_MISC_2, val);
3284}
3285
Paulo Zanoniad186f32018-02-05 13:40:43 -02003286static void icl_display_core_init(struct drm_i915_private *dev_priv,
3287 bool resume)
3288{
Imre Deak67ca07e2018-06-26 17:22:32 +03003289 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3290 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003291 enum port port;
3292 u32 val;
3293
3294 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3295
3296 /* 1. Enable PCH reset handshake. */
3297 val = I915_READ(HSW_NDE_RSTWRN_OPT);
3298 val |= RESET_PCH_HANDSHAKE_ENABLE;
3299 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
3300
3301 for (port = PORT_A; port <= PORT_B; port++) {
3302 /* 2. Enable DDI combo PHY comp. */
3303 val = I915_READ(ICL_PHY_MISC(port));
3304 val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3305 I915_WRITE(ICL_PHY_MISC(port), val);
3306
3307 cnl_set_procmon_ref_values(dev_priv, port);
3308
3309 val = I915_READ(ICL_PORT_COMP_DW0(port));
3310 val |= COMP_INIT;
3311 I915_WRITE(ICL_PORT_COMP_DW0(port), val);
3312
3313 /* 3. Set power down enable. */
3314 val = I915_READ(ICL_PORT_CL_DW5(port));
3315 val |= CL_POWER_DOWN_ENABLE;
3316 I915_WRITE(ICL_PORT_CL_DW5(port), val);
3317 }
3318
Imre Deak67ca07e2018-06-26 17:22:32 +03003319 /*
3320 * 4. Enable Power Well 1 (PG1).
3321 * The AUX IO power wells will be enabled on demand.
3322 */
3323 mutex_lock(&power_domains->lock);
3324 well = lookup_power_well(dev_priv, ICL_DISP_PW_1);
3325 intel_power_well_enable(dev_priv, well);
3326 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003327
3328 /* 5. Enable CDCLK. */
3329 icl_init_cdclk(dev_priv);
3330
3331 /* 6. Enable DBUF. */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003332 icl_dbuf_enable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003333
3334 /* 7. Setup MBUS. */
Mahesh Kumar4cb45852018-02-05 13:40:45 -02003335 icl_mbus_init(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003336}
3337
3338static void icl_display_core_uninit(struct drm_i915_private *dev_priv)
3339{
Imre Deak67ca07e2018-06-26 17:22:32 +03003340 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3341 struct i915_power_well *well;
Paulo Zanoniad186f32018-02-05 13:40:43 -02003342 enum port port;
3343 u32 val;
3344
3345 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
3346
3347 /* 1. Disable all display engine functions -> aready done */
3348
3349 /* 2. Disable DBUF */
Mahesh Kumar746edf82018-02-05 13:40:44 -02003350 icl_dbuf_disable(dev_priv);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003351
3352 /* 3. Disable CD clock */
3353 icl_uninit_cdclk(dev_priv);
3354
Imre Deak67ca07e2018-06-26 17:22:32 +03003355 /*
3356 * 4. Disable Power Well 1 (PG1).
3357 * The AUX IO power wells are toggled on demand, so they are already
3358 * disabled at this point.
3359 */
3360 mutex_lock(&power_domains->lock);
3361 well = lookup_power_well(dev_priv, ICL_DISP_PW_1);
3362 intel_power_well_disable(dev_priv, well);
3363 mutex_unlock(&power_domains->lock);
Paulo Zanoniad186f32018-02-05 13:40:43 -02003364
3365 /* 5. Disable Comp */
3366 for (port = PORT_A; port <= PORT_B; port++) {
3367 val = I915_READ(ICL_PHY_MISC(port));
3368 val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
3369 I915_WRITE(ICL_PHY_MISC(port), val);
3370 }
3371}
3372
Ville Syrjälä70722462015-04-10 18:21:28 +03003373static void chv_phy_control_init(struct drm_i915_private *dev_priv)
3374{
3375 struct i915_power_well *cmn_bc =
3376 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3377 struct i915_power_well *cmn_d =
3378 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
3379
3380 /*
3381 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
3382 * workaround never ever read DISPLAY_PHY_CONTROL, and
3383 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003384 * power well state and lane status to reconstruct the
3385 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03003386 */
3387 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03003388 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
3389 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003390 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
3391 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
3392 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
3393
3394 /*
3395 * If all lanes are disabled we leave the override disabled
3396 * with all power down bits cleared to match the state we
3397 * would use after disabling the port. Otherwise enable the
3398 * override and set the lane powerdown bits accding to the
3399 * current lane status.
3400 */
3401 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
3402 uint32_t status = I915_READ(DPLL(PIPE_A));
3403 unsigned int mask;
3404
3405 mask = status & DPLL_PORTB_READY_MASK;
3406 if (mask == 0xf)
3407 mask = 0x0;
3408 else
3409 dev_priv->chv_phy_control |=
3410 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
3411
3412 dev_priv->chv_phy_control |=
3413 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
3414
3415 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
3416 if (mask == 0xf)
3417 mask = 0x0;
3418 else
3419 dev_priv->chv_phy_control |=
3420 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
3421
3422 dev_priv->chv_phy_control |=
3423 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
3424
Ville Syrjälä70722462015-04-10 18:21:28 +03003425 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003426
3427 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
3428 } else {
3429 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003430 }
3431
3432 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
3433 uint32_t status = I915_READ(DPIO_PHY_STATUS);
3434 unsigned int mask;
3435
3436 mask = status & DPLL_PORTD_READY_MASK;
3437
3438 if (mask == 0xf)
3439 mask = 0x0;
3440 else
3441 dev_priv->chv_phy_control |=
3442 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
3443
3444 dev_priv->chv_phy_control |=
3445 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
3446
Ville Syrjälä70722462015-04-10 18:21:28 +03003447 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03003448
3449 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
3450 } else {
3451 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03003452 }
3453
3454 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
3455
3456 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
3457 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03003458}
3459
Daniel Vetter9c065a72014-09-30 10:56:38 +02003460static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
3461{
3462 struct i915_power_well *cmn =
3463 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
3464 struct i915_power_well *disp2d =
3465 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
3466
Daniel Vetter9c065a72014-09-30 10:56:38 +02003467 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03003468 if (cmn->ops->is_enabled(dev_priv, cmn) &&
3469 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02003470 I915_READ(DPIO_CTL) & DPIO_CMNRST)
3471 return;
3472
3473 DRM_DEBUG_KMS("toggling display PHY side reset\n");
3474
3475 /* cmnlane needs DPLL registers */
3476 disp2d->ops->enable(dev_priv, disp2d);
3477
3478 /*
3479 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
3480 * Need to assert and de-assert PHY SB reset by gating the
3481 * common lane power, then un-gating it.
3482 * Simply ungating isn't enough to reset the PHY enough to get
3483 * ports and lanes running.
3484 */
3485 cmn->ops->disable(dev_priv, cmn);
3486}
3487
Daniel Vettere4e76842014-09-30 10:56:42 +02003488/**
3489 * intel_power_domains_init_hw - initialize hardware power domain state
3490 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003491 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02003492 *
3493 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02003494 * power wells belonging to the INIT power domain. Power wells in other
3495 * domains (and not in the INIT domain) are referenced or disabled during the
3496 * modeset state HW readout. After that the reference count of each power well
3497 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003498 */
Imre Deak73dfc222015-11-17 17:33:53 +02003499void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003500{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003501 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3502
3503 power_domains->initializing = true;
3504
Paulo Zanoniad186f32018-02-05 13:40:43 -02003505 if (IS_ICELAKE(dev_priv)) {
3506 icl_display_core_init(dev_priv, resume);
3507 } else if (IS_CANNONLAKE(dev_priv)) {
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003508 cnl_display_core_init(dev_priv, resume);
3509 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003510 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003511 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003512 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003513 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003514 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003515 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003516 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003517 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003518 mutex_lock(&power_domains->lock);
3519 vlv_cmnlane_wa(dev_priv);
3520 mutex_unlock(&power_domains->lock);
3521 }
3522
3523 /* For now, we need the power well to be always enabled. */
3524 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003525 /* Disable power support if the user asked so. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003526 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003527 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003528 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003529 power_domains->initializing = false;
3530}
3531
Daniel Vettere4e76842014-09-30 10:56:42 +02003532/**
Imre Deak48a287e2018-08-06 12:58:35 +03003533 * intel_power_domains_fini_hw - deinitialize hw power domain state
3534 * @dev_priv: i915 device instance
3535 *
3536 * De-initializes the display power domain HW state. It also ensures that the
3537 * device stays powered up so that the driver can be reloaded.
3538 */
3539void intel_power_domains_fini_hw(struct drm_i915_private *dev_priv)
3540{
3541 struct device *kdev = &dev_priv->drm.pdev->dev;
3542
3543 /*
3544 * The i915.ko module is still not prepared to be loaded when
3545 * the power well is not enabled, so just enable it in case
3546 * we're going to unload/reload.
3547 * The following also reacquires the RPM reference the core passed
3548 * to the driver during loading, which is dropped in
3549 * intel_runtime_pm_enable(). We have to hand back the control of the
3550 * device to the core with this reference held.
3551 */
3552 intel_display_set_init_power(dev_priv, true);
3553
3554 /* Remove the refcount we took to keep power well support disabled. */
3555 if (!i915_modparams.disable_power_well)
3556 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
3557
3558 /*
3559 * Remove the refcount we took in intel_runtime_pm_enable() in case
3560 * the platform doesn't support runtime PM.
3561 */
3562 if (!HAS_RUNTIME_PM(dev_priv))
3563 pm_runtime_put(kdev);
3564}
3565
3566/**
Imre Deak73dfc222015-11-17 17:33:53 +02003567 * intel_power_domains_suspend - suspend power domain state
3568 * @dev_priv: i915 device instance
3569 *
3570 * This function prepares the hardware power domain state before entering
3571 * system suspend. It must be paired with intel_power_domains_init_hw().
3572 */
3573void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3574{
Imre Deakd314cd42015-11-17 17:44:23 +02003575 /*
3576 * Even if power well support was disabled we still want to disable
3577 * power wells while we are system suspended.
3578 */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003579 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003580 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003581
Paulo Zanoniad186f32018-02-05 13:40:43 -02003582 if (IS_ICELAKE(dev_priv))
3583 icl_display_core_uninit(dev_priv);
3584 else if (IS_CANNONLAKE(dev_priv))
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003585 cnl_display_core_uninit(dev_priv);
3586 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003587 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003588 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003589 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003590}
3591
Imre Deak8d8c3862017-02-17 17:39:46 +02003592static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3593{
3594 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3595 struct i915_power_well *power_well;
3596
3597 for_each_power_well(dev_priv, power_well) {
3598 enum intel_display_power_domain domain;
3599
3600 DRM_DEBUG_DRIVER("%-25s %d\n",
3601 power_well->name, power_well->count);
3602
3603 for_each_power_domain(domain, power_well->domains)
3604 DRM_DEBUG_DRIVER(" %-23s %d\n",
3605 intel_display_power_domain_str(domain),
3606 power_domains->domain_use_count[domain]);
3607 }
3608}
3609
3610/**
3611 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3612 * @dev_priv: i915 device instance
3613 *
3614 * Verify if the reference count of each power well matches its HW enabled
3615 * state and the total refcount of the domains it belongs to. This must be
3616 * called after modeset HW state sanitization, which is responsible for
3617 * acquiring reference counts for any power wells in use and disabling the
3618 * ones left on by BIOS but not required by any active output.
3619 */
3620void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3621{
3622 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3623 struct i915_power_well *power_well;
3624 bool dump_domain_info;
3625
3626 mutex_lock(&power_domains->lock);
3627
3628 dump_domain_info = false;
3629 for_each_power_well(dev_priv, power_well) {
3630 enum intel_display_power_domain domain;
3631 int domains_count;
3632 bool enabled;
3633
3634 /*
3635 * Power wells not belonging to any domain (like the MISC_IO
3636 * and PW1 power wells) are under FW control, so ignore them,
3637 * since their state can change asynchronously.
3638 */
3639 if (!power_well->domains)
3640 continue;
3641
3642 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3643 if ((power_well->count || power_well->always_on) != enabled)
3644 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3645 power_well->name, power_well->count, enabled);
3646
3647 domains_count = 0;
3648 for_each_power_domain(domain, power_well->domains)
3649 domains_count += power_domains->domain_use_count[domain];
3650
3651 if (power_well->count != domains_count) {
3652 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3653 "(refcount %d/domains refcount %d)\n",
3654 power_well->name, power_well->count,
3655 domains_count);
3656 dump_domain_info = true;
3657 }
3658 }
3659
3660 if (dump_domain_info) {
3661 static bool dumped;
3662
3663 if (!dumped) {
3664 intel_power_domains_dump_info(dev_priv);
3665 dumped = true;
3666 }
3667 }
3668
3669 mutex_unlock(&power_domains->lock);
3670}
3671
Imre Deak73dfc222015-11-17 17:33:53 +02003672/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003673 * intel_runtime_pm_get - grab a runtime pm reference
3674 * @dev_priv: i915 device instance
3675 *
3676 * This function grabs a device-level runtime pm reference (mostly used for GEM
3677 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3678 *
3679 * Any runtime pm reference obtained by this function must have a symmetric
3680 * call to intel_runtime_pm_put() to release the reference again.
3681 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003682void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3683{
David Weinehall52a05c32016-08-22 13:32:44 +03003684 struct pci_dev *pdev = dev_priv->drm.pdev;
3685 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003686 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003687
Imre Deakf5073822017-03-28 12:38:55 +03003688 ret = pm_runtime_get_sync(kdev);
3689 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003690
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003691 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003692 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003693}
3694
Daniel Vettere4e76842014-09-30 10:56:42 +02003695/**
Imre Deak09731282016-02-17 14:17:42 +02003696 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3697 * @dev_priv: i915 device instance
3698 *
3699 * This function grabs a device-level runtime pm reference if the device is
Chris Wilsonacb79142018-02-19 12:50:46 +00003700 * already in use and ensures that it is powered up. It is illegal to try
3701 * and access the HW should intel_runtime_pm_get_if_in_use() report failure.
Imre Deak09731282016-02-17 14:17:42 +02003702 *
3703 * Any runtime pm reference obtained by this function must have a symmetric
3704 * call to intel_runtime_pm_put() to release the reference again.
Chris Wilsonacb79142018-02-19 12:50:46 +00003705 *
3706 * Returns: True if the wakeref was acquired, or False otherwise.
Imre Deak09731282016-02-17 14:17:42 +02003707 */
3708bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3709{
Chris Wilson135dc792016-02-25 21:10:28 +00003710 if (IS_ENABLED(CONFIG_PM)) {
Chris Wilsonacb79142018-02-19 12:50:46 +00003711 struct pci_dev *pdev = dev_priv->drm.pdev;
3712 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003713
Chris Wilson135dc792016-02-25 21:10:28 +00003714 /*
3715 * In cases runtime PM is disabled by the RPM core and we get
3716 * an -EINVAL return value we are not supposed to call this
3717 * function, since the power state is undefined. This applies
3718 * atm to the late/early system suspend/resume handlers.
3719 */
Chris Wilsonacb79142018-02-19 12:50:46 +00003720 if (pm_runtime_get_if_in_use(kdev) <= 0)
Chris Wilson135dc792016-02-25 21:10:28 +00003721 return false;
3722 }
Imre Deak09731282016-02-17 14:17:42 +02003723
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003724 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deak09731282016-02-17 14:17:42 +02003725 assert_rpm_wakelock_held(dev_priv);
3726
3727 return true;
3728}
3729
3730/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003731 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3732 * @dev_priv: i915 device instance
3733 *
3734 * This function grabs a device-level runtime pm reference (mostly used for GEM
3735 * code to ensure the GTT or GT is on).
3736 *
3737 * It will _not_ power up the device but instead only check that it's powered
3738 * on. Therefore it is only valid to call this functions from contexts where
3739 * the device is known to be powered up and where trying to power it up would
3740 * result in hilarity and deadlocks. That pretty much means only the system
3741 * suspend/resume code where this is used to grab runtime pm references for
3742 * delayed setup down in work items.
3743 *
3744 * Any runtime pm reference obtained by this function must have a symmetric
3745 * call to intel_runtime_pm_put() to release the reference again.
3746 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003747void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3748{
David Weinehall52a05c32016-08-22 13:32:44 +03003749 struct pci_dev *pdev = dev_priv->drm.pdev;
3750 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003751
Imre Deakc9b88462015-12-15 20:10:34 +02003752 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003753 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003754
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003755 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003756}
3757
Daniel Vettere4e76842014-09-30 10:56:42 +02003758/**
3759 * intel_runtime_pm_put - release a runtime pm reference
3760 * @dev_priv: i915 device instance
3761 *
3762 * This function drops the device-level runtime pm reference obtained by
3763 * intel_runtime_pm_get() and might power down the corresponding
3764 * hardware block right away if this is the last reference.
3765 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003766void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3767{
David Weinehall52a05c32016-08-22 13:32:44 +03003768 struct pci_dev *pdev = dev_priv->drm.pdev;
3769 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003770
Imre Deak542db3c2015-12-15 20:10:36 +02003771 assert_rpm_wakelock_held(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003772 atomic_dec(&dev_priv->runtime_pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003773
David Weinehallc49d13e2016-08-22 13:32:42 +03003774 pm_runtime_mark_last_busy(kdev);
3775 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003776}
3777
Daniel Vettere4e76842014-09-30 10:56:42 +02003778/**
3779 * intel_runtime_pm_enable - enable runtime pm
3780 * @dev_priv: i915 device instance
3781 *
3782 * This function enables runtime pm at the end of the driver load sequence.
3783 *
3784 * Note that this function does currently not enable runtime pm for the
3785 * subordinate display power domains. That is only done on the first modeset
3786 * using intel_display_set_init_power().
3787 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003788void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003789{
David Weinehall52a05c32016-08-22 13:32:44 +03003790 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003791 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003792
David Weinehallc49d13e2016-08-22 13:32:42 +03003793 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3794 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003795
Imre Deak25b181b2015-12-17 13:44:56 +02003796 /*
3797 * Take a permanent reference to disable the RPM functionality and drop
3798 * it only when unloading the driver. Use the low level get/put helpers,
3799 * so the driver's own RPM reference tracking asserts also work on
3800 * platforms without RPM support.
3801 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003802 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003803 int ret;
3804
David Weinehallc49d13e2016-08-22 13:32:42 +03003805 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003806 ret = pm_runtime_get_sync(kdev);
3807 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003808 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003809 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003810 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003811
Imre Deakaabee1b2015-12-15 20:10:29 +02003812 /*
3813 * The core calls the driver load handler with an RPM reference held.
3814 * We drop that here and will reacquire it during unloading in
3815 * intel_power_domains_fini().
3816 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003817 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003818}