blob: 5b1aa4b9c72c61ab860fba22554392c69ab33d6e [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
Lucas De Marchiddd39e42017-11-28 14:05:53 -0800393 /* Display WA #1178: cnl */
394 if (IS_CANNONLAKE(dev_priv) &&
395 (id == CNL_DISP_PW_AUX_B || id == CNL_DISP_PW_AUX_C ||
396 id == CNL_DISP_PW_AUX_D)) {
397 val = I915_READ(CNL_AUX_ANAOVRD1(id));
398 val |= CNL_AUX_ANAOVRD1_ENABLE | CNL_AUX_ANAOVRD1_LDO_BYPASS;
399 I915_WRITE(CNL_AUX_ANAOVRD1(id), val);
400 }
401
Imre Deakb2891eb2017-07-11 23:42:35 +0300402 if (wait_fuses)
403 gen9_wait_for_power_well_fuses(dev_priv, pg);
404
Imre Deak001bd2c2017-07-12 18:54:13 +0300405 hsw_power_well_post_enable(dev_priv, power_well->hsw.irq_pipe_mask,
406 power_well->hsw.has_vga);
Imre Deakec46d482017-07-06 17:40:33 +0300407}
Daniel Vetter9c065a72014-09-30 10:56:38 +0200408
Imre Deakec46d482017-07-06 17:40:33 +0300409static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
410 struct i915_power_well *power_well)
411{
Imre Deak1af474f2017-07-06 17:40:34 +0300412 enum i915_power_well_id id = power_well->id;
413 u32 val;
414
Imre Deak001bd2c2017-07-12 18:54:13 +0300415 hsw_power_well_pre_disable(dev_priv, power_well->hsw.irq_pipe_mask);
416
Imre Deak9c3a16c2017-08-14 18:15:30 +0300417 val = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
418 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id),
419 val & ~HSW_PWR_WELL_CTL_REQ(id));
Imre Deak76347c02017-07-06 17:40:36 +0300420 hsw_wait_for_power_well_disable(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200421}
422
Imre Deakd42539b2017-07-06 17:40:39 +0300423/*
424 * We should only use the power well if we explicitly asked the hardware to
425 * enable it, so check if it's enabled and also check if we've requested it to
426 * be enabled.
427 */
428static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
429 struct i915_power_well *power_well)
430{
431 enum i915_power_well_id id = power_well->id;
432 u32 mask = HSW_PWR_WELL_CTL_REQ(id) | HSW_PWR_WELL_CTL_STATE(id);
433
Imre Deak9c3a16c2017-08-14 18:15:30 +0300434 return (I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) & mask) == mask;
Imre Deakd42539b2017-07-06 17:40:39 +0300435}
436
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530437static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
438{
Imre Deak9c3a16c2017-08-14 18:15:30 +0300439 enum i915_power_well_id id = SKL_DISP_PW_2;
440
Imre Deakbfcdabe2016-04-01 16:02:37 +0300441 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
442 "DC9 already programmed to be enabled.\n");
443 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
444 "DC5 still not disabled to enable DC9.\n");
Imre Deak9c3a16c2017-08-14 18:15:30 +0300445 WARN_ONCE(I915_READ(HSW_PWR_WELL_CTL_DRIVER(id)) &
446 HSW_PWR_WELL_CTL_REQ(id),
Imre Deake8a3a2a2017-06-29 18:37:00 +0300447 "Power well 2 on.\n");
Imre Deakbfcdabe2016-04-01 16:02:37 +0300448 WARN_ONCE(intel_irqs_enabled(dev_priv),
449 "Interrupts not disabled yet.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530450
451 /*
452 * TODO: check for the following to verify the conditions to enter DC9
453 * state are satisfied:
454 * 1] Check relevant display engine registers to verify if mode set
455 * disable sequence was followed.
456 * 2] Check if display uninitialize sequence is initialized.
457 */
458}
459
460static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
461{
Imre Deakbfcdabe2016-04-01 16:02:37 +0300462 WARN_ONCE(intel_irqs_enabled(dev_priv),
463 "Interrupts not disabled yet.\n");
464 WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
465 "DC5 still not disabled.\n");
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530466
467 /*
468 * TODO: check for the following to verify DC9 state was indeed
469 * entered before programming to disable it:
470 * 1] Check relevant display engine registers to verify if mode
471 * set disable sequence was followed.
472 * 2] Check if display uninitialize sequence is initialized.
473 */
474}
475
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200476static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
477 u32 state)
478{
479 int rewrites = 0;
480 int rereads = 0;
481 u32 v;
482
483 I915_WRITE(DC_STATE_EN, state);
484
485 /* It has been observed that disabling the dc6 state sometimes
486 * doesn't stick and dmc keeps returning old value. Make sure
487 * the write really sticks enough times and also force rewrite until
488 * we are confident that state is exactly what we want.
489 */
490 do {
491 v = I915_READ(DC_STATE_EN);
492
493 if (v != state) {
494 I915_WRITE(DC_STATE_EN, state);
495 rewrites++;
496 rereads = 0;
497 } else if (rereads++ > 5) {
498 break;
499 }
500
501 } while (rewrites < 100);
502
503 if (v != state)
504 DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
505 state, v);
506
507 /* Most of the times we need one retry, avoid spam */
508 if (rewrites > 1)
509 DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
510 state, rewrites);
511}
512
Imre Deakda2f41d2016-04-20 20:27:56 +0300513static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530514{
Imre Deakda2f41d2016-04-20 20:27:56 +0300515 u32 mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530516
Imre Deak13ae3a02015-11-04 19:24:16 +0200517 mask = DC_STATE_EN_UPTO_DC5;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200518 if (IS_GEN9_LP(dev_priv))
Imre Deak13ae3a02015-11-04 19:24:16 +0200519 mask |= DC_STATE_EN_DC9;
520 else
521 mask |= DC_STATE_EN_UPTO_DC6;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530522
Imre Deakda2f41d2016-04-20 20:27:56 +0300523 return mask;
524}
525
526void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
527{
528 u32 val;
529
530 val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
531
532 DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
533 dev_priv->csr.dc_state, val);
534 dev_priv->csr.dc_state = val;
535}
536
537static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
538{
539 uint32_t val;
540 uint32_t mask;
541
Imre Deaka37baf32016-02-29 22:49:03 +0200542 if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
543 state &= dev_priv->csr.allowed_dc_mask;
Patrik Jakobsson443646c2015-11-16 15:01:06 +0100544
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530545 val = I915_READ(DC_STATE_EN);
Imre Deakda2f41d2016-04-20 20:27:56 +0300546 mask = gen9_dc_mask(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200547 DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
548 val & mask, state);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200549
550 /* Check if DMC is ignoring our DC state requests */
551 if ((val & mask) != dev_priv->csr.dc_state)
552 DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
553 dev_priv->csr.dc_state, val & mask);
554
Imre Deak13ae3a02015-11-04 19:24:16 +0200555 val &= ~mask;
556 val |= state;
Mika Kuoppala779cb5d2016-02-18 17:58:09 +0200557
558 gen9_write_dc_state(dev_priv, val);
Patrik Jakobsson832dba82016-02-18 17:21:11 +0200559
560 dev_priv->csr.dc_state = val & mask;
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530561}
562
Imre Deak13ae3a02015-11-04 19:24:16 +0200563void bxt_enable_dc9(struct drm_i915_private *dev_priv)
564{
565 assert_can_enable_dc9(dev_priv);
566
567 DRM_DEBUG_KMS("Enabling DC9\n");
568
Imre Deak78597992016-06-16 16:37:20 +0300569 intel_power_sequencer_reset(dev_priv);
Imre Deak13ae3a02015-11-04 19:24:16 +0200570 gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
571}
572
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530573void bxt_disable_dc9(struct drm_i915_private *dev_priv)
574{
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530575 assert_can_disable_dc9(dev_priv);
576
577 DRM_DEBUG_KMS("Disabling DC9\n");
578
Imre Deak13ae3a02015-11-04 19:24:16 +0200579 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deak8090ba82016-08-10 14:07:33 +0300580
581 intel_pps_unlock_regs_wa(dev_priv);
A.Sunil Kamath664326f2014-11-24 13:37:44 +0530582}
583
Daniel Vetteraf5fead2015-10-28 23:58:57 +0200584static void assert_csr_loaded(struct drm_i915_private *dev_priv)
585{
586 WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
587 "CSR program storage start is NULL\n");
588 WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
589 WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
590}
591
Suketu Shah5aefb232015-04-16 14:22:10 +0530592static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shahdc174302015-04-17 19:46:16 +0530593{
Suketu Shah5aefb232015-04-16 14:22:10 +0530594 bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
595 SKL_DISP_PW_2);
596
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700597 WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
Suketu Shah5aefb232015-04-16 14:22:10 +0530598
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700599 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
600 "DC5 already programmed to be enabled.\n");
Imre Deakc9b88462015-12-15 20:10:34 +0200601 assert_rpm_wakelock_held(dev_priv);
Suketu Shah5aefb232015-04-16 14:22:10 +0530602
603 assert_csr_loaded(dev_priv);
604}
605
Imre Deakf62c79b2016-04-20 20:27:57 +0300606void gen9_enable_dc5(struct drm_i915_private *dev_priv)
Suketu Shah5aefb232015-04-16 14:22:10 +0530607{
Suketu Shah5aefb232015-04-16 14:22:10 +0530608 assert_can_enable_dc5(dev_priv);
A.Sunil Kamath6b457d32015-04-16 14:22:09 +0530609
610 DRM_DEBUG_KMS("Enabling DC5\n");
611
Lucas De Marchi53421c22017-12-04 15:22:10 -0800612 /* Wa Display #1183: skl,kbl,cfl */
613 if (IS_GEN9_BC(dev_priv))
614 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
615 SKL_SELECT_ALTERNATE_DC_EXIT);
616
Imre Deak13ae3a02015-11-04 19:24:16 +0200617 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
Suketu Shahdc174302015-04-17 19:46:16 +0530618}
619
Suketu Shah93c7cb62015-04-16 14:22:13 +0530620static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530621{
Jesse Barnes6ff8ab02015-09-10 08:20:28 -0700622 WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
623 "Backlight is not disabled.\n");
624 WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
625 "DC6 already programmed to be enabled.\n");
Suketu Shah93c7cb62015-04-16 14:22:13 +0530626
627 assert_csr_loaded(dev_priv);
628}
629
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530630void skl_enable_dc6(struct drm_i915_private *dev_priv)
Suketu Shah93c7cb62015-04-16 14:22:13 +0530631{
Suketu Shah93c7cb62015-04-16 14:22:13 +0530632 assert_can_enable_dc6(dev_priv);
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530633
634 DRM_DEBUG_KMS("Enabling DC6\n");
635
Imre Deak13ae3a02015-11-04 19:24:16 +0200636 gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
637
Suketu Shahf75a1982015-04-16 14:22:11 +0530638}
639
Animesh Manna0a9d2be2015-09-29 11:01:59 +0530640void skl_disable_dc6(struct drm_i915_private *dev_priv)
Suketu Shahf75a1982015-04-16 14:22:11 +0530641{
A.Sunil Kamath74b4f372015-04-16 14:22:12 +0530642 DRM_DEBUG_KMS("Disabling DC6\n");
643
Lucas De Marchi53421c22017-12-04 15:22:10 -0800644 /* Wa Display #1183: skl,kbl,cfl */
645 if (IS_GEN9_BC(dev_priv))
646 I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
647 SKL_SELECT_ALTERNATE_DC_EXIT);
648
Imre Deak13ae3a02015-11-04 19:24:16 +0200649 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Suketu Shahf75a1982015-04-16 14:22:11 +0530650}
651
Daniel Vetter9c065a72014-09-30 10:56:38 +0200652static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
653 struct i915_power_well *power_well)
654{
Imre Deak1af474f2017-07-06 17:40:34 +0300655 enum i915_power_well_id id = power_well->id;
656 u32 mask = HSW_PWR_WELL_CTL_REQ(id);
Imre Deak9c3a16c2017-08-14 18:15:30 +0300657 u32 bios_req = I915_READ(HSW_PWR_WELL_CTL_BIOS(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300658
Imre Deak16e84912017-02-17 17:39:45 +0200659 /* Take over the request bit if set by BIOS. */
Imre Deak1af474f2017-07-06 17:40:34 +0300660 if (bios_req & mask) {
Imre Deak9c3a16c2017-08-14 18:15:30 +0300661 u32 drv_req = I915_READ(HSW_PWR_WELL_CTL_DRIVER(id));
Imre Deak1af474f2017-07-06 17:40:34 +0300662
663 if (!(drv_req & mask))
Imre Deak9c3a16c2017-08-14 18:15:30 +0300664 I915_WRITE(HSW_PWR_WELL_CTL_DRIVER(id), drv_req | mask);
665 I915_WRITE(HSW_PWR_WELL_CTL_BIOS(id), bios_req & ~mask);
Imre Deak16e84912017-02-17 17:39:45 +0200666 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200667}
668
Imre Deak9c8d0b82016-06-13 16:44:34 +0300669static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
670 struct i915_power_well *power_well)
671{
Imre Deakb5565a22017-07-06 17:40:29 +0300672 bxt_ddi_phy_init(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300673}
674
675static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
676 struct i915_power_well *power_well)
677{
Imre Deakb5565a22017-07-06 17:40:29 +0300678 bxt_ddi_phy_uninit(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300679}
680
681static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
682 struct i915_power_well *power_well)
683{
Imre Deakb5565a22017-07-06 17:40:29 +0300684 return bxt_ddi_phy_is_enabled(dev_priv, power_well->bxt.phy);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300685}
686
Imre Deak9c8d0b82016-06-13 16:44:34 +0300687static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
688{
689 struct i915_power_well *power_well;
690
691 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
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);
Imre Deak9c8d0b82016-06-13 16:44:34 +0300694
695 power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
696 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300697 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200698
699 if (IS_GEMINILAKE(dev_priv)) {
700 power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
701 if (power_well->count > 0)
Imre Deakb5565a22017-07-06 17:40:29 +0300702 bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200703 }
Imre Deak9c8d0b82016-06-13 16:44:34 +0300704}
705
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100706static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
707 struct i915_power_well *power_well)
708{
709 return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
710}
711
Ville Syrjälä18a80672016-05-16 16:59:40 +0300712static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
713{
714 u32 tmp = I915_READ(DBUF_CTL);
715
716 WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
717 (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
718 "Unexpected DBuf power power state (0x%08x)\n", tmp);
719}
720
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100721static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
722 struct i915_power_well *power_well)
723{
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200724 struct intel_cdclk_state cdclk_state = {};
725
Imre Deak5b773eb2016-02-29 22:49:05 +0200726 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
Imre Deakadc7f042016-04-04 17:27:10 +0300727
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200728 dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
Ville Syrjälä64600bd2017-10-24 12:52:08 +0300729 /* Can't read out voltage_level so can't use intel_cdclk_changed() */
730 WARN_ON(intel_cdclk_needs_modeset(&dev_priv->cdclk.hw, &cdclk_state));
Ville Syrjälä342be922016-05-13 23:41:39 +0300731
Ville Syrjälä18a80672016-05-16 16:59:40 +0300732 gen9_assert_dbuf_enabled(dev_priv);
733
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200734 if (IS_GEN9_LP(dev_priv))
Imre Deak9c8d0b82016-06-13 16:44:34 +0300735 bxt_verify_ddi_phy_power_wells(dev_priv);
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100736}
737
738static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
739 struct i915_power_well *power_well)
740{
Imre Deakf74ed082016-04-18 14:48:21 +0300741 if (!dev_priv->csr.dmc_payload)
742 return;
743
Imre Deaka37baf32016-02-29 22:49:03 +0200744 if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100745 skl_enable_dc6(dev_priv);
Imre Deaka37baf32016-02-29 22:49:03 +0200746 else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100747 gen9_enable_dc5(dev_priv);
748}
749
Imre Deak3c1b38e2017-02-17 17:39:42 +0200750static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
751 struct i915_power_well *power_well)
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100752{
Patrik Jakobsson9f836f92015-11-16 16:20:01 +0100753}
754
Daniel Vetter9c065a72014-09-30 10:56:38 +0200755static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
756 struct i915_power_well *power_well)
757{
758}
759
760static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
761 struct i915_power_well *power_well)
762{
763 return true;
764}
765
Ville Syrjälä2ee0da12017-06-01 17:36:16 +0300766static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
767 struct i915_power_well *power_well)
768{
769 if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
770 i830_enable_pipe(dev_priv, PIPE_A);
771 if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
772 i830_enable_pipe(dev_priv, PIPE_B);
773}
774
775static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
776 struct i915_power_well *power_well)
777{
778 i830_disable_pipe(dev_priv, PIPE_B);
779 i830_disable_pipe(dev_priv, PIPE_A);
780}
781
782static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
783 struct i915_power_well *power_well)
784{
785 return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
786 I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
787}
788
789static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
790 struct i915_power_well *power_well)
791{
792 if (power_well->count > 0)
793 i830_pipes_power_well_enable(dev_priv, power_well);
794 else
795 i830_pipes_power_well_disable(dev_priv, power_well);
796}
797
Daniel Vetter9c065a72014-09-30 10:56:38 +0200798static void vlv_set_power_well(struct drm_i915_private *dev_priv,
799 struct i915_power_well *power_well, bool enable)
800{
Imre Deak438b8dc2017-07-11 23:42:30 +0300801 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200802 u32 mask;
803 u32 state;
804 u32 ctrl;
805
806 mask = PUNIT_PWRGT_MASK(power_well_id);
807 state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
808 PUNIT_PWRGT_PWR_GATE(power_well_id);
809
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100810 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200811
812#define COND \
813 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
814
815 if (COND)
816 goto out;
817
818 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
819 ctrl &= ~mask;
820 ctrl |= state;
821 vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
822
823 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +0900824 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +0200825 state,
826 vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
827
828#undef COND
829
830out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100831 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200832}
833
Daniel Vetter9c065a72014-09-30 10:56:38 +0200834static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
835 struct i915_power_well *power_well)
836{
837 vlv_set_power_well(dev_priv, power_well, true);
838}
839
840static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
841 struct i915_power_well *power_well)
842{
843 vlv_set_power_well(dev_priv, power_well, false);
844}
845
846static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
847 struct i915_power_well *power_well)
848{
Imre Deak438b8dc2017-07-11 23:42:30 +0300849 enum i915_power_well_id power_well_id = power_well->id;
Daniel Vetter9c065a72014-09-30 10:56:38 +0200850 bool enabled = false;
851 u32 mask;
852 u32 state;
853 u32 ctrl;
854
855 mask = PUNIT_PWRGT_MASK(power_well_id);
856 ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
857
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100858 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200859
860 state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
861 /*
862 * We only ever set the power-on and power-gate states, anything
863 * else is unexpected.
864 */
865 WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
866 state != PUNIT_PWRGT_PWR_GATE(power_well_id));
867 if (state == ctrl)
868 enabled = true;
869
870 /*
871 * A transient state at this point would mean some unexpected party
872 * is poking at the power controls too.
873 */
874 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
875 WARN_ON(ctrl != state);
876
Sagar Arun Kamble9f817502017-10-10 22:30:05 +0100877 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200878
879 return enabled;
880}
881
Ville Syrjälä766078d2016-04-11 16:56:30 +0300882static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
883{
Hans de Goede721d4842016-12-02 15:29:04 +0100884 u32 val;
885
886 /*
887 * On driver load, a pipe may be active and driving a DSI display.
888 * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
889 * (and never recovering) in this case. intel_dsi_post_disable() will
890 * clear it when we turn off the display.
891 */
892 val = I915_READ(DSPCLK_GATE_D);
893 val &= DPOUNIT_CLOCK_GATE_DISABLE;
894 val |= VRHUNIT_CLOCK_GATE_DISABLE;
895 I915_WRITE(DSPCLK_GATE_D, val);
Ville Syrjälä766078d2016-04-11 16:56:30 +0300896
897 /*
898 * Disable trickle feed and enable pnd deadline calculation
899 */
900 I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
901 I915_WRITE(CBR1_VLV, 0);
Ville Syrjälä19ab4ed2016-04-27 17:43:22 +0300902
903 WARN_ON(dev_priv->rawclk_freq == 0);
904
905 I915_WRITE(RAWCLK_FREQ_VLV,
906 DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
Ville Syrjälä766078d2016-04-11 16:56:30 +0300907}
908
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300909static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +0200910{
Lyude9504a892016-06-21 17:03:42 -0400911 struct intel_encoder *encoder;
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300912 enum pipe pipe;
913
914 /*
915 * Enable the CRI clock source so we can get at the
916 * display and the reference clock for VGA
917 * hotplug / manual detection. Supposedly DSI also
918 * needs the ref clock up and running.
919 *
920 * CHV DPLL B/C have some issues if VGA mode is enabled.
921 */
Tvrtko Ursulin801388c2016-11-16 08:55:44 +0000922 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300923 u32 val = I915_READ(DPLL(pipe));
924
925 val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
926 if (pipe != PIPE_A)
927 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
928
929 I915_WRITE(DPLL(pipe), val);
930 }
Daniel Vetter9c065a72014-09-30 10:56:38 +0200931
Ville Syrjälä766078d2016-04-11 16:56:30 +0300932 vlv_init_display_clock_gating(dev_priv);
933
Daniel Vetter9c065a72014-09-30 10:56:38 +0200934 spin_lock_irq(&dev_priv->irq_lock);
935 valleyview_enable_display_irqs(dev_priv);
936 spin_unlock_irq(&dev_priv->irq_lock);
937
938 /*
939 * During driver initialization/resume we can avoid restoring the
940 * part of the HW/SW state that will be inited anyway explicitly.
941 */
942 if (dev_priv->power_domains.initializing)
943 return;
944
Daniel Vetterb9632912014-09-30 10:56:44 +0200945 intel_hpd_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200946
Lyude9504a892016-06-21 17:03:42 -0400947 /* Re-enable the ADPA, if we have one */
948 for_each_intel_encoder(&dev_priv->drm, encoder) {
949 if (encoder->type == INTEL_OUTPUT_ANALOG)
950 intel_crt_reset(&encoder->base);
951 }
952
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +0000953 i915_redisable_vga_power_on(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +0300954
955 intel_pps_unlock_regs_wa(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200956}
957
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300958static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
959{
960 spin_lock_irq(&dev_priv->irq_lock);
961 valleyview_disable_display_irqs(dev_priv);
962 spin_unlock_irq(&dev_priv->irq_lock);
963
Ville Syrjälä2230fde2016-02-19 18:41:52 +0200964 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +0100965 synchronize_irq(dev_priv->drm.irq);
Ville Syrjälä2230fde2016-02-19 18:41:52 +0200966
Imre Deak78597992016-06-16 16:37:20 +0300967 intel_power_sequencer_reset(dev_priv);
Lyude19625e82016-06-21 17:03:44 -0400968
Lyudeb64b5402016-10-26 12:36:09 -0400969 /* Prevent us from re-enabling polling on accident in late suspend */
970 if (!dev_priv->drm.dev->power.is_suspended)
971 intel_hpd_poll_init(dev_priv);
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300972}
973
974static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
975 struct i915_power_well *power_well)
976{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300977 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300978
979 vlv_set_power_well(dev_priv, power_well, true);
980
981 vlv_display_power_well_init(dev_priv);
982}
983
Daniel Vetter9c065a72014-09-30 10:56:38 +0200984static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
985 struct i915_power_well *power_well)
986{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300987 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200988
Ville Syrjälä2be7d542015-06-29 15:25:51 +0300989 vlv_display_power_well_deinit(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200990
991 vlv_set_power_well(dev_priv, power_well, false);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200992}
993
994static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
995 struct i915_power_well *power_well)
996{
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +0300997 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +0200998
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +0300999 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001000 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1001
1002 vlv_set_power_well(dev_priv, power_well, true);
1003
1004 /*
1005 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
1006 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
1007 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
1008 * b. The other bits such as sfr settings / modesel may all
1009 * be set to 0.
1010 *
1011 * This should only be done on init and resume from S3 with
1012 * both PLLs disabled, or we risk losing DPIO and PLL
1013 * synchronization.
1014 */
1015 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
1016}
1017
1018static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1019 struct i915_power_well *power_well)
1020{
1021 enum pipe pipe;
1022
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001023 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001024
1025 for_each_pipe(dev_priv, pipe)
1026 assert_pll_disabled(dev_priv, pipe);
1027
1028 /* Assert common reset */
1029 I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
1030
1031 vlv_set_power_well(dev_priv, power_well, false);
1032}
1033
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001034#define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
Ville Syrjälä30142272015-07-08 23:46:01 +03001035
Imre Deak438b8dc2017-07-11 23:42:30 +03001036static struct i915_power_well *
1037lookup_power_well(struct drm_i915_private *dev_priv,
1038 enum i915_power_well_id power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001039{
1040 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Ville Syrjälä30142272015-07-08 23:46:01 +03001041 int i;
1042
Imre Deakfc17f222015-11-04 19:24:11 +02001043 for (i = 0; i < power_domains->power_well_count; i++) {
1044 struct i915_power_well *power_well;
1045
1046 power_well = &power_domains->power_wells[i];
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001047 if (power_well->id == power_well_id)
Ville Syrjälä30142272015-07-08 23:46:01 +03001048 return power_well;
1049 }
1050
1051 return NULL;
1052}
1053
1054#define BITS_SET(val, bits) (((val) & (bits)) == (bits))
1055
1056static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
1057{
1058 struct i915_power_well *cmn_bc =
1059 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
1060 struct i915_power_well *cmn_d =
1061 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
1062 u32 phy_control = dev_priv->chv_phy_control;
1063 u32 phy_status = 0;
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001064 u32 phy_status_mask = 0xffffffff;
Ville Syrjälä30142272015-07-08 23:46:01 +03001065
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001066 /*
1067 * The BIOS can leave the PHY is some weird state
1068 * where it doesn't fully power down some parts.
1069 * Disable the asserts until the PHY has been fully
1070 * reset (ie. the power well has been disabled at
1071 * least once).
1072 */
1073 if (!dev_priv->chv_phy_assert[DPIO_PHY0])
1074 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
1075 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
1076 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
1077 PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
1078 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
1079 PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
1080
1081 if (!dev_priv->chv_phy_assert[DPIO_PHY1])
1082 phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
1083 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
1084 PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
1085
Ville Syrjälä30142272015-07-08 23:46:01 +03001086 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
1087 phy_status |= PHY_POWERGOOD(DPIO_PHY0);
1088
1089 /* this assumes override is only used to enable lanes */
1090 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
1091 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
1092
1093 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
1094 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
1095
1096 /* CL1 is on whenever anything is on in either channel */
1097 if (BITS_SET(phy_control,
1098 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
1099 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
1100 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
1101
1102 /*
1103 * The DPLLB check accounts for the pipe B + port A usage
1104 * with CL2 powered up but all the lanes in the second channel
1105 * powered down.
1106 */
1107 if (BITS_SET(phy_control,
1108 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
1109 (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
1110 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
1111
1112 if (BITS_SET(phy_control,
1113 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
1114 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
1115 if (BITS_SET(phy_control,
1116 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
1117 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
1118
1119 if (BITS_SET(phy_control,
1120 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
1121 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
1122 if (BITS_SET(phy_control,
1123 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
1124 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
1125 }
1126
1127 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
1128 phy_status |= PHY_POWERGOOD(DPIO_PHY1);
1129
1130 /* this assumes override is only used to enable lanes */
1131 if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
1132 phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
1133
1134 if (BITS_SET(phy_control,
1135 PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
1136 phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
1137
1138 if (BITS_SET(phy_control,
1139 PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
1140 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
1141 if (BITS_SET(phy_control,
1142 PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
1143 phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
1144 }
1145
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001146 phy_status &= phy_status_mask;
1147
Ville Syrjälä30142272015-07-08 23:46:01 +03001148 /*
1149 * The PHY may be busy with some initial calibration and whatnot,
1150 * so the power state can take a while to actually change.
1151 */
Chris Wilson919fcd52016-06-30 15:33:35 +01001152 if (intel_wait_for_register(dev_priv,
1153 DISPLAY_PHY_STATUS,
1154 phy_status_mask,
1155 phy_status,
1156 10))
1157 DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
1158 I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
1159 phy_status, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001160}
1161
1162#undef BITS_SET
1163
Daniel Vetter9c065a72014-09-30 10:56:38 +02001164static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
1165 struct i915_power_well *power_well)
1166{
1167 enum dpio_phy phy;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001168 enum pipe pipe;
1169 uint32_t tmp;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001170
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001171 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1172 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001173
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001174 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001175 pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001176 phy = DPIO_PHY0;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001177 } else {
1178 pipe = PIPE_C;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001179 phy = DPIO_PHY1;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001180 }
Ville Syrjälä5a8fbb72015-06-29 15:25:53 +03001181
1182 /* since ref/cri clock was enabled */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001183 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
1184 vlv_set_power_well(dev_priv, power_well, true);
1185
1186 /* Poll for phypwrgood signal */
Chris Wilsonffebb832016-06-30 15:33:36 +01001187 if (intel_wait_for_register(dev_priv,
1188 DISPLAY_PHY_STATUS,
1189 PHY_POWERGOOD(phy),
1190 PHY_POWERGOOD(phy),
1191 1))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001192 DRM_ERROR("Display PHY %d is not power up\n", phy);
1193
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001194 mutex_lock(&dev_priv->sb_lock);
1195
1196 /* Enable dynamic power down */
1197 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
Ville Syrjäläee279212015-07-08 23:45:57 +03001198 tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
1199 DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001200 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
1201
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001202 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001203 tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
1204 tmp |= DPIO_DYNPWRDOWNEN_CH1;
1205 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
Ville Syrjälä3e288782015-07-08 23:45:58 +03001206 } else {
1207 /*
1208 * Force the non-existing CL2 off. BXT does this
1209 * too, so maybe it saves some power even though
1210 * CL2 doesn't exist?
1211 */
1212 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1213 tmp |= DPIO_CL2_LDOFUSE_PWRENB;
1214 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001215 }
1216
1217 mutex_unlock(&dev_priv->sb_lock);
1218
Ville Syrjälä70722462015-04-10 18:21:28 +03001219 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
1220 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001221
1222 DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1223 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001224
1225 assert_chv_phy_status(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001226}
1227
1228static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
1229 struct i915_power_well *power_well)
1230{
1231 enum dpio_phy phy;
1232
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001233 WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
1234 power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001235
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03001236 if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02001237 phy = DPIO_PHY0;
1238 assert_pll_disabled(dev_priv, PIPE_A);
1239 assert_pll_disabled(dev_priv, PIPE_B);
1240 } else {
1241 phy = DPIO_PHY1;
1242 assert_pll_disabled(dev_priv, PIPE_C);
1243 }
1244
Ville Syrjälä70722462015-04-10 18:21:28 +03001245 dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
1246 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001247
1248 vlv_set_power_well(dev_priv, power_well, false);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001249
1250 DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
1251 phy, dev_priv->chv_phy_control);
Ville Syrjälä30142272015-07-08 23:46:01 +03001252
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001253 /* PHY is fully reset now, so we can enable the PHY state asserts */
1254 dev_priv->chv_phy_assert[phy] = true;
1255
Ville Syrjälä30142272015-07-08 23:46:01 +03001256 assert_chv_phy_status(dev_priv);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001257}
1258
Ville Syrjälä6669e392015-07-08 23:46:00 +03001259static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1260 enum dpio_channel ch, bool override, unsigned int mask)
1261{
1262 enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
1263 u32 reg, val, expected, actual;
1264
Ville Syrjälä3be60de2015-09-08 18:05:45 +03001265 /*
1266 * The BIOS can leave the PHY is some weird state
1267 * where it doesn't fully power down some parts.
1268 * Disable the asserts until the PHY has been fully
1269 * reset (ie. the power well has been disabled at
1270 * least once).
1271 */
1272 if (!dev_priv->chv_phy_assert[phy])
1273 return;
1274
Ville Syrjälä6669e392015-07-08 23:46:00 +03001275 if (ch == DPIO_CH0)
1276 reg = _CHV_CMN_DW0_CH0;
1277 else
1278 reg = _CHV_CMN_DW6_CH1;
1279
1280 mutex_lock(&dev_priv->sb_lock);
1281 val = vlv_dpio_read(dev_priv, pipe, reg);
1282 mutex_unlock(&dev_priv->sb_lock);
1283
1284 /*
1285 * This assumes !override is only used when the port is disabled.
1286 * All lanes should power down even without the override when
1287 * the port is disabled.
1288 */
1289 if (!override || mask == 0xf) {
1290 expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1291 /*
1292 * If CH1 common lane is not active anymore
1293 * (eg. for pipe B DPLL) the entire channel will
1294 * shut down, which causes the common lane registers
1295 * to read as 0. That means we can't actually check
1296 * the lane power down status bits, but as the entire
1297 * register reads as 0 it's a good indication that the
1298 * channel is indeed entirely powered down.
1299 */
1300 if (ch == DPIO_CH1 && val == 0)
1301 expected = 0;
1302 } else if (mask != 0x0) {
1303 expected = DPIO_ANYDL_POWERDOWN;
1304 } else {
1305 expected = 0;
1306 }
1307
1308 if (ch == DPIO_CH0)
1309 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
1310 else
1311 actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
1312 actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
1313
1314 WARN(actual != expected,
1315 "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
1316 !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
1317 !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
1318 reg, val);
1319}
1320
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001321bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
1322 enum dpio_channel ch, bool override)
1323{
1324 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1325 bool was_override;
1326
1327 mutex_lock(&power_domains->lock);
1328
1329 was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1330
1331 if (override == was_override)
1332 goto out;
1333
1334 if (override)
1335 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1336 else
1337 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1338
1339 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1340
1341 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
1342 phy, ch, dev_priv->chv_phy_control);
1343
Ville Syrjälä30142272015-07-08 23:46:01 +03001344 assert_chv_phy_status(dev_priv);
1345
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001346out:
1347 mutex_unlock(&power_domains->lock);
1348
1349 return was_override;
1350}
1351
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001352void chv_phy_powergate_lanes(struct intel_encoder *encoder,
1353 bool override, unsigned int mask)
1354{
1355 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1356 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1357 enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
1358 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1359
1360 mutex_lock(&power_domains->lock);
1361
1362 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
1363 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
1364
1365 if (override)
1366 dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1367 else
1368 dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
1369
1370 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
1371
1372 DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
1373 phy, ch, mask, dev_priv->chv_phy_control);
1374
Ville Syrjälä30142272015-07-08 23:46:01 +03001375 assert_chv_phy_status(dev_priv);
1376
Ville Syrjälä6669e392015-07-08 23:46:00 +03001377 assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
1378
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001379 mutex_unlock(&power_domains->lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001380}
1381
1382static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
1383 struct i915_power_well *power_well)
1384{
Imre Deakf49193c2017-07-06 17:40:23 +03001385 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001386 bool enabled;
1387 u32 state, ctrl;
1388
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001389 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001390
1391 state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
1392 /*
1393 * We only ever set the power-on and power-gate states, anything
1394 * else is unexpected.
1395 */
1396 WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
1397 enabled = state == DP_SSS_PWR_ON(pipe);
1398
1399 /*
1400 * A transient state at this point would mean some unexpected party
1401 * is poking at the power controls too.
1402 */
1403 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
1404 WARN_ON(ctrl << 16 != state);
1405
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001406 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001407
1408 return enabled;
1409}
1410
1411static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
1412 struct i915_power_well *power_well,
1413 bool enable)
1414{
Imre Deakf49193c2017-07-06 17:40:23 +03001415 enum pipe pipe = PIPE_A;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001416 u32 state;
1417 u32 ctrl;
1418
1419 state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
1420
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001421 mutex_lock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001422
1423#define COND \
1424 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
1425
1426 if (COND)
1427 goto out;
1428
1429 ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
1430 ctrl &= ~DP_SSC_MASK(pipe);
1431 ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
1432 vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
1433
1434 if (wait_for(COND, 100))
Masanari Iida7e35ab82015-05-10 01:00:23 +09001435 DRM_ERROR("timeout setting power well state %08x (%08x)\n",
Daniel Vetter9c065a72014-09-30 10:56:38 +02001436 state,
1437 vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
1438
1439#undef COND
1440
1441out:
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001442 mutex_unlock(&dev_priv->pcu_lock);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001443}
1444
Daniel Vetter9c065a72014-09-30 10:56:38 +02001445static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
1446 struct i915_power_well *power_well)
1447{
Imre Deakf49193c2017-07-06 17:40:23 +03001448 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001449
1450 chv_set_pipe_power_well(dev_priv, power_well, true);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001451
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001452 vlv_display_power_well_init(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001453}
1454
1455static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
1456 struct i915_power_well *power_well)
1457{
Imre Deakf49193c2017-07-06 17:40:23 +03001458 WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001459
Ville Syrjälä2be7d542015-06-29 15:25:51 +03001460 vlv_display_power_well_deinit(dev_priv);
Ville Syrjäläafd62752014-10-30 19:43:03 +02001461
Daniel Vetter9c065a72014-09-30 10:56:38 +02001462 chv_set_pipe_power_well(dev_priv, power_well, false);
1463}
1464
Imre Deak09731282016-02-17 14:17:42 +02001465static void
1466__intel_display_power_get_domain(struct drm_i915_private *dev_priv,
1467 enum intel_display_power_domain domain)
1468{
1469 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1470 struct i915_power_well *power_well;
Imre Deak09731282016-02-17 14:17:42 +02001471
Imre Deak75ccb2e2017-02-17 17:39:43 +02001472 for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001473 intel_power_well_get(dev_priv, power_well);
Imre Deak09731282016-02-17 14:17:42 +02001474
1475 power_domains->domain_use_count[domain]++;
1476}
1477
Daniel Vettere4e76842014-09-30 10:56:42 +02001478/**
1479 * intel_display_power_get - grab a power domain reference
1480 * @dev_priv: i915 device instance
1481 * @domain: power domain to reference
1482 *
1483 * This function grabs a power domain reference for @domain and ensures that the
1484 * power domain and all its parents are powered up. Therefore users should only
1485 * grab a reference to the innermost power domain they need.
1486 *
1487 * Any power domain reference obtained by this function must have a symmetric
1488 * call to intel_display_power_put() to release the reference again.
1489 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001490void intel_display_power_get(struct drm_i915_private *dev_priv,
1491 enum intel_display_power_domain domain)
1492{
Imre Deak09731282016-02-17 14:17:42 +02001493 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001494
1495 intel_runtime_pm_get(dev_priv);
1496
Imre Deak09731282016-02-17 14:17:42 +02001497 mutex_lock(&power_domains->lock);
1498
1499 __intel_display_power_get_domain(dev_priv, domain);
1500
1501 mutex_unlock(&power_domains->lock);
1502}
1503
1504/**
1505 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
1506 * @dev_priv: i915 device instance
1507 * @domain: power domain to reference
1508 *
1509 * This function grabs a power domain reference for @domain and ensures that the
1510 * power domain and all its parents are powered up. Therefore users should only
1511 * grab a reference to the innermost power domain they need.
1512 *
1513 * Any power domain reference obtained by this function must have a symmetric
1514 * call to intel_display_power_put() to release the reference again.
1515 */
1516bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
1517 enum intel_display_power_domain domain)
1518{
1519 struct i915_power_domains *power_domains = &dev_priv->power_domains;
1520 bool is_enabled;
1521
1522 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1523 return false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001524
1525 mutex_lock(&power_domains->lock);
1526
Imre Deak09731282016-02-17 14:17:42 +02001527 if (__intel_display_power_is_enabled(dev_priv, domain)) {
1528 __intel_display_power_get_domain(dev_priv, domain);
1529 is_enabled = true;
1530 } else {
1531 is_enabled = false;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001532 }
1533
Daniel Vetter9c065a72014-09-30 10:56:38 +02001534 mutex_unlock(&power_domains->lock);
Imre Deak09731282016-02-17 14:17:42 +02001535
1536 if (!is_enabled)
1537 intel_runtime_pm_put(dev_priv);
1538
1539 return is_enabled;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001540}
1541
Daniel Vettere4e76842014-09-30 10:56:42 +02001542/**
1543 * intel_display_power_put - release a power domain reference
1544 * @dev_priv: i915 device instance
1545 * @domain: power domain to reference
1546 *
1547 * This function drops the power domain reference obtained by
1548 * intel_display_power_get() and might power down the corresponding hardware
1549 * block right away if this is the last reference.
1550 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02001551void intel_display_power_put(struct drm_i915_private *dev_priv,
1552 enum intel_display_power_domain domain)
1553{
1554 struct i915_power_domains *power_domains;
1555 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02001556
1557 power_domains = &dev_priv->power_domains;
1558
1559 mutex_lock(&power_domains->lock);
1560
Daniel Stone11c86db2015-11-20 15:55:34 +00001561 WARN(!power_domains->domain_use_count[domain],
1562 "Use count on domain %s is already zero\n",
1563 intel_display_power_domain_str(domain));
Daniel Vetter9c065a72014-09-30 10:56:38 +02001564 power_domains->domain_use_count[domain]--;
1565
Imre Deak75ccb2e2017-02-17 17:39:43 +02001566 for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
Imre Deakb409ca92016-06-13 16:44:33 +03001567 intel_power_well_put(dev_priv, power_well);
Daniel Vetter9c065a72014-09-30 10:56:38 +02001568
1569 mutex_unlock(&power_domains->lock);
1570
1571 intel_runtime_pm_put(dev_priv);
1572}
1573
Imre Deak965a79a2017-07-06 17:40:40 +03001574#define I830_PIPES_POWER_DOMAINS ( \
1575 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) | \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001581 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001582
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001583#define VLV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001584 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1585 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1586 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1587 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1588 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1589 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1590 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1591 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1592 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1593 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1594 BIT_ULL(POWER_DOMAIN_VGA) | \
1595 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1596 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1597 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1598 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1599 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001600
1601#define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001602 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1603 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1604 BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
1605 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1606 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1607 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001608
1609#define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001610 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1611 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1612 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001613
1614#define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001615 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1616 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1617 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001618
1619#define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001620 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1621 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1622 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001623
1624#define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001625 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1626 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1627 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001628
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001629#define CHV_DISPLAY_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001630 BIT_ULL(POWER_DOMAIN_PIPE_A) | \
1631 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1632 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1633 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1634 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1635 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1636 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1637 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1638 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1639 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1640 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1641 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1642 BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
1643 BIT_ULL(POWER_DOMAIN_VGA) | \
1644 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1645 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1646 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1647 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1648 BIT_ULL(POWER_DOMAIN_GMBUS) | \
1649 BIT_ULL(POWER_DOMAIN_INIT))
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03001650
Daniel Vetter9c065a72014-09-30 10:56:38 +02001651#define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001652 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1653 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1654 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1655 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1656 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001657
1658#define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02001659 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1660 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1661 BIT_ULL(POWER_DOMAIN_INIT))
Daniel Vetter9c065a72014-09-30 10:56:38 +02001662
Imre Deak965a79a2017-07-06 17:40:40 +03001663#define HSW_DISPLAY_POWER_DOMAINS ( \
1664 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1665 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1666 BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
1667 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1668 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1669 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1670 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1671 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1672 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1673 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1674 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1675 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1676 BIT_ULL(POWER_DOMAIN_VGA) | \
1677 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1678 BIT_ULL(POWER_DOMAIN_INIT))
1679
1680#define BDW_DISPLAY_POWER_DOMAINS ( \
1681 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1682 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1683 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1684 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1685 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1686 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1687 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1688 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1689 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1690 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1691 BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
1692 BIT_ULL(POWER_DOMAIN_VGA) | \
1693 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1694 BIT_ULL(POWER_DOMAIN_INIT))
1695
1696#define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1697 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1698 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1699 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1700 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1701 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1702 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1703 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1704 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1705 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1706 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
1707 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
1708 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1709 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1710 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1711 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1712 BIT_ULL(POWER_DOMAIN_VGA) | \
1713 BIT_ULL(POWER_DOMAIN_INIT))
1714#define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
1715 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
1716 BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
1717 BIT_ULL(POWER_DOMAIN_INIT))
1718#define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1719 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1720 BIT_ULL(POWER_DOMAIN_INIT))
1721#define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1722 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1723 BIT_ULL(POWER_DOMAIN_INIT))
1724#define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
1725 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1726 BIT_ULL(POWER_DOMAIN_INIT))
1727#define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1728 SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001729 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001730 BIT_ULL(POWER_DOMAIN_MODESET) | \
1731 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1732 BIT_ULL(POWER_DOMAIN_INIT))
1733
1734#define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1735 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1736 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1737 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1738 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1739 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1740 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1741 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1742 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1743 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1744 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1745 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1746 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1747 BIT_ULL(POWER_DOMAIN_VGA) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001748 BIT_ULL(POWER_DOMAIN_INIT))
1749#define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1750 BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001751 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001752 BIT_ULL(POWER_DOMAIN_MODESET) | \
1753 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä54c105d2017-12-08 23:37:37 +02001754 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001755 BIT_ULL(POWER_DOMAIN_INIT))
1756#define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
1757 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1758 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1759 BIT_ULL(POWER_DOMAIN_INIT))
1760#define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
1761 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1762 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1763 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1764 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1765 BIT_ULL(POWER_DOMAIN_INIT))
1766
1767#define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1768 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1769 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1770 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1771 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1772 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1773 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1774 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1775 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1776 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1777 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1778 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1779 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1780 BIT_ULL(POWER_DOMAIN_VGA) | \
1781 BIT_ULL(POWER_DOMAIN_INIT))
1782#define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
1783 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
1784#define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
1785 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
1786#define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
1787 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
1788#define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
1789 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
1790 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1791 BIT_ULL(POWER_DOMAIN_INIT))
1792#define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
1793 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1794 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1795 BIT_ULL(POWER_DOMAIN_INIT))
1796#define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
1797 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1798 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1799 BIT_ULL(POWER_DOMAIN_INIT))
1800#define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
1801 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1802 BIT_ULL(POWER_DOMAIN_INIT))
1803#define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
1804 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1805 BIT_ULL(POWER_DOMAIN_INIT))
1806#define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
1807 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1808 BIT_ULL(POWER_DOMAIN_INIT))
1809#define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1810 GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulinb6876372017-12-05 13:28:54 +00001811 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001812 BIT_ULL(POWER_DOMAIN_MODESET) | \
1813 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä156961a2017-12-08 23:37:36 +02001814 BIT_ULL(POWER_DOMAIN_GMBUS) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001815 BIT_ULL(POWER_DOMAIN_INIT))
1816
1817#define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
1818 BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
1819 BIT_ULL(POWER_DOMAIN_PIPE_B) | \
1820 BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
1821 BIT_ULL(POWER_DOMAIN_PIPE_C) | \
1822 BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
1823 BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
1824 BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
1825 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
1826 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
1827 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001828 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1829 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1830 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1831 BIT_ULL(POWER_DOMAIN_AUDIO) | \
1832 BIT_ULL(POWER_DOMAIN_VGA) | \
1833 BIT_ULL(POWER_DOMAIN_INIT))
1834#define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
1835 BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001836 BIT_ULL(POWER_DOMAIN_INIT))
1837#define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
1838 BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
1839 BIT_ULL(POWER_DOMAIN_INIT))
1840#define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
1841 BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
1842 BIT_ULL(POWER_DOMAIN_INIT))
1843#define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
1844 BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
1845 BIT_ULL(POWER_DOMAIN_INIT))
1846#define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
1847 BIT_ULL(POWER_DOMAIN_AUX_A) | \
1848 BIT_ULL(POWER_DOMAIN_INIT))
1849#define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
1850 BIT_ULL(POWER_DOMAIN_AUX_B) | \
1851 BIT_ULL(POWER_DOMAIN_INIT))
1852#define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
1853 BIT_ULL(POWER_DOMAIN_AUX_C) | \
1854 BIT_ULL(POWER_DOMAIN_INIT))
1855#define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
1856 BIT_ULL(POWER_DOMAIN_AUX_D) | \
1857 BIT_ULL(POWER_DOMAIN_INIT))
1858#define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
1859 CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
Tvrtko Ursulin6e7a3f52018-01-11 08:24:17 +00001860 BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
Imre Deak965a79a2017-07-06 17:40:40 +03001861 BIT_ULL(POWER_DOMAIN_MODESET) | \
1862 BIT_ULL(POWER_DOMAIN_AUX_A) | \
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001863 BIT_ULL(POWER_DOMAIN_INIT))
1864
Daniel Vetter9c065a72014-09-30 10:56:38 +02001865static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001866 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001867 .enable = i9xx_always_on_power_well_noop,
1868 .disable = i9xx_always_on_power_well_noop,
1869 .is_enabled = i9xx_always_on_power_well_enabled,
1870};
1871
1872static const struct i915_power_well_ops chv_pipe_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001873 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001874 .enable = chv_pipe_power_well_enable,
1875 .disable = chv_pipe_power_well_disable,
1876 .is_enabled = chv_pipe_power_well_enabled,
1877};
1878
1879static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001880 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001881 .enable = chv_dpio_cmn_power_well_enable,
1882 .disable = chv_dpio_cmn_power_well_disable,
1883 .is_enabled = vlv_power_well_enabled,
1884};
1885
1886static struct i915_power_well i9xx_always_on_power_well[] = {
1887 {
1888 .name = "always-on",
1889 .always_on = 1,
1890 .domains = POWER_DOMAIN_MASK,
1891 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001892 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001893 },
1894};
1895
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001896static const struct i915_power_well_ops i830_pipes_power_well_ops = {
1897 .sync_hw = i830_pipes_power_well_sync_hw,
1898 .enable = i830_pipes_power_well_enable,
1899 .disable = i830_pipes_power_well_disable,
1900 .is_enabled = i830_pipes_power_well_enabled,
1901};
1902
1903static struct i915_power_well i830_power_wells[] = {
1904 {
1905 .name = "always-on",
1906 .always_on = 1,
1907 .domains = POWER_DOMAIN_MASK,
1908 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001909 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001910 },
1911 {
1912 .name = "pipes",
1913 .domains = I830_PIPES_POWER_DOMAINS,
1914 .ops = &i830_pipes_power_well_ops,
Imre Deak120b56a2017-07-11 23:42:31 +03001915 .id = I830_DISP_PW_PIPES,
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03001916 },
1917};
1918
Daniel Vetter9c065a72014-09-30 10:56:38 +02001919static const struct i915_power_well_ops hsw_power_well_ops = {
1920 .sync_hw = hsw_power_well_sync_hw,
1921 .enable = hsw_power_well_enable,
1922 .disable = hsw_power_well_disable,
1923 .is_enabled = hsw_power_well_enabled,
1924};
1925
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001926static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001927 .sync_hw = i9xx_power_well_sync_hw_noop,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01001928 .enable = gen9_dc_off_power_well_enable,
1929 .disable = gen9_dc_off_power_well_disable,
1930 .is_enabled = gen9_dc_off_power_well_enabled,
1931};
1932
Imre Deak9c8d0b82016-06-13 16:44:34 +03001933static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001934 .sync_hw = i9xx_power_well_sync_hw_noop,
Imre Deak9c8d0b82016-06-13 16:44:34 +03001935 .enable = bxt_dpio_cmn_power_well_enable,
1936 .disable = bxt_dpio_cmn_power_well_disable,
1937 .is_enabled = bxt_dpio_cmn_power_well_enabled,
1938};
1939
Daniel Vetter9c065a72014-09-30 10:56:38 +02001940static struct i915_power_well hsw_power_wells[] = {
1941 {
1942 .name = "always-on",
1943 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001944 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001945 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001946 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001947 },
1948 {
1949 .name = "display",
1950 .domains = HSW_DISPLAY_POWER_DOMAINS,
1951 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03001952 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03001953 {
1954 .hsw.has_vga = true,
1955 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001956 },
1957};
1958
1959static struct i915_power_well bdw_power_wells[] = {
1960 {
1961 .name = "always-on",
1962 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03001963 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001964 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03001965 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001966 },
1967 {
1968 .name = "display",
1969 .domains = BDW_DISPLAY_POWER_DOMAINS,
1970 .ops = &hsw_power_well_ops,
Imre Deakfb9248e2017-07-11 23:42:32 +03001971 .id = HSW_DISP_PW_GLOBAL,
Imre Deak0a445942017-08-14 18:15:29 +03001972 {
1973 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
1974 .hsw.has_vga = true,
1975 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02001976 },
1977};
1978
1979static const struct i915_power_well_ops vlv_display_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001980 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001981 .enable = vlv_display_power_well_enable,
1982 .disable = vlv_display_power_well_disable,
1983 .is_enabled = vlv_power_well_enabled,
1984};
1985
1986static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001987 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001988 .enable = vlv_dpio_cmn_power_well_enable,
1989 .disable = vlv_dpio_cmn_power_well_disable,
1990 .is_enabled = vlv_power_well_enabled,
1991};
1992
1993static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
Imre Deak3c1b38e2017-02-17 17:39:42 +02001994 .sync_hw = i9xx_power_well_sync_hw_noop,
Daniel Vetter9c065a72014-09-30 10:56:38 +02001995 .enable = vlv_power_well_enable,
1996 .disable = vlv_power_well_disable,
1997 .is_enabled = vlv_power_well_enabled,
1998};
1999
2000static struct i915_power_well vlv_power_wells[] = {
2001 {
2002 .name = "always-on",
2003 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002004 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002005 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002006 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002007 },
2008 {
2009 .name = "display",
2010 .domains = VLV_DISPLAY_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002011 .id = PUNIT_POWER_WELL_DISP2D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002012 .ops = &vlv_display_power_well_ops,
2013 },
2014 {
2015 .name = "dpio-tx-b-01",
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_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002022 },
2023 {
2024 .name = "dpio-tx-b-23",
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_B_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002031 },
2032 {
2033 .name = "dpio-tx-c-01",
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_01,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002040 },
2041 {
2042 .name = "dpio-tx-c-23",
2043 .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
2044 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
2045 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
2046 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
2047 .ops = &vlv_dpio_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002048 .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002049 },
2050 {
2051 .name = "dpio-common",
2052 .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002053 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002054 .ops = &vlv_dpio_cmn_power_well_ops,
2055 },
2056};
2057
2058static struct i915_power_well chv_power_wells[] = {
2059 {
2060 .name = "always-on",
2061 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002062 .domains = POWER_DOMAIN_MASK,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002063 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002064 .id = I915_DISP_PW_ALWAYS_ON,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002065 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002066 {
2067 .name = "display",
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002068 /*
Ville Syrjäläfde61e42015-05-26 20:22:39 +03002069 * Pipe A power well is the new disp2d well. Pipe B and C
2070 * power wells don't actually exist. Pipe A power well is
2071 * required for any pipe to work.
Ville Syrjäläbaa4e572014-10-27 16:07:32 +02002072 */
Ville Syrjälä465ac0c2016-04-18 14:02:27 +03002073 .domains = CHV_DISPLAY_POWER_DOMAINS,
Imre Deakf49193c2017-07-06 17:40:23 +03002074 .id = CHV_DISP_PW_PIPE_A,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002075 .ops = &chv_pipe_power_well_ops,
2076 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002077 {
2078 .name = "dpio-common-bc",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002079 .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002080 .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002081 .ops = &chv_dpio_cmn_power_well_ops,
2082 },
2083 {
2084 .name = "dpio-common-d",
Ville Syrjälä71849b62015-04-10 18:21:29 +03002085 .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002086 .id = PUNIT_POWER_WELL_DPIO_CMN_D,
Daniel Vetter9c065a72014-09-30 10:56:38 +02002087 .ops = &chv_dpio_cmn_power_well_ops,
2088 },
Daniel Vetter9c065a72014-09-30 10:56:38 +02002089};
2090
Suketu Shah5aefb232015-04-16 14:22:10 +05302091bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
Imre Deak438b8dc2017-07-11 23:42:30 +03002092 enum i915_power_well_id power_well_id)
Suketu Shah5aefb232015-04-16 14:22:10 +05302093{
2094 struct i915_power_well *power_well;
2095 bool ret;
2096
2097 power_well = lookup_power_well(dev_priv, power_well_id);
2098 ret = power_well->ops->is_enabled(dev_priv, power_well);
2099
2100 return ret;
2101}
2102
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002103static struct i915_power_well skl_power_wells[] = {
2104 {
2105 .name = "always-on",
2106 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002107 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002108 .ops = &i9xx_always_on_power_well_ops,
Imre Deak438b8dc2017-07-11 23:42:30 +03002109 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002110 },
2111 {
2112 .name = "power well 1",
Imre Deak4a76f292015-11-04 19:24:15 +02002113 /* Handled by the DMC firmware */
2114 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002115 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002116 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002117 {
2118 .hsw.has_fuses = true,
2119 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002120 },
2121 {
2122 .name = "MISC IO power well",
Imre Deak4a76f292015-11-04 19:24:15 +02002123 /* Handled by the DMC firmware */
2124 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002125 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002126 .id = SKL_DISP_PW_MISC_IO,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002127 },
2128 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002129 .name = "DC off",
2130 .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
2131 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002132 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002133 },
2134 {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002135 .name = "power well 2",
2136 .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002137 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002138 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002139 {
2140 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2141 .hsw.has_vga = true,
2142 .hsw.has_fuses = true,
2143 },
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002144 },
2145 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002146 .name = "DDI A/E IO power well",
2147 .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002148 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002149 .id = SKL_DISP_PW_DDI_A_E,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002150 },
2151 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002152 .name = "DDI B IO power well",
2153 .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002154 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002155 .id = SKL_DISP_PW_DDI_B,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002156 },
2157 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002158 .name = "DDI C IO power well",
2159 .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002160 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002161 .id = SKL_DISP_PW_DDI_C,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002162 },
2163 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002164 .name = "DDI D IO power well",
2165 .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002166 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002167 .id = SKL_DISP_PW_DDI_D,
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002168 },
2169};
2170
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302171static struct i915_power_well bxt_power_wells[] = {
2172 {
2173 .name = "always-on",
2174 .always_on = 1,
Ville Syrjälä998bd662016-04-18 14:02:26 +03002175 .domains = POWER_DOMAIN_MASK,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302176 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002177 .id = I915_DISP_PW_ALWAYS_ON,
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302178 },
2179 {
2180 .name = "power well 1",
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002181 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002182 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002183 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002184 {
2185 .hsw.has_fuses = true,
2186 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302187 },
2188 {
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002189 .name = "DC off",
2190 .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
2191 .ops = &gen9_dc_off_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002192 .id = SKL_DISP_PW_DC_OFF,
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002193 },
2194 {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302195 .name = "power well 2",
2196 .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002197 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002198 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002199 {
2200 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2201 .hsw.has_vga = true,
2202 .hsw.has_fuses = true,
2203 },
Patrik Jakobsson9f836f92015-11-16 16:20:01 +01002204 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002205 {
2206 .name = "dpio-common-a",
2207 .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
2208 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002209 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002210 {
2211 .bxt.phy = DPIO_PHY1,
2212 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002213 },
2214 {
2215 .name = "dpio-common-bc",
2216 .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
2217 .ops = &bxt_dpio_cmn_power_well_ops,
Ander Conselvan de Oliveira01c3faa2016-10-06 19:22:14 +03002218 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002219 {
2220 .bxt.phy = DPIO_PHY0,
2221 },
Imre Deak9c8d0b82016-06-13 16:44:34 +03002222 },
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302223};
2224
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002225static struct i915_power_well glk_power_wells[] = {
2226 {
2227 .name = "always-on",
2228 .always_on = 1,
2229 .domains = POWER_DOMAIN_MASK,
2230 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002231 .id = I915_DISP_PW_ALWAYS_ON,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002232 },
2233 {
2234 .name = "power well 1",
2235 /* Handled by the DMC firmware */
2236 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002237 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002238 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002239 {
2240 .hsw.has_fuses = true,
2241 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002242 },
2243 {
2244 .name = "DC off",
2245 .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
2246 .ops = &gen9_dc_off_power_well_ops,
2247 .id = SKL_DISP_PW_DC_OFF,
2248 },
2249 {
2250 .name = "power well 2",
2251 .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002252 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002253 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002254 {
2255 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2256 .hsw.has_vga = true,
2257 .hsw.has_fuses = true,
2258 },
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002259 },
2260 {
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002261 .name = "dpio-common-a",
2262 .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
2263 .ops = &bxt_dpio_cmn_power_well_ops,
2264 .id = BXT_DPIO_CMN_A,
Imre Deak0a445942017-08-14 18:15:29 +03002265 {
2266 .bxt.phy = DPIO_PHY1,
2267 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002268 },
2269 {
2270 .name = "dpio-common-b",
2271 .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
2272 .ops = &bxt_dpio_cmn_power_well_ops,
2273 .id = BXT_DPIO_CMN_BC,
Imre Deak0a445942017-08-14 18:15:29 +03002274 {
2275 .bxt.phy = DPIO_PHY0,
2276 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002277 },
2278 {
2279 .name = "dpio-common-c",
2280 .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
2281 .ops = &bxt_dpio_cmn_power_well_ops,
2282 .id = GLK_DPIO_CMN_C,
Imre Deak0a445942017-08-14 18:15:29 +03002283 {
2284 .bxt.phy = DPIO_PHY2,
2285 },
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +02002286 },
2287 {
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002288 .name = "AUX A",
2289 .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002290 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002291 .id = GLK_DISP_PW_AUX_A,
2292 },
2293 {
2294 .name = "AUX B",
2295 .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002296 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002297 .id = GLK_DISP_PW_AUX_B,
2298 },
2299 {
2300 .name = "AUX C",
2301 .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002302 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002303 .id = GLK_DISP_PW_AUX_C,
2304 },
2305 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002306 .name = "DDI A IO power well",
2307 .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002308 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002309 .id = GLK_DISP_PW_DDI_A,
2310 },
2311 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002312 .name = "DDI B IO power well",
2313 .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002314 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002315 .id = SKL_DISP_PW_DDI_B,
2316 },
2317 {
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002318 .name = "DDI C IO power well",
2319 .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002320 .ops = &hsw_power_well_ops,
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002321 .id = SKL_DISP_PW_DDI_C,
2322 },
2323};
2324
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002325static struct i915_power_well cnl_power_wells[] = {
2326 {
2327 .name = "always-on",
2328 .always_on = 1,
2329 .domains = POWER_DOMAIN_MASK,
2330 .ops = &i9xx_always_on_power_well_ops,
Imre Deak029d80d2017-07-06 17:40:25 +03002331 .id = I915_DISP_PW_ALWAYS_ON,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002332 },
2333 {
2334 .name = "power well 1",
2335 /* Handled by the DMC firmware */
2336 .domains = 0,
Imre Deak4196b912017-07-11 23:42:36 +03002337 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002338 .id = SKL_DISP_PW_1,
Imre Deak0a445942017-08-14 18:15:29 +03002339 {
2340 .hsw.has_fuses = true,
2341 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002342 },
2343 {
2344 .name = "AUX A",
2345 .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002346 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002347 .id = CNL_DISP_PW_AUX_A,
2348 },
2349 {
2350 .name = "AUX B",
2351 .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002352 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002353 .id = CNL_DISP_PW_AUX_B,
2354 },
2355 {
2356 .name = "AUX C",
2357 .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002358 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002359 .id = CNL_DISP_PW_AUX_C,
2360 },
2361 {
2362 .name = "AUX D",
2363 .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002364 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002365 .id = CNL_DISP_PW_AUX_D,
2366 },
2367 {
2368 .name = "DC off",
2369 .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
2370 .ops = &gen9_dc_off_power_well_ops,
2371 .id = SKL_DISP_PW_DC_OFF,
2372 },
2373 {
2374 .name = "power well 2",
2375 .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002376 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002377 .id = SKL_DISP_PW_2,
Imre Deak0a445942017-08-14 18:15:29 +03002378 {
2379 .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
2380 .hsw.has_vga = true,
2381 .hsw.has_fuses = true,
2382 },
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002383 },
2384 {
2385 .name = "DDI A IO power well",
2386 .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002387 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002388 .id = CNL_DISP_PW_DDI_A,
2389 },
2390 {
2391 .name = "DDI B IO power well",
2392 .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002393 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002394 .id = SKL_DISP_PW_DDI_B,
2395 },
2396 {
2397 .name = "DDI C IO power well",
2398 .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002399 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002400 .id = SKL_DISP_PW_DDI_C,
2401 },
2402 {
2403 .name = "DDI D IO power well",
2404 .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
Imre Deak4196b912017-07-11 23:42:36 +03002405 .ops = &hsw_power_well_ops,
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002406 .id = SKL_DISP_PW_DDI_D,
2407 },
2408};
2409
Imre Deak1b0e3a02015-11-05 23:04:11 +02002410static int
2411sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
2412 int disable_power_well)
2413{
2414 if (disable_power_well >= 0)
2415 return !!disable_power_well;
2416
Imre Deak1b0e3a02015-11-05 23:04:11 +02002417 return 1;
2418}
2419
Imre Deaka37baf32016-02-29 22:49:03 +02002420static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
2421 int enable_dc)
2422{
2423 uint32_t mask;
2424 int requested_dc;
2425 int max_dc;
2426
Rodrigo Vivi6d6a8972017-07-06 13:45:08 -07002427 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002428 max_dc = 2;
2429 mask = 0;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002430 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deaka37baf32016-02-29 22:49:03 +02002431 max_dc = 1;
2432 /*
2433 * DC9 has a separate HW flow from the rest of the DC states,
2434 * not depending on the DMC firmware. It's needed by system
2435 * suspend/resume, so allow it unconditionally.
2436 */
2437 mask = DC_STATE_EN_DC9;
2438 } else {
2439 max_dc = 0;
2440 mask = 0;
2441 }
2442
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002443 if (!i915_modparams.disable_power_well)
Imre Deak66e2c4c2016-02-29 22:49:04 +02002444 max_dc = 0;
2445
Imre Deaka37baf32016-02-29 22:49:03 +02002446 if (enable_dc >= 0 && enable_dc <= max_dc) {
2447 requested_dc = enable_dc;
2448 } else if (enable_dc == -1) {
2449 requested_dc = max_dc;
2450 } else if (enable_dc > max_dc && enable_dc <= 2) {
2451 DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
2452 enable_dc, max_dc);
2453 requested_dc = max_dc;
2454 } else {
2455 DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
2456 requested_dc = max_dc;
2457 }
2458
2459 if (requested_dc > 1)
2460 mask |= DC_STATE_EN_UPTO_DC6;
2461 if (requested_dc > 0)
2462 mask |= DC_STATE_EN_UPTO_DC5;
2463
2464 DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
2465
2466 return mask;
2467}
2468
Imre Deak21792c62017-07-11 23:42:33 +03002469static void assert_power_well_ids_unique(struct drm_i915_private *dev_priv)
2470{
2471 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2472 u64 power_well_ids;
2473 int i;
2474
2475 power_well_ids = 0;
2476 for (i = 0; i < power_domains->power_well_count; i++) {
2477 enum i915_power_well_id id = power_domains->power_wells[i].id;
2478
2479 WARN_ON(id >= sizeof(power_well_ids) * 8);
2480 WARN_ON(power_well_ids & BIT_ULL(id));
2481 power_well_ids |= BIT_ULL(id);
2482 }
2483}
2484
Daniel Vetter9c065a72014-09-30 10:56:38 +02002485#define set_power_wells(power_domains, __power_wells) ({ \
2486 (power_domains)->power_wells = (__power_wells); \
2487 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
2488})
2489
Daniel Vettere4e76842014-09-30 10:56:42 +02002490/**
2491 * intel_power_domains_init - initializes the power domain structures
2492 * @dev_priv: i915 device instance
2493 *
2494 * Initializes the power domain structures for @dev_priv depending upon the
2495 * supported platform.
2496 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02002497int intel_power_domains_init(struct drm_i915_private *dev_priv)
2498{
2499 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2500
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002501 i915_modparams.disable_power_well =
2502 sanitize_disable_power_well_option(dev_priv,
2503 i915_modparams.disable_power_well);
2504 dev_priv->csr.allowed_dc_mask =
2505 get_allowed_dc_mask(dev_priv, i915_modparams.enable_dc);
Imre Deak1b0e3a02015-11-05 23:04:11 +02002506
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02002507 BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
Ville Syrjäläf0ab43e2015-11-09 16:48:19 +01002508
Daniel Vetter9c065a72014-09-30 10:56:38 +02002509 mutex_init(&power_domains->lock);
2510
2511 /*
2512 * The enabling order will be from lower to higher indexed wells,
2513 * the disabling order is reversed.
2514 */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002515 if (IS_HASWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002516 set_power_wells(power_domains, hsw_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002517 } else if (IS_BROADWELL(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002518 set_power_wells(power_domains, bdw_power_wells);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002519 } else if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna M94dd5132015-02-04 13:57:44 +00002520 set_power_wells(power_domains, skl_power_wells);
Ville Syrjälä8bcd3dd2017-06-06 13:30:39 -07002521 } else if (IS_CANNONLAKE(dev_priv)) {
2522 set_power_wells(power_domains, cnl_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002523 } else if (IS_BROXTON(dev_priv)) {
Satheeshakrishna M0b4a2a32014-07-11 14:51:13 +05302524 set_power_wells(power_domains, bxt_power_wells);
Ander Conselvan de Oliveira0d039262016-12-02 10:23:50 +02002525 } else if (IS_GEMINILAKE(dev_priv)) {
2526 set_power_wells(power_domains, glk_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002527 } else if (IS_CHERRYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002528 set_power_wells(power_domains, chv_power_wells);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002529 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002530 set_power_wells(power_domains, vlv_power_wells);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03002531 } else if (IS_I830(dev_priv)) {
2532 set_power_wells(power_domains, i830_power_wells);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002533 } else {
2534 set_power_wells(power_domains, i9xx_always_on_power_well);
2535 }
2536
Imre Deak21792c62017-07-11 23:42:33 +03002537 assert_power_well_ids_unique(dev_priv);
2538
Daniel Vetter9c065a72014-09-30 10:56:38 +02002539 return 0;
2540}
2541
Daniel Vettere4e76842014-09-30 10:56:42 +02002542/**
2543 * intel_power_domains_fini - finalizes the power domain structures
2544 * @dev_priv: i915 device instance
2545 *
2546 * Finalizes the power domain structures for @dev_priv depending upon the
2547 * supported platform. This function also disables runtime pm and ensures that
2548 * the device stays powered up so that the driver can be reloaded.
2549 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002550void intel_power_domains_fini(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002551{
David Weinehallc49d13e2016-08-22 13:32:42 +03002552 struct device *kdev = &dev_priv->drm.pdev->dev;
Imre Deak25b181b2015-12-17 13:44:56 +02002553
Imre Deakaabee1b2015-12-15 20:10:29 +02002554 /*
2555 * The i915.ko module is still not prepared to be loaded when
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002556 * the power well is not enabled, so just enable it in case
Imre Deakaabee1b2015-12-15 20:10:29 +02002557 * we're going to unload/reload.
2558 * The following also reacquires the RPM reference the core passed
2559 * to the driver during loading, which is dropped in
2560 * intel_runtime_pm_enable(). We have to hand back the control of the
2561 * device to the core with this reference held.
2562 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002563 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02002564
2565 /* Remove the refcount we took to keep power well support disabled. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002566 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02002567 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak25b181b2015-12-17 13:44:56 +02002568
2569 /*
2570 * Remove the refcount we took in intel_runtime_pm_enable() in case
2571 * the platform doesn't support runtime PM.
2572 */
2573 if (!HAS_RUNTIME_PM(dev_priv))
David Weinehallc49d13e2016-08-22 13:32:42 +03002574 pm_runtime_put(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02002575}
2576
Imre Deak30eade12015-11-04 19:24:13 +02002577static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02002578{
2579 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2580 struct i915_power_well *power_well;
Daniel Vetter9c065a72014-09-30 10:56:38 +02002581
2582 mutex_lock(&power_domains->lock);
Imre Deak75ccb2e2017-02-17 17:39:43 +02002583 for_each_power_well(dev_priv, power_well) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02002584 power_well->ops->sync_hw(dev_priv, power_well);
2585 power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
2586 power_well);
2587 }
2588 mutex_unlock(&power_domains->lock);
2589}
2590
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002591static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
2592{
2593 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
2594 POSTING_READ(DBUF_CTL);
2595
2596 udelay(10);
2597
2598 if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
2599 DRM_ERROR("DBuf power enable timeout\n");
2600}
2601
2602static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
2603{
2604 I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
2605 POSTING_READ(DBUF_CTL);
2606
2607 udelay(10);
2608
2609 if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
2610 DRM_ERROR("DBuf power disable timeout!\n");
2611}
2612
Imre Deak73dfc222015-11-17 17:33:53 +02002613static void skl_display_core_init(struct drm_i915_private *dev_priv,
Imre Deak443a93a2016-04-04 15:42:57 +03002614 bool resume)
Imre Deak73dfc222015-11-17 17:33:53 +02002615{
2616 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002617 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002618 uint32_t val;
2619
Imre Deakd26fa1d2015-11-04 19:24:17 +02002620 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2621
Imre Deak73dfc222015-11-17 17:33:53 +02002622 /* enable PCH reset handshake */
2623 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2624 I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
2625
2626 /* enable PG1 and Misc I/O */
2627 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002628
2629 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2630 intel_power_well_enable(dev_priv, well);
2631
2632 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
2633 intel_power_well_enable(dev_priv, well);
2634
Imre Deak73dfc222015-11-17 17:33:53 +02002635 mutex_unlock(&power_domains->lock);
2636
Imre Deak73dfc222015-11-17 17:33:53 +02002637 skl_init_cdclk(dev_priv);
2638
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002639 gen9_dbuf_enable(dev_priv);
2640
Ville Syrjälä9f7eb312016-05-13 23:41:29 +03002641 if (resume && dev_priv->csr.dmc_payload)
Imre Deak2abc5252016-03-04 21:57:41 +02002642 intel_csr_load_program(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02002643}
2644
2645static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
2646{
2647 struct i915_power_domains *power_domains = &dev_priv->power_domains;
Imre Deak443a93a2016-04-04 15:42:57 +03002648 struct i915_power_well *well;
Imre Deak73dfc222015-11-17 17:33:53 +02002649
Imre Deakd26fa1d2015-11-04 19:24:17 +02002650 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2651
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002652 gen9_dbuf_disable(dev_priv);
2653
Imre Deak73dfc222015-11-17 17:33:53 +02002654 skl_uninit_cdclk(dev_priv);
2655
2656 /* The spec doesn't call for removing the reset handshake flag */
2657 /* disable PG1 and Misc I/O */
Imre Deak443a93a2016-04-04 15:42:57 +03002658
Imre Deak73dfc222015-11-17 17:33:53 +02002659 mutex_lock(&power_domains->lock);
Imre Deak443a93a2016-04-04 15:42:57 +03002660
Imre Deakedfda8e2017-06-29 18:36:59 +03002661 /*
2662 * BSpec says to keep the MISC IO power well enabled here, only
2663 * remove our request for power well 1.
Imre Deak42d93662017-06-29 18:37:01 +03002664 * Note that even though the driver's request is removed power well 1
2665 * may stay enabled after this due to DMC's own request on it.
Imre Deakedfda8e2017-06-29 18:36:59 +03002666 */
Imre Deak443a93a2016-04-04 15:42:57 +03002667 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2668 intel_power_well_disable(dev_priv, well);
2669
Imre Deak73dfc222015-11-17 17:33:53 +02002670 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002671
2672 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deak73dfc222015-11-17 17:33:53 +02002673}
2674
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002675void bxt_display_core_init(struct drm_i915_private *dev_priv,
2676 bool resume)
2677{
2678 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2679 struct i915_power_well *well;
2680 uint32_t val;
2681
2682 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2683
2684 /*
2685 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
2686 * or else the reset will hang because there is no PCH to respond.
2687 * Move the handshake programming to initialization sequence.
2688 * Previously was left up to BIOS.
2689 */
2690 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2691 val &= ~RESET_PCH_HANDSHAKE_ENABLE;
2692 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2693
2694 /* Enable PG1 */
2695 mutex_lock(&power_domains->lock);
2696
2697 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2698 intel_power_well_enable(dev_priv, well);
2699
2700 mutex_unlock(&power_domains->lock);
2701
Imre Deak324513c2016-06-13 16:44:36 +03002702 bxt_init_cdclk(dev_priv);
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002703
2704 gen9_dbuf_enable(dev_priv);
2705
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002706 if (resume && dev_priv->csr.dmc_payload)
2707 intel_csr_load_program(dev_priv);
2708}
2709
2710void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
2711{
2712 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2713 struct i915_power_well *well;
2714
2715 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2716
Ville Syrjälä70c2c182016-05-13 23:41:30 +03002717 gen9_dbuf_disable(dev_priv);
2718
Imre Deak324513c2016-06-13 16:44:36 +03002719 bxt_uninit_cdclk(dev_priv);
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002720
2721 /* The spec doesn't call for removing the reset handshake flag */
2722
Imre Deak42d93662017-06-29 18:37:01 +03002723 /*
2724 * Disable PW1 (PG1).
2725 * Note that even though the driver's request is removed power well 1
2726 * may stay enabled after this due to DMC's own request on it.
2727 */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002728 mutex_lock(&power_domains->lock);
2729
2730 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2731 intel_power_well_disable(dev_priv, well);
2732
2733 mutex_unlock(&power_domains->lock);
Imre Deak846c6b22017-06-29 18:36:58 +03002734
2735 usleep_range(10, 30); /* 10 us delay per Bspec */
Imre Deakd7d7c9e2016-04-01 16:02:42 +03002736}
2737
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002738enum {
2739 PROCMON_0_85V_DOT_0,
2740 PROCMON_0_95V_DOT_0,
2741 PROCMON_0_95V_DOT_1,
2742 PROCMON_1_05V_DOT_0,
2743 PROCMON_1_05V_DOT_1,
2744};
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002745
2746static const struct cnl_procmon {
2747 u32 dw1, dw9, dw10;
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002748} cnl_procmon_values[] = {
2749 [PROCMON_0_85V_DOT_0] =
2750 { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
2751 [PROCMON_0_95V_DOT_0] =
2752 { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
2753 [PROCMON_0_95V_DOT_1] =
2754 { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
2755 [PROCMON_1_05V_DOT_0] =
2756 { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
2757 [PROCMON_1_05V_DOT_1] =
2758 { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002759};
2760
Paulo Zanoniade5ee72017-08-21 17:03:56 -07002761static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv)
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002762{
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002763 const struct cnl_procmon *procmon;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002764 u32 val;
2765
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002766 val = I915_READ(CNL_PORT_COMP_DW3);
Paulo Zanonie0b8acf2017-08-21 17:03:55 -07002767 switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
2768 default:
2769 MISSING_CASE(val);
2770 case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
2771 procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
2772 break;
2773 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
2774 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
2775 break;
2776 case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
2777 procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
2778 break;
2779 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
2780 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
2781 break;
2782 case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
2783 procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
2784 break;
2785 }
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002786
2787 val = I915_READ(CNL_PORT_COMP_DW1);
2788 val &= ~((0xff << 16) | 0xff);
2789 val |= procmon->dw1;
2790 I915_WRITE(CNL_PORT_COMP_DW1, val);
2791
2792 I915_WRITE(CNL_PORT_COMP_DW9, procmon->dw9);
2793 I915_WRITE(CNL_PORT_COMP_DW10, procmon->dw10);
Paulo Zanoniade5ee72017-08-21 17:03:56 -07002794}
2795
2796static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
2797{
2798 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2799 struct i915_power_well *well;
2800 u32 val;
2801
2802 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2803
2804 /* 1. Enable PCH Reset Handshake */
2805 val = I915_READ(HSW_NDE_RSTWRN_OPT);
2806 val |= RESET_PCH_HANDSHAKE_ENABLE;
2807 I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
2808
2809 /* 2. Enable Comp */
2810 val = I915_READ(CHICKEN_MISC_2);
2811 val &= ~CNL_COMP_PWR_DOWN;
2812 I915_WRITE(CHICKEN_MISC_2, val);
2813
2814 cnl_set_procmon_ref_values(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002815
2816 val = I915_READ(CNL_PORT_COMP_DW0);
2817 val |= COMP_INIT;
2818 I915_WRITE(CNL_PORT_COMP_DW0, val);
2819
2820 /* 3. */
2821 val = I915_READ(CNL_PORT_CL1CM_DW5);
2822 val |= CL_POWER_DOWN_ENABLE;
2823 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2824
Imre Deakb38131f2017-06-29 18:37:02 +03002825 /*
2826 * 4. Enable Power Well 1 (PG1).
2827 * The AUX IO power wells will be enabled on demand.
2828 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002829 mutex_lock(&power_domains->lock);
2830 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2831 intel_power_well_enable(dev_priv, well);
2832 mutex_unlock(&power_domains->lock);
2833
2834 /* 5. Enable CD clock */
2835 cnl_init_cdclk(dev_priv);
2836
2837 /* 6. Enable DBUF */
2838 gen9_dbuf_enable(dev_priv);
Imre Deak57522c42017-10-03 12:51:58 +03002839
2840 if (resume && dev_priv->csr.dmc_payload)
2841 intel_csr_load_program(dev_priv);
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002842}
2843
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002844static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
2845{
2846 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2847 struct i915_power_well *well;
2848 u32 val;
2849
2850 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
2851
2852 /* 1. Disable all display engine functions -> aready done */
2853
2854 /* 2. Disable DBUF */
2855 gen9_dbuf_disable(dev_priv);
2856
2857 /* 3. Disable CD clock */
2858 cnl_uninit_cdclk(dev_priv);
2859
Imre Deakb38131f2017-06-29 18:37:02 +03002860 /*
2861 * 4. Disable Power Well 1 (PG1).
2862 * The AUX IO power wells are toggled on demand, so they are already
2863 * disabled at this point.
2864 */
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002865 mutex_lock(&power_domains->lock);
2866 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
2867 intel_power_well_disable(dev_priv, well);
2868 mutex_unlock(&power_domains->lock);
2869
Imre Deak846c6b22017-06-29 18:36:58 +03002870 usleep_range(10, 30); /* 10 us delay per Bspec */
2871
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002872 /* 5. Disable Comp */
2873 val = I915_READ(CHICKEN_MISC_2);
Paulo Zanoni746a5172017-07-14 14:52:28 -03002874 val |= CNL_COMP_PWR_DOWN;
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07002875 I915_WRITE(CHICKEN_MISC_2, val);
2876}
2877
Ville Syrjälä70722462015-04-10 18:21:28 +03002878static void chv_phy_control_init(struct drm_i915_private *dev_priv)
2879{
2880 struct i915_power_well *cmn_bc =
2881 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2882 struct i915_power_well *cmn_d =
2883 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
2884
2885 /*
2886 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
2887 * workaround never ever read DISPLAY_PHY_CONTROL, and
2888 * instead maintain a shadow copy ourselves. Use the actual
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002889 * power well state and lane status to reconstruct the
2890 * expected initial value.
Ville Syrjälä70722462015-04-10 18:21:28 +03002891 */
2892 dev_priv->chv_phy_control =
Ville Syrjäläbc284542015-05-26 20:22:38 +03002893 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
2894 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002895 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
2896 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
2897 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
2898
2899 /*
2900 * If all lanes are disabled we leave the override disabled
2901 * with all power down bits cleared to match the state we
2902 * would use after disabling the port. Otherwise enable the
2903 * override and set the lane powerdown bits accding to the
2904 * current lane status.
2905 */
2906 if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
2907 uint32_t status = I915_READ(DPLL(PIPE_A));
2908 unsigned int mask;
2909
2910 mask = status & DPLL_PORTB_READY_MASK;
2911 if (mask == 0xf)
2912 mask = 0x0;
2913 else
2914 dev_priv->chv_phy_control |=
2915 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
2916
2917 dev_priv->chv_phy_control |=
2918 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
2919
2920 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
2921 if (mask == 0xf)
2922 mask = 0x0;
2923 else
2924 dev_priv->chv_phy_control |=
2925 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
2926
2927 dev_priv->chv_phy_control |=
2928 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
2929
Ville Syrjälä70722462015-04-10 18:21:28 +03002930 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002931
2932 dev_priv->chv_phy_assert[DPIO_PHY0] = false;
2933 } else {
2934 dev_priv->chv_phy_assert[DPIO_PHY0] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002935 }
2936
2937 if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
2938 uint32_t status = I915_READ(DPIO_PHY_STATUS);
2939 unsigned int mask;
2940
2941 mask = status & DPLL_PORTD_READY_MASK;
2942
2943 if (mask == 0xf)
2944 mask = 0x0;
2945 else
2946 dev_priv->chv_phy_control |=
2947 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
2948
2949 dev_priv->chv_phy_control |=
2950 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
2951
Ville Syrjälä70722462015-04-10 18:21:28 +03002952 dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
Ville Syrjälä3be60de2015-09-08 18:05:45 +03002953
2954 dev_priv->chv_phy_assert[DPIO_PHY1] = false;
2955 } else {
2956 dev_priv->chv_phy_assert[DPIO_PHY1] = true;
Ville Syrjäläe0fce782015-07-08 23:45:54 +03002957 }
2958
2959 I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
2960
2961 DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
2962 dev_priv->chv_phy_control);
Ville Syrjälä70722462015-04-10 18:21:28 +03002963}
2964
Daniel Vetter9c065a72014-09-30 10:56:38 +02002965static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
2966{
2967 struct i915_power_well *cmn =
2968 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
2969 struct i915_power_well *disp2d =
2970 lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
2971
Daniel Vetter9c065a72014-09-30 10:56:38 +02002972 /* If the display might be already active skip this */
Ville Syrjälä5d93a6e2014-10-16 20:52:33 +03002973 if (cmn->ops->is_enabled(dev_priv, cmn) &&
2974 disp2d->ops->is_enabled(dev_priv, disp2d) &&
Daniel Vetter9c065a72014-09-30 10:56:38 +02002975 I915_READ(DPIO_CTL) & DPIO_CMNRST)
2976 return;
2977
2978 DRM_DEBUG_KMS("toggling display PHY side reset\n");
2979
2980 /* cmnlane needs DPLL registers */
2981 disp2d->ops->enable(dev_priv, disp2d);
2982
2983 /*
2984 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
2985 * Need to assert and de-assert PHY SB reset by gating the
2986 * common lane power, then un-gating it.
2987 * Simply ungating isn't enough to reset the PHY enough to get
2988 * ports and lanes running.
2989 */
2990 cmn->ops->disable(dev_priv, cmn);
2991}
2992
Daniel Vettere4e76842014-09-30 10:56:42 +02002993/**
2994 * intel_power_domains_init_hw - initialize hardware power domain state
2995 * @dev_priv: i915 device instance
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002996 * @resume: Called from resume code paths or not
Daniel Vettere4e76842014-09-30 10:56:42 +02002997 *
2998 * This function initializes the hardware power domain state and enables all
Imre Deak8d8c3862017-02-17 17:39:46 +02002999 * power wells belonging to the INIT power domain. Power wells in other
3000 * domains (and not in the INIT domain) are referenced or disabled during the
3001 * modeset state HW readout. After that the reference count of each power well
3002 * must match its HW enabled state, see intel_power_domains_verify_state().
Daniel Vettere4e76842014-09-30 10:56:42 +02003003 */
Imre Deak73dfc222015-11-17 17:33:53 +02003004void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003005{
Daniel Vetter9c065a72014-09-30 10:56:38 +02003006 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3007
3008 power_domains->initializing = true;
3009
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003010 if (IS_CANNONLAKE(dev_priv)) {
3011 cnl_display_core_init(dev_priv, resume);
3012 } else if (IS_GEN9_BC(dev_priv)) {
Imre Deak73dfc222015-11-17 17:33:53 +02003013 skl_display_core_init(dev_priv, resume);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003014 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003015 bxt_display_core_init(dev_priv, resume);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01003016 } else if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä770effb2015-07-08 23:45:51 +03003017 mutex_lock(&power_domains->lock);
Ville Syrjälä70722462015-04-10 18:21:28 +03003018 chv_phy_control_init(dev_priv);
Ville Syrjälä770effb2015-07-08 23:45:51 +03003019 mutex_unlock(&power_domains->lock);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01003020 } else if (IS_VALLEYVIEW(dev_priv)) {
Daniel Vetter9c065a72014-09-30 10:56:38 +02003021 mutex_lock(&power_domains->lock);
3022 vlv_cmnlane_wa(dev_priv);
3023 mutex_unlock(&power_domains->lock);
3024 }
3025
3026 /* For now, we need the power well to be always enabled. */
3027 intel_display_set_init_power(dev_priv, true);
Imre Deakd314cd42015-11-17 17:44:23 +02003028 /* Disable power support if the user asked so. */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003029 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003030 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak30eade12015-11-04 19:24:13 +02003031 intel_power_domains_sync_hw(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003032 power_domains->initializing = false;
3033}
3034
Daniel Vettere4e76842014-09-30 10:56:42 +02003035/**
Imre Deak73dfc222015-11-17 17:33:53 +02003036 * intel_power_domains_suspend - suspend power domain state
3037 * @dev_priv: i915 device instance
3038 *
3039 * This function prepares the hardware power domain state before entering
3040 * system suspend. It must be paired with intel_power_domains_init_hw().
3041 */
3042void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
3043{
Imre Deakd314cd42015-11-17 17:44:23 +02003044 /*
3045 * Even if power well support was disabled we still want to disable
3046 * power wells while we are system suspended.
3047 */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003048 if (!i915_modparams.disable_power_well)
Imre Deakd314cd42015-11-17 17:44:23 +02003049 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2622d792016-02-29 22:49:02 +02003050
Ville Syrjäläd8d4a512017-06-09 15:26:00 -07003051 if (IS_CANNONLAKE(dev_priv))
3052 cnl_display_core_uninit(dev_priv);
3053 else if (IS_GEN9_BC(dev_priv))
Imre Deak2622d792016-02-29 22:49:02 +02003054 skl_display_core_uninit(dev_priv);
Ander Conselvan de Oliveirab817c442016-12-02 10:23:56 +02003055 else if (IS_GEN9_LP(dev_priv))
Imre Deakd7d7c9e2016-04-01 16:02:42 +03003056 bxt_display_core_uninit(dev_priv);
Imre Deak73dfc222015-11-17 17:33:53 +02003057}
3058
Imre Deak8d8c3862017-02-17 17:39:46 +02003059static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
3060{
3061 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3062 struct i915_power_well *power_well;
3063
3064 for_each_power_well(dev_priv, power_well) {
3065 enum intel_display_power_domain domain;
3066
3067 DRM_DEBUG_DRIVER("%-25s %d\n",
3068 power_well->name, power_well->count);
3069
3070 for_each_power_domain(domain, power_well->domains)
3071 DRM_DEBUG_DRIVER(" %-23s %d\n",
3072 intel_display_power_domain_str(domain),
3073 power_domains->domain_use_count[domain]);
3074 }
3075}
3076
3077/**
3078 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
3079 * @dev_priv: i915 device instance
3080 *
3081 * Verify if the reference count of each power well matches its HW enabled
3082 * state and the total refcount of the domains it belongs to. This must be
3083 * called after modeset HW state sanitization, which is responsible for
3084 * acquiring reference counts for any power wells in use and disabling the
3085 * ones left on by BIOS but not required by any active output.
3086 */
3087void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
3088{
3089 struct i915_power_domains *power_domains = &dev_priv->power_domains;
3090 struct i915_power_well *power_well;
3091 bool dump_domain_info;
3092
3093 mutex_lock(&power_domains->lock);
3094
3095 dump_domain_info = false;
3096 for_each_power_well(dev_priv, power_well) {
3097 enum intel_display_power_domain domain;
3098 int domains_count;
3099 bool enabled;
3100
3101 /*
3102 * Power wells not belonging to any domain (like the MISC_IO
3103 * and PW1 power wells) are under FW control, so ignore them,
3104 * since their state can change asynchronously.
3105 */
3106 if (!power_well->domains)
3107 continue;
3108
3109 enabled = power_well->ops->is_enabled(dev_priv, power_well);
3110 if ((power_well->count || power_well->always_on) != enabled)
3111 DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
3112 power_well->name, power_well->count, enabled);
3113
3114 domains_count = 0;
3115 for_each_power_domain(domain, power_well->domains)
3116 domains_count += power_domains->domain_use_count[domain];
3117
3118 if (power_well->count != domains_count) {
3119 DRM_ERROR("power well %s refcount/domain refcount mismatch "
3120 "(refcount %d/domains refcount %d)\n",
3121 power_well->name, power_well->count,
3122 domains_count);
3123 dump_domain_info = true;
3124 }
3125 }
3126
3127 if (dump_domain_info) {
3128 static bool dumped;
3129
3130 if (!dumped) {
3131 intel_power_domains_dump_info(dev_priv);
3132 dumped = true;
3133 }
3134 }
3135
3136 mutex_unlock(&power_domains->lock);
3137}
3138
Imre Deak73dfc222015-11-17 17:33:53 +02003139/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003140 * intel_runtime_pm_get - grab a runtime pm reference
3141 * @dev_priv: i915 device instance
3142 *
3143 * This function grabs a device-level runtime pm reference (mostly used for GEM
3144 * code to ensure the GTT or GT is on) and ensures that it is powered up.
3145 *
3146 * Any runtime pm reference obtained by this function must have a symmetric
3147 * call to intel_runtime_pm_put() to release the reference again.
3148 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003149void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
3150{
David Weinehall52a05c32016-08-22 13:32:44 +03003151 struct pci_dev *pdev = dev_priv->drm.pdev;
3152 struct device *kdev = &pdev->dev;
Imre Deakf5073822017-03-28 12:38:55 +03003153 int ret;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003154
Imre Deakf5073822017-03-28 12:38:55 +03003155 ret = pm_runtime_get_sync(kdev);
3156 WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deak1f814da2015-12-16 02:52:19 +02003157
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003158 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deakc9b88462015-12-15 20:10:34 +02003159 assert_rpm_wakelock_held(dev_priv);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003160}
3161
Daniel Vettere4e76842014-09-30 10:56:42 +02003162/**
Imre Deak09731282016-02-17 14:17:42 +02003163 * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
3164 * @dev_priv: i915 device instance
3165 *
3166 * This function grabs a device-level runtime pm reference if the device is
3167 * already in use and ensures that it is powered up.
3168 *
3169 * Any runtime pm reference obtained by this function must have a symmetric
3170 * call to intel_runtime_pm_put() to release the reference again.
3171 */
3172bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
3173{
David Weinehall52a05c32016-08-22 13:32:44 +03003174 struct pci_dev *pdev = dev_priv->drm.pdev;
3175 struct device *kdev = &pdev->dev;
Imre Deak09731282016-02-17 14:17:42 +02003176
Chris Wilson135dc792016-02-25 21:10:28 +00003177 if (IS_ENABLED(CONFIG_PM)) {
David Weinehallc49d13e2016-08-22 13:32:42 +03003178 int ret = pm_runtime_get_if_in_use(kdev);
Imre Deak09731282016-02-17 14:17:42 +02003179
Chris Wilson135dc792016-02-25 21:10:28 +00003180 /*
3181 * In cases runtime PM is disabled by the RPM core and we get
3182 * an -EINVAL return value we are not supposed to call this
3183 * function, since the power state is undefined. This applies
3184 * atm to the late/early system suspend/resume handlers.
3185 */
Imre Deakf5073822017-03-28 12:38:55 +03003186 WARN_ONCE(ret < 0,
3187 "pm_runtime_get_if_in_use() failed: %d\n", ret);
Chris Wilson135dc792016-02-25 21:10:28 +00003188 if (ret <= 0)
3189 return false;
3190 }
Imre Deak09731282016-02-17 14:17:42 +02003191
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003192 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Imre Deak09731282016-02-17 14:17:42 +02003193 assert_rpm_wakelock_held(dev_priv);
3194
3195 return true;
3196}
3197
3198/**
Daniel Vettere4e76842014-09-30 10:56:42 +02003199 * intel_runtime_pm_get_noresume - grab a runtime pm reference
3200 * @dev_priv: i915 device instance
3201 *
3202 * This function grabs a device-level runtime pm reference (mostly used for GEM
3203 * code to ensure the GTT or GT is on).
3204 *
3205 * It will _not_ power up the device but instead only check that it's powered
3206 * on. Therefore it is only valid to call this functions from contexts where
3207 * the device is known to be powered up and where trying to power it up would
3208 * result in hilarity and deadlocks. That pretty much means only the system
3209 * suspend/resume code where this is used to grab runtime pm references for
3210 * delayed setup down in work items.
3211 *
3212 * Any runtime pm reference obtained by this function must have a symmetric
3213 * call to intel_runtime_pm_put() to release the reference again.
3214 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003215void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
3216{
David Weinehall52a05c32016-08-22 13:32:44 +03003217 struct pci_dev *pdev = dev_priv->drm.pdev;
3218 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003219
Imre Deakc9b88462015-12-15 20:10:34 +02003220 assert_rpm_wakelock_held(dev_priv);
David Weinehallc49d13e2016-08-22 13:32:42 +03003221 pm_runtime_get_noresume(kdev);
Imre Deak1f814da2015-12-16 02:52:19 +02003222
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003223 atomic_inc(&dev_priv->runtime_pm.wakeref_count);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003224}
3225
Daniel Vettere4e76842014-09-30 10:56:42 +02003226/**
3227 * intel_runtime_pm_put - release a runtime pm reference
3228 * @dev_priv: i915 device instance
3229 *
3230 * This function drops the device-level runtime pm reference obtained by
3231 * intel_runtime_pm_get() and might power down the corresponding
3232 * hardware block right away if this is the last reference.
3233 */
Daniel Vetter9c065a72014-09-30 10:56:38 +02003234void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
3235{
David Weinehall52a05c32016-08-22 13:32:44 +03003236 struct pci_dev *pdev = dev_priv->drm.pdev;
3237 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003238
Imre Deak542db3c2015-12-15 20:10:36 +02003239 assert_rpm_wakelock_held(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01003240 atomic_dec(&dev_priv->runtime_pm.wakeref_count);
Imre Deak1f814da2015-12-16 02:52:19 +02003241
David Weinehallc49d13e2016-08-22 13:32:42 +03003242 pm_runtime_mark_last_busy(kdev);
3243 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003244}
3245
Daniel Vettere4e76842014-09-30 10:56:42 +02003246/**
3247 * intel_runtime_pm_enable - enable runtime pm
3248 * @dev_priv: i915 device instance
3249 *
3250 * This function enables runtime pm at the end of the driver load sequence.
3251 *
3252 * Note that this function does currently not enable runtime pm for the
3253 * subordinate display power domains. That is only done on the first modeset
3254 * using intel_display_set_init_power().
3255 */
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003256void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
Daniel Vetter9c065a72014-09-30 10:56:38 +02003257{
David Weinehall52a05c32016-08-22 13:32:44 +03003258 struct pci_dev *pdev = dev_priv->drm.pdev;
David Weinehall52a05c32016-08-22 13:32:44 +03003259 struct device *kdev = &pdev->dev;
Daniel Vetter9c065a72014-09-30 10:56:38 +02003260
David Weinehallc49d13e2016-08-22 13:32:42 +03003261 pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
3262 pm_runtime_mark_last_busy(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003263
Imre Deak25b181b2015-12-17 13:44:56 +02003264 /*
3265 * Take a permanent reference to disable the RPM functionality and drop
3266 * it only when unloading the driver. Use the low level get/put helpers,
3267 * so the driver's own RPM reference tracking asserts also work on
3268 * platforms without RPM support.
3269 */
Tvrtko Ursulin6772ffe2016-10-13 11:02:55 +01003270 if (!HAS_RUNTIME_PM(dev_priv)) {
Imre Deakf5073822017-03-28 12:38:55 +03003271 int ret;
3272
David Weinehallc49d13e2016-08-22 13:32:42 +03003273 pm_runtime_dont_use_autosuspend(kdev);
Imre Deakf5073822017-03-28 12:38:55 +03003274 ret = pm_runtime_get_sync(kdev);
3275 WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003276 } else {
David Weinehallc49d13e2016-08-22 13:32:42 +03003277 pm_runtime_use_autosuspend(kdev);
Imre Deakcbc68dc2015-12-17 19:04:33 +02003278 }
Daniel Vetter9c065a72014-09-30 10:56:38 +02003279
Imre Deakaabee1b2015-12-15 20:10:29 +02003280 /*
3281 * The core calls the driver load handler with an RPM reference held.
3282 * We drop that here and will reacquire it during unloading in
3283 * intel_power_domains_fini().
3284 */
David Weinehallc49d13e2016-08-22 13:32:42 +03003285 pm_runtime_put_autosuspend(kdev);
Daniel Vetter9c065a72014-09-30 10:56:38 +02003286}