blob: 4996c4ea8a80cbed07360490940d036e787607ed [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";
Tvrtko Ursulinb6876372017-12-05 13:28:54 +0000133 case POWER_DOMAIN_GT_IRQ:
134 return "GT_IRQ";
Daniel Stone9895ad02015-11-20 15:55:33 +0000135 default:
136 MISSING_CASE(domain);
137 return "?";
138 }
139}
140
Damien Lespiaue8ca9322015-07-30 18:20:26 -0300141static void intel_power_well_enable(struct drm_i915_private *dev_priv,
142 struct i915_power_well *power_well)
143{
144 DRM_DEBUG_KMS("enabling %s\n", power_well->name);
145 power_well->ops->enable(dev_priv, power_well);
146 power_well->hw_enabled = true;
147}
148
Damien Lespiaudcddab32015-07-30 18:20:27 -0300149static void intel_power_well_disable(struct drm_i915_private *dev_priv,
150 struct i915_power_well *power_well)
151{
152 DRM_DEBUG_KMS("disabling %s\n", power_well->name);
153 power_well->hw_enabled = false;
154 power_well->ops->disable(dev_priv, power_well);
155}
156
Imre Deakb409ca92016-06-13 16:44:33 +0300157static void intel_power_well_get(struct drm_i915_private *dev_priv,
158 struct i915_power_well *power_well)
159{
160 if (!power_well->count++)
161 intel_power_well_enable(dev_priv, power_well);
162}
163
164static void intel_power_well_put(struct drm_i915_private *dev_priv,
165 struct i915_power_well *power_well)
166{
167 WARN(!power_well->count, "Use count on power well %s is already zero",
168 power_well->name);
169
170 if (!--power_well->count)
171 intel_power_well_disable(dev_priv, power_well);
172}
173
Daniel Vettere4e76842014-09-30 10:56:42 +0200174/**
175 * __intel_display_power_is_enabled - unlocked check for a power domain
176 * @dev_priv: i915 device instance
177 * @domain: power domain to check
178 *
179 * This is the unlocked version of intel_display_power_is_enabled() and should
180 * only be used from error capture and recovery code where deadlocks are
181 * possible.
182 *
183 * Returns:
184 * True when the power domain is enabled, false otherwise.
185 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200186bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
187 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200188{
Daniel Vetter9c065a72014-09-30 10:56:38 +0200189 struct i915_power_well *power_well;
190 bool is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200191
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +0100192 if (dev_priv->runtime_pm.suspended)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200193 return false;
194
Daniel Vetter9c065a72014-09-30 10:56:38 +0200195 is_enabled = true;
196
Imre Deak75ccb2e2017-02-17 17:39:43 +0200197 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +0200198 if (power_well->always_on)
199 continue;
200
201 if (!power_well->hw_enabled) {
202 is_enabled = false;
203 break;
204 }
205 }
206
207 return is_enabled;
208}
209
Daniel Vettere4e76842014-09-30 10:56:42 +0200210/**
Damien Lespiauf61ccae2014-11-25 13:45:41 +0000211 * intel_display_power_is_enabled - check for a power domain
Daniel Vettere4e76842014-09-30 10:56:42 +0200212 * @dev_priv: i915 device instance
213 * @domain: power domain to check
214 *
215 * This function can be used to check the hw power domain state. It is mostly
216 * used in hardware state readout functions. Everywhere else code should rely
217 * upon explicit power domain reference counting to ensure that the hardware
218 * block is powered up before accessing it.
219 *
220 * Callers must hold the relevant modesetting locks to ensure that concurrent
221 * threads can't disable the power well while the caller tries to read a few
222 * registers.
223 *
224 * Returns:
225 * True when the power domain is enabled, false otherwise.
226 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200227bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
228 enum intel_display_power_domain domain)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200229{
230 struct i915_power_domains *power_domains;
231 bool ret;
232
233 power_domains = &dev_priv->power_domains;
234
235 mutex_lock(&power_domains->lock);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200236 ret = __intel_display_power_is_enabled(dev_priv, domain);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200237 mutex_unlock(&power_domains->lock);
238
239 return ret;
240}
241
Daniel Vettere4e76842014-09-30 10:56:42 +0200242/**
243 * intel_display_set_init_power - set the initial power domain state
244 * @dev_priv: i915 device instance
245 * @enable: whether to enable or disable the initial power domain state
246 *
247 * For simplicity our driver load/unload and system suspend/resume code assumes
248 * that all power domains are always enabled. This functions controls the state
249 * of this little hack. While the initial power domain state is enabled runtime
250 * pm is effectively disabled.
251 */
Daniel Vetterd9bc89d92014-09-30 10:56:40 +0200252void intel_display_set_init_power(struct drm_i915_private *dev_priv,
253 bool enable)
254{
255 if (dev_priv->power_domains.init_power_on == enable)
256 return;
257
258 if (enable)
259 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
260 else
261 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
262
263 dev_priv->power_domains.init_power_on = enable;
264}
265
Daniel Vetter9c065a72014-09-30 10:56:38 +0200266/*
267 * Starting with Haswell, we have a "Power Down Well" that can be turned off
268 * when not needed anymore. We have 4 registers that can request the power well
269 * to be enabled, and it will only be disabled if none of the registers is
270 * requesting it to be enabled.
271 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300272static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv,
273 u8 irq_pipe_mask, bool has_vga)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200274{
David Weinehall52a05c32016-08-22 13:32:44 +0300275 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200276
277 /*
278 * After we re-enable the power well, if we touch VGA register 0x3d5
279 * we'll get unclaimed register interrupts. This stops after we write
280 * anything to the VGA MSR register. The vgacon module uses this
281 * register all the time, so if we unbind our driver and, as a
282 * consequence, bind vgacon, we'll get stuck in an infinite loop at
283 * console_unlock(). So make here we touch the VGA MSR register, making
284 * sure vgacon can keep working normally without triggering interrupts
285 * and error messages.
286 */
Imre Deak001bd2c2017-07-12 18:54:13 +0300287 if (has_vga) {
288 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
289 outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
290 vga_put(pdev, VGA_RSRC_LEGACY_IO);
291 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200292
Imre Deak001bd2c2017-07-12 18:54:13 +0300293 if (irq_pipe_mask)
294 gen8_irq_power_well_post_enable(dev_priv, irq_pipe_mask);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200295}
296
Imre Deak001bd2c2017-07-12 18:54:13 +0300297static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv,
298 u8 irq_pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200299{
Imre Deak001bd2c2017-07-12 18:54:13 +0300300 if (irq_pipe_mask)
301 gen8_irq_power_well_pre_disable(dev_priv, irq_pipe_mask);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200302}
303
Ville Syrjäläaae8ba82016-02-19 20:47:30 +0200304
Imre Deak76347c02017-07-06 17:40:36 +0300305static void hsw_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
306 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300307{
Imre Deak438b8dc2017-07-11 23:42:30 +0300308 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300309
310 /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
311 WARN_ON(intel_wait_for_register(dev_priv,
Imre Deak9c3a16c2017-08-14 18:15:30 +0300312 HSW_PWR_WELL_CTL_DRIVER(id),
Imre Deak1af474f2017-07-06 17:40:34 +0300313 HSW_PWR_WELL_CTL_STATE(id),
314 HSW_PWR_WELL_CTL_STATE(id),
Imre Deak42d93662017-06-29 18:37:01 +0300315 1));
316}
317
Imre Deak76347c02017-07-06 17:40:36 +0300318static u32 hsw_power_well_requesters(struct drm_i915_private *dev_priv,
319 enum i915_power_well_id id)
Imre Deak42d93662017-06-29 18:37:01 +0300320{
Imre Deak1af474f2017-07-06 17:40:34 +0300321 u32 req_mask = HSW_PWR_WELL_CTL_REQ(id);
Imre Deak42d93662017-06-29 18:37:01 +0300322 u32 ret;
323
Imre Deak9c3a16c2017-08-14 18:15:30 +0300324 ret = I915_READ(HSW_PWR_WELL_CTL_BIOS(id)) & req_mask ? 1 : 0;
325 ret |= I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & req_mask ? 2 : 0;
326 ret |= I915_READ(HSW_PWR_WELL_CTL_KVMR) & req_mask ? 4 : 0;
327 ret |= I915_READ(HSW_PWR_WELL_CTL_DEBUG(id)) & req_mask ? 8 : 0;
Imre Deak42d93662017-06-29 18:37:01 +0300328
329 return ret;
330}
331
Imre Deak76347c02017-07-06 17:40:36 +0300332static void hsw_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
333 struct i915_power_well *power_well)
Imre Deak42d93662017-06-29 18:37:01 +0300334{
Imre Deak438b8dc2017-07-11 23:42:30 +0300335 enum i915_power_well_id id = power_well->id;
Imre Deak42d93662017-06-29 18:37:01 +0300336 bool disabled;
337 u32 reqs;
338
339 /*
340 * Bspec doesn't require waiting for PWs to get disabled, but still do
341 * this for paranoia. The known cases where a PW will be forced on:
342 * - a KVMR request on any power well via the KVMR request register
343 * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
344 * DEBUG request registers
345 * Skip the wait in case any of the request bits are set and print a
346 * diagnostic message.
347 */
Imre Deak9c3a16c2017-08-14 18:15:30 +0300348 wait_for((disabled = !(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
Imre Deak1af474f2017-07-06 17:40:34 +0300349 HSW_PWR_WELL_CTL_STATE(id))) ||
Imre Deak76347c02017-07-06 17:40:36 +0300350 (reqs = hsw_power_well_requesters(dev_priv, id)), 1);
Imre Deak42d93662017-06-29 18:37:01 +0300351 if (disabled)
352 return;
353
354 DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
355 power_well->name,
356 !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
357}
358
Imre Deakb2891eb2017-07-11 23:42:35 +0300359static void gen9_wait_for_power_well_fuses(struct drm_i915_private *dev_priv,
360 enum skl_power_gate pg)
361{
362 /* Timeout 5us for PG#0, for other PGs 1us */
363 WARN_ON(intel_wait_for_register(dev_priv, SKL_FUSE_STATUS,
364 SKL_FUSE_PG_DIST_STATUS(pg),
365 SKL_FUSE_PG_DIST_STATUS(pg), 1));
366}
367
Imre Deakec46d482017-07-06 17:40:33 +0300368static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
369 struct i915_power_well *power_well)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200370{
Imre Deak1af474f2017-07-06 17:40:34 +0300371 enum i915_power_well_id id = power_well->id;
Imre Deakb2891eb2017-07-11 23:42:35 +0300372 bool wait_fuses = power_well->hsw.has_fuses;
Chris Wilson320671f2017-10-02 11:04:16 +0100373 enum skl_power_gate uninitialized_var(pg);
Imre Deak1af474f2017-07-06 17:40:34 +0300374 u32 val;
375
Imre Deakb2891eb2017-07-11 23:42:35 +0300376 if (wait_fuses) {
377 pg = SKL_PW_TO_PG(id);
378 /*
379 * For PW1 we have to wait both for the PW0/PG0 fuse state
380 * before enabling the power well and PW1/PG1's own fuse
381 * state after the enabling. For all other power wells with
382 * fuses we only have to wait for that PW/PG's fuse state
383 * after the enabling.
384 */
385 if (pg == SKL_PG1)
386 gen9_wait_for_power_well_fuses(dev_priv, SKL_PG0);
387 }
388
Imre Deak9c3a16c2017-08-14 18:15:30 +0300389 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
390 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), val | HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300391 hsw_wait_for_power_well_enable(dev_priv, power_well);
Imre Deak001bd2c2017-07-12 18:54:13 +0300392
Imre Deakb2891eb2017-07-11 23:42:35 +0300393 if (wait_fuses)
394 gen9_wait_for_power_well_fuses(dev_priv, pg);
395
Imre Deak001bd2c2017-07-12 18:54:13 +0300396 hsw_power_well_post_enable(dev_priv, power_well->hsw.irq_pipe_mask,
397 power_well->hsw.has_vga);
Imre Deakec46d482017-07-06 17:40:33 +0300398}
Daniel Vetter9c065a72014-09-30 10:56:38 +0200399
Imre Deakec46d482017-07-06 17:40:33 +0300400static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
401 struct i915_power_well *power_well)
402{
Imre Deak1af474f2017-07-06 17:40:34 +0300403 enum i915_power_well_id id = power_well->id;
404 u32 val;
405
Imre Deak001bd2c2017-07-12 18:54:13 +0300406 hsw_power_well_pre_disable(dev_priv, power_well->hsw.irq_pipe_mask);
407
Imre Deak9c3a16c2017-08-14 18:15:30 +0300408 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
409 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id),
410 val & ~HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300411 hsw_wait_for_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200412}
413
Imre Deakd42539b2017-07-06 17:40:39 +0300414/*
415 * We should only use the power well if we explicitly asked the hardware to
416 * enable it, so check if it's enabled and also check if we've requested it to
417 * be enabled.
418 */
419static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
420 struct i915_power_well *power_well)
421{
422 enum i915_power_well_id id = power_well->id;
423 u32 mask = HSW_PWR_WELL_CTL_REQ(id) | HSW_PWR_WELL_CTL_STATE(id);
424
Imre Deak9c3a16c2017-08-14 18:15:30 +0300425 return (I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & mask) == mask;
Imre Deakd42539b2017-07-06 17:40:39 +0300426}
427
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530428static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
429{
Imre Deak9c3a16c2017-08-14 18:15:30 +0300430 enum i915_power_well_id id = SKL_DISP_PW_2;
431
Imre Deakbfcdabe2016-04-01 16:02:37 +0300432 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
433 "DC9 already programmed to be enabled.\n");
434 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
435 "DC5 still not disabled to enable DC9.\n");
Imre Deak9c3a16c2017-08-14 18:15:30 +0300436 WARN_ONCE(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
437 HSW_PWR_WELL_CTL_REQ(id),
Imre Deake8a3a2a2017-06-29 18:37:00 +0300438 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300439 WARN_ONCE(intel_irqs_enabled(dev_priv),
440 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530441
442 /*
443 * TODO: check for the following to verify the conditions to enter DC9
444 * state are satisfied:
445 * 1] Check relevant display engine registers to verify if mode set
446 * disable sequence was followed.
447 * 2] Check if display uninitialize sequence is initialized.
448 */
449}
450
451static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
452{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300453 WARN_ONCE(intel_irqs_enabled(dev_priv),
454 "Interrupts not disabled yet.\n");
455 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
456 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530457
458 /*
459 * TODO: check for the following to verify DC9 state was indeed
460 * entered before programming to disable it:
461 * 1] Check relevant display engine registers to verify if mode
462 * set disable sequence was followed.
463 * 2] Check if display uninitialize sequence is initialized.
464 */
465}
466
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200467static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
468 u32 state)
469{
470 int rewrites = 0;
471 int rereads = 0;
472 u32 v;
473
474 I915_WRITE(DC_STATE_EN, state);
475
476 /* It has been observed that disabling the dc6 state sometimes
477 * doesn't stick and dmc keeps returning old value. Make sure
478 * the write really sticks enough times and also force rewrite until
479 * we are confident that state is exactly what we want.
480 */
481 do {
482 v = I915_READ(DC_STATE_EN);
483
484 if (v != state) {
485 I915_WRITE(DC_STATE_EN, state);
486 rewrites++;
487 rereads = 0;
488 } else if (rereads++ > 5) {
489 break;
490 }
491
492 } while (rewrites < 100);
493
494 if (v != state)
495 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
496 state, v);
497
498 /* Most of the times we need one retry, avoid spam */
499 if (rewrites > 1)
500 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
501 state, rewrites);
502}
503
Imre Deakda2f41d2016-04-20 20:27:56 +0300504static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530505{
Imre Deakda2f41d2016-04-20 20:27:56 +0300506 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530507
Imre Deak13ae3a02015-11-04 19:24:16 +0200508 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200509 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200510 mask |= DC_STATE_EN_DC9;
511 else
512 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530513
Imre Deakda2f41d2016-04-20 20:27:56 +0300514 return mask;
515}
516
517void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
518{
519 u32 val;
520
521 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
522
523 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
524 dev_priv->csr.dc_state, val);
525 dev_priv->csr.dc_state = val;
526}
527
528static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
529{
530 uint32_t val;
531 uint32_t mask;
532
Imre Deaka37baf32016-02-29 22:49:03 +0200533 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
534 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100535
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530536 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300537 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200538 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
539 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200540
541 /* Check if DMC is ignoring our DC state requests */
542 if ((val & mask) != dev_priv->csr.dc_state)
543 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
544 dev_priv->csr.dc_state, val & mask);
545
Imre Deak13ae3a02015-11-04 19:24:16 +0200546 val &= ~mask;
547 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200548
549 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200550
551 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530552}
553
Imre Deak13ae3a02015-11-04 19:24:16 +0200554void bxt_enable_dc9(struct drm_i915_private *dev_priv)
555{
556 assert_can_enable_dc9(dev_priv);
557
558 DRM_DEBUG_KMS("Enabling DC9\n");
559
Imre Deak78597992016-06-16 16:37:20 +0300560 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200561 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
562}
563
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530564void bxt_disable_dc9(struct drm_i915_private *dev_priv)
565{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530566 assert_can_disable_dc9(dev_priv);
567
568 DRM_DEBUG_KMS("Disabling DC9\n");
569
Imre Deak13ae3a02015-11-04 19:24:16 +0200570 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300571
572 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530573}
574
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200575static void assert_csr_loaded(struct drm_i915_private *dev_priv)
576{
577 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
578 "CSR program storage start is NULL\n");
579 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
580 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
581}
582
Suketu Shah5aefb232015-04-16 14:22:10 +0530583static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530584{
Suketu Shah5aefb232015-04-16 14:22:10 +0530585 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
586 SKL_DISP_PW_2);
587
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700588 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530589
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700590 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
591 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200592 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530593
594 assert_csr_loaded(dev_priv);
595}
596
Imre Deakf62c79b2016-04-20 20:27:57 +0300597void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530598{
Suketu Shah5aefb232015-04-16 14:22:10 +0530599 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530600
601 DRM_DEBUG_KMS("Enabling DC5\n");
602
Lucas De Marchi53421c22017-12-04 15:22:10 -0800603 /* Wa Display #1183: skl,kbl,cfl */
604 if (IS_GEN9_BC(dev_priv))
605 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
606 SKL_SELECT_ALTERNATE_DC_EXIT);
607
Imre Deak13ae3a02015-11-04 19:24:16 +0200608 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530609}
610
Suketu Shah93c7cb62015-04-16 14:22:13 +0530611static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530612{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700613 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
614 "Backlight is not disabled.\n");
615 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
616 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530617
618 assert_csr_loaded(dev_priv);
619}
620
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530621void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530622{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530623 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530624
625 DRM_DEBUG_KMS("Enabling DC6\n");
626
Imre Deak13ae3a02015-11-04 19:24:16 +0200627 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
628
Suketu Shahf75a1982015-04-16 14:22:11 +0530629}
630
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530631void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530632{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530633 DRM_DEBUG_KMS("Disabling DC6\n");
634
Lucas De Marchi53421c22017-12-04 15:22:10 -0800635 /* Wa Display #1183: skl,kbl,cfl */
636 if (IS_GEN9_BC(dev_priv))
637 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
638 SKL_SELECT_ALTERNATE_DC_EXIT);
639
Imre Deak13ae3a02015-11-04 19:24:16 +0200640 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530641}
642
Daniel Vetter9c065a72014-09-30 10:56:38 +0200643static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
644 struct i915_power_well *power_well)
645{
Imre Deak1af474f2017-07-06 17:40:34 +0300646 enum i915_power_well_id id = power_well->id;
647 u32 mask = HSW_PWR_WELL_CTL_REQ(id);
Imre Deak9c3a16c2017-08-14 18:15:30 +0300648 u32 bios_req = I915_READ(HSW_PWR_WELL_CTL_BIOS(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300649
Imre Deak16e84912017-02-17 17:39:45 +0200650 /* Take over the request bit if set by BIOS. */
Imre Deak1af474f2017-07-06 17:40:34 +0300651 if (bios_req & mask) {
Imre Deak9c3a16c2017-08-14 18:15:30 +0300652 u32 drv_req = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300653
654 if (!(drv_req & mask))
Imre Deak9c3a16c2017-08-14 18:15:30 +0300655 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), drv_req | mask);
656 I915_WRITE(HSW_PWR_WELL_CTL_BIOS(id), bios_req & ~mask);
Imre Deak16e84912017-02-17 17:39:45 +0200657 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200658}
659
Imre Deak9c8d0b82016-06-13 16:44:34 +0300660static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
661 struct i915_power_well *power_well)
662{
Imre Deakb5565a22017-07-06 17:40:29 +0300663 bxt_ddi_phy_init(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300664}
665
666static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
667 struct i915_power_well *power_well)
668{
Imre Deakb5565a22017-07-06 17:40:29 +0300669 bxt_ddi_phy_uninit(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300670}
671
672static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
673 struct i915_power_well *power_well)
674{
Imre Deakb5565a22017-07-06 17:40:29 +0300675 return bxt_ddi_phy_is_enabled(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300676}
677
Imre Deak9c8d0b82016-06-13 16:44:34 +0300678static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
679{
680 struct i915_power_well *power_well;
681
682 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
683 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300684 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300685
686 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
687 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300688 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200689
690 if (IS_GEMINILAKE(dev_priv)) {
691 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
692 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300693 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200694 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300695}
696
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100697static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
698 struct i915_power_well *power_well)
699{
700 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
701}
702
Ville Syrjälä18a80672016-05-16 16:59:40 +0300703static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
704{
705 u32 tmp = I915_READ(DBUF_CTL);
706
707 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
708 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
709 "Unexpected DBuf power power state (0x%08x)\n", tmp);
710}
711
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100712static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
713 struct i915_power_well *power_well)
714{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200715 struct intel_cdclk_state cdclk_state = {};
716
Imre Deak5b773eb2016-02-29 22:49:05 +0200717 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300718
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200719 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
Ville Syrjälä64600bd2017-10-24 12:52:08 +0300720 /* Can't read out voltage_level so can't use intel_cdclk_changed() */
721 WARN_ON(intel_cdclk_needs_modeset(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300722
Ville Syrjälä18a80672016-05-16 16:59:40 +0300723 gen9_assert_dbuf_enabled(dev_priv);
724
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200725 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300726 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100727}
728
729static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
730 struct i915_power_well *power_well)
731{
Imre Deakf74ed082016-04-18 14:48:21 +0300732 if (!dev_priv->csr.dmc_payload)
733 return;
734
Imre Deaka37baf32016-02-29 22:49:03 +0200735 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100736 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200737 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100738 gen9_enable_dc5(dev_priv);
739}
740
Imre Deak3c1b38e2017-02-17 17:39:42 +0200741static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
742 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100743{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100744}
745
Daniel Vetter9c065a72014-09-30 10:56:38 +0200746static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
747 struct i915_power_well *power_well)
748{
749}
750
751static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
752 struct i915_power_well *power_well)
753{
754 return true;
755}
756
Ville Syrjälä2ee0da12017-06-01 17:36:16 +0300757static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
758 struct i915_power_well *power_well)
759{
760 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
761 i830_enable_pipe(dev_priv, PIPE_A);
762 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
763 i830_enable_pipe(dev_priv, PIPE_B);
764}
765
766static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
767 struct i915_power_well *power_well)
768{
769 i830_disable_pipe(dev_priv, PIPE_B);
770 i830_disable_pipe(dev_priv, PIPE_A);
771}
772
773static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
774 struct i915_power_well *power_well)
775{
776 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
777 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
778}
779
780static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
781 struct i915_power_well *power_well)
782{
783 if (power_well->count > 0)
784 i830_pipes_power_well_enable(dev_priv, power_well);
785 else
786 i830_pipes_power_well_disable(dev_priv, power_well);
787}
788
Daniel Vetter9c065a72014-09-30 10:56:38 +0200789static void vlv_set_power_well(struct drm_i915_private *dev_priv,
790 struct i915_power_well *power_well, bool enable)
791{
Imre Deak438b8dc2017-07-11 23:42:30 +0300792 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200793 u32 mask;
794 u32 state;
795 u32 ctrl;
796
797 mask = PUNIT_PWRGT_MASK(power_well_id);
798 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
799 PUNIT_PWRGT_PWR_GATE(power_well_id);
800
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100801 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200802
803#define COND \
804 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
805
806 if (COND)
807 goto out;
808
809 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
810 ctrl &= ~mask;
811 ctrl |= state;
812 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
813
814 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900815 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200816 state,
817 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
818
819#undef COND
820
821out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100822 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200823}
824
Daniel Vetter9c065a72014-09-30 10:56:38 +0200825static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
826 struct i915_power_well *power_well)
827{
828 vlv_set_power_well(dev_priv, power_well, true);
829}
830
831static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
832 struct i915_power_well *power_well)
833{
834 vlv_set_power_well(dev_priv, power_well, false);
835}
836
837static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
838 struct i915_power_well *power_well)
839{
Imre Deak438b8dc2017-07-11 23:42:30 +0300840 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200841 bool enabled = false;
842 u32 mask;
843 u32 state;
844 u32 ctrl;
845
846 mask = PUNIT_PWRGT_MASK(power_well_id);
847 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
848
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100849 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200850
851 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
852 /*
853 * We only ever set the power-on and power-gate states, anything
854 * else is unexpected.
855 */
856 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
857 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
858 if (state == ctrl)
859 enabled = true;
860
861 /*
862 * A transient state at this point would mean some unexpected party
863 * is poking at the power controls too.
864 */
865 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
866 WARN_ON(ctrl != state);
867
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100868 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200869
870 return enabled;
871}
872
Ville Syrjälä766078d2016-04-11 16:56:30 +0300873static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
874{
Hans de Goede721d4842016-12-02 15:29:04 +0100875 u32 val;
876
877 /*
878 * On driver load, a pipe may be active and driving a DSI display.
879 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
880 * (and never recovering) in this case. intel_dsi_post_disable() will
881 * clear it when we turn off the display.
882 */
883 val = I915_READ(DSPCLK_GATE_D);
884 val &= DPOUNIT_CLOCK_GATE_DISABLE;
885 val |= VRHUNIT_CLOCK_GATE_DISABLE;
886 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +0300887
888 /*
889 * Disable trickle feed and enable pnd deadline calculation
890 */
891 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
892 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +0300893
894 WARN_ON(dev_priv->rawclk_freq == 0);
895
896 I915_WRITE(RAWCLK_FREQ_VLV,
897 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +0300898}
899
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300900static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200901{
Lyude9504a892016-06-21 17:03:42 -0400902 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300903 enum pipe pipe;
904
905 /*
906 * Enable the CRI clock source so we can get at the
907 * display and the reference clock for VGA
908 * hotplug / manual detection. Supposedly DSI also
909 * needs the ref clock up and running.
910 *
911 * CHV DPLL B/C have some issues if VGA mode is enabled.
912 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +0000913 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300914 u32 val = I915_READ(DPLL(pipe));
915
916 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
917 if (pipe != PIPE_A)
918 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
919
920 I915_WRITE(DPLL(pipe), val);
921 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200922
Ville Syrjälä766078d2016-04-11 16:56:30 +0300923 vlv_init_display_clock_gating(dev_priv);
924
Daniel Vetter9c065a72014-09-30 10:56:38 +0200925 spin_lock_irq(&dev_priv->irq_lock);
926 valleyview_enable_display_irqs(dev_priv);
927 spin_unlock_irq(&dev_priv->irq_lock);
928
929 /*
930 * During driver initialization/resume we can avoid restoring the
931 * part of the HW/SW state that will be inited anyway explicitly.
932 */
933 if (dev_priv->power_domains.initializing)
934 return;
935
Daniel Vetterb9632912014-09-30 10:56:44 +0200936 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200937
Lyude9504a892016-06-21 17:03:42 -0400938 /* Re-enable the ADPA, if we have one */
939 for_each_intel_encoder(&dev_priv->drm, encoder) {
940 if (encoder->type == INTEL_OUTPUT_ANALOG)
941 intel_crt_reset(&encoder->base);
942 }
943
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +0000944 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +0300945
946 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200947}
948
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300949static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
950{
951 spin_lock_irq(&dev_priv->irq_lock);
952 valleyview_disable_display_irqs(dev_priv);
953 spin_unlock_irq(&dev_priv->irq_lock);
954
Ville Syrjälä2230fde2016-02-19 18:41:52 +0200955 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +0100956 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +0200957
Imre Deak78597992016-06-16 16:37:20 +0300958 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -0400959
Lyudeb64b5402016-10-26 12:36:09 -0400960 /* Prevent us from re-enabling polling on accident in late suspend */
961 if (!dev_priv->drm.dev->power.is_suspended)
962 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300963}
964
965static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
966 struct i915_power_well *power_well)
967{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300968 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300969
970 vlv_set_power_well(dev_priv, power_well, true);
971
972 vlv_display_power_well_init(dev_priv);
973}
974
Daniel Vetter9c065a72014-09-30 10:56:38 +0200975static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
976 struct i915_power_well *power_well)
977{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300978 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200979
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300980 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200981
982 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200983}
984
985static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
986 struct i915_power_well *power_well)
987{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300988 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200989
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300990 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +0200991 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
992
993 vlv_set_power_well(dev_priv, power_well, true);
994
995 /*
996 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
997 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
998 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
999 * b. The other bits such as sfr settings / modesel may all
1000 * be set to 0.
1001 *
1002 * This should only be done on init and resume from S3 with
1003 * both PLLs disabled, or we risk losing DPIO and PLL
1004 * synchronization.
1005 */
1006 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1007}
1008
1009static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1010 struct i915_power_well *power_well)
1011{
1012 enum pipe pipe;
1013
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001014 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001015
1016 for_each_pipe(dev_priv, pipe)
1017 assert_pll_disabled(dev_priv, pipe);
1018
1019 /* Assert common reset */
1020 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1021
1022 vlv_set_power_well(dev_priv, power_well, false);
1023}
1024
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001025#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001026
Imre Deak438b8dc2017-07-11 23:42:30 +03001027static struct i915_power_well *
1028lookup_power_well(struct drm_i915_private *dev_priv,
1029 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001030{
1031 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001032 int i;
1033
Imre Deakfc17f222015-11-04 19:24:11 +02001034 for (i = 0; i < power_domains->power_well_count; i++) {
1035 struct i915_power_well *power_well;
1036
1037 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001038 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001039 return power_well;
1040 }
1041
1042 return NULL;
1043}
1044
1045#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1046
1047static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1048{
1049 struct i915_power_well *cmn_bc =
1050 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1051 struct i915_power_well *cmn_d =
1052 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1053 u32 phy_control = dev_priv->chv_phy_control;
1054 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001055 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001056
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001057 /*
1058 * The BIOS can leave the PHY is some weird state
1059 * where it doesn't fully power down some parts.
1060 * Disable the asserts until the PHY has been fully
1061 * reset (ie. the power well has been disabled at
1062 * least once).
1063 */
1064 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1065 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1066 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1067 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1068 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1069 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1070 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1071
1072 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1073 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1074 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1075 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1076
Ville Syrjälä30142272015-07-08 23:46:01 +03001077 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1078 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1079
1080 /* this assumes override is only used to enable lanes */
1081 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1082 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1083
1084 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1085 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1086
1087 /* CL1 is on whenever anything is on in either channel */
1088 if (BITS_SET(phy_control,
1089 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1090 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1091 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1092
1093 /*
1094 * The DPLLB check accounts for the pipe B + port A usage
1095 * with CL2 powered up but all the lanes in the second channel
1096 * powered down.
1097 */
1098 if (BITS_SET(phy_control,
1099 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1100 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1101 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1102
1103 if (BITS_SET(phy_control,
1104 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1105 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1106 if (BITS_SET(phy_control,
1107 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1108 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1109
1110 if (BITS_SET(phy_control,
1111 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1112 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1113 if (BITS_SET(phy_control,
1114 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1115 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1116 }
1117
1118 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1119 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1120
1121 /* this assumes override is only used to enable lanes */
1122 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1123 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1124
1125 if (BITS_SET(phy_control,
1126 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1127 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1128
1129 if (BITS_SET(phy_control,
1130 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1131 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1132 if (BITS_SET(phy_control,
1133 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1134 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1135 }
1136
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001137 phy_status &= phy_status_mask;
1138
Ville Syrjälä30142272015-07-08 23:46:01 +03001139 /*
1140 * The PHY may be busy with some initial calibration and whatnot,
1141 * so the power state can take a while to actually change.
1142 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001143 if (intel_wait_for_register(dev_priv,
1144 DISPLAY_PHY_STATUS,
1145 phy_status_mask,
1146 phy_status,
1147 10))
1148 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1149 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1150 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001151}
1152
1153#undef BITS_SET
1154
Daniel Vetter9c065a72014-09-30 10:56:38 +02001155static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1156 struct i915_power_well *power_well)
1157{
1158 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001159 enum pipe pipe;
1160 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001161
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001162 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1163 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001164
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001165 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001166 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001167 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001168 } else {
1169 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001170 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001171 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001172
1173 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001174 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1175 vlv_set_power_well(dev_priv, power_well, true);
1176
1177 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001178 if (intel_wait_for_register(dev_priv,
1179 DISPLAY_PHY_STATUS,
1180 PHY_POWERGOOD(phy),
1181 PHY_POWERGOOD(phy),
1182 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001183 DRM_ERROR("Display PHY %d is not power up\n", phy);
1184
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001185 mutex_lock(&dev_priv->sb_lock);
1186
1187 /* Enable dynamic power down */
1188 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001189 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1190 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001191 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1192
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001193 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001194 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1195 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1196 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001197 } else {
1198 /*
1199 * Force the non-existing CL2 off. BXT does this
1200 * too, so maybe it saves some power even though
1201 * CL2 doesn't exist?
1202 */
1203 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1204 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1205 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001206 }
1207
1208 mutex_unlock(&dev_priv->sb_lock);
1209
Ville Syrjälä70722462015-04-10 18:21:28 +03001210 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1211 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001212
1213 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1214 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001215
1216 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001217}
1218
1219static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1220 struct i915_power_well *power_well)
1221{
1222 enum dpio_phy phy;
1223
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001224 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1225 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001226
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001227 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001228 phy = DPIO_PHY0;
1229 assert_pll_disabled(dev_priv, PIPE_A);
1230 assert_pll_disabled(dev_priv, PIPE_B);
1231 } else {
1232 phy = DPIO_PHY1;
1233 assert_pll_disabled(dev_priv, PIPE_C);
1234 }
1235
Ville Syrjälä70722462015-04-10 18:21:28 +03001236 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1237 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001238
1239 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001240
1241 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1242 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001243
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001244 /* PHY is fully reset now, so we can enable the PHY state asserts */
1245 dev_priv->chv_phy_assert[phy] = true;
1246
Ville Syrjälä30142272015-07-08 23:46:01 +03001247 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001248}
1249
Ville Syrjälä6669e392015-07-08 23:46:00 +03001250static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1251 enum dpio_channel ch, bool override, unsigned int mask)
1252{
1253 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1254 u32 reg, val, expected, actual;
1255
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001256 /*
1257 * The BIOS can leave the PHY is some weird state
1258 * where it doesn't fully power down some parts.
1259 * Disable the asserts until the PHY has been fully
1260 * reset (ie. the power well has been disabled at
1261 * least once).
1262 */
1263 if (!dev_priv->chv_phy_assert[phy])
1264 return;
1265
Ville Syrjälä6669e392015-07-08 23:46:00 +03001266 if (ch == DPIO_CH0)
1267 reg = _CHV_CMN_DW0_CH0;
1268 else
1269 reg = _CHV_CMN_DW6_CH1;
1270
1271 mutex_lock(&dev_priv->sb_lock);
1272 val = vlv_dpio_read(dev_priv, pipe, reg);
1273 mutex_unlock(&dev_priv->sb_lock);
1274
1275 /*
1276 * This assumes !override is only used when the port is disabled.
1277 * All lanes should power down even without the override when
1278 * the port is disabled.
1279 */
1280 if (!override || mask == 0xf) {
1281 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1282 /*
1283 * If CH1 common lane is not active anymore
1284 * (eg. for pipe B DPLL) the entire channel will
1285 * shut down, which causes the common lane registers
1286 * to read as 0. That means we can't actually check
1287 * the lane power down status bits, but as the entire
1288 * register reads as 0 it's a good indication that the
1289 * channel is indeed entirely powered down.
1290 */
1291 if (ch == DPIO_CH1 && val == 0)
1292 expected = 0;
1293 } else if (mask != 0x0) {
1294 expected = DPIO_ANYDL_POWERDOWN;
1295 } else {
1296 expected = 0;
1297 }
1298
1299 if (ch == DPIO_CH0)
1300 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1301 else
1302 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1303 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1304
1305 WARN(actual != expected,
1306 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1307 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1308 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1309 reg, val);
1310}
1311
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001312bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1313 enum dpio_channel ch, bool override)
1314{
1315 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1316 bool was_override;
1317
1318 mutex_lock(&power_domains->lock);
1319
1320 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1321
1322 if (override == was_override)
1323 goto out;
1324
1325 if (override)
1326 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1327 else
1328 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1329
1330 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1331
1332 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1333 phy, ch, dev_priv->chv_phy_control);
1334
Ville Syrjälä30142272015-07-08 23:46:01 +03001335 assert_chv_phy_status(dev_priv);
1336
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001337out:
1338 mutex_unlock(&power_domains->lock);
1339
1340 return was_override;
1341}
1342
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001343void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1344 bool override, unsigned int mask)
1345{
1346 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1347 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1348 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1349 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1350
1351 mutex_lock(&power_domains->lock);
1352
1353 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1354 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1355
1356 if (override)
1357 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1358 else
1359 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1360
1361 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1362
1363 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1364 phy, ch, mask, dev_priv->chv_phy_control);
1365
Ville Syrjälä30142272015-07-08 23:46:01 +03001366 assert_chv_phy_status(dev_priv);
1367
Ville Syrjälä6669e392015-07-08 23:46:00 +03001368 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1369
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001370 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001371}
1372
1373static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1374 struct i915_power_well *power_well)
1375{
Imre Deakf49193c2017-07-06 17:40:23 +03001376 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001377 bool enabled;
1378 u32 state, ctrl;
1379
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001380 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001381
1382 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1383 /*
1384 * We only ever set the power-on and power-gate states, anything
1385 * else is unexpected.
1386 */
1387 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1388 enabled = state == DP_SSS_PWR_ON(pipe);
1389
1390 /*
1391 * A transient state at this point would mean some unexpected party
1392 * is poking at the power controls too.
1393 */
1394 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1395 WARN_ON(ctrl << 16 != state);
1396
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001397 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001398
1399 return enabled;
1400}
1401
1402static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1403 struct i915_power_well *power_well,
1404 bool enable)
1405{
Imre Deakf49193c2017-07-06 17:40:23 +03001406 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001407 u32 state;
1408 u32 ctrl;
1409
1410 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1411
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001412 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001413
1414#define COND \
1415 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1416
1417 if (COND)
1418 goto out;
1419
1420 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1421 ctrl &= ~DP_SSC_MASK(pipe);
1422 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1423 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1424
1425 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001426 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001427 state,
1428 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1429
1430#undef COND
1431
1432out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001433 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001434}
1435
Daniel Vetter9c065a72014-09-30 10:56:38 +02001436static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1437 struct i915_power_well *power_well)
1438{
Imre Deakf49193c2017-07-06 17:40:23 +03001439 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001440
1441 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001442
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001443 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001444}
1445
1446static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1447 struct i915_power_well *power_well)
1448{
Imre Deakf49193c2017-07-06 17:40:23 +03001449 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001450
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001451 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001452
Daniel Vetter9c065a72014-09-30 10:56:38 +02001453 chv_set_pipe_power_well(dev_priv, power_well, false);
1454}
1455
Imre Deak09731282016-02-17 14:17:42 +02001456static void
1457__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1458 enum intel_display_power_domain domain)
1459{
1460 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1461 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001462
Imre Deak75ccb2e2017-02-17 17:39:43 +02001463 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001464 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001465
1466 power_domains->domain_use_count[domain]++;
1467}
1468
Daniel Vettere4e76842014-09-30 10:56:42 +02001469/**
1470 * intel_display_power_get - grab a power domain reference
1471 * @dev_priv: i915 device instance
1472 * @domain: power domain to reference
1473 *
1474 * This function grabs a power domain reference for @domain and ensures that the
1475 * power domain and all its parents are powered up. Therefore users should only
1476 * grab a reference to the innermost power domain they need.
1477 *
1478 * Any power domain reference obtained by this function must have a symmetric
1479 * call to intel_display_power_put() to release the reference again.
1480 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001481void intel_display_power_get(struct drm_i915_private *dev_priv,
1482 enum intel_display_power_domain domain)
1483{
Imre Deak09731282016-02-17 14:17:42 +02001484 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001485
1486 intel_runtime_pm_get(dev_priv);
1487
Imre Deak09731282016-02-17 14:17:42 +02001488 mutex_lock(&power_domains->lock);
1489
1490 __intel_display_power_get_domain(dev_priv, domain);
1491
1492 mutex_unlock(&power_domains->lock);
1493}
1494
1495/**
1496 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1497 * @dev_priv: i915 device instance
1498 * @domain: power domain to reference
1499 *
1500 * This function grabs a power domain reference for @domain and ensures that the
1501 * power domain and all its parents are powered up. Therefore users should only
1502 * grab a reference to the innermost power domain they need.
1503 *
1504 * Any power domain reference obtained by this function must have a symmetric
1505 * call to intel_display_power_put() to release the reference again.
1506 */
1507bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1508 enum intel_display_power_domain domain)
1509{
1510 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1511 bool is_enabled;
1512
1513 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1514 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001515
1516 mutex_lock(&power_domains->lock);
1517
Imre Deak09731282016-02-17 14:17:42 +02001518 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1519 __intel_display_power_get_domain(dev_priv, domain);
1520 is_enabled = true;
1521 } else {
1522 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001523 }
1524
Daniel Vetter9c065a72014-09-30 10:56:38 +02001525 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001526
1527 if (!is_enabled)
1528 intel_runtime_pm_put(dev_priv);
1529
1530 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001531}
1532
Daniel Vettere4e76842014-09-30 10:56:42 +02001533/**
1534 * intel_display_power_put - release a power domain reference
1535 * @dev_priv: i915 device instance
1536 * @domain: power domain to reference
1537 *
1538 * This function drops the power domain reference obtained by
1539 * intel_display_power_get() and might power down the corresponding hardware
1540 * block right away if this is the last reference.
1541 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001542void intel_display_power_put(struct drm_i915_private *dev_priv,
1543 enum intel_display_power_domain domain)
1544{
1545 struct i915_power_domains *power_domains;
1546 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001547
1548 power_domains = &dev_priv->power_domains;
1549
1550 mutex_lock(&power_domains->lock);
1551
Daniel Stone11c86db2015-11-20 15:55:34 +00001552 WARN(!power_domains->domain_use_count[domain],
1553 "Use count on domain %s is already zero\n",
1554 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001555 power_domains->domain_use_count[domain]--;
1556
Imre Deak75ccb2e2017-02-17 17:39:43 +02001557 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001558 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001559
1560 mutex_unlock(&power_domains->lock);
1561
1562 intel_runtime_pm_put(dev_priv);
1563}
1564
Imre Deak965a79a2017-07-06 17:40:40 +03001565#define I830_PIPES_POWER_DOMAINS ( \
1566 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1567 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1568 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1569 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1570 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1571 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001572 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001573
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001574#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001575 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1576 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1577 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1578 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1579 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1580 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1581 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1582 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1583 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1584 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1585 BIT_ULL(POWER_DOMAIN_VGA) | \
1586 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1587 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1588 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1589 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1590 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001591
1592#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001593 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1594 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1595 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1596 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1597 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1598 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001599
1600#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001601 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1602 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1603 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001604
1605#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001606 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1607 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1608 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001609
1610#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001611 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1612 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1613 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001614
1615#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001616 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1617 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1618 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001619
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001620#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001621 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1622 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1623 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1624 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1625 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1626 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1627 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1628 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1629 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1630 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1631 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1632 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1633 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1634 BIT_ULL(POWER_DOMAIN_VGA) | \
1635 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1636 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1637 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1638 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1639 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1640 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001641
Daniel Vetter9c065a72014-09-30 10:56:38 +02001642#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001643 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1644 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1645 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1646 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1647 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001648
1649#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001650 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1651 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1652 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001653
Imre Deak965a79a2017-07-06 17:40:40 +03001654#define HSW_DISPLAY_POWER_DOMAINS ( \
1655 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1656 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1657 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1658 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1659 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1660 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1661 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1662 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1663 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1664 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1665 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1666 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1667 BIT_ULL(POWER_DOMAIN_VGA) | \
1668 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1669 BIT_ULL(POWER_DOMAIN_INIT))
1670
1671#define BDW_DISPLAY_POWER_DOMAINS ( \
1672 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1673 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1674 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1675 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1676 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1677 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1678 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1679 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1680 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1681 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1682 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1683 BIT_ULL(POWER_DOMAIN_VGA) | \
1684 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1685 BIT_ULL(POWER_DOMAIN_INIT))
1686
1687#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1688 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1689 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1690 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1691 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1692 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1693 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1694 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1695 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1696 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1697 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1698 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1699 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1700 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1701 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1702 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1703 BIT_ULL(POWER_DOMAIN_VGA) | \
1704 BIT_ULL(POWER_DOMAIN_INIT))
1705#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
1706 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
1707 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1708 BIT_ULL(POWER_DOMAIN_INIT))
1709#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1710 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1711 BIT_ULL(POWER_DOMAIN_INIT))
1712#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1713 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1714 BIT_ULL(POWER_DOMAIN_INIT))
1715#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
1716 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1717 BIT_ULL(POWER_DOMAIN_INIT))
1718#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1719 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001720 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001721 BIT_ULL(POWER_DOMAIN_MODESET) | \
1722 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1723 BIT_ULL(POWER_DOMAIN_INIT))
1724
1725#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1726 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1727 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1728 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1729 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1730 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1731 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1732 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1733 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1734 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1735 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1736 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1737 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1738 BIT_ULL(POWER_DOMAIN_VGA) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001739 BIT_ULL(POWER_DOMAIN_INIT))
1740#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1741 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001742 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001743 BIT_ULL(POWER_DOMAIN_MODESET) | \
1744 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä54c105d2017-12-08 23:37:37 +02001745 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001746 BIT_ULL(POWER_DOMAIN_INIT))
1747#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
1748 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1749 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1750 BIT_ULL(POWER_DOMAIN_INIT))
1751#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
1752 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1753 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1754 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1755 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1756 BIT_ULL(POWER_DOMAIN_INIT))
1757
1758#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1759 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1760 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1761 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1762 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1763 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1764 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1765 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1766 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1767 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1768 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1769 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1770 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1771 BIT_ULL(POWER_DOMAIN_VGA) | \
1772 BIT_ULL(POWER_DOMAIN_INIT))
1773#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
1774 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
1775#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1776 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
1777#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1778 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
1779#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
1780 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1781 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1782 BIT_ULL(POWER_DOMAIN_INIT))
1783#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
1784 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1785 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1786 BIT_ULL(POWER_DOMAIN_INIT))
1787#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
1788 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1789 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1790 BIT_ULL(POWER_DOMAIN_INIT))
1791#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
1792 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1793 BIT_ULL(POWER_DOMAIN_INIT))
1794#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
1795 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1796 BIT_ULL(POWER_DOMAIN_INIT))
1797#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
1798 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1799 BIT_ULL(POWER_DOMAIN_INIT))
1800#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1801 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001802 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001803 BIT_ULL(POWER_DOMAIN_MODESET) | \
1804 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä156961a2017-12-08 23:37:36 +02001805 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001806 BIT_ULL(POWER_DOMAIN_INIT))
1807
1808#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1809 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1810 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1811 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1812 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1813 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1814 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1815 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1816 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1817 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1818 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001819 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1820 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1821 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1822 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1823 BIT_ULL(POWER_DOMAIN_VGA) | \
1824 BIT_ULL(POWER_DOMAIN_INIT))
1825#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
1826 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001827 BIT_ULL(POWER_DOMAIN_INIT))
1828#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
1829 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1830 BIT_ULL(POWER_DOMAIN_INIT))
1831#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
1832 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1833 BIT_ULL(POWER_DOMAIN_INIT))
1834#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
1835 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1836 BIT_ULL(POWER_DOMAIN_INIT))
1837#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
1838 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1839 BIT_ULL(POWER_DOMAIN_INIT))
1840#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
1841 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1842 BIT_ULL(POWER_DOMAIN_INIT))
1843#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
1844 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1845 BIT_ULL(POWER_DOMAIN_INIT))
1846#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
1847 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1848 BIT_ULL(POWER_DOMAIN_INIT))
1849#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1850 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulin6e7a3f52018-01-11 08:24:17 +00001851 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001852 BIT_ULL(POWER_DOMAIN_MODESET) | \
1853 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001854 BIT_ULL(POWER_DOMAIN_INIT))
1855
Daniel Vetter9c065a72014-09-30 10:56:38 +02001856static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001857 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001858 .enable = i9xx_always_on_power_well_noop,
1859 .disable = i9xx_always_on_power_well_noop,
1860 .is_enabled = i9xx_always_on_power_well_enabled,
1861};
1862
1863static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001864 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001865 .enable = chv_pipe_power_well_enable,
1866 .disable = chv_pipe_power_well_disable,
1867 .is_enabled = chv_pipe_power_well_enabled,
1868};
1869
1870static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001871 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001872 .enable = chv_dpio_cmn_power_well_enable,
1873 .disable = chv_dpio_cmn_power_well_disable,
1874 .is_enabled = vlv_power_well_enabled,
1875};
1876
1877static struct i915_power_well i9xx_always_on_power_well[] = {
1878 {
1879 .name = "always-on",
1880 .always_on = 1,
1881 .domains = POWER_DOMAIN_MASK,
1882 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001883 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001884 },
1885};
1886
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001887static const struct i915_power_well_ops i830_pipes_power_well_ops = {
1888 .sync_hw = i830_pipes_power_well_sync_hw,
1889 .enable = i830_pipes_power_well_enable,
1890 .disable = i830_pipes_power_well_disable,
1891 .is_enabled = i830_pipes_power_well_enabled,
1892};
1893
1894static struct i915_power_well i830_power_wells[] = {
1895 {
1896 .name = "always-on",
1897 .always_on = 1,
1898 .domains = POWER_DOMAIN_MASK,
1899 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001900 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001901 },
1902 {
1903 .name = "pipes",
1904 .domains = I830_PIPES_POWER_DOMAINS,
1905 .ops = &i830_pipes_power_well_ops,
Imre Deak120b56a2017-07-11 23:42:31 +03001906 .id = I830_DISP_PW_PIPES,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001907 },
1908};
1909
Daniel Vetter9c065a72014-09-30 10:56:38 +02001910static const struct i915_power_well_ops hsw_power_well_ops = {
1911 .sync_hw = hsw_power_well_sync_hw,
1912 .enable = hsw_power_well_enable,
1913 .disable = hsw_power_well_disable,
1914 .is_enabled = hsw_power_well_enabled,
1915};
1916
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001917static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001918 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001919 .enable = gen9_dc_off_power_well_enable,
1920 .disable = gen9_dc_off_power_well_disable,
1921 .is_enabled = gen9_dc_off_power_well_enabled,
1922};
1923
Imre Deak9c8d0b82016-06-13 16:44:34 +03001924static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001925 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03001926 .enable = bxt_dpio_cmn_power_well_enable,
1927 .disable = bxt_dpio_cmn_power_well_disable,
1928 .is_enabled = bxt_dpio_cmn_power_well_enabled,
1929};
1930
Daniel Vetter9c065a72014-09-30 10:56:38 +02001931static struct i915_power_well hsw_power_wells[] = {
1932 {
1933 .name = "always-on",
1934 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001935 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001936 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001937 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001938 },
1939 {
1940 .name = "display",
1941 .domains = HSW_DISPLAY_POWER_DOMAINS,
1942 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03001943 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03001944 {
1945 .hsw.has_vga = true,
1946 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001947 },
1948};
1949
1950static struct i915_power_well bdw_power_wells[] = {
1951 {
1952 .name = "always-on",
1953 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001954 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001955 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001956 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001957 },
1958 {
1959 .name = "display",
1960 .domains = BDW_DISPLAY_POWER_DOMAINS,
1961 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03001962 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03001963 {
1964 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
1965 .hsw.has_vga = true,
1966 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001967 },
1968};
1969
1970static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001971 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001972 .enable = vlv_display_power_well_enable,
1973 .disable = vlv_display_power_well_disable,
1974 .is_enabled = vlv_power_well_enabled,
1975};
1976
1977static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001978 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001979 .enable = vlv_dpio_cmn_power_well_enable,
1980 .disable = vlv_dpio_cmn_power_well_disable,
1981 .is_enabled = vlv_power_well_enabled,
1982};
1983
1984static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001985 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001986 .enable = vlv_power_well_enable,
1987 .disable = vlv_power_well_disable,
1988 .is_enabled = vlv_power_well_enabled,
1989};
1990
1991static struct i915_power_well vlv_power_wells[] = {
1992 {
1993 .name = "always-on",
1994 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001995 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001996 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03001997 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001998 },
1999 {
2000 .name = "display",
2001 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002002 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002003 .ops = &vlv_display_power_well_ops,
2004 },
2005 {
2006 .name = "dpio-tx-b-01",
2007 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2008 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2009 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2010 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2011 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002012 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002013 },
2014 {
2015 .name = "dpio-tx-b-23",
2016 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2017 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2018 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2019 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2020 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002021 .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002022 },
2023 {
2024 .name = "dpio-tx-c-01",
2025 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2026 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2027 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2028 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2029 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002030 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002031 },
2032 {
2033 .name = "dpio-tx-c-23",
2034 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2035 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2036 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2037 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2038 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002039 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002040 },
2041 {
2042 .name = "dpio-common",
2043 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002044 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002045 .ops = &vlv_dpio_cmn_power_well_ops,
2046 },
2047};
2048
2049static struct i915_power_well chv_power_wells[] = {
2050 {
2051 .name = "always-on",
2052 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002053 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002054 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002055 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002056 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002057 {
2058 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002059 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002060 * Pipe A power well is the new disp2d well. Pipe B and C
2061 * power wells don't actually exist. Pipe A power well is
2062 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002063 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002064 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002065 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002066 .ops = &chv_pipe_power_well_ops,
2067 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002068 {
2069 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002070 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002071 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002072 .ops = &chv_dpio_cmn_power_well_ops,
2073 },
2074 {
2075 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002076 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002077 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002078 .ops = &chv_dpio_cmn_power_well_ops,
2079 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002080};
2081
Suketu Shah5aefb232015-04-16 14:22:10 +05302082bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002083 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302084{
2085 struct i915_power_well *power_well;
2086 bool ret;
2087
2088 power_well = lookup_power_well(dev_priv, power_well_id);
2089 ret = power_well->ops->is_enabled(dev_priv, power_well);
2090
2091 return ret;
2092}
2093
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002094static struct i915_power_well skl_power_wells[] = {
2095 {
2096 .name = "always-on",
2097 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002098 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002099 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002100 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002101 },
2102 {
2103 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002104 /* Handled by the DMC firmware */
2105 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002106 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002107 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002108 {
2109 .hsw.has_fuses = true,
2110 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002111 },
2112 {
2113 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002114 /* Handled by the DMC firmware */
2115 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002116 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002117 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002118 },
2119 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002120 .name = "DC off",
2121 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2122 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002123 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002124 },
2125 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002126 .name = "power well 2",
2127 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002128 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002129 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002130 {
2131 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2132 .hsw.has_vga = true,
2133 .hsw.has_fuses = true,
2134 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002135 },
2136 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002137 .name = "DDI A/E IO power well",
2138 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002139 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002140 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002141 },
2142 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002143 .name = "DDI B IO power well",
2144 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002145 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002146 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002147 },
2148 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002149 .name = "DDI C IO power well",
2150 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002151 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002152 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002153 },
2154 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002155 .name = "DDI D IO power well",
2156 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002157 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002158 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002159 },
2160};
2161
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302162static struct i915_power_well bxt_power_wells[] = {
2163 {
2164 .name = "always-on",
2165 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002166 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302167 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002168 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302169 },
2170 {
2171 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002172 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002173 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002174 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002175 {
2176 .hsw.has_fuses = true,
2177 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302178 },
2179 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002180 .name = "DC off",
2181 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2182 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002183 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002184 },
2185 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302186 .name = "power well 2",
2187 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002188 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002189 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002190 {
2191 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2192 .hsw.has_vga = true,
2193 .hsw.has_fuses = true,
2194 },
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002195 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002196 {
2197 .name = "dpio-common-a",
2198 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2199 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002200 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002201 {
2202 .bxt.phy = DPIO_PHY1,
2203 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002204 },
2205 {
2206 .name = "dpio-common-bc",
2207 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2208 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002209 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002210 {
2211 .bxt.phy = DPIO_PHY0,
2212 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002213 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302214};
2215
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002216static struct i915_power_well glk_power_wells[] = {
2217 {
2218 .name = "always-on",
2219 .always_on = 1,
2220 .domains = POWER_DOMAIN_MASK,
2221 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002222 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002223 },
2224 {
2225 .name = "power well 1",
2226 /* Handled by the DMC firmware */
2227 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002228 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002229 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002230 {
2231 .hsw.has_fuses = true,
2232 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002233 },
2234 {
2235 .name = "DC off",
2236 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2237 .ops = &gen9_dc_off_power_well_ops,
2238 .id = SKL_DISP_PW_DC_OFF,
2239 },
2240 {
2241 .name = "power well 2",
2242 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002243 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002244 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002245 {
2246 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2247 .hsw.has_vga = true,
2248 .hsw.has_fuses = true,
2249 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002250 },
2251 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002252 .name = "dpio-common-a",
2253 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2254 .ops = &bxt_dpio_cmn_power_well_ops,
2255 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002256 {
2257 .bxt.phy = DPIO_PHY1,
2258 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002259 },
2260 {
2261 .name = "dpio-common-b",
2262 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2263 .ops = &bxt_dpio_cmn_power_well_ops,
2264 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002265 {
2266 .bxt.phy = DPIO_PHY0,
2267 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002268 },
2269 {
2270 .name = "dpio-common-c",
2271 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2272 .ops = &bxt_dpio_cmn_power_well_ops,
2273 .id = GLK_DPIO_CMN_C,
Imre Deak0a445942017-08-14 18:15:29 +03002274 {
2275 .bxt.phy = DPIO_PHY2,
2276 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002277 },
2278 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002279 .name = "AUX A",
2280 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002281 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002282 .id = GLK_DISP_PW_AUX_A,
2283 },
2284 {
2285 .name = "AUX B",
2286 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002287 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002288 .id = GLK_DISP_PW_AUX_B,
2289 },
2290 {
2291 .name = "AUX C",
2292 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002293 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002294 .id = GLK_DISP_PW_AUX_C,
2295 },
2296 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002297 .name = "DDI A IO power well",
2298 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002299 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002300 .id = GLK_DISP_PW_DDI_A,
2301 },
2302 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002303 .name = "DDI B IO power well",
2304 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002305 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002306 .id = SKL_DISP_PW_DDI_B,
2307 },
2308 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002309 .name = "DDI C IO power well",
2310 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002311 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002312 .id = SKL_DISP_PW_DDI_C,
2313 },
2314};
2315
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002316static struct i915_power_well cnl_power_wells[] = {
2317 {
2318 .name = "always-on",
2319 .always_on = 1,
2320 .domains = POWER_DOMAIN_MASK,
2321 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002322 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002323 },
2324 {
2325 .name = "power well 1",
2326 /* Handled by the DMC firmware */
2327 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002328 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002329 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002330 {
2331 .hsw.has_fuses = true,
2332 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002333 },
2334 {
2335 .name = "AUX A",
2336 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002337 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002338 .id = CNL_DISP_PW_AUX_A,
2339 },
2340 {
2341 .name = "AUX B",
2342 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002343 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002344 .id = CNL_DISP_PW_AUX_B,
2345 },
2346 {
2347 .name = "AUX C",
2348 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002349 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002350 .id = CNL_DISP_PW_AUX_C,
2351 },
2352 {
2353 .name = "AUX D",
2354 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002355 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002356 .id = CNL_DISP_PW_AUX_D,
2357 },
2358 {
2359 .name = "DC off",
2360 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2361 .ops = &gen9_dc_off_power_well_ops,
2362 .id = SKL_DISP_PW_DC_OFF,
2363 },
2364 {
2365 .name = "power well 2",
2366 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002367 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002368 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002369 {
2370 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2371 .hsw.has_vga = true,
2372 .hsw.has_fuses = true,
2373 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002374 },
2375 {
2376 .name = "DDI A IO power well",
2377 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002378 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002379 .id = CNL_DISP_PW_DDI_A,
2380 },
2381 {
2382 .name = "DDI B IO power well",
2383 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002384 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002385 .id = SKL_DISP_PW_DDI_B,
2386 },
2387 {
2388 .name = "DDI C IO power well",
2389 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002390 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002391 .id = SKL_DISP_PW_DDI_C,
2392 },
2393 {
2394 .name = "DDI D IO power well",
2395 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002396 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002397 .id = SKL_DISP_PW_DDI_D,
2398 },
2399};
2400
Imre Deak1b0e3a02015-11-05 23:04:11 +02002401static int
2402sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2403 int disable_power_well)
2404{
2405 if (disable_power_well >= 0)
2406 return !!disable_power_well;
2407
Imre Deak1b0e3a02015-11-05 23:04:11 +02002408 return 1;
2409}
2410
Imre Deaka37baf32016-02-29 22:49:03 +02002411static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2412 int enable_dc)
2413{
2414 uint32_t mask;
2415 int requested_dc;
2416 int max_dc;
2417
Rodrigo Vivi6d6a8972017-07-06 13:45:08 -07002418 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002419 max_dc = 2;
2420 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002421 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002422 max_dc = 1;
2423 /*
2424 * DC9 has a separate HW flow from the rest of the DC states,
2425 * not depending on the DMC firmware. It's needed by system
2426 * suspend/resume, so allow it unconditionally.
2427 */
2428 mask = DC_STATE_EN_DC9;
2429 } else {
2430 max_dc = 0;
2431 mask = 0;
2432 }
2433
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002434 if (!i915_modparams.disable_power_well)
Imre Deak66e2c4c2016-02-29 22:49:04 +02002435 max_dc = 0;
2436
Imre Deaka37baf32016-02-29 22:49:03 +02002437 if (enable_dc >= 0 && enable_dc <= max_dc) {
2438 requested_dc = enable_dc;
2439 } else if (enable_dc == -1) {
2440 requested_dc = max_dc;
2441 } else if (enable_dc > max_dc && enable_dc <= 2) {
2442 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2443 enable_dc, max_dc);
2444 requested_dc = max_dc;
2445 } else {
2446 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2447 requested_dc = max_dc;
2448 }
2449
2450 if (requested_dc > 1)
2451 mask |= DC_STATE_EN_UPTO_DC6;
2452 if (requested_dc > 0)
2453 mask |= DC_STATE_EN_UPTO_DC5;
2454
2455 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2456
2457 return mask;
2458}
2459
Imre Deak21792c62017-07-11 23:42:33 +03002460static void assert_power_well_ids_unique(struct drm_i915_private *dev_priv)
2461{
2462 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2463 u64 power_well_ids;
2464 int i;
2465
2466 power_well_ids = 0;
2467 for (i = 0; i < power_domains->power_well_count; i++) {
2468 enum i915_power_well_id id = power_domains->power_wells[i].id;
2469
2470 WARN_ON(id >= sizeof(power_well_ids) * 8);
2471 WARN_ON(power_well_ids & BIT_ULL(id));
2472 power_well_ids |= BIT_ULL(id);
2473 }
2474}
2475
Daniel Vetter9c065a72014-09-30 10:56:38 +02002476#define set_power_wells(power_domains, __power_wells) ({ \
2477 (power_domains)->power_wells = (__power_wells); \
2478 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2479})
2480
Daniel Vettere4e76842014-09-30 10:56:42 +02002481/**
2482 * intel_power_domains_init - initializes the power domain structures
2483 * @dev_priv: i915 device instance
2484 *
2485 * Initializes the power domain structures for @dev_priv depending upon the
2486 * supported platform.
2487 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002488int intel_power_domains_init(struct drm_i915_private *dev_priv)
2489{
2490 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2491
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002492 i915_modparams.disable_power_well =
2493 sanitize_disable_power_well_option(dev_priv,
2494 i915_modparams.disable_power_well);
2495 dev_priv->csr.allowed_dc_mask =
2496 get_allowed_dc_mask(dev_priv, i915_modparams.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002497
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002498 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002499
Daniel Vetter9c065a72014-09-30 10:56:38 +02002500 mutex_init(&power_domains->lock);
2501
2502 /*
2503 * The enabling order will be from lower to higher indexed wells,
2504 * the disabling order is reversed.
2505 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002506 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002507 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002508 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002509 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002510 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002511 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002512 } else if (IS_CANNONLAKE(dev_priv)) {
2513 set_power_wells(power_domains, cnl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002514 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302515 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002516 } else if (IS_GEMINILAKE(dev_priv)) {
2517 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002518 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002519 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002520 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002521 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002522 } else if (IS_I830(dev_priv)) {
2523 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002524 } else {
2525 set_power_wells(power_domains, i9xx_always_on_power_well);
2526 }
2527
Imre Deak21792c62017-07-11 23:42:33 +03002528 assert_power_well_ids_unique(dev_priv);
2529
Daniel Vetter9c065a72014-09-30 10:56:38 +02002530 return 0;
2531}
2532
Daniel Vettere4e76842014-09-30 10:56:42 +02002533/**
2534 * intel_power_domains_fini - finalizes the power domain structures
2535 * @dev_priv: i915 device instance
2536 *
2537 * Finalizes the power domain structures for @dev_priv depending upon the
2538 * supported platform. This function also disables runtime pm and ensures that
2539 * the device stays powered up so that the driver can be reloaded.
2540 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002541void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002542{
David Weinehallc49d13e2016-08-22 13:32:42 +03002543 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002544
Imre Deakaabee1b2015-12-15 20:10:29 +02002545 /*
2546 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002547 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002548 * we're going to unload/reload.
2549 * The following also reacquires the RPM reference the core passed
2550 * to the driver during loading, which is dropped in
2551 * intel_runtime_pm_enable(). We have to hand back the control of the
2552 * device to the core with this reference held.
2553 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002554 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002555
2556 /* Remove the refcount we took to keep power well support disabled. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002557 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02002558 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002559
2560 /*
2561 * Remove the refcount we took in intel_runtime_pm_enable() in case
2562 * the platform doesn't support runtime PM.
2563 */
2564 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002565 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002566}
2567
Imre Deak30eade12015-11-04 19:24:13 +02002568static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002569{
2570 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2571 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002572
2573 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002574 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002575 power_well->ops->sync_hw(dev_priv, power_well);
2576 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2577 power_well);
2578 }
2579 mutex_unlock(&power_domains->lock);
2580}
2581
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002582static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2583{
2584 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2585 POSTING_READ(DBUF_CTL);
2586
2587 udelay(10);
2588
2589 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2590 DRM_ERROR("DBuf power enable timeout\n");
2591}
2592
2593static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2594{
2595 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2596 POSTING_READ(DBUF_CTL);
2597
2598 udelay(10);
2599
2600 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2601 DRM_ERROR("DBuf power disable timeout!\n");
2602}
2603
Imre Deak73dfc222015-11-17 17:33:53 +02002604static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002605 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002606{
2607 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002608 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002609 uint32_t val;
2610
Imre Deakd26fa1d2015-11-04 19:24:17 +02002611 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2612
Imre Deak73dfc222015-11-17 17:33:53 +02002613 /* enable PCH reset handshake */
2614 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2615 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2616
2617 /* enable PG1 and Misc I/O */
2618 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002619
2620 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2621 intel_power_well_enable(dev_priv, well);
2622
2623 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2624 intel_power_well_enable(dev_priv, well);
2625
Imre Deak73dfc222015-11-17 17:33:53 +02002626 mutex_unlock(&power_domains->lock);
2627
Imre Deak73dfc222015-11-17 17:33:53 +02002628 skl_init_cdclk(dev_priv);
2629
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002630 gen9_dbuf_enable(dev_priv);
2631
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002632 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002633 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002634}
2635
2636static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2637{
2638 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002639 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002640
Imre Deakd26fa1d2015-11-04 19:24:17 +02002641 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2642
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002643 gen9_dbuf_disable(dev_priv);
2644
Imre Deak73dfc222015-11-17 17:33:53 +02002645 skl_uninit_cdclk(dev_priv);
2646
2647 /* The spec doesn't call for removing the reset handshake flag */
2648 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002649
Imre Deak73dfc222015-11-17 17:33:53 +02002650 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002651
Imre Deakedfda8e2017-06-29 18:36:59 +03002652 /*
2653 * BSpec says to keep the MISC IO power well enabled here, only
2654 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03002655 * Note that even though the driver's request is removed power well 1
2656 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03002657 */
Imre Deak443a93a2016-04-04 15:42:57 +03002658 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2659 intel_power_well_disable(dev_priv, well);
2660
Imre Deak73dfc222015-11-17 17:33:53 +02002661 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002662
2663 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02002664}
2665
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002666void bxt_display_core_init(struct drm_i915_private *dev_priv,
2667 bool resume)
2668{
2669 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2670 struct i915_power_well *well;
2671 uint32_t val;
2672
2673 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2674
2675 /*
2676 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2677 * or else the reset will hang because there is no PCH to respond.
2678 * Move the handshake programming to initialization sequence.
2679 * Previously was left up to BIOS.
2680 */
2681 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2682 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2683 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2684
2685 /* Enable PG1 */
2686 mutex_lock(&power_domains->lock);
2687
2688 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2689 intel_power_well_enable(dev_priv, well);
2690
2691 mutex_unlock(&power_domains->lock);
2692
Imre Deak324513c2016-06-13 16:44:36 +03002693 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002694
2695 gen9_dbuf_enable(dev_priv);
2696
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002697 if (resume && dev_priv->csr.dmc_payload)
2698 intel_csr_load_program(dev_priv);
2699}
2700
2701void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2702{
2703 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2704 struct i915_power_well *well;
2705
2706 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2707
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002708 gen9_dbuf_disable(dev_priv);
2709
Imre Deak324513c2016-06-13 16:44:36 +03002710 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002711
2712 /* The spec doesn't call for removing the reset handshake flag */
2713
Imre Deak42d93662017-06-29 18:37:01 +03002714 /*
2715 * Disable PW1 (PG1).
2716 * Note that even though the driver's request is removed power well 1
2717 * may stay enabled after this due to DMC's own request on it.
2718 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002719 mutex_lock(&power_domains->lock);
2720
2721 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2722 intel_power_well_disable(dev_priv, well);
2723
2724 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002725
2726 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002727}
2728
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002729enum {
2730 PROCMON_0_85V_DOT_0,
2731 PROCMON_0_95V_DOT_0,
2732 PROCMON_0_95V_DOT_1,
2733 PROCMON_1_05V_DOT_0,
2734 PROCMON_1_05V_DOT_1,
2735};
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002736
2737static const struct cnl_procmon {
2738 u32 dw1, dw9, dw10;
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002739} cnl_procmon_values[] = {
2740 [PROCMON_0_85V_DOT_0] =
2741 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
2742 [PROCMON_0_95V_DOT_0] =
2743 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
2744 [PROCMON_0_95V_DOT_1] =
2745 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
2746 [PROCMON_1_05V_DOT_0] =
2747 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
2748 [PROCMON_1_05V_DOT_1] =
2749 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002750};
2751
Paulo Zanoniade5ee72017-08-21 17:03:56 -07002752static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv)
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002753{
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002754 const struct cnl_procmon *procmon;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002755 u32 val;
2756
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002757 val = I915_READ(CNL_PORT_COMP_DW3);
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002758 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
2759 default:
2760 MISSING_CASE(val);
2761 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
2762 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
2763 break;
2764 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
2765 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
2766 break;
2767 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
2768 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
2769 break;
2770 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
2771 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
2772 break;
2773 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
2774 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
2775 break;
2776 }
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002777
2778 val = I915_READ(CNL_PORT_COMP_DW1);
2779 val &= ~((0xff << 16) | 0xff);
2780 val |= procmon->dw1;
2781 I915_WRITE(CNL_PORT_COMP_DW1, val);
2782
2783 I915_WRITE(CNL_PORT_COMP_DW9, procmon->dw9);
2784 I915_WRITE(CNL_PORT_COMP_DW10, procmon->dw10);
Paulo Zanoniade5ee72017-08-21 17:03:56 -07002785}
2786
2787static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
2788{
2789 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2790 struct i915_power_well *well;
2791 u32 val;
2792
2793 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2794
2795 /* 1. Enable PCH Reset Handshake */
2796 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2797 val |= RESET_PCH_HANDSHAKE_ENABLE;
2798 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2799
2800 /* 2. Enable Comp */
2801 val = I915_READ(CHICKEN_MISC_2);
2802 val &= ~CNL_COMP_PWR_DOWN;
2803 I915_WRITE(CHICKEN_MISC_2, val);
2804
2805 cnl_set_procmon_ref_values(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002806
2807 val = I915_READ(CNL_PORT_COMP_DW0);
2808 val |= COMP_INIT;
2809 I915_WRITE(CNL_PORT_COMP_DW0, val);
2810
2811 /* 3. */
2812 val = I915_READ(CNL_PORT_CL1CM_DW5);
2813 val |= CL_POWER_DOWN_ENABLE;
2814 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2815
Imre Deakb38131f2017-06-29 18:37:02 +03002816 /*
2817 * 4. Enable Power Well 1 (PG1).
2818 * The AUX IO power wells will be enabled on demand.
2819 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002820 mutex_lock(&power_domains->lock);
2821 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2822 intel_power_well_enable(dev_priv, well);
2823 mutex_unlock(&power_domains->lock);
2824
2825 /* 5. Enable CD clock */
2826 cnl_init_cdclk(dev_priv);
2827
2828 /* 6. Enable DBUF */
2829 gen9_dbuf_enable(dev_priv);
Imre Deak57522c42017-10-03 12:51:58 +03002830
2831 if (resume && dev_priv->csr.dmc_payload)
2832 intel_csr_load_program(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002833}
2834
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002835static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
2836{
2837 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2838 struct i915_power_well *well;
2839 u32 val;
2840
2841 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2842
2843 /* 1. Disable all display engine functions -> aready done */
2844
2845 /* 2. Disable DBUF */
2846 gen9_dbuf_disable(dev_priv);
2847
2848 /* 3. Disable CD clock */
2849 cnl_uninit_cdclk(dev_priv);
2850
Imre Deakb38131f2017-06-29 18:37:02 +03002851 /*
2852 * 4. Disable Power Well 1 (PG1).
2853 * The AUX IO power wells are toggled on demand, so they are already
2854 * disabled at this point.
2855 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002856 mutex_lock(&power_domains->lock);
2857 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2858 intel_power_well_disable(dev_priv, well);
2859 mutex_unlock(&power_domains->lock);
2860
Imre Deak846c6b22017-06-29 18:36:58 +03002861 usleep_range(10, 30); /* 10 us delay per Bspec */
2862
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002863 /* 5. Disable Comp */
2864 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03002865 val |= CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002866 I915_WRITE(CHICKEN_MISC_2, val);
2867}
2868
Ville Syrjälä70722462015-04-10 18:21:28 +03002869static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2870{
2871 struct i915_power_well *cmn_bc =
2872 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2873 struct i915_power_well *cmn_d =
2874 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2875
2876 /*
2877 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2878 * workaround never ever read DISPLAY_PHY_CONTROL, and
2879 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002880 * power well state and lane status to reconstruct the
2881 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002882 */
2883 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002884 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2885 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002886 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2887 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2888 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2889
2890 /*
2891 * If all lanes are disabled we leave the override disabled
2892 * with all power down bits cleared to match the state we
2893 * would use after disabling the port. Otherwise enable the
2894 * override and set the lane powerdown bits accding to the
2895 * current lane status.
2896 */
2897 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2898 uint32_t status = I915_READ(DPLL(PIPE_A));
2899 unsigned int mask;
2900
2901 mask = status & DPLL_PORTB_READY_MASK;
2902 if (mask == 0xf)
2903 mask = 0x0;
2904 else
2905 dev_priv->chv_phy_control |=
2906 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2907
2908 dev_priv->chv_phy_control |=
2909 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2910
2911 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2912 if (mask == 0xf)
2913 mask = 0x0;
2914 else
2915 dev_priv->chv_phy_control |=
2916 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2917
2918 dev_priv->chv_phy_control |=
2919 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2920
Ville Syrjälä70722462015-04-10 18:21:28 +03002921 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002922
2923 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2924 } else {
2925 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002926 }
2927
2928 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2929 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2930 unsigned int mask;
2931
2932 mask = status & DPLL_PORTD_READY_MASK;
2933
2934 if (mask == 0xf)
2935 mask = 0x0;
2936 else
2937 dev_priv->chv_phy_control |=
2938 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2939
2940 dev_priv->chv_phy_control |=
2941 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2942
Ville Syrjälä70722462015-04-10 18:21:28 +03002943 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002944
2945 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2946 } else {
2947 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002948 }
2949
2950 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2951
2952 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2953 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002954}
2955
Daniel Vetter9c065a72014-09-30 10:56:38 +02002956static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2957{
2958 struct i915_power_well *cmn =
2959 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2960 struct i915_power_well *disp2d =
2961 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2962
Daniel Vetter9c065a72014-09-30 10:56:38 +02002963 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03002964 if (cmn->ops->is_enabled(dev_priv, cmn) &&
2965 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02002966 I915_READ(DPIO_CTL) & DPIO_CMNRST)
2967 return;
2968
2969 DRM_DEBUG_KMS("toggling display PHY side reset\n");
2970
2971 /* cmnlane needs DPLL registers */
2972 disp2d->ops->enable(dev_priv, disp2d);
2973
2974 /*
2975 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2976 * Need to assert and de-assert PHY SB reset by gating the
2977 * common lane power, then un-gating it.
2978 * Simply ungating isn't enough to reset the PHY enough to get
2979 * ports and lanes running.
2980 */
2981 cmn->ops->disable(dev_priv, cmn);
2982}
2983
Daniel Vettere4e76842014-09-30 10:56:42 +02002984/**
2985 * intel_power_domains_init_hw - initialize hardware power domain state
2986 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002987 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02002988 *
2989 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02002990 * power wells belonging to the INIT power domain. Power wells in other
2991 * domains (and not in the INIT domain) are referenced or disabled during the
2992 * modeset state HW readout. After that the reference count of each power well
2993 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02002994 */
Imre Deak73dfc222015-11-17 17:33:53 +02002995void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002996{
Daniel Vetter9c065a72014-09-30 10:56:38 +02002997 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2998
2999 power_domains->initializing = true;
3000
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003001 if (IS_CANNONLAKE(dev_priv)) {
3002 cnl_display_core_init(dev_priv, resume);
3003 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003004 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003005 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003006 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003007 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003008 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003009 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003010 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003011 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003012 mutex_lock(&power_domains->lock);
3013 vlv_cmnlane_wa(dev_priv);
3014 mutex_unlock(&power_domains->lock);
3015 }
3016
3017 /* For now, we need the power well to be always enabled. */
3018 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003019 /* Disable power support if the user asked so. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003020 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003021 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003022 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003023 power_domains->initializing = false;
3024}
3025
Daniel Vettere4e76842014-09-30 10:56:42 +02003026/**
Imre Deak73dfc222015-11-17 17:33:53 +02003027 * intel_power_domains_suspend - suspend power domain state
3028 * @dev_priv: i915 device instance
3029 *
3030 * This function prepares the hardware power domain state before entering
3031 * system suspend. It must be paired with intel_power_domains_init_hw().
3032 */
3033void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3034{
Imre Deakd314cd42015-11-17 17:44:23 +02003035 /*
3036 * Even if power well support was disabled we still want to disable
3037 * power wells while we are system suspended.
3038 */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003039 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003040 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003041
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003042 if (IS_CANNONLAKE(dev_priv))
3043 cnl_display_core_uninit(dev_priv);
3044 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003045 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003046 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003047 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003048}
3049
Imre Deak8d8c3862017-02-17 17:39:46 +02003050static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3051{
3052 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3053 struct i915_power_well *power_well;
3054
3055 for_each_power_well(dev_priv, power_well) {
3056 enum intel_display_power_domain domain;
3057
3058 DRM_DEBUG_DRIVER("%-25s %d\n",
3059 power_well->name, power_well->count);
3060
3061 for_each_power_domain(domain, power_well->domains)
3062 DRM_DEBUG_DRIVER(" %-23s %d\n",
3063 intel_display_power_domain_str(domain),
3064 power_domains->domain_use_count[domain]);
3065 }
3066}
3067
3068/**
3069 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3070 * @dev_priv: i915 device instance
3071 *
3072 * Verify if the reference count of each power well matches its HW enabled
3073 * state and the total refcount of the domains it belongs to. This must be
3074 * called after modeset HW state sanitization, which is responsible for
3075 * acquiring reference counts for any power wells in use and disabling the
3076 * ones left on by BIOS but not required by any active output.
3077 */
3078void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3079{
3080 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3081 struct i915_power_well *power_well;
3082 bool dump_domain_info;
3083
3084 mutex_lock(&power_domains->lock);
3085
3086 dump_domain_info = false;
3087 for_each_power_well(dev_priv, power_well) {
3088 enum intel_display_power_domain domain;
3089 int domains_count;
3090 bool enabled;
3091
3092 /*
3093 * Power wells not belonging to any domain (like the MISC_IO
3094 * and PW1 power wells) are under FW control, so ignore them,
3095 * since their state can change asynchronously.
3096 */
3097 if (!power_well->domains)
3098 continue;
3099
3100 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3101 if ((power_well->count || power_well->always_on) != enabled)
3102 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3103 power_well->name, power_well->count, enabled);
3104
3105 domains_count = 0;
3106 for_each_power_domain(domain, power_well->domains)
3107 domains_count += power_domains->domain_use_count[domain];
3108
3109 if (power_well->count != domains_count) {
3110 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3111 "(refcount %d/domains refcount %d)\n",
3112 power_well->name, power_well->count,
3113 domains_count);
3114 dump_domain_info = true;
3115 }
3116 }
3117
3118 if (dump_domain_info) {
3119 static bool dumped;
3120
3121 if (!dumped) {
3122 intel_power_domains_dump_info(dev_priv);
3123 dumped = true;
3124 }
3125 }
3126
3127 mutex_unlock(&power_domains->lock);
3128}
3129
Imre Deak73dfc222015-11-17 17:33:53 +02003130/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003131 * intel_runtime_pm_get - grab a runtime pm reference
3132 * @dev_priv: i915 device instance
3133 *
3134 * This function grabs a device-level runtime pm reference (mostly used for GEM
3135 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3136 *
3137 * Any runtime pm reference obtained by this function must have a symmetric
3138 * call to intel_runtime_pm_put() to release the reference again.
3139 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003140void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3141{
David Weinehall52a05c32016-08-22 13:32:44 +03003142 struct pci_dev *pdev = dev_priv->drm.pdev;
3143 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003144 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003145
Imre Deakf5073822017-03-28 12:38:55 +03003146 ret = pm_runtime_get_sync(kdev);
3147 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003148
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003149 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003150 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003151}
3152
Daniel Vettere4e76842014-09-30 10:56:42 +02003153/**
Imre Deak09731282016-02-17 14:17:42 +02003154 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3155 * @dev_priv: i915 device instance
3156 *
3157 * This function grabs a device-level runtime pm reference if the device is
3158 * already in use and ensures that it is powered up.
3159 *
3160 * Any runtime pm reference obtained by this function must have a symmetric
3161 * call to intel_runtime_pm_put() to release the reference again.
3162 */
3163bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3164{
David Weinehall52a05c32016-08-22 13:32:44 +03003165 struct pci_dev *pdev = dev_priv->drm.pdev;
3166 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003167
Chris Wilson135dc792016-02-25 21:10:28 +00003168 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03003169 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02003170
Chris Wilson135dc792016-02-25 21:10:28 +00003171 /*
3172 * In cases runtime PM is disabled by the RPM core and we get
3173 * an -EINVAL return value we are not supposed to call this
3174 * function, since the power state is undefined. This applies
3175 * atm to the late/early system suspend/resume handlers.
3176 */
Imre Deakf5073822017-03-28 12:38:55 +03003177 WARN_ONCE(ret < 0,
3178 "pm_runtime_get_if_in_use() failed: %d\n", ret);
Chris Wilson135dc792016-02-25 21:10:28 +00003179 if (ret <= 0)
3180 return false;
3181 }
Imre Deak09731282016-02-17 14:17:42 +02003182
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003183 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deak09731282016-02-17 14:17:42 +02003184 assert_rpm_wakelock_held(dev_priv);
3185
3186 return true;
3187}
3188
3189/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003190 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3191 * @dev_priv: i915 device instance
3192 *
3193 * This function grabs a device-level runtime pm reference (mostly used for GEM
3194 * code to ensure the GTT or GT is on).
3195 *
3196 * It will _not_ power up the device but instead only check that it's powered
3197 * on. Therefore it is only valid to call this functions from contexts where
3198 * the device is known to be powered up and where trying to power it up would
3199 * result in hilarity and deadlocks. That pretty much means only the system
3200 * suspend/resume code where this is used to grab runtime pm references for
3201 * delayed setup down in work items.
3202 *
3203 * Any runtime pm reference obtained by this function must have a symmetric
3204 * call to intel_runtime_pm_put() to release the reference again.
3205 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003206void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3207{
David Weinehall52a05c32016-08-22 13:32:44 +03003208 struct pci_dev *pdev = dev_priv->drm.pdev;
3209 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003210
Imre Deakc9b88462015-12-15 20:10:34 +02003211 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003212 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003213
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003214 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003215}
3216
Daniel Vettere4e76842014-09-30 10:56:42 +02003217/**
3218 * intel_runtime_pm_put - release a runtime pm reference
3219 * @dev_priv: i915 device instance
3220 *
3221 * This function drops the device-level runtime pm reference obtained by
3222 * intel_runtime_pm_get() and might power down the corresponding
3223 * hardware block right away if this is the last reference.
3224 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003225void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3226{
David Weinehall52a05c32016-08-22 13:32:44 +03003227 struct pci_dev *pdev = dev_priv->drm.pdev;
3228 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003229
Imre Deak542db3c2015-12-15 20:10:36 +02003230 assert_rpm_wakelock_held(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003231 atomic_dec(&dev_priv->runtime_pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003232
David Weinehallc49d13e2016-08-22 13:32:42 +03003233 pm_runtime_mark_last_busy(kdev);
3234 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003235}
3236
Daniel Vettere4e76842014-09-30 10:56:42 +02003237/**
3238 * intel_runtime_pm_enable - enable runtime pm
3239 * @dev_priv: i915 device instance
3240 *
3241 * This function enables runtime pm at the end of the driver load sequence.
3242 *
3243 * Note that this function does currently not enable runtime pm for the
3244 * subordinate display power domains. That is only done on the first modeset
3245 * using intel_display_set_init_power().
3246 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003247void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003248{
David Weinehall52a05c32016-08-22 13:32:44 +03003249 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003250 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003251
David Weinehallc49d13e2016-08-22 13:32:42 +03003252 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3253 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003254
Imre Deak25b181b2015-12-17 13:44:56 +02003255 /*
3256 * Take a permanent reference to disable the RPM functionality and drop
3257 * it only when unloading the driver. Use the low level get/put helpers,
3258 * so the driver's own RPM reference tracking asserts also work on
3259 * platforms without RPM support.
3260 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003261 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003262 int ret;
3263
David Weinehallc49d13e2016-08-22 13:32:42 +03003264 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003265 ret = pm_runtime_get_sync(kdev);
3266 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003267 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003268 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003269 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003270
Imre Deakaabee1b2015-12-15 20:10:29 +02003271 /*
3272 * The core calls the driver load handler with an RPM reference held.
3273 * We drop that here and will reacquire it during unloading in
3274 * intel_power_domains_fini().
3275 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003276 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003277}