blob: b66d8e136aa37c3b72d072312d0f06d141223237 [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";
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020097 case POWER_DOMAIN_PORT_DDI_A_IO:
98 return "PORT_DDI_A_IO";
99 case POWER_DOMAIN_PORT_DDI_B_IO:
100 return "PORT_DDI_B_IO";
101 case POWER_DOMAIN_PORT_DDI_C_IO:
102 return "PORT_DDI_C_IO";
103 case POWER_DOMAIN_PORT_DDI_D_IO:
104 return "PORT_DDI_D_IO";
105 case POWER_DOMAIN_PORT_DDI_E_IO:
106 return "PORT_DDI_E_IO";
Daniel Stone9895ad02015-11-20 15:55:33 +0000107 case POWER_DOMAIN_PORT_DSI:
108 return "PORT_DSI";
109 case POWER_DOMAIN_PORT_CRT:
110 return "PORT_CRT";
111 case POWER_DOMAIN_PORT_OTHER:
112 return "PORT_OTHER";
113 case POWER_DOMAIN_VGA:
114 return "VGA";
115 case POWER_DOMAIN_AUDIO:
116 return "AUDIO";
117 case POWER_DOMAIN_PLLS:
118 return "PLLS";
119 case POWER_DOMAIN_AUX_A:
120 return "AUX_A";
121 case POWER_DOMAIN_AUX_B:
122 return "AUX_B";
123 case POWER_DOMAIN_AUX_C:
124 return "AUX_C";
125 case POWER_DOMAIN_AUX_D:
126 return "AUX_D";
127 case POWER_DOMAIN_GMBUS:
128 return "GMBUS";
129 case POWER_DOMAIN_INIT:
130 return "INIT";
131 case POWER_DOMAIN_MODESET:
132 return "MODESET";
133 default:
134 MISSING_CASE(domain);
135 return "?";
136 }
137}
138
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300139static void intel_power_well_enable(struct drm_i915_private *dev_priv,
140 struct i915_power_well *power_well)
141{
142 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
143 power_well->ops->enable(dev_priv, power_well);
144 power_well->hw_enabled = true;
145}
146
Damien Lespiaudcddab32015-07-30 18:20:27 -0300147static void intel_power_well_disable(struct drm_i915_private *dev_priv,
148 struct i915_power_well *power_well)
149{
150 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
151 power_well->hw_enabled = false;
152 power_well->ops->disable(dev_priv, power_well);
153}
154
Imre Deakb409ca92016-06-13 16:44:33 +0300155static void intel_power_well_get(struct drm_i915_private *dev_priv,
156 struct i915_power_well *power_well)
157{
158 if (!power_well->count++)
159 intel_power_well_enable(dev_priv, power_well);
160}
161
162static void intel_power_well_put(struct drm_i915_private *dev_priv,
163 struct i915_power_well *power_well)
164{
165 WARN(!power_well->count, "Use count on power well %s is already zero",
166 power_well->name);
167
168 if (!--power_well->count)
169 intel_power_well_disable(dev_priv, power_well);
170}
171
Daniel Vettere4e76842014-09-30 10:56:42 +0200172/**
173 * __intel_display_power_is_enabled - unlocked check for a power domain
174 * @dev_priv: i915 device instance
175 * @domain: power domain to check
176 *
177 * This is the unlocked version of intel_display_power_is_enabled() and should
178 * only be used from error capture and recovery code where deadlocks are
179 * possible.
180 *
181 * Returns:
182 * True when the power domain is enabled, false otherwise.
183 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200184bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
185 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200186{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200187 struct i915_power_well *power_well;
188 bool is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200189
190 if (dev_priv->pm.suspended)
191 return false;
192
Daniel Vetter9c065a72014-09-30 10:56:38 +0200193 is_enabled = true;
194
Imre Deak75ccb2e2017-02-17 17:39:43 +0200195 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +0200196 if (power_well->always_on)
197 continue;
198
199 if (!power_well->hw_enabled) {
200 is_enabled = false;
201 break;
202 }
203 }
204
205 return is_enabled;
206}
207
Daniel Vettere4e76842014-09-30 10:56:42 +0200208/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000209 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200210 * @dev_priv: i915 device instance
211 * @domain: power domain to check
212 *
213 * This function can be used to check the hw power domain state. It is mostly
214 * used in hardware state readout functions. Everywhere else code should rely
215 * upon explicit power domain reference counting to ensure that the hardware
216 * block is powered up before accessing it.
217 *
218 * Callers must hold the relevant modesetting locks to ensure that concurrent
219 * threads can't disable the power well while the caller tries to read a few
220 * registers.
221 *
222 * Returns:
223 * True when the power domain is enabled, false otherwise.
224 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200225bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
226 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200227{
228 struct i915_power_domains *power_domains;
229 bool ret;
230
231 power_domains = &dev_priv->power_domains;
232
233 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200234 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200235 mutex_unlock(&power_domains->lock);
236
237 return ret;
238}
239
Daniel Vettere4e76842014-09-30 10:56:42 +0200240/**
241 * intel_display_set_init_power - set the initial power domain state
242 * @dev_priv: i915 device instance
243 * @enable: whether to enable or disable the initial power domain state
244 *
245 * For simplicity our driver load/unload and system suspend/resume code assumes
246 * that all power domains are always enabled. This functions controls the state
247 * of this little hack. While the initial power domain state is enabled runtime
248 * pm is effectively disabled.
249 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200250void intel_display_set_init_power(struct drm_i915_private *dev_priv,
251 bool enable)
252{
253 if (dev_priv->power_domains.init_power_on == enable)
254 return;
255
256 if (enable)
257 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
258 else
259 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
260
261 dev_priv->power_domains.init_power_on = enable;
262}
263
Daniel Vetter9c065a72014-09-30 10:56:38 +0200264/*
265 * Starting with Haswell, we have a "Power Down Well" that can be turned off
266 * when not needed anymore. We have 4 registers that can request the power well
267 * to be enabled, and it will only be disabled if none of the registers is
268 * requesting it to be enabled.
269 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300270static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv,
271 u8 irq_pipe_mask, bool has_vga)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200272{
David Weinehall52a05c32016-08-22 13:32:44 +0300273 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200274
275 /*
276 * After we re-enable the power well, if we touch VGA register 0x3d5
277 * we'll get unclaimed register interrupts. This stops after we write
278 * anything to the VGA MSR register. The vgacon module uses this
279 * register all the time, so if we unbind our driver and, as a
280 * consequence, bind vgacon, we'll get stuck in an infinite loop at
281 * console_unlock(). So make here we touch the VGA MSR register, making
282 * sure vgacon can keep working normally without triggering interrupts
283 * and error messages.
284 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300285 if (has_vga) {
286 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
287 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
288 vga_put(pdev, VGA_RSRC_LEGACY_IO);
289 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200290
Imre Deak001bd2c2017-07-12 18:54:13 +0300291 if (irq_pipe_mask)
292 gen8_irq_power_well_post_enable(dev_priv, irq_pipe_mask);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200293}
294
Imre Deak001bd2c2017-07-12 18:54:13 +0300295static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv,
296 u8 irq_pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200297{
Imre Deak001bd2c2017-07-12 18:54:13 +0300298 if (irq_pipe_mask)
299 gen8_irq_power_well_pre_disable(dev_priv, irq_pipe_mask);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200300}
301
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200302
Imre Deak76347c02017-07-06 17:40:36 +0300303static void hsw_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
304 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300305{
Imre Deak438b8dc2017-07-11 23:42:30 +0300306 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300307
308 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
309 WARN_ON(intel_wait_for_register(dev_priv,
Imre Deak9c3a16c2017-08-14 18:15:30 +0300310 HSW_PWR_WELL_CTL_DRIVER(id),
Imre Deak1af474f2017-07-06 17:40:34 +0300311 HSW_PWR_WELL_CTL_STATE(id),
312 HSW_PWR_WELL_CTL_STATE(id),
Imre Deak42d93662017-06-29 18:37:01 +0300313 1));
314}
315
Imre Deak76347c02017-07-06 17:40:36 +0300316static u32 hsw_power_well_requesters(struct drm_i915_private *dev_priv,
317 enum i915_power_well_id id)
Imre Deak42d93662017-06-29 18:37:01 +0300318{
Imre Deak1af474f2017-07-06 17:40:34 +0300319 u32 req_mask = HSW_PWR_WELL_CTL_REQ(id);
Imre Deak42d93662017-06-29 18:37:01 +0300320 u32 ret;
321
Imre Deak9c3a16c2017-08-14 18:15:30 +0300322 ret = I915_READ(HSW_PWR_WELL_CTL_BIOS(id)) & req_mask ? 1 : 0;
323 ret |= I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & req_mask ? 2 : 0;
324 ret |= I915_READ(HSW_PWR_WELL_CTL_KVMR) & req_mask ? 4 : 0;
325 ret |= I915_READ(HSW_PWR_WELL_CTL_DEBUG(id)) & req_mask ? 8 : 0;
Imre Deak42d93662017-06-29 18:37:01 +0300326
327 return ret;
328}
329
Imre Deak76347c02017-07-06 17:40:36 +0300330static void hsw_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
331 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300332{
Imre Deak438b8dc2017-07-11 23:42:30 +0300333 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300334 bool disabled;
335 u32 reqs;
336
337 /*
338 * Bspec doesn't require waiting for PWs to get disabled, but still do
339 * this for paranoia. The known cases where a PW will be forced on:
340 * - a KVMR request on any power well via the KVMR request register
341 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
342 * DEBUG request registers
343 * Skip the wait in case any of the request bits are set and print a
344 * diagnostic message.
345 */
Imre Deak9c3a16c2017-08-14 18:15:30 +0300346 wait_for((disabled = !(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
Imre Deak1af474f2017-07-06 17:40:34 +0300347 HSW_PWR_WELL_CTL_STATE(id))) ||
Imre Deak76347c02017-07-06 17:40:36 +0300348 (reqs = hsw_power_well_requesters(dev_priv, id)), 1);
Imre Deak42d93662017-06-29 18:37:01 +0300349 if (disabled)
350 return;
351
352 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
353 power_well->name,
354 !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
355}
356
Imre Deakb2891eb2017-07-11 23:42:35 +0300357static void gen9_wait_for_power_well_fuses(struct drm_i915_private *dev_priv,
358 enum skl_power_gate pg)
359{
360 /* Timeout 5us for PG#0, for other PGs 1us */
361 WARN_ON(intel_wait_for_register(dev_priv, SKL_FUSE_STATUS,
362 SKL_FUSE_PG_DIST_STATUS(pg),
363 SKL_FUSE_PG_DIST_STATUS(pg), 1));
364}
365
Imre Deakec46d482017-07-06 17:40:33 +0300366static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
367 struct i915_power_well *power_well)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200368{
Imre Deak1af474f2017-07-06 17:40:34 +0300369 enum i915_power_well_id id = power_well->id;
Imre Deakb2891eb2017-07-11 23:42:35 +0300370 bool wait_fuses = power_well->hsw.has_fuses;
371 enum skl_power_gate pg;
Imre Deak1af474f2017-07-06 17:40:34 +0300372 u32 val;
373
Imre Deakb2891eb2017-07-11 23:42:35 +0300374 if (wait_fuses) {
375 pg = SKL_PW_TO_PG(id);
376 /*
377 * For PW1 we have to wait both for the PW0/PG0 fuse state
378 * before enabling the power well and PW1/PG1's own fuse
379 * state after the enabling. For all other power wells with
380 * fuses we only have to wait for that PW/PG's fuse state
381 * after the enabling.
382 */
383 if (pg == SKL_PG1)
384 gen9_wait_for_power_well_fuses(dev_priv, SKL_PG0);
385 }
386
Imre Deak9c3a16c2017-08-14 18:15:30 +0300387 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
388 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), val | HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300389 hsw_wait_for_power_well_enable(dev_priv, power_well);
Imre Deak001bd2c2017-07-12 18:54:13 +0300390
Imre Deakb2891eb2017-07-11 23:42:35 +0300391 if (wait_fuses)
392 gen9_wait_for_power_well_fuses(dev_priv, pg);
393
Imre Deak001bd2c2017-07-12 18:54:13 +0300394 hsw_power_well_post_enable(dev_priv, power_well->hsw.irq_pipe_mask,
395 power_well->hsw.has_vga);
Imre Deakec46d482017-07-06 17:40:33 +0300396}
Daniel Vetter9c065a72014-09-30 10:56:38 +0200397
Imre Deakec46d482017-07-06 17:40:33 +0300398static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
399 struct i915_power_well *power_well)
400{
Imre Deak1af474f2017-07-06 17:40:34 +0300401 enum i915_power_well_id id = power_well->id;
402 u32 val;
403
Imre Deak001bd2c2017-07-12 18:54:13 +0300404 hsw_power_well_pre_disable(dev_priv, power_well->hsw.irq_pipe_mask);
405
Imre Deak9c3a16c2017-08-14 18:15:30 +0300406 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
407 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id),
408 val & ~HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300409 hsw_wait_for_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200410}
411
Imre Deakd42539b2017-07-06 17:40:39 +0300412/*
413 * We should only use the power well if we explicitly asked the hardware to
414 * enable it, so check if it's enabled and also check if we've requested it to
415 * be enabled.
416 */
417static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
418 struct i915_power_well *power_well)
419{
420 enum i915_power_well_id id = power_well->id;
421 u32 mask = HSW_PWR_WELL_CTL_REQ(id) | HSW_PWR_WELL_CTL_STATE(id);
422
Imre Deak9c3a16c2017-08-14 18:15:30 +0300423 return (I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & mask) == mask;
Imre Deakd42539b2017-07-06 17:40:39 +0300424}
425
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530426static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
427{
Imre Deak9c3a16c2017-08-14 18:15:30 +0300428 enum i915_power_well_id id = SKL_DISP_PW_2;
429
Imre Deakbfcdabe2016-04-01 16:02:37 +0300430 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
431 "DC9 already programmed to be enabled.\n");
432 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
433 "DC5 still not disabled to enable DC9.\n");
Imre Deak9c3a16c2017-08-14 18:15:30 +0300434 WARN_ONCE(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
435 HSW_PWR_WELL_CTL_REQ(id),
Imre Deake8a3a2a2017-06-29 18:37:00 +0300436 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300437 WARN_ONCE(intel_irqs_enabled(dev_priv),
438 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530439
440 /*
441 * TODO: check for the following to verify the conditions to enter DC9
442 * state are satisfied:
443 * 1] Check relevant display engine registers to verify if mode set
444 * disable sequence was followed.
445 * 2] Check if display uninitialize sequence is initialized.
446 */
447}
448
449static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
450{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300451 WARN_ONCE(intel_irqs_enabled(dev_priv),
452 "Interrupts not disabled yet.\n");
453 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
454 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530455
456 /*
457 * TODO: check for the following to verify DC9 state was indeed
458 * entered before programming to disable it:
459 * 1] Check relevant display engine registers to verify if mode
460 * set disable sequence was followed.
461 * 2] Check if display uninitialize sequence is initialized.
462 */
463}
464
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200465static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
466 u32 state)
467{
468 int rewrites = 0;
469 int rereads = 0;
470 u32 v;
471
472 I915_WRITE(DC_STATE_EN, state);
473
474 /* It has been observed that disabling the dc6 state sometimes
475 * doesn't stick and dmc keeps returning old value. Make sure
476 * the write really sticks enough times and also force rewrite until
477 * we are confident that state is exactly what we want.
478 */
479 do {
480 v = I915_READ(DC_STATE_EN);
481
482 if (v != state) {
483 I915_WRITE(DC_STATE_EN, state);
484 rewrites++;
485 rereads = 0;
486 } else if (rereads++ > 5) {
487 break;
488 }
489
490 } while (rewrites < 100);
491
492 if (v != state)
493 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
494 state, v);
495
496 /* Most of the times we need one retry, avoid spam */
497 if (rewrites > 1)
498 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
499 state, rewrites);
500}
501
Imre Deakda2f41d2016-04-20 20:27:56 +0300502static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530503{
Imre Deakda2f41d2016-04-20 20:27:56 +0300504 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530505
Imre Deak13ae3a02015-11-04 19:24:16 +0200506 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200507 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200508 mask |= DC_STATE_EN_DC9;
509 else
510 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530511
Imre Deakda2f41d2016-04-20 20:27:56 +0300512 return mask;
513}
514
515void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
516{
517 u32 val;
518
519 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
520
521 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
522 dev_priv->csr.dc_state, val);
523 dev_priv->csr.dc_state = val;
524}
525
526static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
527{
528 uint32_t val;
529 uint32_t mask;
530
Imre Deaka37baf32016-02-29 22:49:03 +0200531 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
532 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100533
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530534 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300535 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200536 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
537 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200538
539 /* Check if DMC is ignoring our DC state requests */
540 if ((val & mask) != dev_priv->csr.dc_state)
541 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
542 dev_priv->csr.dc_state, val & mask);
543
Imre Deak13ae3a02015-11-04 19:24:16 +0200544 val &= ~mask;
545 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200546
547 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200548
549 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530550}
551
Imre Deak13ae3a02015-11-04 19:24:16 +0200552void bxt_enable_dc9(struct drm_i915_private *dev_priv)
553{
554 assert_can_enable_dc9(dev_priv);
555
556 DRM_DEBUG_KMS("Enabling DC9\n");
557
Imre Deak78597992016-06-16 16:37:20 +0300558 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200559 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
560}
561
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530562void bxt_disable_dc9(struct drm_i915_private *dev_priv)
563{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530564 assert_can_disable_dc9(dev_priv);
565
566 DRM_DEBUG_KMS("Disabling DC9\n");
567
Imre Deak13ae3a02015-11-04 19:24:16 +0200568 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300569
570 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530571}
572
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200573static void assert_csr_loaded(struct drm_i915_private *dev_priv)
574{
575 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
576 "CSR program storage start is NULL\n");
577 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
578 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
579}
580
Suketu Shah5aefb232015-04-16 14:22:10 +0530581static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530582{
Suketu Shah5aefb232015-04-16 14:22:10 +0530583 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
584 SKL_DISP_PW_2);
585
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700586 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530587
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700588 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
589 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200590 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530591
592 assert_csr_loaded(dev_priv);
593}
594
Imre Deakf62c79b2016-04-20 20:27:57 +0300595void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530596{
Suketu Shah5aefb232015-04-16 14:22:10 +0530597 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530598
599 DRM_DEBUG_KMS("Enabling DC5\n");
600
Imre Deak13ae3a02015-11-04 19:24:16 +0200601 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530602}
603
Suketu Shah93c7cb62015-04-16 14:22:13 +0530604static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530605{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700606 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
607 "Backlight is not disabled.\n");
608 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
609 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530610
611 assert_csr_loaded(dev_priv);
612}
613
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530614void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530615{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530616 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530617
618 DRM_DEBUG_KMS("Enabling DC6\n");
619
Imre Deak13ae3a02015-11-04 19:24:16 +0200620 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
621
Suketu Shahf75a1982015-04-16 14:22:11 +0530622}
623
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530624void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530625{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530626 DRM_DEBUG_KMS("Disabling DC6\n");
627
Imre Deak13ae3a02015-11-04 19:24:16 +0200628 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530629}
630
Daniel Vetter9c065a72014-09-30 10:56:38 +0200631static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
632 struct i915_power_well *power_well)
633{
Imre Deak1af474f2017-07-06 17:40:34 +0300634 enum i915_power_well_id id = power_well->id;
635 u32 mask = HSW_PWR_WELL_CTL_REQ(id);
Imre Deak9c3a16c2017-08-14 18:15:30 +0300636 u32 bios_req = I915_READ(HSW_PWR_WELL_CTL_BIOS(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300637
Imre Deak16e84912017-02-17 17:39:45 +0200638 /* Take over the request bit if set by BIOS. */
Imre Deak1af474f2017-07-06 17:40:34 +0300639 if (bios_req & mask) {
Imre Deak9c3a16c2017-08-14 18:15:30 +0300640 u32 drv_req = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300641
642 if (!(drv_req & mask))
Imre Deak9c3a16c2017-08-14 18:15:30 +0300643 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), drv_req | mask);
644 I915_WRITE(HSW_PWR_WELL_CTL_BIOS(id), bios_req & ~mask);
Imre Deak16e84912017-02-17 17:39:45 +0200645 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200646}
647
Imre Deak9c8d0b82016-06-13 16:44:34 +0300648static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
649 struct i915_power_well *power_well)
650{
Imre Deakb5565a22017-07-06 17:40:29 +0300651 bxt_ddi_phy_init(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300652}
653
654static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
655 struct i915_power_well *power_well)
656{
Imre Deakb5565a22017-07-06 17:40:29 +0300657 bxt_ddi_phy_uninit(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300658}
659
660static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
661 struct i915_power_well *power_well)
662{
Imre Deakb5565a22017-07-06 17:40:29 +0300663 return bxt_ddi_phy_is_enabled(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300664}
665
Imre Deak9c8d0b82016-06-13 16:44:34 +0300666static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
667{
668 struct i915_power_well *power_well;
669
670 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
671 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300672 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300673
674 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
675 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300676 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200677
678 if (IS_GEMINILAKE(dev_priv)) {
679 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
680 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300681 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200682 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300683}
684
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100685static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
686 struct i915_power_well *power_well)
687{
688 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
689}
690
Ville Syrjälä18a80672016-05-16 16:59:40 +0300691static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
692{
693 u32 tmp = I915_READ(DBUF_CTL);
694
695 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
696 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
697 "Unexpected DBuf power power state (0x%08x)\n", tmp);
698}
699
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100700static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
701 struct i915_power_well *power_well)
702{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200703 struct intel_cdclk_state cdclk_state = {};
704
Imre Deak5b773eb2016-02-29 22:49:05 +0200705 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300706
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200707 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
708 WARN_ON(!intel_cdclk_state_compare(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300709
Ville Syrjälä18a80672016-05-16 16:59:40 +0300710 gen9_assert_dbuf_enabled(dev_priv);
711
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200712 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300713 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100714}
715
716static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
717 struct i915_power_well *power_well)
718{
Imre Deakf74ed082016-04-18 14:48:21 +0300719 if (!dev_priv->csr.dmc_payload)
720 return;
721
Imre Deaka37baf32016-02-29 22:49:03 +0200722 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100723 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200724 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100725 gen9_enable_dc5(dev_priv);
726}
727
Imre Deak3c1b38e2017-02-17 17:39:42 +0200728static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
729 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100730{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100731}
732
Daniel Vetter9c065a72014-09-30 10:56:38 +0200733static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
734 struct i915_power_well *power_well)
735{
736}
737
738static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
739 struct i915_power_well *power_well)
740{
741 return true;
742}
743
Ville Syrjälä2ee0da12017-06-01 17:36:16 +0300744static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
745 struct i915_power_well *power_well)
746{
747 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
748 i830_enable_pipe(dev_priv, PIPE_A);
749 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
750 i830_enable_pipe(dev_priv, PIPE_B);
751}
752
753static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
754 struct i915_power_well *power_well)
755{
756 i830_disable_pipe(dev_priv, PIPE_B);
757 i830_disable_pipe(dev_priv, PIPE_A);
758}
759
760static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
761 struct i915_power_well *power_well)
762{
763 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
764 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
765}
766
767static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
768 struct i915_power_well *power_well)
769{
770 if (power_well->count > 0)
771 i830_pipes_power_well_enable(dev_priv, power_well);
772 else
773 i830_pipes_power_well_disable(dev_priv, power_well);
774}
775
Daniel Vetter9c065a72014-09-30 10:56:38 +0200776static void vlv_set_power_well(struct drm_i915_private *dev_priv,
777 struct i915_power_well *power_well, bool enable)
778{
Imre Deak438b8dc2017-07-11 23:42:30 +0300779 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200780 u32 mask;
781 u32 state;
782 u32 ctrl;
783
784 mask = PUNIT_PWRGT_MASK(power_well_id);
785 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
786 PUNIT_PWRGT_PWR_GATE(power_well_id);
787
788 mutex_lock(&dev_priv->rps.hw_lock);
789
790#define COND \
791 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
792
793 if (COND)
794 goto out;
795
796 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
797 ctrl &= ~mask;
798 ctrl |= state;
799 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
800
801 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900802 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200803 state,
804 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
805
806#undef COND
807
808out:
809 mutex_unlock(&dev_priv->rps.hw_lock);
810}
811
Daniel Vetter9c065a72014-09-30 10:56:38 +0200812static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
813 struct i915_power_well *power_well)
814{
815 vlv_set_power_well(dev_priv, power_well, true);
816}
817
818static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
819 struct i915_power_well *power_well)
820{
821 vlv_set_power_well(dev_priv, power_well, false);
822}
823
824static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
825 struct i915_power_well *power_well)
826{
Imre Deak438b8dc2017-07-11 23:42:30 +0300827 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200828 bool enabled = false;
829 u32 mask;
830 u32 state;
831 u32 ctrl;
832
833 mask = PUNIT_PWRGT_MASK(power_well_id);
834 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
835
836 mutex_lock(&dev_priv->rps.hw_lock);
837
838 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
839 /*
840 * We only ever set the power-on and power-gate states, anything
841 * else is unexpected.
842 */
843 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
844 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
845 if (state == ctrl)
846 enabled = true;
847
848 /*
849 * A transient state at this point would mean some unexpected party
850 * is poking at the power controls too.
851 */
852 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
853 WARN_ON(ctrl != state);
854
855 mutex_unlock(&dev_priv->rps.hw_lock);
856
857 return enabled;
858}
859
Ville Syrjälä766078d2016-04-11 16:56:30 +0300860static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
861{
Hans de Goede721d4842016-12-02 15:29:04 +0100862 u32 val;
863
864 /*
865 * On driver load, a pipe may be active and driving a DSI display.
866 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
867 * (and never recovering) in this case. intel_dsi_post_disable() will
868 * clear it when we turn off the display.
869 */
870 val = I915_READ(DSPCLK_GATE_D);
871 val &= DPOUNIT_CLOCK_GATE_DISABLE;
872 val |= VRHUNIT_CLOCK_GATE_DISABLE;
873 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +0300874
875 /*
876 * Disable trickle feed and enable pnd deadline calculation
877 */
878 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
879 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +0300880
881 WARN_ON(dev_priv->rawclk_freq == 0);
882
883 I915_WRITE(RAWCLK_FREQ_VLV,
884 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +0300885}
886
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300887static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200888{
Lyude9504a892016-06-21 17:03:42 -0400889 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300890 enum pipe pipe;
891
892 /*
893 * Enable the CRI clock source so we can get at the
894 * display and the reference clock for VGA
895 * hotplug / manual detection. Supposedly DSI also
896 * needs the ref clock up and running.
897 *
898 * CHV DPLL B/C have some issues if VGA mode is enabled.
899 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +0000900 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300901 u32 val = I915_READ(DPLL(pipe));
902
903 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
904 if (pipe != PIPE_A)
905 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
906
907 I915_WRITE(DPLL(pipe), val);
908 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200909
Ville Syrjälä766078d2016-04-11 16:56:30 +0300910 vlv_init_display_clock_gating(dev_priv);
911
Daniel Vetter9c065a72014-09-30 10:56:38 +0200912 spin_lock_irq(&dev_priv->irq_lock);
913 valleyview_enable_display_irqs(dev_priv);
914 spin_unlock_irq(&dev_priv->irq_lock);
915
916 /*
917 * During driver initialization/resume we can avoid restoring the
918 * part of the HW/SW state that will be inited anyway explicitly.
919 */
920 if (dev_priv->power_domains.initializing)
921 return;
922
Daniel Vetterb9632912014-09-30 10:56:44 +0200923 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200924
Lyude9504a892016-06-21 17:03:42 -0400925 /* Re-enable the ADPA, if we have one */
926 for_each_intel_encoder(&dev_priv->drm, encoder) {
927 if (encoder->type == INTEL_OUTPUT_ANALOG)
928 intel_crt_reset(&encoder->base);
929 }
930
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +0000931 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +0300932
933 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200934}
935
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300936static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
937{
938 spin_lock_irq(&dev_priv->irq_lock);
939 valleyview_disable_display_irqs(dev_priv);
940 spin_unlock_irq(&dev_priv->irq_lock);
941
Ville Syrjälä2230fde2016-02-19 18:41:52 +0200942 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +0100943 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +0200944
Imre Deak78597992016-06-16 16:37:20 +0300945 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -0400946
Lyudeb64b5402016-10-26 12:36:09 -0400947 /* Prevent us from re-enabling polling on accident in late suspend */
948 if (!dev_priv->drm.dev->power.is_suspended)
949 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300950}
951
952static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
953 struct i915_power_well *power_well)
954{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300955 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300956
957 vlv_set_power_well(dev_priv, power_well, true);
958
959 vlv_display_power_well_init(dev_priv);
960}
961
Daniel Vetter9c065a72014-09-30 10:56:38 +0200962static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
963 struct i915_power_well *power_well)
964{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300965 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200966
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300967 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200968
969 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200970}
971
972static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
973 struct i915_power_well *power_well)
974{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300975 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200976
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300977 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +0200978 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
979
980 vlv_set_power_well(dev_priv, power_well, true);
981
982 /*
983 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
984 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
985 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
986 * b. The other bits such as sfr settings / modesel may all
987 * be set to 0.
988 *
989 * This should only be done on init and resume from S3 with
990 * both PLLs disabled, or we risk losing DPIO and PLL
991 * synchronization.
992 */
993 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
994}
995
996static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
997 struct i915_power_well *power_well)
998{
999 enum pipe pipe;
1000
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001001 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001002
1003 for_each_pipe(dev_priv, pipe)
1004 assert_pll_disabled(dev_priv, pipe);
1005
1006 /* Assert common reset */
1007 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1008
1009 vlv_set_power_well(dev_priv, power_well, false);
1010}
1011
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001012#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001013
Imre Deak438b8dc2017-07-11 23:42:30 +03001014static struct i915_power_well *
1015lookup_power_well(struct drm_i915_private *dev_priv,
1016 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001017{
1018 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001019 int i;
1020
Imre Deakfc17f222015-11-04 19:24:11 +02001021 for (i = 0; i < power_domains->power_well_count; i++) {
1022 struct i915_power_well *power_well;
1023
1024 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001025 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001026 return power_well;
1027 }
1028
1029 return NULL;
1030}
1031
1032#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1033
1034static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1035{
1036 struct i915_power_well *cmn_bc =
1037 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1038 struct i915_power_well *cmn_d =
1039 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1040 u32 phy_control = dev_priv->chv_phy_control;
1041 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001042 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001043
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001044 /*
1045 * The BIOS can leave the PHY is some weird state
1046 * where it doesn't fully power down some parts.
1047 * Disable the asserts until the PHY has been fully
1048 * reset (ie. the power well has been disabled at
1049 * least once).
1050 */
1051 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1052 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1053 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1054 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1055 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1056 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1057 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1058
1059 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1060 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1061 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1062 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1063
Ville Syrjälä30142272015-07-08 23:46:01 +03001064 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1065 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1066
1067 /* this assumes override is only used to enable lanes */
1068 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1069 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1070
1071 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1072 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1073
1074 /* CL1 is on whenever anything is on in either channel */
1075 if (BITS_SET(phy_control,
1076 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1077 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1078 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1079
1080 /*
1081 * The DPLLB check accounts for the pipe B + port A usage
1082 * with CL2 powered up but all the lanes in the second channel
1083 * powered down.
1084 */
1085 if (BITS_SET(phy_control,
1086 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1087 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1088 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1089
1090 if (BITS_SET(phy_control,
1091 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1092 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1093 if (BITS_SET(phy_control,
1094 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1095 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1096
1097 if (BITS_SET(phy_control,
1098 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1099 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1100 if (BITS_SET(phy_control,
1101 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1102 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1103 }
1104
1105 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1106 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1107
1108 /* this assumes override is only used to enable lanes */
1109 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1110 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1111
1112 if (BITS_SET(phy_control,
1113 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1114 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1115
1116 if (BITS_SET(phy_control,
1117 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1118 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1119 if (BITS_SET(phy_control,
1120 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1121 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1122 }
1123
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001124 phy_status &= phy_status_mask;
1125
Ville Syrjälä30142272015-07-08 23:46:01 +03001126 /*
1127 * The PHY may be busy with some initial calibration and whatnot,
1128 * so the power state can take a while to actually change.
1129 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001130 if (intel_wait_for_register(dev_priv,
1131 DISPLAY_PHY_STATUS,
1132 phy_status_mask,
1133 phy_status,
1134 10))
1135 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1136 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1137 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001138}
1139
1140#undef BITS_SET
1141
Daniel Vetter9c065a72014-09-30 10:56:38 +02001142static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1143 struct i915_power_well *power_well)
1144{
1145 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001146 enum pipe pipe;
1147 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001148
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001149 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1150 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001151
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001152 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001153 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001154 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001155 } else {
1156 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001157 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001158 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001159
1160 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001161 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1162 vlv_set_power_well(dev_priv, power_well, true);
1163
1164 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001165 if (intel_wait_for_register(dev_priv,
1166 DISPLAY_PHY_STATUS,
1167 PHY_POWERGOOD(phy),
1168 PHY_POWERGOOD(phy),
1169 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001170 DRM_ERROR("Display PHY %d is not power up\n", phy);
1171
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001172 mutex_lock(&dev_priv->sb_lock);
1173
1174 /* Enable dynamic power down */
1175 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001176 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1177 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001178 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1179
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001180 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001181 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1182 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1183 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001184 } else {
1185 /*
1186 * Force the non-existing CL2 off. BXT does this
1187 * too, so maybe it saves some power even though
1188 * CL2 doesn't exist?
1189 */
1190 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1191 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1192 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001193 }
1194
1195 mutex_unlock(&dev_priv->sb_lock);
1196
Ville Syrjälä70722462015-04-10 18:21:28 +03001197 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1198 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001199
1200 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1201 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001202
1203 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001204}
1205
1206static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1207 struct i915_power_well *power_well)
1208{
1209 enum dpio_phy phy;
1210
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001211 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1212 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001213
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001214 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001215 phy = DPIO_PHY0;
1216 assert_pll_disabled(dev_priv, PIPE_A);
1217 assert_pll_disabled(dev_priv, PIPE_B);
1218 } else {
1219 phy = DPIO_PHY1;
1220 assert_pll_disabled(dev_priv, PIPE_C);
1221 }
1222
Ville Syrjälä70722462015-04-10 18:21:28 +03001223 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1224 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001225
1226 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001227
1228 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1229 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001230
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001231 /* PHY is fully reset now, so we can enable the PHY state asserts */
1232 dev_priv->chv_phy_assert[phy] = true;
1233
Ville Syrjälä30142272015-07-08 23:46:01 +03001234 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001235}
1236
Ville Syrjälä6669e392015-07-08 23:46:00 +03001237static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1238 enum dpio_channel ch, bool override, unsigned int mask)
1239{
1240 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1241 u32 reg, val, expected, actual;
1242
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001243 /*
1244 * The BIOS can leave the PHY is some weird state
1245 * where it doesn't fully power down some parts.
1246 * Disable the asserts until the PHY has been fully
1247 * reset (ie. the power well has been disabled at
1248 * least once).
1249 */
1250 if (!dev_priv->chv_phy_assert[phy])
1251 return;
1252
Ville Syrjälä6669e392015-07-08 23:46:00 +03001253 if (ch == DPIO_CH0)
1254 reg = _CHV_CMN_DW0_CH0;
1255 else
1256 reg = _CHV_CMN_DW6_CH1;
1257
1258 mutex_lock(&dev_priv->sb_lock);
1259 val = vlv_dpio_read(dev_priv, pipe, reg);
1260 mutex_unlock(&dev_priv->sb_lock);
1261
1262 /*
1263 * This assumes !override is only used when the port is disabled.
1264 * All lanes should power down even without the override when
1265 * the port is disabled.
1266 */
1267 if (!override || mask == 0xf) {
1268 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1269 /*
1270 * If CH1 common lane is not active anymore
1271 * (eg. for pipe B DPLL) the entire channel will
1272 * shut down, which causes the common lane registers
1273 * to read as 0. That means we can't actually check
1274 * the lane power down status bits, but as the entire
1275 * register reads as 0 it's a good indication that the
1276 * channel is indeed entirely powered down.
1277 */
1278 if (ch == DPIO_CH1 && val == 0)
1279 expected = 0;
1280 } else if (mask != 0x0) {
1281 expected = DPIO_ANYDL_POWERDOWN;
1282 } else {
1283 expected = 0;
1284 }
1285
1286 if (ch == DPIO_CH0)
1287 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1288 else
1289 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1290 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1291
1292 WARN(actual != expected,
1293 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1294 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1295 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1296 reg, val);
1297}
1298
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001299bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1300 enum dpio_channel ch, bool override)
1301{
1302 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1303 bool was_override;
1304
1305 mutex_lock(&power_domains->lock);
1306
1307 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1308
1309 if (override == was_override)
1310 goto out;
1311
1312 if (override)
1313 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1314 else
1315 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1316
1317 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1318
1319 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1320 phy, ch, dev_priv->chv_phy_control);
1321
Ville Syrjälä30142272015-07-08 23:46:01 +03001322 assert_chv_phy_status(dev_priv);
1323
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001324out:
1325 mutex_unlock(&power_domains->lock);
1326
1327 return was_override;
1328}
1329
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001330void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1331 bool override, unsigned int mask)
1332{
1333 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1334 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1335 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1336 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1337
1338 mutex_lock(&power_domains->lock);
1339
1340 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1341 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1342
1343 if (override)
1344 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1345 else
1346 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1347
1348 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1349
1350 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1351 phy, ch, mask, dev_priv->chv_phy_control);
1352
Ville Syrjälä30142272015-07-08 23:46:01 +03001353 assert_chv_phy_status(dev_priv);
1354
Ville Syrjälä6669e392015-07-08 23:46:00 +03001355 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1356
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001357 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001358}
1359
1360static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1361 struct i915_power_well *power_well)
1362{
Imre Deakf49193c2017-07-06 17:40:23 +03001363 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001364 bool enabled;
1365 u32 state, ctrl;
1366
1367 mutex_lock(&dev_priv->rps.hw_lock);
1368
1369 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1370 /*
1371 * We only ever set the power-on and power-gate states, anything
1372 * else is unexpected.
1373 */
1374 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1375 enabled = state == DP_SSS_PWR_ON(pipe);
1376
1377 /*
1378 * A transient state at this point would mean some unexpected party
1379 * is poking at the power controls too.
1380 */
1381 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1382 WARN_ON(ctrl << 16 != state);
1383
1384 mutex_unlock(&dev_priv->rps.hw_lock);
1385
1386 return enabled;
1387}
1388
1389static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1390 struct i915_power_well *power_well,
1391 bool enable)
1392{
Imre Deakf49193c2017-07-06 17:40:23 +03001393 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001394 u32 state;
1395 u32 ctrl;
1396
1397 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1398
1399 mutex_lock(&dev_priv->rps.hw_lock);
1400
1401#define COND \
1402 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1403
1404 if (COND)
1405 goto out;
1406
1407 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1408 ctrl &= ~DP_SSC_MASK(pipe);
1409 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1410 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1411
1412 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001413 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001414 state,
1415 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1416
1417#undef COND
1418
1419out:
1420 mutex_unlock(&dev_priv->rps.hw_lock);
1421}
1422
Daniel Vetter9c065a72014-09-30 10:56:38 +02001423static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1424 struct i915_power_well *power_well)
1425{
Imre Deakf49193c2017-07-06 17:40:23 +03001426 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001427
1428 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001429
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001430 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001431}
1432
1433static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1434 struct i915_power_well *power_well)
1435{
Imre Deakf49193c2017-07-06 17:40:23 +03001436 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001437
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001438 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001439
Daniel Vetter9c065a72014-09-30 10:56:38 +02001440 chv_set_pipe_power_well(dev_priv, power_well, false);
1441}
1442
Imre Deak09731282016-02-17 14:17:42 +02001443static void
1444__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1445 enum intel_display_power_domain domain)
1446{
1447 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1448 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001449
Imre Deak75ccb2e2017-02-17 17:39:43 +02001450 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001451 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001452
1453 power_domains->domain_use_count[domain]++;
1454}
1455
Daniel Vettere4e76842014-09-30 10:56:42 +02001456/**
1457 * intel_display_power_get - grab a power domain reference
1458 * @dev_priv: i915 device instance
1459 * @domain: power domain to reference
1460 *
1461 * This function grabs a power domain reference for @domain and ensures that the
1462 * power domain and all its parents are powered up. Therefore users should only
1463 * grab a reference to the innermost power domain they need.
1464 *
1465 * Any power domain reference obtained by this function must have a symmetric
1466 * call to intel_display_power_put() to release the reference again.
1467 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001468void intel_display_power_get(struct drm_i915_private *dev_priv,
1469 enum intel_display_power_domain domain)
1470{
Imre Deak09731282016-02-17 14:17:42 +02001471 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001472
1473 intel_runtime_pm_get(dev_priv);
1474
Imre Deak09731282016-02-17 14:17:42 +02001475 mutex_lock(&power_domains->lock);
1476
1477 __intel_display_power_get_domain(dev_priv, domain);
1478
1479 mutex_unlock(&power_domains->lock);
1480}
1481
1482/**
1483 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1484 * @dev_priv: i915 device instance
1485 * @domain: power domain to reference
1486 *
1487 * This function grabs a power domain reference for @domain and ensures that the
1488 * power domain and all its parents are powered up. Therefore users should only
1489 * grab a reference to the innermost power domain they need.
1490 *
1491 * Any power domain reference obtained by this function must have a symmetric
1492 * call to intel_display_power_put() to release the reference again.
1493 */
1494bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1495 enum intel_display_power_domain domain)
1496{
1497 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1498 bool is_enabled;
1499
1500 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1501 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001502
1503 mutex_lock(&power_domains->lock);
1504
Imre Deak09731282016-02-17 14:17:42 +02001505 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1506 __intel_display_power_get_domain(dev_priv, domain);
1507 is_enabled = true;
1508 } else {
1509 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001510 }
1511
Daniel Vetter9c065a72014-09-30 10:56:38 +02001512 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001513
1514 if (!is_enabled)
1515 intel_runtime_pm_put(dev_priv);
1516
1517 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001518}
1519
Daniel Vettere4e76842014-09-30 10:56:42 +02001520/**
1521 * intel_display_power_put - release a power domain reference
1522 * @dev_priv: i915 device instance
1523 * @domain: power domain to reference
1524 *
1525 * This function drops the power domain reference obtained by
1526 * intel_display_power_get() and might power down the corresponding hardware
1527 * block right away if this is the last reference.
1528 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001529void intel_display_power_put(struct drm_i915_private *dev_priv,
1530 enum intel_display_power_domain domain)
1531{
1532 struct i915_power_domains *power_domains;
1533 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001534
1535 power_domains = &dev_priv->power_domains;
1536
1537 mutex_lock(&power_domains->lock);
1538
Daniel Stone11c86db2015-11-20 15:55:34 +00001539 WARN(!power_domains->domain_use_count[domain],
1540 "Use count on domain %s is already zero\n",
1541 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001542 power_domains->domain_use_count[domain]--;
1543
Imre Deak75ccb2e2017-02-17 17:39:43 +02001544 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001545 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001546
1547 mutex_unlock(&power_domains->lock);
1548
1549 intel_runtime_pm_put(dev_priv);
1550}
1551
Imre Deak965a79a2017-07-06 17:40:40 +03001552#define I830_PIPES_POWER_DOMAINS ( \
1553 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1554 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1555 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1556 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1557 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1558 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001559 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001560
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001561#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001562 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1563 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1564 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1565 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1566 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1567 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1568 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1569 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1570 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1571 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1572 BIT_ULL(POWER_DOMAIN_VGA) | \
1573 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1574 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1575 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1576 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1577 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001578
1579#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001580 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1581 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1582 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1583 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1584 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1585 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001586
1587#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001588 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1589 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1590 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001591
1592#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001593 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1594 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1595 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001596
1597#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001598 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1599 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1600 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001601
1602#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001603 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1604 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1605 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001606
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001607#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001608 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1609 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1610 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1611 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1612 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1613 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1614 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1615 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1616 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1617 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1618 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1619 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1620 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1621 BIT_ULL(POWER_DOMAIN_VGA) | \
1622 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1623 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1624 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1625 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1626 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1627 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001628
Daniel Vetter9c065a72014-09-30 10:56:38 +02001629#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001630 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1631 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1632 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1633 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1634 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001635
1636#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001637 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1638 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1639 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001640
Imre Deak965a79a2017-07-06 17:40:40 +03001641#define HSW_DISPLAY_POWER_DOMAINS ( \
1642 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1643 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1644 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1645 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1646 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1647 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1648 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1649 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1650 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1651 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1652 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1653 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1654 BIT_ULL(POWER_DOMAIN_VGA) | \
1655 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1656 BIT_ULL(POWER_DOMAIN_INIT))
1657
1658#define BDW_DISPLAY_POWER_DOMAINS ( \
1659 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1660 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1661 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1662 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1663 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1664 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1665 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1666 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1667 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1668 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1669 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1670 BIT_ULL(POWER_DOMAIN_VGA) | \
1671 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1672 BIT_ULL(POWER_DOMAIN_INIT))
1673
1674#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1675 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1676 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1677 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1678 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1679 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1680 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1681 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1682 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1683 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1684 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1685 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1686 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1687 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1688 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1689 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1690 BIT_ULL(POWER_DOMAIN_VGA) | \
1691 BIT_ULL(POWER_DOMAIN_INIT))
1692#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
1693 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
1694 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1695 BIT_ULL(POWER_DOMAIN_INIT))
1696#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1697 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1698 BIT_ULL(POWER_DOMAIN_INIT))
1699#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1700 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1701 BIT_ULL(POWER_DOMAIN_INIT))
1702#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
1703 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1704 BIT_ULL(POWER_DOMAIN_INIT))
1705#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1706 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
1707 BIT_ULL(POWER_DOMAIN_MODESET) | \
1708 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1709 BIT_ULL(POWER_DOMAIN_INIT))
1710
1711#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1712 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1713 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1714 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1715 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1716 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1717 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1718 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1719 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1720 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1721 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1722 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1723 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1724 BIT_ULL(POWER_DOMAIN_VGA) | \
1725 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1726 BIT_ULL(POWER_DOMAIN_INIT))
1727#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1728 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
1729 BIT_ULL(POWER_DOMAIN_MODESET) | \
1730 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1731 BIT_ULL(POWER_DOMAIN_INIT))
1732#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
1733 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1734 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1735 BIT_ULL(POWER_DOMAIN_INIT))
1736#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
1737 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1738 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1739 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1740 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1741 BIT_ULL(POWER_DOMAIN_INIT))
1742
1743#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1744 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1745 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1746 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1747 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1748 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1749 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1750 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1751 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1752 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1753 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1754 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1755 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1756 BIT_ULL(POWER_DOMAIN_VGA) | \
1757 BIT_ULL(POWER_DOMAIN_INIT))
1758#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
1759 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
1760#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1761 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
1762#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1763 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
1764#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
1765 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1766 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1767 BIT_ULL(POWER_DOMAIN_INIT))
1768#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
1769 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1770 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1771 BIT_ULL(POWER_DOMAIN_INIT))
1772#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
1773 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1774 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1775 BIT_ULL(POWER_DOMAIN_INIT))
1776#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
1777 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1778 BIT_ULL(POWER_DOMAIN_INIT))
1779#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
1780 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1781 BIT_ULL(POWER_DOMAIN_INIT))
1782#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
1783 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1784 BIT_ULL(POWER_DOMAIN_INIT))
1785#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1786 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
1787 BIT_ULL(POWER_DOMAIN_MODESET) | \
1788 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1789 BIT_ULL(POWER_DOMAIN_INIT))
1790
1791#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1792 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1793 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1794 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1795 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1796 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1797 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1798 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1799 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1800 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1801 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001802 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1803 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1804 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1805 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1806 BIT_ULL(POWER_DOMAIN_VGA) | \
1807 BIT_ULL(POWER_DOMAIN_INIT))
1808#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
1809 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001810 BIT_ULL(POWER_DOMAIN_INIT))
1811#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
1812 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1813 BIT_ULL(POWER_DOMAIN_INIT))
1814#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
1815 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1816 BIT_ULL(POWER_DOMAIN_INIT))
1817#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
1818 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1819 BIT_ULL(POWER_DOMAIN_INIT))
1820#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
1821 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1822 BIT_ULL(POWER_DOMAIN_INIT))
1823#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
1824 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1825 BIT_ULL(POWER_DOMAIN_INIT))
1826#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
1827 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1828 BIT_ULL(POWER_DOMAIN_INIT))
1829#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
1830 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1831 BIT_ULL(POWER_DOMAIN_INIT))
1832#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1833 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
1834 BIT_ULL(POWER_DOMAIN_MODESET) | \
1835 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001836 BIT_ULL(POWER_DOMAIN_INIT))
1837
Daniel Vetter9c065a72014-09-30 10:56:38 +02001838static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001839 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001840 .enable = i9xx_always_on_power_well_noop,
1841 .disable = i9xx_always_on_power_well_noop,
1842 .is_enabled = i9xx_always_on_power_well_enabled,
1843};
1844
1845static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001846 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001847 .enable = chv_pipe_power_well_enable,
1848 .disable = chv_pipe_power_well_disable,
1849 .is_enabled = chv_pipe_power_well_enabled,
1850};
1851
1852static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001853 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001854 .enable = chv_dpio_cmn_power_well_enable,
1855 .disable = chv_dpio_cmn_power_well_disable,
1856 .is_enabled = vlv_power_well_enabled,
1857};
1858
1859static struct i915_power_well i9xx_always_on_power_well[] = {
1860 {
1861 .name = "always-on",
1862 .always_on = 1,
1863 .domains = POWER_DOMAIN_MASK,
1864 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001865 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001866 },
1867};
1868
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001869static const struct i915_power_well_ops i830_pipes_power_well_ops = {
1870 .sync_hw = i830_pipes_power_well_sync_hw,
1871 .enable = i830_pipes_power_well_enable,
1872 .disable = i830_pipes_power_well_disable,
1873 .is_enabled = i830_pipes_power_well_enabled,
1874};
1875
1876static struct i915_power_well i830_power_wells[] = {
1877 {
1878 .name = "always-on",
1879 .always_on = 1,
1880 .domains = POWER_DOMAIN_MASK,
1881 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001882 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001883 },
1884 {
1885 .name = "pipes",
1886 .domains = I830_PIPES_POWER_DOMAINS,
1887 .ops = &i830_pipes_power_well_ops,
Imre Deak120b56a2017-07-11 23:42:31 +03001888 .id = I830_DISP_PW_PIPES,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001889 },
1890};
1891
Daniel Vetter9c065a72014-09-30 10:56:38 +02001892static const struct i915_power_well_ops hsw_power_well_ops = {
1893 .sync_hw = hsw_power_well_sync_hw,
1894 .enable = hsw_power_well_enable,
1895 .disable = hsw_power_well_disable,
1896 .is_enabled = hsw_power_well_enabled,
1897};
1898
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001899static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001900 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001901 .enable = gen9_dc_off_power_well_enable,
1902 .disable = gen9_dc_off_power_well_disable,
1903 .is_enabled = gen9_dc_off_power_well_enabled,
1904};
1905
Imre Deak9c8d0b82016-06-13 16:44:34 +03001906static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001907 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03001908 .enable = bxt_dpio_cmn_power_well_enable,
1909 .disable = bxt_dpio_cmn_power_well_disable,
1910 .is_enabled = bxt_dpio_cmn_power_well_enabled,
1911};
1912
Daniel Vetter9c065a72014-09-30 10:56:38 +02001913static struct i915_power_well hsw_power_wells[] = {
1914 {
1915 .name = "always-on",
1916 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001917 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001918 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001919 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001920 },
1921 {
1922 .name = "display",
1923 .domains = HSW_DISPLAY_POWER_DOMAINS,
1924 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03001925 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03001926 {
1927 .hsw.has_vga = true,
1928 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001929 },
1930};
1931
1932static struct i915_power_well bdw_power_wells[] = {
1933 {
1934 .name = "always-on",
1935 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001936 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001937 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001938 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001939 },
1940 {
1941 .name = "display",
1942 .domains = BDW_DISPLAY_POWER_DOMAINS,
1943 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03001944 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03001945 {
1946 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
1947 .hsw.has_vga = true,
1948 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001949 },
1950};
1951
1952static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001953 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001954 .enable = vlv_display_power_well_enable,
1955 .disable = vlv_display_power_well_disable,
1956 .is_enabled = vlv_power_well_enabled,
1957};
1958
1959static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001960 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001961 .enable = vlv_dpio_cmn_power_well_enable,
1962 .disable = vlv_dpio_cmn_power_well_disable,
1963 .is_enabled = vlv_power_well_enabled,
1964};
1965
1966static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001967 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001968 .enable = vlv_power_well_enable,
1969 .disable = vlv_power_well_disable,
1970 .is_enabled = vlv_power_well_enabled,
1971};
1972
1973static struct i915_power_well vlv_power_wells[] = {
1974 {
1975 .name = "always-on",
1976 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001977 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001978 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03001979 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001980 },
1981 {
1982 .name = "display",
1983 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001984 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001985 .ops = &vlv_display_power_well_ops,
1986 },
1987 {
1988 .name = "dpio-tx-b-01",
1989 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1990 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1991 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1992 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1993 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001994 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001995 },
1996 {
1997 .name = "dpio-tx-b-23",
1998 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1999 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2000 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2001 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2002 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002003 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002004 },
2005 {
2006 .name = "dpio-tx-c-01",
2007 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2008 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2009 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2010 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2011 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002012 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002013 },
2014 {
2015 .name = "dpio-tx-c-23",
2016 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2017 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2018 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2019 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2020 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002021 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002022 },
2023 {
2024 .name = "dpio-common",
2025 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002026 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002027 .ops = &vlv_dpio_cmn_power_well_ops,
2028 },
2029};
2030
2031static struct i915_power_well chv_power_wells[] = {
2032 {
2033 .name = "always-on",
2034 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002035 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002036 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002037 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002038 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002039 {
2040 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002041 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002042 * Pipe A power well is the new disp2d well. Pipe B and C
2043 * power wells don't actually exist. Pipe A power well is
2044 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002045 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002046 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002047 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002048 .ops = &chv_pipe_power_well_ops,
2049 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002050 {
2051 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002052 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002053 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002054 .ops = &chv_dpio_cmn_power_well_ops,
2055 },
2056 {
2057 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002058 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002059 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002060 .ops = &chv_dpio_cmn_power_well_ops,
2061 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002062};
2063
Suketu Shah5aefb232015-04-16 14:22:10 +05302064bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002065 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302066{
2067 struct i915_power_well *power_well;
2068 bool ret;
2069
2070 power_well = lookup_power_well(dev_priv, power_well_id);
2071 ret = power_well->ops->is_enabled(dev_priv, power_well);
2072
2073 return ret;
2074}
2075
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002076static struct i915_power_well skl_power_wells[] = {
2077 {
2078 .name = "always-on",
2079 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002080 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002081 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002082 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002083 },
2084 {
2085 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002086 /* Handled by the DMC firmware */
2087 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002088 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002089 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002090 {
2091 .hsw.has_fuses = true,
2092 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002093 },
2094 {
2095 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002096 /* Handled by the DMC firmware */
2097 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002098 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002099 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002100 },
2101 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002102 .name = "DC off",
2103 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2104 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002105 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002106 },
2107 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002108 .name = "power well 2",
2109 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002110 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002111 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002112 {
2113 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2114 .hsw.has_vga = true,
2115 .hsw.has_fuses = true,
2116 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002117 },
2118 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002119 .name = "DDI A/E IO power well",
2120 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002121 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002122 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002123 },
2124 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002125 .name = "DDI B IO power well",
2126 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002127 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002128 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002129 },
2130 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002131 .name = "DDI C IO power well",
2132 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002133 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002134 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002135 },
2136 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002137 .name = "DDI D IO power well",
2138 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002139 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002140 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002141 },
2142};
2143
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302144static struct i915_power_well bxt_power_wells[] = {
2145 {
2146 .name = "always-on",
2147 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002148 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302149 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002150 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302151 },
2152 {
2153 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002154 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002155 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002156 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002157 {
2158 .hsw.has_fuses = true,
2159 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302160 },
2161 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002162 .name = "DC off",
2163 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2164 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002165 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002166 },
2167 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302168 .name = "power well 2",
2169 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002170 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002171 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002172 {
2173 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2174 .hsw.has_vga = true,
2175 .hsw.has_fuses = true,
2176 },
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002177 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002178 {
2179 .name = "dpio-common-a",
2180 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2181 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002182 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002183 {
2184 .bxt.phy = DPIO_PHY1,
2185 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002186 },
2187 {
2188 .name = "dpio-common-bc",
2189 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2190 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002191 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002192 {
2193 .bxt.phy = DPIO_PHY0,
2194 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002195 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302196};
2197
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002198static struct i915_power_well glk_power_wells[] = {
2199 {
2200 .name = "always-on",
2201 .always_on = 1,
2202 .domains = POWER_DOMAIN_MASK,
2203 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002204 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002205 },
2206 {
2207 .name = "power well 1",
2208 /* Handled by the DMC firmware */
2209 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002210 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002211 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002212 {
2213 .hsw.has_fuses = true,
2214 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002215 },
2216 {
2217 .name = "DC off",
2218 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2219 .ops = &gen9_dc_off_power_well_ops,
2220 .id = SKL_DISP_PW_DC_OFF,
2221 },
2222 {
2223 .name = "power well 2",
2224 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002225 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002226 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002227 {
2228 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2229 .hsw.has_vga = true,
2230 .hsw.has_fuses = true,
2231 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002232 },
2233 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002234 .name = "dpio-common-a",
2235 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2236 .ops = &bxt_dpio_cmn_power_well_ops,
2237 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002238 {
2239 .bxt.phy = DPIO_PHY1,
2240 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002241 },
2242 {
2243 .name = "dpio-common-b",
2244 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2245 .ops = &bxt_dpio_cmn_power_well_ops,
2246 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002247 {
2248 .bxt.phy = DPIO_PHY0,
2249 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002250 },
2251 {
2252 .name = "dpio-common-c",
2253 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2254 .ops = &bxt_dpio_cmn_power_well_ops,
2255 .id = GLK_DPIO_CMN_C,
Imre Deak0a445942017-08-14 18:15:29 +03002256 {
2257 .bxt.phy = DPIO_PHY2,
2258 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002259 },
2260 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002261 .name = "AUX A",
2262 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002263 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002264 .id = GLK_DISP_PW_AUX_A,
2265 },
2266 {
2267 .name = "AUX B",
2268 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002269 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002270 .id = GLK_DISP_PW_AUX_B,
2271 },
2272 {
2273 .name = "AUX C",
2274 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002275 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002276 .id = GLK_DISP_PW_AUX_C,
2277 },
2278 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002279 .name = "DDI A IO power well",
2280 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002281 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002282 .id = GLK_DISP_PW_DDI_A,
2283 },
2284 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002285 .name = "DDI B IO power well",
2286 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002287 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002288 .id = SKL_DISP_PW_DDI_B,
2289 },
2290 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002291 .name = "DDI C IO power well",
2292 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002293 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002294 .id = SKL_DISP_PW_DDI_C,
2295 },
2296};
2297
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002298static struct i915_power_well cnl_power_wells[] = {
2299 {
2300 .name = "always-on",
2301 .always_on = 1,
2302 .domains = POWER_DOMAIN_MASK,
2303 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002304 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002305 },
2306 {
2307 .name = "power well 1",
2308 /* Handled by the DMC firmware */
2309 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002310 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002311 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002312 {
2313 .hsw.has_fuses = true,
2314 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002315 },
2316 {
2317 .name = "AUX A",
2318 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002319 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002320 .id = CNL_DISP_PW_AUX_A,
2321 },
2322 {
2323 .name = "AUX B",
2324 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002325 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002326 .id = CNL_DISP_PW_AUX_B,
2327 },
2328 {
2329 .name = "AUX C",
2330 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002331 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002332 .id = CNL_DISP_PW_AUX_C,
2333 },
2334 {
2335 .name = "AUX D",
2336 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002337 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002338 .id = CNL_DISP_PW_AUX_D,
2339 },
2340 {
2341 .name = "DC off",
2342 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2343 .ops = &gen9_dc_off_power_well_ops,
2344 .id = SKL_DISP_PW_DC_OFF,
2345 },
2346 {
2347 .name = "power well 2",
2348 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002349 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002350 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002351 {
2352 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2353 .hsw.has_vga = true,
2354 .hsw.has_fuses = true,
2355 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002356 },
2357 {
2358 .name = "DDI A IO power well",
2359 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002360 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002361 .id = CNL_DISP_PW_DDI_A,
2362 },
2363 {
2364 .name = "DDI B IO power well",
2365 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002366 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002367 .id = SKL_DISP_PW_DDI_B,
2368 },
2369 {
2370 .name = "DDI C IO power well",
2371 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002372 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002373 .id = SKL_DISP_PW_DDI_C,
2374 },
2375 {
2376 .name = "DDI D IO power well",
2377 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002378 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002379 .id = SKL_DISP_PW_DDI_D,
2380 },
2381};
2382
Imre Deak1b0e3a02015-11-05 23:04:11 +02002383static int
2384sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2385 int disable_power_well)
2386{
2387 if (disable_power_well >= 0)
2388 return !!disable_power_well;
2389
Imre Deak1b0e3a02015-11-05 23:04:11 +02002390 return 1;
2391}
2392
Imre Deaka37baf32016-02-29 22:49:03 +02002393static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2394 int enable_dc)
2395{
2396 uint32_t mask;
2397 int requested_dc;
2398 int max_dc;
2399
Rodrigo Vivi6d6a8972017-07-06 13:45:08 -07002400 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002401 max_dc = 2;
2402 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002403 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002404 max_dc = 1;
2405 /*
2406 * DC9 has a separate HW flow from the rest of the DC states,
2407 * not depending on the DMC firmware. It's needed by system
2408 * suspend/resume, so allow it unconditionally.
2409 */
2410 mask = DC_STATE_EN_DC9;
2411 } else {
2412 max_dc = 0;
2413 mask = 0;
2414 }
2415
Imre Deak66e2c4c2016-02-29 22:49:04 +02002416 if (!i915.disable_power_well)
2417 max_dc = 0;
2418
Imre Deaka37baf32016-02-29 22:49:03 +02002419 if (enable_dc >= 0 && enable_dc <= max_dc) {
2420 requested_dc = enable_dc;
2421 } else if (enable_dc == -1) {
2422 requested_dc = max_dc;
2423 } else if (enable_dc > max_dc && enable_dc <= 2) {
2424 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2425 enable_dc, max_dc);
2426 requested_dc = max_dc;
2427 } else {
2428 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2429 requested_dc = max_dc;
2430 }
2431
2432 if (requested_dc > 1)
2433 mask |= DC_STATE_EN_UPTO_DC6;
2434 if (requested_dc > 0)
2435 mask |= DC_STATE_EN_UPTO_DC5;
2436
2437 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2438
2439 return mask;
2440}
2441
Imre Deak21792c62017-07-11 23:42:33 +03002442static void assert_power_well_ids_unique(struct drm_i915_private *dev_priv)
2443{
2444 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2445 u64 power_well_ids;
2446 int i;
2447
2448 power_well_ids = 0;
2449 for (i = 0; i < power_domains->power_well_count; i++) {
2450 enum i915_power_well_id id = power_domains->power_wells[i].id;
2451
2452 WARN_ON(id >= sizeof(power_well_ids) * 8);
2453 WARN_ON(power_well_ids & BIT_ULL(id));
2454 power_well_ids |= BIT_ULL(id);
2455 }
2456}
2457
Daniel Vetter9c065a72014-09-30 10:56:38 +02002458#define set_power_wells(power_domains, __power_wells) ({ \
2459 (power_domains)->power_wells = (__power_wells); \
2460 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2461})
2462
Daniel Vettere4e76842014-09-30 10:56:42 +02002463/**
2464 * intel_power_domains_init - initializes the power domain structures
2465 * @dev_priv: i915 device instance
2466 *
2467 * Initializes the power domain structures for @dev_priv depending upon the
2468 * supported platform.
2469 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002470int intel_power_domains_init(struct drm_i915_private *dev_priv)
2471{
2472 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2473
Imre Deak1b0e3a02015-11-05 23:04:11 +02002474 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2475 i915.disable_power_well);
Imre Deaka37baf32016-02-29 22:49:03 +02002476 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2477 i915.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002478
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002479 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002480
Daniel Vetter9c065a72014-09-30 10:56:38 +02002481 mutex_init(&power_domains->lock);
2482
2483 /*
2484 * The enabling order will be from lower to higher indexed wells,
2485 * the disabling order is reversed.
2486 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002487 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002488 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002489 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002490 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002491 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002492 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002493 } else if (IS_CANNONLAKE(dev_priv)) {
2494 set_power_wells(power_domains, cnl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002495 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302496 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002497 } else if (IS_GEMINILAKE(dev_priv)) {
2498 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002499 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002500 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002501 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002502 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002503 } else if (IS_I830(dev_priv)) {
2504 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002505 } else {
2506 set_power_wells(power_domains, i9xx_always_on_power_well);
2507 }
2508
Imre Deak21792c62017-07-11 23:42:33 +03002509 assert_power_well_ids_unique(dev_priv);
2510
Daniel Vetter9c065a72014-09-30 10:56:38 +02002511 return 0;
2512}
2513
Daniel Vettere4e76842014-09-30 10:56:42 +02002514/**
2515 * intel_power_domains_fini - finalizes the power domain structures
2516 * @dev_priv: i915 device instance
2517 *
2518 * Finalizes the power domain structures for @dev_priv depending upon the
2519 * supported platform. This function also disables runtime pm and ensures that
2520 * the device stays powered up so that the driver can be reloaded.
2521 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002522void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002523{
David Weinehallc49d13e2016-08-22 13:32:42 +03002524 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002525
Imre Deakaabee1b2015-12-15 20:10:29 +02002526 /*
2527 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002528 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002529 * we're going to unload/reload.
2530 * The following also reacquires the RPM reference the core passed
2531 * to the driver during loading, which is dropped in
2532 * intel_runtime_pm_enable(). We have to hand back the control of the
2533 * device to the core with this reference held.
2534 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002535 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002536
2537 /* Remove the refcount we took to keep power well support disabled. */
2538 if (!i915.disable_power_well)
2539 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002540
2541 /*
2542 * Remove the refcount we took in intel_runtime_pm_enable() in case
2543 * the platform doesn't support runtime PM.
2544 */
2545 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002546 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002547}
2548
Imre Deak30eade12015-11-04 19:24:13 +02002549static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002550{
2551 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2552 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002553
2554 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002555 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002556 power_well->ops->sync_hw(dev_priv, power_well);
2557 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2558 power_well);
2559 }
2560 mutex_unlock(&power_domains->lock);
2561}
2562
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002563static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2564{
2565 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2566 POSTING_READ(DBUF_CTL);
2567
2568 udelay(10);
2569
2570 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2571 DRM_ERROR("DBuf power enable timeout\n");
2572}
2573
2574static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2575{
2576 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2577 POSTING_READ(DBUF_CTL);
2578
2579 udelay(10);
2580
2581 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2582 DRM_ERROR("DBuf power disable timeout!\n");
2583}
2584
Imre Deak73dfc222015-11-17 17:33:53 +02002585static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002586 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002587{
2588 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002589 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002590 uint32_t val;
2591
Imre Deakd26fa1d2015-11-04 19:24:17 +02002592 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2593
Imre Deak73dfc222015-11-17 17:33:53 +02002594 /* enable PCH reset handshake */
2595 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2596 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2597
2598 /* enable PG1 and Misc I/O */
2599 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002600
2601 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2602 intel_power_well_enable(dev_priv, well);
2603
2604 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2605 intel_power_well_enable(dev_priv, well);
2606
Imre Deak73dfc222015-11-17 17:33:53 +02002607 mutex_unlock(&power_domains->lock);
2608
Imre Deak73dfc222015-11-17 17:33:53 +02002609 skl_init_cdclk(dev_priv);
2610
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002611 gen9_dbuf_enable(dev_priv);
2612
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002613 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002614 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002615}
2616
2617static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2618{
2619 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002620 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002621
Imre Deakd26fa1d2015-11-04 19:24:17 +02002622 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2623
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002624 gen9_dbuf_disable(dev_priv);
2625
Imre Deak73dfc222015-11-17 17:33:53 +02002626 skl_uninit_cdclk(dev_priv);
2627
2628 /* The spec doesn't call for removing the reset handshake flag */
2629 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002630
Imre Deak73dfc222015-11-17 17:33:53 +02002631 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002632
Imre Deakedfda8e2017-06-29 18:36:59 +03002633 /*
2634 * BSpec says to keep the MISC IO power well enabled here, only
2635 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03002636 * Note that even though the driver's request is removed power well 1
2637 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03002638 */
Imre Deak443a93a2016-04-04 15:42:57 +03002639 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2640 intel_power_well_disable(dev_priv, well);
2641
Imre Deak73dfc222015-11-17 17:33:53 +02002642 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002643
2644 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02002645}
2646
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002647void bxt_display_core_init(struct drm_i915_private *dev_priv,
2648 bool resume)
2649{
2650 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2651 struct i915_power_well *well;
2652 uint32_t val;
2653
2654 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2655
2656 /*
2657 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2658 * or else the reset will hang because there is no PCH to respond.
2659 * Move the handshake programming to initialization sequence.
2660 * Previously was left up to BIOS.
2661 */
2662 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2663 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2664 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2665
2666 /* Enable PG1 */
2667 mutex_lock(&power_domains->lock);
2668
2669 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2670 intel_power_well_enable(dev_priv, well);
2671
2672 mutex_unlock(&power_domains->lock);
2673
Imre Deak324513c2016-06-13 16:44:36 +03002674 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002675
2676 gen9_dbuf_enable(dev_priv);
2677
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002678 if (resume && dev_priv->csr.dmc_payload)
2679 intel_csr_load_program(dev_priv);
2680}
2681
2682void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2683{
2684 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2685 struct i915_power_well *well;
2686
2687 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2688
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002689 gen9_dbuf_disable(dev_priv);
2690
Imre Deak324513c2016-06-13 16:44:36 +03002691 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002692
2693 /* The spec doesn't call for removing the reset handshake flag */
2694
Imre Deak42d93662017-06-29 18:37:01 +03002695 /*
2696 * Disable PW1 (PG1).
2697 * Note that even though the driver's request is removed power well 1
2698 * may stay enabled after this due to DMC's own request on it.
2699 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002700 mutex_lock(&power_domains->lock);
2701
2702 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2703 intel_power_well_disable(dev_priv, well);
2704
2705 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002706
2707 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002708}
2709
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002710#define CNL_PROCMON_IDX(val) \
2711 (((val) & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) >> VOLTAGE_INFO_SHIFT)
2712#define NUM_CNL_PROCMON \
2713 (CNL_PROCMON_IDX(VOLTAGE_INFO_MASK | PROCESS_INFO_MASK) + 1)
2714
2715static const struct cnl_procmon {
2716 u32 dw1, dw9, dw10;
2717} cnl_procmon_values[NUM_CNL_PROCMON] = {
2718 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0)] =
2719 { .dw1 = 0x00 << 16, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
2720 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0)] =
2721 { .dw1 = 0x00 << 16, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
2722 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1)] =
2723 { .dw1 = 0x00 << 16, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
2724 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0)] =
2725 { .dw1 = 0x00 << 16, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
2726 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1)] =
2727 { .dw1 = 0x44 << 16, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
2728};
2729
2730static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
2731{
2732 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2733 const struct cnl_procmon *procmon;
2734 struct i915_power_well *well;
2735 u32 val;
2736
2737 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2738
2739 /* 1. Enable PCH Reset Handshake */
2740 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2741 val |= RESET_PCH_HANDSHAKE_ENABLE;
2742 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2743
2744 /* 2. Enable Comp */
2745 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03002746 val &= ~CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002747 I915_WRITE(CHICKEN_MISC_2, val);
2748
2749 val = I915_READ(CNL_PORT_COMP_DW3);
2750 procmon = &cnl_procmon_values[CNL_PROCMON_IDX(val)];
2751
2752 WARN_ON(procmon->dw10 == 0);
2753
2754 val = I915_READ(CNL_PORT_COMP_DW1);
2755 val &= ~((0xff << 16) | 0xff);
2756 val |= procmon->dw1;
2757 I915_WRITE(CNL_PORT_COMP_DW1, val);
2758
2759 I915_WRITE(CNL_PORT_COMP_DW9, procmon->dw9);
2760 I915_WRITE(CNL_PORT_COMP_DW10, procmon->dw10);
2761
2762 val = I915_READ(CNL_PORT_COMP_DW0);
2763 val |= COMP_INIT;
2764 I915_WRITE(CNL_PORT_COMP_DW0, val);
2765
2766 /* 3. */
2767 val = I915_READ(CNL_PORT_CL1CM_DW5);
2768 val |= CL_POWER_DOWN_ENABLE;
2769 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2770
Imre Deakb38131f2017-06-29 18:37:02 +03002771 /*
2772 * 4. Enable Power Well 1 (PG1).
2773 * The AUX IO power wells will be enabled on demand.
2774 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002775 mutex_lock(&power_domains->lock);
2776 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2777 intel_power_well_enable(dev_priv, well);
2778 mutex_unlock(&power_domains->lock);
2779
2780 /* 5. Enable CD clock */
2781 cnl_init_cdclk(dev_priv);
2782
2783 /* 6. Enable DBUF */
2784 gen9_dbuf_enable(dev_priv);
2785}
2786
2787#undef CNL_PROCMON_IDX
2788#undef NUM_CNL_PROCMON
2789
2790static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
2791{
2792 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2793 struct i915_power_well *well;
2794 u32 val;
2795
2796 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2797
2798 /* 1. Disable all display engine functions -> aready done */
2799
2800 /* 2. Disable DBUF */
2801 gen9_dbuf_disable(dev_priv);
2802
2803 /* 3. Disable CD clock */
2804 cnl_uninit_cdclk(dev_priv);
2805
Imre Deakb38131f2017-06-29 18:37:02 +03002806 /*
2807 * 4. Disable Power Well 1 (PG1).
2808 * The AUX IO power wells are toggled on demand, so they are already
2809 * disabled at this point.
2810 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002811 mutex_lock(&power_domains->lock);
2812 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2813 intel_power_well_disable(dev_priv, well);
2814 mutex_unlock(&power_domains->lock);
2815
Imre Deak846c6b22017-06-29 18:36:58 +03002816 usleep_range(10, 30); /* 10 us delay per Bspec */
2817
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002818 /* 5. Disable Comp */
2819 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03002820 val |= CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002821 I915_WRITE(CHICKEN_MISC_2, val);
2822}
2823
Ville Syrjälä70722462015-04-10 18:21:28 +03002824static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2825{
2826 struct i915_power_well *cmn_bc =
2827 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2828 struct i915_power_well *cmn_d =
2829 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2830
2831 /*
2832 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2833 * workaround never ever read DISPLAY_PHY_CONTROL, and
2834 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002835 * power well state and lane status to reconstruct the
2836 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002837 */
2838 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002839 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2840 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002841 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2842 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2843 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2844
2845 /*
2846 * If all lanes are disabled we leave the override disabled
2847 * with all power down bits cleared to match the state we
2848 * would use after disabling the port. Otherwise enable the
2849 * override and set the lane powerdown bits accding to the
2850 * current lane status.
2851 */
2852 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2853 uint32_t status = I915_READ(DPLL(PIPE_A));
2854 unsigned int mask;
2855
2856 mask = status & DPLL_PORTB_READY_MASK;
2857 if (mask == 0xf)
2858 mask = 0x0;
2859 else
2860 dev_priv->chv_phy_control |=
2861 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2862
2863 dev_priv->chv_phy_control |=
2864 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2865
2866 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2867 if (mask == 0xf)
2868 mask = 0x0;
2869 else
2870 dev_priv->chv_phy_control |=
2871 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2872
2873 dev_priv->chv_phy_control |=
2874 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2875
Ville Syrjälä70722462015-04-10 18:21:28 +03002876 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002877
2878 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2879 } else {
2880 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002881 }
2882
2883 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2884 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2885 unsigned int mask;
2886
2887 mask = status & DPLL_PORTD_READY_MASK;
2888
2889 if (mask == 0xf)
2890 mask = 0x0;
2891 else
2892 dev_priv->chv_phy_control |=
2893 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2894
2895 dev_priv->chv_phy_control |=
2896 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2897
Ville Syrjälä70722462015-04-10 18:21:28 +03002898 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002899
2900 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2901 } else {
2902 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002903 }
2904
2905 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2906
2907 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2908 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002909}
2910
Daniel Vetter9c065a72014-09-30 10:56:38 +02002911static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2912{
2913 struct i915_power_well *cmn =
2914 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2915 struct i915_power_well *disp2d =
2916 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2917
Daniel Vetter9c065a72014-09-30 10:56:38 +02002918 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03002919 if (cmn->ops->is_enabled(dev_priv, cmn) &&
2920 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02002921 I915_READ(DPIO_CTL) & DPIO_CMNRST)
2922 return;
2923
2924 DRM_DEBUG_KMS("toggling display PHY side reset\n");
2925
2926 /* cmnlane needs DPLL registers */
2927 disp2d->ops->enable(dev_priv, disp2d);
2928
2929 /*
2930 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2931 * Need to assert and de-assert PHY SB reset by gating the
2932 * common lane power, then un-gating it.
2933 * Simply ungating isn't enough to reset the PHY enough to get
2934 * ports and lanes running.
2935 */
2936 cmn->ops->disable(dev_priv, cmn);
2937}
2938
Daniel Vettere4e76842014-09-30 10:56:42 +02002939/**
2940 * intel_power_domains_init_hw - initialize hardware power domain state
2941 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002942 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02002943 *
2944 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02002945 * power wells belonging to the INIT power domain. Power wells in other
2946 * domains (and not in the INIT domain) are referenced or disabled during the
2947 * modeset state HW readout. After that the reference count of each power well
2948 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02002949 */
Imre Deak73dfc222015-11-17 17:33:53 +02002950void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002951{
Daniel Vetter9c065a72014-09-30 10:56:38 +02002952 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2953
2954 power_domains->initializing = true;
2955
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002956 if (IS_CANNONLAKE(dev_priv)) {
2957 cnl_display_core_init(dev_priv, resume);
2958 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02002959 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02002960 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002961 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002962 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03002963 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03002964 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03002965 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01002966 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002967 mutex_lock(&power_domains->lock);
2968 vlv_cmnlane_wa(dev_priv);
2969 mutex_unlock(&power_domains->lock);
2970 }
2971
2972 /* For now, we need the power well to be always enabled. */
2973 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002974 /* Disable power support if the user asked so. */
2975 if (!i915.disable_power_well)
2976 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02002977 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002978 power_domains->initializing = false;
2979}
2980
Daniel Vettere4e76842014-09-30 10:56:42 +02002981/**
Imre Deak73dfc222015-11-17 17:33:53 +02002982 * intel_power_domains_suspend - suspend power domain state
2983 * @dev_priv: i915 device instance
2984 *
2985 * This function prepares the hardware power domain state before entering
2986 * system suspend. It must be paired with intel_power_domains_init_hw().
2987 */
2988void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
2989{
Imre Deakd314cd42015-11-17 17:44:23 +02002990 /*
2991 * Even if power well support was disabled we still want to disable
2992 * power wells while we are system suspended.
2993 */
2994 if (!i915.disable_power_well)
2995 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02002996
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002997 if (IS_CANNONLAKE(dev_priv))
2998 cnl_display_core_uninit(dev_priv);
2999 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003000 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003001 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003002 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003003}
3004
Imre Deak8d8c3862017-02-17 17:39:46 +02003005static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3006{
3007 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3008 struct i915_power_well *power_well;
3009
3010 for_each_power_well(dev_priv, power_well) {
3011 enum intel_display_power_domain domain;
3012
3013 DRM_DEBUG_DRIVER("%-25s %d\n",
3014 power_well->name, power_well->count);
3015
3016 for_each_power_domain(domain, power_well->domains)
3017 DRM_DEBUG_DRIVER(" %-23s %d\n",
3018 intel_display_power_domain_str(domain),
3019 power_domains->domain_use_count[domain]);
3020 }
3021}
3022
3023/**
3024 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3025 * @dev_priv: i915 device instance
3026 *
3027 * Verify if the reference count of each power well matches its HW enabled
3028 * state and the total refcount of the domains it belongs to. This must be
3029 * called after modeset HW state sanitization, which is responsible for
3030 * acquiring reference counts for any power wells in use and disabling the
3031 * ones left on by BIOS but not required by any active output.
3032 */
3033void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3034{
3035 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3036 struct i915_power_well *power_well;
3037 bool dump_domain_info;
3038
3039 mutex_lock(&power_domains->lock);
3040
3041 dump_domain_info = false;
3042 for_each_power_well(dev_priv, power_well) {
3043 enum intel_display_power_domain domain;
3044 int domains_count;
3045 bool enabled;
3046
3047 /*
3048 * Power wells not belonging to any domain (like the MISC_IO
3049 * and PW1 power wells) are under FW control, so ignore them,
3050 * since their state can change asynchronously.
3051 */
3052 if (!power_well->domains)
3053 continue;
3054
3055 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3056 if ((power_well->count || power_well->always_on) != enabled)
3057 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3058 power_well->name, power_well->count, enabled);
3059
3060 domains_count = 0;
3061 for_each_power_domain(domain, power_well->domains)
3062 domains_count += power_domains->domain_use_count[domain];
3063
3064 if (power_well->count != domains_count) {
3065 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3066 "(refcount %d/domains refcount %d)\n",
3067 power_well->name, power_well->count,
3068 domains_count);
3069 dump_domain_info = true;
3070 }
3071 }
3072
3073 if (dump_domain_info) {
3074 static bool dumped;
3075
3076 if (!dumped) {
3077 intel_power_domains_dump_info(dev_priv);
3078 dumped = true;
3079 }
3080 }
3081
3082 mutex_unlock(&power_domains->lock);
3083}
3084
Imre Deak73dfc222015-11-17 17:33:53 +02003085/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003086 * intel_runtime_pm_get - grab a runtime pm reference
3087 * @dev_priv: i915 device instance
3088 *
3089 * This function grabs a device-level runtime pm reference (mostly used for GEM
3090 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3091 *
3092 * Any runtime pm reference obtained by this function must have a symmetric
3093 * call to intel_runtime_pm_put() to release the reference again.
3094 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003095void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3096{
David Weinehall52a05c32016-08-22 13:32:44 +03003097 struct pci_dev *pdev = dev_priv->drm.pdev;
3098 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003099 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003100
Imre Deakf5073822017-03-28 12:38:55 +03003101 ret = pm_runtime_get_sync(kdev);
3102 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003103
3104 atomic_inc(&dev_priv->pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003105 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003106}
3107
Daniel Vettere4e76842014-09-30 10:56:42 +02003108/**
Imre Deak09731282016-02-17 14:17:42 +02003109 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3110 * @dev_priv: i915 device instance
3111 *
3112 * This function grabs a device-level runtime pm reference if the device is
3113 * already in use and ensures that it is powered up.
3114 *
3115 * Any runtime pm reference obtained by this function must have a symmetric
3116 * call to intel_runtime_pm_put() to release the reference again.
3117 */
3118bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3119{
David Weinehall52a05c32016-08-22 13:32:44 +03003120 struct pci_dev *pdev = dev_priv->drm.pdev;
3121 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003122
Chris Wilson135dc792016-02-25 21:10:28 +00003123 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03003124 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02003125
Chris Wilson135dc792016-02-25 21:10:28 +00003126 /*
3127 * In cases runtime PM is disabled by the RPM core and we get
3128 * an -EINVAL return value we are not supposed to call this
3129 * function, since the power state is undefined. This applies
3130 * atm to the late/early system suspend/resume handlers.
3131 */
Imre Deakf5073822017-03-28 12:38:55 +03003132 WARN_ONCE(ret < 0,
3133 "pm_runtime_get_if_in_use() failed: %d\n", ret);
Chris Wilson135dc792016-02-25 21:10:28 +00003134 if (ret <= 0)
3135 return false;
3136 }
Imre Deak09731282016-02-17 14:17:42 +02003137
3138 atomic_inc(&dev_priv->pm.wakeref_count);
3139 assert_rpm_wakelock_held(dev_priv);
3140
3141 return true;
3142}
3143
3144/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003145 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3146 * @dev_priv: i915 device instance
3147 *
3148 * This function grabs a device-level runtime pm reference (mostly used for GEM
3149 * code to ensure the GTT or GT is on).
3150 *
3151 * It will _not_ power up the device but instead only check that it's powered
3152 * on. Therefore it is only valid to call this functions from contexts where
3153 * the device is known to be powered up and where trying to power it up would
3154 * result in hilarity and deadlocks. That pretty much means only the system
3155 * suspend/resume code where this is used to grab runtime pm references for
3156 * delayed setup down in work items.
3157 *
3158 * Any runtime pm reference obtained by this function must have a symmetric
3159 * call to intel_runtime_pm_put() to release the reference again.
3160 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003161void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3162{
David Weinehall52a05c32016-08-22 13:32:44 +03003163 struct pci_dev *pdev = dev_priv->drm.pdev;
3164 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003165
Imre Deakc9b88462015-12-15 20:10:34 +02003166 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003167 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003168
3169 atomic_inc(&dev_priv->pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003170}
3171
Daniel Vettere4e76842014-09-30 10:56:42 +02003172/**
3173 * intel_runtime_pm_put - release a runtime pm reference
3174 * @dev_priv: i915 device instance
3175 *
3176 * This function drops the device-level runtime pm reference obtained by
3177 * intel_runtime_pm_get() and might power down the corresponding
3178 * hardware block right away if this is the last reference.
3179 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003180void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3181{
David Weinehall52a05c32016-08-22 13:32:44 +03003182 struct pci_dev *pdev = dev_priv->drm.pdev;
3183 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003184
Imre Deak542db3c2015-12-15 20:10:36 +02003185 assert_rpm_wakelock_held(dev_priv);
Chris Wilson2eedfc72016-10-24 13:42:17 +01003186 atomic_dec(&dev_priv->pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003187
David Weinehallc49d13e2016-08-22 13:32:42 +03003188 pm_runtime_mark_last_busy(kdev);
3189 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003190}
3191
Daniel Vettere4e76842014-09-30 10:56:42 +02003192/**
3193 * intel_runtime_pm_enable - enable runtime pm
3194 * @dev_priv: i915 device instance
3195 *
3196 * This function enables runtime pm at the end of the driver load sequence.
3197 *
3198 * Note that this function does currently not enable runtime pm for the
3199 * subordinate display power domains. That is only done on the first modeset
3200 * using intel_display_set_init_power().
3201 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003202void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003203{
David Weinehall52a05c32016-08-22 13:32:44 +03003204 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003205 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003206
David Weinehallc49d13e2016-08-22 13:32:42 +03003207 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3208 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003209
Imre Deak25b181b2015-12-17 13:44:56 +02003210 /*
3211 * Take a permanent reference to disable the RPM functionality and drop
3212 * it only when unloading the driver. Use the low level get/put helpers,
3213 * so the driver's own RPM reference tracking asserts also work on
3214 * platforms without RPM support.
3215 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003216 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003217 int ret;
3218
David Weinehallc49d13e2016-08-22 13:32:42 +03003219 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003220 ret = pm_runtime_get_sync(kdev);
3221 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003222 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003223 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003224 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003225
Imre Deakaabee1b2015-12-15 20:10:29 +02003226 /*
3227 * The core calls the driver load handler with an RPM reference held.
3228 * We drop that here and will reacquire it during unloading in
3229 * intel_power_domains_fini().
3230 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003231 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003232}