blob: 3f24483071af4eca7cebc24ee1d9650d1cf8fdba [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,
310 HSW_PWR_WELL_DRIVER,
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
322 ret = I915_READ(HSW_PWR_WELL_BIOS) & req_mask ? 1 : 0;
323 ret |= I915_READ(HSW_PWR_WELL_DRIVER) & req_mask ? 2 : 0;
324 ret |= I915_READ(HSW_PWR_WELL_KVMR) & req_mask ? 4 : 0;
325 ret |= I915_READ(HSW_PWR_WELL_DEBUG) & req_mask ? 8 : 0;
326
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 */
346 wait_for((disabled = !(I915_READ(HSW_PWR_WELL_DRIVER) &
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 Deak1af474f2017-07-06 17:40:34 +0300387 val = I915_READ(HSW_PWR_WELL_DRIVER);
388 I915_WRITE(HSW_PWR_WELL_DRIVER, 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 Deak1af474f2017-07-06 17:40:34 +0300406 val = I915_READ(HSW_PWR_WELL_DRIVER);
407 I915_WRITE(HSW_PWR_WELL_DRIVER, val & ~HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300408 hsw_wait_for_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200409}
410
Imre Deakd42539b2017-07-06 17:40:39 +0300411/*
412 * We should only use the power well if we explicitly asked the hardware to
413 * enable it, so check if it's enabled and also check if we've requested it to
414 * be enabled.
415 */
416static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
417 struct i915_power_well *power_well)
418{
419 enum i915_power_well_id id = power_well->id;
420 u32 mask = HSW_PWR_WELL_CTL_REQ(id) | HSW_PWR_WELL_CTL_STATE(id);
421
422 return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
423}
424
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000425#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200426 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
427 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
428 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
429 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
430 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
431 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
432 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
433 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
434 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
435 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
436 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
437 BIT_ULL(POWER_DOMAIN_AUX_B) | \
438 BIT_ULL(POWER_DOMAIN_AUX_C) | \
439 BIT_ULL(POWER_DOMAIN_AUX_D) | \
440 BIT_ULL(POWER_DOMAIN_AUDIO) | \
441 BIT_ULL(POWER_DOMAIN_VGA) | \
442 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200443#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
444 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
445 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200446 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200447#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
448 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200449 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200450#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
451 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200452 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200453#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
454 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200455 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100456#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
457 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200458 BIT_ULL(POWER_DOMAIN_MODESET) | \
459 BIT_ULL(POWER_DOMAIN_AUX_A) | \
460 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M94dd5132015-02-04 13:57:44 +0000461
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530462#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200463 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
464 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
465 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
466 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
467 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
468 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
469 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
470 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
471 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
472 BIT_ULL(POWER_DOMAIN_AUX_B) | \
473 BIT_ULL(POWER_DOMAIN_AUX_C) | \
474 BIT_ULL(POWER_DOMAIN_AUDIO) | \
475 BIT_ULL(POWER_DOMAIN_VGA) | \
476 BIT_ULL(POWER_DOMAIN_GMBUS) | \
477 BIT_ULL(POWER_DOMAIN_INIT))
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100478#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
479 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200480 BIT_ULL(POWER_DOMAIN_MODESET) | \
481 BIT_ULL(POWER_DOMAIN_AUX_A) | \
482 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300483#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200484 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
485 BIT_ULL(POWER_DOMAIN_AUX_A) | \
486 BIT_ULL(POWER_DOMAIN_INIT))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300487#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200488 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
489 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
490 BIT_ULL(POWER_DOMAIN_AUX_B) | \
491 BIT_ULL(POWER_DOMAIN_AUX_C) | \
492 BIT_ULL(POWER_DOMAIN_INIT))
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +0530493
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200494#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200495 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
496 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
497 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
498 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
499 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
500 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
501 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
502 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
503 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
504 BIT_ULL(POWER_DOMAIN_AUX_B) | \
505 BIT_ULL(POWER_DOMAIN_AUX_C) | \
506 BIT_ULL(POWER_DOMAIN_AUDIO) | \
507 BIT_ULL(POWER_DOMAIN_VGA) | \
508 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +0200509#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
510 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
511#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
512 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
513#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
514 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200515#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200516 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
517 BIT_ULL(POWER_DOMAIN_AUX_A) | \
518 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200519#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200520 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
521 BIT_ULL(POWER_DOMAIN_AUX_B) | \
522 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200523#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200524 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
525 BIT_ULL(POWER_DOMAIN_AUX_C) | \
526 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200527#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200528 BIT_ULL(POWER_DOMAIN_AUX_A) | \
529 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200530#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200531 BIT_ULL(POWER_DOMAIN_AUX_B) | \
532 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200533#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200534 BIT_ULL(POWER_DOMAIN_AUX_C) | \
535 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200536#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
537 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +0200538 BIT_ULL(POWER_DOMAIN_MODESET) | \
539 BIT_ULL(POWER_DOMAIN_AUX_A) | \
540 BIT_ULL(POWER_DOMAIN_INIT))
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +0200541
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -0700542#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
543 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
544 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
545 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
546 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
547 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
548 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
549 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
550 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
551 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
552 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
553 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
554 BIT_ULL(POWER_DOMAIN_AUX_B) | \
555 BIT_ULL(POWER_DOMAIN_AUX_C) | \
556 BIT_ULL(POWER_DOMAIN_AUX_D) | \
557 BIT_ULL(POWER_DOMAIN_AUDIO) | \
558 BIT_ULL(POWER_DOMAIN_VGA) | \
559 BIT_ULL(POWER_DOMAIN_INIT))
560#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
561 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
562 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
563 BIT_ULL(POWER_DOMAIN_INIT))
564#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
565 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
566 BIT_ULL(POWER_DOMAIN_INIT))
567#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
568 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
569 BIT_ULL(POWER_DOMAIN_INIT))
570#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
571 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
572 BIT_ULL(POWER_DOMAIN_INIT))
573#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
574 BIT_ULL(POWER_DOMAIN_AUX_A) | \
575 BIT_ULL(POWER_DOMAIN_INIT))
576#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
577 BIT_ULL(POWER_DOMAIN_AUX_B) | \
578 BIT_ULL(POWER_DOMAIN_INIT))
579#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
580 BIT_ULL(POWER_DOMAIN_AUX_C) | \
581 BIT_ULL(POWER_DOMAIN_INIT))
582#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
583 BIT_ULL(POWER_DOMAIN_AUX_D) | \
584 BIT_ULL(POWER_DOMAIN_INIT))
585#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
586 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
587 BIT_ULL(POWER_DOMAIN_MODESET) | \
588 BIT_ULL(POWER_DOMAIN_AUX_A) | \
589 BIT_ULL(POWER_DOMAIN_INIT))
590
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530591static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
592{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300593 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
594 "DC9 already programmed to be enabled.\n");
595 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
596 "DC5 still not disabled to enable DC9.\n");
Imre Deake8a3a2a2017-06-29 18:37:00 +0300597 WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER) &
Imre Deak1af474f2017-07-06 17:40:34 +0300598 HSW_PWR_WELL_CTL_REQ(SKL_DISP_PW_2),
Imre Deake8a3a2a2017-06-29 18:37:00 +0300599 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300600 WARN_ONCE(intel_irqs_enabled(dev_priv),
601 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530602
603 /*
604 * TODO: check for the following to verify the conditions to enter DC9
605 * state are satisfied:
606 * 1] Check relevant display engine registers to verify if mode set
607 * disable sequence was followed.
608 * 2] Check if display uninitialize sequence is initialized.
609 */
610}
611
612static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
613{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300614 WARN_ONCE(intel_irqs_enabled(dev_priv),
615 "Interrupts not disabled yet.\n");
616 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
617 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530618
619 /*
620 * TODO: check for the following to verify DC9 state was indeed
621 * entered before programming to disable it:
622 * 1] Check relevant display engine registers to verify if mode
623 * set disable sequence was followed.
624 * 2] Check if display uninitialize sequence is initialized.
625 */
626}
627
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200628static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
629 u32 state)
630{
631 int rewrites = 0;
632 int rereads = 0;
633 u32 v;
634
635 I915_WRITE(DC_STATE_EN, state);
636
637 /* It has been observed that disabling the dc6 state sometimes
638 * doesn't stick and dmc keeps returning old value. Make sure
639 * the write really sticks enough times and also force rewrite until
640 * we are confident that state is exactly what we want.
641 */
642 do {
643 v = I915_READ(DC_STATE_EN);
644
645 if (v != state) {
646 I915_WRITE(DC_STATE_EN, state);
647 rewrites++;
648 rereads = 0;
649 } else if (rereads++ > 5) {
650 break;
651 }
652
653 } while (rewrites < 100);
654
655 if (v != state)
656 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
657 state, v);
658
659 /* Most of the times we need one retry, avoid spam */
660 if (rewrites > 1)
661 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
662 state, rewrites);
663}
664
Imre Deakda2f41d2016-04-20 20:27:56 +0300665static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530666{
Imre Deakda2f41d2016-04-20 20:27:56 +0300667 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530668
Imre Deak13ae3a02015-11-04 19:24:16 +0200669 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200670 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200671 mask |= DC_STATE_EN_DC9;
672 else
673 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530674
Imre Deakda2f41d2016-04-20 20:27:56 +0300675 return mask;
676}
677
678void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
679{
680 u32 val;
681
682 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
683
684 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
685 dev_priv->csr.dc_state, val);
686 dev_priv->csr.dc_state = val;
687}
688
689static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
690{
691 uint32_t val;
692 uint32_t mask;
693
Imre Deaka37baf32016-02-29 22:49:03 +0200694 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
695 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100696
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530697 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300698 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200699 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
700 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200701
702 /* Check if DMC is ignoring our DC state requests */
703 if ((val & mask) != dev_priv->csr.dc_state)
704 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
705 dev_priv->csr.dc_state, val & mask);
706
Imre Deak13ae3a02015-11-04 19:24:16 +0200707 val &= ~mask;
708 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200709
710 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200711
712 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530713}
714
Imre Deak13ae3a02015-11-04 19:24:16 +0200715void bxt_enable_dc9(struct drm_i915_private *dev_priv)
716{
717 assert_can_enable_dc9(dev_priv);
718
719 DRM_DEBUG_KMS("Enabling DC9\n");
720
Imre Deak78597992016-06-16 16:37:20 +0300721 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200722 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
723}
724
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530725void bxt_disable_dc9(struct drm_i915_private *dev_priv)
726{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530727 assert_can_disable_dc9(dev_priv);
728
729 DRM_DEBUG_KMS("Disabling DC9\n");
730
Imre Deak13ae3a02015-11-04 19:24:16 +0200731 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300732
733 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530734}
735
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200736static void assert_csr_loaded(struct drm_i915_private *dev_priv)
737{
738 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
739 "CSR program storage start is NULL\n");
740 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
741 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
742}
743
Suketu Shah5aefb232015-04-16 14:22:10 +0530744static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530745{
Suketu Shah5aefb232015-04-16 14:22:10 +0530746 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
747 SKL_DISP_PW_2);
748
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700749 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530750
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700751 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
752 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200753 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530754
755 assert_csr_loaded(dev_priv);
756}
757
Imre Deakf62c79b2016-04-20 20:27:57 +0300758void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530759{
Suketu Shah5aefb232015-04-16 14:22:10 +0530760 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530761
762 DRM_DEBUG_KMS("Enabling DC5\n");
763
Imre Deak13ae3a02015-11-04 19:24:16 +0200764 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530765}
766
Suketu Shah93c7cb62015-04-16 14:22:13 +0530767static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530768{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700769 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
770 "Backlight is not disabled.\n");
771 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
772 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530773
774 assert_csr_loaded(dev_priv);
775}
776
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530777void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530778{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530779 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530780
781 DRM_DEBUG_KMS("Enabling DC6\n");
782
Imre Deak13ae3a02015-11-04 19:24:16 +0200783 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
784
Suketu Shahf75a1982015-04-16 14:22:11 +0530785}
786
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530787void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530788{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530789 DRM_DEBUG_KMS("Disabling DC6\n");
790
Imre Deak13ae3a02015-11-04 19:24:16 +0200791 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530792}
793
Daniel Vetter9c065a72014-09-30 10:56:38 +0200794static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
795 struct i915_power_well *power_well)
796{
Imre Deak1af474f2017-07-06 17:40:34 +0300797 enum i915_power_well_id id = power_well->id;
798 u32 mask = HSW_PWR_WELL_CTL_REQ(id);
799 u32 bios_req = I915_READ(HSW_PWR_WELL_BIOS);
800
Imre Deak16e84912017-02-17 17:39:45 +0200801 /* Take over the request bit if set by BIOS. */
Imre Deak1af474f2017-07-06 17:40:34 +0300802 if (bios_req & mask) {
803 u32 drv_req = I915_READ(HSW_PWR_WELL_DRIVER);
804
805 if (!(drv_req & mask))
806 I915_WRITE(HSW_PWR_WELL_DRIVER, drv_req | mask);
807 I915_WRITE(HSW_PWR_WELL_BIOS, bios_req & ~mask);
Imre Deak16e84912017-02-17 17:39:45 +0200808 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200809}
810
Imre Deak9c8d0b82016-06-13 16:44:34 +0300811static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
812 struct i915_power_well *power_well)
813{
Imre Deakb5565a22017-07-06 17:40:29 +0300814 bxt_ddi_phy_init(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300815}
816
817static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
818 struct i915_power_well *power_well)
819{
Imre Deakb5565a22017-07-06 17:40:29 +0300820 bxt_ddi_phy_uninit(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300821}
822
823static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
824 struct i915_power_well *power_well)
825{
Imre Deakb5565a22017-07-06 17:40:29 +0300826 return bxt_ddi_phy_is_enabled(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300827}
828
Imre Deak9c8d0b82016-06-13 16:44:34 +0300829static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
830{
831 struct i915_power_well *power_well;
832
833 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
834 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300835 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300836
837 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
838 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300839 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200840
841 if (IS_GEMINILAKE(dev_priv)) {
842 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
843 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300844 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200845 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300846}
847
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100848static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
849 struct i915_power_well *power_well)
850{
851 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
852}
853
Ville Syrjälä18a80672016-05-16 16:59:40 +0300854static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
855{
856 u32 tmp = I915_READ(DBUF_CTL);
857
858 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
859 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
860 "Unexpected DBuf power power state (0x%08x)\n", tmp);
861}
862
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100863static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
864 struct i915_power_well *power_well)
865{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200866 struct intel_cdclk_state cdclk_state = {};
867
Imre Deak5b773eb2016-02-29 22:49:05 +0200868 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300869
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200870 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
871 WARN_ON(!intel_cdclk_state_compare(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300872
Ville Syrjälä18a80672016-05-16 16:59:40 +0300873 gen9_assert_dbuf_enabled(dev_priv);
874
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200875 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300876 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100877}
878
879static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
880 struct i915_power_well *power_well)
881{
Imre Deakf74ed082016-04-18 14:48:21 +0300882 if (!dev_priv->csr.dmc_payload)
883 return;
884
Imre Deaka37baf32016-02-29 22:49:03 +0200885 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100886 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200887 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100888 gen9_enable_dc5(dev_priv);
889}
890
Imre Deak3c1b38e2017-02-17 17:39:42 +0200891static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
892 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100893{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100894}
895
Daniel Vetter9c065a72014-09-30 10:56:38 +0200896static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
897 struct i915_power_well *power_well)
898{
899}
900
901static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
902 struct i915_power_well *power_well)
903{
904 return true;
905}
906
Ville Syrjälä2ee0da12017-06-01 17:36:16 +0300907static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
908 struct i915_power_well *power_well)
909{
910 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
911 i830_enable_pipe(dev_priv, PIPE_A);
912 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
913 i830_enable_pipe(dev_priv, PIPE_B);
914}
915
916static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
917 struct i915_power_well *power_well)
918{
919 i830_disable_pipe(dev_priv, PIPE_B);
920 i830_disable_pipe(dev_priv, PIPE_A);
921}
922
923static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
924 struct i915_power_well *power_well)
925{
926 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
927 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
928}
929
930static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
931 struct i915_power_well *power_well)
932{
933 if (power_well->count > 0)
934 i830_pipes_power_well_enable(dev_priv, power_well);
935 else
936 i830_pipes_power_well_disable(dev_priv, power_well);
937}
938
Daniel Vetter9c065a72014-09-30 10:56:38 +0200939static void vlv_set_power_well(struct drm_i915_private *dev_priv,
940 struct i915_power_well *power_well, bool enable)
941{
Imre Deak438b8dc2017-07-11 23:42:30 +0300942 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200943 u32 mask;
944 u32 state;
945 u32 ctrl;
946
947 mask = PUNIT_PWRGT_MASK(power_well_id);
948 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
949 PUNIT_PWRGT_PWR_GATE(power_well_id);
950
951 mutex_lock(&dev_priv->rps.hw_lock);
952
953#define COND \
954 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
955
956 if (COND)
957 goto out;
958
959 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
960 ctrl &= ~mask;
961 ctrl |= state;
962 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
963
964 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900965 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200966 state,
967 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
968
969#undef COND
970
971out:
972 mutex_unlock(&dev_priv->rps.hw_lock);
973}
974
Daniel Vetter9c065a72014-09-30 10:56:38 +0200975static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
976 struct i915_power_well *power_well)
977{
978 vlv_set_power_well(dev_priv, power_well, true);
979}
980
981static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
982 struct i915_power_well *power_well)
983{
984 vlv_set_power_well(dev_priv, power_well, false);
985}
986
987static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
988 struct i915_power_well *power_well)
989{
Imre Deak438b8dc2017-07-11 23:42:30 +0300990 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200991 bool enabled = false;
992 u32 mask;
993 u32 state;
994 u32 ctrl;
995
996 mask = PUNIT_PWRGT_MASK(power_well_id);
997 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
998
999 mutex_lock(&dev_priv->rps.hw_lock);
1000
1001 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
1002 /*
1003 * We only ever set the power-on and power-gate states, anything
1004 * else is unexpected.
1005 */
1006 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
1007 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
1008 if (state == ctrl)
1009 enabled = true;
1010
1011 /*
1012 * A transient state at this point would mean some unexpected party
1013 * is poking at the power controls too.
1014 */
1015 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
1016 WARN_ON(ctrl != state);
1017
1018 mutex_unlock(&dev_priv->rps.hw_lock);
1019
1020 return enabled;
1021}
1022
Ville Syrjälä766078d2016-04-11 16:56:30 +03001023static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
1024{
Hans de Goede721d4842016-12-02 15:29:04 +01001025 u32 val;
1026
1027 /*
1028 * On driver load, a pipe may be active and driving a DSI display.
1029 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
1030 * (and never recovering) in this case. intel_dsi_post_disable() will
1031 * clear it when we turn off the display.
1032 */
1033 val = I915_READ(DSPCLK_GATE_D);
1034 val &= DPOUNIT_CLOCK_GATE_DISABLE;
1035 val |= VRHUNIT_CLOCK_GATE_DISABLE;
1036 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +03001037
1038 /*
1039 * Disable trickle feed and enable pnd deadline calculation
1040 */
1041 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
1042 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +03001043
1044 WARN_ON(dev_priv->rawclk_freq == 0);
1045
1046 I915_WRITE(RAWCLK_FREQ_VLV,
1047 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +03001048}
1049
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001050static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02001051{
Lyude9504a892016-06-21 17:03:42 -04001052 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001053 enum pipe pipe;
1054
1055 /*
1056 * Enable the CRI clock source so we can get at the
1057 * display and the reference clock for VGA
1058 * hotplug / manual detection. Supposedly DSI also
1059 * needs the ref clock up and running.
1060 *
1061 * CHV DPLL B/C have some issues if VGA mode is enabled.
1062 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +00001063 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001064 u32 val = I915_READ(DPLL(pipe));
1065
1066 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1067 if (pipe != PIPE_A)
1068 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1069
1070 I915_WRITE(DPLL(pipe), val);
1071 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02001072
Ville Syrjälä766078d2016-04-11 16:56:30 +03001073 vlv_init_display_clock_gating(dev_priv);
1074
Daniel Vetter9c065a72014-09-30 10:56:38 +02001075 spin_lock_irq(&dev_priv->irq_lock);
1076 valleyview_enable_display_irqs(dev_priv);
1077 spin_unlock_irq(&dev_priv->irq_lock);
1078
1079 /*
1080 * During driver initialization/resume we can avoid restoring the
1081 * part of the HW/SW state that will be inited anyway explicitly.
1082 */
1083 if (dev_priv->power_domains.initializing)
1084 return;
1085
Daniel Vetterb9632912014-09-30 10:56:44 +02001086 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001087
Lyude9504a892016-06-21 17:03:42 -04001088 /* Re-enable the ADPA, if we have one */
1089 for_each_intel_encoder(&dev_priv->drm, encoder) {
1090 if (encoder->type == INTEL_OUTPUT_ANALOG)
1091 intel_crt_reset(&encoder->base);
1092 }
1093
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00001094 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001095
1096 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001097}
1098
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001099static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1100{
1101 spin_lock_irq(&dev_priv->irq_lock);
1102 valleyview_disable_display_irqs(dev_priv);
1103 spin_unlock_irq(&dev_priv->irq_lock);
1104
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001105 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01001106 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +02001107
Imre Deak78597992016-06-16 16:37:20 +03001108 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001109
Lyudeb64b5402016-10-26 12:36:09 -04001110 /* Prevent us from re-enabling polling on accident in late suspend */
1111 if (!dev_priv->drm.dev->power.is_suspended)
1112 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001113}
1114
1115static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
1116 struct i915_power_well *power_well)
1117{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001118 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001119
1120 vlv_set_power_well(dev_priv, power_well, true);
1121
1122 vlv_display_power_well_init(dev_priv);
1123}
1124
Daniel Vetter9c065a72014-09-30 10:56:38 +02001125static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
1126 struct i915_power_well *power_well)
1127{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001128 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001129
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001130 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001131
1132 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001133}
1134
1135static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1136 struct i915_power_well *power_well)
1137{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001138 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001139
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001140 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001141 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1142
1143 vlv_set_power_well(dev_priv, power_well, true);
1144
1145 /*
1146 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1147 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1148 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1149 * b. The other bits such as sfr settings / modesel may all
1150 * be set to 0.
1151 *
1152 * This should only be done on init and resume from S3 with
1153 * both PLLs disabled, or we risk losing DPIO and PLL
1154 * synchronization.
1155 */
1156 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1157}
1158
1159static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1160 struct i915_power_well *power_well)
1161{
1162 enum pipe pipe;
1163
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001164 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001165
1166 for_each_pipe(dev_priv, pipe)
1167 assert_pll_disabled(dev_priv, pipe);
1168
1169 /* Assert common reset */
1170 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1171
1172 vlv_set_power_well(dev_priv, power_well, false);
1173}
1174
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001175#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001176
Imre Deak438b8dc2017-07-11 23:42:30 +03001177static struct i915_power_well *
1178lookup_power_well(struct drm_i915_private *dev_priv,
1179 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001180{
1181 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001182 int i;
1183
Imre Deakfc17f222015-11-04 19:24:11 +02001184 for (i = 0; i < power_domains->power_well_count; i++) {
1185 struct i915_power_well *power_well;
1186
1187 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001188 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001189 return power_well;
1190 }
1191
1192 return NULL;
1193}
1194
1195#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1196
1197static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1198{
1199 struct i915_power_well *cmn_bc =
1200 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1201 struct i915_power_well *cmn_d =
1202 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1203 u32 phy_control = dev_priv->chv_phy_control;
1204 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001205 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001206
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001207 /*
1208 * The BIOS can leave the PHY is some weird state
1209 * where it doesn't fully power down some parts.
1210 * Disable the asserts until the PHY has been fully
1211 * reset (ie. the power well has been disabled at
1212 * least once).
1213 */
1214 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1215 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1216 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1217 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1218 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1219 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1220 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1221
1222 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1223 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1224 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1225 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1226
Ville Syrjälä30142272015-07-08 23:46:01 +03001227 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1228 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1229
1230 /* this assumes override is only used to enable lanes */
1231 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1232 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1233
1234 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1235 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1236
1237 /* CL1 is on whenever anything is on in either channel */
1238 if (BITS_SET(phy_control,
1239 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1240 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1241 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1242
1243 /*
1244 * The DPLLB check accounts for the pipe B + port A usage
1245 * with CL2 powered up but all the lanes in the second channel
1246 * powered down.
1247 */
1248 if (BITS_SET(phy_control,
1249 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1250 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1251 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1252
1253 if (BITS_SET(phy_control,
1254 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1255 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1256 if (BITS_SET(phy_control,
1257 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1258 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1259
1260 if (BITS_SET(phy_control,
1261 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1262 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1263 if (BITS_SET(phy_control,
1264 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1265 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1266 }
1267
1268 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1269 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1270
1271 /* this assumes override is only used to enable lanes */
1272 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1273 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1274
1275 if (BITS_SET(phy_control,
1276 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1277 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1278
1279 if (BITS_SET(phy_control,
1280 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1281 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1282 if (BITS_SET(phy_control,
1283 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1284 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1285 }
1286
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001287 phy_status &= phy_status_mask;
1288
Ville Syrjälä30142272015-07-08 23:46:01 +03001289 /*
1290 * The PHY may be busy with some initial calibration and whatnot,
1291 * so the power state can take a while to actually change.
1292 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001293 if (intel_wait_for_register(dev_priv,
1294 DISPLAY_PHY_STATUS,
1295 phy_status_mask,
1296 phy_status,
1297 10))
1298 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1299 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1300 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001301}
1302
1303#undef BITS_SET
1304
Daniel Vetter9c065a72014-09-30 10:56:38 +02001305static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1306 struct i915_power_well *power_well)
1307{
1308 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001309 enum pipe pipe;
1310 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001311
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001312 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1313 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001314
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001315 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001316 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001317 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001318 } else {
1319 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001320 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001321 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001322
1323 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001324 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1325 vlv_set_power_well(dev_priv, power_well, true);
1326
1327 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001328 if (intel_wait_for_register(dev_priv,
1329 DISPLAY_PHY_STATUS,
1330 PHY_POWERGOOD(phy),
1331 PHY_POWERGOOD(phy),
1332 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001333 DRM_ERROR("Display PHY %d is not power up\n", phy);
1334
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001335 mutex_lock(&dev_priv->sb_lock);
1336
1337 /* Enable dynamic power down */
1338 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001339 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1340 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001341 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1342
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001343 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001344 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1345 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1346 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001347 } else {
1348 /*
1349 * Force the non-existing CL2 off. BXT does this
1350 * too, so maybe it saves some power even though
1351 * CL2 doesn't exist?
1352 */
1353 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1354 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1355 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001356 }
1357
1358 mutex_unlock(&dev_priv->sb_lock);
1359
Ville Syrjälä70722462015-04-10 18:21:28 +03001360 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1361 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001362
1363 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1364 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001365
1366 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001367}
1368
1369static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1370 struct i915_power_well *power_well)
1371{
1372 enum dpio_phy phy;
1373
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001374 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1375 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001376
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001377 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001378 phy = DPIO_PHY0;
1379 assert_pll_disabled(dev_priv, PIPE_A);
1380 assert_pll_disabled(dev_priv, PIPE_B);
1381 } else {
1382 phy = DPIO_PHY1;
1383 assert_pll_disabled(dev_priv, PIPE_C);
1384 }
1385
Ville Syrjälä70722462015-04-10 18:21:28 +03001386 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1387 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001388
1389 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001390
1391 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1392 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001393
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001394 /* PHY is fully reset now, so we can enable the PHY state asserts */
1395 dev_priv->chv_phy_assert[phy] = true;
1396
Ville Syrjälä30142272015-07-08 23:46:01 +03001397 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001398}
1399
Ville Syrjälä6669e392015-07-08 23:46:00 +03001400static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1401 enum dpio_channel ch, bool override, unsigned int mask)
1402{
1403 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1404 u32 reg, val, expected, actual;
1405
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001406 /*
1407 * The BIOS can leave the PHY is some weird state
1408 * where it doesn't fully power down some parts.
1409 * Disable the asserts until the PHY has been fully
1410 * reset (ie. the power well has been disabled at
1411 * least once).
1412 */
1413 if (!dev_priv->chv_phy_assert[phy])
1414 return;
1415
Ville Syrjälä6669e392015-07-08 23:46:00 +03001416 if (ch == DPIO_CH0)
1417 reg = _CHV_CMN_DW0_CH0;
1418 else
1419 reg = _CHV_CMN_DW6_CH1;
1420
1421 mutex_lock(&dev_priv->sb_lock);
1422 val = vlv_dpio_read(dev_priv, pipe, reg);
1423 mutex_unlock(&dev_priv->sb_lock);
1424
1425 /*
1426 * This assumes !override is only used when the port is disabled.
1427 * All lanes should power down even without the override when
1428 * the port is disabled.
1429 */
1430 if (!override || mask == 0xf) {
1431 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1432 /*
1433 * If CH1 common lane is not active anymore
1434 * (eg. for pipe B DPLL) the entire channel will
1435 * shut down, which causes the common lane registers
1436 * to read as 0. That means we can't actually check
1437 * the lane power down status bits, but as the entire
1438 * register reads as 0 it's a good indication that the
1439 * channel is indeed entirely powered down.
1440 */
1441 if (ch == DPIO_CH1 && val == 0)
1442 expected = 0;
1443 } else if (mask != 0x0) {
1444 expected = DPIO_ANYDL_POWERDOWN;
1445 } else {
1446 expected = 0;
1447 }
1448
1449 if (ch == DPIO_CH0)
1450 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1451 else
1452 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1453 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1454
1455 WARN(actual != expected,
1456 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1457 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1458 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1459 reg, val);
1460}
1461
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001462bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1463 enum dpio_channel ch, bool override)
1464{
1465 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1466 bool was_override;
1467
1468 mutex_lock(&power_domains->lock);
1469
1470 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1471
1472 if (override == was_override)
1473 goto out;
1474
1475 if (override)
1476 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1477 else
1478 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1479
1480 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1481
1482 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1483 phy, ch, dev_priv->chv_phy_control);
1484
Ville Syrjälä30142272015-07-08 23:46:01 +03001485 assert_chv_phy_status(dev_priv);
1486
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001487out:
1488 mutex_unlock(&power_domains->lock);
1489
1490 return was_override;
1491}
1492
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001493void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1494 bool override, unsigned int mask)
1495{
1496 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1497 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1498 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1499 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1500
1501 mutex_lock(&power_domains->lock);
1502
1503 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1504 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1505
1506 if (override)
1507 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1508 else
1509 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1510
1511 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1512
1513 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1514 phy, ch, mask, dev_priv->chv_phy_control);
1515
Ville Syrjälä30142272015-07-08 23:46:01 +03001516 assert_chv_phy_status(dev_priv);
1517
Ville Syrjälä6669e392015-07-08 23:46:00 +03001518 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1519
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001520 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001521}
1522
1523static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1524 struct i915_power_well *power_well)
1525{
Imre Deakf49193c2017-07-06 17:40:23 +03001526 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001527 bool enabled;
1528 u32 state, ctrl;
1529
1530 mutex_lock(&dev_priv->rps.hw_lock);
1531
1532 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1533 /*
1534 * We only ever set the power-on and power-gate states, anything
1535 * else is unexpected.
1536 */
1537 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1538 enabled = state == DP_SSS_PWR_ON(pipe);
1539
1540 /*
1541 * A transient state at this point would mean some unexpected party
1542 * is poking at the power controls too.
1543 */
1544 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1545 WARN_ON(ctrl << 16 != state);
1546
1547 mutex_unlock(&dev_priv->rps.hw_lock);
1548
1549 return enabled;
1550}
1551
1552static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1553 struct i915_power_well *power_well,
1554 bool enable)
1555{
Imre Deakf49193c2017-07-06 17:40:23 +03001556 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001557 u32 state;
1558 u32 ctrl;
1559
1560 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1561
1562 mutex_lock(&dev_priv->rps.hw_lock);
1563
1564#define COND \
1565 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1566
1567 if (COND)
1568 goto out;
1569
1570 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1571 ctrl &= ~DP_SSC_MASK(pipe);
1572 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1573 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1574
1575 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001576 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001577 state,
1578 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1579
1580#undef COND
1581
1582out:
1583 mutex_unlock(&dev_priv->rps.hw_lock);
1584}
1585
Daniel Vetter9c065a72014-09-30 10:56:38 +02001586static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1587 struct i915_power_well *power_well)
1588{
Imre Deakf49193c2017-07-06 17:40:23 +03001589 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001590
1591 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001592
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001593 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001594}
1595
1596static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1597 struct i915_power_well *power_well)
1598{
Imre Deakf49193c2017-07-06 17:40:23 +03001599 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001600
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001601 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001602
Daniel Vetter9c065a72014-09-30 10:56:38 +02001603 chv_set_pipe_power_well(dev_priv, power_well, false);
1604}
1605
Imre Deak09731282016-02-17 14:17:42 +02001606static void
1607__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1608 enum intel_display_power_domain domain)
1609{
1610 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1611 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001612
Imre Deak75ccb2e2017-02-17 17:39:43 +02001613 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001614 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001615
1616 power_domains->domain_use_count[domain]++;
1617}
1618
Daniel Vettere4e76842014-09-30 10:56:42 +02001619/**
1620 * intel_display_power_get - grab a power domain reference
1621 * @dev_priv: i915 device instance
1622 * @domain: power domain to reference
1623 *
1624 * This function grabs a power domain reference for @domain and ensures that the
1625 * power domain and all its parents are powered up. Therefore users should only
1626 * grab a reference to the innermost power domain they need.
1627 *
1628 * Any power domain reference obtained by this function must have a symmetric
1629 * call to intel_display_power_put() to release the reference again.
1630 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001631void intel_display_power_get(struct drm_i915_private *dev_priv,
1632 enum intel_display_power_domain domain)
1633{
Imre Deak09731282016-02-17 14:17:42 +02001634 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001635
1636 intel_runtime_pm_get(dev_priv);
1637
Imre Deak09731282016-02-17 14:17:42 +02001638 mutex_lock(&power_domains->lock);
1639
1640 __intel_display_power_get_domain(dev_priv, domain);
1641
1642 mutex_unlock(&power_domains->lock);
1643}
1644
1645/**
1646 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1647 * @dev_priv: i915 device instance
1648 * @domain: power domain to reference
1649 *
1650 * This function grabs a power domain reference for @domain and ensures that the
1651 * power domain and all its parents are powered up. Therefore users should only
1652 * grab a reference to the innermost power domain they need.
1653 *
1654 * Any power domain reference obtained by this function must have a symmetric
1655 * call to intel_display_power_put() to release the reference again.
1656 */
1657bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1658 enum intel_display_power_domain domain)
1659{
1660 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1661 bool is_enabled;
1662
1663 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1664 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001665
1666 mutex_lock(&power_domains->lock);
1667
Imre Deak09731282016-02-17 14:17:42 +02001668 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1669 __intel_display_power_get_domain(dev_priv, domain);
1670 is_enabled = true;
1671 } else {
1672 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001673 }
1674
Daniel Vetter9c065a72014-09-30 10:56:38 +02001675 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001676
1677 if (!is_enabled)
1678 intel_runtime_pm_put(dev_priv);
1679
1680 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001681}
1682
Daniel Vettere4e76842014-09-30 10:56:42 +02001683/**
1684 * intel_display_power_put - release a power domain reference
1685 * @dev_priv: i915 device instance
1686 * @domain: power domain to reference
1687 *
1688 * This function drops the power domain reference obtained by
1689 * intel_display_power_get() and might power down the corresponding hardware
1690 * block right away if this is the last reference.
1691 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001692void intel_display_power_put(struct drm_i915_private *dev_priv,
1693 enum intel_display_power_domain domain)
1694{
1695 struct i915_power_domains *power_domains;
1696 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001697
1698 power_domains = &dev_priv->power_domains;
1699
1700 mutex_lock(&power_domains->lock);
1701
Daniel Stone11c86db2015-11-20 15:55:34 +00001702 WARN(!power_domains->domain_use_count[domain],
1703 "Use count on domain %s is already zero\n",
1704 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001705 power_domains->domain_use_count[domain]--;
1706
Imre Deak75ccb2e2017-02-17 17:39:43 +02001707 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001708 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001709
1710 mutex_unlock(&power_domains->lock);
1711
1712 intel_runtime_pm_put(dev_priv);
1713}
1714
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001715#define HSW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001716 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1717 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1718 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1719 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1720 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1721 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1722 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1723 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1724 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1725 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1726 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1727 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1728 BIT_ULL(POWER_DOMAIN_VGA) | \
1729 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1730 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001731
Ville Syrjälä9d0996b2016-04-18 14:02:28 +03001732#define BDW_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001733 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1734 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1735 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1736 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1737 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1738 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1739 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1740 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1741 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1742 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1743 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1744 BIT_ULL(POWER_DOMAIN_VGA) | \
1745 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1746 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001747
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001748#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001749 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1750 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1751 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1752 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1753 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1754 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1755 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1756 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1757 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1758 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1759 BIT_ULL(POWER_DOMAIN_VGA) | \
1760 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1761 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1762 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1763 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1764 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001765
1766#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001767 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1768 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1769 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1770 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1771 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1772 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001773
1774#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001775 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1776 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1777 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001778
1779#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001780 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1781 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1782 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001783
1784#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001785 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1786 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1787 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001788
1789#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001790 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1791 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1792 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001793
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001794#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001795 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1796 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1797 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1798 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1799 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1800 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1801 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1802 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1803 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1804 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1805 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1806 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1807 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1808 BIT_ULL(POWER_DOMAIN_VGA) | \
1809 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1810 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1811 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1812 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1813 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1814 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001815
Daniel Vetter9c065a72014-09-30 10:56:38 +02001816#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001817 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1818 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1819 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1820 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1821 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001822
1823#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001824 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1825 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1826 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001827
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001828#define I830_PIPES_POWER_DOMAINS ( \
1829 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1830 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1831 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1832 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1833 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1834 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1835 BIT_ULL(POWER_DOMAIN_INIT))
1836
Daniel Vetter9c065a72014-09-30 10:56:38 +02001837static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001838 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001839 .enable = i9xx_always_on_power_well_noop,
1840 .disable = i9xx_always_on_power_well_noop,
1841 .is_enabled = i9xx_always_on_power_well_enabled,
1842};
1843
1844static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001845 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001846 .enable = chv_pipe_power_well_enable,
1847 .disable = chv_pipe_power_well_disable,
1848 .is_enabled = chv_pipe_power_well_enabled,
1849};
1850
1851static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001852 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001853 .enable = chv_dpio_cmn_power_well_enable,
1854 .disable = chv_dpio_cmn_power_well_disable,
1855 .is_enabled = vlv_power_well_enabled,
1856};
1857
1858static struct i915_power_well i9xx_always_on_power_well[] = {
1859 {
1860 .name = "always-on",
1861 .always_on = 1,
1862 .domains = POWER_DOMAIN_MASK,
1863 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001864 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001865 },
1866};
1867
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001868static const struct i915_power_well_ops i830_pipes_power_well_ops = {
1869 .sync_hw = i830_pipes_power_well_sync_hw,
1870 .enable = i830_pipes_power_well_enable,
1871 .disable = i830_pipes_power_well_disable,
1872 .is_enabled = i830_pipes_power_well_enabled,
1873};
1874
1875static struct i915_power_well i830_power_wells[] = {
1876 {
1877 .name = "always-on",
1878 .always_on = 1,
1879 .domains = POWER_DOMAIN_MASK,
1880 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001881 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001882 },
1883 {
1884 .name = "pipes",
1885 .domains = I830_PIPES_POWER_DOMAINS,
1886 .ops = &i830_pipes_power_well_ops,
Imre Deak120b56a2017-07-11 23:42:31 +03001887 .id = I830_DISP_PW_PIPES,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001888 },
1889};
1890
Daniel Vetter9c065a72014-09-30 10:56:38 +02001891static const struct i915_power_well_ops hsw_power_well_ops = {
1892 .sync_hw = hsw_power_well_sync_hw,
1893 .enable = hsw_power_well_enable,
1894 .disable = hsw_power_well_disable,
1895 .is_enabled = hsw_power_well_enabled,
1896};
1897
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001898static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001899 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001900 .enable = gen9_dc_off_power_well_enable,
1901 .disable = gen9_dc_off_power_well_disable,
1902 .is_enabled = gen9_dc_off_power_well_enabled,
1903};
1904
Imre Deak9c8d0b82016-06-13 16:44:34 +03001905static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001906 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03001907 .enable = bxt_dpio_cmn_power_well_enable,
1908 .disable = bxt_dpio_cmn_power_well_disable,
1909 .is_enabled = bxt_dpio_cmn_power_well_enabled,
1910};
1911
Daniel Vetter9c065a72014-09-30 10:56:38 +02001912static struct i915_power_well hsw_power_wells[] = {
1913 {
1914 .name = "always-on",
1915 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001916 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001917 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001918 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001919 },
1920 {
1921 .name = "display",
1922 .domains = HSW_DISPLAY_POWER_DOMAINS,
1923 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03001924 .id = HSW_DISP_PW_GLOBAL,
Imre Deak001bd2c2017-07-12 18:54:13 +03001925 .hsw.has_vga = true,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001926 },
1927};
1928
1929static struct i915_power_well bdw_power_wells[] = {
1930 {
1931 .name = "always-on",
1932 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001933 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001934 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001935 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001936 },
1937 {
1938 .name = "display",
1939 .domains = BDW_DISPLAY_POWER_DOMAINS,
1940 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03001941 .id = HSW_DISP_PW_GLOBAL,
Imre Deak001bd2c2017-07-12 18:54:13 +03001942 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
1943 .hsw.has_vga = true,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001944 },
1945};
1946
1947static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001948 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001949 .enable = vlv_display_power_well_enable,
1950 .disable = vlv_display_power_well_disable,
1951 .is_enabled = vlv_power_well_enabled,
1952};
1953
1954static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001955 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001956 .enable = vlv_dpio_cmn_power_well_enable,
1957 .disable = vlv_dpio_cmn_power_well_disable,
1958 .is_enabled = vlv_power_well_enabled,
1959};
1960
1961static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001962 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001963 .enable = vlv_power_well_enable,
1964 .disable = vlv_power_well_disable,
1965 .is_enabled = vlv_power_well_enabled,
1966};
1967
1968static struct i915_power_well vlv_power_wells[] = {
1969 {
1970 .name = "always-on",
1971 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001972 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001973 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03001974 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001975 },
1976 {
1977 .name = "display",
1978 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001979 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001980 .ops = &vlv_display_power_well_ops,
1981 },
1982 {
1983 .name = "dpio-tx-b-01",
1984 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1985 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1986 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1987 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1988 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001989 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001990 },
1991 {
1992 .name = "dpio-tx-b-23",
1993 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
1994 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
1995 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
1996 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
1997 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001998 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001999 },
2000 {
2001 .name = "dpio-tx-c-01",
2002 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2003 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2004 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2005 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2006 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002007 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002008 },
2009 {
2010 .name = "dpio-tx-c-23",
2011 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2012 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2013 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2014 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2015 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002016 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002017 },
2018 {
2019 .name = "dpio-common",
2020 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002021 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002022 .ops = &vlv_dpio_cmn_power_well_ops,
2023 },
2024};
2025
2026static struct i915_power_well chv_power_wells[] = {
2027 {
2028 .name = "always-on",
2029 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002030 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002031 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002032 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002033 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002034 {
2035 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002036 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002037 * Pipe A power well is the new disp2d well. Pipe B and C
2038 * power wells don't actually exist. Pipe A power well is
2039 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002040 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002041 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002042 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002043 .ops = &chv_pipe_power_well_ops,
2044 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002045 {
2046 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002047 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002048 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002049 .ops = &chv_dpio_cmn_power_well_ops,
2050 },
2051 {
2052 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002053 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002054 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002055 .ops = &chv_dpio_cmn_power_well_ops,
2056 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002057};
2058
Suketu Shah5aefb232015-04-16 14:22:10 +05302059bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002060 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302061{
2062 struct i915_power_well *power_well;
2063 bool ret;
2064
2065 power_well = lookup_power_well(dev_priv, power_well_id);
2066 ret = power_well->ops->is_enabled(dev_priv, power_well);
2067
2068 return ret;
2069}
2070
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002071static struct i915_power_well skl_power_wells[] = {
2072 {
2073 .name = "always-on",
2074 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002075 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002076 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002077 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002078 },
2079 {
2080 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002081 /* Handled by the DMC firmware */
2082 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002083 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002084 .id = SKL_DISP_PW_1,
Imre Deak4196b912017-07-11 23:42:36 +03002085 .hsw.has_fuses = true,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002086 },
2087 {
2088 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002089 /* Handled by the DMC firmware */
2090 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002091 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002092 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002093 },
2094 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002095 .name = "DC off",
2096 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2097 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002098 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002099 },
2100 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002101 .name = "power well 2",
2102 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002103 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002104 .id = SKL_DISP_PW_2,
Imre Deak4196b912017-07-11 23:42:36 +03002105 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2106 .hsw.has_vga = true,
2107 .hsw.has_fuses = true,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002108 },
2109 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002110 .name = "DDI A/E IO power well",
2111 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002112 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002113 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002114 },
2115 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002116 .name = "DDI B IO power well",
2117 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002118 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002119 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002120 },
2121 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002122 .name = "DDI C IO power well",
2123 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002124 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002125 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002126 },
2127 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002128 .name = "DDI D IO power well",
2129 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002130 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002131 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002132 },
2133};
2134
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302135static struct i915_power_well bxt_power_wells[] = {
2136 {
2137 .name = "always-on",
2138 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002139 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302140 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002141 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302142 },
2143 {
2144 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002145 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002146 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002147 .id = SKL_DISP_PW_1,
Imre Deak4196b912017-07-11 23:42:36 +03002148 .hsw.has_fuses = true,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302149 },
2150 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002151 .name = "DC off",
2152 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2153 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002154 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002155 },
2156 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302157 .name = "power well 2",
2158 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002159 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002160 .id = SKL_DISP_PW_2,
Imre Deak4196b912017-07-11 23:42:36 +03002161 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2162 .hsw.has_vga = true,
2163 .hsw.has_fuses = true,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002164 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002165 {
2166 .name = "dpio-common-a",
2167 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2168 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002169 .id = BXT_DPIO_CMN_A,
Imre Deakb5565a22017-07-06 17:40:29 +03002170 .bxt.phy = DPIO_PHY1,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002171 },
2172 {
2173 .name = "dpio-common-bc",
2174 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2175 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002176 .id = BXT_DPIO_CMN_BC,
Imre Deakb5565a22017-07-06 17:40:29 +03002177 .bxt.phy = DPIO_PHY0,
Imre Deak9c8d0b82016-06-13 16:44:34 +03002178 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302179};
2180
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002181static struct i915_power_well glk_power_wells[] = {
2182 {
2183 .name = "always-on",
2184 .always_on = 1,
2185 .domains = POWER_DOMAIN_MASK,
2186 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002187 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002188 },
2189 {
2190 .name = "power well 1",
2191 /* Handled by the DMC firmware */
2192 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002193 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002194 .id = SKL_DISP_PW_1,
Imre Deak4196b912017-07-11 23:42:36 +03002195 .hsw.has_fuses = true,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002196 },
2197 {
2198 .name = "DC off",
2199 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2200 .ops = &gen9_dc_off_power_well_ops,
2201 .id = SKL_DISP_PW_DC_OFF,
2202 },
2203 {
2204 .name = "power well 2",
2205 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002206 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002207 .id = SKL_DISP_PW_2,
Imre Deak4196b912017-07-11 23:42:36 +03002208 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2209 .hsw.has_vga = true,
2210 .hsw.has_fuses = true,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002211 },
2212 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002213 .name = "dpio-common-a",
2214 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2215 .ops = &bxt_dpio_cmn_power_well_ops,
2216 .id = BXT_DPIO_CMN_A,
Imre Deakb5565a22017-07-06 17:40:29 +03002217 .bxt.phy = DPIO_PHY1,
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002218 },
2219 {
2220 .name = "dpio-common-b",
2221 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2222 .ops = &bxt_dpio_cmn_power_well_ops,
2223 .id = BXT_DPIO_CMN_BC,
Imre Deakb5565a22017-07-06 17:40:29 +03002224 .bxt.phy = DPIO_PHY0,
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002225 },
2226 {
2227 .name = "dpio-common-c",
2228 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2229 .ops = &bxt_dpio_cmn_power_well_ops,
2230 .id = GLK_DPIO_CMN_C,
Imre Deakb5565a22017-07-06 17:40:29 +03002231 .bxt.phy = DPIO_PHY2,
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002232 },
2233 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002234 .name = "AUX A",
2235 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002236 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002237 .id = GLK_DISP_PW_AUX_A,
2238 },
2239 {
2240 .name = "AUX B",
2241 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002242 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002243 .id = GLK_DISP_PW_AUX_B,
2244 },
2245 {
2246 .name = "AUX C",
2247 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002248 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002249 .id = GLK_DISP_PW_AUX_C,
2250 },
2251 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002252 .name = "DDI A IO power well",
2253 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002254 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002255 .id = GLK_DISP_PW_DDI_A,
2256 },
2257 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002258 .name = "DDI B IO power well",
2259 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002260 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002261 .id = SKL_DISP_PW_DDI_B,
2262 },
2263 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002264 .name = "DDI C IO power well",
2265 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002266 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002267 .id = SKL_DISP_PW_DDI_C,
2268 },
2269};
2270
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002271static struct i915_power_well cnl_power_wells[] = {
2272 {
2273 .name = "always-on",
2274 .always_on = 1,
2275 .domains = POWER_DOMAIN_MASK,
2276 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002277 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002278 },
2279 {
2280 .name = "power well 1",
2281 /* Handled by the DMC firmware */
2282 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002283 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002284 .id = SKL_DISP_PW_1,
Imre Deak4196b912017-07-11 23:42:36 +03002285 .hsw.has_fuses = true,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002286 },
2287 {
2288 .name = "AUX A",
2289 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002290 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002291 .id = CNL_DISP_PW_AUX_A,
2292 },
2293 {
2294 .name = "AUX B",
2295 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002296 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002297 .id = CNL_DISP_PW_AUX_B,
2298 },
2299 {
2300 .name = "AUX C",
2301 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002302 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002303 .id = CNL_DISP_PW_AUX_C,
2304 },
2305 {
2306 .name = "AUX D",
2307 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002308 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002309 .id = CNL_DISP_PW_AUX_D,
2310 },
2311 {
2312 .name = "DC off",
2313 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2314 .ops = &gen9_dc_off_power_well_ops,
2315 .id = SKL_DISP_PW_DC_OFF,
2316 },
2317 {
2318 .name = "power well 2",
2319 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002320 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002321 .id = SKL_DISP_PW_2,
Imre Deak4196b912017-07-11 23:42:36 +03002322 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2323 .hsw.has_vga = true,
2324 .hsw.has_fuses = true,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002325 },
2326 {
2327 .name = "DDI A IO power well",
2328 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002329 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002330 .id = CNL_DISP_PW_DDI_A,
2331 },
2332 {
2333 .name = "DDI B IO power well",
2334 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002335 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002336 .id = SKL_DISP_PW_DDI_B,
2337 },
2338 {
2339 .name = "DDI C IO power well",
2340 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002341 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002342 .id = SKL_DISP_PW_DDI_C,
2343 },
2344 {
2345 .name = "DDI D IO power well",
2346 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002347 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002348 .id = SKL_DISP_PW_DDI_D,
2349 },
2350};
2351
Imre Deak1b0e3a02015-11-05 23:04:11 +02002352static int
2353sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2354 int disable_power_well)
2355{
2356 if (disable_power_well >= 0)
2357 return !!disable_power_well;
2358
Imre Deak1b0e3a02015-11-05 23:04:11 +02002359 return 1;
2360}
2361
Imre Deaka37baf32016-02-29 22:49:03 +02002362static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2363 int enable_dc)
2364{
2365 uint32_t mask;
2366 int requested_dc;
2367 int max_dc;
2368
Rodrigo Vivi6d6a8972017-07-06 13:45:08 -07002369 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002370 max_dc = 2;
2371 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002372 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002373 max_dc = 1;
2374 /*
2375 * DC9 has a separate HW flow from the rest of the DC states,
2376 * not depending on the DMC firmware. It's needed by system
2377 * suspend/resume, so allow it unconditionally.
2378 */
2379 mask = DC_STATE_EN_DC9;
2380 } else {
2381 max_dc = 0;
2382 mask = 0;
2383 }
2384
Imre Deak66e2c4c2016-02-29 22:49:04 +02002385 if (!i915.disable_power_well)
2386 max_dc = 0;
2387
Imre Deaka37baf32016-02-29 22:49:03 +02002388 if (enable_dc >= 0 && enable_dc <= max_dc) {
2389 requested_dc = enable_dc;
2390 } else if (enable_dc == -1) {
2391 requested_dc = max_dc;
2392 } else if (enable_dc > max_dc && enable_dc <= 2) {
2393 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2394 enable_dc, max_dc);
2395 requested_dc = max_dc;
2396 } else {
2397 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2398 requested_dc = max_dc;
2399 }
2400
2401 if (requested_dc > 1)
2402 mask |= DC_STATE_EN_UPTO_DC6;
2403 if (requested_dc > 0)
2404 mask |= DC_STATE_EN_UPTO_DC5;
2405
2406 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2407
2408 return mask;
2409}
2410
Imre Deak21792c62017-07-11 23:42:33 +03002411static void assert_power_well_ids_unique(struct drm_i915_private *dev_priv)
2412{
2413 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2414 u64 power_well_ids;
2415 int i;
2416
2417 power_well_ids = 0;
2418 for (i = 0; i < power_domains->power_well_count; i++) {
2419 enum i915_power_well_id id = power_domains->power_wells[i].id;
2420
2421 WARN_ON(id >= sizeof(power_well_ids) * 8);
2422 WARN_ON(power_well_ids & BIT_ULL(id));
2423 power_well_ids |= BIT_ULL(id);
2424 }
2425}
2426
Daniel Vetter9c065a72014-09-30 10:56:38 +02002427#define set_power_wells(power_domains, __power_wells) ({ \
2428 (power_domains)->power_wells = (__power_wells); \
2429 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2430})
2431
Daniel Vettere4e76842014-09-30 10:56:42 +02002432/**
2433 * intel_power_domains_init - initializes the power domain structures
2434 * @dev_priv: i915 device instance
2435 *
2436 * Initializes the power domain structures for @dev_priv depending upon the
2437 * supported platform.
2438 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002439int intel_power_domains_init(struct drm_i915_private *dev_priv)
2440{
2441 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2442
Imre Deak1b0e3a02015-11-05 23:04:11 +02002443 i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
2444 i915.disable_power_well);
Imre Deaka37baf32016-02-29 22:49:03 +02002445 dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
2446 i915.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002447
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002448 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002449
Daniel Vetter9c065a72014-09-30 10:56:38 +02002450 mutex_init(&power_domains->lock);
2451
2452 /*
2453 * The enabling order will be from lower to higher indexed wells,
2454 * the disabling order is reversed.
2455 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002456 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002457 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002458 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002459 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002460 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002461 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002462 } else if (IS_CANNONLAKE(dev_priv)) {
2463 set_power_wells(power_domains, cnl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002464 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302465 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002466 } else if (IS_GEMINILAKE(dev_priv)) {
2467 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002468 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002469 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002470 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002471 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002472 } else if (IS_I830(dev_priv)) {
2473 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002474 } else {
2475 set_power_wells(power_domains, i9xx_always_on_power_well);
2476 }
2477
Imre Deak21792c62017-07-11 23:42:33 +03002478 assert_power_well_ids_unique(dev_priv);
2479
Daniel Vetter9c065a72014-09-30 10:56:38 +02002480 return 0;
2481}
2482
Daniel Vettere4e76842014-09-30 10:56:42 +02002483/**
2484 * intel_power_domains_fini - finalizes the power domain structures
2485 * @dev_priv: i915 device instance
2486 *
2487 * Finalizes the power domain structures for @dev_priv depending upon the
2488 * supported platform. This function also disables runtime pm and ensures that
2489 * the device stays powered up so that the driver can be reloaded.
2490 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002491void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002492{
David Weinehallc49d13e2016-08-22 13:32:42 +03002493 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002494
Imre Deakaabee1b2015-12-15 20:10:29 +02002495 /*
2496 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002497 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002498 * we're going to unload/reload.
2499 * The following also reacquires the RPM reference the core passed
2500 * to the driver during loading, which is dropped in
2501 * intel_runtime_pm_enable(). We have to hand back the control of the
2502 * device to the core with this reference held.
2503 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002504 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002505
2506 /* Remove the refcount we took to keep power well support disabled. */
2507 if (!i915.disable_power_well)
2508 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002509
2510 /*
2511 * Remove the refcount we took in intel_runtime_pm_enable() in case
2512 * the platform doesn't support runtime PM.
2513 */
2514 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002515 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002516}
2517
Imre Deak30eade12015-11-04 19:24:13 +02002518static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002519{
2520 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2521 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002522
2523 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002524 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002525 power_well->ops->sync_hw(dev_priv, power_well);
2526 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2527 power_well);
2528 }
2529 mutex_unlock(&power_domains->lock);
2530}
2531
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002532static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2533{
2534 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2535 POSTING_READ(DBUF_CTL);
2536
2537 udelay(10);
2538
2539 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2540 DRM_ERROR("DBuf power enable timeout\n");
2541}
2542
2543static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2544{
2545 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2546 POSTING_READ(DBUF_CTL);
2547
2548 udelay(10);
2549
2550 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2551 DRM_ERROR("DBuf power disable timeout!\n");
2552}
2553
Imre Deak73dfc222015-11-17 17:33:53 +02002554static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002555 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002556{
2557 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002558 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002559 uint32_t val;
2560
Imre Deakd26fa1d2015-11-04 19:24:17 +02002561 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2562
Imre Deak73dfc222015-11-17 17:33:53 +02002563 /* enable PCH reset handshake */
2564 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2565 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2566
2567 /* enable PG1 and Misc I/O */
2568 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002569
2570 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2571 intel_power_well_enable(dev_priv, well);
2572
2573 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2574 intel_power_well_enable(dev_priv, well);
2575
Imre Deak73dfc222015-11-17 17:33:53 +02002576 mutex_unlock(&power_domains->lock);
2577
Imre Deak73dfc222015-11-17 17:33:53 +02002578 skl_init_cdclk(dev_priv);
2579
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002580 gen9_dbuf_enable(dev_priv);
2581
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002582 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002583 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002584}
2585
2586static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2587{
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
Imre Deakd26fa1d2015-11-04 19:24:17 +02002591 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2592
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002593 gen9_dbuf_disable(dev_priv);
2594
Imre Deak73dfc222015-11-17 17:33:53 +02002595 skl_uninit_cdclk(dev_priv);
2596
2597 /* The spec doesn't call for removing the reset handshake flag */
2598 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002599
Imre Deak73dfc222015-11-17 17:33:53 +02002600 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002601
Imre Deakedfda8e2017-06-29 18:36:59 +03002602 /*
2603 * BSpec says to keep the MISC IO power well enabled here, only
2604 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03002605 * Note that even though the driver's request is removed power well 1
2606 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03002607 */
Imre Deak443a93a2016-04-04 15:42:57 +03002608 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2609 intel_power_well_disable(dev_priv, well);
2610
Imre Deak73dfc222015-11-17 17:33:53 +02002611 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002612
2613 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02002614}
2615
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002616void bxt_display_core_init(struct drm_i915_private *dev_priv,
2617 bool resume)
2618{
2619 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2620 struct i915_power_well *well;
2621 uint32_t val;
2622
2623 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2624
2625 /*
2626 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2627 * or else the reset will hang because there is no PCH to respond.
2628 * Move the handshake programming to initialization sequence.
2629 * Previously was left up to BIOS.
2630 */
2631 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2632 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2633 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2634
2635 /* Enable PG1 */
2636 mutex_lock(&power_domains->lock);
2637
2638 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2639 intel_power_well_enable(dev_priv, well);
2640
2641 mutex_unlock(&power_domains->lock);
2642
Imre Deak324513c2016-06-13 16:44:36 +03002643 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002644
2645 gen9_dbuf_enable(dev_priv);
2646
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002647 if (resume && dev_priv->csr.dmc_payload)
2648 intel_csr_load_program(dev_priv);
2649}
2650
2651void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2652{
2653 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2654 struct i915_power_well *well;
2655
2656 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2657
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002658 gen9_dbuf_disable(dev_priv);
2659
Imre Deak324513c2016-06-13 16:44:36 +03002660 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002661
2662 /* The spec doesn't call for removing the reset handshake flag */
2663
Imre Deak42d93662017-06-29 18:37:01 +03002664 /*
2665 * Disable PW1 (PG1).
2666 * Note that even though the driver's request is removed power well 1
2667 * may stay enabled after this due to DMC's own request on it.
2668 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002669 mutex_lock(&power_domains->lock);
2670
2671 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2672 intel_power_well_disable(dev_priv, well);
2673
2674 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002675
2676 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002677}
2678
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002679#define CNL_PROCMON_IDX(val) \
2680 (((val) & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) >> VOLTAGE_INFO_SHIFT)
2681#define NUM_CNL_PROCMON \
2682 (CNL_PROCMON_IDX(VOLTAGE_INFO_MASK | PROCESS_INFO_MASK) + 1)
2683
2684static const struct cnl_procmon {
2685 u32 dw1, dw9, dw10;
2686} cnl_procmon_values[NUM_CNL_PROCMON] = {
2687 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0)] =
2688 { .dw1 = 0x00 << 16, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
2689 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0)] =
2690 { .dw1 = 0x00 << 16, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
2691 [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1)] =
2692 { .dw1 = 0x00 << 16, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
2693 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0)] =
2694 { .dw1 = 0x00 << 16, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
2695 [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1)] =
2696 { .dw1 = 0x44 << 16, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
2697};
2698
2699static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
2700{
2701 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2702 const struct cnl_procmon *procmon;
2703 struct i915_power_well *well;
2704 u32 val;
2705
2706 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2707
2708 /* 1. Enable PCH Reset Handshake */
2709 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2710 val |= RESET_PCH_HANDSHAKE_ENABLE;
2711 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2712
2713 /* 2. Enable Comp */
2714 val = I915_READ(CHICKEN_MISC_2);
2715 val &= ~COMP_PWR_DOWN;
2716 I915_WRITE(CHICKEN_MISC_2, val);
2717
2718 val = I915_READ(CNL_PORT_COMP_DW3);
2719 procmon = &cnl_procmon_values[CNL_PROCMON_IDX(val)];
2720
2721 WARN_ON(procmon->dw10 == 0);
2722
2723 val = I915_READ(CNL_PORT_COMP_DW1);
2724 val &= ~((0xff << 16) | 0xff);
2725 val |= procmon->dw1;
2726 I915_WRITE(CNL_PORT_COMP_DW1, val);
2727
2728 I915_WRITE(CNL_PORT_COMP_DW9, procmon->dw9);
2729 I915_WRITE(CNL_PORT_COMP_DW10, procmon->dw10);
2730
2731 val = I915_READ(CNL_PORT_COMP_DW0);
2732 val |= COMP_INIT;
2733 I915_WRITE(CNL_PORT_COMP_DW0, val);
2734
2735 /* 3. */
2736 val = I915_READ(CNL_PORT_CL1CM_DW5);
2737 val |= CL_POWER_DOWN_ENABLE;
2738 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2739
Imre Deakb38131f2017-06-29 18:37:02 +03002740 /*
2741 * 4. Enable Power Well 1 (PG1).
2742 * The AUX IO power wells will be enabled on demand.
2743 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002744 mutex_lock(&power_domains->lock);
2745 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2746 intel_power_well_enable(dev_priv, well);
2747 mutex_unlock(&power_domains->lock);
2748
2749 /* 5. Enable CD clock */
2750 cnl_init_cdclk(dev_priv);
2751
2752 /* 6. Enable DBUF */
2753 gen9_dbuf_enable(dev_priv);
2754}
2755
2756#undef CNL_PROCMON_IDX
2757#undef NUM_CNL_PROCMON
2758
2759static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
2760{
2761 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2762 struct i915_power_well *well;
2763 u32 val;
2764
2765 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2766
2767 /* 1. Disable all display engine functions -> aready done */
2768
2769 /* 2. Disable DBUF */
2770 gen9_dbuf_disable(dev_priv);
2771
2772 /* 3. Disable CD clock */
2773 cnl_uninit_cdclk(dev_priv);
2774
Imre Deakb38131f2017-06-29 18:37:02 +03002775 /*
2776 * 4. Disable Power Well 1 (PG1).
2777 * The AUX IO power wells are toggled on demand, so they are already
2778 * disabled at this point.
2779 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002780 mutex_lock(&power_domains->lock);
2781 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2782 intel_power_well_disable(dev_priv, well);
2783 mutex_unlock(&power_domains->lock);
2784
Imre Deak846c6b22017-06-29 18:36:58 +03002785 usleep_range(10, 30); /* 10 us delay per Bspec */
2786
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002787 /* 5. Disable Comp */
2788 val = I915_READ(CHICKEN_MISC_2);
2789 val |= COMP_PWR_DOWN;
2790 I915_WRITE(CHICKEN_MISC_2, val);
2791}
2792
Ville Syrjälä70722462015-04-10 18:21:28 +03002793static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2794{
2795 struct i915_power_well *cmn_bc =
2796 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2797 struct i915_power_well *cmn_d =
2798 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2799
2800 /*
2801 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2802 * workaround never ever read DISPLAY_PHY_CONTROL, and
2803 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002804 * power well state and lane status to reconstruct the
2805 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002806 */
2807 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002808 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2809 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002810 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2811 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2812 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2813
2814 /*
2815 * If all lanes are disabled we leave the override disabled
2816 * with all power down bits cleared to match the state we
2817 * would use after disabling the port. Otherwise enable the
2818 * override and set the lane powerdown bits accding to the
2819 * current lane status.
2820 */
2821 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2822 uint32_t status = I915_READ(DPLL(PIPE_A));
2823 unsigned int mask;
2824
2825 mask = status & DPLL_PORTB_READY_MASK;
2826 if (mask == 0xf)
2827 mask = 0x0;
2828 else
2829 dev_priv->chv_phy_control |=
2830 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2831
2832 dev_priv->chv_phy_control |=
2833 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2834
2835 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2836 if (mask == 0xf)
2837 mask = 0x0;
2838 else
2839 dev_priv->chv_phy_control |=
2840 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2841
2842 dev_priv->chv_phy_control |=
2843 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2844
Ville Syrjälä70722462015-04-10 18:21:28 +03002845 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002846
2847 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2848 } else {
2849 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002850 }
2851
2852 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2853 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2854 unsigned int mask;
2855
2856 mask = status & DPLL_PORTD_READY_MASK;
2857
2858 if (mask == 0xf)
2859 mask = 0x0;
2860 else
2861 dev_priv->chv_phy_control |=
2862 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2863
2864 dev_priv->chv_phy_control |=
2865 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2866
Ville Syrjälä70722462015-04-10 18:21:28 +03002867 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002868
2869 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2870 } else {
2871 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002872 }
2873
2874 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2875
2876 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2877 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002878}
2879
Daniel Vetter9c065a72014-09-30 10:56:38 +02002880static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2881{
2882 struct i915_power_well *cmn =
2883 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2884 struct i915_power_well *disp2d =
2885 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2886
Daniel Vetter9c065a72014-09-30 10:56:38 +02002887 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03002888 if (cmn->ops->is_enabled(dev_priv, cmn) &&
2889 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02002890 I915_READ(DPIO_CTL) & DPIO_CMNRST)
2891 return;
2892
2893 DRM_DEBUG_KMS("toggling display PHY side reset\n");
2894
2895 /* cmnlane needs DPLL registers */
2896 disp2d->ops->enable(dev_priv, disp2d);
2897
2898 /*
2899 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2900 * Need to assert and de-assert PHY SB reset by gating the
2901 * common lane power, then un-gating it.
2902 * Simply ungating isn't enough to reset the PHY enough to get
2903 * ports and lanes running.
2904 */
2905 cmn->ops->disable(dev_priv, cmn);
2906}
2907
Daniel Vettere4e76842014-09-30 10:56:42 +02002908/**
2909 * intel_power_domains_init_hw - initialize hardware power domain state
2910 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002911 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02002912 *
2913 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02002914 * power wells belonging to the INIT power domain. Power wells in other
2915 * domains (and not in the INIT domain) are referenced or disabled during the
2916 * modeset state HW readout. After that the reference count of each power well
2917 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02002918 */
Imre Deak73dfc222015-11-17 17:33:53 +02002919void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002920{
Daniel Vetter9c065a72014-09-30 10:56:38 +02002921 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2922
2923 power_domains->initializing = true;
2924
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002925 if (IS_CANNONLAKE(dev_priv)) {
2926 cnl_display_core_init(dev_priv, resume);
2927 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02002928 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02002929 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002930 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002931 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03002932 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03002933 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03002934 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01002935 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002936 mutex_lock(&power_domains->lock);
2937 vlv_cmnlane_wa(dev_priv);
2938 mutex_unlock(&power_domains->lock);
2939 }
2940
2941 /* For now, we need the power well to be always enabled. */
2942 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002943 /* Disable power support if the user asked so. */
2944 if (!i915.disable_power_well)
2945 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02002946 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002947 power_domains->initializing = false;
2948}
2949
Daniel Vettere4e76842014-09-30 10:56:42 +02002950/**
Imre Deak73dfc222015-11-17 17:33:53 +02002951 * intel_power_domains_suspend - suspend power domain state
2952 * @dev_priv: i915 device instance
2953 *
2954 * This function prepares the hardware power domain state before entering
2955 * system suspend. It must be paired with intel_power_domains_init_hw().
2956 */
2957void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
2958{
Imre Deakd314cd42015-11-17 17:44:23 +02002959 /*
2960 * Even if power well support was disabled we still want to disable
2961 * power wells while we are system suspended.
2962 */
2963 if (!i915.disable_power_well)
2964 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02002965
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002966 if (IS_CANNONLAKE(dev_priv))
2967 cnl_display_core_uninit(dev_priv);
2968 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02002969 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02002970 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002971 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002972}
2973
Imre Deak8d8c3862017-02-17 17:39:46 +02002974static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
2975{
2976 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2977 struct i915_power_well *power_well;
2978
2979 for_each_power_well(dev_priv, power_well) {
2980 enum intel_display_power_domain domain;
2981
2982 DRM_DEBUG_DRIVER("%-25s %d\n",
2983 power_well->name, power_well->count);
2984
2985 for_each_power_domain(domain, power_well->domains)
2986 DRM_DEBUG_DRIVER(" %-23s %d\n",
2987 intel_display_power_domain_str(domain),
2988 power_domains->domain_use_count[domain]);
2989 }
2990}
2991
2992/**
2993 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
2994 * @dev_priv: i915 device instance
2995 *
2996 * Verify if the reference count of each power well matches its HW enabled
2997 * state and the total refcount of the domains it belongs to. This must be
2998 * called after modeset HW state sanitization, which is responsible for
2999 * acquiring reference counts for any power wells in use and disabling the
3000 * ones left on by BIOS but not required by any active output.
3001 */
3002void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3003{
3004 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3005 struct i915_power_well *power_well;
3006 bool dump_domain_info;
3007
3008 mutex_lock(&power_domains->lock);
3009
3010 dump_domain_info = false;
3011 for_each_power_well(dev_priv, power_well) {
3012 enum intel_display_power_domain domain;
3013 int domains_count;
3014 bool enabled;
3015
3016 /*
3017 * Power wells not belonging to any domain (like the MISC_IO
3018 * and PW1 power wells) are under FW control, so ignore them,
3019 * since their state can change asynchronously.
3020 */
3021 if (!power_well->domains)
3022 continue;
3023
3024 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3025 if ((power_well->count || power_well->always_on) != enabled)
3026 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3027 power_well->name, power_well->count, enabled);
3028
3029 domains_count = 0;
3030 for_each_power_domain(domain, power_well->domains)
3031 domains_count += power_domains->domain_use_count[domain];
3032
3033 if (power_well->count != domains_count) {
3034 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3035 "(refcount %d/domains refcount %d)\n",
3036 power_well->name, power_well->count,
3037 domains_count);
3038 dump_domain_info = true;
3039 }
3040 }
3041
3042 if (dump_domain_info) {
3043 static bool dumped;
3044
3045 if (!dumped) {
3046 intel_power_domains_dump_info(dev_priv);
3047 dumped = true;
3048 }
3049 }
3050
3051 mutex_unlock(&power_domains->lock);
3052}
3053
Imre Deak73dfc222015-11-17 17:33:53 +02003054/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003055 * intel_runtime_pm_get - grab a runtime pm reference
3056 * @dev_priv: i915 device instance
3057 *
3058 * This function grabs a device-level runtime pm reference (mostly used for GEM
3059 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3060 *
3061 * Any runtime pm reference obtained by this function must have a symmetric
3062 * call to intel_runtime_pm_put() to release the reference again.
3063 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003064void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3065{
David Weinehall52a05c32016-08-22 13:32:44 +03003066 struct pci_dev *pdev = dev_priv->drm.pdev;
3067 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003068 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003069
Imre Deakf5073822017-03-28 12:38:55 +03003070 ret = pm_runtime_get_sync(kdev);
3071 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003072
3073 atomic_inc(&dev_priv->pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003074 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003075}
3076
Daniel Vettere4e76842014-09-30 10:56:42 +02003077/**
Imre Deak09731282016-02-17 14:17:42 +02003078 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3079 * @dev_priv: i915 device instance
3080 *
3081 * This function grabs a device-level runtime pm reference if the device is
3082 * already in use and ensures that it is powered up.
3083 *
3084 * Any runtime pm reference obtained by this function must have a symmetric
3085 * call to intel_runtime_pm_put() to release the reference again.
3086 */
3087bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3088{
David Weinehall52a05c32016-08-22 13:32:44 +03003089 struct pci_dev *pdev = dev_priv->drm.pdev;
3090 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003091
Chris Wilson135dc792016-02-25 21:10:28 +00003092 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03003093 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02003094
Chris Wilson135dc792016-02-25 21:10:28 +00003095 /*
3096 * In cases runtime PM is disabled by the RPM core and we get
3097 * an -EINVAL return value we are not supposed to call this
3098 * function, since the power state is undefined. This applies
3099 * atm to the late/early system suspend/resume handlers.
3100 */
Imre Deakf5073822017-03-28 12:38:55 +03003101 WARN_ONCE(ret < 0,
3102 "pm_runtime_get_if_in_use() failed: %d\n", ret);
Chris Wilson135dc792016-02-25 21:10:28 +00003103 if (ret <= 0)
3104 return false;
3105 }
Imre Deak09731282016-02-17 14:17:42 +02003106
3107 atomic_inc(&dev_priv->pm.wakeref_count);
3108 assert_rpm_wakelock_held(dev_priv);
3109
3110 return true;
3111}
3112
3113/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003114 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3115 * @dev_priv: i915 device instance
3116 *
3117 * This function grabs a device-level runtime pm reference (mostly used for GEM
3118 * code to ensure the GTT or GT is on).
3119 *
3120 * It will _not_ power up the device but instead only check that it's powered
3121 * on. Therefore it is only valid to call this functions from contexts where
3122 * the device is known to be powered up and where trying to power it up would
3123 * result in hilarity and deadlocks. That pretty much means only the system
3124 * suspend/resume code where this is used to grab runtime pm references for
3125 * delayed setup down in work items.
3126 *
3127 * Any runtime pm reference obtained by this function must have a symmetric
3128 * call to intel_runtime_pm_put() to release the reference again.
3129 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003130void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3131{
David Weinehall52a05c32016-08-22 13:32:44 +03003132 struct pci_dev *pdev = dev_priv->drm.pdev;
3133 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003134
Imre Deakc9b88462015-12-15 20:10:34 +02003135 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003136 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003137
3138 atomic_inc(&dev_priv->pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003139}
3140
Daniel Vettere4e76842014-09-30 10:56:42 +02003141/**
3142 * intel_runtime_pm_put - release a runtime pm reference
3143 * @dev_priv: i915 device instance
3144 *
3145 * This function drops the device-level runtime pm reference obtained by
3146 * intel_runtime_pm_get() and might power down the corresponding
3147 * hardware block right away if this is the last reference.
3148 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003149void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3150{
David Weinehall52a05c32016-08-22 13:32:44 +03003151 struct pci_dev *pdev = dev_priv->drm.pdev;
3152 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003153
Imre Deak542db3c2015-12-15 20:10:36 +02003154 assert_rpm_wakelock_held(dev_priv);
Chris Wilson2eedfc72016-10-24 13:42:17 +01003155 atomic_dec(&dev_priv->pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003156
David Weinehallc49d13e2016-08-22 13:32:42 +03003157 pm_runtime_mark_last_busy(kdev);
3158 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003159}
3160
Daniel Vettere4e76842014-09-30 10:56:42 +02003161/**
3162 * intel_runtime_pm_enable - enable runtime pm
3163 * @dev_priv: i915 device instance
3164 *
3165 * This function enables runtime pm at the end of the driver load sequence.
3166 *
3167 * Note that this function does currently not enable runtime pm for the
3168 * subordinate display power domains. That is only done on the first modeset
3169 * using intel_display_set_init_power().
3170 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003171void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003172{
David Weinehall52a05c32016-08-22 13:32:44 +03003173 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003174 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003175
David Weinehallc49d13e2016-08-22 13:32:42 +03003176 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3177 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003178
Imre Deak25b181b2015-12-17 13:44:56 +02003179 /*
3180 * Take a permanent reference to disable the RPM functionality and drop
3181 * it only when unloading the driver. Use the low level get/put helpers,
3182 * so the driver's own RPM reference tracking asserts also work on
3183 * platforms without RPM support.
3184 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003185 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003186 int ret;
3187
David Weinehallc49d13e2016-08-22 13:32:42 +03003188 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003189 ret = pm_runtime_get_sync(kdev);
3190 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003191 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003192 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003193 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003194
Imre Deakaabee1b2015-12-15 20:10:29 +02003195 /*
3196 * The core calls the driver load handler with an RPM reference held.
3197 * We drop that here and will reacquire it during unloading in
3198 * intel_power_domains_fini().
3199 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003200 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003201}